From 843529c7bb1edf90e6182df33112d2f200e4e1ed Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 3 Feb 2021 22:30:43 -0500 Subject: [PATCH] Update to latest wgpu git (around 0.7), temporarily disable shader validation due to naga bug, rebase fixes!! --- voxygen/Cargo.toml | 2 +- voxygen/src/render/pipelines/clouds.rs | 40 +++--- voxygen/src/render/pipelines/figure.rs | 58 +++++---- voxygen/src/render/pipelines/fluid.rs | 83 ++++++------ voxygen/src/render/pipelines/lod_terrain.rs | 67 +++++----- voxygen/src/render/pipelines/particle.rs | 90 ++++++------- voxygen/src/render/pipelines/postprocess.rs | 49 ++++--- voxygen/src/render/pipelines/shadow.rs | 136 ++++++++++---------- voxygen/src/render/pipelines/skybox.rs | 66 +++++----- voxygen/src/render/pipelines/sprite.rs | 90 ++++++------- voxygen/src/render/pipelines/terrain.rs | 66 +++++----- voxygen/src/render/pipelines/ui.rs | 79 +++++------- voxygen/src/render/renderer.rs | 4 +- voxygen/src/render/renderer/drawer.rs | 27 +++- voxygen/src/scene/terrain.rs | 22 ++-- voxygen/src/window.rs | 13 +- 16 files changed, 447 insertions(+), 445 deletions(-) diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 86e4fa260f..ca7cc92441 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -45,7 +45,7 @@ i18n = {package = "veloren-i18n", path = "i18n"} # Graphics winit = {version = "0.24.0", features = ["serde"]} -wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "ab8b0e3766558d541206da2790dfd63f15b13bc4" } +wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "f891e86e87f0733f04a8078f4be8ead2f24551cf" } bytemuck = { version="1.4", features=["derive"] } shaderc = "0.6.2" diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index b657e2dcd1..7b4244e33b 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -171,30 +171,34 @@ impl CloudsPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Clouds pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, + front_face: wgpu::FrontFace::Ccw, + cull_mode: wgpu::CullMode::None, + polygon_mode: wgpu::PolygonMode::Fill, + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, + }, + fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + alpha_blend: wgpu::BlendState::REPLACE, + color_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], }), - rasterization_state: None, - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[], - }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, }); Self { diff --git a/voxygen/src/render/pipelines/figure.rs b/voxygen/src/render/pipelines/figure.rs index 799f42087f..695e1a33a7 100644 --- a/voxygen/src/render/pipelines/figure.rs +++ b/voxygen/src/render/pipelines/figure.rs @@ -202,48 +202,50 @@ impl FigurePipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Figure pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index a8a8fa55b9..d0d9305917 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -32,11 +32,10 @@ impl Vertex { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 1] = - wgpu::vertex_attr_array![0 => Uint]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 1] = wgpu::vertex_attr_array![0 => Uint]; + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -145,56 +144,58 @@ impl FluidPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Fluid pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::None, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: false, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/lod_terrain.rs b/voxygen/src/render/pipelines/lod_terrain.rs index f7774cf24f..de601a49f2 100644 --- a/voxygen/src/render/pipelines/lod_terrain.rs +++ b/voxygen/src/render/pipelines/lod_terrain.rs @@ -16,11 +16,10 @@ impl Vertex { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 1] = - wgpu::vertex_attr_array![0 => Float2]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 1] = wgpu::vertex_attr_array![0 => Float2]; + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -162,48 +161,50 @@ impl LodTerrainPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Lod terrain pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index 009589a290..66d2813848 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -32,11 +32,11 @@ impl Vertex { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 2] = + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 2] = wgpu::vertex_attr_array![0 => Float3, 1 => Uint]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -154,10 +154,10 @@ impl Instance { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 6] = wgpu::vertex_attr_array![2 => Float, 3 => Float, 4 => Float, 5 => Int, 6 => Float3, 7 => Float3]; - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 6] = wgpu::vertex_attr_array![2 => Float, 3 => Float, 4 => Float, 5 => Int, 6 => Float3, 7 => Float3]; + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::InputStepMode::Instance, attributes: &ATTRIBUTES, } @@ -200,56 +200,58 @@ impl ParticlePipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Particle pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc(), Instance::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc(), Instance::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/postprocess.rs b/voxygen/src/render/pipelines/postprocess.rs index 09ec66baba..fcb40f0fb7 100644 --- a/voxygen/src/render/pipelines/postprocess.rs +++ b/voxygen/src/render/pipelines/postprocess.rs @@ -114,7 +114,6 @@ impl PostProcessPipeline { sc_desc: &wgpu::SwapChainDescriptor, global_layout: &GlobalsLayouts, layout: &PostProcessLayout, - aa_mode: AaMode, ) -> Self { common_base::span!(_guard, "PostProcessPipeline::new"); let render_pipeline_layout = @@ -124,41 +123,37 @@ impl PostProcessPipeline { bind_group_layouts: &[&global_layout.globals, &layout.layout], }); - let samples = match aa_mode { - AaMode::None | AaMode::Fxaa => 1, - // TODO: Ensure sampling in the shader is exactly between the 4 texels - AaMode::MsaaX4 => 4, - AaMode::MsaaX8 => 8, - AaMode::MsaaX16 => 16, - }; - let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Post process pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, + front_face: wgpu::FrontFace::Ccw, + cull_mode: wgpu::CullMode::None, + polygon_mode: wgpu::PolygonMode::Fill, + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, + fragment: Some(wgpu::FragmentState { module: fs_module, entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], }), - rasterization_state: None, - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[], - }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, }); Self { diff --git a/voxygen/src/render/pipelines/shadow.rs b/voxygen/src/render/pipelines/shadow.rs index 56ba0ff024..a74d4e7957 100644 --- a/voxygen/src/render/pipelines/shadow.rs +++ b/voxygen/src/render/pipelines/shadow.rs @@ -157,43 +157,41 @@ impl ShadowFigurePipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Directed shadow figure pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[TerrainVertex::desc()], }, - fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - })*/None, - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: wgpu::CullMode::Front, + cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: true, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth24Plus, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: true, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[TerrainVertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: None, }); Self { @@ -233,43 +231,41 @@ impl ShadowPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Directed shadow pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[TerrainVertex::desc()], }, - fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - })*/None, - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: wgpu::CullMode::Front, + cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: true, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth24Plus, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: true, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[TerrainVertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: None, }); Self { @@ -311,43 +307,41 @@ impl PointShadowPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Point shadow pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[TerrainVertex::desc()], }, - fragment_stage: /*Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - })*/None, - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth24Plus, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[TerrainVertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: None, }); Self { diff --git a/voxygen/src/render/pipelines/skybox.rs b/voxygen/src/render/pipelines/skybox.rs index c041c89d90..072e8d17bc 100644 --- a/voxygen/src/render/pipelines/skybox.rs +++ b/voxygen/src/render/pipelines/skybox.rs @@ -9,11 +9,11 @@ pub struct Vertex { } impl Vertex { - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[wgpu::VertexAttributeDescriptor { + attributes: &[wgpu::VertexAttribute { offset: 0, shader_location: 0, format: wgpu::VertexFormat::Float3, @@ -58,48 +58,50 @@ impl SkyboxPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Skybox pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 442fe16648..55c774a908 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -60,11 +60,11 @@ impl Vertex { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 3] = + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 3] = wgpu::vertex_attr_array![0 => Float3, 1 => Uint, 2 => Uint]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -113,10 +113,10 @@ impl Instance { } } - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 7] = wgpu::vertex_attr_array![3 => Uint, 4 => Float4, 5 => Float4, 6 => Float4,7 => Float4, 8 => Float4, 9 => Float]; - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 7] = wgpu::vertex_attr_array![3 => Uint, 4 => Float4, 5 => Float4, 6 => Float4,7 => Float4, 8 => Float4, 9 => Float]; + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::InputStepMode::Instance, attributes: &ATTRIBUTES, } @@ -237,56 +237,58 @@ impl SpritePipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Sprite pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc(), Instance::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc(), Instance::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index f9ff492229..8ad0376774 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -119,11 +119,11 @@ impl Vertex { self.pos_norm = (self.pos_norm & !(0xF << 27)) | ((bone_idx as u32 & 0xF) << 27); } - pub fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 2] = + pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 2] = wgpu::vertex_attr_array![0 => Uint,1 => Uint]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -236,48 +236,50 @@ impl TerrainPipeline { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Terrain pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor::REPLACE, - alpha_blend: wgpu::BlendDescriptor::REPLACE, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { + }, + depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, depth_compare: wgpu::CompareFunction::GreaterEqual, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, + stencil: wgpu::StencilState { + front: wgpu::StencilFaceState::IGNORE, + back: wgpu::StencilFaceState::IGNORE, read_mask: !0, write_mask: !0, }, + bias: wgpu::DepthBiasState { + constant: 0, + slope_scale: 0.0, + clamp: 0.0, + }, + clamp_depth: false, }), - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], + multisample: wgpu::MultisampleState { + count: samples, + mask: !0, + alpha_to_coverage_enabled: false, }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState::REPLACE, + alpha_blend: wgpu::BlendState::REPLACE, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/pipelines/ui.rs b/voxygen/src/render/pipelines/ui.rs index 74727780bd..d0ed277ffc 100644 --- a/voxygen/src/render/pipelines/ui.rs +++ b/voxygen/src/render/pipelines/ui.rs @@ -16,11 +16,11 @@ pub struct Vertex { } impl Vertex { - fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 5] = + fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + const ATTRIBUTES: [wgpu::VertexAttribute; 5] = wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Float4, 3 => Float2, 4 => Uint]; - wgpu::VertexBufferDescriptor { - stride: Self::STRIDE, + wgpu::VertexBufferLayout { + array_stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } @@ -192,7 +192,6 @@ impl UiPipeline { sc_desc: &wgpu::SwapChainDescriptor, global_layout: &GlobalsLayouts, layout: &UiLayout, - aa_mode: AaMode, ) -> Self { let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { @@ -201,57 +200,45 @@ impl UiPipeline { bind_group_layouts: &[&global_layout.globals, &layout.locals, &layout.texture], }); - let samples = match aa_mode { - AaMode::None | AaMode::Fxaa => 1, - // TODO: Ensure sampling in the shader is exactly between the 4 texels - AaMode::MsaaX4 => 4, - AaMode::MsaaX8 => 8, - AaMode::MsaaX16 => 16, - }; - let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("UI pipeline"), layout: Some(&render_pipeline_layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: vs_module, entry_point: "main", + buffers: &[Vertex::desc()], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + strip_index_format: None, front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, polygon_mode: wgpu::PolygonMode::Fill, - clamp_depth: false, - depth_bias: 0, - depth_bias_slope_scale: 0.0, - depth_bias_clamp: 0.0, - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: None, - vertex_buffers: &[Vertex::desc()], }, - sample_count: samples, - sample_mask: !0, - alpha_to_coverage_enabled: false, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, + fragment: Some(wgpu::FragmentState { + module: fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), }); Self { diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 7aa4672650..9cc3fc2212 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -2237,7 +2237,6 @@ fn create_pipelines( sc_desc, &layouts.global, &layouts.ui, - mode.aa, ); // Construct a pipeline for rendering terrain @@ -2270,7 +2269,6 @@ fn create_pipelines( sc_desc, &layouts.global, &layouts.postprocess, - mode.aa, ); // Consider reenabling at some time in the future @@ -2362,6 +2360,6 @@ fn create_shader_module( Ok(device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some(source), source: wgpu::ShaderSource::SpirV(Cow::Borrowed(spv.as_binary())), - flags: wgpu::ShaderFlags::VALIDATION, + flags: wgpu::ShaderFlags::empty(), // TODO: renable wgpu::ShaderFlags::VALIDATION, })) } diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index 837a44146b..9ae24a42fe 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -12,6 +12,7 @@ use super::{ Renderer, ShadowMap, ShadowMapRenderer, }; use core::{num::NonZeroU32, ops::Range}; +use std::sync::Arc; use vek::Aabr; pub struct Drawer<'a> { @@ -324,17 +325,13 @@ impl<'pass> FirstPassDrawer<'pass> { } } - pub fn draw_terrain<'data: 'pass>( - &mut self, - col_lights: &'data ColLights, - ) -> TerrainDrawer<'_, 'pass> { + pub fn draw_terrain<'data: 'pass>(&mut self) -> TerrainDrawer<'_, 'pass> { self.render_pass .set_pipeline(&self.renderer.terrain_pipeline.pipeline); - self.render_pass - .set_bind_group(3, &col_lights.bind_group, &[]); TerrainDrawer { render_pass: &mut self.render_pass, + col_lights: None, } } @@ -397,15 +394,31 @@ impl<'pass_ref, 'pass: 'pass_ref> FigureDrawer<'pass_ref, 'pass> { pub struct TerrainDrawer<'pass_ref, 'pass: 'pass_ref> { render_pass: &'pass_ref mut wgpu::RenderPass<'pass>, + col_lights: Option<&'pass_ref Arc>>, } impl<'pass_ref, 'pass: 'pass_ref> TerrainDrawer<'pass_ref, 'pass> { pub fn draw<'data: 'pass>( &mut self, model: &'data Model, + col_lights: &'data Arc>, locals: &'data terrain::BoundLocals, ) { - self.render_pass.set_bind_group(2, &locals.bind_group, &[]); + let col_lights = if let Some(col_lights) = self + .col_lights + // Check if we are still using the same atlas texture as the previous drawn + // chunk + .filter(|current_col_lights| Arc::ptr_eq(current_col_lights, col_lights)) + { + col_lights + } else { + self.render_pass + .set_bind_group(3, &col_lights.bind_group, &[]); // TODO: put this in slot 2 + self.col_lights = Some(col_lights); + col_lights + }; + + self.render_pass.set_bind_group(2, &locals.bind_group, &[]); // TODO: put this in slot 3 self.render_pass.set_vertex_buffer(0, model.buf().slice(..)); self.render_pass.draw(0..model.len() as u32, 0..1) } diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 509dc9363b..eec1fda1ef 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -72,7 +72,7 @@ pub struct TerrainChunkData { fluid_model: Option>, /// If this is `None`, this texture is not allocated in the current atlas, /// and therefore there is no need to free its allocation. - col_lights: Option, + col_lights_alloc: Option, /// The actual backing texture for this chunk. Use this for rendering /// purposes. The texture is reference-counted, so it will be /// automatically freed when no chunks are left that need it (though @@ -334,7 +334,7 @@ pub struct Terrain { /// we allocate. Code cannot assume that this is the assigned texture /// for any particular chunk; look at the `texture` field in /// `TerrainChunkData` for that. - col_lights: ColLights, + col_lights: Arc>, waves: FluidWaves, phantom: PhantomData, @@ -579,7 +579,7 @@ impl Terrain { renderer.fluid_bind_waves(waves_tex) }, - col_lights, + col_lights: Arc::new(col_lights), phantom: PhantomData, } } @@ -638,7 +638,7 @@ impl Terrain { fn remove_chunk_meta(&mut self, _pos: Vec2, chunk: &TerrainChunkData) { // No need to free the allocation if the chunk is not allocated in the current // atlas, since we don't bother tracking it at that point. - if let Some(col_lights) = chunk.col_lights { + if let Some(col_lights) = chunk.col_lights_alloc { self.atlas.deallocate(col_lights); } /* let (zmin, zmax) = chunk.z_bounds; @@ -1128,10 +1128,10 @@ impl Terrain { // TODO: Consider attempting defragmentation first rather than just // always moving everything into the new chunk. chunks.iter_mut().for_each(|(_, chunk)| { - chunk.col_lights = None; + chunk.col_lights_alloc = None; }); *atlas = new_atlas; - *col_lights = new_col_lights; + *col_lights = Arc::new(new_col_lights); atlas .allocate(guillotiere::Size::new( @@ -1149,7 +1149,7 @@ impl Terrain { allocation.rectangle.min.y as u32, ); renderer.update_texture( - &col_lights, + &col_lights.texture, atlas_offs.into_array(), tex_size.into_array(), &tex, @@ -1169,8 +1169,8 @@ impl Terrain { } else { None }, - col_lights: Some(allocation.id), - texture: self.col_lights.clone(), + col_lights_alloc: Some(allocation.id), + col_lights: Arc::clone(&self.col_lights), light_map: mesh.light_map, glow_map: mesh.glow_map, sprite_instances, @@ -1468,7 +1468,7 @@ impl Terrain { pub fn render<'a>(&'a self, drawer: &mut FirstPassDrawer<'a>, focus_pos: Vec3) { span!(_guard, "render", "Terrain::render"); - let mut drawer = drawer.draw_terrain(&self.col_lights); + let mut drawer = drawer.draw_terrain(); let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| { (e as i32).div_euclid(sz as i32) @@ -1481,7 +1481,7 @@ impl Terrain { }) .take(self.chunks.len()) .filter(|chunk| chunk.visible.is_visible()) - .for_each(|chunk| drawer.draw(&chunk.opaque_model, &chunk.locals)); + .for_each(|chunk| drawer.draw(&chunk.opaque_model, &chunk.col_lights, &chunk.locals)); } pub fn render_translucent<'a>( diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index f520fd852c..470897178e 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -1105,13 +1105,12 @@ impl Window { pub fn center_cursor(&self) { let dimensions: Vec2 = self.logical_size(); - if let Err(err) = - self.window - .window() - .set_cursor_position(winit::dpi::PhysicalPosition::new( - dimensions[0] / (2_f64), - dimensions[1] / (2_f64), - )) + if let Err(err) = self + .window + .set_cursor_position(winit::dpi::PhysicalPosition::new( + dimensions[0] / (2_f64), + dimensions[1] / (2_f64), + )) { error!("Error centering cursor position: {:?}", err); }