Ralith / hypermine

A hyperbolic voxel game
Apache License 2.0
160 stars 20 forks source link

Vulkan validation layers found sync hazards #390

Closed patowen closed 6 months ago

patowen commented 6 months ago

The following validation errors appear when the "Synchronization" validation layers are turned on in the latest version of the Vulkan SDK (1.3.280.0) on Windows 10:

Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0x2a7f70000000053, name = surface extraction params, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0xe4d96472 | vkCmdDispatch(): Hazard READ_AFTER_WRITE for VkBuffer 0x2a7f70000000053[surface extraction params] in VkCommandBuffer 0x20080c0d690[post-frame], VkPipeline 0x72303f0000000052[extract], and VkDescriptorSet 0x854315000000025c[], type: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding #0 index 0. Access info (usage: SYNC_COMPUTE_SHADER_UNIFORM_READ, prior_usage: SYNC_CLEAR_TRANSFER_WRITE, write_barriers: SYNC_COMPUTE_SHADER_SHADER_BINDING_TABLE_READ|SYNC_COMPUTE_SHADER_SHADER_SAMPLED_READ|SYNC_COMPUTE_SHADER_SHADER_STORAGE_READ, command: vkCmdUpdateBuffer, seq_no: 1, reset_no: 1). id=SYNC-HAZARD-READ-AFTER-WRITE number=-455515022 queue_labels= cmd_labels= objects=BUFFER 2a7f70000000053 SYNC-HAZARD-READ-AFTER-WRITE The breakpoint for this is at https://github.com/Ralith/hypermine/blob/50cf2ffd56f0a401983bc53ac18530b0c3198c9a/client/src/graphics/voxels/surface_extraction.rs#L454

Validation Error: [ SYNC-HAZARD-WRITE-AFTER-WRITE ] Object 0: handle = 0x59ffe0000000003d, name = indirect, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x5c0ec5d6 | vkCmdDispatch(): Hazard WRITE_AFTER_WRITE for VkBuffer 0x59ffe0000000003d[indirect] in VkCommandBuffer 0x20080c0d690[post-frame], VkPipeline 0x72303f0000000052[extract], and VkDescriptorSet 0x363e11000000025b[], type: VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, binding #2 index 0. Access info (usage: SYNC_COMPUTE_SHADER_SHADER_STORAGE_WRITE, prior_usage: SYNC_CLEAR_TRANSFER_WRITE, write_barriers: SYNC_COMPUTE_SHADER_SHADER_BINDING_TABLE_READ|SYNC_COMPUTE_SHADER_SHADER_SAMPLED_READ|SYNC_COMPUTE_SHADER_SHADER_STORAGE_READ, command: vkCmdUpdateBuffer, seq_no: 5, reset_no: 1). id=SYNC-HAZARD-WRITE-AFTER-WRITE number=1544472022 queue_labels= cmd_labels= objects=BUFFER 59ffe0000000003d SYNC-HAZARD-WRITE-AFTER-WRITE The breakpoint is the same as before: https://github.com/Ralith/hypermine/blob/50cf2ffd56f0a401983bc53ac18530b0c3198c9a/client/src/graphics/voxels/surface_extraction.rs#L454

Validation Error: [ SYNC-HAZARD-WRITE-AFTER-READ ] Object 0: handle = 0x1d1055c7360, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x376bc9df | vkQueueSubmit(): Hazard WRITE_AFTER_READ for entry 0, VkCommandBuffer 0x1d105e778b0[post-frame], Submitted access info (submitted_usage: SYNC_CLEAR_TRANSFER_WRITE, command: vkCmdUpdateBuffer, seq_no: 1, reset_no: 3). Access info (prior_usage: SYNC_COMPUTE_SHADER_UNIFORM_READ, read_barriers: VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT|VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT|VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT|VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT|VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT|VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT|VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT|VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT|VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT|VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT|VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT|VK_PIPELINE_STAGE_2_TASK_SHADER_BIT_EXT|VK_PIPELINE_STAGE_2_MESH_SHADER_BIT_EXT|VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT|VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT|VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT, queue: VkQueue 0x1d1055c7360[], submit: 3, batch: 1, batch_tag: 101, command: vkCmdDispatch, command_buffer: VkCommandBuffer 0x1d105e7be90[post-frame], seq_no: 238, reset_no: 1). id=SYNC-HAZARD-WRITE-AFTER-READ number=929810911 queue_labels= cmd_labels= objects=QUEUE 1d1055c7360 The breakpoint is at https://github.com/Ralith/hypermine/blob/50cf2ffd56f0a401983bc53ac18530b0c3198c9a/client/src/graphics/draw.rs#L501

Validation Error: [ SYNC-HAZARD-WRITE-AFTER-READ ] Object 0: handle = 0x1d1055c7360, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x376bc9df | vkQueueSubmit(): Hazard WRITE_AFTER_READ for entry 0, VkCommandBuffer 0x1d105e7be90[post-frame], Submitted access info (submitted_usage: SYNC_COMPUTE_SHADER_SHADER_STORAGE_WRITE, command: vkCmdDispatch, seq_no: 89, reset_no: 3). Access info (prior_usage: SYNC_VERTEX_SHADER_SHADER_STORAGE_READ, read_barriers: VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, queue: VkQueue 0x1d1055c7360[], submit: 7, batch: 0, batch_tag: 606, command: vkCmdDrawIndirect, command_buffer: VkCommandBuffer 0x1d105e79ba0[frame], seq_no: 121, reset_no: 3). id=SYNC-HAZARD-WRITE-AFTER-READ number=929810911 queue_labels= cmd_labels= objects=QUEUE 1d1055c7360 Same breakpoint: https://github.com/Ralith/hypermine/blob/50cf2ffd56f0a401983bc53ac18530b0c3198c9a/client/src/graphics/draw.rs#L501

ERROR Validation Error: [ SYNC-HAZARD-WRITE-AFTER-READ ] Object 0: handle = 0x1d1055c7360, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x376bc9df | vkQueueSubmit(): Hazard WRITE_AFTER_READ for entry 0, VkCommandBuffer 0x1d105e778b0[post-frame], Submitted access info (submitted_usage: SYNC_CLEAR_TRANSFER_WRITE, command: vkCmdUpdateBuffer, seq_no: 1, reset_no: 7). Access info (prior_usage: SYNC_COMPUTE_SHADER_UNIFORM_READ, read_barriers: VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT|VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT|VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT|VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT|VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT|VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT|VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT|VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT|VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT|VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT|VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT|VK_PIPELINE_STAGE_2_TASK_SHADER_BIT_EXT|VK_PIPELINE_STAGE_2_MESH_SHADER_BIT_EXT|VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT|VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT|VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT, queue: VkQueue 0x1d1055c7360[], submit: 11, batch: 1, batch_tag: 1400, command: vkCmdDispatch, command_buffer: VkCommandBuffer 0x1d105e7be90[post-frame], seq_no: 136, reset_no: 5). id=SYNC-HAZARD-WRITE-AFTER-READ number=929810911 queue_labels= cmd_labels= objects=QUEUE 1d1055c7360 Breakpoint: https://github.com/Ralith/hypermine/blob/50cf2ffd56f0a401983bc53ac18530b0c3198c9a/common/src/graph.rs#L103

There are also three more I found when breakpoints were switched off: ERROR Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0xb9181f0000000029, name = uniforms, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0xe4d96472 | vkCmdDrawIndirect(): Hazard READ_AFTER_WRITE for VkBuffer 0xb9181f0000000029[uniforms] in VkCommandBuffer 0x12f1ea4c920[frame], VkPipeline 0x73a850000000004d[voxels], and VkDescriptorSet 0xc4f3070000000021[], type: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, binding #0 index 0. Access info (usage: SYNC_VERTEX_SHADER_UNIFORM_READ, prior_usage: SYNC_COPY_TRANSFER_WRITE, write_barriers: SYNC_VERTEX_SHADER_SHADER_BINDING_TABLE_READ|SYNC_VERTEX_SHADER_SHADER_SAMPLED_READ|SYNC_VERTEX_SHADER_SHADER_STORAGE_READ|SYNC_FRAGMENT_SHADER_SHADER_BINDING_TABLE_READ|SYNC_FRAGMENT_SHADER_SHADER_SAMPLED_READ|SYNC_FRAGMENT_SHADER_SHADER_STORAGE_READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ|SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, command: vkCmdCopyBuffer, seq_no: 1, reset_no: 47). id=SYNC-HAZARD-READ-AFTER-WRITE number=-455515022 queue_labels= cmd_labels= objects=BUFFER b9181f0000000029 SYNC-HAZARD-READ-AFTER-WRITE

2024-05-04T02:17:01.236408Z ERROR Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0x97c990000000270, name = depth, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0xe4d96472 | vkCmdDraw(): Hazard READ_AFTER_WRITE for VkImageView 0x97c990000000270[depth], in VkCommandBuffer 0x12f1ea4c920[frame], and VkPipeline 0x9f9b41000000003c[fog], VkDescriptorSet 0xc4f3070000000021[], type: VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, imageLayout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, binding #1, index 0. Access info (usage: SYNC_FRAGMENT_SHADER_INPUT_ATTACHMENT_READ, prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: SYNC_EARLY_FRAGMENT_TESTS_DEPTH_STENCIL_ATTACHMENT_READ, command: vkCmdNextSubpass, seq_no: 510, subcmd: 1, renderpass: VkRenderPass 0xf56c9b0000000004[], reset_no: 47). id=SYNC-HAZARD-READ-AFTER-WRITE number=-455515022 queue_labels= cmd_labels= objects=IMAGE_VIEW 97c990000000270 SYNC-HAZARD-READ-AFTER-WRITE

2024-05-04T02:17:01.238118Z ERROR Validation Error: [ SYNC-HAZARD-WRITE-AFTER-WRITE ] Object 0: handle = 0x12f1e51a350, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x5c0ec5d6 | vkQueueSubmit(): Hazard WRITE_AFTER_WRITE for entry 0, VkCommandBuffer 0x12f1ea4eec0[post-frame], Submitted access info (submitted_usage: SYNC_CLEAR_TRANSFER_WRITE, command: vkCmdUpdateBuffer, seq_no: 1, reset_no: 47). Access info (prior_usage: SYNC_CLEAR_TRANSFER_WRITE, write_barriers: SYNC_DRAW_INDIRECT_INDIRECT_COMMAND_READ|SYNC_VERTEX_SHADER_SHADER_BINDING_TABLE_READ|SYNC_VERTEX_SHADER_SHADER_SAMPLED_READ|SYNC_VERTEX_SHADER_SHADER_STORAGE_READ|SYNC_COMPUTE_SHADER_SHADER_BINDING_TABLE_READ|SYNC_COMPUTE_SHADER_SHADER_SAMPLED_READ|SYNC_COMPUTE_SHADER_SHADER_STORAGE_READ, queue: VkQueue 0x12f1e51a350[], submit: 91, batch: 1, batch_tag: 22570, command: vkCmdUpdateBuffer, command_buffer: VkCommandBuffer 0x12f1ea539e0[post-frame], seq_no: 1, reset_no: 45). id=SYNC-HAZARD-WRITE-AFTER-WRITE number=1544472022 queue_labels= cmd_labels= objects=QUEUE 12f1e51a350

I'm not sure if all of these breakpoints are relevant, but hopefully, they can be at least a little helpful in debugging these synchronization hazards. I'm also not sure if this is exhaustive.