[rs] Update wgpu with Naga changes, replace hello-triangle shaders with WGSL

This commit is contained in:
Dzmitry Malyshau 2020-12-07 09:45:24 -05:00
parent 19e5c748ad
commit 95dcacd1ad
7 changed files with 33 additions and 31 deletions

View File

@ -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]

View File

@ -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,
);

View File

@ -1,7 +0,0 @@
#version 450
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(1.0, 0.0, 0.0, 1.0);
}

View File

@ -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);
}

View File

@ -0,0 +1,19 @@
[[builtin(vertex_index)]]
var<in> in_vertex_index: u32;
[[builtin(position)]]
var<out> out_pos: vec4<f32>;
[[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<f32>(x, y, 0.0, 1.0);
}
[[location(0)]]
var<out> out_color: vec4<f32>;
[[stage(fragment)]]
fn fs_main() {
out_color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
}