bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Use a read-only depth buffer for transparent/transmissive passes

Open JMS55 opened this issue 1 year ago • 1 comments

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()

JMS55 avatar Dec 03 '24 18:12 JMS55

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

JMS55 avatar Dec 03 '24 18:12 JMS55

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.

JMS55 avatar Jan 24 '25 07:01 JMS55

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.

snail-with-tea avatar Aug 27 '25 19:08 snail-with-tea

Nevermind, I used wrong texture format. This PR is awesome anyways.

snail-with-tea avatar Sep 08 '25 09:09 snail-with-tea