turnip: fix a crash when rasterizerDiscardEnable is set
authorJonathan Marek <jonathan@marek.ca>
Wed, 17 Jun 2020 18:23:37 +0000 (14:23 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Jun 2020 03:15:26 +0000 (03:15 +0000)
pMultisampleState needs to be ignored when rasterizerDiscardEnable, so the
current code can crash when trying to load msaa_info->pNext.

At the same time this simplifies tu_pipeline_shader_key_init a bit, by not
calling it for the compute shader case (which doesn't need to set anything
in the key struct).

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5499>

src/freedreno/vulkan/tu_pipeline.c

index 418023eb4bf1a350484f4a58569e44a463982eea..f48958321d3416fab66d2690619947d6a95a6ba5 100644 (file)
@@ -1856,33 +1856,27 @@ static void
 tu_pipeline_shader_key_init(struct ir3_shader_key *key,
                             const VkGraphicsPipelineCreateInfo *pipeline_info)
 {
-   bool has_gs = false;
-   bool msaa = false;
-   if (pipeline_info) {
-      for (uint32_t i = 0; i < pipeline_info->stageCount; i++) {
-         if (pipeline_info->pStages[i].stage == VK_SHADER_STAGE_GEOMETRY_BIT) {
-            has_gs = true;
-            break;
-         }
+   for (uint32_t i = 0; i < pipeline_info->stageCount; i++) {
+      if (pipeline_info->pStages[i].stage == VK_SHADER_STAGE_GEOMETRY_BIT) {
+         key->has_gs = true;
+         break;
       }
+   }
 
-      const VkPipelineMultisampleStateCreateInfo *msaa_info = pipeline_info->pMultisampleState;
-      const struct VkPipelineSampleLocationsStateCreateInfoEXT *sample_locations =
-         vk_find_struct_const(msaa_info->pNext, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT);
-      if (!pipeline_info->pRasterizationState->rasterizerDiscardEnable &&
-          (msaa_info->rasterizationSamples > 1 ||
-          /* also set msaa key when sample location is not the default
-           * since this affects varying interpolation */
-           (sample_locations && sample_locations->sampleLocationsEnable))) {
-         msaa = true;
-      }
+   if (pipeline_info->pRasterizationState->rasterizerDiscardEnable)
+      return;
+
+   const VkPipelineMultisampleStateCreateInfo *msaa_info = pipeline_info->pMultisampleState;
+   const struct VkPipelineSampleLocationsStateCreateInfoEXT *sample_locations =
+      vk_find_struct_const(msaa_info->pNext, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT);
+   if (msaa_info->rasterizationSamples > 1 ||
+       /* also set msaa key when sample location is not the default
+        * since this affects varying interpolation */
+       (sample_locations && sample_locations->sampleLocationsEnable)) {
+      key->msaa = true;
    }
 
    /* TODO: Populate the remaining fields of ir3_shader_key. */
-   *key = (struct ir3_shader_key) {
-      .has_gs = has_gs,
-      .msaa = msaa,
-   };
 }
 
 static VkResult
@@ -1897,7 +1891,7 @@ tu_pipeline_builder_compile_shaders(struct tu_pipeline_builder *builder)
       stage_infos[stage] = &builder->create_info->pStages[i];
    }
 
-   struct ir3_shader_key key;
+   struct ir3_shader_key key = {};
    tu_pipeline_shader_key_init(&key, builder->create_info);
 
    for (gl_shader_stage stage = MESA_SHADER_VERTEX;
@@ -2512,8 +2506,7 @@ tu_compute_pipeline_create(VkDevice device,
 
    pipeline->layout = layout;
 
-   struct ir3_shader_key key;
-   tu_pipeline_shader_key_init(&key, NULL);
+   struct ir3_shader_key key = {};
 
    struct tu_shader *shader =
       tu_shader_create(dev, MESA_SHADER_COMPUTE, stage_info, layout, pAllocator);