From 2fae02d8b297585156955b13469eb2d736928952 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 17 Mar 2021 09:35:54 -0400 Subject: [PATCH] [rs] Update naga to gfx-16 --- wgpu/Cargo.toml | 10 +++++----- wgpu/examples/boids/draw.wgsl | 4 ++-- wgpu/examples/hello-triangle/shader.wgsl | 4 ++-- wgpu/examples/mipmap/blit.wgsl | 6 +++--- wgpu/examples/mipmap/draw.wgsl | 2 +- wgpu/examples/shadow/shader.wgsl | 20 ++++++++++---------- wgpu/examples/skybox/shader.wgsl | 18 +++++++++--------- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index beef8c2e58..d58859ff16 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -26,20 +26,20 @@ webgl = ["wgc"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "2f3b398e3887a336c963c43e7954f94cae42dd31" +rev = "bb9a5a85d2bc1ee555739c646976f992a48127b5" features = ["raw-window-handle", "cross"] [target.'cfg(target_arch = "wasm32")'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "2f3b398e3887a336c963c43e7954f94cae42dd31" +rev = "bb9a5a85d2bc1ee555739c646976f992a48127b5" features = ["raw-window-handle", "cross"] optional = true [dependencies.wgt] package = "wgpu-types" git = "https://github.com/gfx-rs/wgpu" -rev = "2f3b398e3887a336c963c43e7954f94cae42dd31" +rev = "bb9a5a85d2bc1ee555739c646976f992a48127b5" [dependencies] arrayvec = "0.5" @@ -68,13 +68,13 @@ env_logger = "0.8" # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-15" +tag = "gfx-16" features = ["wgsl-in"] # used to generate SPIR-V for the Web target [target.'cfg(target_arch = "wasm32")'.dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-15" +tag = "gfx-16" features = ["wgsl-in", "spv-out"] [[example]] diff --git a/wgpu/examples/boids/draw.wgsl b/wgpu/examples/boids/draw.wgsl index 48e2386eaf..d9cf38124c 100644 --- a/wgpu/examples/boids/draw.wgsl +++ b/wgpu/examples/boids/draw.wgsl @@ -4,8 +4,8 @@ fn main( [[location(1)]] particle_vel: vec2, [[location(2)]] position: vec2, ) -> [[builtin(position)]] vec4 { - const angle: f32 = -atan2(particle_vel.x, particle_vel.y); - const pos: vec2 = vec2( + const angle = -atan2(particle_vel.x, particle_vel.y); + const pos = vec2( position.x * cos(angle) - position.y * sin(angle), position.x * sin(angle) + position.y * cos(angle) ); diff --git a/wgpu/examples/hello-triangle/shader.wgsl b/wgpu/examples/hello-triangle/shader.wgsl index 9594a07c7c..027aa9473f 100644 --- a/wgpu/examples/hello-triangle/shader.wgsl +++ b/wgpu/examples/hello-triangle/shader.wgsl @@ -1,7 +1,7 @@ [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4 { - var x: f32 = f32(i32(in_vertex_index) - 1); - var y: f32 = f32(i32(in_vertex_index & 1) * 2 - 1); + const x = f32(i32(in_vertex_index) - 1); + const y = f32(i32(in_vertex_index & 1) * 2 - 1); return vec4(x, y, 0.0, 1.0); } diff --git a/wgpu/examples/mipmap/blit.wgsl b/wgpu/examples/mipmap/blit.wgsl index 61bb6caa58..8d4c014448 100644 --- a/wgpu/examples/mipmap/blit.wgsl +++ b/wgpu/examples/mipmap/blit.wgsl @@ -6,9 +6,9 @@ struct VertexOutput { [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { var out: VertexOutput; - var x: i32 = i32(vertex_index) / 2; - var y: i32 = i32(vertex_index) & 1; - const tc: vec2 = vec2( + const x = i32(vertex_index) / 2; + const y = i32(vertex_index) & 1; + const tc = vec2( f32(x) * 2.0, f32(y) * 2.0 ); diff --git a/wgpu/examples/mipmap/draw.wgsl b/wgpu/examples/mipmap/draw.wgsl index 0b9cec5bd9..3179f39e19 100644 --- a/wgpu/examples/mipmap/draw.wgsl +++ b/wgpu/examples/mipmap/draw.wgsl @@ -12,7 +12,7 @@ var r_data: Locals; [[stage(vertex)]] fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { - var pos: vec2 = vec2( + const pos = vec2( 100.0 * (1.0 - f32(vertex_index & 2u)), 1000.0 * f32(vertex_index & 1u) ); diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl index 2cdfadcefd..fb0305542e 100644 --- a/wgpu/examples/shadow/shader.wgsl +++ b/wgpu/examples/shadow/shader.wgsl @@ -32,8 +32,8 @@ fn vs_main( [[location(0)]] position: vec4, [[location(1)]] normal: vec4, ) -> VertexOutput { - const w: mat4x4 = u_entity.world; - const world_pos: vec4 = u_entity.world * vec4(position); + const w = u_entity.world; + const world_pos = u_entity.world * vec4(position); var out: VertexOutput; out.world_normal = mat3x3(w.x.xyz, w.y.xyz, w.z.xyz) * vec3(normal.xyz); out.world_position = world_pos; @@ -67,10 +67,10 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { return 1.0; } // compensate for the Y-flip difference between the NDC and texture coordinates - const flip_correction: vec2 = vec2(0.5, -0.5); + const flip_correction = vec2(0.5, -0.5); // compute texture coordinates for shadow lookup - const proj_correction: f32 = 1.0 / homogeneous_coords.w; - const light_local: vec2 = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); + const proj_correction = 1.0 / homogeneous_coords.w; + const light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); // do the lookup, using HW PCF and comparison return textureSampleCompare(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction); } @@ -80,7 +80,7 @@ const c_max_lights: u32 = 10u; [[stage(fragment)]] fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { - const normal: vec3 = normalize(in.world_normal); + const normal = normalize(in.world_normal); // accumulate color var color: vec3 = c_ambient; var i: u32 = 0u; @@ -88,12 +88,12 @@ fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { if (i >= min(u_globals.num_lights.x, c_max_lights)) { break; } - const light: Light = s_lights.data[i]; + const light = s_lights.data[i]; // project into the light space - const shadow: f32 = fetch_shadow(i, light.proj * in.world_position); + const shadow = fetch_shadow(i, light.proj * in.world_position); // compute Lambertian diffuse term - const light_dir: vec3 = normalize(light.pos.xyz - in.world_position.xyz); - const diffuse: f32 = max(0.0, dot(normal, light_dir)); + const light_dir = normalize(light.pos.xyz - in.world_position.xyz); + const diffuse = max(0.0, dot(normal, light_dir)); // add light contribution color = color + shadow * diffuse * light.color.xyz; continuing { diff --git a/wgpu/examples/skybox/shader.wgsl b/wgpu/examples/skybox/shader.wgsl index fe4af3aed6..1a5888ea2a 100644 --- a/wgpu/examples/skybox/shader.wgsl +++ b/wgpu/examples/skybox/shader.wgsl @@ -20,9 +20,9 @@ var r_data: Data; [[stage(vertex)]] fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput { // hacky way to draw a large triangle - var tmp1: i32 = i32(vertex_index) / 2; - var tmp2: i32 = i32(vertex_index) & 1; - const pos: vec4 = vec4( + const tmp1 = i32(vertex_index) / 2; + const tmp2 = i32(vertex_index) & 1; + const pos = vec4( f32(tmp1) * 4.0 - 1.0, f32(tmp2) * 4.0 - 1.0, 1.0, @@ -30,8 +30,8 @@ fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput { ); // transposition = inversion for this orthonormal matrix - const inv_model_view: mat3x3 = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); - const unprojected: vec4 = r_data.proj_inv * pos; + const inv_model_view = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); + const unprojected = r_data.proj_inv * pos; var out: SkyOutput; out.uv = inv_model_view * unprojected.xyz; @@ -69,10 +69,10 @@ fn fs_sky(in: SkyOutput) -> [[location(0)]] vec4 { [[stage(fragment)]] fn fs_entity(in: EntityOutput) -> [[location(0)]] vec4 { - const incident: vec3 = normalize(in.view); - const normal: vec3 = normalize(in.normal); - const reflected: vec3 = incident - 2.0 * dot(normal, incident) * normal; + const incident = normalize(in.view); + const normal = normalize(in.normal); + const reflected = incident - 2.0 * dot(normal, incident) * normal; - const reflected_color: vec4 = textureSample(r_texture, r_sampler, reflected); + const reflected_color = textureSample(r_texture, r_sampler, reflected); return vec4(0.1, 0.1, 0.1, 0.1) + 0.5 * reflected_color; }