From ffad50b3c275325f8fc8621f8cbc38614ce72e8f Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 12 Dec 2017 13:01:10 +0100 Subject: [PATCH] Remove duplicate swizzles in remap_swizzle. Makes HLSL image-load-store look much nicer. --- reference/opt/shaders-hlsl/comp/atomic.comp | 2 +- reference/opt/shaders-hlsl/comp/image.comp | 14 +++++++------- reference/shaders-hlsl/comp/atomic.comp | 2 +- spirv_glsl.cpp | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/reference/opt/shaders-hlsl/comp/atomic.comp b/reference/opt/shaders-hlsl/comp/atomic.comp index e485a0ce..72e15bf7 100644 --- a/reference/opt/shaders-hlsl/comp/atomic.comp +++ b/reference/opt/shaders-hlsl/comp/atomic.comp @@ -13,7 +13,7 @@ void comp_main() InterlockedAdd(uImage[int2(1, 5)], 1u, _19); uint _27; InterlockedAdd(uImage[int2(1, 5)], 1u, _27); - iImage[int2(1, 6)] = int(_27).xxxx.x; + iImage[int2(1, 6)] = int(_27).x; uint _32; InterlockedOr(uImage[int2(1, 5)], 1u, _32); uint _34; diff --git a/reference/opt/shaders-hlsl/comp/image.comp b/reference/opt/shaders-hlsl/comp/image.comp index 1cec6f59..a8fc1375 100644 --- a/reference/opt/shaders-hlsl/comp/image.comp +++ b/reference/opt/shaders-hlsl/comp/image.comp @@ -34,13 +34,13 @@ struct SPIRV_Cross_Input void comp_main() { - uImageOutF[int2(gl_GlobalInvocationID.xy)] = uImageInF[int2(gl_GlobalInvocationID.xy)].xxxx.x; - uImageOutI[int2(gl_GlobalInvocationID.xy)] = uImageInI[int2(gl_GlobalInvocationID.xy)].xxxx.x; - uImageOutU[int2(gl_GlobalInvocationID.xy)] = uImageInU[int2(gl_GlobalInvocationID.xy)].xxxx.x; - uImageOutBuffer[int(gl_GlobalInvocationID.x)] = uImageInBuffer[int(gl_GlobalInvocationID.x)].xxxx.x; - uImageOutF2[int2(gl_GlobalInvocationID.xy)] = uImageInF2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; - uImageOutI2[int2(gl_GlobalInvocationID.xy)] = uImageInI2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; - uImageOutU2[int2(gl_GlobalInvocationID.xy)] = uImageInU2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; + uImageOutF[int2(gl_GlobalInvocationID.xy)] = uImageInF[int2(gl_GlobalInvocationID.xy)].x; + uImageOutI[int2(gl_GlobalInvocationID.xy)] = uImageInI[int2(gl_GlobalInvocationID.xy)].x; + uImageOutU[int2(gl_GlobalInvocationID.xy)] = uImageInU[int2(gl_GlobalInvocationID.xy)].x; + uImageOutBuffer[int(gl_GlobalInvocationID.x)] = uImageInBuffer[int(gl_GlobalInvocationID.x)].x; + uImageOutF2[int2(gl_GlobalInvocationID.xy)] = uImageInF2[int2(gl_GlobalInvocationID.xy)].xy; + uImageOutI2[int2(gl_GlobalInvocationID.xy)] = uImageInI2[int2(gl_GlobalInvocationID.xy)].xy; + uImageOutU2[int2(gl_GlobalInvocationID.xy)] = uImageInU2[int2(gl_GlobalInvocationID.xy)].xy; float4 _135 = uImageInBuffer2[int(gl_GlobalInvocationID.x)].xyyy; uImageOutBuffer2[int(gl_GlobalInvocationID.x)] = _135.xy; uImageOutF4[int2(gl_GlobalInvocationID.xy)] = uImageInF4[int2(gl_GlobalInvocationID.xy)]; diff --git a/reference/shaders-hlsl/comp/atomic.comp b/reference/shaders-hlsl/comp/atomic.comp index e485a0ce..72e15bf7 100644 --- a/reference/shaders-hlsl/comp/atomic.comp +++ b/reference/shaders-hlsl/comp/atomic.comp @@ -13,7 +13,7 @@ void comp_main() InterlockedAdd(uImage[int2(1, 5)], 1u, _19); uint _27; InterlockedAdd(uImage[int2(1, 5)], 1u, _27); - iImage[int2(1, 6)] = int(_27).xxxx.x; + iImage[int2(1, 6)] = int(_27).x; uint _32; InterlockedOr(uImage[int2(1, 5)], 1u, _32); uint _34; diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 69a200b2..ce6fb358 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -1732,6 +1732,8 @@ string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_comp e += index_to_swizzle(min(c, input_components - 1)); if (backend.swizzle_is_function && out_type.vecsize > 1) e += "()"; + + remove_duplicate_swizzle(e); return e; } }