diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index e102e28e39c..271f22eacfd 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -2161,7 +2161,6 @@ emit_store_shared(struct ntv_context *ctx, nir_intrinsic_instr *intr) } } -/* FIXME: this is currently VERY specific to injected TCS usage */ static void emit_load_push_const(struct ntv_context *ctx, nir_intrinsic_instr *intr) { @@ -2179,8 +2178,6 @@ emit_load_push_const(struct ntv_context *ctx, nir_intrinsic_instr *intr) /* destination type for the load */ SpvId type = get_dest_uvec_type(ctx, &intr->dest); - /* an id of an array member in bytes */ - SpvId uint_size = emit_uint_const(ctx, 32, sizeof(uint32_t)); SpvId one = emit_uint_const(ctx, 32, 1); /* we grab a single array member at a time, so it's a pointer to a uint */ @@ -2188,12 +2185,9 @@ emit_load_push_const(struct ntv_context *ctx, nir_intrinsic_instr *intr) SpvStorageClassPushConstant, load_type); - SpvId member = emit_uint_const(ctx, 32, 0); - /* this is the offset (in bytes) that we're accessing: - * it may be a const value or it may be dynamic in the shader - */ - SpvId offset = get_src(ctx, &intr->src[0]); - offset = emit_binop(ctx, SpvOpUDiv, uint_type, offset, uint_size); + SpvId member = get_src(ctx, &intr->src[0]); + /* reuse the offset from ZINK_PUSH_CONST_OFFSET */ + SpvId offset = emit_uint_const(ctx, 32, 0); /* OpAccessChain takes an array of indices that drill into a hierarchy based on the type: * index 0 is accessing 'base' * index 1 is accessing 'base[index 1]' diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 9af61879137..caff88a2c67 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -646,23 +646,23 @@ zink_shader_tcs_create(struct zink_context *ctx, struct zink_shader *vs) gl_TessLevelOuter->data.patch = 1; /* hacks so we can size these right for now */ - struct glsl_struct_field *fields = ralloc_size(nir, 2 * sizeof(struct glsl_struct_field)); - fields[0].type = glsl_array_type(glsl_uint_type(), 2, 0); - fields[0].name = ralloc_asprintf(nir, "gl_TessLevelInner"); + struct glsl_struct_field *fields = rzalloc_array(nir, struct glsl_struct_field, 3); + /* just use a single blob for padding here because it's easier */ + fields[0].type = glsl_array_type(glsl_uint_type(), offsetof(struct zink_push_constant, default_inner_level) / 4, 0); + fields[0].name = ralloc_asprintf(nir, "padding"); fields[0].offset = 0; - fields[1].type = glsl_array_type(glsl_uint_type(), 4, 0); - fields[1].name = ralloc_asprintf(nir, "gl_TessLevelOuter"); - fields[1].offset = 8; + fields[1].type = glsl_array_type(glsl_uint_type(), 2, 0); + fields[1].name = ralloc_asprintf(nir, "gl_TessLevelInner"); + fields[1].offset = offsetof(struct zink_push_constant, default_inner_level); + fields[2].type = glsl_array_type(glsl_uint_type(), 4, 0); + fields[2].name = ralloc_asprintf(nir, "gl_TessLevelOuter"); + fields[2].offset = offsetof(struct zink_push_constant, default_outer_level); nir_variable *pushconst = nir_variable_create(nir, nir_var_mem_push_const, - glsl_struct_type(fields, 2, "struct", false), "pushconst"); + glsl_struct_type(fields, 3, "struct", false), "pushconst"); pushconst->data.location = VARYING_SLOT_VAR0; - nir_ssa_def *load_inner = nir_load_push_constant(&b, 2, 32, - nir_imm_int(&b, offsetof(struct zink_push_constant, default_inner_level)), - .base = offsetof(struct zink_push_constant, default_inner_level), .range = 8); - nir_ssa_def *load_outer = nir_load_push_constant(&b, 4, 32, - nir_imm_int(&b, offsetof(struct zink_push_constant, default_outer_level)), - .base = offsetof(struct zink_push_constant, default_outer_level), .range = 16); + nir_ssa_def *load_inner = nir_load_push_constant(&b, 2, 32, nir_imm_int(&b, 1), .base = 1, .range = 8); + nir_ssa_def *load_outer = nir_load_push_constant(&b, 4, 32, nir_imm_int(&b, 2), .base = 2, .range = 16); for (unsigned i = 0; i < 2; i++) { nir_deref_instr *store_idx = nir_build_deref_array_imm(&b, nir_build_deref_var(&b, gl_TessLevelInner), i);