From 7efa54e41555ec8687a474182fe7574f9b62ad07 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:57:10 +0100 Subject: [PATCH] [glsl-in] fix swizzle in a global const context --- naga/src/front/glsl/context.rs | 6 ++++- naga/tests/in/glsl/const-global-swizzle.frag | 15 +++++++++++ .../out/wgsl/const-global-swizzle.frag.wgsl | 26 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 naga/tests/in/glsl/const-global-swizzle.frag create mode 100644 naga/tests/out/wgsl/const-global-swizzle.frag.wgsl diff --git a/naga/src/front/glsl/context.rs b/naga/src/front/glsl/context.rs index 8a5249211e..98ec021a5a 100644 --- a/naga/src/front/glsl/context.rs +++ b/naga/src/front/glsl/context.rs @@ -1478,7 +1478,11 @@ impl Index> for Context<'_> { type Output = Expression; fn index(&self, index: Handle) -> &Self::Output { - &self.expressions[index] + if self.is_const { + &self.module.const_expressions[index] + } else { + &self.expressions[index] + } } } diff --git a/naga/tests/in/glsl/const-global-swizzle.frag b/naga/tests/in/glsl/const-global-swizzle.frag new file mode 100644 index 0000000000..956f33560d --- /dev/null +++ b/naga/tests/in/glsl/const-global-swizzle.frag @@ -0,0 +1,15 @@ +// ISSUE: #4773 +#version 450 + +#define MIX2(c) c.xy + +layout(location = 0) in vec2 v_Uv; + +layout(location = 0) out vec4 o_Target; + +const vec2 blank = MIX2(vec2(0.0, 1.0)); + +void main() { + vec2 col = MIX2(v_Uv) * blank; + o_Target = vec4(col, 0.0, 1.0); +} \ No newline at end of file diff --git a/naga/tests/out/wgsl/const-global-swizzle.frag.wgsl b/naga/tests/out/wgsl/const-global-swizzle.frag.wgsl new file mode 100644 index 0000000000..dee49c2463 --- /dev/null +++ b/naga/tests/out/wgsl/const-global-swizzle.frag.wgsl @@ -0,0 +1,26 @@ +struct FragmentOutput { + @location(0) o_Target: vec4, +} + +const blank: vec2 = vec2(0f, 1f); + +var v_Uv_1: vec2; +var o_Target: vec4; + +fn main_1() { + var col: vec2; + + let _e3 = v_Uv_1; + col = (_e3.xy * blank); + let _e7 = col; + o_Target = vec4(_e7.x, _e7.y, 0f, 1f); + return; +} + +@fragment +fn main(@location(0) v_Uv: vec2) -> FragmentOutput { + v_Uv_1 = v_Uv; + main_1(); + let _e9 = o_Target; + return FragmentOutput(_e9); +}