Vulkan顶点着色器用SSBO遇vertexPipelineStoresAndAtomics验证警告
vertexPipelineStoresAndAtomics Warning First, let's recap your setup and the issue:
You've written GLSL code for a vertex shader using a read-only SSBO:
layout(binding = 1) readonly buffer MyBuffer { vec3 buf[]; } myBuffer; // ... vec3 test = myBuffer[gl_VertexIndex]; // Note: Syntax error here!
You compiled it with glslc to SPIR-V (with NonWriteable opcode), set up descriptor sets correctly on the CPU, and the functionality works fine—but the validation layer throws this warning:
ERROR: [Validation] Code 15 : Object: VK_NULL_HANDLE (Type = 0) | Shader requires vertexPipelineStoresAndAtomics but is not enabled on the device
You're right to be confused: vertexPipelineStoresAndAtomics is only required for writes/atomic operations in non-compute shaders, and you're only reading data. Here's what's going on:
Why This Warning Happens
This is mostly a validation layer false positive, but there's a syntax issue in your code that might be contributing:
- Incorrect SSBO Access: Your code tries to index
myBufferdirectly, butmyBufferis the buffer block—you need to index the inner arraybufinstead. The line should bevec3 test = myBuffer.buf[gl_VertexIndex];. Even if your code "works" (maybe the compiler is being lenient), this incorrect syntax can cause the GLSL compiler to generate unexpected SPIR-V instructions, which the validation layer misinterprets as requiring atomic operations support. - Compiler Quirk: Even with correct syntax, some versions of
glslcwill generate SPIR-V that includes atomic-related instructions for SSBO array access in vertex shaders, even for read-only operations. The validation layer sees these instructions and incorrectly flags the need forvertexPipelineStoresAndAtomics.
Fixes to Eliminate the Warning
- Fix the SSBO Access Syntax: Correct the line to
myBuffer.buf[gl_VertexIndex]. This is the proper way to access the array inside the buffer block, and it often makes the compiler generate cleaner SPIR-V that avoids the validation layer trigger. - Add a Compiler Flag: When compiling with
glslc, add the-fno-vertex-pipeline-stores-and-atomicsflag. This forces the compiler to omit any vertex pipeline store/atomic instructions, even if it would normally generate them, which makes the validation layer happy. - Ignore the False Positive: Since you're only performing read operations and the functionality works as expected, this warning doesn't affect your program's correctness. If you don't want to modify code or build settings, you can safely ignore it (though fixing the syntax is still good practice).
Remember: You never need to enable vertexPipelineStoresAndAtomics for read-only SSBO access in vertex shaders—this is definitely a validation layer misjudgment in this scenario.
内容的提问来源于stack exchange,提问作者FrickeFresh

