diff options
| author | Yong He <yonghe@outlook.com> | 2022-06-29 13:38:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-29 13:38:50 -0700 |
| commit | abc100f81d4b22229105f9ed569a7efafc653a3a (patch) | |
| tree | 06c98c1941ab05d9989c9b7566571ec64ab11c39 /source/slang/slang-ir.cpp | |
| parent | b7638b8fffe78ade657f361cadc08dffc8c10acf (diff) | |
Native call marshalling for ComPtr parameters and return values. (#2305)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index dd71ae782..081b9103f 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -2539,6 +2539,11 @@ namespace Slang return (IRNativeStringType*)getType(kIROp_NativeStringType); } + IRNativePtrType* IRBuilder::getNativePtrType(IRType* valueType) + { + return (IRNativePtrType*)getType(kIROp_NativePtrType, (IRInst*)valueType); + } + IRType* IRBuilder::getCapabilitySetType() { @@ -4441,6 +4446,56 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitGetNativePtr(IRInst* value) + { + auto valueType = value->getDataType(); + SLANG_RELEASE_ASSERT(valueType); + switch (valueType->getOp()) + { + case kIROp_InterfaceType: + return emitIntrinsicInst( + getNativePtrType((IRType*)valueType), kIROp_GetNativePtr, 1, &value); + break; + case kIROp_ComPtrType: + return emitIntrinsicInst( + getNativePtrType((IRType*)valueType->getOperand(0)), kIROp_GetNativePtr, 1, &value); + break; + default: + SLANG_UNEXPECTED("invalid operand type for `getNativePtr`."); + UNREACHABLE_RETURN(nullptr); + } + } + + IRInst* IRBuilder::emitManagedPtrAttach(IRInst* managedPtrVar, IRInst* value) + { + IRInst* args[] = { managedPtrVar, value }; + return emitIntrinsicInst(getVoidType(), kIROp_ManagedPtrAttach, 2, args); + } + + IRInst* IRBuilder::emitManagedPtrDetach(IRInst* managedPtrVar) + { + return emitIntrinsicInst(getVoidType(), kIROp_ManagedPtrDetach, 1, &managedPtrVar); + } + + IRInst* IRBuilder::emitGetManagedPtrWriteRef(IRInst* ptrToManagedPtr) + { + auto type = ptrToManagedPtr->getDataType(); + auto ptrType = as<IRPtrTypeBase>(type); + SLANG_RELEASE_ASSERT(ptrType); + auto managedPtrType = ptrType->getValueType(); + switch (managedPtrType->getOp()) + { + case kIROp_InterfaceType: + case kIROp_ComPtrType: + return emitIntrinsicInst( + getPtrType(getNativePtrType((IRType*)managedPtrType->getOperand(0))), kIROp_GetManagedPtrWriteRef, 1, &ptrToManagedPtr); + break; + default: + SLANG_UNEXPECTED("invalid operand type for `getNativePtr`."); + UNREACHABLE_RETURN(nullptr); + } + } + IRInst* IRBuilder::emitGpuForeach(List<IRInst*> args) { auto inst = createInst<IRInst>( |
