glslang icon indicating copy to clipboard operation
glslang copied to clipboard

VulkanMemoryModelDeviceScopeKHR capability missing form SPIRV

Open MatejSakmary opened this issue 1 year ago • 1 comments

When requesting GL_KHR_memory_scope_semantics the generated SPIRV is missing OpCapability VulkanMemoryModelDeviceScopeKHR. I tested this by compiling a similar shader to the following

#version 460

#extension GL_KHR_memory_scope_semantics : require

layout(local_size_x = 1) in;
shared int i;
void main()
{
    atomicAdd(i, 1, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsAcquire | gl_SemanticsMakeVisible);
}

and reading the disassembly (generated by spirv-dis.exe). Only OpCapability VulkanMemoryModel is present. This is caught by Vulkan validation layers and reported as the following error:

Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] | MessageID = 0x2a1bf17f | SPIR-V module not valid: Use of device scope with VulkanKHR memory model requires the VulkanMemoryModelDeviceScopeKHR capability
  OpMemoryBarrier %uint_1 %uint_24648

Note: Here the instruction reported is MemoryBarrier but the same should apply for other instructions affected by the GL_KHR_memory_scope_semantics extension.

When manually adding the OpCapability VulkanMemoryModelDeviceScopeKHR to the spirv there are no validation layer errors reported.

The shader was compiled via glslang --target-env spirv1.6 -V shader.comp -o shader.comp.spv. Glslang version:

Glslang Version: 11:12.3.1
ESSL Version: OpenGL ES GLSL 3.20 glslang Khronos. 12.3.1
GLSL Version: 4.60 glslang Khronos. 12.3.1
SPIR-V Version 0x00010600, Revision 1
GLSL.std.450 Version 100, Revision 1
Khronos Tool ID 8
SPIR-V Generator Version 11
GL_KHR_vulkan_glsl version 100
ARB_GL_gl_spirv version 100

MatejSakmary avatar Dec 02 '23 02:12 MatejSakmary

This does seem to be a bug and unfortunately seems to have escaped the unit tests. It seems like the code to add the capabilities when the scope arguments are passed to atomicAdd and friends was never added.

arcady-lunarg avatar Jan 31 '24 21:01 arcady-lunarg