tutorial9 wgsl attempt

pull/177/head
Ben Hansen 3 years ago
parent 601273ec2b
commit 8a72178353

4
Cargo.lock generated

@ -833,6 +833,7 @@ dependencies = [
"arrayvec",
"bitflags",
"fxhash",
"gfx-auxil",
"gfx-hal",
"glow",
"js-sys",
@ -842,6 +843,7 @@ dependencies = [
"naga",
"parking_lot",
"raw-window-handle",
"spirv_cross",
"wasm-bindgen",
"web-sys",
]
@ -859,6 +861,7 @@ dependencies = [
"copyless",
"foreign-types",
"fxhash",
"gfx-auxil",
"gfx-hal",
"log",
"metal",
@ -868,6 +871,7 @@ dependencies = [
"profiling",
"range-alloc",
"raw-window-handle",
"spirv_cross",
"storage-map",
]

@ -13,7 +13,7 @@ futures = "0.3"
image = "0.23"
log = "0.4"
tobj = "2.0"
wgpu = "0.8"
wgpu = {version = "0.8", features = [ "cross" ]}
winit = "0.24"
[build-dependencies]

@ -261,7 +261,8 @@ impl State {
features: wgpu::Features::empty(),
limits: wgpu::Limits::default(),
},
Some(&std::path::Path::new("trace")), // Trace path
// Some(&std::path::Path::new("trace")), // Trace path
None, // Trace path
)
.await
.unwrap();
@ -388,8 +389,13 @@ impl State {
)
.unwrap();
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 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: Some("shader.wgsl"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
flags: wgpu::ShaderFlags::VALIDATION,
});
let depth_texture =
texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture");
@ -405,12 +411,12 @@ impl State {
label: Some("Render Pipeline"),
layout: Some(&render_pipeline_layout),
vertex: wgpu::VertexState {
module: &vs_module,
module: &shader,
entry_point: "main",
buffers: &[model::ModelVertex::desc(), InstanceRaw::desc()],
},
fragment: Some(wgpu::FragmentState {
module: &fs_module,
module: &shader,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: sc_desc.format,

@ -0,0 +1,53 @@
// Vertex shader
[[block]]
struct Uniforms {
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
var<uniform> uniforms: Uniforms;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
[[stage(vertex)]]
fn main(
model: VertexInput,
instance: InstanceInput,
) -> VertexOutput {
let model_matrix = mat4x4<f32>(
instance.model_matrix_0,
instance.model_matrix_1,
instance.model_matrix_2,
instance.model_matrix_3,
);
var out: VertexOutput;
out.tex_coords = model.tex_coords;
out.clip_position = uniforms.view_proj * model_matrix * vec4<f32>(model.position, 1.0);
return out;
}
// Fragment shader
[[group(0), binding(0)]]
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
var s_diffuse: sampler;
[[stage(fragment)]]
fn main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -13,7 +13,7 @@ futures = "0.3"
image = "0.23"
log = "0.4"
tobj = "2.0"
wgpu = "0.8"
wgpu = { version = "0.8", features = ["cross"]}
winit = "0.24"
[build-dependencies]

@ -266,9 +266,11 @@ fn create_render_pipeline(
color_format: wgpu::TextureFormat,
depth_format: Option<wgpu::TextureFormat>,
vertex_layouts: &[wgpu::VertexBufferLayout],
vs_src: wgpu::ShaderModuleDescriptor,
fs_src: wgpu::ShaderModuleDescriptor,
mut vs_src: wgpu::ShaderModuleDescriptor,
mut fs_src: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
vs_src.flags = wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION;
fs_src.flags = wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION;
let vs_module = device.create_shader_module(&vs_src);
let fs_module = device.create_shader_module(&fs_src);
@ -341,7 +343,7 @@ impl State {
features: wgpu::Features::empty(),
limits: wgpu::Limits::default(),
},
Some(&std::path::Path::new("trace")), // Trace path
None,
)
.await
.unwrap();

Loading…
Cancel
Save