Remove no-op functionality from IdentifyBuiltIns and refactor
Adding array built-ins like gl_FragData and gl_LastFragData to the
symbol table with a name that included their size in brackets was
incorrect and unnecessary. Remove this. The array built-ins should only
be added with their proper name and with an array type.
Also refactor the code to reduce unnecessary repetition of conditions.
The previous version attempted to split the built-ins that had
dependencies on resources into their own part of the code, but this split
was not clearly defined and only made the code harder to follow and
prone to issues.
TEST=WebGL conformance tests
Change-Id: I7a77865a594864a22f3b566f9d3da1d0ead46466
Reviewed-on: https://chromium-review.googlesource.com/258751
Reviewed-by: Nicolas Capens <capn@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Initialize.cpp b/src/compiler/translator/Initialize.cpp
index 8f79b1a..9e11405 100644
--- a/src/compiler/translator/Initialize.cpp
+++ b/src/compiler/translator/Initialize.cpp
@@ -479,7 +479,7 @@
TSymbolTable &symbolTable)
{
//
- // First, insert some special built-in variables that are not in
+ // Insert some special built-in variables that are not in
// the built-in header files.
//
switch (type)
@@ -500,27 +500,34 @@
{
symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"),
TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
- symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"),
- TType(EbtFloat, EbpMedium, EvqFragData, 4)));
+ TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
+ fragData.setArraySize(resources.MaxDrawBuffers);
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
+
if (resources.EXT_frag_depth)
{
symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_frag_depth", new TVariable(NewPoolTString("gl_FragDepthEXT"),
TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
}
- if (resources.EXT_shader_framebuffer_fetch)
+
+ if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch)
{
- symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch",
- new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"),
- TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
- }
- else if (resources.NV_shader_framebuffer_fetch)
- {
- symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
- new TVariable(NewPoolTString("gl_LastFragColor"),
- TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
- symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
- new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"),
- TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
+ TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
+ lastFragData.setArraySize(resources.MaxDrawBuffers);
+
+ if (resources.EXT_shader_framebuffer_fetch)
+ {
+ symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch",
+ new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
+ }
+ else if (resources.NV_shader_framebuffer_fetch)
+ {
+ symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
+ new TVariable(NewPoolTString("gl_LastFragColor"),
+ TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
+ symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
+ new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
+ }
}
else if (resources.ARM_shader_framebuffer_fetch)
{
@@ -551,38 +558,6 @@
default:
assert(false && "Language not supported");
}
-
- // Finally add resource-specific variables.
- switch (type)
- {
- case GL_FRAGMENT_SHADER:
- if (spec != SH_CSS_SHADERS_SPEC)
- {
- TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
- fragData.setArraySize(resources.MaxDrawBuffers);
- symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
-
- if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch)
- {
- TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
- lastFragData.setArraySize(resources.MaxDrawBuffers);
-
- if (resources.EXT_shader_framebuffer_fetch)
- {
- symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch",
- new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
- }
- else if (resources.NV_shader_framebuffer_fetch)
- {
- symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
- new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
- }
- }
- }
- break;
- default:
- break;
- }
}
void InitExtensionBehavior(const ShBuiltInResources& resources,