broadcom/vc5: Emit flat shade flags for varying components > 24.
authorEric Anholt <eric@anholt.net>
Wed, 27 Dec 2017 23:38:57 +0000 (15:38 -0800)
committerEric Anholt <eric@anholt.net>
Wed, 3 Jan 2018 22:25:23 +0000 (14:25 -0800)
This means that with no flatshading we'll emit the single-byte
ZERO_ALL_FLAT_SHADE_FLAGS, and otherwise emit a set of FLAT_SHADE_FLAGS to
get all the bits we need set.

There's a _SET enum in the packet we could use to possibly set entire
ranges of the bitfield without using another packet, but this at least
fixes the conformance failure.

src/broadcom/cle/v3d_packet_v33.xml
src/broadcom/compiler/v3d_compiler.h
src/broadcom/compiler/vir.c
src/gallium/drivers/vc5/vc5_emit.c

index 0402484dd71f5f8c5a456c6ae0cae4cb5b86fd48..6ec5332aeb7152d8cf01d6a4e9ed03d758f119e9 100644 (file)
     <value name="ANISOTROPIC_16_1" value="15"/>
   </enum>
 
+  <enum name="Flat Shade Action" prefix="V3D_FLAT_SHADE_ACTION">
+    <value name="unchanged" value="0"/>
+    <value name="zeroed" value="1"/>
+    <value name="set" value="2"/>
+  </enum>
+
   <packet code="0" name="Halt"/>
   <packet code="1" name="NOP"/>
   <packet code="4" name="Flush"/>
 
   <packet code="98" name="Flat Shade Flags">
     <field name="Flat Shade Flags for varyings V0*24" size="24" start="8" type="uint"/>
-    <field name="Action for Flat Shade Flags of higher numbered varyings" size="2" start="6" type="uint"/>
-    <field name="Action for Flat Shade Flags of lower numbered varyings" size="2" start="4" type="uint"/>
+    <field name="Action for Flat Shade Flags of higher numbered varyings" size="2" start="6" type="Flat Shade Action"/>
+    <field name="Action for Flat Shade Flags of lower numbered varyings" size="2" start="4" type="Flat Shade Action"/>
     <field name="Varying offset V0" size="4" start="0" type="uint"/>
   </packet>
 
index 99d58e73ae8f6126f71197125b83bbdaab29135a..85def2cb02c54635de56b2b9ff04842f30a83738 100644 (file)
@@ -421,7 +421,7 @@ struct v3d_compile {
          * flat-shaded.  This includes gl_FragColor flat-shading, which is
          * customized based on the shademodel_flat shader key.
          */
-        BITSET_WORD flat_shade_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
+        uint32_t flat_shade_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
 
         struct v3d_ubo_range *ubo_ranges;
         bool *ubo_range_used;
@@ -569,9 +569,12 @@ struct v3d_fs_prog_data {
 
         struct v3d_varying_slot input_slots[V3D_MAX_FS_INPUTS];
 
-        /* Bitmask for whether the corresponding input is flat-shaded.
+        /* Array of flat shade flags.
+         *
+         * Each entry is only 24 bits (high 8 bits 0), to match the hardware
+         * packet layout.
          */
-        BITSET_WORD flat_shade_flags[BITSET_WORDS(V3D_MAX_FS_INPUTS)];
+        uint32_t flat_shade_flags[((V3D_MAX_FS_INPUTS - 1) / 24) + 1];
 
         bool writes_z;
         bool discard;
index 2589c7f554d273c7d9661ca676918fc9f4e445e2..4e78a477bd7d430cc86b24304125056f094dc4b3 100644 (file)
@@ -714,8 +714,12 @@ v3d_set_fs_prog_data_inputs(struct v3d_compile *c,
         memcpy(prog_data->input_slots, c->input_slots,
                c->num_inputs * sizeof(*c->input_slots));
 
-        memcpy(prog_data->flat_shade_flags, c->flat_shade_flags,
-               sizeof(c->flat_shade_flags));
+        STATIC_ASSERT(ARRAY_SIZE(prog_data->flat_shade_flags) >
+                      (V3D_MAX_FS_INPUTS - 1) / 24);
+        for (int i = 0; i < V3D_MAX_FS_INPUTS; i++) {
+                if (BITSET_TEST(c->flat_shade_flags, i))
+                        prog_data->flat_shade_flags[i / 24] |= 1 << (i % 24);
+        }
 }
 
 uint64_t *v3d_compile_fs(const struct v3d_compiler *compiler,
index 3914a346e9d36a437b9806a40d3803f5e6509a67..321f59d14c44f1a3f16d4ee3607fae3d2d8facb6 100644 (file)
@@ -501,12 +501,39 @@ vc5_emit_state(struct pipe_context *pctx)
                 emit_textures(vc5, &vc5->verttex);
 
         if (vc5->dirty & VC5_DIRTY_FLAT_SHADE_FLAGS) {
-                /* XXX: Need to handle more than 24 entries. */
-                cl_emit(&job->bcl, FLAT_SHADE_FLAGS, flags) {
-                        flags.varying_offset_v0 = 0;
+                bool emitted_any = false;
+
+                for (int i = 0; i < ARRAY_SIZE(vc5->prog.fs->prog_data.fs->flat_shade_flags); i++) {
+                        if (!vc5->prog.fs->prog_data.fs->flat_shade_flags[i])
+                                continue;
+
+                        cl_emit(&job->bcl, FLAT_SHADE_FLAGS, flags) {
+                                flags.varying_offset_v0 = i;
+
+                                if (emitted_any) {
+                                        flags.action_for_flat_shade_flags_of_lower_numbered_varyings =
+                                                V3D_FLAT_SHADE_ACTION_UNCHANGED;
+                                        flags.action_for_flat_shade_flags_of_higher_numbered_varyings =
+                                                V3D_FLAT_SHADE_ACTION_UNCHANGED;
+                                } else {
+                                        flags.action_for_flat_shade_flags_of_lower_numbered_varyings =
+                                                ((i == 0) ?
+                                                 V3D_FLAT_SHADE_ACTION_UNCHANGED :
+                                                 V3D_FLAT_SHADE_ACTION_ZEROED);
+
+                                        flags.action_for_flat_shade_flags_of_higher_numbered_varyings =
+                                                V3D_FLAT_SHADE_ACTION_ZEROED;
+                                }
+
+                                flags.flat_shade_flags_for_varyings_v024 =
+                                        vc5->prog.fs->prog_data.fs->flat_shade_flags[i];
+                        }
+
+                        emitted_any = true;
+                }
 
-                        flags.flat_shade_flags_for_varyings_v024 =
-                                vc5->prog.fs->prog_data.fs->flat_shade_flags[0] & 0xfffff;
+                if (!emitted_any) {
+                        cl_emit(&job->bcl, ZERO_ALL_FLAT_SHADE_FLAGS, flags);
                 }
         }