From: Iago Toral Quiroga Date: Tue, 21 Jul 2020 08:01:34 +0000 (+0200) Subject: v3d/compiler: handle compact varyings X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=71d5c19241876e899d37dfe23efd25b23553d5e0;p=mesa.git v3d/compiler: handle compact varyings We are going to need this in Vulkan because the SPIR-V compiler defines clip distances as a single compact array of scalars, so our compiler needs to know what to do with them. Reviewed-by: Alejandro PiƱeiro Part-of: --- diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index 999c7eef3e2..fa4910fea3f 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -737,6 +737,19 @@ emit_fragment_input(struct v3d_compile *c, int attr, nir_variable *var, } } +static void +emit_compact_fragment_input(struct v3d_compile *c, int attr, nir_variable *var, + int array_index) +{ + /* Compact variables are scalar arrays where each set of 4 elements + * consumes a single location. + */ + int loc_offset = array_index / 4; + int chan = var->data.location_frac + array_index % 4; + c->inputs[(attr + loc_offset) * 4 + chan] = + emit_fragment_varying(c, var, chan, loc_offset); +} + static void add_output(struct v3d_compile *c, uint32_t decl_offset, @@ -1658,6 +1671,9 @@ ntq_setup_fs_inputs(struct v3d_compile *c) c->fs_key->point_sprite_mask)) { c->inputs[loc * 4 + 0] = c->point_x; c->inputs[loc * 4 + 1] = c->point_y; + } else if (var->data.compact) { + for (int j = 0; j < array_len; j++) + emit_compact_fragment_input(c, loc, var, j); } else { for (int j = 0; j < array_len; j++) emit_fragment_input(c, loc + j, var, j); diff --git a/src/broadcom/compiler/v3d_nir_lower_io.c b/src/broadcom/compiler/v3d_nir_lower_io.c index d35061d33a1..4b616b054a7 100644 --- a/src/broadcom/compiler/v3d_nir_lower_io.c +++ b/src/broadcom/compiler/v3d_nir_lower_io.c @@ -172,13 +172,14 @@ v3d_nir_lower_vpm_output(struct v3d_compile *c, nir_builder *b, int start_comp = nir_intrinsic_component(intr); nir_ssa_def *src = nir_ssa_for_src(b, intr->src[0], intr->num_components); - nir_variable *var = NULL; nir_foreach_variable(scan_var, &c->s->outputs) { + int components = scan_var->data.compact ? + glsl_get_length(scan_var->type) : + glsl_get_components(scan_var->type); if (scan_var->data.driver_location != nir_intrinsic_base(intr) || start_comp < scan_var->data.location_frac || - start_comp >= scan_var->data.location_frac + - glsl_get_components(scan_var->type)) { + start_comp >= scan_var->data.location_frac + components) { continue; } var = scan_var; @@ -253,6 +254,9 @@ v3d_nir_lower_vpm_output(struct v3d_compile *c, nir_builder *b, if (vpm_offset == -1) continue; + if (var->data.compact) + vpm_offset += nir_src_as_uint(intr->src[1]) * 4; + BITSET_SET(state->varyings_stored, vpm_offset); v3d_nir_store_output(b, state->varyings_vpm_offset + vpm_offset,