mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-22 15:31:03 +01:00
Make the parser code more closely follow the spec's grammar around
`unary_expression`, `postfix_expression`, and `singular_expression`.
Change the handling of postfix expressions (indexing, member/component access,
and swizzling) to apply the indirection at the appropriate time, resulting in
code improvements on all output formats. For example, where we used to generate
the following MSL:
metal::float4 _e13 = bar.matrix[3];
float b = _e13.x;
we now generate, simply:
float b = bar.matrix[3].x;
Propagate WGSL reference types correctly, so that parenthesizing expressions no
longer causes the Load Rule to be applied.
Together with #1332 (already landed), this is a replacement for #1312, and
unblocks #1352.
Fixes #1351.
55 lines
1.3 KiB
GLSL
55 lines
1.3 KiB
GLSL
#version 310 es
|
|
|
|
precision highp float;
|
|
precision highp int;
|
|
|
|
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
|
|
|
struct Foo {
|
|
vec4 a;
|
|
int b;
|
|
};
|
|
|
|
|
|
vec4 builtins() {
|
|
int s1_ = (true ? 1 : 0);
|
|
vec4 s2_ = (true ? vec4(1.0, 1.0, 1.0, 1.0) : vec4(0.0, 0.0, 0.0, 0.0));
|
|
vec4 s3_ = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(0.0, 0.0, 0.0, 0.0), bvec4(false, false, false, false));
|
|
vec4 m1_ = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0), vec4(0.5, 0.5, 0.5, 0.5));
|
|
vec4 m2_ = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0), 0.10000000149011612);
|
|
float b1_ = intBitsToFloat(ivec4(1, 1, 1, 1).x);
|
|
vec4 b2_ = intBitsToFloat(ivec4(1, 1, 1, 1));
|
|
ivec4 v_i32_zero = ivec4(vec4(0.0, 0.0, 0.0, 0.0));
|
|
return (((((vec4((ivec4(s1_) + v_i32_zero)) + s2_) + m1_) + m2_) + vec4(b1_)) + b2_);
|
|
}
|
|
|
|
vec4 splat() {
|
|
vec2 a = (((vec2(1.0) + vec2(2.0)) - vec2(3.0)) / vec2(4.0));
|
|
ivec4 b = (ivec4(5) % ivec4(2));
|
|
return (a.xyxy + vec4(b));
|
|
}
|
|
|
|
int unary() {
|
|
if ((! true)) {
|
|
return 1;
|
|
} else {
|
|
return (~ 1);
|
|
}
|
|
}
|
|
|
|
float constructors() {
|
|
Foo foo;
|
|
foo = Foo(vec4(1.0), 1);
|
|
float _e11 = foo.a.x;
|
|
return _e11;
|
|
}
|
|
|
|
void main() {
|
|
vec4 _e4 = builtins();
|
|
vec4 _e5 = splat();
|
|
int _e6 = unary();
|
|
float _e7 = constructors();
|
|
return;
|
|
}
|
|
|