@@ -103,6 +103,12 @@ struct AnyValueMarshallingContext
103
103
intraFieldOffset = 0 ;
104
104
}
105
105
}
106
+ void ensureOffsetAt8ByteBoundary ()
107
+ {
108
+ ensureOffsetAt4ByteBoundary ();
109
+ if ((fieldOffset & 1 ) != 0 )
110
+ fieldOffset++;
111
+ }
106
112
void ensureOffsetAt2ByteBoundary ()
107
113
{
108
114
if (intraFieldOffset == 0 )
@@ -146,6 +152,7 @@ struct AnyValueMarshallingContext
146
152
case kIROp_BoolType :
147
153
case kIROp_IntPtrType :
148
154
case kIROp_UIntPtrType :
155
+ case kIROp_PtrType :
149
156
context->marshalBasicType (builder, dataType, concreteTypedVar);
150
157
break ;
151
158
case kIROp_VectorType :
@@ -166,17 +173,36 @@ struct AnyValueMarshallingContext
166
173
auto matrixType = static_cast <IRMatrixType*>(dataType);
167
174
auto colCount = getIntVal (matrixType->getColumnCount ());
168
175
auto rowCount = getIntVal (matrixType->getRowCount ());
169
- for (IRIntegerValue i = 0 ; i < colCount; i++ )
176
+ if ( getIntVal (matrixType-> getLayout ()) == SLANG_MATRIX_LAYOUT_COLUMN_MAJOR )
170
177
{
171
- auto col = builder->emitElementAddress (
172
- concreteTypedVar,
173
- builder->getIntValue (builder->getIntType (), i));
174
- for (IRIntegerValue j = 0 ; j < rowCount; j++)
178
+ for (IRIntegerValue i = 0 ; i < colCount; i++)
179
+ {
180
+ for (IRIntegerValue j = 0 ; j < rowCount; j++)
181
+ {
182
+ auto row = builder->emitElementAddress (
183
+ concreteTypedVar,
184
+ builder->getIntValue (builder->getIntType (), j));
185
+ auto element = builder->emitElementAddress (
186
+ row,
187
+ builder->getIntValue (builder->getIntType (), i));
188
+ emitMarshallingCode (builder, context, element);
189
+ }
190
+ }
191
+ }
192
+ else
193
+ {
194
+ for (IRIntegerValue i = 0 ; i < rowCount; i++)
175
195
{
176
- auto element = builder->emitElementAddress (
177
- col,
178
- builder->getIntValue (builder->getIntType (), j));
179
- emitMarshallingCode (builder, context, element);
196
+ auto row = builder->emitElementAddress (
197
+ concreteTypedVar,
198
+ builder->getIntValue (builder->getIntType (), i));
199
+ for (IRIntegerValue j = 0 ; j < colCount; j++)
200
+ {
201
+ auto element = builder->emitElementAddress (
202
+ row,
203
+ builder->getIntValue (builder->getIntType (), j));
204
+ emitMarshallingCode (builder, context, element);
205
+ }
180
206
}
181
207
}
182
208
break ;
@@ -348,11 +374,39 @@ struct AnyValueMarshallingContext
348
374
case kIROp_UInt64Type :
349
375
case kIROp_Int64Type :
350
376
case kIROp_DoubleType :
377
+ case kIROp_PtrType :
351
378
#if SLANG_PTR_IS_64
352
379
case kIROp_UIntPtrType :
353
380
case kIROp_IntPtrType :
354
381
#endif
355
- SLANG_UNIMPLEMENTED_X (" AnyValue type packing for non 32-bit elements" );
382
+ ensureOffsetAt8ByteBoundary ();
383
+ if (fieldOffset < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
384
+ {
385
+ auto srcVal = builder->emitLoad (concreteVar);
386
+ auto dstVal = builder->emitBitCast (builder->getUInt64Type (), srcVal);
387
+ auto lowBits = builder->emitCast (builder->getUIntType (), dstVal);
388
+ auto highBits = builder->emitShr (
389
+ builder->getUInt64Type (),
390
+ dstVal,
391
+ builder->getIntValue (builder->getIntType (), 32 ));
392
+ highBits = builder->emitCast (builder->getUIntType (), highBits);
393
+
394
+ auto dstAddr = builder->emitFieldAddress (
395
+ uintPtrType,
396
+ anyValueVar,
397
+ anyValInfo->fieldKeys [fieldOffset]);
398
+ builder->emitStore (dstAddr, lowBits);
399
+ fieldOffset++;
400
+ if (fieldOffset < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
401
+ {
402
+ dstAddr = builder->emitFieldAddress (
403
+ uintPtrType,
404
+ anyValueVar,
405
+ anyValInfo->fieldKeys [fieldOffset]);
406
+ builder->emitStore (dstAddr, lowBits);
407
+ fieldOffset++;
408
+ }
409
+ }
356
410
break ;
357
411
default :
358
412
SLANG_UNREACHABLE (" unknown basic type" );
@@ -545,7 +599,34 @@ struct AnyValueMarshallingContext
545
599
case kIROp_DoubleType :
546
600
case kIROp_Int8Type :
547
601
case kIROp_UInt8Type :
548
- SLANG_UNIMPLEMENTED_X (" AnyValue type packing for non 32-bit elements" );
602
+ case kIROp_PtrType :
603
+ #if SLANG_PTR_IS_64
604
+ case kIROp_IntPtrType :
605
+ case kIROp_UIntPtrType :
606
+ #endif
607
+ ensureOffsetAt8ByteBoundary ();
608
+ if (fieldOffset < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
609
+ {
610
+ auto srcAddr = builder->emitFieldAddress (
611
+ uintPtrType,
612
+ anyValueVar,
613
+ anyValInfo->fieldKeys [fieldOffset]);
614
+ auto lowBits = builder->emitLoad (srcAddr);
615
+ fieldOffset++;
616
+ if (fieldOffset < static_cast <uint32_t >(anyValInfo->fieldKeys .getCount ()))
617
+ {
618
+ auto srcAddr1 = builder->emitFieldAddress (
619
+ uintPtrType,
620
+ anyValueVar,
621
+ anyValInfo->fieldKeys [fieldOffset]);
622
+ fieldOffset++;
623
+ auto highBits = builder->emitLoad (srcAddr1);
624
+ auto combinedBits = builder->emitMakeUInt64 (lowBits, highBits);
625
+ if (dataType->getOp () != kIROp_UInt64Type )
626
+ combinedBits = builder->emitBitCast (dataType, combinedBits);
627
+ builder->emitStore (concreteVar, combinedBits);
628
+ }
629
+ }
549
630
break ;
550
631
default :
551
632
SLANG_UNREACHABLE (" unknown basic type" );
@@ -735,7 +816,8 @@ SlangInt _getAnyValueSizeRaw(IRType* type, SlangInt offset)
735
816
case kIROp_UInt64Type :
736
817
case kIROp_Int64Type :
737
818
case kIROp_DoubleType :
738
- return -1 ;
819
+ case kIROp_PtrType :
820
+ return alignUp (offset, 8 ) + 8 ;
739
821
case kIROp_Int16Type :
740
822
case kIROp_UInt16Type :
741
823
case kIROp_HalfType :
@@ -762,9 +844,9 @@ SlangInt _getAnyValueSizeRaw(IRType* type, SlangInt offset)
762
844
auto elementType = matrixType->getElementType ();
763
845
auto colCount = getIntVal (matrixType->getColumnCount ());
764
846
auto rowCount = getIntVal (matrixType->getRowCount ());
765
- for (IRIntegerValue i = 0 ; i < colCount ; i++)
847
+ for (IRIntegerValue i = 0 ; i < rowCount ; i++)
766
848
{
767
- for (IRIntegerValue j = 0 ; j < rowCount ; j++)
849
+ for (IRIntegerValue j = 0 ; j < colCount ; j++)
768
850
{
769
851
offset = _getAnyValueSizeRaw (elementType, offset);
770
852
if (offset < 0 )
0 commit comments