summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-lower-buffer-element-type.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-12 19:31:25 -0700
committerGitHub <noreply@github.com>2024-03-12 19:31:25 -0700
commit6f7c8271710b43349d34b8f7569ceb6957400548 (patch)
tree288c18bb4b9a2cf32de7e400c1fe8b56385b727e /source/slang/slang-ir-lower-buffer-element-type.cpp
parenteef7e208bf7436a4f111a9290f37204e3220d82b (diff)
Fix `sessionDesc.defaultMatrixLayoutMode` being ineffective. (#3753)
* Fix `sessionDesc.defaultMatrixLayoutMode` being ineffective. * Fix matrix layout in buffer pointer. * Attempt to fix. * Fix buffer element type lowering for buffer pointers. * Add comment. * Fix test. * Fix member lookup in `Ref<T>`. * Fix validation error. * Enhance test.
Diffstat (limited to 'source/slang/slang-ir-lower-buffer-element-type.cpp')
-rw-r--r--source/slang/slang-ir-lower-buffer-element-type.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp
index 5c797ab23..eb5fba6a9 100644
--- a/source/slang/slang-ir-lower-buffer-element-type.cpp
+++ b/source/slang/slang-ir-lower-buffer-element-type.cpp
@@ -24,9 +24,10 @@ namespace Slang
SlangMatrixLayoutMode defaultMatrixLayout = SLANG_MATRIX_LAYOUT_ROW_MAJOR;
TargetProgram* target;
+ bool lowerBufferPointer = false;
- LoweredElementTypeContext(TargetProgram* target, SlangMatrixLayoutMode inDefaultMatrixLayout)
- : target(target), defaultMatrixLayout(inDefaultMatrixLayout)
+ LoweredElementTypeContext(TargetProgram* target, bool lowerBufferPointer, SlangMatrixLayoutMode inDefaultMatrixLayout)
+ : target(target), defaultMatrixLayout(inDefaultMatrixLayout), lowerBufferPointer(lowerBufferPointer)
{}
IRFunc* createMatrixUnpackFunc(
@@ -460,7 +461,15 @@ namespace Slang
LoweredElementTypeInfo getLoweredTypeInfo(IRType* type, IRTypeLayoutRules* rules)
{
+ // If `type` is already a lowered type, no more lowering is required.
LoweredElementTypeInfo info;
+ if (auto pInfo = mapLoweredTypeToInfo->tryGetValue(type))
+ {
+ info.originalType = type;
+ info.loweredType = type;
+ return info;
+ }
+
if (loweredTypeInfo[(int)rules->ruleName].tryGetValue(type, info))
return info;
info = getLoweredTypeInfoImpl(type, rules);
@@ -513,10 +522,21 @@ namespace Slang
for (auto globalInst : module->getGlobalInsts())
{
IRType* elementType = nullptr;
- if (auto structBuffer = as<IRHLSLStructuredBufferTypeBase>(globalInst))
- elementType = structBuffer->getElementType();
- else if (auto constBuffer = as<IRUniformParameterGroupType>(globalInst))
- elementType = constBuffer->getElementType();
+ if (lowerBufferPointer)
+ {
+ if (auto ptrType = as<IRPtrType>(globalInst))
+ {
+ if (ptrType->getAddressSpace() == SpvStorageClassPhysicalStorageBuffer)
+ elementType = ptrType->getValueType();
+ }
+ }
+ else
+ {
+ if (auto structBuffer = as<IRHLSLStructuredBufferTypeBase>(globalInst))
+ elementType = structBuffer->getElementType();
+ else if (auto constBuffer = as<IRUniformParameterGroupType>(globalInst))
+ elementType = constBuffer->getElementType();
+ }
if (as<IRTextureBufferType>(globalInst))
continue;
if (!as<IRStructType>(elementType) && !as<IRMatrixType>(elementType) && !as<IRArrayType>(elementType) && !as<IRBoolType>(elementType))
@@ -654,17 +674,19 @@ namespace Slang
}
break;
case kIROp_RWStructuredBufferGetElementPtr:
+ case kIROp_GetOffsetPtr:
ptrValsWorkList.add(user);
break;
case kIROp_StructuredBufferGetDimensions:
break;
case kIROp_Call:
{
- // If a structured buffer typed value is used directly as an argument,
+ // If a structured buffer or pointer typed value is used directly as an argument,
// we don't need to do any marshalling here.
if (as<IRHLSLStructuredBufferTypeBase>(ptrVal->getDataType()))
break;
-
+ if (lowerBufferPointer && as<IRPtrType>(ptrVal->getDataType()))
+ break;
// If we are calling a function with an l-value pointer from buffer access,
// we need to materialize the object as a local variable, and pass the address
// of the local variable to the function.
@@ -681,7 +703,6 @@ namespace Slang
}
break;
default:
- SLANG_UNREACHABLE("unhandled inst of a buffer/pointer value that needs storage lowering.");
break;
}
});
@@ -801,12 +822,12 @@ namespace Slang
}
};
- void lowerBufferElementTypeToStorageType(TargetProgram* target, IRModule* module)
+ void lowerBufferElementTypeToStorageType(TargetProgram* target, IRModule* module, bool lowerBufferPointer)
{
SlangMatrixLayoutMode defaultMatrixMode = (SlangMatrixLayoutMode)target->getOptionSet().getMatrixLayoutMode();
if (defaultMatrixMode == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)
defaultMatrixMode = SLANG_MATRIX_LAYOUT_ROW_MAJOR;
- LoweredElementTypeContext context(target, defaultMatrixMode);
+ LoweredElementTypeContext context(target, lowerBufferPointer, defaultMatrixMode);
context.processModule(module);
}
@@ -853,6 +874,8 @@ namespace Slang
case kIROp_ConstantBufferType:
case kIROp_ParameterBlockType:
return IRTypeLayoutRules::getStd140();
+ case kIROp_PtrType:
+ return IRTypeLayoutRules::getNatural();
}
return IRTypeLayoutRules::getNatural();
}