summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ast-natural-layout.cpp6
-rw-r--r--source/slang/slang-ir-layout.cpp11
-rw-r--r--source/slang/slang-ir-peephole.cpp2
-rw-r--r--tests/hlsl-intrinsic/size-of/size-of-tuple.slang48
4 files changed, 66 insertions, 1 deletions
diff --git a/source/slang/slang-ast-natural-layout.cpp b/source/slang/slang-ast-natural-layout.cpp
index f15dee1d1..7643e0433 100644
--- a/source/slang/slang-ast-natural-layout.cpp
+++ b/source/slang/slang-ast-natural-layout.cpp
@@ -153,6 +153,12 @@ NaturalSize ASTNaturalLayoutContext::_calcSizeImpl(Type* type)
// Initialize empty
NaturalSize size = NaturalSize::makeEmpty();
+ // We can't compute the size of an abstract type pack yet.
+ if (isAbstractTypePack(tupleType->getTypePack()))
+ {
+ return NaturalSize::makeInvalid();
+ }
+
// Accumulate over all the member types
for (auto cur = 0; cur < tupleType->getMemberCount(); cur++)
{
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp
index 795f47f55..ac0c79601 100644
--- a/source/slang/slang-ir-layout.cpp
+++ b/source/slang/slang-ir-layout.cpp
@@ -275,15 +275,26 @@ static Result _calcSizeAndAlignment(
{
auto tupleType = cast<IRTupleType>(type);
IRSizeAndAlignment resultLayout;
+ IRIntegerValue lastFieldAlignment = 0;
+ IRType* lastFieldType = NULL;
for (UInt i = 0; i < tupleType->getOperandCount(); i++)
{
auto elementType = tupleType->getOperand(i);
IRSizeAndAlignment fieldTypeLayout;
SLANG_RETURN_ON_FAIL(
getSizeAndAlignment(optionSet, rules, (IRType*)elementType, &fieldTypeLayout));
+ resultLayout.size = rules->adjustOffset(
+ resultLayout.size,
+ fieldTypeLayout.size,
+ lastFieldType,
+ lastFieldAlignment);
resultLayout.size = align(resultLayout.size, fieldTypeLayout.alignment);
resultLayout.alignment =
std::max(resultLayout.alignment, fieldTypeLayout.alignment);
+
+ resultLayout.size += fieldTypeLayout.size;
+ lastFieldType = as<IRType>(elementType);
+ lastFieldAlignment = fieldTypeLayout.alignment;
}
*outSizeAndAlignment = rules->alignCompositeElement(resultLayout);
return SLANG_OK;
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp
index 7f3ff1d68..cafe978f9 100644
--- a/source/slang/slang-ir-peephole.cpp
+++ b/source/slang/slang-ir-peephole.cpp
@@ -281,7 +281,7 @@ struct PeepholeContext : InstPassBase
baseType,
&sizeAlignment)))
break;
- if (sizeAlignment.size == 0)
+ if (sizeAlignment.size == IRSizeAndAlignment::kIndeterminateSize)
break;
IRBuilder builder(module);
diff --git a/tests/hlsl-intrinsic/size-of/size-of-tuple.slang b/tests/hlsl-intrinsic/size-of/size-of-tuple.slang
new file mode 100644
index 000000000..2c7d18e71
--- /dev/null
+++ b/tests/hlsl-intrinsic/size-of/size-of-tuple.slang
@@ -0,0 +1,48 @@
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -dx12 -shaderobj
+//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj
+//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -compute -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name outputBuffer
+
+RWStructuredBuffer<int> outputBuffer;
+
+struct Thing<each T>
+{
+ int val;
+ Tuple<expand each T> tuple;
+};
+
+int tupleSize1<T>(T vals)
+{
+ return sizeof(Tuple<T>);
+}
+
+int tupleSize2<each T>(T vals)
+{
+ return sizeof(Tuple<expand each T>);
+}
+
+int tupleSize3<each T>(T vals)
+{
+ return sizeof(Tuple<int, expand each T>);
+}
+
+int tupleSize4<each T>(T vals)
+{
+ return sizeof(Thing<expand each T>);
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ outputBuffer[0] = tupleSize2(); // CHECK: 0
+ outputBuffer[1] = tupleSize3(); // CHECK-NEXT: 4
+ outputBuffer[2] = tupleSize4(); // CHECK-NEXT: 4
+
+ outputBuffer[3] = tupleSize1(1); // CHECK-NEXT: 4
+ outputBuffer[4] = tupleSize2(1,2); // CHECK-NEXT: 8
+ outputBuffer[5] = tupleSize3(1,2,3); // CHECK-NEXT: 10
+ outputBuffer[6] = tupleSize4(1,2,3,4); // CHECK-NEXT: 14
+}