draw/gs: don't crash when vs/gs signatures don't match
authorZack Rusin <zackr@vmware.com>
Thu, 2 May 2013 01:09:32 +0000 (21:09 -0400)
committerZack Rusin <zackr@vmware.com>
Thu, 2 May 2013 06:43:42 +0000 (02:43 -0400)
instead of crashing just fill zeros at the input slots that don't
match, that's the mandated behavior and it avoids debug asserts.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/draw/draw_gs.c

index fbb01b457d1081dea955010f37f870a80376cad7..fcd6e2ddfdb581262cf1bac39ecf150adc3d4ef1 100644 (file)
@@ -57,7 +57,6 @@ draw_gs_get_input_index(int semantic, int index,
           input_semantic_indices[i] == index)
          return i;
    }
-   debug_assert(0);
    return -1;
 }
 
@@ -154,29 +153,37 @@ static void tgsi_fetch_gs_input(struct draw_geometry_shader *shader,
                (float)shader->in_prim_idx;
          } else {
             vs_slot = draw_gs_get_input_index(
-                        shader->info.input_semantic_name[slot],
-                        shader->info.input_semantic_index[slot],
-                        shader->input_info);
+               shader->info.input_semantic_name[slot],
+               shader->info.input_semantic_index[slot],
+               shader->input_info);
+            if (vs_slot < 0) {
+               debug_printf("VS/GS signature mismatch!\n");
+               machine->Inputs[idx].xyzw[0].f[prim_idx] = 0;
+               machine->Inputs[idx].xyzw[1].f[prim_idx] = 0;
+               machine->Inputs[idx].xyzw[2].f[prim_idx] = 0;
+               machine->Inputs[idx].xyzw[3].f[prim_idx] = 0;
+            } else {
 #if DEBUG_INPUTS
-            debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n",
-                         slot, vs_slot, idx);
-            assert(!util_is_inf_or_nan(input[vs_slot][0]));
-            assert(!util_is_inf_or_nan(input[vs_slot][1]));
-            assert(!util_is_inf_or_nan(input[vs_slot][2]));
-            assert(!util_is_inf_or_nan(input[vs_slot][3]));
+               debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n",
+                            slot, vs_slot, idx);
+               assert(!util_is_inf_or_nan(input[vs_slot][0]));
+               assert(!util_is_inf_or_nan(input[vs_slot][1]));
+               assert(!util_is_inf_or_nan(input[vs_slot][2]));
+               assert(!util_is_inf_or_nan(input[vs_slot][3]));
 #endif
-            machine->Inputs[idx].xyzw[0].f[prim_idx] = input[vs_slot][0];
-            machine->Inputs[idx].xyzw[1].f[prim_idx] = input[vs_slot][1];
-            machine->Inputs[idx].xyzw[2].f[prim_idx] = input[vs_slot][2];
-            machine->Inputs[idx].xyzw[3].f[prim_idx] = input[vs_slot][3];
+               machine->Inputs[idx].xyzw[0].f[prim_idx] = input[vs_slot][0];
+               machine->Inputs[idx].xyzw[1].f[prim_idx] = input[vs_slot][1];
+               machine->Inputs[idx].xyzw[2].f[prim_idx] = input[vs_slot][2];
+               machine->Inputs[idx].xyzw[3].f[prim_idx] = input[vs_slot][3];
 #if DEBUG_INPUTS
-            debug_printf("\t\t%f %f %f %f\n",
-                         machine->Inputs[idx].xyzw[0].f[prim_idx],
-                         machine->Inputs[idx].xyzw[1].f[prim_idx],
-                         machine->Inputs[idx].xyzw[2].f[prim_idx],
-                         machine->Inputs[idx].xyzw[3].f[prim_idx]);
+               debug_printf("\t\t%f %f %f %f\n",
+                            machine->Inputs[idx].xyzw[0].f[prim_idx],
+                            machine->Inputs[idx].xyzw[1].f[prim_idx],
+                            machine->Inputs[idx].xyzw[2].f[prim_idx],
+                            machine->Inputs[idx].xyzw[3].f[prim_idx]);
 #endif
-            ++vs_slot;
+               ++vs_slot;
+            }
          }
       }
    }
@@ -241,29 +248,37 @@ llvm_fetch_gs_input(struct draw_geometry_shader *shader,
             /* skip. we handle system values through gallivm */
          } else {
             vs_slot = draw_gs_get_input_index(
-                        shader->info.input_semantic_name[slot],
-                        shader->info.input_semantic_index[slot],
-                        shader->input_info);
+               shader->info.input_semantic_name[slot],
+               shader->info.input_semantic_index[slot],
+               shader->input_info);
+            if (vs_slot < 0) {
+               debug_printf("VS/GS signature mismatch!\n");
+               (*input_data)[i][slot][0][prim_idx] = 0;
+               (*input_data)[i][slot][1][prim_idx] = 0;
+               (*input_data)[i][slot][2][prim_idx] = 0;
+               (*input_data)[i][slot][3][prim_idx] = 0;
+            } else {
 #if DEBUG_INPUTS
-            debug_printf("\tSlot = %d, vs_slot = %d, i = %d:\n",
-                         slot, vs_slot, i);
-            assert(!util_is_inf_or_nan(input[vs_slot][0]));
-            assert(!util_is_inf_or_nan(input[vs_slot][1]));
-            assert(!util_is_inf_or_nan(input[vs_slot][2]));
-            assert(!util_is_inf_or_nan(input[vs_slot][3]));
+               debug_printf("\tSlot = %d, vs_slot = %d, i = %d:\n",
+                            slot, vs_slot, i);
+               assert(!util_is_inf_or_nan(input[vs_slot][0]));
+               assert(!util_is_inf_or_nan(input[vs_slot][1]));
+               assert(!util_is_inf_or_nan(input[vs_slot][2]));
+               assert(!util_is_inf_or_nan(input[vs_slot][3]));
 #endif
-            (*input_data)[i][slot][0][prim_idx] = input[vs_slot][0];
-            (*input_data)[i][slot][1][prim_idx] = input[vs_slot][1];
-            (*input_data)[i][slot][2][prim_idx] = input[vs_slot][2];
-            (*input_data)[i][slot][3][prim_idx] = input[vs_slot][3];
+               (*input_data)[i][slot][0][prim_idx] = input[vs_slot][0];
+               (*input_data)[i][slot][1][prim_idx] = input[vs_slot][1];
+               (*input_data)[i][slot][2][prim_idx] = input[vs_slot][2];
+               (*input_data)[i][slot][3][prim_idx] = input[vs_slot][3];
 #if DEBUG_INPUTS
-            debug_printf("\t\t%f %f %f %f\n",
-                         (*input_data)[i][slot][0][prim_idx],
-                         (*input_data)[i][slot][1][prim_idx],
-                         (*input_data)[i][slot][2][prim_idx],
-                         (*input_data)[i][slot][3][prim_idx]);
+               debug_printf("\t\t%f %f %f %f\n",
+                            (*input_data)[i][slot][0][prim_idx],
+                            (*input_data)[i][slot][1][prim_idx],
+                            (*input_data)[i][slot][2][prim_idx],
+                            (*input_data)[i][slot][3][prim_idx]);
 #endif
-            ++vs_slot;
+               ++vs_slot;
+            }
          }
       }
    }