tgsi_to_nir: only update TGSI properties of the current shader stage
authorJose Maria Casanova Crespo <jmcasanova@igalia.com>
Mon, 19 Aug 2019 13:05:25 +0000 (15:05 +0200)
committerJosé Casanova Crespo <jmcasanova@igalia.com>
Tue, 20 Aug 2019 10:30:21 +0000 (10:30 +0000)
The implementation introduced in "tgsi_to_nir: be careful about not
losing any TGSI properties silently (v2)" updates all the TGSI properties,
but it didn't take into account that the shader_info structure uses a union
to store the different attributes for each shader stage.

Now we only update the attributes if they affect current shader stage,
avoiding to overwrite members of the union that should be overwritten.
This has created hundreds of regressions in v3d.

For example the TGSI_PROPERTY_VS_BLIT_SGPRS_AMD was overwritting the
same position used by TGSI_PROPERY_CS_FIXED_BLOCK_DEPTH.

Fixes: e3003651978 ("tgsi_to_nir: be careful about not losing any TGSI properties silently (v2)")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/nir/tgsi_to_nir.c

index 1fc886991f216b5823dd5eeeb360b3d908afb003..79d04fae9d9e929ceed6e721c2b34462df382ee7 100644 (file)
@@ -2464,34 +2464,43 @@ ttn_compile_init(const void *tgsi_tokens,
       case TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS:
          break; /* handled in ttn_emit_declaration */
       case TGSI_PROPERTY_FS_COORD_ORIGIN:
-         s->info.fs.origin_upper_left = value == TGSI_FS_COORD_ORIGIN_UPPER_LEFT;
+         if (s->info.stage == MESA_SHADER_FRAGMENT)
+            s->info.fs.origin_upper_left = value == TGSI_FS_COORD_ORIGIN_UPPER_LEFT;
          break;
       case TGSI_PROPERTY_FS_COORD_PIXEL_CENTER:
-         s->info.fs.pixel_center_integer = value == TGSI_FS_COORD_PIXEL_CENTER_INTEGER;
+         if (s->info.stage == MESA_SHADER_FRAGMENT)
+            s->info.fs.pixel_center_integer = value == TGSI_FS_COORD_PIXEL_CENTER_INTEGER;
          break;
       case TGSI_PROPERTY_FS_DEPTH_LAYOUT:
-         s->info.fs.depth_layout = ttn_get_depth_layout(value);
+         if (s->info.stage == MESA_SHADER_FRAGMENT)
+            s->info.fs.depth_layout = ttn_get_depth_layout(value);
          break;
       case TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION:
-         s->info.vs.window_space_position = value;
+         if (s->info.stage == MESA_SHADER_VERTEX)
+            s->info.vs.window_space_position = value;
          break;
       case TGSI_PROPERTY_NEXT_SHADER:
          s->info.next_stage = tgsi_processor_to_shader_stage(value);
          break;
       case TGSI_PROPERTY_VS_BLIT_SGPRS_AMD:
-         s->info.vs.blit_sgprs_amd = value;
+         if (s->info.stage == MESA_SHADER_VERTEX)
+            s->info.vs.blit_sgprs_amd = value;
          break;
       case TGSI_PROPERTY_CS_FIXED_BLOCK_WIDTH:
-         s->info.cs.local_size[0] = value;
+         if (s->info.stage == MESA_SHADER_COMPUTE)
+            s->info.cs.local_size[0] = value;
          break;
       case TGSI_PROPERTY_CS_FIXED_BLOCK_HEIGHT:
-         s->info.cs.local_size[1] = value;
+         if (s->info.stage == MESA_SHADER_COMPUTE)
+            s->info.cs.local_size[1] = value;
          break;
       case TGSI_PROPERTY_CS_FIXED_BLOCK_DEPTH:
-         s->info.cs.local_size[2] = value;
+         if (s->info.stage == MESA_SHADER_COMPUTE)
+            s->info.cs.local_size[2] = value;
          break;
       case TGSI_PROPERTY_CS_USER_DATA_COMPONENTS_AMD:
-         s->info.cs.user_data_components_amd = value;
+         if (s->info.stage == MESA_SHADER_COMPUTE)
+            s->info.cs.user_data_components_amd = value;
          break;
       default:
          if (value) {