summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-18 20:46:57 -0700
committerGitHub <noreply@github.com>2023-09-18 20:46:57 -0700
commitd1efc69a20d941116d1398e4471689658cd6b888 (patch)
tree22d7e56c02cea2d125ba483089a85205bbf45c15
parent95fcf65c38d52ed458a3b11622ea8b55a3864c24 (diff)
Use target-dependent pointer size in natural layout. (#3210)
Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--source/slang/slang-emit-spirv.cpp20
-rw-r--r--source/slang/slang-ir-any-value-inference.cpp5
-rw-r--r--source/slang/slang-ir-any-value-inference.h1
-rw-r--r--source/slang/slang-ir-byte-address-legalize.cpp16
-rw-r--r--source/slang/slang-ir-dll-import.cpp2
-rw-r--r--source/slang/slang-ir-extract-value-from-type.cpp12
-rw-r--r--source/slang/slang-ir-generics-lowering-context.cpp6
-rw-r--r--source/slang/slang-ir-layout.cpp53
-rw-r--r--source/slang/slang-ir-layout.h12
-rw-r--r--source/slang/slang-ir-lower-append-consume-structured-buffer.cpp2
-rw-r--r--source/slang/slang-ir-lower-bit-cast.cpp8
-rw-r--r--source/slang/slang-ir-lower-buffer-element-type.cpp6
-rw-r--r--source/slang/slang-ir-lower-generics.cpp2
-rw-r--r--source/slang/slang-ir-lower-reinterpret.cpp2
-rw-r--r--source/slang/slang-ir-lower-size-of.cpp2
-rw-r--r--source/slang/slang-ir-spirv-legalize.cpp6
-rw-r--r--tests/expected-failure.txt1
17 files changed, 93 insertions, 63 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 88fb8b0fe..b373383aa 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1282,7 +1282,7 @@ struct SPIRVEmitContext
else
{
IRSizeAndAlignment sizeAndAlignment;
- getNaturalSizeAndAlignment(elementType, &sizeAndAlignment);
+ getNaturalSizeAndAlignment(m_targetRequest, elementType, &sizeAndAlignment);
stride = (int)sizeAndAlignment.getStride();
}
emitOpDecorateArrayStride(
@@ -2127,9 +2127,23 @@ struct SPIRVEmitContext
return emitOpUndef(parent, inst, inst->getDataType());
case kIROp_SPIRVAsm:
return emitSPIRVAsm(parent, as<IRSPIRVAsm>(inst));
+ case kIROp_ImageLoad:
+ return emitImageLoad(parent, as<IRImageLoad>(inst));
+ case kIROp_ImageStore:
+ return emitImageStore(parent, as<IRImageStore>(inst));
}
}
+ SpvInst* emitImageLoad(SpvInstParent* parent, IRImageLoad* load)
+ {
+ return emitInst(parent, load, SpvOpImageRead, load->getDataType(), kResultID, load->getImage(), load->getCoord());
+ }
+
+ SpvInst* emitImageStore(SpvInstParent* parent, IRImageStore* store)
+ {
+ return emitInst(parent, store, SpvOpImageWrite, store->getImage(), store->getCoord(), store->getValue());
+ }
+
SpvInst* emitGetStringHash(IRInst* inst)
{
auto getStringHashInst = as<IRGetStringHash>(inst);
@@ -2415,7 +2429,7 @@ struct SPIRVEmitContext
}
else
{
- getOffset(IRTypeLayoutRules::get(layoutRuleName), field, &offset);
+ getOffset(m_targetRequest, IRTypeLayoutRules::get(layoutRuleName), field, &offset);
}
emitOpMemberDecorateOffset(
getSection(SpvLogicalSectionID::Annotations),
@@ -2440,7 +2454,7 @@ struct SPIRVEmitContext
IRIntegerValue matrixStride = 0;
auto rule = IRTypeLayoutRules::get(layoutRuleName);
IRSizeAndAlignment elementSizeAlignment;
- getSizeAndAlignment(rule, matrixType->getElementType(), &elementSizeAlignment);
+ getSizeAndAlignment(m_targetRequest, rule, matrixType->getElementType(), &elementSizeAlignment);
// Reminder: the meaning of row/column major layout
// in our semantics is the *opposite* of what GLSL/SPIRV
diff --git a/source/slang/slang-ir-any-value-inference.cpp b/source/slang/slang-ir-any-value-inference.cpp
index eb4aa670f..ae3e67397 100644
--- a/source/slang/slang-ir-any-value-inference.cpp
+++ b/source/slang/slang-ir-any-value-inference.cpp
@@ -86,6 +86,7 @@ namespace Slang
}
void inferAnyValueSizeWhereNecessary(
+ TargetRequest* targetReq,
IRModule* module)
{
// Go through the global insts and collect all interface types.
@@ -212,7 +213,7 @@ namespace Slang
for (auto implType : mapInterfaceToImplementations[interfaceType])
{
IRSizeAndAlignment sizeAndAlignment;
- getNaturalSizeAndAlignment((IRType*)implType, &sizeAndAlignment);
+ getNaturalSizeAndAlignment(targetReq, (IRType*)implType, &sizeAndAlignment);
maxAnyValueSize = Math::Max(maxAnyValueSize, sizeAndAlignment.size);
}
@@ -228,4 +229,4 @@ namespace Slang
}
}
}
-}; \ No newline at end of file
+};
diff --git a/source/slang/slang-ir-any-value-inference.h b/source/slang/slang-ir-any-value-inference.h
index eb202d626..a7911ff23 100644
--- a/source/slang/slang-ir-any-value-inference.h
+++ b/source/slang/slang-ir-any-value-inference.h
@@ -9,5 +9,6 @@
namespace Slang
{
void inferAnyValueSizeWhereNecessary(
+ TargetRequest* targetReq,
IRModule* module);
}
diff --git a/source/slang/slang-ir-byte-address-legalize.cpp b/source/slang/slang-ir-byte-address-legalize.cpp
index b4de66d77..e405dd606 100644
--- a/source/slang/slang-ir-byte-address-legalize.cpp
+++ b/source/slang/slang-ir-byte-address-legalize.cpp
@@ -208,18 +208,18 @@ struct ByteAddressBufferLegalizationContext
{
if (target->getHLSLToVulkanLayoutOptions() && target->getHLSLToVulkanLayoutOptions()->shouldUseGLLayout())
{
- return getStd430Offset(field, outOffset);
+ return getStd430Offset(target, field, outOffset);
}
- return getNaturalOffset(field, outOffset);
+ return getNaturalOffset(target, field, outOffset);
}
SlangResult getSizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAndAlignment* outSizeAlignment)
{
if (target->getHLSLToVulkanLayoutOptions() && target->getHLSLToVulkanLayoutOptions()->shouldUseGLLayout())
{
- return getStd430SizeAndAlignment(type, outSizeAlignment);
+ return getStd430SizeAndAlignment(target, type, outSizeAlignment);
}
- return getNaturalSizeAndAlignment(type, outSizeAlignment);
+ return getNaturalSizeAndAlignment(target, type, outSizeAlignment);
}
// The core workhorse routine for the load case is `emitLegalLoad`,
@@ -456,7 +456,7 @@ struct ByteAddressBufferLegalizationContext
// the "stride" of the element type.
//
IRSizeAndAlignment elementLayout;
- SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(elementType, &elementLayout));
+ SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(m_target, elementType, &elementLayout));
IRIntegerValue elementStride = elementLayout.getStride();
// We will collect all the element values into an array so
@@ -546,7 +546,7 @@ struct ByteAddressBufferLegalizationContext
auto offsetType = offset->getDataType();
IRSizeAndAlignment typeLayout;
- SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(type, &typeLayout));
+ SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(m_target, type, &typeLayout));
auto typeStrideVal = typeLayout.getStride();
auto typeStrideInst = m_builder.getIntValue(offsetType, typeStrideVal);
@@ -952,7 +952,7 @@ struct ByteAddressBufferLegalizationContext
auto indexType = offset->getDataType();
IRSizeAndAlignment typeLayout;
- SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(type, &typeLayout));
+ SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(m_target, type, &typeLayout));
auto typeStride = m_builder.getIntValue(indexType, typeLayout.getStride());
@@ -980,7 +980,7 @@ struct ByteAddressBufferLegalizationContext
// We iterate over the elements and fetch then store each one.
//
IRSizeAndAlignment elementLayout;
- SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(elementType, &elementLayout));
+ SLANG_RETURN_ON_FAIL(getNaturalSizeAndAlignment(m_target, elementType, &elementLayout));
IRIntegerValue elementStride = elementLayout.getStride();
auto indexType = m_builder.getIntType();
diff --git a/source/slang/slang-ir-dll-import.cpp b/source/slang/slang-ir-dll-import.cpp
index a2a0c7071..2da89ad3e 100644
--- a/source/slang/slang-ir-dll-import.cpp
+++ b/source/slang/slang-ir-dll-import.cpp
@@ -91,7 +91,7 @@ struct DllImportContext
for (auto param : func->getParams())
{
IRSizeAndAlignment sizeAndAlignment;
- getNaturalSizeAndAlignment(param->getDataType(), &sizeAndAlignment);
+ getNaturalSizeAndAlignment(targetReq, param->getDataType(), &sizeAndAlignment);
result += (uint32_t)align(sizeAndAlignment.size, 4);
}
return result;
diff --git a/source/slang/slang-ir-extract-value-from-type.cpp b/source/slang/slang-ir-extract-value-from-type.cpp
index ba3b73736..fa8c6e441 100644
--- a/source/slang/slang-ir-extract-value-from-type.cpp
+++ b/source/slang/slang-ir-extract-value-from-type.cpp
@@ -42,8 +42,8 @@ FindLeafValueResult findLeafValueAtOffset(
{
IRIntegerValue fieldOffset = 0;
IRSizeAndAlignment fieldLayout;
- CHECK(getNaturalSizeAndAlignment(field->getFieldType(), &fieldLayout));
- CHECK(getNaturalOffset(field, &fieldOffset));
+ CHECK(getNaturalSizeAndAlignment(targetReq, field->getFieldType(), &fieldLayout));
+ CHECK(getNaturalOffset(targetReq, field, &fieldOffset));
if (fieldOffset + fieldLayout.size > offset)
{
if (fieldOffset > offset)
@@ -81,7 +81,7 @@ FindLeafValueResult findLeafValueAtOffset(
auto arrayType = as<IRArrayType>(dataType);
auto elementType = arrayType->getElementType();
IRSizeAndAlignment elementLayout;
- CHECK(getNaturalSizeAndAlignment(elementType, &elementLayout));
+ CHECK(getNaturalSizeAndAlignment(targetReq, elementType, &elementLayout));
if (elementLayout.getStride() == 0)
{
result.leafValue = builder.getIntValue(builder.getUIntType(), 0);
@@ -106,7 +106,7 @@ FindLeafValueResult findLeafValueAtOffset(
auto vectorType = as<IRVectorType>(dataType);
auto elementType = vectorType->getElementType();
IRSizeAndAlignment elementLayout;
- CHECK(getNaturalSizeAndAlignment(elementType, &elementLayout));
+ CHECK(getNaturalSizeAndAlignment(targetReq, elementType, &elementLayout));
uint32_t index =
elementLayout.getStride() == 0 ? 0 : (uint32_t)(offset / elementLayout.getStride());
auto elementValue = builder.emitElementExtract(
@@ -129,7 +129,7 @@ FindLeafValueResult findLeafValueAtOffset(
auto columnCount = as<IRIntLit>(matrixType->getColumnCount())->value.intVal;
auto rowType = builder.getVectorType(elementType, matrixType->getColumnCount());
IRSizeAndAlignment rowLayout;
- CHECK(getNaturalSizeAndAlignment(rowType, &rowLayout));
+ CHECK(getNaturalSizeAndAlignment(targetReq, rowType, &rowLayout));
uint32_t rowIndex = rowLayout.getStride() == 0
? 0
: (uint32_t)(offset / (columnCount * rowLayout.getStride()));
@@ -266,7 +266,7 @@ IRInst* extractValueAtOffset(
{
auto dataType = src->getDataType();
IRSizeAndAlignment typeLayout;
- SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(dataType, &typeLayout));
+ SLANG_RETURN_NULL_ON_FAIL(getNaturalSizeAndAlignment(targetReq, dataType, &typeLayout));
if (offset + size > typeLayout.size)
{
return builder.getIntValue(builder.getIntType(), 0);
diff --git a/source/slang/slang-ir-generics-lowering-context.cpp b/source/slang/slang-ir-generics-lowering-context.cpp
index 2172e7d21..325568040 100644
--- a/source/slang/slang-ir-generics-lowering-context.cpp
+++ b/source/slang/slang-ir-generics-lowering-context.cpp
@@ -66,7 +66,7 @@ namespace Slang
// For now the only type info we encapsualte is type size.
IRSizeAndAlignment sizeAndAlignment;
- getNaturalSizeAndAlignment((IRType*)typeInst, &sizeAndAlignment);
+ getNaturalSizeAndAlignment(targetReq, (IRType*)typeInst, &sizeAndAlignment);
builder->addRTTITypeSizeDecoration(result, sizeAndAlignment.size);
// Give a name to the rtti object.
@@ -234,7 +234,7 @@ namespace Slang
// value must be stored out-of-line.
//
IRSizeAndAlignment sizeAndAlignment;
- Result result = getNaturalSizeAndAlignment(concreteType, &sizeAndAlignment);
+ Result result = getNaturalSizeAndAlignment(targetReq, concreteType, &sizeAndAlignment);
if(SLANG_FAILED(result) || (sizeAndAlignment.size > anyValueSize))
{
// If the value must be stored out-of-line, we construct
@@ -385,7 +385,7 @@ namespace Slang
if (outLimit) *outLimit = anyValueSize;
IRSizeAndAlignment sizeAndAlignment;
- Result result = getNaturalSizeAndAlignment(concreteType, &sizeAndAlignment);
+ Result result = getNaturalSizeAndAlignment(targetReq, concreteType, &sizeAndAlignment);
if (outTypeSize) *outTypeSize = sizeAndAlignment.size;
if(SLANG_FAILED(result) || (sizeAndAlignment.size > anyValueSize))
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp
index 39210ea1d..c87eca587 100644
--- a/source/slang/slang-ir-layout.cpp
+++ b/source/slang/slang-ir-layout.cpp
@@ -51,6 +51,7 @@
namespace Slang
{
static Result _calcArraySizeAndAlignment(
+ TargetRequest* target,
IRTypeLayoutRules* rules,
IRType* elementType,
IRInst* elementCountInst,
@@ -68,7 +69,7 @@ static Result _calcArraySizeAndAlignment(
}
IRSizeAndAlignment elementTypeLayout;
- SLANG_RETURN_ON_FAIL(getSizeAndAlignment(rules, elementType, &elementTypeLayout));
+ SLANG_RETURN_ON_FAIL(getSizeAndAlignment(target, rules, elementType, &elementTypeLayout));
elementTypeLayout = rules->alignCompositeElement(elementTypeLayout);
*outSizeAndAlignment = IRSizeAndAlignment(
@@ -84,10 +85,21 @@ IRIntegerValue getIntegerValueFromInst(IRInst* inst)
}
static Result _calcSizeAndAlignment(
+ TargetRequest* target,
IRTypeLayoutRules* rules,
IRType* type,
IRSizeAndAlignment* outSizeAndAlignment)
{
+ int kPointerSize = 8;
+ switch (target->getTarget())
+ {
+ case CodeGenTarget::HostCPPSource:
+ case CodeGenTarget::HostHostCallable:
+ case CodeGenTarget::HostExecutable:
+ kPointerSize = (int)sizeof(void*);
+ break;
+ }
+
switch (type->getOp())
{
@@ -113,8 +125,8 @@ case kIROp_##TYPE##Type: \
BASE(Int64, 8);
BASE(UInt64, 8);
- BASE(IntPtr, 8);
- BASE(UIntPtr, 8);
+ BASE(IntPtr, kPointerSize);
+ BASE(UIntPtr, kPointerSize);
BASE(Double, 8);
// We are currently handling `bool` following the HLSL
@@ -143,7 +155,7 @@ case kIROp_##TYPE##Type: \
for (auto field : structType->getFields())
{
IRSizeAndAlignment fieldTypeLayout;
- SLANG_RETURN_ON_FAIL(getSizeAndAlignment(rules, field->getFieldType(), &fieldTypeLayout));
+ SLANG_RETURN_ON_FAIL(getSizeAndAlignment(target, rules, field->getFieldType(), &fieldTypeLayout));
structLayout.size = align(offset, fieldTypeLayout.alignment);
structLayout.alignment = std::max(structLayout.alignment, fieldTypeLayout.alignment);
@@ -182,6 +194,7 @@ case kIROp_##TYPE##Type: \
auto arrayType = cast<IRArrayType>(type);
return _calcArraySizeAndAlignment(
+ target,
rules ,
arrayType->getElementType(),
arrayType->getElementCount(),
@@ -193,7 +206,7 @@ case kIROp_##TYPE##Type: \
{
auto vecType = cast<IRVectorType>(type);
IRSizeAndAlignment elementTypeLayout;
- getSizeAndAlignment(rules, vecType->getElementType(), &elementTypeLayout);
+ getSizeAndAlignment(target, rules, vecType->getElementType(), &elementTypeLayout);
*outSizeAndAlignment = rules->getVectorSizeAndAlignment(elementTypeLayout, getIntegerValueFromInst(vecType->getElementCount()));
return SLANG_OK;
}
@@ -215,7 +228,7 @@ case kIROp_##TYPE##Type: \
{
auto elementType = tupleType->getOperand(i);
IRSizeAndAlignment fieldTypeLayout;
- SLANG_RETURN_ON_FAIL(getSizeAndAlignment(rules, (IRType*)elementType, &fieldTypeLayout));
+ SLANG_RETURN_ON_FAIL(getSizeAndAlignment(target, rules, (IRType*)elementType, &fieldTypeLayout));
resultLayout.size = align(resultLayout.size, fieldTypeLayout.alignment);
resultLayout.alignment = std::max(resultLayout.alignment, fieldTypeLayout.alignment);
}
@@ -253,6 +266,7 @@ case kIROp_##TYPE##Type: \
{
auto colVector = builder.getVectorType(matType->getElementType(), matType->getRowCount());
return _calcArraySizeAndAlignment(
+ target,
rules,
colVector,
matType->getColumnCount(),
@@ -262,6 +276,7 @@ case kIROp_##TYPE##Type: \
{
auto rowVector = builder.getVectorType(matType->getElementType(), matType->getColumnCount());
return _calcArraySizeAndAlignment(
+ target,
rules,
rowVector,
matType->getRowCount(),
@@ -279,7 +294,7 @@ case kIROp_##TYPE##Type: \
case kIROp_NativeStringType:
case kIROp_HLSLConstBufferPointerType:
{
- *outSizeAndAlignment = IRSizeAndAlignment(8, 8);
+ *outSizeAndAlignment = IRSizeAndAlignment(kPointerSize, kPointerSize);
return SLANG_OK;
}
break;
@@ -307,7 +322,7 @@ IRSizeAndAlignmentDecoration* findSizeAndAlignmentDecorationForLayout(IRType* ty
return nullptr;
}
-Result getSizeAndAlignment(IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
+Result getSizeAndAlignment(TargetRequest* target, IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
{
if (auto decor = findSizeAndAlignmentDecorationForLayout(type, rules->ruleName))
{
@@ -316,7 +331,7 @@ Result getSizeAndAlignment(IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlig
}
IRSizeAndAlignment sizeAndAlignment;
- SLANG_RETURN_ON_FAIL(_calcSizeAndAlignment(rules, type, &sizeAndAlignment));
+ SLANG_RETURN_ON_FAIL(_calcSizeAndAlignment(target, rules, type, &sizeAndAlignment));
if (auto module = type->getModule())
{
@@ -347,7 +362,7 @@ IROffsetDecoration* findOffsetDecorationForLayout(IRStructField* field, IRTypeLa
return nullptr;
}
-Result getOffset(IRTypeLayoutRules* rules, IRStructField* field, IRIntegerValue* outOffset)
+Result getOffset(TargetRequest* target, IRTypeLayoutRules* rules, IRStructField* field, IRIntegerValue* outOffset)
{
if (auto decor = findOffsetDecorationForLayout(field, rules->ruleName))
{
@@ -365,7 +380,7 @@ Result getOffset(IRTypeLayoutRules* rules, IRStructField* field, IRIntegerValue*
return SLANG_FAIL;
IRSizeAndAlignment structTypeLayout;
- SLANG_RETURN_ON_FAIL(getSizeAndAlignment(rules, structType, &structTypeLayout));
+ SLANG_RETURN_ON_FAIL(getSizeAndAlignment(target, rules, structType, &structTypeLayout));
if (auto decor = findOffsetDecorationForLayout(field, rules->ruleName))
{
@@ -451,15 +466,15 @@ struct Std140LayoutRules : IRTypeLayoutRules
}
};
-Result getNaturalSizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
+Result getNaturalSizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
{
- return getSizeAndAlignment(IRTypeLayoutRules::getNatural(), type, outSizeAndAlignment);
+ return getSizeAndAlignment(target, IRTypeLayoutRules::getNatural(), type, outSizeAndAlignment);
}
-Result getNaturalOffset(IRStructField* field, IRIntegerValue* outOffset)
+Result getNaturalOffset(TargetRequest* target, IRStructField* field, IRIntegerValue* outOffset)
{
- return getOffset(IRTypeLayoutRules::getNatural(), field, outOffset);
+ return getOffset(target, IRTypeLayoutRules::getNatural(), field, outOffset);
}
@@ -467,14 +482,14 @@ Result getNaturalOffset(IRStructField* field, IRIntegerValue* outOffset)
// Std430 Layout
//////////////////////////
-Result getStd430SizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
+Result getStd430SizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAndAlignment* outSizeAndAlignment)
{
- return getSizeAndAlignment(IRTypeLayoutRules::getStd430(), type, outSizeAndAlignment);
+ return getSizeAndAlignment(target, IRTypeLayoutRules::getStd430(), type, outSizeAndAlignment);
}
-Result getStd430Offset(IRStructField* field, IRIntegerValue* outOffset)
+Result getStd430Offset(TargetRequest* target, IRStructField* field, IRIntegerValue* outOffset)
{
- return getOffset(IRTypeLayoutRules::getStd430(), field, outOffset);
+ return getOffset(target, IRTypeLayoutRules::getStd430(), field, outOffset);
}
IRTypeLayoutRules* IRTypeLayoutRules::getStd430()
diff --git a/source/slang/slang-ir-layout.h b/source/slang/slang-ir-layout.h
index cae8d788a..b5eb54497 100644
--- a/source/slang/slang-ir-layout.h
+++ b/source/slang/slang-ir-layout.h
@@ -63,9 +63,9 @@ public:
static IRTypeLayoutRules* get(IRTypeLayoutRuleName name);
};
-Result getOffset(IRTypeLayoutRules* rules, IRStructField* field, IRIntegerValue* outOffset);
+Result getOffset(TargetRequest* target, IRTypeLayoutRules* rules, IRStructField* field, IRIntegerValue* outOffset);
-Result getSizeAndAlignment(IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
+Result getSizeAndAlignment(TargetRequest* target, IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
/// Compute (if necessary) and return the natural size and alignment of `type`.
///
@@ -73,7 +73,7 @@ Result getSizeAndAlignment(IRTypeLayoutRules* rules, IRType* type, IRSizeAndAlig
/// general-purpose memory for the current target. In that case the
/// type is considered to have no natural layout.
///
-Result getNaturalSizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
+Result getNaturalSizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
/// Compute (if necessary) and return the natural offset of `field`
///
@@ -81,7 +81,7 @@ Result getNaturalSizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAl
/// that can be stored in general-purpose memory. In that case, the
/// field is considered to have no natural offset.
///
-Result getNaturalOffset(IRStructField* field, IRIntegerValue* outOffset);
+Result getNaturalOffset(TargetRequest* target, IRStructField* field, IRIntegerValue* outOffset);
/// Compute (if necessary) and return the std430 size and alignment of `type`.
///
@@ -89,7 +89,7 @@ Result getNaturalOffset(IRStructField* field, IRIntegerValue* outOffset);
/// general-purpose memory for the current target. In that case the
/// type is considered to have no std430 layout.
///
-Result getStd430SizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
+Result getStd430SizeAndAlignment(TargetRequest* target, IRType* type, IRSizeAndAlignment* outSizeAndAlignment);
/// Compute (if necessary) and return the std430 offset of `field`
///
@@ -97,7 +97,7 @@ Result getStd430SizeAndAlignment(IRType* type, IRSizeAndAlignment* outSizeAndAli
/// that can be stored in general-purpose memory. In that case, the
/// field is considered to have no std430 offset.
///
-Result getStd430Offset(IRStructField* field, IRIntegerValue* outOffset);
+Result getStd430Offset(TargetRequest* target, IRStructField* field, IRIntegerValue* outOffset);
}
diff --git a/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp b/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp
index eeafd1866..9df5f4e7e 100644
--- a/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp
+++ b/source/slang/slang-ir-lower-append-consume-structured-buffer.cpp
@@ -42,7 +42,7 @@ namespace Slang
IRTypeLayout::Builder elementTypeLayoutBuilder(&builder);
IRSizeAndAlignment elementSize;
- getSizeAndAlignment(layoutRules, elementType, &elementSize);
+ getSizeAndAlignment(target, layoutRules, elementType, &elementSize);
elementTypeLayoutBuilder.addResourceUsage(LayoutResourceKind::Uniform, LayoutSize((LayoutSize::RawValue)elementSize.getStride()));
auto elementTypeLayout = elementTypeLayoutBuilder.build();
diff --git a/source/slang/slang-ir-lower-bit-cast.cpp b/source/slang/slang-ir-lower-bit-cast.cpp
index a5ac05ead..79e95f7de 100644
--- a/source/slang/slang-ir-lower-bit-cast.cpp
+++ b/source/slang/slang-ir-lower-bit-cast.cpp
@@ -72,7 +72,7 @@ struct BitCastLoweringContext
{
IRIntegerValue fieldOffset = 0;
SLANG_RELEASE_ASSERT(
- getNaturalOffset(field, &fieldOffset) == SLANG_OK);
+ getNaturalOffset(targetReq, field, &fieldOffset) == SLANG_OK);
auto fieldType = field->getFieldType();
auto fieldValue =
readObject(builder, src, fieldType, (uint32_t)(fieldOffset + offset));
@@ -90,7 +90,7 @@ struct BitCastLoweringContext
IRSizeAndAlignment elementLayout;
SLANG_RELEASE_ASSERT(
getNaturalSizeAndAlignment(
- arrayType->getElementType(), &elementLayout) == SLANG_OK);
+ targetReq, arrayType->getElementType(), &elementLayout) == SLANG_OK);
for (IRIntegerValue i = 0; i < arrayCount->value.intVal; i++)
{
elements.add(readObject(
@@ -111,7 +111,7 @@ struct BitCastLoweringContext
IRSizeAndAlignment elementLayout;
SLANG_RELEASE_ASSERT(
getNaturalSizeAndAlignment(
- vectorType->getElementType(), &elementLayout) == SLANG_OK);
+ targetReq, vectorType->getElementType(), &elementLayout) == SLANG_OK);
for (IRIntegerValue i = 0; i < elementCount->value.intVal; i++)
{
elements.add(readObject(
@@ -136,7 +136,7 @@ struct BitCastLoweringContext
matrixType->getElementType(), matrixType->getColumnCount());
IRSizeAndAlignment elementLayout;
SLANG_RELEASE_ASSERT(
- getNaturalSizeAndAlignment(elementType, &elementLayout) == SLANG_OK);
+ getNaturalSizeAndAlignment(targetReq, elementType, &elementLayout) == SLANG_OK);
for (IRIntegerValue i = 0; i < elementCount->value.intVal; i++)
{
elements.add(readObject(
diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp
index af25cacd0..6a4d639c9 100644
--- a/source/slang/slang-ir-lower-buffer-element-type.cpp
+++ b/source/slang/slang-ir-lower-buffer-element-type.cpp
@@ -257,7 +257,7 @@ namespace Slang
auto vectorType = builder.getVectorType(matrixType->getElementType(),
isColMajor?matrixType->getRowCount():matrixType->getColumnCount());
IRSizeAndAlignment elementSizeAlignment;
- getSizeAndAlignment(rules, vectorType, &elementSizeAlignment);
+ getSizeAndAlignment(target, rules, vectorType, &elementSizeAlignment);
elementSizeAlignment = rules->alignCompositeElement(elementSizeAlignment);
auto arrayType = builder.getArrayType(
@@ -297,7 +297,7 @@ namespace Slang
auto structKey = builder.createStructKey();
builder.addNameHintDecoration(structKey, UnownedStringSlice("data"));
IRSizeAndAlignment elementSizeAlignment;
- getSizeAndAlignment(rules, loweredInnerTypeInfo.loweredType, &elementSizeAlignment);
+ getSizeAndAlignment(target, rules, loweredInnerTypeInfo.loweredType, &elementSizeAlignment);
elementSizeAlignment = rules->alignCompositeElement(elementSizeAlignment);
auto innerArrayType = builder.getArrayType(
loweredInnerTypeInfo.loweredType,
@@ -456,7 +456,7 @@ namespace Slang
return info;
info = getLoweredTypeInfoImpl(type, rules);
IRSizeAndAlignment sizeAlignment;
- getSizeAndAlignment(rules, info.loweredType, &sizeAlignment);
+ getSizeAndAlignment(target, rules, info.loweredType, &sizeAlignment);
loweredTypeInfo[(int)rules->ruleName].set(type, info);
mapLoweredTypeToInfo[(int)rules->ruleName].set(info.loweredType, info);
return info;
diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp
index 19f713548..722515692 100644
--- a/source/slang/slang-ir-lower-generics.cpp
+++ b/source/slang/slang-ir-lower-generics.cpp
@@ -217,7 +217,7 @@ namespace Slang
checkTypeConformanceExists(&sharedContext);
- inferAnyValueSizeWhereNecessary(module);
+ inferAnyValueSizeWhereNecessary(targetReq, module);
// Replace all `makeExistential` insts with `makeExistentialWithRTTI`
// before making any other changes. This is necessary because a parameter of
diff --git a/source/slang/slang-ir-lower-reinterpret.cpp b/source/slang/slang-ir-lower-reinterpret.cpp
index 689cc8505..c4d39b635 100644
--- a/source/slang/slang-ir-lower-reinterpret.cpp
+++ b/source/slang/slang-ir-lower-reinterpret.cpp
@@ -88,7 +88,7 @@ void lowerReinterpret(TargetRequest* targetReq, IRModule* module, DiagnosticSink
// Before processing reinterpret insts, ensure that existential types without
// user-defined sizes have inferred sizes where possible.
//
- inferAnyValueSizeWhereNecessary(module);
+ inferAnyValueSizeWhereNecessary(targetReq, module);
ReinterpretLoweringContext context;
context.module = module;
diff --git a/source/slang/slang-ir-lower-size-of.cpp b/source/slang/slang-ir-lower-size-of.cpp
index ffef82797..a8b599031 100644
--- a/source/slang/slang-ir-lower-size-of.cpp
+++ b/source/slang/slang-ir-lower-size-of.cpp
@@ -55,7 +55,7 @@ struct SizeOfLikeLoweringContext
IRSizeAndAlignment sizeAndAlignment;
- if (SLANG_FAILED(getNaturalSizeAndAlignment(typeOperand, &sizeAndAlignment)))
+ if (SLANG_FAILED(getNaturalSizeAndAlignment(m_targetReq, typeOperand, &sizeAndAlignment)))
{
// Output a diagnostic failure
if(sizeOfLikeInst->getOp() == kIROp_AlignOf)
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp
index 54cacf4a6..48c118486 100644
--- a/source/slang/slang-ir-spirv-legalize.cpp
+++ b/source/slang/slang-ir-spirv-legalize.cpp
@@ -47,7 +47,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
builder.setInsertBefore(inst);
auto elementType = inst->getElementType();
IRSizeAndAlignment elementSize;
- getSizeAndAlignment(layoutRules, elementType, &elementSize);
+ getSizeAndAlignment(m_sharedContext->m_targetRequest, layoutRules, elementType, &elementSize);
elementSize = layoutRules->alignCompositeElement(elementSize);
const auto arrayType = builder.getUnsizedArrayType(inst->getElementType(), builder.getIntValue(builder.getIntType(), elementSize.getStride()));
@@ -55,7 +55,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
const auto arrayKey = builder.createStructKey();
builder.createStructField(structType, arrayKey, arrayType);
IRSizeAndAlignment structSize;
- getSizeAndAlignment(layoutRules, structType, &structSize);
+ getSizeAndAlignment(m_sharedContext->m_targetRequest, layoutRules, structType, &structSize);
StringBuilder nameSb;
switch (inst->getOp())
@@ -135,7 +135,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
cbParamInst->setFullType(newCbType);
auto rules = getTypeLayoutRuleForBuffer(m_sharedContext->m_targetRequest, cbParamInst->getDataType());
IRSizeAndAlignment sizeAlignment;
- getSizeAndAlignment(rules, structType, &sizeAlignment);
+ getSizeAndAlignment(m_sharedContext->m_targetRequest, rules, structType, &sizeAlignment);
traverseUses(cbParamInst, [&](IRUse* use)
{
builder.setInsertBefore(use->getUser());
diff --git a/tests/expected-failure.txt b/tests/expected-failure.txt
index 724f2588e..b3efed2d1 100644
--- a/tests/expected-failure.txt
+++ b/tests/expected-failure.txt
@@ -1,5 +1,4 @@
tests/autodiff/global-param-hoisting.slang.1 (vk)
-tests/bugs/buffer-swizzle-store.slang.1 (vk)
tests/language-feature/constants/constexpr-loop.slang.1 (vk)
tests/optimization/func-resource-result/func-resource-result-complex.slang.1 (vk)
tests/type/texture-sampler/texture-sampler-2d.slang (vk)