From 122126c006e53bd48064f220104d425b8bf91ddf Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 5 Feb 2020 10:16:14 -0800 Subject: Add support for RWBuffer writes on GLSL/SPIR-V target (#1199) This appears to have been an oversight in the work that added support for `imageStore` as well as atomics when writing to `RWTexture*` and friends. The HLSL/Slang `RWBuffer` type maps to GLSL as an `imageBuffer`, which is effectively just another case of writable texture image (bonus points to anybody who can explain to me the meaningful distinction between an `imageBuffer` and an `image1D`). This change copies the handling of subscript access (`operator[]`) from textures over to buffers, and adds a test case to confirm that the new handling works for the simple case of setting a buffer element. --- tests/cross-compile/rw-buffer.slang | 14 ++++++++++++++ tests/cross-compile/rw-buffer.slang.glsl | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/cross-compile/rw-buffer.slang create mode 100644 tests/cross-compile/rw-buffer.slang.glsl (limited to 'tests') diff --git a/tests/cross-compile/rw-buffer.slang b/tests/cross-compile/rw-buffer.slang new file mode 100644 index 000000000..f5246ed78 --- /dev/null +++ b/tests/cross-compile/rw-buffer.slang @@ -0,0 +1,14 @@ +// rw-buffer.slang + +// Confirm that writing into a `RWBuffer` generates appropriate GLSL/SPIR-V. + +//TEST:CROSS_COMPILE: -profile ps_5_0 -entry main -target spirv-assembly + +RWBuffer buffer; + + +float4 main(float u : U, int idx : IDX) : SV_Target +{ + buffer[idx] = u; + return u; +} diff --git a/tests/cross-compile/rw-buffer.slang.glsl b/tests/cross-compile/rw-buffer.slang.glsl new file mode 100644 index 000000000..55e25656e --- /dev/null +++ b/tests/cross-compile/rw-buffer.slang.glsl @@ -0,0 +1,26 @@ +// rw-buffer.slang.glsl +//TEST_IGNORE_FILE: + +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; + +layout(r32f) +layout(binding = 0) +uniform imageBuffer buffer_0; + +layout(location = 0) +out vec4 _S1; + +layout(location = 0) +in float _S2; + +flat layout(location = 1) +in int _S3; + +void main() +{ + imageStore(buffer_0, int(uint(_S3)), vec4(_S2, float(0), float(0), float(0))); + _S1 = vec4(_S2); + return; +} -- cgit v1.2.3