radv/gfx10: Move NGG output handling outside of giant if-statement.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 7 Jul 2019 23:19:55 +0000 (01:19 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 7 Jul 2019 23:49:54 +0000 (01:49 +0200)
In merged shaders we put a big if around each shader, so both stages
can have a different number of threads. However, the NGG output code
still needs to run if the first shader is not executed.

This can happen when there are more gs threads than vs/es threads, or
when there are 0 es/vs threads (why? no clue).

Fixes: ee21bd7440c "radv/gfx10: implement NGG support (VS only)"
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_nir_to_llvm.c

index 51414be2304a9a298f678be276ea3f08f125c570..fb6b4bef584a7349364f11d90eae884157e338ad 100644 (file)
@@ -3647,10 +3647,10 @@ handle_shader_outputs_post(struct ac_shader_abi *abi, unsigned max_outputs,
        case MESA_SHADER_VERTEX:
                if (ctx->options->key.vs.out.as_ls)
                        handle_ls_outputs_post(ctx);
+               else if (ctx->options->key.vs.out.as_ngg)
+                       break; /* handled outside of the shader body */
                else if (ctx->options->key.vs.out.as_es)
                        handle_es_outputs_post(ctx, &ctx->shader_info->vs.es_info);
-               else if (ctx->options->key.vs.out.as_ngg)
-                       handle_ngg_outputs_post(ctx);
                else
                        handle_vs_outputs_post(ctx, ctx->options->key.vs.out.export_prim_id,
                                               ctx->options->key.vs.out.export_layer_id,
@@ -4023,6 +4023,14 @@ LLVMModuleRef ac_translate_nir_to_llvm(struct ac_llvm_compiler *ac_llvm,
                        LLVMPositionBuilderAtEnd(ctx.ac.builder, merge_block);
                }
 
+               /* This needs to be outside the if wrapping the shader body, as sometimes
+                * the HW generates waves with 0 es/vs threads. */
+               if (is_pre_gs_stage(shaders[i]->info.stage) &&
+                   ctx.options->key.vs.out.as_ngg &&
+                   i == shader_count - 1) {
+                       handle_ngg_outputs_post(&ctx);
+               }
+
                if (shaders[i]->info.stage == MESA_SHADER_GEOMETRY) {
                        shader_info->gs.gsvs_vertex_size = ctx.gsvs_vertex_size;
                        shader_info->gs.max_gsvs_emit_size = ctx.max_gsvs_emit_size;