broadcom/vc5: Add a cl_emit() variant for merging with a pre-packed struct.
authorEric Anholt <eric@anholt.net>
Wed, 1 Nov 2017 22:16:59 +0000 (15:16 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 7 Nov 2017 17:19:48 +0000 (09:19 -0800)
Cleans up the hand-written code, at the cost of another ugly macro.

src/gallium/drivers/vc5/vc5_cl.h
src/gallium/drivers/vc5/vc5_draw.c

index 64ccac80593a838956915fcd9693d67e98fdcb71..4c64f084d3d129cb3dc905bc81c09fbce741ed22 100644 (file)
@@ -221,8 +221,23 @@ cl_get_emit_space(struct vc5_cl_out **cl, size_t size)
         ({                                                       \
                 struct vc5_cl_out *cl_out = cl_start(cl);        \
                 cl_packet_pack(packet)(cl, (uint8_t *)cl_out, &name); \
-                VG(VALGRIND_CHECK_MEM_IS_DEFINED(cl_out,         \
-                                                 cl_packet_length(packet))); \
+                cl_advance(&cl_out, cl_packet_length(packet));   \
+                cl_end(cl, cl_out);                              \
+                _loop_terminate = NULL;                          \
+        }))                                                      \
+
+#define cl_emit_with_prepacked(cl, packet, prepacked, name)      \
+        for (struct cl_packet_struct(packet) name = {            \
+                cl_packet_header(packet)                         \
+        },                                                       \
+        *_loop_terminate = &name;                                \
+        __builtin_expect(_loop_terminate != NULL, 1);            \
+        ({                                                       \
+                struct vc5_cl_out *cl_out = cl_start(cl);        \
+                uint8_t packed[cl_packet_length(packet)];         \
+                cl_packet_pack(packet)(cl, packed, &name);       \
+                for (int _i = 0; _i < cl_packet_length(packet); _i++) \
+                        ((uint8_t *)cl_out)[_i] = packed[_i] | (prepacked)[_i]; \
                 cl_advance(&cl_out, cl_packet_length(packet));   \
                 cl_end(cl, cl_out);                              \
                 _loop_terminate = NULL;                          \
index 2ff604f02f23acfc6b8ce2cb43fb781bea058b02..edc528591542e50b3b974b0d341c83636f6ed9c3 100644 (file)
@@ -221,25 +221,20 @@ vc5_emit_gl_shader_state(struct vc5_context *vc5,
                         &vertexbuf->vb[elem->vertex_buffer_index];
                 struct vc5_resource *rsc = vc5_resource(vb->buffer.resource);
 
-                struct V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD attr_unpacked = {
-                        .stride = vb->stride,
-                        .address = cl_address(rsc->bo,
-                                              vb->buffer_offset +
-                                              elem->src_offset),
-                        .number_of_values_read_by_coordinate_shader =
-                                vc5->prog.cs->prog_data.vs->vattr_sizes[i],
-                        .number_of_values_read_by_vertex_shader =
-                                vc5->prog.vs->prog_data.vs->vattr_sizes[i],
-                };
                 const uint32_t size =
                         cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
-                uint8_t attr_packed[size];
-                V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD_pack(&job->indirect,
-                                                            attr_packed,
-                                                            &attr_unpacked);
-                for (int j = 0; j < size; j++)
-                        attr_packed[j] |= vtx->attrs[i * size + j];
-                cl_emit_prepacked(&job->indirect, &attr_packed);
+                cl_emit_with_prepacked(&job->indirect,
+                                       GL_SHADER_STATE_ATTRIBUTE_RECORD,
+                                       &vtx->attrs[i * size], attr) {
+                        attr.stride = vb->stride;
+                        attr.address = cl_address(rsc->bo,
+                                                  vb->buffer_offset +
+                                                  elem->src_offset);
+                        attr.number_of_values_read_by_coordinate_shader =
+                                vc5->prog.cs->prog_data.vs->vattr_sizes[i];
+                        attr.number_of_values_read_by_vertex_shader =
+                                vc5->prog.vs->prog_data.vs->vattr_sizes[i];
+                }
         }
 
         if (vtx->num_elements == 0) {