vc4: Actually add support for polygon offset.
authorEric Anholt <eric@anholt.net>
Wed, 24 Sep 2014 20:59:53 +0000 (13:59 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 24 Sep 2014 22:56:39 +0000 (15:56 -0700)
Setting the bit without setting the offset values is kind of useless.
Fixes piglit polygon-offset (but not polygon-mode-offset).

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

index 7839a5a8868fc57850c8571f898b8cecf7e98d66..94306a7e86c5d3b8b61cb1cb5bd237d8e6c6527e 100644 (file)
@@ -205,6 +205,17 @@ struct vc4_rasterizer_state {
         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 vc4_depth_stencil_alpha_state {
index 2a25ca08b9dc9448e9c2ca335ce13bf383e3a175..49f0010e20c08aeecd0249b0d5156e803dd74000 100644 (file)
@@ -49,6 +49,12 @@ vc4_emit_state(struct pipe_context *pctx)
                       vc4->zsa->config_bits[2]);
         }
 
+        if (vc4->dirty & VC4_DIRTY_RASTERIZER) {
+                cl_u8(&vc4->bcl, VC4_PACKET_DEPTH_OFFSET);
+                cl_u16(&vc4->bcl, vc4->rasterizer->offset_factor);
+                cl_u16(&vc4->bcl, vc4->rasterizer->offset_units);
+        }
+
         if (vc4->dirty & VC4_DIRTY_VIEWPORT) {
                 cl_u8(&vc4->bcl, VC4_PACKET_CLIPPER_XY_SCALING);
                 cl_f(&vc4->bcl, vc4->viewport.scale[0] * 16.0f);
index 2e14573deb0e985930fa45ecf55e32a4d87acd42..81dac21f548bcc0b8f9320f28aa2f982df0faf5b 100644 (file)
@@ -79,6 +79,12 @@ vc4_set_sample_mask(struct pipe_context *pctx, unsigned sample_mask)
         vc4->dirty |= VC4_DIRTY_SAMPLE_MASK;
 }
 
+static uint16_t
+float_to_187_half(float f)
+{
+        return fui(f) >> 16;
+}
+
 static void *
 vc4_create_rasterizer_state(struct pipe_context *pctx,
                             const struct pipe_rasterizer_state *cso)
@@ -102,9 +108,13 @@ vc4_create_rasterizer_state(struct pipe_context *pctx,
         if (cso->front_ccw)
                 so->config_bits[0] |= VC4_CONFIG_BITS_CW_PRIMITIVES;
 
-        if (cso->offset_tri)
+        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);
+        }
+
         return so;
 }