Module: Mesa Branch: main Commit: 6915d1978aacc78414fea29bfffa3672318160fc URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6915d1978aacc78414fea29bfffa3672318160fc
Author: Mike Blumenkrantz <[email protected]> Date: Wed Aug 3 17:12:32 2022 -0400 tgsi_to_nir: handle compact arrays for clipdistance Reviewed-by: Emma Anholt <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17770> --- src/gallium/auxiliary/nir/tgsi_to_nir.c | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index 99898a7eae0..0521c24934e 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -85,6 +85,7 @@ struct ttn_compile { nir_variable *input_var_face; nir_variable *input_var_position; nir_variable *input_var_point; + nir_variable *clipdist; /* How many TGSI_FILE_IMMEDIATE vec4s have been parsed so far. */ unsigned next_imm; @@ -94,6 +95,7 @@ struct ttn_compile { bool cap_point_is_sysval; bool cap_samplers_as_deref; bool cap_integers; + bool cap_compact_arrays; }; #define ttn_swizzle(b, src, x, y, z, w) \ @@ -434,6 +436,12 @@ ttn_emit_declaration(struct ttn_compile *c) var->type = glsl_float_type(); } else if (var->data.location == VARYING_SLOT_LAYER) { var->type = glsl_int_type(); + } else if (c->cap_compact_arrays && + var->data.location == VARYING_SLOT_CLIP_DIST0) { + var->type = glsl_array_type(glsl_float_type(), + b->shader->info.clip_distance_array_size, + sizeof(float)); + c->clipdist = var; } } @@ -450,6 +458,11 @@ ttn_emit_declaration(struct ttn_compile *c) c->outputs[idx] = var; + if (c->cap_compact_arrays && var->data.location == VARYING_SLOT_CLIP_DIST1) { + /* ignore this entirely */ + continue; + } + for (int i = 0; i < array_size; i++) b->shader->info.outputs_written |= 1ull << (var->data.location + i); } @@ -2242,8 +2255,29 @@ ttn_add_output_stores(struct ttn_compile *c) } } - if (store_mask) + if (c->cap_compact_arrays && + (var->data.location == VARYING_SLOT_CLIP_DIST0 || + var->data.location == VARYING_SLOT_CLIP_DIST1)) { + if (!store_mask) + continue; + + nir_deref_instr *deref = nir_build_deref_var(b, c->clipdist); + nir_ssa_def *zero = nir_imm_zero(b, 1, 32); + unsigned offset = var->data.location == VARYING_SLOT_CLIP_DIST1 ? 4 : 0; + unsigned size = var->data.location == VARYING_SLOT_CLIP_DIST1 ? + b->shader->info.clip_distance_array_size : + MIN2(4, b->shader->info.clip_distance_array_size); + for (unsigned i = offset; i < size; i++) { + /* deref the array member and store each component */ + nir_deref_instr *component_deref = nir_build_deref_array_imm(b, deref, i); + nir_ssa_def *val = zero; + if (store_mask & BITFIELD_BIT(i - offset)) + val = nir_channel(b, store_value, i - offset); + nir_store_deref(b, component_deref, val, 0x1); + } + } else { nir_store_deref(b, nir_build_deref_var(b, var), store_value, store_mask); + } } } @@ -2290,6 +2324,7 @@ ttn_read_pipe_caps(struct ttn_compile *c, c->cap_position_is_sysval = screen->get_param(screen, PIPE_CAP_FS_POSITION_IS_SYSVAL); c->cap_point_is_sysval = screen->get_param(screen, PIPE_CAP_FS_POINT_IS_SYSVAL); c->cap_integers = screen->get_shader_param(screen, c->scan->processor, PIPE_SHADER_CAP_INTEGERS); + c->cap_compact_arrays = screen->get_param(screen, PIPE_CAP_NIR_COMPACT_ARRAYS); } #define BITSET_SET32(bitset, u32_mask) do { \
