diff --git a/src/front/glsl/parser/declarations.rs b/src/front/glsl/parser/declarations.rs index a91f15c9ed..954c5807f3 100644 --- a/src/front/glsl/parser/declarations.rs +++ b/src/front/glsl/parser/declarations.rs @@ -251,8 +251,7 @@ impl<'source> ParsingContext<'source> { } else if ctx.external { init.and_then(|expr| ctx.ctx.lift_up_const_expression(expr).ok()) } else { - None - // init.filter(|expr| ctx.ctx.expressions.is_const(*expr)) + init.filter(|expr| ctx.ctx.expressions.is_const(*expr)) }; let pointer = ctx.add_var(frontend, ty, name, maybe_const_expr, meta)?; diff --git a/tests/out/wgsl/246-collatz-comp.wgsl b/tests/out/wgsl/246-collatz-comp.wgsl index 0712aedec3..424051cf8b 100644 --- a/tests/out/wgsl/246-collatz-comp.wgsl +++ b/tests/out/wgsl/246-collatz-comp.wgsl @@ -8,11 +8,10 @@ var gl_GlobalInvocationID: vec3; fn collatz_iterations(n: u32) -> u32 { var n_1: u32; - var i: u32; + var i: u32 = 0u; _ = (&global.indices); n_1 = n; - i = 0u; loop { let _e7 = n_1; if !((_e7 != 1u)) { diff --git a/tests/out/wgsl/277-casting-frag.wgsl b/tests/out/wgsl/277-casting-frag.wgsl index 84c50ddd45..87761aff4e 100644 --- a/tests/out/wgsl/277-casting-frag.wgsl +++ b/tests/out/wgsl/277-casting-frag.wgsl @@ -1,7 +1,6 @@ fn main_1() { - var a: f32; + var a: f32 = 1.0; - a = 1.0; return; } diff --git a/tests/out/wgsl/280-matrix-cast-frag.wgsl b/tests/out/wgsl/280-matrix-cast-frag.wgsl index ad9f85b74e..aceabfc63e 100644 --- a/tests/out/wgsl/280-matrix-cast-frag.wgsl +++ b/tests/out/wgsl/280-matrix-cast-frag.wgsl @@ -1,8 +1,7 @@ fn main_1() { - var a: mat4x4; + var a: mat4x4 = mat4x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); - a = mat4x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); - return; + _ = mat4x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); } @fragment diff --git a/tests/out/wgsl/901-lhs-field-select-frag.wgsl b/tests/out/wgsl/901-lhs-field-select-frag.wgsl index 71b9870512..b39e71f82a 100644 --- a/tests/out/wgsl/901-lhs-field-select-frag.wgsl +++ b/tests/out/wgsl/901-lhs-field-select-frag.wgsl @@ -1,7 +1,7 @@ fn main_1() { - var a: vec4; + var a: vec4 = vec4(1.0); - a = vec4(1.0); + _ = vec4(1.0); a.x = 2.0; return; } diff --git a/tests/out/wgsl/932-for-loop-if-frag.wgsl b/tests/out/wgsl/932-for-loop-if-frag.wgsl index f9a29ae87e..ad1fdd34ee 100644 --- a/tests/out/wgsl/932-for-loop-if-frag.wgsl +++ b/tests/out/wgsl/932-for-loop-if-frag.wgsl @@ -1,7 +1,6 @@ fn main_1() { - var i: i32; + var i: i32 = 0; - i = 0; loop { let _e2 = i; if !((_e2 < 1)) { diff --git a/tests/out/wgsl/bevy-pbr-frag.wgsl b/tests/out/wgsl/bevy-pbr-frag.wgsl index 4bc7a1870a..27bdc97f86 100644 --- a/tests/out/wgsl/bevy-pbr-frag.wgsl +++ b/tests/out/wgsl/bevy-pbr-frag.wgsl @@ -452,8 +452,8 @@ fn EnvBRDFApprox(f0_7: vec3, perceptual_roughness: f32, NoV_6: f32) -> vec3 var f0_8: vec3; var perceptual_roughness_1: f32; var NoV_7: f32; - var c0_: vec4; - var c1_: vec4; + var c0_: vec4 = vec4(-1.0, -0.0275, -0.572, 0.022); + var c1_: vec4 = vec4(1.0, 0.0425, 1.04, -0.04); var r: vec4; var a004_: f32; var AB: vec2; @@ -472,8 +472,8 @@ fn EnvBRDFApprox(f0_7: vec3, perceptual_roughness: f32, NoV_6: f32) -> vec3 f0_8 = f0_7; perceptual_roughness_1 = perceptual_roughness; NoV_7 = NoV_6; - c0_ = vec4(-1.0, -0.0275, -0.572, 0.022); - c1_ = vec4(1.0, 0.0425, 1.04, -0.04); + _ = vec4(-1.0, -0.0275, -0.572, 0.022); + _ = vec4(1.0, 0.0425, 1.04, -0.04); let _e62 = perceptual_roughness_1; let _e64 = c0_; let _e66 = c1_; @@ -943,7 +943,7 @@ fn dir_light(light_2: DirectionalLight, roughness_10: f32, NdotV_2: f32, normal: var NoH_5: f32; var LoH_7: f32; var diffuse_1: vec3; - var specularIntensity_3: f32; + var specularIntensity_3: f32 = 1.0; var specular_2: vec3; _ = (&global.ViewProj); @@ -1014,7 +1014,6 @@ fn dir_light(light_2: DirectionalLight, roughness_10: f32, NdotV_2: f32, normal: let _e124 = LoH_7; let _e125 = Fd_Burley(_e121, _e122, _e123, _e124); diffuse_1 = (_e116 * _e125); - specularIntensity_3 = 1.0; _ = F0_3; _ = roughness_11; _ = half_vector; @@ -1060,9 +1059,9 @@ fn main_1() { var F0_4: vec3; var diffuseColor_4: vec3; var R_4: vec3; - var light_accum: vec3; - var i: i32; - var i_1: i32; + var light_accum: vec3 = vec3(0.0); + var i: i32 = 0; + var i_1: i32 = 0; var diffuse_ambient: vec3; var specular_ambient: vec3; @@ -1191,8 +1190,7 @@ fn main_1() { let _e217 = V_3; let _e219 = N_2; R_4 = reflect(-(_e217), _e219); - light_accum = vec3(0.0); - i = 0; + _ = vec3(0.0); loop { let _e227 = i; let _e228 = global_2.NumLights; @@ -1228,7 +1226,6 @@ fn main_1() { i = (_e236 + 1); } } - i_1 = 0; loop { let _e264 = i_1; let _e265 = global_2.NumLights; diff --git a/tests/out/wgsl/bits_glsl-frag.wgsl b/tests/out/wgsl/bits_glsl-frag.wgsl index 1d23bb84cf..9dcc2be191 100644 --- a/tests/out/wgsl/bits_glsl-frag.wgsl +++ b/tests/out/wgsl/bits_glsl-frag.wgsl @@ -1,25 +1,23 @@ fn main_1() { - var i: i32; - var i2_: vec2; - var i3_: vec3; - var i4_: vec4; - var u: u32; - var u2_: vec2; - var u3_: vec3; - var u4_: vec4; - var f2_: vec2; - var f4_: vec4; + var i: i32 = 0; + var i2_: vec2 = vec2(0); + var i3_: vec3 = vec3(0); + var i4_: vec4 = vec4(0); + var u: u32 = 0u; + var u2_: vec2 = vec2(0u); + var u3_: vec3 = vec3(0u); + var u4_: vec4 = vec4(0u); + var f2_: vec2 = vec2(0.0); + var f4_: vec4 = vec4(0.0); - i = 0; - i2_ = vec2(0); - i3_ = vec3(0); - i4_ = vec4(0); - u = 0u; - u2_ = vec2(0u); - u3_ = vec3(0u); - u4_ = vec4(0u); - f2_ = vec2(0.0); - f4_ = vec4(0.0); + _ = vec2(0); + _ = vec3(0); + _ = vec4(0); + _ = vec2(0u); + _ = vec3(0u); + _ = vec4(0u); + _ = vec2(0.0); + _ = vec4(0.0); _ = f4_; let _e33 = f4_; u = pack4x8snorm(_e33); diff --git a/tests/out/wgsl/constant-array-size-frag.wgsl b/tests/out/wgsl/constant-array-size-frag.wgsl index 18da4f7cd9..613dd37a42 100644 --- a/tests/out/wgsl/constant-array-size-frag.wgsl +++ b/tests/out/wgsl/constant-array-size-frag.wgsl @@ -8,11 +8,10 @@ const NUM_VECS: i32 = 42; var global: Data; fn function() -> vec4 { - var sum: vec4; - var i: i32; + var sum: vec4 = vec4(0.0); + var i: i32 = 0; - sum = vec4(0.0); - i = 0; + _ = vec4(0.0); loop { let _e9 = i; if !((_e9 < NUM_VECS)) { diff --git a/tests/out/wgsl/declarations-frag.wgsl b/tests/out/wgsl/declarations-frag.wgsl index 209ee13dcc..f7112612c4 100644 --- a/tests/out/wgsl/declarations-frag.wgsl +++ b/tests/out/wgsl/declarations-frag.wgsl @@ -28,8 +28,8 @@ var array_2d: array, 2>; var array_toomanyd: array, 2>, 2>, 2>, 2>, 2>, 2>; fn main_1() { - var positions: array, 2>; - var strct: TestStruct; + var positions: array, 2> = array, 2>(vec3(-1.0, 1.0, 0.0), vec3(-1.0, -1.0, 0.0)); + var strct: TestStruct = TestStruct(1.0, 2.0); var from_input_array: vec4; var a_1: f32; var b: f32; @@ -38,8 +38,8 @@ fn main_1() { _ = (&vert.a); _ = (&frag.position); _ = (&frag.a); - positions = array, 2>(vec3(-1.0, 1.0, 0.0), vec3(-1.0, -1.0, 0.0)); - strct = TestStruct(1.0, 2.0); + _ = array, 2>(vec3(-1.0, 1.0, 0.0), vec3(-1.0, -1.0, 0.0)); + _ = TestStruct(1.0, 2.0); let _e35 = in_array_2[1]; from_input_array = _e35; let _e41 = array_2d[0][0]; diff --git a/tests/out/wgsl/expressions-frag.wgsl b/tests/out/wgsl/expressions-frag.wgsl index 19b60a57c6..6b3ccf55e2 100644 --- a/tests/out/wgsl/expressions-frag.wgsl +++ b/tests/out/wgsl/expressions-frag.wgsl @@ -280,25 +280,21 @@ fn testUnaryOpMat(a_16: mat3x3) { } fn testStructConstructor() { - var tree: BST; + var tree: BST = BST(1); - tree = BST(1); - return; + _ = BST(1); } fn testNonScalarToScalarConstructor() { - var f: f32; + var f: f32 = 1.0; _ = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0)); - f = 1.0; - return; } fn testArrayConstructor() { - var tree_1: array; + var tree_1: array = array(0.0); - tree_1 = array(0.0); - return; + _ = array(0.0); } fn testFreestandingConstructor() { @@ -306,10 +302,9 @@ fn testFreestandingConstructor() { } fn testNonImplicitCastVectorCast() { - var a_18: u32; + var a_18: u32 = 1u; var b_16: vec4; - a_18 = 1u; let _e3 = a_18; b_16 = vec4(i32(_e3)); return; @@ -394,13 +389,11 @@ fn testLength() { fn testConstantLength(a_24: array) { var a_25: array; - var len_1: i32; + var len_1: i32 = 4; _ = (&global_1.a); a_25 = a_24; _ = a_25; - len_1 = 4; - return; } fn indexConstantNonConstantIndex(i: i32) { diff --git a/tests/out/wgsl/long-form-matrix-frag.wgsl b/tests/out/wgsl/long-form-matrix-frag.wgsl index 202986485c..299fc1e32a 100644 --- a/tests/out/wgsl/long-form-matrix-frag.wgsl +++ b/tests/out/wgsl/long-form-matrix-frag.wgsl @@ -1,36 +1,35 @@ fn main_1() { - var splat: mat2x2; - var normal: mat2x2; - var from_matrix: mat2x4; - var a: mat2x2; - var b: mat2x2; - var c: mat3x3; - var d: mat3x3; - var e: mat4x4; + var splat: mat2x2 = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0)); + var normal: mat2x2 = mat2x2(vec2(1.0, 1.0), vec2(2.0, 2.0)); + var from_matrix: mat2x4 = mat2x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0)); + var a: mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + var b: mat2x2 = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + var c: mat3x3 = mat3x3(vec3(1.0, 2.0, 3.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); + var d: mat3x3 = mat3x3(vec3(2.0, 2.0, 1.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); + var e: mat4x4 = mat4x4(vec4(2.0, 2.0, 1.0, 1.0), vec4(1.0, 1.0, 2.0, 2.0), vec4(1.0, 1.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0)); - splat = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0)); + _ = mat2x2(vec2(1.0, 0.0), vec2(0.0, 1.0)); _ = vec2(1.0); _ = vec2(2.0); - normal = mat2x2(vec2(1.0, 1.0), vec2(2.0, 2.0)); + _ = mat2x2(vec2(1.0, 1.0), vec2(2.0, 2.0)); _ = mat3x3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0)); - from_matrix = mat2x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0)); - a = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + _ = mat2x4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0)); + _ = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); _ = vec2(2.0, 3.0); - b = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); + _ = mat2x2(vec2(1.0, 2.0), vec2(3.0, 4.0)); _ = vec3(1.0); _ = vec3(1.0); - c = mat3x3(vec3(1.0, 2.0, 3.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); + _ = mat3x3(vec3(1.0, 2.0, 3.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); _ = vec2(2.0); _ = vec3(1.0); _ = vec3(1.0); - d = mat3x3(vec3(2.0, 2.0, 1.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); + _ = mat3x3(vec3(2.0, 2.0, 1.0), vec3(1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0)); _ = vec2(2.0); _ = vec4(1.0); _ = vec2(2.0); _ = vec4(1.0); _ = vec4(1.0); - e = mat4x4(vec4(2.0, 2.0, 1.0, 1.0), vec4(1.0, 1.0, 2.0, 2.0), vec4(1.0, 1.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0)); - return; + _ = mat4x4(vec4(2.0, 2.0, 1.0, 1.0), vec4(1.0, 1.0, 2.0, 2.0), vec4(1.0, 1.0, 1.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0)); } @fragment diff --git a/tests/out/wgsl/math-functions-frag.wgsl b/tests/out/wgsl/math-functions-frag.wgsl index c86ac56bba..0bfc734976 100644 --- a/tests/out/wgsl/math-functions-frag.wgsl +++ b/tests/out/wgsl/math-functions-frag.wgsl @@ -1,8 +1,8 @@ fn main_1() { - var a: vec4; - var b: vec4; + var a: vec4 = vec4(1.0); + var b: vec4 = vec4(2.0); var m: mat4x4; - var i: i32; + var i: i32 = 5; var ceilOut: vec4; var roundOut: vec4; var floorOut: vec4; @@ -48,14 +48,13 @@ fn main_1() { var smoothStepVector: vec4; var smoothStepMixed: vec4; - a = vec4(1.0); - b = vec4(2.0); + _ = vec4(1.0); + _ = vec4(2.0); let _e6 = a; let _e7 = b; let _e8 = a; let _e9 = b; m = mat4x4(vec4(_e6.x, _e6.y, _e6.z, _e6.w), vec4(_e7.x, _e7.y, _e7.z, _e7.w), vec4(_e8.x, _e8.y, _e8.z, _e8.w), vec4(_e9.x, _e9.y, _e9.z, _e9.w)); - i = 5; _ = a; let _e35 = a; ceilOut = ceil(_e35); diff --git a/tests/out/wgsl/prepostfix-frag.wgsl b/tests/out/wgsl/prepostfix-frag.wgsl index 5b8f1bfb6e..891edb932b 100644 --- a/tests/out/wgsl/prepostfix-frag.wgsl +++ b/tests/out/wgsl/prepostfix-frag.wgsl @@ -1,12 +1,11 @@ fn main_1() { var scalar_target: i32; - var scalar: i32; + var scalar: i32 = 1; var vec_target: vec2; - var vec: vec2; + var vec: vec2 = vec2(1u); var mat_target: mat4x3; - var mat: mat4x3; + var mat: mat4x3 = mat4x3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 0.0)); - scalar = 1; let _e3 = scalar; scalar = (_e3 + 1); scalar_target = _e3; @@ -14,7 +13,7 @@ fn main_1() { let _e8 = (_e6 - 1); scalar = _e8; scalar_target = _e8; - vec = vec2(1u); + _ = vec2(1u); let _e14 = vec; vec = (_e14 - vec2(1u)); vec_target = _e14; @@ -22,7 +21,7 @@ fn main_1() { let _e21 = (_e18 + vec2(1u)); vec = _e21; vec_target = _e21; - mat = mat4x3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 0.0)); + _ = mat4x3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 0.0)); let _e32 = mat; let _e34 = vec3(1.0); mat = (_e32 + mat4x3(_e34, _e34, _e34, _e34)); diff --git a/tests/out/wgsl/sampler-functions-frag.wgsl b/tests/out/wgsl/sampler-functions-frag.wgsl index 5275b756e9..13c57d1b71 100644 --- a/tests/out/wgsl/sampler-functions-frag.wgsl +++ b/tests/out/wgsl/sampler-functions-frag.wgsl @@ -1,9 +1,8 @@ fn CalcShadowPCF1_(T_P_t_TextureDepth: texture_depth_2d, S_P_t_TextureDepth: sampler_comparison, t_ProjCoord: vec3) -> f32 { var t_ProjCoord_1: vec3; - var t_Res: f32; + var t_Res: f32 = 0.0; t_ProjCoord_1 = t_ProjCoord; - t_Res = 0.0; let _e6 = t_Res; let _e7 = t_ProjCoord_1; _ = _e7.xyz;