diff --git a/Cargo.toml b/Cargo.toml index 7ef1119..d538441 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ slab = "^0.4" smallmap = "^1.0" smallvec = "^1.0" strum = { version = "0.24", features = ["derive"] } -wgpu = "^0.12" +wgpu = "^0.13" winit = "0.26" [dependencies.legion] @@ -31,7 +31,7 @@ version = "^0.4" optional = true [dependencies.naga] -version = "0.8.5" +version = "0.9" features = ["wgsl-in", "glsl-in", "wgsl-out", "serialize", "deserialize"] [[bin]] diff --git a/editor/Cargo.toml b/editor/Cargo.toml index 1e9af72..d78b2b5 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -7,16 +7,16 @@ edition = "2021" bytemuck = "^1.0" crossbeam-channel = "^0.5" cyborg = { path = "../", features = ["legion"] } -egui = "0.17.0" -egui-winit = "0.17.0" -egui_wgpu_backend = "0.17.0" +egui = "0.18" +egui-winit = "0.18.0" +egui_wgpu_backend = "0.18.0" glam = { version = "0.20", features = ["serde"] } gltf = { version = "1.0", features = ["utils"] } legion = "^0.4" parking_lot = "^0.11" pollster = "0.2" puffin = "^0.13" -puffin_egui = "0.14.0" +puffin_egui = "0.16.0" rfd = "^0.8" stl = "0.2.1" diff --git a/editor/src/main.rs b/editor/src/main.rs index 370639e..30ff556 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -60,10 +60,10 @@ impl Application { .unwrap(); let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: surface.get_preferred_format(&adapter).unwrap(), + format: *surface.get_supported_formats(&adapter).first().unwrap(), width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::Fifo, }; surface.configure(&device, &config); diff --git a/shaders/mesh_forward.wgsl b/shaders/mesh_forward.wgsl index 6ab86d9..bfa58dd 100644 --- a/shaders/mesh_forward.wgsl +++ b/shaders/mesh_forward.wgsl @@ -1,30 +1,30 @@ struct CameraUniform { - eye: vec4; - vp: mat4x4; + eye: vec4, + vp: mat4x4, }; struct VertexInput { - [[location(0)]] position: vec3; - [[location(1)]] tan_frame: u32; + @location(0) position: vec3, + @location(1) tan_frame: u32, }; struct VertexOutput { - [[builtin(position)]] clip_position: vec4; - [[location(0)]] position: vec3; - [[location(1)]] color: vec3; + @builtin(position) clip_position: vec4, + @location(0) position: vec3, + @location(1) color: vec3, }; -[[group(0), binding(0)]] +@group(0) @binding(0) var camera: CameraUniform; fn random(seed: u32, salt: f32) -> f32 { return abs(sin((f32(seed & u32(0x11111)) * 0.7071 + salt) * 78.233)); } -[[stage(vertex)]] +@vertex fn vs_main( - [[builtin(instance_index)]] mesh_idx: u32, - [[builtin(vertex_index)]] vertex_idx: u32, + @builtin(instance_index) mesh_idx: u32, + @builtin(vertex_index) vertex_idx: u32, vertex: VertexInput, ) -> VertexOutput { let world_pos = vertex.position; @@ -38,9 +38,9 @@ fn vs_main( return out; } -[[stage(fragment)]] +@fragment fn fs_main( frag: VertexOutput, -) -> [[location(0)]] vec4 { +) -> @location(0) vec4 { return vec4(frag.color, 1.0); } diff --git a/shaders/mesh_skinning.wgsl b/shaders/mesh_skinning.wgsl index b091650..d136fe1 100644 --- a/shaders/mesh_skinning.wgsl +++ b/shaders/mesh_skinning.wgsl @@ -2,32 +2,33 @@ #include skin.wgsl struct SkinningUniform { - transform: mat4x4; - src_offset: u32; - dst_offset: u32; - count: u32; + transform: mat4x4, + src_offset: u32, + dst_offset: u32, + count: u32, }; -[[group(0), binding(0)]] +@group(0) @binding(0) var skinning_ubo: SkinningUniform; -[[group(0), binding(1)]] +@group(0) @binding(1) var dst_vertices: SkinnedVertexArray; -[[group(0), binding(2)]] +@group(0) @binding(2) var src_vertices: SkinnedVertexArray; -[[stage(compute), workgroup_size(64)]] +@compute +@workgroup_size(64) fn cs_main( - [[builtin(global_invocation_id)]] global_invocation_id: vec3, + @builtin(global_invocation_id) global_invocation_id: vec3, ) { let vertex_index = global_invocation_id.x; if (vertex_index >= skinning_ubo.count) { return; } - let src_index = skinning_ubo.src_offset + vertex_index; - let dst_index = skinning_ubo.dst_offset + vertex_index; + let src_index = skinning_ubo.src_offset + vertex_index; + let dst_index = skinning_ubo.dst_offset + vertex_index; let ptf = src_vertices.data[src_index].ptf; let position = ptf.xyz; diff --git a/shaders/oct_encoding.wgsl b/shaders/oct_encoding.wgsl index 201cd09..1fefb09 100644 --- a/shaders/oct_encoding.wgsl +++ b/shaders/oct_encoding.wgsl @@ -1,6 +1,6 @@ struct TangentFrame { - normal: vec3; - tangent: vec3; + normal: vec3, + tangent: vec3 }; // https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/?like_comment=12 diff --git a/shaders/skin.wgsl b/shaders/skin.wgsl index 3d382f4..69c18dd 100644 --- a/shaders/skin.wgsl +++ b/shaders/skin.wgsl @@ -1,7 +1,7 @@ struct SkinnedVertex { - ptf: vec4; + ptf: vec4 }; struct SkinnedVertexArray { - data: array; + data: array }; diff --git a/src/lib.rs b/src/lib.rs index 110e9f2..448f57d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,14 +268,14 @@ impl Renderer { let mut rp = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: target_views.output, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), store: true, }, - }], + })], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { view: target_views.depth, depth_ops: Some(wgpu::Operations { diff --git a/src/pass/debug.rs b/src/pass/debug.rs index 0c0170f..135f1c1 100644 --- a/src/pass/debug.rs +++ b/src/pass/debug.rs @@ -24,7 +24,7 @@ impl DebugPass { target_info: ViewportInfo, ) -> Self { // TODO hook into ShaderStore system - let shader = device.create_shader_module(&wgpu::include_wgsl!("debug_shader.wgsl")); + let shader = device.create_shader_module(wgpu::include_wgsl!("debug_shader.wgsl")); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("DebugPass Pipeline Layout"), @@ -43,11 +43,11 @@ impl DebugPass { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format: target_info.output_format, blend: Some(wgpu::BlendState::REPLACE), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::LineList, @@ -130,7 +130,7 @@ impl RenderPass for DebugPass { self.device .create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor { label: Some("DebugPass Render Bundle"), - color_formats: &[self.target_info.output_format], + color_formats: &[Some(self.target_info.output_format)], depth_stencil: Some(wgpu::RenderBundleDepthStencil { format: self.target_info.depth_format, depth_read_only: false, // TODO optimize? diff --git a/src/pass/debug_shader.wgsl b/src/pass/debug_shader.wgsl index ffba437..445d2cf 100644 --- a/src/pass/debug_shader.wgsl +++ b/src/pass/debug_shader.wgsl @@ -1,26 +1,26 @@ struct CameraUniform { - eye: vec4; - vp: mat4x4; + eye: vec4, + vp: mat4x4, }; struct VertexInput { - [[location(0)]] position: vec3; - [[location(1)]] color: vec3; + @location(0) position: vec3, + @location(1) color: vec3 }; struct VertexOutput { - [[builtin(position)]] clip_position: vec4; - [[location(0)]] position: vec3; - [[location(1)]] color: vec3; + @builtin(position) clip_position: vec4, + @location(0) position: vec3, + @location(1) color: vec3 }; -[[group(0), binding(0)]] +@group(0) @binding(0) var camera: CameraUniform; -[[stage(vertex)]] +@vertex fn vs_main( - [[builtin(instance_index)]] mesh_idx: u32, - [[builtin(vertex_index)]] vertex_idx: u32, + @builtin(instance_index) mesh_idx: u32, + @builtin(vertex_index) vertex_idx: u32, vertex: VertexInput, ) -> VertexOutput { let world_pos = vertex.position; @@ -32,9 +32,9 @@ fn vs_main( return out; } -[[stage(fragment)]] +@fragment fn fs_main( frag: VertexOutput, -) -> [[location(0)]] vec4 { +) -> @location(0) vec4 { return vec4(frag.color, 1.0); } diff --git a/src/pass/mesh.rs b/src/pass/mesh.rs index e2ca3b8..dd3598d 100644 --- a/src/pass/mesh.rs +++ b/src/pass/mesh.rs @@ -142,11 +142,11 @@ impl MeshPass { let shader = shader_info.store.get(&shader_info.forward).unwrap(); - let targets = &[wgpu::ColorTargetState { + let targets = &[Some(wgpu::ColorTargetState { format: target_info.output_format, blend: Some(wgpu::BlendState::REPLACE), write_mask: wgpu::ColorWrites::ALL, - }]; + })]; let mut pipeline_desc = wgpu::RenderPipelineDescriptor { label: Some("Opaque MeshPass Pipeline"), @@ -449,7 +449,7 @@ impl RenderPass for MeshPass { mesh.vertex_count / 64 + 1 }; - cmds.dispatch(workgroup_num as u32, 1, 1); + cmds.dispatch_workgroups(workgroup_num as u32, 1, 1); } } } @@ -465,7 +465,7 @@ impl RenderPass for MeshPass { self.device .create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor { label: Some("Opaque Pass Render Bundle"), - color_formats: &[self.target_info.output_format], + color_formats: &[Some(self.target_info.output_format)], depth_stencil: Some(wgpu::RenderBundleDepthStencil { format: self.target_info.depth_format, depth_read_only: false, // TODO optimize? diff --git a/src/shader.rs b/src/shader.rs index 3ac07ee..0ff4368 100644 --- a/src/shader.rs +++ b/src/shader.rs @@ -83,7 +83,7 @@ impl ShaderStore { fn load_wgsl(&self, wgsl_source: String) -> Result { let shader = self .device - .create_shader_module(&wgpu::ShaderModuleDescriptor { + .create_shader_module(wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Owned(wgsl_source)), }); diff --git a/src/viewport.rs b/src/viewport.rs index 5675286..596ca00 100644 --- a/src/viewport.rs +++ b/src/viewport.rs @@ -58,10 +58,10 @@ impl WinitViewport { .unwrap(); let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: surface.get_preferred_format(&adapter).unwrap(), + format: *surface.get_supported_formats(&adapter).first().unwrap(), width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::Fifo, }; surface.configure(&device, &config);