[Vk] Improve Stencil Handling and Fix Read-After-Write Hazard #235

Merged
Shinmegumi merged 1 commit from wildcard/eden:fixRAWsyncerror into master 2025-08-23 20:04:48 +02:00
Member
  1. Improves stencil handling:

    • Adds surface type detection to distinguish between color, depth, stencil, and depth-stencil formats
    • Only enables stencil load/store operations for surfaces that actually contain stencil data
    • Avoids unnecessary stencil operations for non-stencil formats (DONT_CARE)
  2. Fixes read-after-write (RAW) synchronization hazards:

    • Adds a subpass self-dependency (subpass 0 → subpass 0)
    • Synchronizes color/depth writes with subsequent shader reads
    • Uses VK_DEPENDENCY_BY_REGION_BIT for efficient synchronization
    • Covers all possible relevant stages,
      • src: Color output + Early/Late fragment tests
      • dst: Fragment shader
      • Access: Write → Read transitions
      here is what hazard looks like [1147.550616] Render.Vulkan video_core/vulkan_common/vulkan_debug_callback.cpp:DebugUtilCallback:55: Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0x7409630000000192, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0xe4d96472 | vkCmdDrawIndexed: Hazard READ_AFTER_WRITE for VkImageView 0x7409630000000192[], in VkCommandBuffer 0xb400007cb003ea70[], and VkPipeline 0x44d3470000000213[], VkDescriptorSet 0x0[], type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, imageLayout: VK_IMAGE_LAYOUT_GENERAL, binding #2, index 0. Access info (usage: SYNC_FRAGMENT_SHADER_SHADER_SAMPLED_READ, prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: SYNC_FRAGMENT_SHADER_COLOR_ATTACHMENT_READ|SYNC_FRAGMENT_SHADER_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE|SYNC_SUBPASS_SHADER_HUAWEI_INPUT_ATTACHMENT_READ, command: vkCmdPipelineBarrier, seq_no: 45, reset_no: 129).
1. Improves stencil handling: - Adds surface type detection to distinguish between color, depth, stencil, and depth-stencil formats - Only enables stencil load/store operations for surfaces that actually contain stencil data - Avoids unnecessary stencil operations for non-stencil formats (DONT_CARE) 2. Fixes read-after-write (RAW) synchronization hazards: - Adds a subpass self-dependency (subpass 0 → subpass 0) - Synchronizes color/depth writes with subsequent shader reads - Uses VK_DEPENDENCY_BY_REGION_BIT for efficient synchronization - Covers all possible relevant stages, • src: Color output + Early/Late fragment tests • dst: Fragment shader • Access: Write → Read transitions here is what hazard looks like [1147.550616] Render.Vulkan <Critical> video_core/vulkan_common/vulkan_debug_callback.cpp:DebugUtilCallback:55: Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0x7409630000000192, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0xe4d96472 | vkCmdDrawIndexed: Hazard READ_AFTER_WRITE for VkImageView 0x7409630000000192[], in VkCommandBuffer 0xb400007cb003ea70[], and VkPipeline 0x44d3470000000213[], VkDescriptorSet 0x0[], type: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, imageLayout: VK_IMAGE_LAYOUT_GENERAL, binding #2, index 0. Access info (usage: SYNC_FRAGMENT_SHADER_SHADER_SAMPLED_READ, prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: SYNC_FRAGMENT_SHADER_COLOR_ATTACHMENT_READ|SYNC_FRAGMENT_SHADER_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ|SYNC_LATE_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_WRITE|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE|SYNC_SUBPASS_SHADER_HUAWEI_INPUT_ATTACHMENT_READ, command: vkCmdPipelineBarrier, seq_no: 45, reset_no: 129).
wildcard added 2 commits 2025-08-09 22:36:15 +02:00
[ VUID-vkCmdPipelineBarrier-dstAccessMask-02816 ] The Vulkan spec states: The dstAccessMask member of each element of pMemoryBarriers must only include access flags that are supported by one or more of the pipeline stages in dstStageMask, as specified in the table of supported access types. Fixes the said validation error.
revert Fix VUID error 02816

[ VUID-vkCmdPipelineBarrier-dstAccessMask-02816 ] The Vulkan spec states: The dstAccessMask member of each element of pMemoryBarriers must only include access flags that are supported by one or more of the pipeline stages in dstStageMask, as specified in the table of supported access types. Fixes the said validation error.
Shinmegumi force-pushed fixRAWsyncerror from cb48dcc858 to 8cb82b8919 2025-08-12 17:13:26 +02:00 Compare
Shinmegumi force-pushed fixRAWsyncerror from 8cb82b8919 to d3558b794d 2025-08-13 15:40:48 +02:00 Compare
Shinmegumi added this to the 0.0.3 Release Candidate PRs project 2025-08-13 15:43:12 +02:00
crueter approved these changes 2025-08-15 01:20:14 +02:00
Dismissed
crueter left a comment
Owner

looks good pending further testing

looks good pending further testing
crueter force-pushed fixRAWsyncerror from d3558b794d to 5310112818 2025-08-15 01:21:16 +02:00 Compare
crueter force-pushed fixRAWsyncerror from 5310112818 to df1b42948c 2025-08-15 01:22:11 +02:00 Compare
crueter dismissed crueter's review 2025-08-15 01:22:11 +02:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

Shinmegumi force-pushed fixRAWsyncerror from df1b42948c to f35018782d 2025-08-15 20:17:20 +02:00 Compare
crueter modified the project from 0.0.3 Release Candidate PRs to Development Tracking 2025-08-15 23:40:46 +02:00
Shinmegumi force-pushed fixRAWsyncerror from f35018782d to 4fca9d7a68 2025-08-23 20:04:19 +02:00 Compare
Shinmegumi approved these changes 2025-08-23 20:04:41 +02:00
Shinmegumi merged commit 4eb6d10d62 into master 2025-08-23 20:04:48 +02:00
Sign in to join this conversation.
No description provided.