Repository: shader-slang/slang
File: source/slang/slang-ir-lower-buffer-element-type.cpp (C++)

Code before:
    KhronosTargetBufferElementTypeLoweringPolicy(
        TargetProgram* inTarget,
        BufferElementTypeLoweringOptions inOptions)
        : DefaultBufferElementTypeLoweringPolicy(inTarget, inOptions)
    {
    }

    virtual bool canUseStorageTypeInLocalVar() override
    {
        // SPIRV (Vulkan) does not allow using an explicitly laid out type to declare a local
        // variable.
        return false;
    }

    virtual bool shouldLowerMatrixType(IRMatrixType* matrixType, TypeLoweringConfig config) override
    {
        // For spirv, we generally want to lower all matrix types, because SPIRV does not support
        // specifying matrix layout/stride if the matrix type is used in places other than
        // defining a struct field. This means that if a matrix is used to define a varying
        // parameter, we always want to wrap it in a struct.
        // Matrices within uniform and storage buffers are already members in the overall buffer
        // struct type, hence do not need to be lowered.
        if (target->shouldEmitSPIRVDirectly())
        {
            bool isInUniformOrStorageBuffer = config.addressSpace == AddressSpace::Uniform ||
                                              config.addressSpace == AddressSpace::StorageBuffer;
            return !isInUniformOrStorageBuffer;
        }

        return DefaultBufferElementTypeLoweringPolicy::shouldLowerMatrixType(matrixType, config);
    }

    virtual bool shouldAlwaysCreateLoweredStorageTypeForCompositeTypes(
        TypeLoweringConfig config) override
    {
        // For spirv backend, we always want to lower all array types, even if the element type
        // comes out the same. This is because different layout rules may have different array
        // stride requirements.
        //
        // Additionally, `buffer` blocks do not work correctly unless lowered when targeting
        // GLSL.
        return target->shouldEmitSPIRVDirectly() && config.addressSpace != AddressSpace::Input;
    }

    LoweredElementTypeInfo lowerLeafLogicalType(IRType* type, TypeLoweringConfig config) override
    {
        if (target->shouldEmitSPIRVDirectly())
        {
            LoweredElementTypeInfo info = {};
            info.originalType = type;


Review comment (suggestion):
also: `AddressSpace::UserPointer`.

Use a `switch` statement to list all cases, instead of using concatenated `||` exprs for readabilty.

Code after:
    KhronosTargetBufferElementTypeLoweringPolicy(
        TargetProgram* inTarget,
        BufferElementTypeLoweringOptions inOptions)
        : DefaultBufferElementTypeLoweringPolicy(inTarget, inOptions)
    {
    }

    virtual bool canUseStorageTypeInLocalVar() override
    {
        // SPIRV (Vulkan) does not allow using an explicitly laid out type to declare a local
        // variable.
        return false;
    }

    virtual bool shouldLowerMatrixType(IRMatrixType* matrixType, TypeLoweringConfig config) override
    {
        // For spirv, we generally want to lower all matrix types, because SPIRV does not support
        // specifying matrix layout/stride if the matrix type is used in places other than
        // defining a struct field. This means that if a matrix is used to define a varying
        // parameter, we always want to wrap it in a struct.
        // Matrices within uniform and storage buffers are already members in the overall buffer
        // struct type, hence do not need to be lowered.
        if (target->shouldEmitSPIRVDirectly())
        {
            switch (config.addressSpace)
            {
            case AddressSpace::Uniform:
            case AddressSpace::StorageBuffer:
                return false;
            default:
                return true;
            }
        }

        return DefaultBufferElementTypeLoweringPolicy::shouldLowerMatrixType(matrixType, config);
    }

    virtual bool shouldAlwaysCreateLoweredStorageTypeForCompositeTypes(
        TypeLoweringConfig config) override
    {
        // For spirv backend, we always want to lower all array types, even if the element type
        // comes out the same. This is because different layout rules may have different array
        // stride requirements.
        //
        // Additionally, `buffer` blocks do not work correctly unless lowered when targeting
        // GLSL.
        return target->shouldEmitSPIRVDirectly() && config.addressSpace != AddressSpace::Input;
    }

    LoweredElementTypeInfo lowerLeafLogicalType(IRType* type, TypeLoweringConfig config) override
    {