v3d: Move depth offset packet setup to CSO creation time.
authorEric Anholt <eric@anholt.net>
Mon, 30 Jul 2018 20:44:40 +0000 (13:44 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 30 Jul 2018 21:29:01 +0000 (14:29 -0700)
This should be some simpler memcpying at draw time, and makes the next
change easier.

src/gallium/drivers/v3d/v3d_cl.h
src/gallium/drivers/v3d/v3d_context.h
src/gallium/drivers/v3d/v3dx_emit.c
src/gallium/drivers/v3d/v3dx_state.c

index 1f3754f29f55296b56f2094f98ecde37ae6afcbb..0b3058f4fdd1d1c83dc68e7b0ff4ea05b165182b 100644 (file)
@@ -243,11 +243,14 @@ cl_get_emit_space(struct v3d_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));                \
+#define cl_emit_prepacked_sized(cl, packet, size) do {                \
+        memcpy((cl)->next, packet, size);             \
+        cl_advance(&(cl)->next, size);                \
 } while (0)
 
+#define cl_emit_prepacked(cl, packet) \
+        cl_emit_prepacked_sized(cl, packet, sizeof(*(packet)))
+
 #define v3dx_pack(packed, packet, name)                          \
         for (struct cl_packet_struct(packet) name = {            \
                 cl_packet_header(packet)                         \
index b61dacf66c7e38f1c0a5e4dae3ec81b069799162..f6720e2ca93c413d224fe6d6958b7ba67763295a 100644 (file)
@@ -433,21 +433,8 @@ struct v3d_rasterizer_state {
 
         float point_size;
 
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset units for
-         * VC5_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_units;
-        /**
-         * The HW treats polygon offset units based on a Z24 buffer, so we
-         * need to scale up offset_units if we're only Z16.
-         */
-        uint16_t z16_offset_units;
-        /**
-         * Half-float (1/8/7 bits) value of polygon offset scale for
-         * VC5_PACKET_DEPTH_OFFSET
-         */
-        uint16_t offset_factor;
+        uint8_t depth_offset[9];
+        uint8_t depth_offset_z16[9];
 };
 
 struct v3d_depth_stencil_alpha_state {
index 4402218f40437493efbc93031177bba0a8ef6421..ee4849a296f2237ea98e41bec3aa15209eaa464d 100644 (file)
@@ -522,17 +522,15 @@ v3dX(emit_state)(struct pipe_context *pctx)
 
         if (v3d->dirty & VC5_DIRTY_RASTERIZER &&
             v3d->rasterizer->base.offset_tri) {
-                cl_emit(&job->bcl, DEPTH_OFFSET, depth) {
-                        depth.depth_offset_factor =
-                                v3d->rasterizer->offset_factor;
-                        if (job->zsbuf &&
-                            job->zsbuf->format == PIPE_FORMAT_Z16_UNORM) {
-                                depth.depth_offset_units =
-                                        v3d->rasterizer->z16_offset_units;
-                        } else {
-                                depth.depth_offset_units =
-                                        v3d->rasterizer->offset_units;
-                        }
+                if (job->zsbuf &&
+                    job->zsbuf->format == PIPE_FORMAT_Z16_UNORM) {
+                        cl_emit_prepacked_sized(&job->bcl,
+                                                v3d->rasterizer->depth_offset_z16,
+                                                cl_packet_length(DEPTH_OFFSET));
+                } else {
+                        cl_emit_prepacked_sized(&job->bcl,
+                                                v3d->rasterizer->depth_offset,
+                                                cl_packet_length(DEPTH_OFFSET));
                 }
         }
 
index 34b845730f6132bbc2bda089e8a7b55965c261db..6ee4a2a835f53a19c6cb0d7b7314c53270336962 100644 (file)
@@ -104,10 +104,23 @@ v3d_create_rasterizer_state(struct pipe_context *pctx,
          */
         so->point_size = MAX2(cso->point_size, .125f);
 
-        if (cso->offset_tri) {
-                so->offset_units = float_to_187_half(cso->offset_units);
-                so->z16_offset_units = float_to_187_half(cso->offset_units * 256.0);
-                so->offset_factor = float_to_187_half(cso->offset_scale);
+        STATIC_ASSERT(sizeof(so->depth_offset) >=
+                      cl_packet_length(DEPTH_OFFSET));
+        v3dx_pack(&so->depth_offset, DEPTH_OFFSET, depth) {
+                depth.depth_offset_factor =
+                        float_to_187_half(cso->offset_scale);
+                depth.depth_offset_units =
+                        float_to_187_half(cso->offset_units);
+        }
+
+        /* The HW treats polygon offset units based on a Z24 buffer, so we
+         * need to scale up offset_units if we're only Z16.
+         */
+        v3dx_pack(&so->depth_offset_z16, DEPTH_OFFSET, depth) {
+                depth.depth_offset_factor =
+                        float_to_187_half(cso->offset_scale);
+                depth.depth_offset_units =
+                        float_to_187_half(cso->offset_units * 256.0);
         }
 
         return so;