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 59e491519b..0000000000 Binary files a/wgpu/examples/hello-triangle/shader.frag.spv and /dev/null differ 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 ea22e0c6c8..0000000000 Binary files a/wgpu/examples/hello-triangle/shader.vert.spv and /dev/null differ 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); +}