KhronosGroup / KhronosGroup/Vulkan-ValidationLayers

SYNC-HAZARD-READ_AFTER_WRITE: false positive with VK_EXT_fragment_shader_interlock

Open
#4,387 4 comments 0 reactions 0 assignees View on GitHub
Synchronization
Dominant language
C++
Stars
1k
Forks
504
Avg merge
11h 35m
Merged PRs (30d)
224

Description

**Describe the Issue**

I'm hitting SYNC-HAZARD-READ_AFTER_WRITE in the validation layers for VK_LAYER_KHRONOS_validation, while using the [VK_EXT_fragment_shader_interlock](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_fragment_shader_interlock.html) interlock extension.

**Specific use case:**

1. Issue a draw that stores to an image from inside the interlock
2. Issue a second draw that then loads the same image from inside the interlock

```
..\..\src\tests\test_utils\ANGLETest.cpp(65): error: RendererVk.cpp:834 (DebugUtilsMessenger): [ SYNC-HAZARD-READ_AFTER_WRITE ] Validation Error: [ SYNC-HAZARD-READ_AFTER_WRITE ] Object 0: handle = 0x7f000000007f, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0x4cb75b2d | vkCmdDraw: Hazard READ_AFTER_WRITE for VkImageView 0x7f000000007f[], in VkCommandBuffer 0x1ff0a57eca0[], and VkPipeline 0x880000000088[], VkDescriptorSet 0x8a000000008a[], type: VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, imageLayout: VK_IMAGE_LAYOUT_GENERAL, binding #1, index 0. Access info (usage: SYNC_FRAGMENT_SHADER_SHADER_STORAGE_READ, prior_usage: SYNC_FRAGMENT_SHADER_SHADER_STORAGE_WRITE, write_barriers: 0, command: vkCmdDraw, seq_no: 13, reset_no: 1).
Object: 0x7f000000007f (type = Image View(14))
```

One workaround is to also store to the image during draw #(2), after it has been loaded. This can even be done in a branch that never executes:

```
imageLoad(...);

// Inserting the following block fixes the validation error.
if (myUniformThatEquals0 != 0.0) // Never executes
imageStore(...);
```

This appears to be a false positive because the interlock provides the necessary synchronization and ordering guarantees.

**Other experiments:**
- All tests pass (on NVIDIA and Intel both) if I just turn off validation layers
- All tests fail again (on NVIDIA and Intel both) if I turn off validation layers *and* don't use the interlock

**Environment:**
- OS: Windows 11
- GPU: NVIDIA NVIDIA GeForce RTX 3050 Laptop GPU (0x000025A2)), NVIDIA-512.78.0.0
- SDK or header version if building from repo: https://github.com/KhronosGroup/Vulkan-ValidationLayers/tree/aa7ee26f15bfbe8bf5564e6af3d499e07da8e776
- Options enabled (synchronization, best practices, etc.): spv::CapabilityFragmentShaderPixelInterlockEXT, SPIRVExtensions::FragmentShaderInterlockEXT, spv::ExecutionMode::ExecutionModePixelInterlockOrderedEXT

Contributor guide

Open the contributing guide

Research direction

The report points to ANGLETest.cpp:65 and RendererVk.cpp:834 in the validation output; begin by reproducing the two-draw image load/store case with fragment shader interlock enabled. Trace the synchronization validation path for the reported READ_AFTER_WRITE and compare its handling of the listed interlock execution modes. Done means the false positive no longer appears while the no-interlock case remains diagnosed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.