[Mesa-dev] [PATCH 2/5] st/mesa: fix fragment shader output mapping

Nicolai Hähnle nhaehnle at gmail.com
Thu Oct 13 15:13:14 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Properly handle the case where there is a gap in the assigned output locations,
e.g. a fragment shader writes to color buffer 2 but not to color buffers 0 & 1.

Fixes GL45-CTS.gtf33.GL3Tests.explicit_attrib_location.explicit_attrib_location_pipeline.
---
 src/mesa/state_tracker/st_program.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 91887dc..7cc36b4 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -775,21 +775,20 @@ st_translate_fragment_program(struct st_context *st,
       }
       else {
          inputMapping[attr] = -1;
       }
    }
 
    /*
     * Semantics and mapping for outputs
     */
    {
-      uint numColors = 0;
       GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
 
       /* if z is written, emit that first */
       if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
          fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION;
          fs_output_semantic_index[fs_num_outputs] = 0;
          outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs;
          fs_num_outputs++;
          outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
       }
@@ -819,29 +818,39 @@ st_translate_fragment_program(struct st_context *st,
          if (written & BITFIELD64_BIT(loc)) {
             switch (loc) {
             case FRAG_RESULT_DEPTH:
             case FRAG_RESULT_STENCIL:
             case FRAG_RESULT_SAMPLE_MASK:
                /* handled above */
                assert(0);
                break;
             case FRAG_RESULT_COLOR:
                write_all = GL_TRUE; /* fallthrough */
-            default:
+            default: {
+               int index;
                assert(loc == FRAG_RESULT_COLOR ||
                       (FRAG_RESULT_DATA0 <= loc && loc < FRAG_RESULT_MAX));
+
+               index = (loc == FRAG_RESULT_COLOR) ? 0 : (loc - FRAG_RESULT_DATA0);
+
+               if (attr >= FRAG_RESULT_MAX) {
+                  /* Secondary color for dual source blending. */
+                  assert(index == 0);
+                  index++;
+               }
+
                fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
-               fs_output_semantic_index[fs_num_outputs] = numColors;
+               fs_output_semantic_index[fs_num_outputs] = index;
                outputMapping[attr] = fs_num_outputs;
-               numColors++;
                break;
             }
+            }
 
             fs_num_outputs++;
          }
       }
    }
 
    if (stfp->shader_program) {
       nir_shader *nir = st_glsl_to_nir(st, &stfp->Base.Base,
                                        stfp->shader_program,
                                        MESA_SHADER_FRAGMENT);
-- 
2.7.4



More information about the mesa-dev mailing list