ac/nir: use shader_info pass to determine whether instance_id is used
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 26 Jun 2017 12:36:47 +0000 (14:36 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 31 Jul 2017 12:55:39 +0000 (14:55 +0200)
This improves the separation of ABI and NIR translation.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_nir_to_llvm.c
src/amd/common/ac_shader_info.c
src/amd/common/ac_shader_info.h

index ec8006889d0f469e5c7aa18aae2ed9d4e863c548..a57fb2fc6b983dce6ced0fa369ac7154d0f3096b 100644 (file)
@@ -4023,8 +4023,6 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
                break;
        case nir_intrinsic_load_instance_id:
                result = ctx->abi->instance_id;
-               ctx->nctx->shader_info->vs.vgpr_comp_cnt = MAX2(3,
-                                           ctx->nctx->shader_info->vs.vgpr_comp_cnt);
                break;
        case nir_intrinsic_load_num_work_groups:
                result = ctx->nctx->num_work_groups;
@@ -6229,6 +6227,11 @@ LLVMModuleRef ac_translate_nir_to_llvm(LLVMTargetMachineRef tm,
                ctx.gs_max_out_vertices = nir->info.gs.vertices_out;
        } else if (nir->stage == MESA_SHADER_TESS_EVAL) {
                ctx.tes_primitive_mode = nir->info.tess.primitive_mode;
+       } else if (nir->stage == MESA_SHADER_VERTEX) {
+               if (shader_info->info.vs.needs_instance_id) {
+                       ctx.shader_info->vs.vgpr_comp_cnt =
+                               MAX2(3, ctx.shader_info->vs.vgpr_comp_cnt);
+               }
        }
 
        ac_setup_rings(&ctx);
index 13d73df11f9d91a80c9cb73e29261985c2072d90..7d34535c1073ad12e43d27703bc0190f33c927de 100644 (file)
@@ -39,6 +39,9 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, struct ac_shader_info *info)
        case nir_intrinsic_load_draw_id:
                info->vs.needs_draw_id = true;
                break;
+       case nir_intrinsic_load_instance_id:
+               info->vs.needs_instance_id = true;
+               break;
        case nir_intrinsic_load_num_work_groups:
                info->cs.grid_components_used = instr->num_components;
                break;
index 5f03e79a83dd4e5f33ab0ece790c4d0aea794936..5bc16cc9d0276f073fd550371ed819172f708210 100644 (file)
@@ -33,6 +33,7 @@ struct ac_shader_info {
        struct {
                bool has_vertex_buffers; /* needs vertex buffers and base/start */
                bool needs_draw_id;
+               bool needs_instance_id;
        } vs;
        struct {
                bool needs_sample_positions;