[Mesa-dev,2/3] mesa: Map program UBOs and SSBOs to Interface Blocks

Submitted by Jordan Justen on Oct. 28, 2015, 5:38 a.m.

Details

Message ID 1446010703-2316-2-git-send-email-jordan.l.justen@intel.com
State Superseded
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Jordan Justen Oct. 28, 2015, 5:38 a.m.
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Cc: Iago Toral Quiroga <itoral@igalia.com>
---
 src/glsl/linker.cpp                 | 14 ++++++++++++++
 src/glsl/standalone_scaffolding.cpp |  5 +++++
 src/mesa/main/mtypes.h              |  7 +++++++
 3 files changed, 26 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 3db2fd3..d925393 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -4448,6 +4448,20 @@  link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
                         &prog->ShaderStorageBlocks,
                         &prog->NumShaderStorageBlocks);
 
+   prog->UboInterfaceBlockIndex =
+      ralloc_array(prog, int, prog->NumUniformBlocks);
+   prog->SsboInterfaceBlockIndex =
+      ralloc_array(prog, int, prog->NumShaderStorageBlocks);
+   for (unsigned i = 0, u = 0, s = 0;
+        i < prog->NumBufferInterfaceBlocks;
+        i++) {
+      if (prog->BufferInterfaceBlocks[i].IsShaderStorage) {
+         prog->SsboInterfaceBlockIndex[s++] = i;
+      } else {
+         prog->UboInterfaceBlockIndex[u++] = i;
+      }
+   }
+
    /* FINISHME: Assign fragment shader output locations. */
 
 done:
diff --git a/src/glsl/standalone_scaffolding.cpp b/src/glsl/standalone_scaffolding.cpp
index fe1d820..5c76295 100644
--- a/src/glsl/standalone_scaffolding.cpp
+++ b/src/glsl/standalone_scaffolding.cpp
@@ -124,6 +124,11 @@  _mesa_clear_shader_program_data(struct gl_shader_program *shProg)
       shProg->InterfaceBlockStageIndex[i] = NULL;
    }
 
+   ralloc_free(shProg->UboInterfaceBlockIndex);
+   shProg->UboInterfaceBlockIndex = NULL;
+   ralloc_free(shProg->SsboInterfaceBlockIndex);
+   shProg->SsboInterfaceBlockIndex = NULL;
+
    ralloc_free(shProg->AtomicBuffers);
    shProg->AtomicBuffers = NULL;
    shProg->NumAtomicBuffers = 0;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index cce959e..c1cbe96 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2725,6 +2725,13 @@  struct gl_shader_program
    int *InterfaceBlockStageIndex[MESA_SHADER_STAGES];
 
    /**
+    * Indices into the BufferInterfaceBlocks[] array for Uniform Buffer
+    * Objects and Shader Storage Buffer Objects.
+    */
+   int *UboInterfaceBlockIndex;
+   int *SsboInterfaceBlockIndex;
+
+   /**
     * Map of active uniform names to locations
     *
     * Maps any active uniform that is not an array element to a location.

Comments

On Tue, 2015-10-27 at 22:38 -0700, Jordan Justen wrote:
> Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
> Cc: Iago Toral Quiroga <itoral@igalia.com>
> ---
>  src/glsl/linker.cpp                 | 14 ++++++++++++++
>  src/glsl/standalone_scaffolding.cpp |  5 +++++
>  src/mesa/main/mtypes.h              |  7 +++++++
>  3 files changed, 26 insertions(+)
> 
> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
> index 3db2fd3..d925393 100644
> --- a/src/glsl/linker.cpp
> +++ b/src/glsl/linker.cpp
> @@ -4448,6 +4448,20 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
>                          &prog->ShaderStorageBlocks,
>                          &prog->NumShaderStorageBlocks);
>  
> +   prog->UboInterfaceBlockIndex =
> +      ralloc_array(prog, int, prog->NumUniformBlocks);
> +   prog->SsboInterfaceBlockIndex =
> +      ralloc_array(prog, int, prog->NumShaderStorageBlocks);
> +   for (unsigned i = 0, u = 0, s = 0;
> +        i < prog->NumBufferInterfaceBlocks;
> +        i++) {
> +      if (prog->BufferInterfaceBlocks[i].IsShaderStorage) {
> +         prog->SsboInterfaceBlockIndex[s++] = i;
> +      } else {
> +         prog->UboInterfaceBlockIndex[u++] = i;
> +      }
> +   }

This loop is pretty much the same we have in split_ubos_and_ssbos and
the functionality implements seems to belong in that function too, so
maybe it would be better if we merged this loop in that function. I am
thinking that we could pass two more arguments to split_ubos_and_ssbos
that would be NULL in the first call (the one we do in the loop for all
shader stages) and in the last call we do outside the loop for the
shader program, we pass &prog->UboInterfaceBlockIndex and
&prog->SsboInterfaceBlockIndex to get these setup.

What do you think?

>     /* FINISHME: Assign fragment shader output locations. */
>  
>  done:
> diff --git a/src/glsl/standalone_scaffolding.cpp b/src/glsl/standalone_scaffolding.cpp
> index fe1d820..5c76295 100644
> --- a/src/glsl/standalone_scaffolding.cpp
> +++ b/src/glsl/standalone_scaffolding.cpp
> @@ -124,6 +124,11 @@ _mesa_clear_shader_program_data(struct gl_shader_program *shProg)
>        shProg->InterfaceBlockStageIndex[i] = NULL;
>     }
>  
> +   ralloc_free(shProg->UboInterfaceBlockIndex);
> +   shProg->UboInterfaceBlockIndex = NULL;
> +   ralloc_free(shProg->SsboInterfaceBlockIndex);
> +   shProg->SsboInterfaceBlockIndex = NULL;
> +
>     ralloc_free(shProg->AtomicBuffers);
>     shProg->AtomicBuffers = NULL;
>     shProg->NumAtomicBuffers = 0;
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index cce959e..c1cbe96 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -2725,6 +2725,13 @@ struct gl_shader_program
>     int *InterfaceBlockStageIndex[MESA_SHADER_STAGES];
>  
>     /**
> +    * Indices into the BufferInterfaceBlocks[] array for Uniform Buffer
> +    * Objects and Shader Storage Buffer Objects.
> +    */
> +   int *UboInterfaceBlockIndex;
> +   int *SsboInterfaceBlockIndex;
> +
> +   /**
>      * Map of active uniform names to locations
>      *
>      * Maps any active uniform that is not an array element to a location.