On 09/29/2015 05:38 PM, Iago Toral Quiroga wrote:
Since we store both in UniformBlocks, we can't just compute the index by
subtracting the array address start, we need to count the number of
buffers of the approriate type.
---
Or we can just fall back to calc_resource_index... that would also work.
This should be a bit faster though since it only traverses the list of
uniform blocks and the code is simple enough, but it probably won't make
a significant difference anyway.
This is correct but I'd vote for using calc_resource_index to reduce
special cases. Ideally in some point gl_program_resource starts to be
something more than pointer and then it helps to have generic code for
these things.
src/mesa/main/shader_query.cpp | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 0cada50..33c95b4 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -602,6 +602,22 @@ calc_resource_index(struct gl_shader_program *shProg,
return GL_INVALID_INDEX;
}
+static GLuint
+calc_ubo_ssbo_index(struct gl_shader_program *shProg,
+ struct gl_program_resource *res)
+{
+ unsigned i;
+ GLuint index = 0;
+ bool is_shader_storage = res->Type == GL_SHADER_STORAGE_BLOCK;
+ for (i = 0; i < shProg->NumBufferInterfaceBlocks; i++) {
+ if (&shProg->UniformBlocks[i] == RESOURCE_UBO(res))
+ return index;
+ if (shProg->UniformBlocks[i].IsShaderStorage == is_shader_storage)
+ index++;
+ }
+ return GL_INVALID_INDEX;
+}
+
/**
* Calculate index for the given resource.
*/
@@ -615,7 +631,7 @@ _mesa_program_resource_index(struct gl_shader_program
*shProg,
switch (res->Type) {
case GL_UNIFORM_BLOCK:
case GL_SHADER_STORAGE_BLOCK:
- return RESOURCE_UBO(res)- shProg->UniformBlocks;
+ return calc_ubo_ssbo_index(shProg, res);
case GL_ATOMIC_COUNTER_BUFFER:
return RESOURCE_ATC(res) - shProg->AtomicBuffers;
case GL_TRANSFORM_FEEDBACK_VARYING:
_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev