[Mesa-dev] [PATCH 10/17] mesa/st: set correct constant buffer index when uniform packing enabled

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


---
 src/mesa/state_tracker/st_atifs_to_tgsi.c  |  7 +++++--
 src/mesa/state_tracker/st_atifs_to_tgsi.h  |  1 +
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 13 ++++++++-----
 src/mesa/state_tracker/st_mesa_to_tgsi.c   |  5 +++--
 src/mesa/state_tracker/st_program.c        |  2 +-
 5 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/mesa/state_tracker/st_atifs_to_tgsi.c b/src/mesa/state_tracker/st_atifs_to_tgsi.c
index 34d4378..3b8975f 100644
--- a/src/mesa/state_tracker/st_atifs_to_tgsi.c
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
@@ -414,20 +414,21 @@ finalize_shader(struct st_translate *t, unsigned numPasses)
    /* signal the end of the program */
    ureg_insn(t->ureg, TGSI_OPCODE_END, dst, 0, src, 0);
 }
 
 /**
  * Called when a new variant is needed, we need to translate
  * the ATI fragment shader to TGSI
  */
 enum pipe_error
 st_translate_atifs_program(
+   struct gl_context *ctx,
    struct ureg_program *ureg,
    struct ati_fragment_shader *atifs,
    struct gl_program *program,
    GLuint numInputs,
    const ubyte inputMapping[],
    const ubyte inputSemanticName[],
    const ubyte inputSemanticIndex[],
    const ubyte interpMode[],
    GLuint numOutputs,
    const ubyte outputMapping[],
@@ -474,23 +475,25 @@ st_translate_atifs_program(
       if (t->constants == NULL) {
          ret = PIPE_ERROR_OUT_OF_MEMORY;
          goto out;
       }
 
       for (i = 0; i < program->Parameters->NumParameters; i++) {
          unsigned pvo = program->Parameters->ParameterValueOffset[i];
 
          switch (program->Parameters->Parameters[i].Type) {
          case PROGRAM_STATE_VAR:
-         case PROGRAM_UNIFORM:
-            t->constants[i] = ureg_DECL_constant(ureg, i);
+         case PROGRAM_UNIFORM: {
+            unsigned idx = ctx->Const.PackedDriverUniformStorage ? pvo : i;
+            t->constants[i] = ureg_DECL_constant(ureg, idx);
             break;
+         }
          case PROGRAM_CONSTANT:
             t->constants[i] =
                ureg_DECL_immediate(ureg,
                                    (const float*)program->Parameters->ParameterValues + pvo,
                                    4);
             break;
          default:
             break;
          }
       }
diff --git a/src/mesa/state_tracker/st_atifs_to_tgsi.h b/src/mesa/state_tracker/st_atifs_to_tgsi.h
index ce54791..50b069c 100644
--- a/src/mesa/state_tracker/st_atifs_to_tgsi.h
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.h
@@ -32,20 +32,21 @@ extern "C" {
 
 struct gl_context;
 struct gl_program;
 struct ureg_program;
 struct tgsi_token;
 struct ati_fragment_shader;
 struct st_fp_variant_key;
 
 enum pipe_error
 st_translate_atifs_program(
+    struct gl_context *ctx,
     struct ureg_program *ureg,
     struct ati_fragment_shader *atifs,
     struct gl_program *program,
     GLuint numInputs,
     const ubyte inputMapping[],
     const ubyte inputSemanticName[],
     const ubyte inputSemanticIndex[],
     const ubyte interpMode[],
     GLuint numOutputs,
     const ubyte outputMapping[],
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 0535ae1..dbb01b5 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6633,36 +6633,37 @@ st_translate_program(
       t->constants = (struct ureg_src *)
          calloc(proginfo->Parameters->NumParameters, sizeof(t->constants[0]));
       if (t->constants == NULL) {
          ret = PIPE_ERROR_OUT_OF_MEMORY;
          goto out;
       }
       t->num_constants = proginfo->Parameters->NumParameters;
 
       for (i = 0; i < proginfo->Parameters->NumParameters; i++) {
          unsigned pvo = proginfo->Parameters->ParameterValueOffset[i];
+         unsigned idx = ctx->Const.PackedDriverUniformStorage ? pvo : i;
 
          switch (proginfo->Parameters->Parameters[i].Type) {
          case PROGRAM_STATE_VAR:
          case PROGRAM_UNIFORM:
-            t->constants[i] = ureg_DECL_constant(ureg, i);
+            t->constants[i] = ureg_DECL_constant(ureg, idx);
             break;
 
          /* Emit immediates for PROGRAM_CONSTANT only when there's no indirect
           * addressing of the const buffer.
           * FIXME: Be smarter and recognize param arrays:
           * indirect addressing is only valid within the referenced
           * array.
           */
          case PROGRAM_CONSTANT:
             if (program->indirect_addr_consts)
-               t->constants[i] = ureg_DECL_constant(ureg, i);
+               t->constants[i] = ureg_DECL_constant(ureg, idx);
             else
                t->constants[i] = emit_immediate(t,
                                                 proginfo->Parameters->ParameterValues + pvo,
                                                 proginfo->Parameters->Parameters[i].DataType,
                                                 proginfo->Parameters->Parameters[i].Size);
             break;
          default:
             break;
          }
       }
@@ -6919,23 +6920,25 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    ralloc_free(shader->ir);
    shader->ir = NULL;
 
    /* This must be done before the uniform storage is associated. */
    if (shader->Stage == MESA_SHADER_FRAGMENT &&
        (prog->info.inputs_read & VARYING_BIT_POS ||
         prog->info.system_values_read & (1 << SYSTEM_VALUE_FRAG_COORD))) {
       static const gl_state_index wposTransformState[STATE_LENGTH] = {
          STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM
       };
-
-      v->wpos_transform_const = _mesa_add_state_reference(prog->Parameters,
-                                                          wposTransformState);
+      unsigned idx = _mesa_add_state_reference(prog->Parameters,
+                                               wposTransformState);
+      idx = ctx->Const.PackedDriverUniformStorage ?
+         prog->Parameters->ParameterValueOffset[idx] : idx;
+      v->wpos_transform_const = idx;
    }
 
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
    _mesa_reserve_parameter_storage(prog->Parameters, 8);
 
    /* This has to be done last.  Any operation the can cause
     * prog->ParameterValues to get reallocated (e.g., anything that adds a
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 30dc5cb..83dbabd 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -992,36 +992,37 @@ st_translate_mesa_program(
    if (program->Parameters) {
       t->constants = calloc( program->Parameters->NumParameters,
                              sizeof t->constants[0] );
       if (t->constants == NULL) {
          ret = PIPE_ERROR_OUT_OF_MEMORY;
          goto out;
       }
 
       for (i = 0; i < program->Parameters->NumParameters; i++) {
          unsigned pvo = program->Parameters->ParameterValueOffset[i];
+         unsigned idx = ctx->Const.PackedDriverUniformStorage ? pvo : i;
 
          switch (program->Parameters->Parameters[i].Type) {
          case PROGRAM_STATE_VAR:
          case PROGRAM_UNIFORM:
-            t->constants[i] = ureg_DECL_constant( ureg, i );
+            t->constants[i] = ureg_DECL_constant(ureg, idx);
             break;
 
             /* Emit immediates only when there's no indirect addressing of
              * the const buffer.
              * FIXME: Be smarter and recognize param arrays:
              * indirect addressing is only valid within the referenced
              * array.
              */
          case PROGRAM_CONSTANT:
             if (program->arb.IndirectRegisterFiles & PROGRAM_ANY_CONST)
-               t->constants[i] = ureg_DECL_constant( ureg, i );
+               t->constants[i] = ureg_DECL_constant(ureg, idx);
             else
                t->constants[i] = 
                   ureg_DECL_immediate(ureg,
                                       (const float*) program->Parameters->ParameterValues + pvo,
                                       program->Parameters->Parameters[i].Size);
             break;
          default:
             break;
          }
       }
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 6de6174..83248be 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1027,21 +1027,21 @@ st_translate_fragment_program(struct st_context *st,
                            input_semantic_index,
                            interpMode,
                            /* outputs */
                            fs_num_outputs,
                            outputMapping,
                            fs_output_semantic_name,
                            fs_output_semantic_index);
 
       free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
    } else if (stfp->ati_fs)
-      st_translate_atifs_program(ureg,
+      st_translate_atifs_program(st->ctx, ureg,
                                  stfp->ati_fs,
                                  &stfp->Base,
                                  /* inputs */
                                  fs_num_inputs,
                                  inputMapping,
                                  input_semantic_name,
                                  input_semantic_index,
                                  interpMode,
                                  /* outputs */
                                  fs_num_outputs,
-- 
2.9.4



More information about the mesa-dev mailing list