Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
devshgraphicsprogramming opened this issue Jan 31, 2023 · 1 comment

Comments

@devshgraphicsprogramming
Copy link

devshgraphicsprogramming commented Jan 31, 2023

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);
}
@natevm
Copy link
Contributor

natevm commented Feb 1, 2023

This appears to be a duplicate of #4986 and should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants