st/mesa: fix fragment shader output mapping
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 13 Oct 2016 07:49:11 +0000 (09:49 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 17 Oct 2016 17:09:37 +0000 (19:09 +0200)
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.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_program.c

index 91887dc27db0b82f9432be9368d557c4b908a8fa..7cc36b4c9854e6959a8da61b1d50220ac4eee122 100644 (file)
@@ -782,7 +782,6 @@ st_translate_fragment_program(struct st_context *st,
     * Semantics and mapping for outputs
     */
    {
-      uint numColors = 0;
       GLbitfield64 outputsWritten = stfp->Base.Base.OutputsWritten;
 
       /* if z is written, emit that first */
@@ -826,15 +825,25 @@ st_translate_fragment_program(struct st_context *st,
                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++;
          }