[RADV] Problems reading primitive ID in fragment shader after tessellation
Description
The vulkan spec says that PrimitiveId can be read from the fragment shader:
In a fragment shader, it will contain the primitive index written by the geometry shader if a geometry shader is present, or with the value that would have been presented as input to the geometry shader had it been present.
Which means that in the case of tessellation with no geometry shader you should get the post-tessellation primitive ID. When tessellation is active though I get a compiler assert (and garbage results if I ignore the assert).
Repro steps
I've made a vkrunner script which should show the crash: tess_prim.shader_test. Also here's a working case where the fragment shader doesn't read PrimitiveId
: tess_noprim.shader_test for comparison.
This is constructed from Sascha Willems' passthrough vertex + tess shaders, combined with either a fixed color fragment shader or one that reads from primitive ID and encodes it into the output.
When running under a release build that doesn't show any problems because I didn't set up sampling to check that the result is sensible, but if you run under debug build (or any build with assertions) you see the assert at least. I don't have an direct way to check that the ID is correct, you'd probably have to set up reasonable inputs to the vkrunner script. If you are able to, the easiest repro is probably to use renderdoc to capture Sascha Willems' tessellation example with wireframe off and run pixel history on the tessellated drawcall. The primitive ID is used to display which primitive wrote to each pixel, so if it's garbage it will be clear.
This happens with aco and with llvm if I set RADV_DEBUG=llvm:
$ ./src/vkrunner tess_prim.shader_test
vkrunner: ../src/amd/compiler/aco_instruction_selection.h:122: aco::Temp aco::get_arg(aco::isel_context*, ac_arg): Assertion `arg.used' failed.
Aborted (core dumped)
$ RADV_DEBUG=llvm ./src/vkrunner tess_prim.shader_test
vkrunner: ../src/amd/llvm/ac_llvm_build.h:590: ac_get_arg: Assertion `arg.used' failed.
Aborted (core dumped)
System information
System: Host: lupino Kernel: 5.4.0-47-generic x86_64 bits: 64 compiler: gcc v: 9.3.0 Desktop: Fluxbox 1.3.5 dm: GDM3
Distro: Ubuntu 20.04.1 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: 1887 MHz min/max: 2200/3400 MHz Core speeds (MHz): 1: 1942 2: 1887 3: 1946 4: 1929 5: 1991 6: 1910 7: 1906
8: 1900 9: 2063 10: 1906 11: 1908 12: 1887 13: 1887 14: 1887 15: 1912 16: 2187
Graphics: Device-1: Advanced Micro Devices [AMD/ATI] 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-47-generic LLVM 10.0.1)
v: 4.6 Mesa 20.3.0-devel (git-123bdb61cc) direct render: Yes