Skip to content

Commit ace9a8d

Browse files
csyongheTim Foley
authored and
Tim Foley
committed
Fixes 574. Eliminate empty structs during type legalization (shader-slang#577)
1 parent 18709fb commit ace9a8d

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

source/slang/ir-legalize-types.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ static LegalVal legalizeInst(
818818
args,
819819
inst->getOperandCount());
820820

821+
case kIROp_undefined:
822+
return LegalVal();
821823
default:
822824
// TODO: produce a user-visible diagnostic here
823825
SLANG_UNEXPECTED("non-simple operand(s)!");

source/slang/legalize-types.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ struct TupleTypeBuilder
301301

302302
LegalType getResult()
303303
{
304+
// If this is an empty struct, return a none type
305+
// This helps get rid of emtpy structs that often trips up the
306+
// downstream compiler
307+
if (!anyOrdinary && !anySpecial && !anyComplex)
308+
return LegalType::tuple(new TuplePseudoType());
309+
304310
// If we didn't see anything "special"
305311
// then we can use the type as-is.
306312
// we can conceivably just use the type as-is

tests/compute/empty-struct.slang

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//TEST(smoke,compute):COMPARE_COMPUTE:
2+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
3+
// Confirm that generics syntax can be used in user
4+
// code and generates valid output.
5+
6+
RWStructuredBuffer<float> outputBuffer;
7+
8+
struct Simple
9+
{
10+
float getVal() {return 1.0;}
11+
};
12+
13+
[numthreads(4, 1, 1)]
14+
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
15+
{
16+
Simple s;
17+
float outVal = s.getVal();
18+
outputBuffer[dispatchThreadID.x] = outVal;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3F800000
2+
3F800000
3+
3F800000
4+
3F800000

0 commit comments

Comments
 (0)