diff options
| author | Yong He <yonghe@outlook.com> | 2022-07-21 22:52:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-21 22:52:27 -0700 |
| commit | 73b52f6075eb8a4f674e5d66d2a6192ca71f26d3 (patch) | |
| tree | 0fb7fbea8356323dcb0ac4173cf2fc97c02d3fcf /source/slang/slang-ir-any-value-marshalling.cpp | |
| parent | 91c8c3f32c4b827dedc74d2ecdfe72a3403fc357 (diff) | |
Allow dynamic dispatch to handle nested interface-typed fields. (#2336)
Diffstat (limited to 'source/slang/slang-ir-any-value-marshalling.cpp')
| -rw-r--r-- | source/slang/slang-ir-any-value-marshalling.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp index ba8f49cdd..5c91766f7 100644 --- a/source/slang/slang-ir-any-value-marshalling.cpp +++ b/source/slang/slang-ir-any-value-marshalling.cpp @@ -215,6 +215,20 @@ namespace Slang } break; } + case kIROp_AnyValueType: + { + auto anyValType = cast<IRAnyValueType>(dataType); + auto info = ensureAnyValueType(anyValType); + for (auto field : info->fieldKeys) + { + auto fieldAddr = builder->emitFieldAddress( + builder->getPtrType(builder->getUIntType()), + concreteTypedVar, + field); + emitMarshallingCode(builder, context, fieldAddr); + } + break; + } default: if (as<IRTextureTypeBase>(dataType) || as<IRSamplerStateTypeBase>(dataType)) { @@ -719,10 +733,34 @@ namespace Slang } return offset; } + case kIROp_AnyValueType: + { + auto anyValueType = cast<IRAnyValueType>(type); + return alignUp(offset, 4) + (SlangInt)getIntVal(anyValueType->getSize()); + } + case kIROp_TupleType: + { + auto tupleType = cast<IRTupleType>(type); + for (UInt i = 0; i < tupleType->getOperandCount(); i++) + { + auto elementType = tupleType->getOperand(i); + offset = _getAnyValueSizeRaw((IRType*)elementType, offset); + if (offset < 0) return offset; + } + return offset; + } + case kIROp_WitnessTableType: + case kIROp_WitnessTableIDType: + case kIROp_RTTIHandleType: + { + return alignUp(offset, 4) + kRTTIHandleSize; + } case kIROp_InterfaceType: { - // TODO: implement anyValue packing for interface types. - return -1; + auto interfaceType = cast<IRInterfaceType>(type); + auto size = SharedGenericsLoweringContext::getInterfaceAnyValueSize(interfaceType, interfaceType->sourceLoc); + size += kRTTIHeaderSize; + return alignUp(offset, 4) + alignUp((SlangInt)size, 4); } default: if (as<IRTextureTypeBase>(type) || as<IRSamplerStateTypeBase>(type)) |
