From 16a9e233da9a4ce64c876e2e69a8e9bb96436ff3 Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Wed, 24 Jun 2020 15:58:44 -0400 Subject: [PATCH] freedreno/ir3: add support for load_draw_id This is part of adding VK_KHR_shader_draw_parameters for turnip. IR3_DP_VTXID_BASE/IR3_DP_VTXCNT_MAX offsets are changed to match what CP_DRAW_INDIRECT_MULTI requires. Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/ir3/ir3_compiler_nir.c | 6 ++++++ src/freedreno/ir3/ir3_context.h | 2 +- src/freedreno/ir3/ir3_nir.c | 6 +++++- src/freedreno/ir3/ir3_shader.h | 5 +++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index 3c8007f5da3..42dc672423c 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -1785,6 +1785,12 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr) } dst[0] = ctx->basevertex; break; + case nir_intrinsic_load_draw_id: + if (!ctx->draw_id) { + ctx->draw_id = create_driver_param(ctx, IR3_DP_DRAWID); + } + dst[0] = ctx->draw_id; + break; case nir_intrinsic_load_base_instance: if (!ctx->base_instance) { ctx->base_instance = create_driver_param(ctx, IR3_DP_INSTID_BASE); diff --git a/src/freedreno/ir3/ir3_context.h b/src/freedreno/ir3/ir3_context.h index 9cd147d9a6d..49b540fec17 100644 --- a/src/freedreno/ir3/ir3_context.h +++ b/src/freedreno/ir3/ir3_context.h @@ -83,7 +83,7 @@ struct ir3_context { struct ir3_instruction *frag_face, *frag_coord; /* For vertex shaders, keep track of the system values sources */ - struct ir3_instruction *vertex_id, *basevertex, *instance_id, *base_instance; + struct ir3_instruction *vertex_id, *basevertex, *instance_id, *base_instance, *draw_id; /* For fragment shaders: */ struct ir3_instruction *samp_id, *samp_mask_in; diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index 228cf0f72be..97b0d35d215 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -514,8 +514,12 @@ ir3_setup_const_state(nir_shader *nir, struct ir3_shader_variant *v, constoff += align(cnt, 4) / 4; } - if (const_state->num_driver_params > 0) + if (const_state->num_driver_params > 0) { + /* offset cannot be 0 for vs params loaded by CP_DRAW_INDIRECT_MULTI */ + if (v->type == MESA_SHADER_VERTEX && compiler->gpu_id >= 600) + constoff = MAX2(constoff, 1); const_state->offsets.driver_param = constoff; + } constoff += const_state->num_driver_params / 4; if ((v->type == MESA_SHADER_VERTEX) && diff --git a/src/freedreno/ir3/ir3_shader.h b/src/freedreno/ir3/ir3_shader.h index 3e7ee89debe..2529de73509 100644 --- a/src/freedreno/ir3/ir3_shader.h +++ b/src/freedreno/ir3/ir3_shader.h @@ -55,9 +55,10 @@ enum ir3_driver_param { IR3_DP_CS_COUNT = 8, /* must be aligned to vec4 */ /* vertex shader driver params: */ - IR3_DP_VTXID_BASE = 0, - IR3_DP_VTXCNT_MAX = 1, + IR3_DP_DRAWID = 0, + IR3_DP_VTXID_BASE = 1, IR3_DP_INSTID_BASE = 2, + IR3_DP_VTXCNT_MAX = 3, /* user-clip-plane components, up to 8x vec4's: */ IR3_DP_UCP0_X = 4, /* .... */ -- 2.30.2