vc4: Move rasterizer state packing to CSO creation time.
authorEric Anholt <eric@anholt.net>
Mon, 6 Feb 2017 22:06:12 +0000 (14:06 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 30 Jun 2017 19:25:45 +0000 (12:25 -0700)
This gets our vc4_emit.c size back down a bit:

before:
   1020       0       0    1020     3fc src/gallium/drivers/vc4/.libs/vc4_emit.o

after:
    968       0       0     968     3c8 src/gallium/drivers/vc4/.libs/vc4_emit.o

src/gallium/drivers/vc4/vc4_cl.h
src/gallium/drivers/vc4/vc4_context.h
src/gallium/drivers/vc4/vc4_emit.c
src/gallium/drivers/vc4/vc4_state.c

index c9a988e85b868325a78f21168e71bc4b36a84a8c..ec3713c8a4aac0b79766496ec51cec6b766e3521 100644 (file)
@@ -279,6 +279,11 @@ cl_get_emit_space(struct vc4_cl_out **cl, size_t size)
                 _loop_terminate = NULL;                          \
         }))                                                      \
 
+#define cl_emit_prepacked(cl, packet) do {                       \
+        memcpy((cl)->next, packet, sizeof(*packet));             \
+        cl_advance(&(cl)->next, sizeof(*packet));                \
+} while (0)
+
 /**
  * Helper function called by the XML-generated pack functions for filling in
  * an address field in shader records.
index 3fe439543a8631717d4ec6d1a966acf14bbff9b2..256f92d545a8b58d01a84c5b81ad431bcfe9d8f5 100644 (file)
@@ -386,18 +386,11 @@ struct vc4_rasterizer_state {
         /* VC4_CONFIGURATION_BITS */
         uint8_t config_bits[3];
 
-        float point_size;
-
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset units for
-         * VC4_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_units;
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset scale for
-         * VC4_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_factor;
+        struct PACKED {
+                uint8_t depth_offset[V3D21_DEPTH_OFFSET_length];
+                uint8_t point_size[V3D21_POINT_SIZE_length];
+                uint8_t line_width[V3D21_LINE_WIDTH_length];
+        } packed;
 };
 
 struct vc4_depth_stencil_alpha_state {
index 8fb379df5e0f5ad2361f652f8e5e6967bd468ca4..d0a701f17b3515d5a9fca9d67c095d04284884bf 100644 (file)
@@ -115,20 +115,7 @@ vc4_emit_state(struct pipe_context *pctx)
         }
 
         if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
-                cl_emit(&job->bcl, DEPTH_OFFSET, depth) {
-                        depth.depth_offset_units =
-                                vc4->rasterizer->offset_units;
-                        depth.depth_offset_factor =
-                                vc4->rasterizer->offset_factor;
-                }
-
-                cl_emit(&job->bcl, POINT_SIZE, points) {
-                        points.point_size = vc4->rasterizer->point_size;
-                }
-
-                cl_emit(&job->bcl, LINE_WIDTH, points) {
-                        points.line_width = vc4->rasterizer->base.line_width;
-                }
+                cl_emit_prepacked(&job->bcl, &vc4->rasterizer->packed);
         }
 
         if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
index 3267bb043f9b895bc01461606f025ce099ce152c..9a3438f8493564b6d340c7df7249b868f6bb4268 100644 (file)
@@ -94,6 +94,9 @@ vc4_create_rasterizer_state(struct pipe_context *pctx,
                             const struct pipe_rasterizer_state *cso)
 {
         struct vc4_rasterizer_state *so;
+        struct V3D21_DEPTH_OFFSET depth_offset = { V3D21_DEPTH_OFFSET_header };
+        struct V3D21_POINT_SIZE point_size = { V3D21_POINT_SIZE_header };
+        struct V3D21_LINE_WIDTH line_width = { V3D21_LINE_WIDTH_header };
 
         so = CALLOC_STRUCT(vc4_rasterizer_state);
         if (!so)
@@ -109,7 +112,9 @@ vc4_create_rasterizer_state(struct pipe_context *pctx,
         /* Workaround: HW-2726 PTB does not handle zero-size points (BCM2835,
          * BCM21553).
          */
-        so->point_size = MAX2(cso->point_size, .125f);
+        point_size.point_size = MAX2(cso->point_size, .125f);
+
+        line_width.line_width = cso->line_width;
 
         if (cso->front_ccw)
                 so->config_bits[0] |= VC4_CONFIG_BITS_CW_PRIMITIVES;
@@ -117,13 +122,19 @@ vc4_create_rasterizer_state(struct pipe_context *pctx,
         if (cso->offset_tri) {
                 so->config_bits[0] |= VC4_CONFIG_BITS_ENABLE_DEPTH_OFFSET;
 
-                so->offset_units = float_to_187_half(cso->offset_units);
-                so->offset_factor = float_to_187_half(cso->offset_scale);
+                depth_offset.depth_offset_units =
+                        float_to_187_half(cso->offset_units);
+                depth_offset.depth_offset_factor =
+                        float_to_187_half(cso->offset_scale);
         }
 
         if (cso->multisample)
                 so->config_bits[0] |= VC4_CONFIG_BITS_RASTERIZER_OVERSAMPLE_4X;
 
+        V3D21_DEPTH_OFFSET_pack(NULL, so->packed.depth_offset, &depth_offset);
+        V3D21_POINT_SIZE_pack(NULL, so->packed.point_size, &point_size);
+        V3D21_LINE_WIDTH_pack(NULL, so->packed.line_width, &line_width);
+
         return so;
 }