shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
MIT License
2.14k stars 181 forks source link

Metal GFX Backend: `RWBuffer` does not work as expected with `slang-test` #4547

Open ArielG-NV opened 3 months ago

ArielG-NV commented 3 months ago

Related to: #4291 tests/compute/atomics-buffer.slang does not produce correct output with Metal target, RWBuffer data is never filled (or not read correctly). The data read back is all 0s, this may be a sign that a shader failed to launch.

csyonghe commented 3 months ago

Update: this is because slang::BindingType::MutableTypedBuffer, or TexelBuffer, is not implemented in the gfx metal backend.

More fundamentally, the test has these lines:

//TEST_INPUT:ubuffer(format=R_UInt32, data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]):out,name outputBuffer

RWBuffer<uint> outputBuffer;

The ubuffer test input line will create a buffer, and bind that buffer to outputBuffer. However, in metal, RWBuffer is translated into a texture, and we need a texture object to bind to this parameter. We currently don't have an abstraction in gfx that will map to a buffer in d3d/vulkan and a texture in metal. We probably need a TexelBuffer class for this purpose.

csyonghe commented 3 months ago

Putting this to low priority as this is only due to a limitation in gfx abstraction and not due to any compiler issues. Texel buffers are a less commonly used feature so it is OK to put on-hold its support it in gfx for now.