Skip to content

Commit 5c97fb6

Browse files
committed
Add a diagnostic check to warn when special types leak from param groups
As part of type legalization, certain special types may be removed from parameter group types. For example, in the following structure: [vk::push_constants] cbuffer PushConstants { int i; RaytracingAccelerationStructure rtas; } `rtas` cannot be included in this structure, and will leak out to a different binding. Warn the user when this happens. Fixes #8818
1 parent 6128e51 commit 5c97fb6

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

source/slang/slang-diagnostic-defs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,17 @@ DIAGNOSTIC(
11831183
imageFormatUnsupportedByBackend,
11841184
"Image format '$0' is not explicitly supported by the $1 backend, using supported format '$2' "
11851185
"instead.")
1186+
DIAGNOSTIC(
1187+
31106,
1188+
Warning,
1189+
specialTypeLeaksFromParameterGroup,
1190+
"Parameter group type includes some members with types which cannot be included in the same "
1191+
"binding. These types will be moved into another parameter binding slot.")
1192+
DIAGNOSTIC(
1193+
31107,
1194+
Warning,
1195+
specialTypeLeaksFromParameterGroupElement,
1196+
"Structure member will leak into separate binding.")
11861197

11871198
DIAGNOSTIC(31120, Error, invalidAttributeTarget, "invalid syntax target for user defined attribute")
11881199
DIAGNOSTIC(

source/slang/slang-legalize-types.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,29 @@ LegalType legalizeTypeImpl(TypeLegalizationContext* context, IRType* type)
12251225
else
12261226
{
12271227
legalElementType = legalizeType(context, originalElementType);
1228+
1229+
// When special types leak out of a parameter group, they need to
1230+
// be bound differently. Warn the user when this happens.
1231+
if (legalElementType.flavor == LegalType::Flavor::pair)
1232+
{
1233+
context->m_sink->diagnose(
1234+
findFirstUseLoc(type),
1235+
Diagnostics::specialTypeLeaksFromParameterGroup);
1236+
1237+
// indicate which elements cannot be part of the parameter group
1238+
auto &specialType = legalElementType.getPair()->specialType;
1239+
if (specialType.flavor == LegalType::Flavor::tuple)
1240+
{
1241+
auto specialTuple = specialType.getTuple();
1242+
for (auto specialElement : specialTuple->elements)
1243+
{
1244+
context->m_sink->diagnose(
1245+
specialElement.key,
1246+
Diagnostics::specialTypeLeaksFromParameterGroupElement);
1247+
}
1248+
}
1249+
}
1250+
12281251
// As a bit of a corner case, if the user requested something
12291252
// like `ConstantBuffer<Texture2D>` the element type would
12301253
// legalize to a "simple" type, and that would be interpreted
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -entry computeMain -target spirv -stage compute -preserve-params
2+
3+
// CHECK:rtas-cbuff-leak.slang(8): warning 31106
4+
// CHECK:rtas-cbuff-leak.slang(10): warning 31107
5+
6+
// RTAS can't be a part of this binding, and will leak to a different binding.
7+
[vk::push_constant]
8+
cbuffer PushConstants {
9+
int i;
10+
RaytracingAccelerationStructure rtas;
11+
};
12+
13+
[numthreads(1,1,1)]
14+
void computeMain()
15+
{
16+
}

0 commit comments

Comments
 (0)