Skip to content

Construct OpAccessChains for RawBufferLoad properly, or overhaul the API #4985

Closed
@devshgraphicsprogramming

Description

struct Test {
    float4 mem1;
    float mem2;
    int mem3;
};

Glslang with GL_EXT_buffer_reference

%23 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_Test_r %_ %int_0
%24 = OpLoad %_ptr_PhysicalStorageBuffer_Test_r %23
%27 = OpAccessChain %_ptr_PhysicalStorageBuffer_float %24 %int_0 %int_1
%28 = OpLoad %float %27 Aligned 4

DXC with vk::RawBufferLoad<Test>(addr).mem2

%36 = OpBitcast %_ptr_PhysicalStorageBuffer_Test %35
%37 = OpLoad %Test %36 Aligned 4
%38 = OpCompositeExtract %float %37 1
    OpStore %30 %38

Now imagine I declared a large array for histogram or something as a member variable.

This is probably a dup of some issue (searched but couldn't find it in the ocean of open SPIR-V issues), since I'm certainly not the first person to discover this.

My suggestion to fix this is

namespace vk
{

namespace impl
{

// you'll need to magically generate and instantiate internally within Clang when you encounter it
template<typename T>
struct AccessChain;
/*
{
   // actually emit the OpLoad
   operator T() const;
   
   // all members redeclared but with types exchanged from U to AccessChain<U>
};
*/

}

template<typename T>
AccessChain<T> RawBufferLoad(uint64_t addr);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions