[RADV] Non-precise occlusion queries return non-zero when all fragments are discarded
Description
When running occlusion queries on radv if they are not precise then it seems like shader discards do not affect the occlusion result.
According to the vulkan spec chapter 27 Fragment Operations sample counting should happen last after fragment shading unless early fragment tests are explicitly enabled in the shader, which they are not in this case. The imprecise version of the queries are allowed to return any non-zero value when there are some samples passing, but they must still return 0 when there are no samples passing (where passing means non-discarded in the case of late fragment tests).
I've attached a repro case in a C++ source file: discard_query.cpp that alternates between precise and imprecise queries of a triangle that discards every fragment. The precise query returns 0, the imprecise query returns 32768.
Apologies for the size of the source file, I wanted to keep it in a single file for simplicity but just smushed in all my helper code...
System information
System:
Host: lupino Kernel: 5.4.0-39-generic x86_64 bits: 64 compiler: gcc
v: 9.3.0 Desktop: Fluxbox 1.3.5 dm: GDM3
Distro: Ubuntu 20.04 LTS (Focal Fossa)
CPU:
Topology: 8-Core model: AMD Ryzen 7 1700X bits: 64 type: MT MCP arch: Zen
rev: 1 L2 cache: 4096 KiB
flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
bogomips: 108795
Speed: 1923 MHz min/max: 2200/3400 MHz Core speeds (MHz): 1: 1889 2: 1895
3: 1890 4: 2011 5: 1997 6: 1890 7: 1886 8: 1887 9: 1893 10: 1898 11: 1887
12: 1890 13: 1909 14: 1995 15: 1899 16: 1888
Graphics:
Device-1: AMD Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]
vendor: PC Partner Limited driver: amdgpu v: kernel bus ID: 24:00.0
chip ID: 1002:67df
Device-2: NVIDIA TU102 [GeForce RTX 2080 Ti Rev. A] driver: N/A
bus ID: 25:00.0 chip ID: 10de:1e07
Display: x11 server: X.Org 1.20.8 driver: ati,modesetting
unloaded: fbdev,radeon,vesa resolution: 1920x1080~60Hz
OpenGL: renderer: AMD Radeon RX 480 Graphics (POLARIS10 DRM 3.35.0
5.4.0-39-generic LLVM 10.0.0)
v: 4.5 Mesa 19.3.0-devel - padoka PPA direct render: Yes