gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
11.48k stars 854 forks source link

Lines are thicker than 1px on Windows Dx12 #5830

Open kjarosh opened 2 weeks ago

kjarosh commented 2 weeks ago

Description

When drawing lines using PrimitiveTopology::LineList or PrimitiveTopology::LineStrip, they are 1px thick on Vulkan and Gl, but on Dx12 they are thicker than 1px when MSAA sample count is greater than 1.

I suspect this has something to do with their rasterization rules:

Rasterization rules for primitives are, in general, unchanged by multisample antialiasing, except: [...] A line is treated as a rectangle made up of two triangles, with a line width of 1.4.

Repro steps

Draw a line on Dx12 using PrimitiveTopology::LineList or PrimitiveTopology::LineStrip with MultisampleState.count > 1.

Expected vs observed behavior

Expected: lines always have 1px.

Observed: lines have 1px for Vulkan, Gl, Dx12 without MSAA, but they are thicker than 1px for Dx12 with MSAA.

Extra materials

Dx12 with MSAA on Windows Vulkan with MSAA on Linux

Platform

I actually do not use Windows at all, but unfortunately our tests at Ruffle started failing on the Windows runner when I started using PrimitiveTopology::LineStrip (https://github.com/ruffle-rs/ruffle/pull/16619, failing job). I have confirmed that it in fact does look like that on a Windows machine.

cwfitzgerald commented 2 weeks ago

This probably needs to be bumped up to webgpu as it's unclear what we're supposed to do here - I suspect there's not a ton we can do about this, without extremely expensive polyfills.

Diggsey commented 2 weeks ago

Couldn't you just set MultisampleEnable to FALSE in the rasterizer state?

https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ns-d3d11-d3d11_rasterizer_desc

MultisampleEnable

Type: BOOL

Specifies whether to use the quadrilateral or alpha line anti-aliasing algorithm on multisample antialiasing (MSAA) render targets. Set to TRUE to use the quadrilateral line anti-aliasing algorithm and to FALSE to use the alpha line anti-aliasing algorithm. For more info about this member, see Remarks.