Skip to content

Commit 6b36891

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 d138e76 commit 6b36891

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

source/slang/slang-diagnostics.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,20 @@ warning(
21632163
span { loc = "location" } -- No span message: this diagnostic has no meaningful source location
21642164
)
21652165

2166+
warning(
2167+
"special-type-leaks-from-parameter-group",
2168+
31106,
2169+
"Parameter group type includes some members with types which cannot be included in the same binding. These types will be moved into another parameter binding slot.",
2170+
span { loc = "location" }
2171+
)
2172+
2173+
warning(
2174+
"special-type-member-leaks-from-parameter-group",
2175+
31107,
2176+
"",
2177+
span { loc = "member:IRInst", message = "This member will leak into a separate binding slot." }
2178+
)
2179+
21662180
err(
21672181
"invalid-attribute-target",
21682182
31120,

source/slang/slang-legalize-types.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,27 @@ 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+
Diagnostics::SpecialTypeLeaksFromParameterGroup{.location = findFirstUseLoc(type)});
1235+
1236+
// indicate which elements cannot be part of the parameter group
1237+
auto& specialType = legalElementType.getPair()->specialType;
1238+
if (specialType.flavor == LegalType::Flavor::tuple)
1239+
{
1240+
auto specialTuple = specialType.getTuple();
1241+
for (auto specialElement : specialTuple->elements)
1242+
{
1243+
context->m_sink->diagnose(
1244+
Diagnostics::SpecialTypeMemberLeaksFromParameterGroup{.member = specialElement.key});
1245+
}
1246+
}
1247+
}
1248+
12281249
// As a bit of a corner case, if the user requested something
12291250
// like `ConstantBuffer<Texture2D>` the element type would
12301251
// legalize to a "simple" type, and that would be interpreted
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -entry computeMain -target spirv -stage compute -preserve-params
2+
3+
// RTAS can't be a part of this binding, and will leak to a different binding.
4+
//
5+
// CHECK: warning[E31106]
6+
// CHECK:rtas-cbuff-leak.slang:[[# @LINE+2]]:
7+
[vk::push_constant]
8+
cbuffer PushConstants {
9+
int i;
10+
// CHECK: warning[E31107]
11+
// CHECK:rtas-cbuff-leak.slang:[[# @LINE+1]]
12+
RaytracingAccelerationStructure rtas;
13+
};
14+
15+
[numthreads(1,1,1)]
16+
void computeMain()
17+
{
18+
}

0 commit comments

Comments
 (0)