radv: fixup tess eval shader when combined.
authorDave Airlie <airlied@redhat.com>
Fri, 20 Oct 2017 02:45:51 +0000 (03:45 +0100)
committerDave Airlie <airlied@redhat.com>
Fri, 20 Oct 2017 05:11:10 +0000 (06:11 +0100)
This fixes some access to the tess eval shader when it's combined
with geometry on gfx9.

This is a review of Bas's commit:
radv: Prevent crashing by accessing TES for VGT reuse depth.

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_pipeline.c

index cc1b9494fbaf46e4bc8ea3d128fcdf70a24be0e5..a62aa6ccb9c4a01eeb09da9e8915223ae3d6b674 100644 (file)
@@ -500,6 +500,11 @@ radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
                        return &pipeline->shaders[MESA_SHADER_TESS_CTRL]->info.user_sgprs_locs.shader_data[idx];
                if (pipeline->shaders[MESA_SHADER_GEOMETRY])
                        return &pipeline->shaders[MESA_SHADER_GEOMETRY]->info.user_sgprs_locs.shader_data[idx];
+       } else if (stage == MESA_SHADER_TESS_EVAL) {
+               if (pipeline->shaders[MESA_SHADER_TESS_EVAL])
+                       return &pipeline->shaders[MESA_SHADER_TESS_EVAL]->info.user_sgprs_locs.shader_data[idx];
+               if (pipeline->shaders[MESA_SHADER_GEOMETRY])
+                       return &pipeline->shaders[MESA_SHADER_GEOMETRY]->info.user_sgprs_locs.shader_data[idx];
        }
        return &pipeline->shaders[stage]->info.user_sgprs_locs.shader_data[idx];
 }
index fa87a458b0d7d82a58dba1b68d076debbe9e0846..21265c45df37b7f2c7e1b7e7ed5b407b8ccedd59 100644 (file)
@@ -1173,9 +1173,13 @@ calculate_gs_ring_sizes(struct radv_pipeline *pipeline)
        /* The maximum size is 63.999 MB per SE. */
        unsigned max_size = ((unsigned)(63.999 * 1024 * 1024) & ~255) * num_se;
        struct ac_shader_variant_info *gs_info = &pipeline->shaders[MESA_SHADER_GEOMETRY]->info;
-       struct ac_es_output_info *es_info = radv_pipeline_has_tess(pipeline) ?
-               &pipeline->shaders[MESA_SHADER_TESS_EVAL]->info.tes.es_info :
-               &pipeline->shaders[MESA_SHADER_VERTEX]->info.vs.es_info;
+       struct ac_es_output_info *es_info;
+       if (pipeline->device->physical_device->rad_info.chip_class >= GFX9) 
+               es_info = radv_pipeline_has_tess(pipeline) ? &gs_info->tes.es_info : &gs_info->vs.es_info;
+       else
+               es_info = radv_pipeline_has_tess(pipeline) ?
+                       &pipeline->shaders[MESA_SHADER_TESS_EVAL]->info.tes.es_info :
+                       &pipeline->shaders[MESA_SHADER_VERTEX]->info.vs.es_info;
 
        /* Calculate the minimum size. */
        unsigned min_esgs_ring_size = align(es_info->esgs_itemsize * gs_vertex_reuse *
@@ -1217,6 +1221,14 @@ radv_get_vertex_shader(struct radv_pipeline *pipeline)
        return pipeline->shaders[MESA_SHADER_GEOMETRY];
 }
 
+static struct radv_shader_variant *
+radv_get_tess_eval_shader(struct radv_pipeline *pipeline)
+{
+       if (pipeline->shaders[MESA_SHADER_TESS_EVAL])
+               return pipeline->shaders[MESA_SHADER_TESS_EVAL];
+       return pipeline->shaders[MESA_SHADER_GEOMETRY];
+}
+
 static void
 calculate_tess_state(struct radv_pipeline *pipeline,
                     const VkGraphicsPipelineCreateInfo *pCreateInfo)
@@ -1309,7 +1321,7 @@ calculate_tess_state(struct radv_pipeline *pipeline,
        tess->num_patches = num_patches;
        tess->num_tcs_input_cp = num_tcs_input_cp;
 
-       struct radv_shader_variant *tes = pipeline->shaders[MESA_SHADER_TESS_EVAL];
+       struct radv_shader_variant *tes = radv_get_tess_eval_shader(pipeline);
        unsigned type = 0, partitioning = 0, topology = 0, distribution_mode = 0;
 
        switch (tes->info.tes.primitive_mode) {
@@ -1961,7 +1973,7 @@ radv_pipeline_init(struct radv_pipeline *pipeline,
        if (radv_pipeline_has_tess(pipeline)) {
                /* SWITCH_ON_EOI must be set if PrimID is used. */
                if (pipeline->shaders[MESA_SHADER_TESS_CTRL]->info.tcs.uses_prim_id ||
-                   pipeline->shaders[MESA_SHADER_TESS_EVAL]->info.tes.uses_prim_id)
+                   radv_get_tess_eval_shader(pipeline)->info.tes.uses_prim_id)
                        pipeline->graphics.ia_switch_on_eoi = true;
        }
 
@@ -2044,7 +2056,7 @@ radv_pipeline_init(struct radv_pipeline *pipeline,
 
        pipeline->graphics.vtx_reuse_depth = 30;
        if (radv_pipeline_has_tess(pipeline) &&
-           pipeline->shaders[MESA_SHADER_TESS_EVAL]->info.tes.spacing == TESS_SPACING_FRACTIONAL_ODD) {
+           radv_get_tess_eval_shader(pipeline)->info.tes.spacing == TESS_SPACING_FRACTIONAL_ODD) {
                pipeline->graphics.vtx_reuse_depth = 14;
        }