v3d/compiler: handle compact varyings
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 21 Jul 2020 08:01:34 +0000 (10:01 +0200)
committerIago Toral Quiroga <itoral@igalia.com>
Mon, 27 Jul 2020 06:25:57 +0000 (08:25 +0200)
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 <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6022>

src/broadcom/compiler/nir_to_vir.c
src/broadcom/compiler/v3d_nir_lower_io.c

index 999c7eef3e21375e60b2b32e82065393721fe243..fa4910fea3fc0c60e65cc2f5ae2d3c675c748fc7 100644 (file)
@@ -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,
 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;
                                                        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);
                 } else {
                         for (int j = 0; j < array_len; j++)
                                 emit_fragment_input(c, loc + j, var, j);
index d35061d33a1128c0da63511258956bb13307ca9a..4b616b054a72f856aa6dad198af8db0b63a9a535 100644 (file)
@@ -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);
         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) {
         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 ||
                 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;
                         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 (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,
                 BITSET_SET(state->varyings_stored, vpm_offset);
 
                 v3d_nir_store_output(b, state->varyings_vpm_offset + vpm_offset,