Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/slang/slang-ast-natural-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
11 changes: 11 additions & 0 deletions source/slang/slang-ir-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions source/slang/slang-ir-peephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ struct PeepholeContext : InstPassBase
baseType,
&sizeAlignment)))
break;
if (sizeAlignment.size == 0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to bail if sizeAlignment.size == IRSizeAndAlignment::kIndeterminateSize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. I pushed a commit to take this into account.

break;

IRBuilder builder(module);
IRBuilderSourceLocRAII srcLocRAII(&builder, inst->sourceLoc);
Expand Down
48 changes: 48 additions & 0 deletions tests/hlsl-intrinsic/size-of/size-of-tuple.slang
Original file line number Diff line number Diff line change
@@ -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
}
Loading