Skip to content

Commit 72f7643

Browse files
authored
[spirv] Clarify error when Globals binding missing (#4519)
When -fvk-bind-register is used, all resource must have corresponding register bindings set, including the Globals cbuffer. This change clarifies the error message when the latter is the cause of failure and directs the user to specify -fvk-bind-globals. Fixes #3781
1 parent e80724a commit 72f7643

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

docs/SPIR-V.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3937,7 +3937,8 @@ codegen for Vulkan:
39373937
option cannot be used together with other binding assignment options.
39383938
It requires all source code resources have ``:register()`` attribute and
39393939
all registers have corresponding Vulkan descriptors specified using this
3940-
option.
3940+
option. If the ``$Globals`` cbuffer resource is used, it must also be bound
3941+
with ``-fvk-bind-globals``.
39413942
- ``-fvk-bind-globals N M``: Places the ``$Globals`` cbuffer at
39423943
descriptor set #M and binding #N. See `HLSL global variables and Vulkan binding`_
39433944
for explanation and examples.

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,14 @@ bool DeclResultIdMapper::decorateResourceBindings() {
22222222
}
22232223
spvBuilder.decorateDSetBinding(var.getSpirvInstr(), setNo, bindNo);
22242224
}
2225-
} else if (bindGlobals && var.isGlobalsBuffer()) {
2225+
} else if (var.isGlobalsBuffer()) {
2226+
if (!bindGlobals) {
2227+
emitError("-fvk-bind-register requires Globals buffer to be bound "
2228+
"with -fvk-bind-globals",
2229+
var.getSourceLocation());
2230+
return false;
2231+
}
2232+
22262233
spvBuilder.decorateDSetBinding(var.getSpirvInstr(), globalsSetNo,
22272234
globalsBindNo);
22282235
} else {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fvk-bind-register t5 0 1 2 -vkbr s3 1 3 4
2+
3+
Texture2D MyTexture : register(t5);
4+
SamplerState MySampler : register(s3, space1);
5+
6+
int globalInteger;
7+
float4 globalFloat4;
8+
9+
float4 main() : SV_Target {
10+
return MyTexture.Sample(MySampler, float2(0.1, 0.2));
11+
}
12+
13+
// CHECK: error: -fvk-bind-register requires Globals buffer to be bound with -fvk-bind-globals

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,10 @@ TEST_F(FileTest, VulkanRegisterBinding1to1MappingInvalidBindNo) {
20152015
TEST_F(FileTest, VulkanRegisterBinding1to1MappingMissingAttr) {
20162016
runFileTest("vk.binding.cl.register.missing-attr.hlsl", Expect::Failure);
20172017
}
2018+
TEST_F(FileTest, VulkanRegisterBinding1to1MappingMissingBindGlobals) {
2019+
runFileTest("vk.binding.cl.register.missing-bind-globals.hlsl",
2020+
Expect::Failure);
2021+
}
20182022
TEST_F(FileTest, VulkanRegisterBinding1to1MappingMissingCLOption) {
20192023
runFileTest("vk.binding.cl.register.missing-cl.hlsl", Expect::Failure);
20202024
}

0 commit comments

Comments
 (0)