From ace9a8dc7e4353b1cf8e846abe2b8dc53ecdbc59 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 25 May 2018 10:01:34 -0400 Subject: Fixes 574. Eliminate empty structs during type legalization (#577) --- source/slang/ir-legalize-types.cpp | 2 ++ source/slang/legalize-types.cpp | 6 ++++++ tests/compute/empty-struct.slang | 19 +++++++++++++++++++ tests/compute/empty-struct.slang.expected.txt | 4 ++++ 4 files changed, 31 insertions(+) create mode 100644 tests/compute/empty-struct.slang create mode 100644 tests/compute/empty-struct.slang.expected.txt diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp index 86907dfde..df3e190e1 100644 --- a/source/slang/ir-legalize-types.cpp +++ b/source/slang/ir-legalize-types.cpp @@ -818,6 +818,8 @@ static LegalVal legalizeInst( args, inst->getOperandCount()); + case kIROp_undefined: + return LegalVal(); default: // TODO: produce a user-visible diagnostic here SLANG_UNEXPECTED("non-simple operand(s)!"); diff --git a/source/slang/legalize-types.cpp b/source/slang/legalize-types.cpp index bbfa6264d..6ab597d93 100644 --- a/source/slang/legalize-types.cpp +++ b/source/slang/legalize-types.cpp @@ -301,6 +301,12 @@ struct TupleTypeBuilder LegalType getResult() { + // If this is an empty struct, return a none type + // This helps get rid of emtpy structs that often trips up the + // downstream compiler + if (!anyOrdinary && !anySpecial && !anyComplex) + return LegalType::tuple(new TuplePseudoType()); + // If we didn't see anything "special" // then we can use the type as-is. // we can conceivably just use the type as-is diff --git a/tests/compute/empty-struct.slang b/tests/compute/empty-struct.slang new file mode 100644 index 000000000..51094fad5 --- /dev/null +++ b/tests/compute/empty-struct.slang @@ -0,0 +1,19 @@ +//TEST(smoke,compute):COMPARE_COMPUTE: +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +// Confirm that generics syntax can be used in user +// code and generates valid output. + +RWStructuredBuffer outputBuffer; + +struct Simple +{ + float getVal() {return 1.0;} +}; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + Simple s; + float outVal = s.getVal(); + outputBuffer[dispatchThreadID.x] = outVal; +} \ No newline at end of file diff --git a/tests/compute/empty-struct.slang.expected.txt b/tests/compute/empty-struct.slang.expected.txt new file mode 100644 index 000000000..e143b7f20 --- /dev/null +++ b/tests/compute/empty-struct.slang.expected.txt @@ -0,0 +1,4 @@ +3F800000 +3F800000 +3F800000 +3F800000 \ No newline at end of file -- cgit v1.2.3