[Mesa-dev] [PATCH] main: Fix block index when mixing UBO and SSBO blocks
Iago Toral
itoral at igalia.com
Wed Sep 30 23:17:47 PDT 2015
On Thu, 2015-10-01 at 09:13 +0300, Tapani Pälli wrote:
>
> 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.
Sure, I'll send a v2. Thanks for looking into it Tapani.
Iago
>
> > 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:
> >
>
More information about the mesa-dev
mailing list