[RADV] broken stencil behaviour when using extended dynamic stencil state
Description
This one is quite strange, it's a follow-on from #3627 (closed) where my tests are still failing because now the stencil values come out wrongly when using extended dynamic stencil state. After some experimentation it only seems to happen when using extended dynamic stencil state and if the stencil buffer is cleared in a separate submit to where the pipeline operates on it. It doesn't make sense to me but it seems consistent.
Repro steps
The program submits two command buffers. The first has a renderpass which clears the depth/stencil (stencil = 0xcc) with a loadOp then stores it with a storeOp. The second command buffer has a RP which loads and renders two overlapping triangles with INCR_AND_SAT stencil state.
It then does a second render with a separate fixed pipeline that tests stencil == 0xce and colours red, which fills in the overlap between the triangles. This is just to show easily whether the stencil values are correct, I do not think it's related to the bug it's just there to make the repro clearer).
I've attached it here: stencil_ext_state_repro.cpp. This one does not have dynamic vertex buffer stride, to avoid any potential confusion with #3627 (closed). Compile and run the same way, this time I set up command line parameters to more easily toggle between tests:
--static
- sets the pipeline state to use static stencil state and not set the extended dynamic stencil states.
--dynamic
- default if neither is present, uses the dynamic stencil states.
and
--one-submit
- submits both command buffers in a single submit. This seems to make the problem go away.
--multi-submit
- default if neither is present. Does one submit with the clearing command buffer, then a second submit with the pipelines command buffer.
For me the default case (with no parameters) which does dynamic stencil and two submits only shows the two overlapping green/blue triangles. This means the red triangle draw which is testing stencil and should have passed on the overlap isn't working:
If you pass either --static
or --one-submit
or both, it has the correct stencil and the red overlap region shows up:
(Just a heads up - if you look at captures of the program in renderdoc you will notice some funny behaviour, because renderdoc will split commands across submits when introspecting. That's the reason I noticed the need for multiple submits)
System information
System:
Host: lupino Kernel: 5.4.0-48-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: 108794
Speed: 1887 MHz min/max: 2200/3400 MHz Core speeds (MHz): 1: 1885 2: 1886
3: 2094 4: 2327 5: 1860 6: 1737 7: 1799 8: 1883 9: 1890 10: 1896 11: 1890
12: 1887 13: 1890 14: 1886 15: 1880 16: 1869
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-48-generic LLVM 10.0.1)
v: 4.6 Mesa 20.3.0-devel (git-1070bba19e) direct render: Yes