Skip to content

Commit

Permalink
[glsl-in] fix swizzle in a global const context
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Jan 3, 2024
1 parent a0c2b25 commit b47d492
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion naga/src/front/glsl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,11 @@ impl Index<Handle<Expression>> for Context<'_> {
type Output = Expression;

fn index(&self, index: Handle<Expression>) -> &Self::Output {
&self.expressions[index]
if self.is_const {
&self.module.const_expressions[index]
} else {
&self.expressions[index]
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions naga/tests/in/glsl/const-global-swizzle.frag
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 26 additions & 0 deletions naga/tests/out/wgsl/const-global-swizzle.frag.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
struct FragmentOutput {
@location(0) o_Target: vec4<f32>,
}

const blank: vec2<f32> = vec2<f32>(0f, 1f);

var<private> v_Uv_1: vec2<f32>;
var<private> o_Target: vec4<f32>;

fn main_1() {
var col: vec2<f32>;

let _e3 = v_Uv_1;
col = (_e3.xy * blank);
let _e7 = col;
o_Target = vec4<f32>(_e7.x, _e7.y, 0f, 1f);
return;
}

@fragment
fn main(@location(0) v_Uv: vec2<f32>) -> FragmentOutput {
v_Uv_1 = v_Uv;
main_1();
let _e9 = o_Target;
return FragmentOutput(_e9);
}

0 comments on commit b47d492

Please sign in to comment.