zink: rework tcs injection to be more compatible with new push const struct

we can simplify the push constant loader to directly take the struct member
index here and then pass that directly to simplify things for future use

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8971>
This commit is contained in:
Mike Blumenkrantz 2020-09-02 12:54:30 -04:00 committed by Marge Bot
parent 00642ab6ed
commit 59aae6db9f
2 changed files with 16 additions and 22 deletions

View file

@ -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]'

View file

@ -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);