Commit 3f155d0
Fix Vulkan validation errors in URP CopyDepthPass
This PR fixes https://jira.unity3d.com/browse/UUM-60387
The bug requires a few things to be true in order to reproduce: have URP with RenderGraph enabled, use Vulkan, have MSAA disabled.
In this case, when the two repro projects were set up in a way that causes CopyDepthPass to be executed (specifically with CopyToDepth=false), the depth was not getting copied correctly, causing subsequent depth tests to fail, resulting in missing objects. When Vulkan validation layers were enabled, the following error was output:
```
VULKAN: VALIDATION ERROR: Validation Error: [ VUID-vkCmdDraw-None-06886 ]
Object 0: handle = 0xab7c3f0000001d62, type = VK_OBJECT_TYPE_PIPELINE; Object 1: handle = 0xceb68d0000001d60, name = ExecuteRenderGraph (C0:C/S, C1:L/S, DS:L/S), type = VK_OBJECT_TYPE_RENDER_PASS;
Object 2: handle = 0x14239304030, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xf157442b | vkCmdDraw:
depthWriteEnable is VK_TRUE, while the layout (VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL) of the depth aspect of the depth/stencil attachment in the render pass is read only. The Vulkan spec states: If the current render pass instance uses a depth/stencil attachment with a read-only layout for the depth aspect, depth writes must be disabled (https://vulkan.lunarg.com/doc/view/1.3.243.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-None-06886)
CommandBuffer labels: CopyDepth | CopyDepthPass
Objects:
#0: { type = VK_OBJECT_TYPE_PIPELINE, handle = 0xab7c3f0000001d62 }
#1: { name = ExecuteRenderGraph (C0:C/S, C1:L/S, DS:L/S), type = VK_OBJECT_TYPE_RENDER_PASS, handle = 0xceb68d0000001d60 }
#2: { type = VK_OBJECT_TYPE_COMMAND_BUFFER, handle = 0x14239304030 }
```
The reason for this error is that the render state is being setup in an inconsistent way:
- `depthWriteEnable=true` because `CopyDepth.shader` contains `ZWrite On`, but
- because we don't bind a depth attachment, the RenderGraph compiler sets `SubPassFlags.ReadOnlyDepth` flag which causes Vulkan backend to use the `VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL` layout.
To fix this conflicting setup we set ZWrite to On/Off depending on whether depth output is active or not. This fixes the validation error, and the incorrect rendering in the original repro project, and makes the new graphics test pass.
Shoutout to @eduardas-vitkus for creating the new graphics test that catches this specific case, and providing a ton of relevant information on the issue, including the Vulkan validation error!1 parent fd01370 commit 3f155d0
17 files changed
Lines changed: 1460 additions & 34 deletions
File tree
- Packages/com.unity.render-pipelines.universal
- Runtime/Passes
- Shaders/Utils
- Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation
- Assets/Scenes
- 311_DepthCopyTransparent
- ProjectSettings
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| |||
178 | 181 | | |
179 | 182 | | |
180 | 183 | | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments