freedreno/ir3: add support for load_draw_id
authorJonathan Marek <jonathan@marek.ca>
Wed, 24 Jun 2020 19:58:44 +0000 (15:58 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 25 Jun 2020 15:57:45 +0000 (15:57 +0000)
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 <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5635>

src/freedreno/ir3/ir3_compiler_nir.c
src/freedreno/ir3/ir3_context.h
src/freedreno/ir3/ir3_nir.c
src/freedreno/ir3/ir3_shader.h

index 3c8007f5da33425dd97d45c75572910c992bbc47..42dc672423ca7cb8b0cdc078ad527beef1818524 100644 (file)
@@ -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);
index 9cd147d9a6d89653618f8838987db3923281082b..49b540fec178989b756c70feadc989cb2633607e 100644 (file)
@@ -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;
index 228cf0f72be36c2fc118dba2f54d6c87ea0b90d0..97b0d35d215770526273b8f4a8e0e013dd375f70 100644 (file)
@@ -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) &&
index 3e7ee89debeeba9bd675691450a41ce6c4a923ed..2529de73509685dde277b3493f16c4ea9e0a9bed 100644 (file)
@@ -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,
        /* .... */