@@ -85,7 +85,8 @@ namespace Slang
85
85
IRInst* anyValueVar;
86
86
// Defines what to do with basic typed data elements.
87
87
virtual void marshalBasicType (IRBuilder* builder, IRType* dataType, IRInst* concreteTypedVar) = 0;
88
-
88
+ // Defines what to do with resource handle elements.
89
+ virtual void marshalResourceHandle (IRBuilder* builder, IRType* dataType, IRInst* concreteTypedVar) = 0;
89
90
// Validates that the type fits in the given AnyValueSize.
90
91
// After calling emitMarshallingCode, `fieldOffset` will be increased to the required `AnyValue` size.
91
92
// If this is larger than the provided AnyValue size, report a dianogstic. We might want to front load
@@ -188,6 +189,11 @@ namespace Slang
188
189
break ;
189
190
}
190
191
default :
192
+ if (as<IRTextureTypeBase>(dataType) || as<IRSamplerStateTypeBase>(dataType))
193
+ {
194
+ context->marshalResourceHandle (builder, dataType, concreteTypedVar);
195
+ return ;
196
+ }
191
197
SLANG_UNIMPLEMENTED_X (" Unimplemented type packing" );
192
198
break ;
193
199
}
@@ -243,6 +249,29 @@ namespace Slang
243
249
SLANG_UNREACHABLE (" unknown basic type" );
244
250
}
245
251
}
252
+
253
+ virtual void marshalResourceHandle (IRBuilder* builder, IRType* dataType, IRInst* concreteVar) override
254
+ {
255
+ SLANG_UNUSED (dataType);
256
+ if (fieldOffset + 1 < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
257
+ {
258
+ auto srcVal = builder->emitLoad (concreteVar);
259
+ auto uint64Val = builder->emitBitCast (builder->getUInt64Type (), srcVal);
260
+ auto lowBits = builder->emitConstructorInst (builder->getUIntType (), 1 , &uint64Val);
261
+ auto shiftedBits = builder->emitShr (
262
+ builder->getUInt64Type (),
263
+ uint64Val,
264
+ builder->getIntValue (builder->getIntType (), 32 ));
265
+ auto highBits = builder->emitBitCast (builder->getUIntType (), shiftedBits);
266
+ auto dstAddr1 = builder->emitFieldAddress (
267
+ uintPtrType, anyValueVar, anyValInfo->fieldKeys [fieldOffset]);
268
+ builder->emitStore (dstAddr1, lowBits);
269
+ auto dstAddr2 = builder->emitFieldAddress (
270
+ uintPtrType, anyValueVar, anyValInfo->fieldKeys [fieldOffset + 1 ]);
271
+ builder->emitStore (dstAddr2, highBits);
272
+ fieldOffset += 2 ;
273
+ }
274
+ }
246
275
};
247
276
248
277
IRFunc* generatePackingFunc (IRType* type, IRAnyValueType* anyValueType)
@@ -335,6 +364,26 @@ namespace Slang
335
364
SLANG_UNREACHABLE (" unknown basic type" );
336
365
}
337
366
}
367
+
368
+ virtual void marshalResourceHandle (
369
+ IRBuilder* builder, IRType* dataType, IRInst* concreteVar) override
370
+ {
371
+ if (fieldOffset + 1 < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
372
+ {
373
+ auto srcAddr = builder->emitFieldAddress (
374
+ uintPtrType, anyValueVar, anyValInfo->fieldKeys [fieldOffset]);
375
+ auto lowBits = builder->emitLoad (srcAddr);
376
+
377
+ auto srcAddr1 = builder->emitFieldAddress (
378
+ uintPtrType, anyValueVar, anyValInfo->fieldKeys [fieldOffset + 1 ]);
379
+ auto highBits = builder->emitLoad (srcAddr1);
380
+
381
+ auto combinedBits = builder->emitMakeUInt64 (lowBits, highBits);
382
+ combinedBits = builder->emitBitCast (dataType, combinedBits);
383
+ builder->emitStore (concreteVar, combinedBits);
384
+ fieldOffset += 2 ;
385
+ }
386
+ }
338
387
};
339
388
340
389
IRFunc* generateUnpackingFunc (IRType* type, IRAnyValueType* anyValueType)
0 commit comments