Repository: shader-slang/slang
File: source/slang/slang-ir-any-value-marshalling.cpp (C++)

Code before:
                sizeAndAlign.size > 0)
            {
                size = sizeAndAlign.size;
            }

            IRIntegerValue numUints = (size + 3) / 4;
            if (fieldOffset + numUints - 1 <
                static_cast<uint32_t>(anyValInfo->fieldKeys.getCount()))
            {
                auto uintNType =
                    builder->getVectorType(builder->getUIntType(), (IRIntegerValue)numUints);
                List<IRInst*> components;
                for (IRIntegerValue i = 0; i < numUints; i++)
                {
                    auto srcAddr = builder->emitFieldAddress(
                        uintPtrType,
                        anyValueVar,
                        anyValInfo->fieldKeys[fieldOffset + (uint32_t)i]);
                    components.add(builder->emitLoad(srcAddr));
                }
                auto uintNVal =
                    builder->emitMakeVector(uintNType, (UInt)numUints, components.getBuffer());
                auto combinedBits = builder->emitBitCast(dataType, uintNVal);
                builder->emitStore(concreteVar, combinedBits);
            }
            advanceOffset((uint32_t)size);
        }

        // unpack: AnyValue -> DescriptorHandle
        virtual void marshalDescriptorHandle(
            IRBuilder* builder,
            IRType* dataType,
            IRInst* concreteVar,
            bool isBindless,
            IRIntegerValue sizeInBytes) override
        {
            ensureOffsetAt4ByteBoundary();

            if (!isBindless)
            {
                // Non-bindless targets: Use CastUInt2ToDescriptorHandle
                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,

Review comment (suggestion):
The previous implementation had `advanceOffset(8)` inside of the `if` condition.
But the new implementation moved it out of `if` condition.

This is inconsistent to how the new implementation does in the line 603.
I think this should change to
```
 if (fieldOffset + numUints - 1 < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount()))
{
  ...
  advanceOffset((uint32_t)size);
}
```

Code after:
                sizeAndAlign.size > 0)
            {
                size = sizeAndAlign.size;
            }

            IRIntegerValue numUints = (size + 3) / 4;
            if (fieldOffset + numUints - 1 <
                static_cast<uint32_t>(anyValInfo->fieldKeys.getCount()))
            {
                auto uintNType =
                    builder->getVectorType(builder->getUIntType(), (IRIntegerValue)numUints);
                List<IRInst*> components;
                for (IRIntegerValue i = 0; i < numUints; i++)
                {
                    auto srcAddr = builder->emitFieldAddress(
                        uintPtrType,
                        anyValueVar,
                        anyValInfo->fieldKeys[fieldOffset + (uint32_t)i]);
                    components.add(builder->emitLoad(srcAddr));
                }
                auto uintNVal =
                    builder->emitMakeVector(uintNType, (UInt)numUints, components.getBuffer());
                auto combinedBits = builder->emitBitCast(dataType, uintNVal);
                builder->emitStore(concreteVar, combinedBits);
                advanceOffset((uint32_t)size);
            }
        }

        // unpack: AnyValue -> DescriptorHandle
        virtual void marshalDescriptorHandle(
            IRBuilder* builder,
            IRType* dataType,
            IRInst* concreteVar,
            bool isBindless,
            IRIntegerValue sizeInBytes) override
        {
            ensureOffsetAt4ByteBoundary();

            if (!isBindless)
            {
                // Non-bindless targets: Use CastUInt2ToDescriptorHandle
                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,