v3d: Line rendering broken when smoothing is enabled
Description
On the Raspberry Pi 5 with Ubuntu 23.10 line rendering is broken when smoothing is enabled and a perspective projection is used. (When an orthographic projection is used, line smoothing works.) I can confirm this on Mesa 24.1.0-devel (git- 425ddc24).
System information
System:
Host: rpi5 Kernel: 6.5.0-1008-raspi arch: aarch64 bits: 64 compiler: N/A
Desktop: KDE Plasma v: 5.27.10 tk: Qt v: 5.15.10 wm: kwin_wayland dm:
1: GDM3 2: SDDM note: stopped Distro: Ubuntu 23.10 (Mantic Minotaur)
CPU:
Info: quad core model: N/A variant: cortex-a76 bits: 64 type: MCP
arch: ARMv8 rev: 1
Speed (MHz): avg: 1000 min/max: 1000/2400 cores: 1: 1000 2: 1000 3: 1000
4: 1000 bogomips: 432
Features: Use -f option to see features
Graphics:
Device-1: bcm2712-hdmi0 driver: vc4_hdmi v: N/A bus-ID: N/A
chip-ID: brcm:107c701400
Device-2: bcm2712-hdmi1 driver: vc4_hdmi v: N/A bus-ID: N/A
chip-ID: brcm:107c706400
Display: wayland server: X.org v: 1.21.1.7 with: Xwayland v: 23.2.0
compositor: kwin_wayland driver: X: loaded: fbdev,modesetting
gpu: vc4_hdmi,vc4_hdmi display-ID: 0
Monitor-1: HDMI-A-2 res: 1920x1200 size: N/A
API: OpenGL v: 3.1 Mesa 23.2.1-1ubuntu3.1 renderer: V3D 7.1
direct-render: Yes
FreeCAD
left: hardware rendering
right: software rendering with LIBGL_ALWAYS_SOFTWARE=1
Note: I also had to export QT_QPA_PLATFORM=xcb on Wayland, otherwise FreeCAD would crash.
Minimal Example Program
The green line is correctly rendered with GL_LINE_SMOOTH disabled whereas the red line (with smoothing) is only shown as some dots.
Analysis and possible Solution
I figured out that nir_load_line_coord() in v3d_nir_lower_line_smooth.c:95 seems to return incorrect values.
When I apply this patch to v3d_nir_lower_io.c everything works:
--- a/src/broadcom/compiler/v3d_nir_lower_io.c
+++ b/src/broadcom/compiler/v3d_nir_lower_io.c
@@ -535,7 +535,7 @@ v3d_nir_emit_ff_vpm_outputs(struct v3d_compile *c, nir_builder *b,
if (state->rcp_wc_vpm_offset != -1) {
v3d_nir_store_output(b, state->rcp_wc_vpm_offset,
- offset_reg, rcp_wc);
+ offset_reg, nir_imm_float(b, 1.f));
}
/* Store 0 to varyings requested by the FS but not stored by the