KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
1.96k stars 549 forks source link

Slang produces spv that works on win/linux but not with MoltenVk #2336

Closed fknfilewalker closed 1 week ago

fknfilewalker commented 3 weeks ago

Using Slang v2024.1.18 and MoltenVk from SDK 1.3.283.0

Output is:

335888549-fb5e548c-9e41-41fb-be50-5c0df315d81c

But should be: Screenshot 2024-06-02 200220

Use the code here to reproduce. https://github.com/fknfilewalker/vulkan-triangle-modern/tree/sdl

My guess is that the pointer arithmetic does not work correctly. So the shift here vertices[vid] is just 1 float.

[[vk::push_constant]] float3* vertices;

[shader("vertex")]
float4 vertexMain(uint vid : SV_VertexID) : SV_Position
{
    return float4(vertices[vid], 1.0);
}
HansKristian-Work commented 3 weeks ago

Can you upload the SPIR-V? I'm not going to figure out how to build and run a random project just to fish out a SPIR-V. Most likely this is caused by float3 being stride 16 in Metal and we have to figure out a way to deal with OpPtrAccessChain with arbitrary ArrayStride.

fknfilewalker commented 3 weeks ago

The spirv is here https://github.com/fknfilewalker/vulkan-triangle-modern/blob/sdl/src/shaders.h

Source is here https://github.com/fknfilewalker/vulkan-triangle-modern/blob/sdl/src/shaders.slang

Is this fine or do you need it in a different form?

HansKristian-Work commented 3 weeks ago

If it's not too much to ask, either a SPIR-V asm file or raw SPIR-V is fine. Surely slang can emit a .spv?

fknfilewalker commented 3 weeks ago

could only share them here in a zip (includes asm as well as spv) spv.zip

HansKristian-Work commented 3 weeks ago

Thanks. That works.

OpDecorate %_ptr_PhysicalStorageBuffer_v3float ArrayStride 12

is the culprit. If you want to workaround this in the interim, try using float4 for now. Pointer to float3 directly will be very awkward in MSL.