draw: handle more TGSI_SEMANTIC_COLOR indices
authorRoland Scheidegger <sroland@vmware.com>
Fri, 7 Jul 2017 22:14:35 +0000 (00:14 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Sat, 8 Jul 2017 04:02:18 +0000 (06:02 +0200)
It could only handle indices 0/1, otherwise what happened was bad (accessing
array out of bounds, no crash but kind of random). This is enough for the gl
state tracker (primary/secondary color) but not enough for some other state
trackers (d3d9 has no limits on the number of color interpolants).
The complexity with color semantics are all due to the front/back mapping (2
outputs in the vs map to one input in the fs) so this isn't extended to
indices > 1 - d3d9 has no use for back colors, therefore this isn't needed and
still only 2 back colors can be handled correctly.

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/auxiliary/draw/draw_pipe_clip.c
src/gallium/auxiliary/draw/draw_pipe_flatshade.c
src/gallium/auxiliary/draw/draw_pipe_twoside.c

index cf2b41738bf3a74387ad465b5adc95b46ed2d6fe..4cfa54b2e17535187e5b3ce34bdd7f96de4ff501 100644 (file)
@@ -771,8 +771,9 @@ find_interp(const struct draw_fragment_shader *fs, int *indexed_interp,
    int interp;
    /* If it's gl_{Front,Back}{,Secondary}Color, pick up the mode
     * from the array we've filled before. */
-   if (semantic_name == TGSI_SEMANTIC_COLOR ||
-       semantic_name == TGSI_SEMANTIC_BCOLOR) {
+   if ((semantic_name == TGSI_SEMANTIC_COLOR ||
+        semantic_name == TGSI_SEMANTIC_BCOLOR) &&
+       semantic_index < 2) {
       interp = indexed_interp[semantic_index];
    } else if (semantic_name == TGSI_SEMANTIC_POSITION ||
               semantic_name == TGSI_SEMANTIC_CLIPVERTEX) {
@@ -851,7 +852,8 @@ clip_init_state(struct draw_stage *stage)
 
    if (fs) {
       for (i = 0; i < fs->info.num_inputs; i++) {
-         if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR) {
+         if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR &&
+             fs->info.input_semantic_index[i] < 2) {
             if (fs->info.input_interpolate[i] != TGSI_INTERPOLATE_COLOR)
                indexed_interp[fs->info.input_semantic_index[i]] = fs->info.input_interpolate[i];
          }
@@ -881,6 +883,15 @@ clip_init_state(struct draw_stage *stage)
          clipper->perspect_attribs[clipper->num_perspect_attribs] = i;
          clipper->num_perspect_attribs++;
          break;
+      case TGSI_INTERPOLATE_COLOR:
+         if (draw->rasterizer->flatshade) {
+            clipper->const_attribs[clipper->num_const_attribs] = i;
+            clipper->num_const_attribs++;
+         } else {
+            clipper->perspect_attribs[clipper->num_perspect_attribs] = i;
+            clipper->num_perspect_attribs++;
+         }
+         break;
       default:
          assert(interp == -1);
          break;
index cd285e6f97c6cc564b33a0f7e0f2bc9040691816..2830435b99323c5b966da4065e37104206984f2a 100644 (file)
@@ -170,8 +170,9 @@ find_interp(const struct draw_fragment_shader *fs, int *indexed_interp,
    int interp;
    /* If it's gl_{Front,Back}{,Secondary}Color, pick up the mode
     * from the array we've filled before. */
-   if (semantic_name == TGSI_SEMANTIC_COLOR ||
-       semantic_name == TGSI_SEMANTIC_BCOLOR) {
+   if ((semantic_name == TGSI_SEMANTIC_COLOR ||
+        semantic_name == TGSI_SEMANTIC_BCOLOR) &&
+       semantic_index < 2) {
       interp = indexed_interp[semantic_index];
    } else {
       /* Otherwise, search in the FS inputs, with a decent default
@@ -216,7 +217,8 @@ static void flatshade_init_state( struct draw_stage *stage )
 
    if (fs) {
       for (i = 0; i < fs->info.num_inputs; i++) {
-         if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR) {
+         if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR &&
+             fs->info.input_semantic_index[i] < 2) {
             if (fs->info.input_interpolate[i] != TGSI_INTERPOLATE_COLOR)
                indexed_interp[fs->info.input_semantic_index[i]] = fs->info.input_interpolate[i];
          }
@@ -236,7 +238,8 @@ static void flatshade_init_state( struct draw_stage *stage )
                                info->output_semantic_index[i]);
       /* If it's flat, add it to the flat vector. */
 
-      if (interp == TGSI_INTERPOLATE_CONSTANT) {
+      if (interp == TGSI_INTERPOLATE_CONSTANT ||
+          (interp == TGSI_INTERPOLATE_COLOR && draw->rasterizer->flatshade)) {
          flat->flat_attribs[flat->num_flat_attribs] = i;
          flat->num_flat_attribs++;
       }
index 52d87c6b2917bc79ab14a460f188fd2f65098eda..7e76835f12e8f82dea0a13eb78a2ca69cf031748 100644 (file)
@@ -111,18 +111,21 @@ static void twoside_first_tri( struct draw_stage *stage,
    twoside->attrib_back0 = -1;
    twoside->attrib_back1 = -1;
 
-   /* Find which vertex shader outputs are front/back colors */
+   /*
+    * Find which vertex shader outputs are front/back colors
+    * (only first two can be front or back).
+    */
    for (i = 0; i < vs->info.num_outputs; i++) {
       if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR) {
          if (vs->info.output_semantic_index[i] == 0)
             twoside->attrib_front0 = i;
-         else
+         else if (vs->info.output_semantic_index[i] == 1)
             twoside->attrib_front1 = i;
       }
       if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) {
          if (vs->info.output_semantic_index[i] == 0)
             twoside->attrib_back0 = i;
-         else
+         else if (vs->info.output_semantic_index[i] == 1)
             twoside->attrib_back1 = i;
       }
    }