diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 1a8e6df8d5..7d4a365e33 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -51,7 +51,9 @@ pub use self::{ }; pub use wgpu::{AddressMode, FilterMode}; -pub trait Vertex = Clone + bytemuck::Pod; +pub trait Vertex: Clone + bytemuck::Pod { + const STRIDE: wgpu::BufferAddress; +} use serde::{Deserialize, Serialize}; /// Anti-aliasing modes diff --git a/voxygen/src/render/model.rs b/voxygen/src/render/model.rs index 8f800f6df6..3fe7be1010 100644 --- a/voxygen/src/render/model.rs +++ b/voxygen/src/render/model.rs @@ -14,7 +14,9 @@ pub struct SubModel<'a, V: Vertex> { impl<'a, V: Vertex> SubModel<'a, V> { pub(super) fn buf(&self) -> wgpu::BufferSlice<'a> { - self.buf.slice(map_range(&self.vertex_range)) + let start = self.vertex_range.start as wgpu::BufferAddress * V::STRIDE; + let end = self.vertex_range.end as wgpu::BufferAddress * V::STRIDE; + self.buf.slice(start..end) } pub fn len(&self) -> u32 { self.vertex_range.end - self.vertex_range.start } @@ -83,5 +85,3 @@ impl DynamicModel { pub fn len(&self) -> usize { self.vbuf.len() } } - -fn map_range(range: &Range) -> Range { (range.start as u64)..(range.end as u64) } diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index 42f08f29c7..1ef62d6fa0 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -1,5 +1,5 @@ use super::{ - super::{AaMode, Bound, Consts, Mesh, Tri}, + super::{AaMode, Consts}, GlobalsLayouts, }; use bytemuck::{Pod, Zeroable}; @@ -186,7 +186,7 @@ impl CloudsPipeline { depth_stencil_state: None, vertex_state: wgpu::VertexStateDescriptor { index_format: None, - vertex_buffers: &[/*Vertex::desc()*/], + vertex_buffers: &[], }, sample_count: samples, sample_mask: !0, diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index 0444737eaa..c90214acd6 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -1,5 +1,6 @@ -use super::super::{AaMode, GlobalsLayouts, TerrainLayout, Texture}; +use super::super::{AaMode, GlobalsLayouts, TerrainLayout, Texture, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; +use std::mem; use vek::*; #[repr(C)] @@ -32,17 +33,20 @@ impl Vertex { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 1] = wgpu::vertex_attr_array![0 => Uint]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + pub struct BindGroup { pub(in super::super) bind_group: wgpu::BindGroup, waves: Texture, diff --git a/voxygen/src/render/pipelines/lod_terrain.rs b/voxygen/src/render/pipelines/lod_terrain.rs index 3f7361d79a..7953f472b8 100644 --- a/voxygen/src/render/pipelines/lod_terrain.rs +++ b/voxygen/src/render/pipelines/lod_terrain.rs @@ -1,5 +1,6 @@ -use super::super::{AaMode, GlobalsLayouts, Renderer, Texture}; +use super::super::{AaMode, GlobalsLayouts, Renderer, Texture, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; +use std::mem; use vek::*; #[repr(C)] @@ -16,17 +17,20 @@ impl Vertex { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 1] = wgpu::vertex_attr_array![0 => Float2]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + pub struct LodData { pub map: Texture, pub alt: Texture, diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index b0d20464ce..55ab3bedea 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -1,5 +1,6 @@ -use super::super::{AaMode, GlobalsLayouts}; +use super::super::{AaMode, GlobalsLayouts, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; +use std::mem; use vek::*; #[repr(C)] @@ -32,17 +33,20 @@ impl Vertex { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 2] = wgpu::vertex_attr_array![0 => Float3, 1 => Uint]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + #[derive(Copy, Clone)] pub enum ParticleMode { CampfireSmoke = 0, @@ -148,7 +152,6 @@ impl Instance { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; 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, diff --git a/voxygen/src/render/pipelines/postprocess.rs b/voxygen/src/render/pipelines/postprocess.rs index d68137fe78..c367eb168e 100644 --- a/voxygen/src/render/pipelines/postprocess.rs +++ b/voxygen/src/render/pipelines/postprocess.rs @@ -1,4 +1,4 @@ -use super::super::{AaMode, Bound, Consts, GlobalsLayouts, Mesh, Tri}; +use super::super::{AaMode, Consts, GlobalsLayouts}; use bytemuck::{Pod, Zeroable}; use vek::*; @@ -154,7 +154,7 @@ impl PostProcessPipeline { depth_stencil_state: None, vertex_state: wgpu::VertexStateDescriptor { index_format: None, - vertex_buffers: &[/*Vertex::desc()*/], + vertex_buffers: &[], }, sample_count: samples, sample_mask: !0, diff --git a/voxygen/src/render/pipelines/skybox.rs b/voxygen/src/render/pipelines/skybox.rs index ed0edd4258..0d4415e71b 100644 --- a/voxygen/src/render/pipelines/skybox.rs +++ b/voxygen/src/render/pipelines/skybox.rs @@ -1,5 +1,6 @@ -use super::super::{AaMode, GlobalsLayouts, Mesh, Quad}; +use super::super::{AaMode, GlobalsLayouts, Mesh, Quad, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; +use std::mem; #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] @@ -9,9 +10,8 @@ pub struct Vertex { impl Vertex { fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &[wgpu::VertexAttributeDescriptor { offset: 0, @@ -22,6 +22,10 @@ impl Vertex { } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + pub struct SkyboxPipeline { pub pipeline: wgpu::RenderPipeline, } diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 0e516e873c..811c13d1b5 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -1,6 +1,7 @@ -use super::super::{AaMode, Bound, Consts, GlobalsLayouts, TerrainLayout}; +use super::super::{AaMode, Bound, Consts, GlobalsLayouts, TerrainLayout, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; use core::fmt; +use std::mem; use vek::*; #[repr(C)] @@ -60,17 +61,20 @@ impl Vertex { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 3] = wgpu::vertex_attr_array![0 => Float3, 1 => Uint, 2 => Uint]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] pub struct Instance { @@ -110,7 +114,6 @@ impl Instance { } fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; 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, diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index a293a84486..6061e03db3 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -1,5 +1,6 @@ -use super::super::{AaMode, Bound, Consts, GlobalsLayouts}; +use super::super::{AaMode, Bound, Consts, GlobalsLayouts, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; +use std::mem; use vek::*; #[repr(C)] @@ -119,17 +120,20 @@ impl Vertex { } pub fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 2] = wgpu::vertex_attr_array![0 => Uint,1 => Uint]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] // TODO: new function and private fields?? diff --git a/voxygen/src/render/pipelines/ui.rs b/voxygen/src/render/pipelines/ui.rs index 9a3dbdc4ee..74727780bd 100644 --- a/voxygen/src/render/pipelines/ui.rs +++ b/voxygen/src/render/pipelines/ui.rs @@ -1,5 +1,8 @@ -use super::super::{AaMode, Bound, Consts, GlobalsLayouts, Quad, Texture, Tri}; +use super::super::{ + AaMode, Bound, Consts, GlobalsLayouts, Quad, Texture, Tri, Vertex as VertexTrait, +}; use bytemuck::{Pod, Zeroable}; +use std::mem; use vek::*; #[repr(C)] @@ -14,17 +17,20 @@ pub struct Vertex { impl Vertex { fn desc<'a>() -> wgpu::VertexBufferDescriptor<'a> { - use std::mem; const ATTRIBUTES: [wgpu::VertexAttributeDescriptor; 5] = wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Float4, 3 => Float2, 4 => Uint]; wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as wgpu::BufferAddress, + stride: Self::STRIDE, step_mode: wgpu::InputStepMode::Vertex, attributes: &ATTRIBUTES, } } } +impl VertexTrait for Vertex { + const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; +} + #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] pub struct Locals { diff --git a/voxygen/src/render/renderer/binding.rs b/voxygen/src/render/renderer/binding.rs index aea000fa07..2ae1ffa8c0 100644 --- a/voxygen/src/render/renderer/binding.rs +++ b/voxygen/src/render/renderer/binding.rs @@ -1,6 +1,5 @@ use super::{ super::{ - consts::Consts, pipelines::{ figure, fluid, lod_terrain, sprite, terrain, ui, ColLights, GlobalModel, GlobalsBindGroup,