Skip to content

Commit bfd84a3

Browse files
committed
Add missing capability when QueueFamily scope is used
Also, if this capability is added and the memory model is not otherwise enabled by pragma, enable it as part of postprocessing.
1 parent 36df92e commit bfd84a3

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

SPIRV/GlslangToSpv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6996,6 +6996,10 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
69966996
builder.addCapability(spv::CapabilityVulkanMemoryModelKHR);
69976997
}
69986998

6999+
if (builder.getConstantScalar(scopeId) == spv::ScopeQueueFamily) {
7000+
builder.addCapability(spv::CapabilityVulkanMemoryModelKHR);
7001+
}
7002+
69997003
if (glslangIntermediate->usingVulkanMemoryModel() && builder.getConstantScalar(scopeId) == spv::ScopeDevice) {
70007004
builder.addCapability(spv::CapabilityVulkanMemoryModelDeviceScopeKHR);
70017005
}

SPIRV/SpvPostProcess.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ void Builder::postProcessFeatures() {
436436
}
437437
}
438438
}
439+
440+
// If any Vulkan memory model-specific functionality is used, update the
441+
// OpMemoryModel to match.
442+
if (capabilities.find(spv::CapabilityVulkanMemoryModelKHR) != capabilities.end()) {
443+
memoryModel = spv::MemoryModelVulkanKHR;
444+
addIncorporatedExtension(spv::E_SPV_KHR_vulkan_memory_model, spv::Spv_1_5);
445+
}
439446
}
440447
#endif
441448

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
spv.queueFamilyScope.comp
2+
// Module Version 10300
3+
// Generated by (magic number): 8000a
4+
// Id's are bound by 21
5+
6+
Capability Shader
7+
Capability VulkanMemoryModelKHR
8+
Extension "SPV_KHR_vulkan_memory_model"
9+
1: ExtInstImport "GLSL.std.450"
10+
MemoryModel Logical VulkanKHR
11+
EntryPoint GLCompute 4 "main"
12+
ExecutionMode 4 LocalSize 1 1 1
13+
Source GLSL 450
14+
SourceExtension "GL_KHR_memory_scope_semantics"
15+
Name 4 "main"
16+
Name 7 "Buffer"
17+
MemberName 7(Buffer) 0 "a"
18+
Name 9 "A"
19+
MemberDecorate 7(Buffer) 0 Offset 0
20+
Decorate 7(Buffer) Block
21+
Decorate 9(A) DescriptorSet 0
22+
Decorate 9(A) Binding 0
23+
2: TypeVoid
24+
3: TypeFunction 2
25+
6: TypeInt 32 0
26+
7(Buffer): TypeStruct 6(int)
27+
8: TypePointer StorageBuffer 7(Buffer)
28+
9(A): 8(ptr) Variable StorageBuffer
29+
10: TypeInt 32 1
30+
11: 10(int) Constant 0
31+
12: TypePointer StorageBuffer 6(int)
32+
14: 10(int) Constant 5
33+
15: 10(int) Constant 64
34+
16: 10(int) Constant 2
35+
17: 6(int) Constant 1
36+
18: 6(int) Constant 0
37+
19: 6(int) Constant 66
38+
4(main): 2 Function None 3
39+
5: Label
40+
13: 12(ptr) AccessChain 9(A) 11
41+
20: 6(int) AtomicLoad 13 14 19
42+
Return
43+
FunctionEnd

Test/spv.queueFamilyScope.comp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#version 450
2+
#extension GL_KHR_memory_scope_semantics : require
3+
4+
layout (binding = 0) buffer Buffer { uint a; } A;
5+
6+
void main()
7+
{
8+
atomicLoad(A.a, gl_ScopeQueueFamily, gl_StorageSemanticsBuffer, gl_SemanticsAcquire);
9+
}
10+

gtests/Spv.FromFile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ INSTANTIATE_TEST_SUITE_P(
503503
"spv.memoryScopeSemantics.comp",
504504
"spv.memoryScopeSemantics_Error.comp",
505505
"spv.multiView.frag",
506+
"spv.queueFamilyScope.comp",
506507
"spv.RayGenShader11.rgen",
507508
"spv.subgroup.frag",
508509
"spv.subgroup.geom",

0 commit comments

Comments
 (0)