bevy
bevy copied to clipboard
Use a read-only depth buffer for transparent/transmissive passes
Objective
- Fix https://github.com/bevyengine/bevy/issues/3776 properly
Solution
- Bind the depth attachment as read-only (depth_ops: None) during the transparent/transmissive pass
Changelog
- Added ViewDepthTexture::get_read_only_attachment()
- Added DepthAttachment::get_read_only_attachment()
Unfortunately we're hitting VK validation errors now.
2024-12-03T18:12:17.469103Z ERROR wgpu_hal::vulkan::instance: VALIDATION [SYNC-HAZARD-WRITE-AFTER-WRITE (0x5c0ec5d6)]
Validation Error: [ SYNC-HAZARD-WRITE-AFTER-WRITE ] Object 0: handle = 0x1ac4c3cdf38, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x5c0ec5d6 | vkQueueSubmit(): Hazard WRITE_AFTER_WRITE for entry 28, VkCommandBuffer 0x1ac6f16d7c8[main_transparent_pass_3d], Submitted access info (submitted_usage: SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE, command: vkCmdEndRenderPass, seq_no: 3, renderpass: VkRenderPass 0x2610a100000001b1[], reset_no: 356, debug_region: main_transparent_pass_3d). Access info (prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: SYNC_VERTEX_SHADER_SHADER_BINDING_TABLE_READ|SYNC_VERTEX_SHADER_SHADER_SAMPLED_READ|SYNC_VERTEX_SHADER_SHADER_STORAGE_READ|SYNC_FRAGMENT_SHADER_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_FRAGMENT_SHADER_SHADER_BINDING_TABLE_READ|SYNC_FRAGMENT_SHADER_SHADER_SAMPLED_READ|SYNC_FRAGMENT_SHADER_SHADER_STORAGE_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_COMPUTE_SHADER_SHADER_BINDING_TABLE_READ|SYNC_COMPUTE_SHADER_SHADER_SAMPLED_READ|SYNC_COMPUTE_SHADER_SHADER_STORAGE_READ, queue: VkQueue 0x1ac4c3cdf38[], submit: 978, batch: 0, batch_tag: 53965, command: vkCmdPipelineBarrier, command_buffer: VkCommandBuffer 0x1ac6f1951c8[(wgpu internal) Transit], seq_no: 1, VkImage 0xcee26f000000015c[view_depth_texture], VkImage 0xf6d9250000000139[], reset_no: 387).
Upstream issue: https://github.com/gfx-rs/wgpu/issues/5231
Also may or may not need to check for support for https://docs.rs/wgpu/latest/wgpu/struct.DownlevelFlags.html#associatedconstant.READ_ONLY_DEPTH_STENCIL in order to not break WebGL2.
Is there any workarounds/temporary fixes for this? I'm trying to write edge detection post processing shader and it is dependent on depth buffer.
Nevermind, I used wrong texture format. This PR is awesome anyways.