diff options
| author | Yong He <yonghe@outlook.com> | 2020-10-09 11:29:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-09 11:29:11 -0700 |
| commit | fab1c9f4c745ba84983c2448646376799d461e96 (patch) | |
| tree | 3176c03987417c01b7220aaf13c35b665813c876 /source/slang/slang-ir-any-value-marshalling.cpp | |
| parent | 11f331771a8d5d80bc1dd317dcad5eb815e9cb55 (diff) | |
Support CUDA bindless texture in dynamic dispatch code. (#1575)
Diffstat (limited to 'source/slang/slang-ir-any-value-marshalling.cpp')
| -rw-r--r-- | source/slang/slang-ir-any-value-marshalling.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp index 0a988da1d..9322ed0eb 100644 --- a/source/slang/slang-ir-any-value-marshalling.cpp +++ b/source/slang/slang-ir-any-value-marshalling.cpp @@ -85,7 +85,8 @@ namespace Slang IRInst* anyValueVar; // Defines what to do with basic typed data elements. virtual void marshalBasicType(IRBuilder* builder, IRType* dataType, IRInst* concreteTypedVar) = 0; - + // Defines what to do with resource handle elements. + virtual void marshalResourceHandle(IRBuilder* builder, IRType* dataType, IRInst* concreteTypedVar) = 0; // Validates that the type fits in the given AnyValueSize. // After calling emitMarshallingCode, `fieldOffset` will be increased to the required `AnyValue` size. // If this is larger than the provided AnyValue size, report a dianogstic. We might want to front load @@ -188,6 +189,11 @@ namespace Slang break; } default: + if (as<IRTextureTypeBase>(dataType) || as<IRSamplerStateTypeBase>(dataType)) + { + context->marshalResourceHandle(builder, dataType, concreteTypedVar); + return; + } SLANG_UNIMPLEMENTED_X("Unimplemented type packing"); break; } @@ -243,6 +249,29 @@ namespace Slang SLANG_UNREACHABLE("unknown basic type"); } } + + virtual void marshalResourceHandle(IRBuilder* builder, IRType* dataType, IRInst* concreteVar) override + { + SLANG_UNUSED(dataType); + if (fieldOffset + 1 < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount())) + { + auto srcVal = builder->emitLoad(concreteVar); + auto uint64Val = builder->emitBitCast(builder->getUInt64Type(), srcVal); + auto lowBits = builder->emitConstructorInst(builder->getUIntType(), 1, &uint64Val); + auto shiftedBits = builder->emitShr( + builder->getUInt64Type(), + uint64Val, + builder->getIntValue(builder->getIntType(), 32)); + auto highBits = builder->emitBitCast(builder->getUIntType(), shiftedBits); + auto dstAddr1 = builder->emitFieldAddress( + uintPtrType, anyValueVar, anyValInfo->fieldKeys[fieldOffset]); + builder->emitStore(dstAddr1, lowBits); + auto dstAddr2 = builder->emitFieldAddress( + uintPtrType, anyValueVar, anyValInfo->fieldKeys[fieldOffset + 1]); + builder->emitStore(dstAddr2, highBits); + fieldOffset += 2; + } + } }; IRFunc* generatePackingFunc(IRType* type, IRAnyValueType* anyValueType) @@ -335,6 +364,26 @@ namespace Slang SLANG_UNREACHABLE("unknown basic type"); } } + + virtual void marshalResourceHandle( + IRBuilder* builder, IRType* dataType, IRInst* concreteVar) override + { + if (fieldOffset + 1 < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount())) + { + auto srcAddr = builder->emitFieldAddress( + uintPtrType, anyValueVar, anyValInfo->fieldKeys[fieldOffset]); + auto lowBits = builder->emitLoad(srcAddr); + + auto srcAddr1 = builder->emitFieldAddress( + uintPtrType, anyValueVar, anyValInfo->fieldKeys[fieldOffset + 1]); + auto highBits = builder->emitLoad(srcAddr1); + + auto combinedBits = builder->emitMakeUInt64(lowBits, highBits); + combinedBits = builder->emitBitCast(dataType, combinedBits); + builder->emitStore(concreteVar, combinedBits); + fieldOffset += 2; + } + } }; IRFunc* generateUnpackingFunc(IRType* type, IRAnyValueType* anyValueType) |
