draw: fix stippling of fractional lines
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 11 Aug 2021 14:53:11 +0000 (16:53 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 19 Aug 2021 09:44:16 +0000 (09:44 +0000)
The OpenGL 4.6 specification, section 14.5.2.1 (Line Stipple) says:

> The masking is achieved using three parameters: the 16-bit line
> stipple p, the line repeat count r, and an integer stipple counter s.

This is pretty clear that the stipple counter shouldn't carry fractional
parts. But we also don't really do anything useful with the fractional
part anyway, apart from skewing the third or later line-segments

Properly carrying over the fractional parts as the Vulkan specification
allows for rectangular lines is trickier than this and would require us
to use a shorter output-line at the start of the following
line-segments.

But let's just do what the OpenGL specification describes, and the
Vulkan specification allows for now.

This, combined with the following patch for the vulkan CTS makes the
last two rasterization-tests pass for me:

https://github.com/KhronosGroup/VK-GL-CTS/pull/279

Fixes the "spec/!opengl 1.1/linestipple/line strip" piglit-test.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12327>

src/gallium/auxiliary/draw/draw_pipe_stipple.c
src/gallium/drivers/llvmpipe/ci/llvmpipe-quick_gl.txt

index eff9bcf..dd1fc8d 100644 (file)
@@ -47,7 +47,7 @@
 /** Subclass of draw_stage */
 struct stipple_stage {
    struct draw_stage stage;
-   float counter;
+   unsigned counter;
    ushort pattern;
    ushort factor;
    bool rectangular;
@@ -110,9 +110,9 @@ emit_segment(struct draw_stage *stage, struct prim_header *header,
 
 
 static inline bool
-stipple_test(int counter, ushort pattern, ushort factor)
+stipple_test(unsigned counter, ushort pattern, ushort factor)
 {
-   int b = (counter / factor) & 0xf;
+   unsigned b = (counter / factor) & 0xf;
    return !!((1 << b) & pattern);
 }
 
@@ -159,7 +159,7 @@ stipple_line(struct draw_stage *stage, struct prim_header *header)
    /* XXX ToDo: instead of iterating pixel-by-pixel, use a look-up table.
     */
    for (i = 0; i < intlength; i++) {
-      bool result = stipple_test((int)stipple->counter + i,
+      bool result = stipple_test(stipple->counter + i,
                                  stipple->pattern, stipple->factor);
       if (result != state) {
          /* changing from "off" to "on" or vice versa */
@@ -178,7 +178,7 @@ stipple_line(struct draw_stage *stage, struct prim_header *header)
    if (state && start < length)
       emit_segment(stage, header, start / length, 1.0);
 
-   stipple->counter += length;
+   stipple->counter += intlength;
 }
 
 
index ba9c578..838d4e8 100644 (file)
@@ -131,7 +131,6 @@ spec/!opengl 1.1/draw-pixels samples=32: skip
 spec/!opengl 1.1/draw-pixels samples=4: skip
 spec/!opengl 1.1/draw-pixels samples=6: skip
 spec/!opengl 1.1/draw-pixels samples=8: skip
-spec/!opengl 1.1/linestipple/line strip: fail
 spec/!opengl 1.1/polygon-mode-facing: fail
 spec/!opengl 1.1/polygon-mode-offset/config 3: expected white pixel on bottom edge: fail
 spec/!opengl 1.1/polygon-mode-offset/config 3: expected white pixel on left edge: fail