Created attachment 137887 [details]
Renderdoc v1.0 capture
On RADV, when using a VK_FORMAT_D32_SFLOAT (or VK_FORMAT_D32_SFLOAT_S8_UINT) depth buffer cleared to 0.0, if a fragment shader discards all fragments in a cleared htile, the htile's depth can be set to 1.0, instead of keeping the clear value of 0.0.
The attached renderdoc capture reproduces the issue by clearing the depth buffer to 0.0 with vkCmdClearAttachments, then drawing a triangle in the upper left half of an image using a shader which discards fragments that lie outside of a semicircle. The bug doesn't reproduce if I remove the vkCmdClearAttachments and use VK_LOAD_OP_CLEAR at the start of the render pass. However I have another more complex application which appears to be using VK_LOAD_OP_CLEAR in an earlier renderpass and loading stored depth values in a renderpass which reproduces this bug, without using other clears in the middle.
I'm using git revision fb5825e7ceeb16ac05f870ffe1e5a5daa09e68dd on an AMD RX 480.
Setting RADV_DEBUG to nohiz or nofastclears avoids the bug.
Created attachment 137888 [details]
Source for application used in RenderDoc frame capture
https://patchwork.freedesktop.org/patch/208935/ fixes it for me on my RX 480, but I haven't had any reviews on that patch yet and I'm not sure if I'm heading in the right direction. It would also be good to test this on other GPUs including Vega.
What should be the expected output?
Created attachment 140095 [details]
A white semicircle on a black background, as shown.
Sorry, the more problematic bit is the depth buffer, which should be 0.5 inside the semicircle and 0.0 outside it, which isn't what is shown in the screenshot.
Looks like the output is correct on my polaris with mesa master, can you confirm?
Ah okay, sorry I missed your latest comment.
Okay, I can reproduce the issue with renderdoc, thanks!
Can you confirm this patch fixes the issue ? https://patchwork.freedesktop.org/patch/229236/
Yes, that patch fixes it. Thanks.