From 95dcacd1ad7eeda863afcb13f9378c314cf1d31e Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 7 Dec 2020 09:45:24 -0500 Subject: [PATCH] [rs] Update wgpu with Naga changes, replace hello-triangle shaders with WGSL --- wgpu/Cargo.toml | 8 +++----- wgpu/examples/hello-triangle/main.rs | 19 +++++++++++-------- wgpu/examples/hello-triangle/shader.frag | 7 ------- wgpu/examples/hello-triangle/shader.frag.spv | Bin 352 -> 0 bytes wgpu/examples/hello-triangle/shader.vert | 11 ----------- wgpu/examples/hello-triangle/shader.vert.spv | Bin 884 -> 0 bytes wgpu/examples/hello-triangle/shader.wgsl | 19 +++++++++++++++++++ 7 files changed, 33 insertions(+), 31 deletions(-) delete mode 100644 wgpu/examples/hello-triangle/shader.frag delete mode 100644 wgpu/examples/hello-triangle/shader.frag.spv delete mode 100644 wgpu/examples/hello-triangle/shader.vert delete mode 100644 wgpu/examples/hello-triangle/shader.vert.spv create mode 100644 wgpu/examples/hello-triangle/shader.wgsl diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 332a72a78b..ecaeefecfe 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -24,16 +24,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] package = "wgpu-core" -#version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "7b886f4b1ed9a739fd0f83b8f0971bf3968d7f67" +rev = "4846e41eb0ffcaafe148833bc25c3a18abce1b26" features = ["raw-window-handle"] [dependencies.wgt] package = "wgpu-types" -#version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "7b886f4b1ed9a739fd0f83b8f0971bf3968d7f67" +rev = "4846e41eb0ffcaafe148833bc25c3a18abce1b26" [dependencies] arrayvec = "0.5" @@ -50,7 +48,7 @@ serde = { version = "1", features = ["derive"], optional = true } # want to opt into X11 explicitly. [target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.gfx-backend-gl] git = "https://github.com/gfx-rs/gfx" -rev = "654ad48ee39ce2a341407ae2857ddf4db639ea54" +rev = "f1398d29c7ad726968723a37187bd3932c539783" features = ["x11"] [dev-dependencies] diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index 24d23ed5c6..6a9ff8e67d 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -3,6 +3,7 @@ use winit::{ event_loop::{ControlFlow, EventLoop}, window::Window, }; +use std::borrow::Cow; async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::TextureFormat) { let size = window.inner_size(); @@ -32,8 +33,11 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu:: .expect("Failed to create device"); // Load the shaders from disk - let vs_module = device.create_shader_module(&wgpu::include_spirv!("shader.vert.spv")); - let fs_module = device.create_shader_module(&wgpu::include_spirv!("shader.frag.spv")); + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + experimental_translation: true, + }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: None, @@ -45,12 +49,12 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu:: label: None, layout: Some(&pipeline_layout), vertex_stage: wgpu::ProgrammableStageDescriptor { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", }, fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_main", }), // Use the default rasterizer state: no culling, no depth bias rasterization_state: None, @@ -83,8 +87,7 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu:: let _ = ( &instance, &adapter, - &vs_module, - &fs_module, + &shader, &pipeline_layout, ); diff --git a/wgpu/examples/hello-triangle/shader.frag b/wgpu/examples/hello-triangle/shader.frag deleted file mode 100644 index 74e14f410e..0000000000 --- a/wgpu/examples/hello-triangle/shader.frag +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 - -layout(location = 0) out vec4 outColor; - -void main() { - outColor = vec4(1.0, 0.0, 0.0, 1.0); -} diff --git a/wgpu/examples/hello-triangle/shader.frag.spv b/wgpu/examples/hello-triangle/shader.frag.spv deleted file mode 100644 index 59e491519bc95272ee281f0c70f2f758e7f55974..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 352 zcmYk2yJ`Yq6og0D^=?!I?PSGL5epLnf)*Awc6ow;ji4?hYwxr9R5pU&{3>{0_MDl2 z&V`Ng!;+L!No6(kh_>=5QccB>*PEZsrPesC^-YKl-R>WRNeXqBx`>v59)9mJ_w0mknd~dA z&!5~gt&QOJR)KV0zIZKgX-t><>cAfBhU+ix^)24x@VqNZOkTje!+kgY+&8!b;(Zb8 diff --git a/wgpu/examples/hello-triangle/shader.vert b/wgpu/examples/hello-triangle/shader.vert deleted file mode 100644 index 9e1e39c1bd..0000000000 --- a/wgpu/examples/hello-triangle/shader.vert +++ /dev/null @@ -1,11 +0,0 @@ -#version 450 - -out gl_PerVertex { - vec4 gl_Position; -}; - -void main() { - float x = float(gl_VertexIndex - 1); - float y = float(((gl_VertexIndex & 1) * 2) - 1); - gl_Position = vec4(x, y, 0.0, 1.0); -} diff --git a/wgpu/examples/hello-triangle/shader.vert.spv b/wgpu/examples/hello-triangle/shader.vert.spv deleted file mode 100644 index ea22e0c6c8c517586dffef3e917584826c32602b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 884 zcmZ9JO-lk{6os$asAXwpYM(Y{Z3?7CMGzIOEO0Rqw2iM|PZI36t_TkY15k<>Hfy9)QiOdMk z5B&l9ys#l;^h@jgP@t!XzcHSeS@~XuOw?74{Ns?JXzbof*Gv6%^OKaOAgXD`X7K7M-D1hdx*`maiZQ&osB3vlfJ9&?qL=LSigW$EyNV%(iwZTN(%OXp7DEsk4}UKQ}2YXjzm zV;<@>1h^Z;Gp{eeAqm%%4wn)FWpSHr!58pxKYCuO2KU<$xH)&GCpPils&FFw0HeY$ Aw*UYD diff --git a/wgpu/examples/hello-triangle/shader.wgsl b/wgpu/examples/hello-triangle/shader.wgsl new file mode 100644 index 0000000000..71934415be --- /dev/null +++ b/wgpu/examples/hello-triangle/shader.wgsl @@ -0,0 +1,19 @@ +[[builtin(vertex_index)]] +var in_vertex_index: u32; +[[builtin(position)]] +var out_pos: vec4; + +[[stage(vertex)]] +fn vs_main() { + var x: f32 = f32(i32(in_vertex_index) - 1); + var y: f32 = f32(i32(in_vertex_index & 1) * 2 - 1); + out_pos = vec4(x, y, 0.0, 1.0); +} + +[[location(0)]] +var out_color: vec4; + +[[stage(fragment)]] +fn fs_main() { + out_color = vec4(1.0, 0.0, 0.0, 1.0); +}