Skip to content

Commit

Permalink
Merge branch 'naga-wgsl-out-f32-literals-suffix' into prerequisites-n…
Browse files Browse the repository at this point in the history
…aga-wgsl-abstract-operators-unary
  • Loading branch information
jimblandy committed Dec 12, 2023
2 parents ba71970 + 466d8a3 commit 71c9d69
Show file tree
Hide file tree
Showing 64 changed files with 597 additions and 599 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ Passing an owned value `window` to `Surface` will return a `Surface<'static>`. S

- In WGSL output, always include the `i` suffix on `i32` literals. By @jimblandy in [#4863](https://github.com/gfx-rs/wgpu/pull/4863).

- In WGSL output, always include the `f` suffix on `f32` literals. By @jimblandy in [#4869](https://github.com/gfx-rs/wgpu/pull/4869).

### Bug Fixes

#### General
Expand Down
32 changes: 14 additions & 18 deletions naga/src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,25 +1087,21 @@ impl<W: Write> Writer<W> {
use crate::Expression;

match expressions[expr] {
Expression::Literal(literal) => {
match literal {
// Floats are written using `Debug` instead of `Display` because it always appends the
// decimal part even it's zero
crate::Literal::F32(value) => write!(self.out, "{:?}", value)?,
crate::Literal::U32(value) => write!(self.out, "{}u", value)?,
crate::Literal::I32(value) => write!(self.out, "{}i", value)?,
crate::Literal::Bool(value) => write!(self.out, "{}", value)?,
crate::Literal::F64(value) => write!(self.out, "{:?}lf", value)?,
crate::Literal::I64(_) => {
return Err(Error::Custom("unsupported i64 literal".to_string()));
}
crate::Literal::AbstractInt(_) | crate::Literal::AbstractFloat(_) => {
return Err(Error::Custom(
"Abstract types should not appear in IR presented to backends".into(),
));
}
Expression::Literal(literal) => match literal {
crate::Literal::F32(value) => write!(self.out, "{}f", value)?,
crate::Literal::U32(value) => write!(self.out, "{}u", value)?,
crate::Literal::I32(value) => write!(self.out, "{}i", value)?,
crate::Literal::Bool(value) => write!(self.out, "{}", value)?,
crate::Literal::F64(value) => write!(self.out, "{:?}lf", value)?,
crate::Literal::I64(_) => {
return Err(Error::Custom("unsupported i64 literal".to_string()));
}
}
crate::Literal::AbstractInt(_) | crate::Literal::AbstractFloat(_) => {
return Err(Error::Custom(
"Abstract types should not appear in IR presented to backends".into(),
));
}
},
Expression::Constant(handle) => {
let constant = &module.constants[handle];
if constant.name.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/wgsl/210-bevy-2d-shader.vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ fn main_1() {
v_Uv = _e10;
let _e11 = Vertex_Position_1;
let _e12 = global_2.size;
position = (_e11 * vec3<f32>(_e12.x, _e12.y, 1.0));
position = (_e11 * vec3<f32>(_e12.x, _e12.y, 1f));
let _e20 = global.ViewProj;
let _e21 = global_1.Model;
let _e23 = position;
gl_Position = ((_e20 * _e21) * vec4<f32>(_e23.x, _e23.y, _e23.z, 1.0));
gl_Position = ((_e20 * _e21) * vec4<f32>(_e23.x, _e23.y, _e23.z, 1f));
return;
}

Expand Down
6 changes: 3 additions & 3 deletions naga/tests/out/wgsl/210-bevy-shader.vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ var<private> gl_Position: vec4<f32>;
fn main_1() {
let _e10 = global_1.Model;
let _e11 = Vertex_Normal_1;
v_Normal = (_e10 * vec4<f32>(_e11.x, _e11.y, _e11.z, 1.0)).xyz;
v_Normal = (_e10 * vec4<f32>(_e11.x, _e11.y, _e11.z, 1f)).xyz;
let _e19 = global_1.Model;
let _e29 = Vertex_Normal_1;
v_Normal = (mat3x3<f32>(_e19[0].xyz, _e19[1].xyz, _e19[2].xyz) * _e29);
let _e31 = global_1.Model;
let _e32 = Vertex_Position_1;
v_Position = (_e31 * vec4<f32>(_e32.x, _e32.y, _e32.z, 1.0)).xyz;
v_Position = (_e31 * vec4<f32>(_e32.x, _e32.y, _e32.z, 1f)).xyz;
let _e40 = Vertex_Uv_1;
v_Uv = _e40;
let _e42 = global.ViewProj;
let _e43 = v_Position;
gl_Position = (_e42 * vec4<f32>(_e43.x, _e43.y, _e43.z, 1.0));
gl_Position = (_e42 * vec4<f32>(_e43.x, _e43.y, _e43.z, 1f));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion naga/tests/out/wgsl/246-collatz.comp.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn collatz_iterations(n: u32) -> u32 {
{
let _e14 = n_1;
let _e15 = f32(_e14);
if ((_e15 - (floor((_e15 / 2.0)) * 2.0)) == 0.0) {
if ((_e15 - (floor((_e15 / 2f)) * 2f)) == 0f) {
{
let _e25 = n_1;
n_1 = (_e25 / 2u);
Expand Down
2 changes: 1 addition & 1 deletion naga/tests/out/wgsl/277-casting.frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main_1() {
var a: f32 = 1.0;
var a: f32 = 1f;

return;
}
Expand Down
2 changes: 1 addition & 1 deletion naga/tests/out/wgsl/280-matrix-cast.frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main_1() {
var a: mat4x4<f32> = mat4x4<f32>(vec4<f32>(1.0, 0.0, 0.0, 0.0), vec4<f32>(0.0, 1.0, 0.0, 0.0), vec4<f32>(0.0, 0.0, 1.0, 0.0), vec4<f32>(0.0, 0.0, 0.0, 1.0));
var a: mat4x4<f32> = mat4x4<f32>(vec4<f32>(1f, 0f, 0f, 0f), vec4<f32>(0f, 1f, 0f, 0f), vec4<f32>(0f, 0f, 1f, 0f), vec4<f32>(0f, 0f, 0f, 1f));

}

Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/wgsl/800-out-of-bounds-panic.vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ fn main_1() {
let _e9 = global.view_matrix;
let _e10 = global_1.world_matrix;
let _e12 = position_1;
gl_Position = ((_e9 * _e10) * vec4<f32>(_e12.x, _e12.y, 0.0, 1.0));
gl_Position = ((_e9 * _e10) * vec4<f32>(_e12.x, _e12.y, 0f, 1f));
let _e20 = gl_Position;
let _e22 = gl_Position;
gl_Position.z = ((_e20.z + _e22.w) / 2.0);
gl_Position.z = ((_e20.z + _e22.w) / 2f);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/wgsl/900-implicit-conversions.frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ fn implicit_dims_3(v_6: vec4<f32>) {

fn main_1() {
exact_1(1i);
implicit(1.0);
implicit_dims_2(vec3(1.0));
implicit(1f);
implicit_dims_2(vec3(1f));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/wgsl/901-lhs-field-select.frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main_1() {
var a: vec4<f32> = vec4(1.0);
var a: vec4<f32> = vec4(1f);

a.x = 2.0;
a.x = 2f;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion naga/tests/out/wgsl/931-constant-emitting.frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const constant: i32 = 10i;

fn function() -> f32 {
return 0.0;
return 0f;
}

fn main_1() {
Expand Down
80 changes: 40 additions & 40 deletions naga/tests/out/wgsl/abstract-types-const.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ struct S {
}

const xvupaiai: vec2<u32> = vec2<u32>(42u, 43u);
const xvfpaiai: vec2<f32> = vec2<f32>(44.0, 45.0);
const xvfpaiai: vec2<f32> = vec2<f32>(44f, 45f);
const xvupuai: vec2<u32> = vec2<u32>(42u, 43u);
const xvupaiu: vec2<u32> = vec2<u32>(42u, 43u);
const xvuuai: vec2<u32> = vec2<u32>(42u, 43u);
const xvuaiu: vec2<u32> = vec2<u32>(42u, 43u);
const xmfpaiaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const xmfpafaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const xmfpaiafaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const xmfpaiaiafai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const xmfpaiaiaiaf: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const imfpaiaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const imfpafaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const imfpafafafaf: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1.0, 2.0), vec2<f32>(3.0, 4.0));
const xmfpaiaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const xmfpafaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const xmfpaiafaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const xmfpaiaiafai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const xmfpaiaiaiaf: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const imfpaiaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const imfpafaiaiai: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const imfpafafafaf: mat2x2<f32> = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
const ivispai: vec2<i32> = vec2(1i);
const ivfspaf: vec2<f32> = vec2(1.0);
const ivfspaf: vec2<f32> = vec2(1f);
const ivis_ai: vec2<i32> = vec2(1i);
const ivus_ai: vec2<u32> = vec2(1u);
const ivfs_ai: vec2<f32> = vec2(1.0);
const ivfs_af: vec2<f32> = vec2(1.0);
const iafafaf: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const iafaiai: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const iafpafaf: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const iafpaiaf: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const iafpafai: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const xafpafaf: array<f32, 2> = array<f32, 2>(1.0, 2.0);
const s_f_i_u: S = S(1.0, 1i, 1u);
const s_f_iai: S = S(1.0, 1i, 1u);
const s_fai_u: S = S(1.0, 1i, 1u);
const s_faiai: S = S(1.0, 1i, 1u);
const saf_i_u: S = S(1.0, 1i, 1u);
const saf_iai: S = S(1.0, 1i, 1u);
const safai_u: S = S(1.0, 1i, 1u);
const safaiai: S = S(1.0, 1i, 1u);
const ivfr_f_f: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivfr_f_af: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivfraf_f: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivfraf_af: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivf_fr_f: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivf_fraf: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivf_afr_f: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivf_afraf: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivfr_f_ai: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivfrai_f: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivfrai_ai: vec3<f32> = vec3<f32>(vec2<f32>(1.0, 2.0), 3.0);
const ivf_frai: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivf_air_f: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivf_airai: vec3<f32> = vec3<f32>(1.0, vec2<f32>(2.0, 3.0));
const ivfs_ai: vec2<f32> = vec2(1f);
const ivfs_af: vec2<f32> = vec2(1f);
const iafafaf: array<f32, 2> = array<f32, 2>(1f, 2f);
const iafaiai: array<f32, 2> = array<f32, 2>(1f, 2f);
const iafpafaf: array<f32, 2> = array<f32, 2>(1f, 2f);
const iafpaiaf: array<f32, 2> = array<f32, 2>(1f, 2f);
const iafpafai: array<f32, 2> = array<f32, 2>(1f, 2f);
const xafpafaf: array<f32, 2> = array<f32, 2>(1f, 2f);
const s_f_i_u: S = S(1f, 1i, 1u);
const s_f_iai: S = S(1f, 1i, 1u);
const s_fai_u: S = S(1f, 1i, 1u);
const s_faiai: S = S(1f, 1i, 1u);
const saf_i_u: S = S(1f, 1i, 1u);
const saf_iai: S = S(1f, 1i, 1u);
const safai_u: S = S(1f, 1i, 1u);
const safaiai: S = S(1f, 1i, 1u);
const ivfr_f_f: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivfr_f_af: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivfraf_f: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivfraf_af: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivf_fr_f: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivf_fraf: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivf_afr_f: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivf_afraf: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivfr_f_ai: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivfrai_f: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivfrai_ai: vec3<f32> = vec3<f32>(vec2<f32>(1f, 2f), 3f);
const ivf_frai: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivf_air_f: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));
const ivf_airai: vec3<f32> = vec3<f32>(1f, vec2<f32>(2f, 3f));

36 changes: 18 additions & 18 deletions naga/tests/out/wgsl/abstract-types-operators.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const plus_fafaf_1: f32 = 3.0;
const plus_fafai_1: f32 = 3.0;
const plus_faf_f_1: f32 = 3.0;
const plus_faiaf_1: f32 = 3.0;
const plus_faiai_1: f32 = 3.0;
const plus_fai_f_1: f32 = 3.0;
const plus_f_faf_1: f32 = 3.0;
const plus_f_fai_1: f32 = 3.0;
const plus_f_f_f_1: f32 = 3.0;
const plus_fafaf_1: f32 = 3f;
const plus_fafai_1: f32 = 3f;
const plus_faf_f_1: f32 = 3f;
const plus_faiaf_1: f32 = 3f;
const plus_faiai_1: f32 = 3f;
const plus_fai_f_1: f32 = 3f;
const plus_f_faf_1: f32 = 3f;
const plus_f_fai_1: f32 = 3f;
const plus_f_f_f_1: f32 = 3f;
const plus_iaiai_1: i32 = 3i;
const plus_iai_i_1: i32 = 3i;
const plus_i_iai_1: i32 = 3i;
Expand All @@ -17,14 +17,14 @@ const plus_u_uai_1: u32 = 3u;
const plus_u_u_u_1: u32 = 3u;

fn runtime_values() {
var f: f32 = 42.0;
var f: f32 = 42f;
var i: i32 = 43i;
var u: u32 = 44u;
var plus_fafaf: f32 = 3.0;
var plus_fafai: f32 = 3.0;
var plus_fafaf: f32 = 3f;
var plus_fafai: f32 = 3f;
var plus_faf_f: f32;
var plus_faiaf: f32 = 3.0;
var plus_faiai: f32 = 3.0;
var plus_faiaf: f32 = 3f;
var plus_faiai: f32 = 3f;
var plus_fai_f: f32;
var plus_f_faf: f32;
var plus_f_fai: f32;
Expand All @@ -39,13 +39,13 @@ fn runtime_values() {
var plus_u_u_u: u32;

let _e8 = f;
plus_faf_f = (1.0 + _e8);
plus_faf_f = (1f + _e8);
let _e14 = f;
plus_fai_f = (1.0 + _e14);
plus_fai_f = (1f + _e14);
let _e18 = f;
plus_f_faf = (_e18 + 2.0);
plus_f_faf = (_e18 + 2f);
let _e22 = f;
plus_f_fai = (_e22 + 2.0);
plus_f_fai = (_e22 + 2f);
let _e26 = f;
let _e27 = f;
plus_f_f_f = (_e26 + _e27);
Expand Down
Loading

0 comments on commit 71c9d69

Please sign in to comment.