From 3312cb03b3163bde964671195cf55d71705f404d Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 5 Feb 2021 22:28:02 -0500 Subject: [PATCH] Update wgpu to fix segfault, fix sprite vertex lookup, normalize sprite normals in vert shader --- Cargo.lock | 6 +++--- assets/voxygen/shaders/sprite-frag.glsl | 1 + assets/voxygen/shaders/sprite-vert.glsl | 8 ++++---- voxygen/Cargo.toml | 2 +- voxygen/src/render/pipelines/sprite.rs | 4 ++-- voxygen/src/render/renderer/drawer.rs | 6 +++++- voxygen/src/scene/terrain.rs | 10 +++++----- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11632ec0a2..b660cf3bee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6583,7 +6583,7 @@ dependencies = [ [[package]] name = "wgpu" version = "0.7.0" -source = "git+https://github.com/gfx-rs/wgpu-rs.git?rev=f891e86e87f0733f04a8078f4be8ead2f24551cf#f891e86e87f0733f04a8078f4be8ead2f24551cf" +source = "git+https://github.com/gfx-rs/wgpu-rs.git?rev=1f1a7e5dd47a1610733bbc3989414acb62395359#1f1a7e5dd47a1610733bbc3989414acb62395359" dependencies = [ "arrayvec", "js-sys", @@ -6602,7 +6602,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.7.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=7c7501cab72fd01b14def06b9d9bc63a8dd44b45#7c7501cab72fd01b14def06b9d9bc63a8dd44b45" +source = "git+https://github.com/gfx-rs/wgpu?rev=3ebe198911b46cb77fcdc481f7d0daf9a962b82e#3ebe198911b46cb77fcdc481f7d0daf9a962b82e" dependencies = [ "arrayvec", "bitflags", @@ -6630,7 +6630,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.7.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=7c7501cab72fd01b14def06b9d9bc63a8dd44b45#7c7501cab72fd01b14def06b9d9bc63a8dd44b45" +source = "git+https://github.com/gfx-rs/wgpu?rev=3ebe198911b46cb77fcdc481f7d0daf9a962b82e#3ebe198911b46cb77fcdc481f7d0daf9a962b82e" dependencies = [ "bitflags", ] diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 5be535c6a2..3874f50582 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -94,4 +94,5 @@ void main() { surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light) * f_light; tgt_color = vec4(surf_color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (sprite_render_distance - FADE_DIST)) / FADE_DIST, 0, 1)); + //tgt_color = vec4(-f_norm, 1.0); } diff --git a/assets/voxygen/shaders/sprite-vert.glsl b/assets/voxygen/shaders/sprite-vert.glsl index a0a2551335..8a042bd1e5 100644 --- a/assets/voxygen/shaders/sprite-vert.glsl +++ b/assets/voxygen/shaders/sprite-vert.glsl @@ -52,7 +52,7 @@ const float SCALE_FACTOR = pow(SCALE, 1.3) * 0.2; const int EXTRA_NEG_Z = 32768; const int VERT_EXTRA_NEG_Z = 128; -const int VERT_PAGE_SIZE = 256; +const int VERT_PAGE_SIZE = 300; void main() { // Matrix to transform this sprite instance from model space to chunk space @@ -68,8 +68,8 @@ void main() { f_inst_light = vec2(inst_light, inst_glow); // Index of the vertex data in the 1D vertex texture - int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page); - const int WIDTH = 16384; // TODO: temp + int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE); + const int WIDTH = 8192; // TODO: temp ivec2 tex_coords = ivec2(vertex_index % WIDTH, vertex_index / WIDTH); uvec2 pos_atlas_pos_norm_ao = texelFetch(usampler2D(t_sprite_verts, s_sprite_verts), tex_coords, 0).xy; uint v_pos_norm = pos_atlas_pos_norm_ao.x; @@ -97,7 +97,7 @@ void main() { // Determine normal vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz); - f_norm = mix(-norm, norm, v_pos_norm >> 29u & 1u); + f_norm = normalize(mix(-norm, norm, v_pos_norm >> 29u & 1u)); // Expand atlas tex coords to floats // NOTE: Could defer to fragment shader if we are vert heavy diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index cf517efe77..20ecacd9c4 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -27,7 +27,7 @@ anim = {package = "veloren-voxygen-anim", path = "anim", default-features = fals # Graphics winit = {version = "0.24.0", features = ["serde"]} -wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "f891e86e87f0733f04a8078f4be8ead2f24551cf" } +wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "1f1a7e5dd47a1610733bbc3989414acb62395359" } bytemuck = { version="1.4", features=["derive"] } shaderc = "0.6.2" diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index c4b26a78eb..c882d73d70 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -10,7 +10,7 @@ use core::fmt; use std::mem; use vek::*; -pub const VERT_PAGE_SIZE: u32 = 256; +pub const VERT_PAGE_SIZE: u32 = 300; #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] @@ -92,7 +92,7 @@ pub fn create_verts_texture(renderer: &mut Renderer, mut mesh: Mesh) -> let format = wgpu::TextureFormat::Rg32Uint; // TODO: temp - const WIDTH: u32 = 16384; + const WIDTH: u32 = 8192; let height = verts.len() as u32 / WIDTH; // Fill in verts to full texture size verts.resize_with(height as usize * WIDTH as usize, Vertex::default); diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index 73eb141431..6af5f66905 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -525,7 +525,7 @@ impl<'pass_ref, 'pass: 'pass_ref> SpriteDrawer<'pass_ref, 'pass> { self.render_pass .set_vertex_buffer(0, instances.buf().slice(..)); self.render_pass - .draw(0..sprite::VERT_PAGE_SIZE - 4, 0..instances.count() as u32); + .draw(0..sprite::VERT_PAGE_SIZE, 0..instances.count() as u32); } } @@ -644,6 +644,10 @@ impl<'pass_ref, 'pass: 'pass_ref> PreparedUiDrawer<'pass_ref, 'pass> { pub fn set_scissor<'data: 'pass>(&mut self, scissor: Aabr) { let Aabr { min, max } = scissor; + // TODO: Got an invalid scissor panic from wgpu, + // use this if you can reproduce + // Note: might have been from changing monitors + // dbg!(&scissor) self.render_pass.set_scissor_rect( min.x as u32, min.y as u32, diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 40d8498ece..0b0c9f4808 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -10,6 +10,7 @@ use crate::{ ColLightInfo, Consts, Drawer, FirstPassDrawer, FluidVertex, FluidWaves, GlobalModel, Instances, LodData, Mesh, Model, RenderError, Renderer, SpriteGlobalsBindGroup, SpriteInstance, SpriteVertex, TerrainLocals, TerrainShadowDrawer, TerrainVertex, Texture, + SPRITE_VERT_PAGE_SIZE, }, }; @@ -41,7 +42,6 @@ use vek::*; const SPRITE_SCALE: Vec3 = Vec3::new(1.0 / 11.0, 1.0 / 11.0, 1.0 / 11.0); const SPRITE_LOD_LEVELS: usize = 5; -const SPRITE_VERT_PAGE_SIZE: usize = 256; #[derive(Clone, Copy, Debug)] struct Visibility { @@ -390,7 +390,7 @@ impl Terrain { }; // Get starting page count of opaque mesh let start_page_num = - opaque_mesh.vertices().len() / SPRITE_VERT_PAGE_SIZE; + opaque_mesh.vertices().len() / SPRITE_VERT_PAGE_SIZE as usize; // Mesh generation exclusively acts using side effects; it // has no interesting return value, but updates the mesh. generate_mesh_base_vol_sprite( @@ -405,11 +405,11 @@ impl Terrain { ); // Get the number of pages after the model was meshed let end_page_num = - (opaque_mesh.vertices().len() + SPRITE_VERT_PAGE_SIZE - 1) - / SPRITE_VERT_PAGE_SIZE; + (opaque_mesh.vertices().len() + SPRITE_VERT_PAGE_SIZE as usize - 1) + / SPRITE_VERT_PAGE_SIZE as usize; // Fill the current last page up with degenerate verts opaque_mesh.vertices_mut_vec().resize_with( - end_page_num * SPRITE_VERT_PAGE_SIZE, + end_page_num * SPRITE_VERT_PAGE_SIZE as usize, SpriteVertex::default, );