[Mesa-dev] [PATCH 20/28] nir/linker: fill up uniform_storage with explicit data

Alejandro PiƱeiro apinheiro at igalia.com
Mon Oct 22 12:24:42 UTC 2018


Specifically, offset, array_stride, matrix_stride and row_major.

On GLSL, most of that info is computed, but on ARB_gl_spirv they are
explicit, and for Mesa, included on the glsl_type.

>From ARB_gl_spirv spec:

   "Mapping of layouts

      std140/std430  ->  explicit *Offset*, *ArrayStride*, and *MatrixStride*
                         Decoration on struct members""

    "7.6.2.spv SPIR-V Uniform Offsets and Strides

    The SPIR-V decorations *GLSLShared* or *GLSLPacked* must not be used. A
    variable in the *Uniform* Storage Class decorated as a *Block* must be
    explicitly laid out using the *Offset*, *ArrayStride*, and *MatrixStride*
    decorations"

For offset, matrix_stride and row_major we needed to include the
parent and index_in_parent while processing the type, as
matrix_stride/row_major are maintained as fields of the parent type,
not on the type itself.
---
 src/compiler/glsl/gl_nir_link_uniforms.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c
index ac445c8560a..448f8277c16 100644
--- a/src/compiler/glsl/gl_nir_link_uniforms.c
+++ b/src/compiler/glsl/gl_nir_link_uniforms.c
@@ -282,6 +282,8 @@ nir_link_uniform(struct gl_context *ctx,
                  struct gl_program *stage_program,
                  gl_shader_stage stage,
                  const struct glsl_type *type,
+                 const struct glsl_type *parent_type,
+                 unsigned index_in_parent,
                  int location,
                  struct nir_link_uniforms_state *state)
 {
@@ -309,7 +311,7 @@ nir_link_uniform(struct gl_context *ctx,
             field_type = glsl_get_array_element(type);
 
          int entries = nir_link_uniform(ctx, prog, stage_program, stage,
-                                        field_type, location,
+                                        field_type, type, i, location,
                                         state);
          if (entries == -1)
             return -1;
@@ -352,9 +354,11 @@ nir_link_uniform(struct gl_context *ctx,
       if (glsl_type_is_array(type)) {
          uniform->type = type_no_array;
          uniform->array_elements = glsl_get_length(type);
+         uniform->array_stride = glsl_get_explicit_array_stride(type);
       } else {
          uniform->type = type;
          uniform->array_elements = 0;
+         uniform->array_stride = 0;
       }
       uniform->active_shader_mask |= 1 << stage;
 
@@ -371,15 +375,31 @@ nir_link_uniform(struct gl_context *ctx,
 
       uniform->is_shader_storage = nir_variable_is_in_ssbo(state->current_var);
 
+      if (nir_variable_is_in_block(state->current_var) &&
+          glsl_type_is_matrix(type)) {
+         assert(parent_type);
+
+         uniform->matrix_stride =
+            glsl_get_struct_field_explicit_matrix_stride(parent_type, index_in_parent);
+
+         uniform->row_major =
+            glsl_get_struct_field_matrix_layout(parent_type, index_in_parent) ==
+            GLSL_MATRIX_LAYOUT_ROW_MAJOR;
+      } else {
+         uniform->matrix_stride = 0;
+         uniform->row_major = false;
+      }
+
+      if (parent_type)
+         uniform->offset = glsl_get_struct_field_offset(parent_type, index_in_parent);
+      else
+         uniform->offset = 0;
+
       /* @FIXME: the initialization of the following will be done as we
        * implement support for their specific features, like SSBO, atomics,
        * etc.
        */
       uniform->block_index = -1;
-      uniform->offset = -1;
-      uniform->matrix_stride = -1;
-      uniform->array_stride = -1;
-      uniform->row_major = false;
       uniform->builtin = false;
       uniform->atomic_buffer_index = -1;
       uniform->top_level_array_size = 0;
@@ -543,6 +563,7 @@ gl_nir_link_uniforms(struct gl_context *ctx,
          state.current_type = type_tree;
 
          int res = nir_link_uniform(ctx, prog, sh->Program, shader_type, type,
+                                    NULL, 0,
                                     location, &state);
 
          free_type_tree(type_tree);
-- 
2.14.1



More information about the mesa-dev mailing list