Adds resource string generation to ANGLE
This will avoid Chrome source having to be updated each time that ANGLE's
ShBuiltInResources changes.
BUG=374942
Change-Id: If54dba8351de9b261ff269e885f231547c08ff0a
Reviewed-on: https://chromium-review.googlesource.com/200171
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <nicolascapens@chromium.org>
Tested-by: Shannon Woods <shannonwoods@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 1864cd8..b15be1a 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -267,6 +267,7 @@
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
{
compileResources = resources;
+ setResourceString();
assert(symbolTable.isEmpty());
symbolTable.push(); // COMMON_BUILTINS
@@ -318,6 +319,34 @@
return true;
}
+void TCompiler::setResourceString()
+{
+ std::ostringstream strstream;
+ strstream << ":MaxVertexAttribs:" << compileResources.MaxVertexAttribs
+ << ":MaxVertexUniformVectors:" << compileResources.MaxVertexUniformVectors
+ << ":MaxVaryingVectors:" << compileResources.MaxVaryingVectors
+ << ":MaxVertexTextureImageUnits:" << compileResources.MaxVertexTextureImageUnits
+ << ":MaxCombinedTextureImageUnits:" << compileResources.MaxCombinedTextureImageUnits
+ << ":MaxTextureImageUnits:" << compileResources.MaxTextureImageUnits
+ << ":MaxFragmentUniformVectors:" << compileResources.MaxFragmentUniformVectors
+ << ":MaxDrawBuffers:" << compileResources.MaxDrawBuffers
+ << ":OES_standard_derivatives:" << compileResources.OES_standard_derivatives
+ << ":OES_EGL_image_external:" << compileResources.OES_EGL_image_external
+ << ":ARB_texture_rectangle:" << compileResources.ARB_texture_rectangle
+ << ":EXT_draw_buffers:" << compileResources.EXT_draw_buffers
+ << ":FragmentPrecisionHigh:" << compileResources.FragmentPrecisionHigh
+ << ":MaxExpressionComplexity:" << compileResources.MaxExpressionComplexity
+ << ":MaxCallStackDepth:" << compileResources.MaxCallStackDepth
+ << ":EXT_frag_depth:" << compileResources.EXT_frag_depth
+ << ":EXT_shader_texture_lod:" << compileResources.EXT_shader_texture_lod
+ << ":MaxVertexOutputVectors:" << compileResources.MaxVertexOutputVectors
+ << ":MaxFragmentInputVectors:" << compileResources.MaxFragmentInputVectors
+ << ":MinProgramTexelOffset:" << compileResources.MinProgramTexelOffset
+ << ":MaxProgramTexelOffset:" << compileResources.MaxProgramTexelOffset;
+
+ builtInResourcesString = strstream.str();
+}
+
void TCompiler::clearResults()
{
arrayBoundsClamper.Cleanup();
diff --git a/src/compiler/translator/ShHandle.h b/src/compiler/translator/ShHandle.h
index 50a8d58..5a2098e 100644
--- a/src/compiler/translator/ShHandle.h
+++ b/src/compiler/translator/ShHandle.h
@@ -74,11 +74,14 @@
NameMap& getNameMap() { return nameMap; }
TSymbolTable& getSymbolTable() { return symbolTable; }
ShShaderSpec getShaderSpec() const { return shaderSpec; }
+ std::string getBuiltInResourcesString() const { return builtInResourcesString; }
protected:
ShShaderType getShaderType() const { return shaderType; }
// Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
+ // Compute the string representation of the built-in resources
+ void setResourceString();
// Clears the results from the previous compilation.
void clearResults();
// Return true if function recursion is detected or call depth exceeded.
@@ -134,6 +137,7 @@
int maxCallStackDepth;
ShBuiltInResources compileResources;
+ std::string builtInResourcesString;
// Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile.
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index 75c97bd..07bd464 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -144,8 +144,25 @@
DeleteCompiler(base->getAsCompiler());
}
+void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outString)
+{
+ if (!handle || !outString)
+ {
+ return;
+ }
+
+ TShHandleBase *base = static_cast<TShHandleBase*>(handle);
+ TCompiler *compiler = base->getAsCompiler();
+ if (!compiler)
+ {
+ return;
+ }
+
+ strncpy(outString, compiler->getBuiltInResourcesString().c_str(), outStringLen);
+ outString[outStringLen - 1] = '\0';
+}
//
-// Do an actual compile on the given strings. The result is left
+// Do an actual compile on the given strings. The result is left
// in the given compile object.
//
// Return: The return value of ShCompile is really boolean, indicating
@@ -229,6 +246,9 @@
case SH_SHADER_VERSION:
*params = compiler->getShaderVersion();
break;
+ case SH_RESOURCES_STRING_LENGTH:
+ *params = compiler->getBuiltInResourcesString().length() + 1;
+ break;
default: UNREACHABLE();
}
}