Skip to content

Commit 31f8eaa

Browse files
committed
Remove warning about unspecified vkbinding
It is permitted that users omit explicit [vk::binding] settings on register definitions of HLSL-style, as they are opting into the default implicit mapping, as with DXC. That does mean register IDs can clash between resources which have different register type but the same register number. For example: Such a problem can be resolved either with explicit bindings in source, or using the "-fvk-binding" slangc options which match DXC behavior. Closes issue #5938
1 parent 4e62f98 commit 31f8eaa

File tree

3 files changed

+5
-45
lines changed

3 files changed

+5
-45
lines changed

source/slang/slang-parameter-binding.cpp

+5-36
Original file line numberDiff line numberDiff line change
@@ -1060,22 +1060,6 @@ static void addExplicitParameterBindings_HLSL(
10601060
}
10611061
}
10621062

1063-
static void _maybeDiagnoseMissingVulkanLayoutModifier(
1064-
ParameterBindingContext* context,
1065-
DeclRef<VarDeclBase> const& varDecl)
1066-
{
1067-
// If the user didn't specify a `binding` (and optional `set`) for Vulkan,
1068-
// but they *did* specify a `register` for D3D, then that is probably an
1069-
// oversight on their part.
1070-
if (auto registerModifier = varDecl.getDecl()->findModifier<HLSLRegisterSemantic>())
1071-
{
1072-
getSink(context)->diagnose(
1073-
registerModifier,
1074-
Diagnostics::registerModifierButNoVulkanLayout,
1075-
varDecl.getName());
1076-
}
1077-
}
1078-
10791063
static void addExplicitParameterBindings_GLSL(
10801064
ParameterBindingContext* context,
10811065
RefPtr<ParameterInfo> parameterInfo,
@@ -1212,13 +1196,6 @@ static void addExplicitParameterBindings_GLSL(
12121196
return;
12131197

12141198
auto hlslToVulkanLayoutOptions = context->getTargetProgram()->getHLSLToVulkanLayoutOptions();
1215-
bool warnedMissingVulkanLayoutModifier = false;
1216-
// If we are not told how to infer bindings with a compile option, we warn
1217-
if (hlslToVulkanLayoutOptions == nullptr || !hlslToVulkanLayoutOptions->canInferBindings())
1218-
{
1219-
warnedMissingVulkanLayoutModifier = true;
1220-
_maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
1221-
}
12221199

12231200
// We need an HLSL register semantic to to infer from
12241201
auto hlslRegSemantic = varDecl.getDecl()->findModifier<HLSLRegisterSemantic>();
@@ -1254,21 +1231,13 @@ static void addExplicitParameterBindings_GLSL(
12541231
return;
12551232
}
12561233

1257-
// If inference is not enabled for this kind, we can issue a warning
1258-
if (hlslToVulkanLayoutOptions &&
1259-
!hlslToVulkanLayoutOptions->canInfer(vulkanKind, hlslInfo.space))
1260-
{
1261-
if (!warnedMissingVulkanLayoutModifier)
1262-
{
1263-
_maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
1264-
warnedMissingVulkanLayoutModifier = true;
1265-
}
1266-
}
12671234

1268-
if (warnedMissingVulkanLayoutModifier)
1235+
if (hlslToVulkanLayoutOptions == nullptr ||
1236+
!hlslToVulkanLayoutOptions->canInferBindings() ||
1237+
!hlslToVulkanLayoutOptions->canInfer(vulkanKind, hlslInfo.space))
12691238
{
1270-
// If we warn due to invalid bindings and user did not set how to interpret 'hlsl style
1271-
// bindings', we should map `register` 1:1 with equivlent vulkan bindings.
1239+
// If the user did not set how to interpret 'hlsl style bindings', we should map
1240+
// `register` 1:1 with equivlent vulkan bindings.
12721241
if (!hlslToVulkanLayoutOptions || hlslToVulkanLayoutOptions->getKindShiftEnabledFlags() ==
12731242
HLSLToVulkanLayoutOptions::KindFlag::None)
12741243
{

tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl.expected

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
result code = -1
22
standard error = {
3-
tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl(11): warning 39013: shader parameter 'c' has a 'register' specified for D3D, but no '[[vk::binding(...)]]` specified for Vulkan
4-
ConstantBuffer<Data> c : register(b2);
5-
^~~~~~~~
6-
tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl(15): warning 39013: shader parameter 'u' has a 'register' specified for D3D, but no '[[vk::binding(...)]]` specified for Vulkan
7-
RWStructuredBuffer<Data> u : register(u11);
8-
^~~~~~~~
93
tests/diagnostics/hlsl-to-vulkan-shift-diagnostic.hlsl(15): error 39025: conflicting vulkan inferred binding for parameter 'c' overlap is 0 and 0
104
RWStructuredBuffer<Data> u : register(u11);
115
^

tests/diagnostics/vk-bindings.slang.expected

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
result code = -1
22
standard error = {
3-
tests/diagnostics/vk-bindings.slang(6): warning 39013: shader parameter 't' has a 'register' specified for D3D, but no '[[vk::binding(...)]]` specified for Vulkan
4-
Texture2D t : register(t0);
5-
^~~~~~~~
63
tests/diagnostics/vk-bindings.slang(14): error 39015: shader parameter 'b' consumes whole descriptor sets, so the binding must be in the form '[[vk::binding(0, ...)]]'; the non-zero binding '2' is not allowed
74
[[vk::binding(2,1)]]
85
^~~~~~~

0 commit comments

Comments
 (0)