Add new shader inspection APIs.
Each new entry point corresponds to one of the variable types:
varyings, attributes, uniforms, output variables, and interface
blocks. They return a pointer to the vector with all of the
parsed variables, which then the app can copy to its own memory.
Currently we do not support the staticUse field in the HLSL
translator.
BUG=angle:466
Change-Id: I7dc09e761ab070feef5360ad27740110c44853b3
Reviewed-on: https://chromium-review.googlesource.com/208750
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/libGLESv2/Shader.cpp b/src/libGLESv2/Shader.cpp
index eda0298..1906657 100644
--- a/src/libGLESv2/Shader.cpp
+++ b/src/libGLESv2/Shader.cpp
@@ -22,6 +22,14 @@
void *Shader::mFragmentCompiler = NULL;
void *Shader::mVertexCompiler = NULL;
+template <typename VarT>
+const std::vector<VarT> *GetShaderVariables(const std::vector<VarT> *variableList)
+{
+ // TODO: handle staticUse. for now, assume all returned variables are active.
+ ASSERT(variableList);
+ return variableList;
+}
+
Shader::Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle)
: mHandle(handle), mRenderer(renderer), mResourceManager(manager)
{
@@ -241,8 +249,8 @@
{
if (!mHlsl.empty())
{
- std::vector<sh::Varying> *activeVaryings;
- ShGetInfoPointer(compiler, SH_ACTIVE_VARYINGS_ARRAY, reinterpret_cast<void**>(&activeVaryings));
+ const std::vector<sh::Varying> *activeVaryings = ShGetVaryings(compiler);
+ ASSERT(activeVaryings);
for (size_t varyingIndex = 0; varyingIndex < activeVaryings->size(); varyingIndex++)
{
@@ -373,11 +381,9 @@
mHlsl = outputHLSL;
#endif
- delete[] outputHLSL;
+ SafeDeleteArray(outputHLSL);
- void *activeUniforms;
- ShGetInfoPointer(compiler, SH_ACTIVE_UNIFORMS_ARRAY, &activeUniforms);
- mActiveUniforms = *(std::vector<sh::Uniform>*)activeUniforms;
+ mActiveUniforms = *GetShaderVariables(ShGetUniforms(compiler));
for (size_t uniformIndex = 0; uniformIndex < mActiveUniforms.size(); uniformIndex++)
{
@@ -391,9 +397,7 @@
mUniformRegisterMap[uniform.name] = index;
}
- void *activeInterfaceBlocks;
- ShGetInfoPointer(compiler, SH_ACTIVE_INTERFACE_BLOCKS_ARRAY, &activeInterfaceBlocks);
- mActiveInterfaceBlocks = *(std::vector<sh::InterfaceBlock>*)activeInterfaceBlocks;
+ mActiveInterfaceBlocks = *GetShaderVariables(ShGetInterfaceBlocks(compiler));
for (size_t blockIndex = 0; blockIndex < mActiveInterfaceBlocks.size(); blockIndex++)
{
@@ -524,9 +528,7 @@
const std::string &hlsl = getHLSL();
if (!hlsl.empty())
{
- void *activeAttributes;
- ShGetInfoPointer(mVertexCompiler, SH_ACTIVE_ATTRIBUTES_ARRAY, &activeAttributes);
- mActiveAttributes = *(std::vector<sh::Attribute>*)activeAttributes;
+ mActiveAttributes = *GetShaderVariables(ShGetAttributes(mVertexCompiler));
}
}
@@ -555,9 +557,7 @@
const std::string &hlsl = getHLSL();
if (!hlsl.empty())
{
- void *activeOutputVariables;
- ShGetInfoPointer(mFragmentCompiler, SH_ACTIVE_OUTPUT_VARIABLES_ARRAY, &activeOutputVariables);
- mActiveOutputVariables = *(std::vector<sh::Attribute>*)activeOutputVariables;
+ mActiveOutputVariables = *GetShaderVariables(ShGetOutputVariables(mFragmentCompiler));
}
}