DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIRV] Incorrect error reported for non uint type template parameter: "error: alignment argument of vk::RawBufferLoad() must be a constant integer"

Open Cazadorro opened this issue 2 years ago • 2 comments

I'm trying to find the consequences of this feature, https://github.com/microsoft/DirectXShaderCompiler/pull/4226, thought it didn't work with template arguments, but it does, realizing that it only takes uint arguments. Error reported made it seem like something completely different.


struct StructTest{
    float a;
    float b; 
};



struct PhysicalDeviceAddress{
    uint64_t address; 
    template<typename T, const int alignment> 
    T load(){
        return vk::RawBufferLoad<T>(address, alignment);
    }
};


[numthreads(1, 1, 1)]
void main(uint tidx : SV_DispatchThreadId) {
    uint64_t test = 0; 
    PhysicalDeviceAddress address = PhysicalDeviceAddress(test); 
    StructTest x = address.load<StructTest, 8>(); 
}

tried in https://shader-playground.timjones.io/# using

MicrosoftDXC, trunk, cs_6_6, entry point main, extra options: -HV 2021, output format SPIR-V, SPIR_V target vulkan 1.3

results in

D:\local\Temp\9796b5d4-0e93-4f29-9a5a-883cbae55d48.hlsl:13:46: error: alignment argument of vk::RawBufferLoad() must be a constant integer
        return vk::RawBufferLoad<T>(address, alignment);
                                             ^

which is not the correct error. The error is that I used a constant integer, instead of a constant unsigned integer.

Cazadorro avatar Aug 14 '22 17:08 Cazadorro

Tagging @Keenuts and @cassiebeckley for visibility. This is a vulkan issue

pow2clk avatar Aug 15 '22 20:08 pow2clk

It seems like the solution to this could be to just change the compiler error message to

“alignment argument of vk::RawBufferLoad() must be a constant unsigned integer”

Am I understanding correctly? That seems like an easy enough change.

natevm avatar Aug 28 '22 22:08 natevm

it seems a bit weird that alignment was added to the RawBufferLoad API as a function and not a template parameter, does LLVM 3.7 or DXC have a problem with const int default template args or what?

I believe it’s discussed here in the referenced issue why a template wasn’t used. Something about template features not always being available for mobile architectures? Tbh I don’t know if I follow, seems like a default template argument would be better…

https://github.com/microsoft/DirectXShaderCompiler/pull/4226#issuecomment-1048883666

natevm avatar Feb 01 '23 01:02 natevm