summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-07-30 20:28:34 -0700
committerGitHub <noreply@github.com>2024-07-30 20:28:34 -0700
commit6e4b82741893be55f6216c31e19650029c667078 (patch)
treefefd4529c6066763653732d7f93ca5cf07027a76 /source/slang/slang-ir.cpp
parent04e7327a2067c82db3eaef51955f211e148ac933 (diff)
Fixes for Metal ParameterBlock support. (#4752)
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp71
1 files changed, 56 insertions, 15 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 88065cedc..1fc15f185 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -4870,6 +4870,27 @@ namespace Slang
return inst;
}
+ IRInst* IRBuilder::emitFieldExtract(IRInst* base, IRInst* fieldKey)
+ {
+ IRType* resultType = nullptr;
+ auto valueType = base->getDataType();
+ auto structType = as<IRStructType>(valueType);
+ SLANG_RELEASE_ASSERT(structType);
+ for (auto child : valueType->getChildren())
+ {
+ auto field = as<IRStructField>(child);
+ if (!field)
+ continue;
+ if (field->getKey() == fieldKey)
+ {
+ resultType = field->getFieldType();
+ break;
+ }
+ }
+ SLANG_RELEASE_ASSERT(resultType);
+ return emitFieldExtract(resultType, base, fieldKey);
+ }
+
IRInst* IRBuilder::emitFieldExtract(
IRType* type,
IRInst* base,
@@ -4903,6 +4924,40 @@ namespace Slang
}
IRInst* IRBuilder::emitFieldAddress(
+ IRInst* basePtr,
+ IRInst* fieldKey)
+ {
+ AddressSpace addrSpace = AddressSpace::Generic;
+ IRInst* valueType = nullptr;
+ auto basePtrType = unwrapAttributedType(basePtr->getDataType());
+ if (auto ptrType = as<IRPtrTypeBase>(basePtrType))
+ {
+ addrSpace = ptrType->getAddressSpace();
+ valueType = ptrType->getValueType();
+ }
+ else if (auto ptrLikeType = as<IRPointerLikeType>(basePtrType))
+ {
+ valueType = ptrLikeType->getElementType();
+ }
+ IRType* resultType = nullptr;
+ auto structType = as<IRStructType>(valueType);
+ SLANG_RELEASE_ASSERT(structType);
+ for (auto child : valueType->getChildren())
+ {
+ auto field = as<IRStructField>(child);
+ if (!field)
+ continue;
+ if (field->getKey() == fieldKey)
+ {
+ resultType = field->getFieldType();
+ break;
+ }
+ }
+ SLANG_RELEASE_ASSERT(resultType);
+ return emitFieldAddress(getPtrType(kIROp_PtrType, resultType, addrSpace), basePtr, fieldKey);
+ }
+
+ IRInst* IRBuilder::emitFieldAddress(
IRType* type,
IRInst* base,
IRInst* field)
@@ -5080,23 +5135,9 @@ namespace Slang
{
for (auto access : accessChain)
{
- auto basePtrType = cast<IRPtrTypeBase>(basePtr->getDataType());
- auto valueType = unwrapAttributedType(basePtrType->getValueType());
- IRType* resultType = nullptr;
if (auto structKey = as<IRStructKey>(access))
{
- auto structType = as<IRStructType>(valueType);
- SLANG_RELEASE_ASSERT(structType);
- for (auto field : structType->getFields())
- {
- if (field->getKey() == structKey)
- {
- resultType = field->getFieldType();
- break;
- }
- }
- SLANG_RELEASE_ASSERT(resultType);
- basePtr = emitFieldAddress(getPtrType(kIROp_PtrType, resultType, basePtrType->getAddressSpace()), basePtr, structKey);
+ basePtr = emitFieldAddress(basePtr, structKey);
}
else
{