diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c5d6b8510..273587eb52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,9 +63,9 @@ For naga changelogs at or before v0.14.0. See [naga's changelog](naga/CHANGELOG. - Improve algorithm used by module compaction. By @jimblandy in [#4662](https://github.com/gfx-rs/wgpu/pull/4662). -##### MSL-OUT +- In Metal Shading Language output, fix issue where local variables were sometimes using variable names from previous functions. -- Fix issue where local variables were sometimes using variable names from previous functions. +- When reading GLSL, fix the argument types of the double-precision floating-point overloads of the `dot`, `reflect`, `distance`, and `ldexp` builtin functions. Correct the WGSL generated for constructing 64-bit floating-point matrices. Add tests for all the above. By @jimblandy in [#4684](https://github.com/gfx-rs/wgpu/pull/4684). ## v0.18.0 (2023-10-25) diff --git a/naga/src/back/wgsl/writer.rs b/naga/src/back/wgsl/writer.rs index 2a398e8845..cd9ae076f3 100644 --- a/naga/src/back/wgsl/writer.rs +++ b/naga/src/back/wgsl/writer.rs @@ -524,14 +524,14 @@ impl Writer { TypeInner::Matrix { columns, rows, - width: _, + width, } => { write!( self.out, - //TODO: Can matrix be other than f32? - "mat{}x{}", + "mat{}x{}<{}>", back::vector_size_str(columns), back::vector_size_str(rows), + scalar_kind_str(crate::Scalar::float(width)) )?; } TypeInner::Pointer { base, space } => { diff --git a/naga/src/front/glsl/builtins.rs b/naga/src/front/glsl/builtins.rs index 0b01204dac..afe404a7eb 100644 --- a/naga/src/front/glsl/builtins.rs +++ b/naga/src/front/glsl/builtins.rs @@ -1246,18 +1246,14 @@ fn inject_common_builtin( _ => unreachable!(), }; - let second_scalar = if fun == MacroCall::MathFunction(MathFunction::Ldexp) { - Scalar { - kind: Sk::Sint, - width: float_width, - } - } else { - float_scalar + let second_scalar = match fun { + MacroCall::MathFunction(MathFunction::Ldexp) => Scalar::I32, + _ => float_scalar, }; declaration .overloads - .push(module.add_builtin(vec![ty(Scalar::F32), ty(second_scalar)], fun)) + .push(module.add_builtin(vec![ty(float_scalar), ty(second_scalar)], fun)) } } "transpose" => { diff --git a/naga/tests/in/glsl/double-math-functions.frag b/naga/tests/in/glsl/double-math-functions.frag new file mode 100644 index 0000000000..78f53f9ef6 --- /dev/null +++ b/naga/tests/in/glsl/double-math-functions.frag @@ -0,0 +1,34 @@ +#version 450 + +void main() { + dvec4 a = dvec4(1.0); + dvec4 b = dvec4(2.0); + dmat4 m = dmat4(a, b, a, b); + int i = 5; + + dvec4 ceilOut = ceil(a); + dvec4 roundOut = round(a); + dvec4 floorOut = floor(a); + dvec4 fractOut = fract(a); + dvec4 truncOut = trunc(a); + dvec4 absOut = abs(a); + dvec4 sqrtOut = sqrt(a); + dvec4 inversesqrtOut = inversesqrt(a); + dvec4 signOut = sign(a); + dmat4 transposeOut = transpose(m); + dvec4 normalizeOut = normalize(a); + double lengthOut = length(a); + double determinantOut = determinant(m); + double modOut = mod(a.x, b.x); + double dotOut = dot(a, b); + dvec4 maxOut = max(a, b); + dvec4 minOut = min(a, b); + dvec4 reflectOut = reflect(a, b); + dvec3 crossOut = cross(a.xyz, b.xyz); + double distanceOut = distance(a, b); + dvec4 stepOut = step(a, b); + double ldexpOut = ldexp(a.x, i); + double smoothStepScalar = smoothstep(0.0, 1.0, 0.5); + dvec4 smoothStepVector = smoothstep(dvec4(0.0), dvec4(1.0), dvec4(0.5)); + dvec4 smoothStepMixed = smoothstep(0.0, 1.0, dvec4(0.5)); +} diff --git a/naga/tests/out/wgsl/double-math-functions.frag.wgsl b/naga/tests/out/wgsl/double-math-functions.frag.wgsl new file mode 100644 index 0000000000..d21d99f4de --- /dev/null +++ b/naga/tests/out/wgsl/double-math-functions.frag.wgsl @@ -0,0 +1,107 @@ +fn main_1() { + var a: vec4; + var b: vec4; + var m: mat4x4; + var i: i32 = 5; + var ceilOut: vec4; + var roundOut: vec4; + var floorOut: vec4; + var fractOut: vec4; + var truncOut: vec4; + var absOut: vec4; + var sqrtOut: vec4; + var inversesqrtOut: vec4; + var signOut: vec4; + var transposeOut: mat4x4; + var normalizeOut: vec4; + var lengthOut: f64; + var determinantOut: f64; + var modOut: f64; + var dotOut: f64; + var maxOut: vec4; + var minOut: vec4; + var reflectOut: vec4; + var crossOut: vec3; + var distanceOut: f64; + var stepOut: vec4; + var ldexpOut: f64; + var smoothStepScalar: f64; + var smoothStepVector: vec4; + var smoothStepMixed: vec4; + + a = vec4(f64(1.0)); + b = vec4(f64(2.0)); + let _e8 = a; + let _e9 = b; + let _e10 = a; + let _e11 = b; + m = mat4x4(vec4(_e8.x, _e8.y, _e8.z, _e8.w), vec4(_e9.x, _e9.y, _e9.z, _e9.w), vec4(_e10.x, _e10.y, _e10.z, _e10.w), vec4(_e11.x, _e11.y, _e11.z, _e11.w)); + let _e37 = a; + ceilOut = ceil(_e37); + let _e41 = a; + roundOut = round(_e41); + let _e45 = a; + floorOut = floor(_e45); + let _e49 = a; + fractOut = fract(_e49); + let _e53 = a; + truncOut = trunc(_e53); + let _e57 = a; + absOut = abs(_e57); + let _e61 = a; + sqrtOut = sqrt(_e61); + let _e65 = a; + inversesqrtOut = inverseSqrt(_e65); + let _e69 = a; + signOut = sign(_e69); + let _e73 = m; + transposeOut = transpose(_e73); + let _e77 = a; + normalizeOut = normalize(_e77); + let _e81 = a; + lengthOut = length(_e81); + let _e85 = m; + determinantOut = determinant(_e85); + let _e88 = a; + let _e90 = b; + let _e92 = a; + let _e94 = b; + modOut = (_e92.x - (floor((_e92.x / _e94.x)) * _e94.x)); + let _e103 = a; + let _e104 = b; + dotOut = dot(_e103, _e104); + let _e109 = a; + let _e110 = b; + maxOut = max(_e109, _e110); + let _e115 = a; + let _e116 = b; + minOut = min(_e115, _e116); + let _e121 = a; + let _e122 = b; + reflectOut = reflect(_e121, _e122); + let _e125 = a; + let _e127 = b; + let _e129 = a; + let _e131 = b; + crossOut = cross(_e129.xyz, _e131.xyz); + let _e137 = a; + let _e138 = b; + distanceOut = distance(_e137, _e138); + let _e143 = a; + let _e144 = b; + stepOut = step(_e143, _e144); + let _e147 = a; + let _e150 = a; + let _e152 = i; + ldexpOut = ldexp(_e150.x, _e152); + smoothStepScalar = f64(smoothstep(0.0, 1.0, 0.5)); + smoothStepVector = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5))); + smoothStepMixed = smoothstep(vec4(f64(0.0)), vec4(f64(1.0)), vec4(f64(0.5))); + return; +} + +@fragment +fn main() { + main_1(); + return; +}