Hash :
02e7f967
Author :
Date :
2023-05-25T14:54:49
Translator: Remove the "variables" option Variable collection is invariably enabled by the front-end as well as other major users of ANGLE such as Firefox. All translator backends except GLSL force-enable variable collection either way. This change removes this compile option and enables variable collection unconditionally. The flag itself remains in ShCompileOptions until references to it are removed from Chromium. Bug: chromium:1447314 Change-Id: I4d3b30c1bfbd345c5ad269abc62c0a6a59de2f56 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4568524 Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_
#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_
#include "compiler/translator/Compiler.h"
namespace sh
{
constexpr const char kUniformsVar[] = "angleUniforms";
constexpr const char kUnassignedAttributeString[] = " __unassigned_attribute__";
constexpr const char kUnassignedFragmentOutputString[] = "__unassigned_output__";
class DriverUniform;
class DriverUniformMetal;
class SpecConst;
class TOutputMSL;
class TranslatorMetalReflection;
typedef std::unordered_map<size_t, std::string> originalNamesMap;
typedef std::unordered_map<std::string, size_t> samplerBindingMap;
typedef std::unordered_map<std::string, size_t> textureBindingMap;
typedef std::unordered_map<int, int> rwTextureBindingMap; // GLSL image -> mtl read_write texture.
typedef std::unordered_map<std::string, size_t> userUniformBufferBindingMap;
typedef std::pair<size_t, size_t> uboBindingInfo;
struct UBOBindingInfo
{
size_t bindIndex = 0;
size_t arraySize = 0;
};
typedef std::unordered_map<std::string, UBOBindingInfo> uniformBufferBindingMap;
namespace mtl
{
TranslatorMetalReflection *getTranslatorMetalReflection(const TCompiler *compiler);
}
class TranslatorMetalReflection
{
public:
TranslatorMetalReflection() : hasUBOs(false), hasFlatInput(false) {}
~TranslatorMetalReflection() {}
void addOriginalName(const size_t id, const std::string &name)
{
originalNames.insert({id, name});
}
void addSamplerBinding(const std::string &name, size_t samplerBinding)
{
samplerBindings.insert({name, samplerBinding});
}
void addTextureBinding(const std::string &name, size_t textureBinding)
{
textureBindings.insert({name, textureBinding});
}
void addRWTextureBinding(int glslImageBinding, int mtlRWTextureBinding)
{
bool inserted = rwTextureBindings.insert({glslImageBinding, mtlRWTextureBinding}).second;
if (!inserted)
{
// Shader images are currently only implemented enough to support pixel local storage,
// which does not allow more than one image to be bound to the same index.
//
// NOTE: Pixel local storage also does not allow image bindings to change via
// glUniform1i, which we do not currently account for in this backend.
UNIMPLEMENTED();
}
}
void addUserUniformBufferBinding(const std::string &name, size_t userUniformBufferBinding)
{
userUniformBufferBindings.insert({name, userUniformBufferBinding});
}
void addUniformBufferBinding(const std::string &name, UBOBindingInfo bindingInfo)
{
uniformBufferBindings.insert({name, bindingInfo});
}
std::string getOriginalName(const size_t id) { return originalNames.at(id); }
samplerBindingMap getSamplerBindings() const { return samplerBindings; }
textureBindingMap getTextureBindings() const { return textureBindings; }
userUniformBufferBindingMap getUserUniformBufferBindings() const
{
return userUniformBufferBindings;
}
uniformBufferBindingMap getUniformBufferBindings() const { return uniformBufferBindings; }
size_t getSamplerBinding(const std::string &name) const
{
auto it = samplerBindings.find(name);
if (it != samplerBindings.end())
{
return it->second;
}
// If we can't find a matching sampler, assert out on Debug, and return an invalid value on
// release.
ASSERT(0);
return std::numeric_limits<size_t>::max();
}
size_t getTextureBinding(const std::string &name) const
{
auto it = textureBindings.find(name);
if (it != textureBindings.end())
{
return it->second;
}
// If we can't find a matching texture, assert out on Debug, and return an invalid value on
// release.
ASSERT(0);
return std::numeric_limits<size_t>::max();
}
int getRWTextureBinding(int glslImageBinding) const
{
auto it = rwTextureBindings.find(glslImageBinding);
if (it != rwTextureBindings.end())
{
return it->second;
}
// If there isn't a shader image bound to this slot, return -1. This signals to the program
// that there is nothing here to bind.
return -1;
}
size_t getUserUniformBufferBinding(const std::string &name) const
{
auto it = userUniformBufferBindings.find(name);
if (it != userUniformBufferBindings.end())
{
return it->second;
}
// If we can't find a matching Uniform binding, assert out on Debug, and return an invalid
// value.
ASSERT(0);
return std::numeric_limits<size_t>::max();
}
UBOBindingInfo getUniformBufferBinding(const std::string &name) const
{
auto it = uniformBufferBindings.find(name);
if (it != uniformBufferBindings.end())
{
return it->second;
}
// If we can't find a matching UBO binding by name, assert out on Debug, and return an
// invalid value.
ASSERT(0);
return {.bindIndex = std::numeric_limits<size_t>::max(),
.arraySize = std::numeric_limits<size_t>::max()};
}
void reset()
{
hasUBOs = false;
hasFlatInput = false;
hasAtan = false;
hasInvariance = false;
originalNames.clear();
samplerBindings.clear();
textureBindings.clear();
rwTextureBindings.clear();
userUniformBufferBindings.clear();
uniformBufferBindings.clear();
}
bool hasUBOs = false;
bool hasFlatInput = false;
bool hasAtan = false;
bool hasInvariance = false;
private:
originalNamesMap originalNames;
samplerBindingMap samplerBindings;
textureBindingMap textureBindings;
rwTextureBindingMap rwTextureBindings;
userUniformBufferBindingMap userUniformBufferBindings;
uniformBufferBindingMap uniformBufferBindings;
};
class TranslatorMetalDirect : public TCompiler
{
public:
TranslatorMetalDirect(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
#ifdef ANGLE_ENABLE_METAL
TranslatorMetalDirect *getAsTranslatorMetalDirect() override { return this; }
#endif
TranslatorMetalReflection *getTranslatorMetalReflection() { return &translatorMetalReflection; }
protected:
bool translate(TIntermBlock *root,
const ShCompileOptions &compileOptions,
PerformanceDiagnostics *perfDiagnostics) override;
// The sample mask can't be in our fragment output struct if we read the framebuffer. Luckily,
// pixel local storage bans gl_SampleMask, so we can just not use it when PLS is active.
bool isSampleMaskAllowed() const { return !hasPixelLocalStorageUniforms(); }
[[nodiscard]] bool translateImpl(TInfoSinkBase &sink,
TIntermBlock *root,
const ShCompileOptions &compileOptions,
PerformanceDiagnostics *perfDiagnostics,
SpecConst *specConst,
DriverUniformMetal *driverUniforms);
[[nodiscard]] bool shouldFlattenPragmaStdglInvariantAll() override;
[[nodiscard]] bool transformDepthBeforeCorrection(TIntermBlock *root,
const DriverUniformMetal *driverUniforms);
[[nodiscard]] bool appendVertexShaderDepthCorrectionToMain(
TIntermBlock *root,
const DriverUniformMetal *driverUniforms);
[[nodiscard]] bool insertSampleMaskWritingLogic(TIntermBlock &root,
DriverUniformMetal &driverUniforms);
[[nodiscard]] bool insertRasterizationDiscardLogic(TIntermBlock &root);
TranslatorMetalReflection translatorMetalReflection = {};
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_H_