[Mesa-dev] [PATCH 08/17] mesa: add uniform packing support to _mesa_add_typed_unnamed_constant()

Timothy Arceri tarceri at itsqueeze.com
Sun Jun 25 01:31:40 UTC 2017


---
 src/mesa/program/prog_parameter.c          | 53 +++++++++++++++++-------------
 src/mesa/program/prog_parameter.h          | 14 +++++---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |  5 +--
 3 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index a677493..7a5ccda 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -304,56 +304,65 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
  *    MOV r, { 0, 1, 2, 3 };
  * If swizzleOut is non-null we'll search the parameter list for an
  * existing instance of the constant which matches with a swizzle.
  *
  * \param paramList  the parameter list
  * \param values  four float values
  * \param swizzleOut  returns swizzle mask for accessing the constant
  * \return index/position of the new parameter in the parameter list.
  */
 GLint
-_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
-                           const gl_constant_value values[4], GLuint size,
-                           GLenum datatype, GLuint *swizzleOut)
+_mesa_add_typed_unnamed_constant(struct gl_context *ctx,
+                                 struct gl_program_parameter_list *paramList,
+                                 const gl_constant_value values[4],
+                                 GLuint size, GLenum datatype,
+                                 GLuint *swizzleOut)
 {
    GLint pos;
    assert(size >= 1);
    assert(size <= 4);
 
    if (swizzleOut &&
        lookup_parameter_constant(paramList, values, size, &pos, swizzleOut)) {
       return pos;
    }
 
-   /* Look for empty space in an already unnamed constant parameter
-    * to add this constant.  This will only work for single-element
-    * constants because we rely on smearing (i.e. .yyyy or .zzzz).
-    */
-   if (size == 1 && swizzleOut) {
-      for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) {
-         struct gl_program_parameter *p = paramList->Parameters + pos;
-         unsigned offset = paramList->ParameterValueOffset[pos];
-         if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) {
-            /* ok, found room */
-            gl_constant_value *pVal = paramList->ParameterValues + offset;
-            GLuint swz = p->Size; /* 1, 2 or 3 for Y, Z, W */
-            pVal[p->Size] = values[0];
-            p->Size++;
-            *swizzleOut = MAKE_SWIZZLE4(swz, swz, swz, swz);
-            return pos;
+   if (ctx->Const.PackedDriverUniformStorage) {
+      /* add a new parameter to store this constant */
+      pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
+                                size, datatype, values, NULL, false);
+   } else {
+      /* Look for empty space in an already unnamed constant parameter
+       * to add this constant.  This will only work for single-element
+       * constants because we rely on smearing (i.e. .yyyy or .zzzz).
+       */
+      if (size == 1 && swizzleOut) {
+         for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) {
+            struct gl_program_parameter *p = paramList->Parameters + pos;
+            unsigned offset = paramList->ParameterValueOffset[pos];
+            if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) {
+               /* ok, found room */
+               gl_constant_value *pVal = paramList->ParameterValues + offset;
+               GLuint swz = p->Size; /* 1, 2 or 3 for Y, Z, W */
+               pVal[p->Size] = values[0];
+               p->Size++;
+               *swizzleOut = MAKE_SWIZZLE4(swz, swz, swz, swz);
+               return pos;
+            }
          }
       }
+
+      /* add a new parameter to store this constant */
+      pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
+                                size, datatype, values, NULL, size < 4);
    }
 
-   /* add a new parameter to store this constant */
-   pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL,
-                             size, datatype, values, NULL, size < 4);
    if (pos >= 0 && swizzleOut) {
       if (size == 1)
          *swizzleOut = SWIZZLE_XXXX;
       else
          *swizzleOut = SWIZZLE_NOOP;
    }
    return pos;
 }
 
 
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index e5f3b39..39bf205 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -107,31 +107,35 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
 
 extern GLint
 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
                     gl_register_file type, const char *name,
                     GLuint size, GLenum datatype,
                     const gl_constant_value *values,
                     const gl_state_index state[STATE_LENGTH],
                     bool pad_and_align);
 
 extern GLint
-_mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
-                           const gl_constant_value values[4], GLuint size,
-                           GLenum datatype, GLuint *swizzleOut);
+_mesa_add_typed_unnamed_constant(struct gl_context *ctx,
+                                 struct gl_program_parameter_list *paramList,
+                                 const gl_constant_value values[4],
+                                 GLuint size, GLenum datatype,
+                                 GLuint *swizzleOut);
 
 static inline GLint
 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
                            const gl_constant_value values[4], GLuint size,
                            GLuint *swizzleOut)
 {
-   return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
-                                           swizzleOut);
+   GET_CURRENT_CONTEXT(ctx);
+
+   return _mesa_add_typed_unnamed_constant(ctx, paramList, values, size,
+                                           GL_NONE, swizzleOut);
 }
 
 extern GLint
 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
                           const gl_state_index stateTokens[STATE_LENGTH]);
 
 
 static inline GLint
 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
                              const char *name)
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 5c540c1..cf58212 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1119,22 +1119,23 @@ glsl_to_tgsi_visitor::emit_arl(ir_instruction *ir,
    emit_asm(NULL, op, dst, src0);
 }
 
 int
 glsl_to_tgsi_visitor::add_constant(gl_register_file file,
                                    gl_constant_value values[8], int size, int datatype,
                                    uint16_t *swizzle_out)
 {
    if (file == PROGRAM_CONSTANT) {
       GLuint swizzle = swizzle_out ? *swizzle_out : 0;
-      int result = _mesa_add_typed_unnamed_constant(this->prog->Parameters, values,
-                                                    size, datatype, &swizzle);
+      int result = _mesa_add_typed_unnamed_constant(ctx, prog->Parameters,
+                                                    values, size, datatype,
+                                                    &swizzle);
       if (swizzle_out)
          *swizzle_out = swizzle;
       return result;
    }
 
    assert(file == PROGRAM_IMMEDIATE);
 
    int index = 0;
    immediate_storage *entry;
    int size32 = size * ((datatype == GL_DOUBLE ||
-- 
2.9.4



More information about the mesa-dev mailing list