From 5ea746a571ced32a8975eb3a238c562b3d487149 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 31 Jul 2018 09:02:22 -0700 Subject: Fix imageStore output for types other than 4-vectors (#622) Fixes issue #620 Given a `RWTexture*` store operation like: ```hlsl RWTexture3D a; ... float x = 1.0f; a[crd] = x; ``` We were generating output GLSL like: ```glsl layout(rgba32f) image3D a; ... float x = 1.0f; imageStore(a, crd, x); ``` but in that case, the `imageStore` operation expected a `vec4` and not a `float` for the last argument, and we fail GLSL compilation. This change extends our handling of the `imageStore` operation in the stdlib so that we pad out the last argument if it is not a 4-vector. We also flesh out the code that was picking a `layout(...)` modifier for image formats so that it doesn't just blindly use `layout(rgba32f)` and instead takes the element type fed to `RWTexture3D<...>` into account. With these two changes, the above HLSL/Slang code now translates to: ```glsl layout(r32f) image3D a; ... float x = 1.0f; imageStore(a, crd, vec4(x, float(0), float(0), float(0))); ``` Note that we are padding out the `x` argument to a full vector, and also that we declare the image with `layout(r32f)` to reflect the fact that it has only as single channel. --- source/slang/core.meta.slang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/slang/core.meta.slang') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 899c24539..9da424fba 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -744,7 +744,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) break; default: - sb << "__target_intrinsic(glsl, \"imageStore($0, " << ivecN << "($1), $2)\") set;\n"; + sb << "__target_intrinsic(glsl, \"imageStore($0, " << ivecN << "($1), $V2)\") set;\n"; // Note: HLSL doesn't support component-granularity access into typed UAVs, // and also doesn't support atomic operations on them. As such, there should -- cgit v1.2.3