From 1684013138b4fd8d8570dafe496d1db268afb09d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 22 May 2019 19:30:18 +0100 Subject: [PATCH 1/2] Improved GPU memory usage by ~5x by compressing vertex data Former-commit-id: b657ae88e44c6ecbede8073ffe17991ba3a99886 --- voxygen/shaders/terrain.vert | 27 ++++++++++++++++++------- voxygen/src/render/pipelines/terrain.rs | 23 ++++++++++++--------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/voxygen/shaders/terrain.vert b/voxygen/shaders/terrain.vert index e7cf46b882..2a0fb39c90 100644 --- a/voxygen/shaders/terrain.vert +++ b/voxygen/shaders/terrain.vert @@ -2,9 +2,8 @@ #include -in vec3 v_pos; -in vec3 v_norm; -in vec3 v_col; +in uint v_pos; +in uint v_col_norm; layout (std140) uniform u_locals { @@ -16,12 +15,26 @@ out vec3 f_norm; out vec3 f_col; void main() { - f_pos = v_pos; - f_norm = v_norm; - f_col = v_col; + f_pos = vec3( + float((v_pos >> 0) & 0x00FFu), + float((v_pos >> 8) & 0x00FFu), + float((v_pos >> 16) & 0xFFFFu) + ); + + f_norm = vec3( + float((v_col_norm >> 0) & 0x3u), + float((v_col_norm >> 2) & 0x3u), + float((v_col_norm >> 4) & 0x3u) + ) - 1.0; + + f_col = vec3( + float((v_col_norm >> 8) & 0xFFu), + float((v_col_norm >> 16) & 0xFFu), + float((v_col_norm >> 24) & 0xFFu) + ) / 255.0; gl_Position = proj_mat * view_mat * - vec4(v_pos + model_offs, 1); + vec4(f_pos + model_offs, 1); } diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index e687afa18c..147963a43f 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -1,4 +1,4 @@ -// Library +use std::ops::{Add, Mul, Div}; use gfx::{ self, gfx_constant_struct_meta, @@ -10,8 +10,6 @@ use gfx::{ gfx_vertex_struct_meta, }; use vek::*; - -// Local use super::{ super::{Pipeline, TgtColorFmt, TgtDepthFmt}, Globals, @@ -19,9 +17,8 @@ use super::{ gfx_defines! { vertex Vertex { - pos: [f32; 3] = "v_pos", - norm: [f32; 3] = "v_norm", - col: [f32; 3] = "v_col", + pos: u32 = "v_pos", + col_norm: u32 = "v_col_norm", } constant Locals { @@ -42,9 +39,17 @@ gfx_defines! { impl Vertex { pub fn new(pos: Vec3, norm: Vec3, col: Rgb) -> Self { Self { - pos: pos.into_array(), - col: col.into_array(), - norm: norm.into_array(), + pos: 0 + | ((pos.x as u32) & 0x00FF) << 0 + | ((pos.y as u32) & 0x00FF) << 8 + | ((pos.z as u32) & 0xFFFF) << 16, + col_norm: 0 + | ((col.r.mul(255.0) as u32) & 0xFF) << 8 + | ((col.g.mul(255.0) as u32) & 0xFF) << 16 + | ((col.b.mul(255.0) as u32) & 0xFF) << 24 + | ((norm.x.add(1.0) as u32) & 0x3) << 0 + | ((norm.y.add(1.0) as u32) & 0x3) << 2 + | ((norm.z.add(1.0) as u32) & 0x3) << 4, } } } From 3963d4a3efdf6198f4179fb3c46aca39de4f1abd Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 22 May 2019 19:49:06 +0100 Subject: [PATCH 2/2] fmt Former-commit-id: b76defa253e555cd381ab6ccf66c8e7f3e816433 --- voxygen/src/render/pipelines/terrain.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index 147963a43f..06bec4cd98 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -1,4 +1,7 @@ -use std::ops::{Add, Mul, Div}; +use super::{ + super::{Pipeline, TgtColorFmt, TgtDepthFmt}, + Globals, +}; use gfx::{ self, gfx_constant_struct_meta, @@ -9,11 +12,8 @@ use gfx::{ gfx_pipeline_inner, gfx_vertex_struct_meta, }; +use std::ops::{Add, Div, Mul}; use vek::*; -use super::{ - super::{Pipeline, TgtColorFmt, TgtDepthFmt}, - Globals, -}; gfx_defines! { vertex Vertex {