[Mesa-dev] [PATCH] main: Fix block index when mixing UBO and SSBO blocks

Iago Toral Quiroga itoral at igalia.com
Tue Sep 29 07:38:18 PDT 2015


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.

 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:
-- 
1.9.1



More information about the mesa-dev mailing list