Fix issue with missing capability when enabling shaderc optimizations

See https://github.com/gfx-rs/wgpu/issues/4915

Also:
* Remove unused vert-out frag-in variables from shaders (naga doesn't
  like this probably because they are optimized out on the fragment
  side). This restriction from naga may be relaxed in the future
  see https://github.com/gfx-rs/wgpu/issues/3748.
* Enable OptimizationLevel::Performance for shaderc by default
* Add a environment variable VOXYGEN_SHADERC_OPTS for disabling this
  (e.g. to test if it actually makes a difference on any platform).
  (TODO: testing might be easier if there was a way to do toggle it
  without restarting...)
This commit is contained in:
Imbris 2024-02-08 23:48:50 -05:00
parent 68ba2b4e1e
commit 5434ce546b
7 changed files with 39 additions and 29 deletions

18
Cargo.lock generated
View File

@ -3863,7 +3863,7 @@ dependencies = [
[[package]] [[package]]
name = "naga" name = "naga"
version = "0.14.2" version = "0.14.2"
source = "git+https://github.com/IsseW/wgpu?rev=5ea160164#5ea16016402bb83b4ccd7ac8e6d4b0a2f85da6a0" source = "git+https://github.com/Imberflur/wgpu.git?tag=0.18-with-fixes-for-veloren-v1#df527ef82e2eba827eda9278caa583506a06aa87"
dependencies = [ dependencies = [
"bit-set", "bit-set",
"bitflags 2.4.2", "bitflags 2.4.2",
@ -8110,7 +8110,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/IsseW/wgpu?rev=5ea160164#5ea16016402bb83b4ccd7ac8e6d4b0a2f85da6a0" source = "git+https://github.com/Imberflur/wgpu.git?tag=0.18-with-fixes-for-veloren-v1#df527ef82e2eba827eda9278caa583506a06aa87"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@ -8118,7 +8118,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"naga", "naga",
"parking_lot 0.12.1", "parking_lot 0.11.2",
"profiling", "profiling",
"raw-window-handle 0.5.2", "raw-window-handle 0.5.2",
"serde", "serde",
@ -8135,7 +8135,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/IsseW/wgpu?rev=5ea160164#5ea16016402bb83b4ccd7ac8e6d4b0a2f85da6a0" source = "git+https://github.com/Imberflur/wgpu.git?tag=0.18-with-fixes-for-veloren-v1#df527ef82e2eba827eda9278caa583506a06aa87"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"bit-vec", "bit-vec",
@ -8143,7 +8143,7 @@ dependencies = [
"codespan-reporting", "codespan-reporting",
"log", "log",
"naga", "naga",
"parking_lot 0.12.1", "parking_lot 0.11.2",
"profiling", "profiling",
"raw-window-handle 0.5.2", "raw-window-handle 0.5.2",
"ron", "ron",
@ -8159,7 +8159,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-hal" name = "wgpu-hal"
version = "0.18.1" version = "0.18.1"
source = "git+https://github.com/IsseW/wgpu?rev=5ea160164#5ea16016402bb83b4ccd7ac8e6d4b0a2f85da6a0" source = "git+https://github.com/Imberflur/wgpu.git?tag=0.18-with-fixes-for-veloren-v1#df527ef82e2eba827eda9278caa583506a06aa87"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"arrayvec", "arrayvec",
@ -8178,13 +8178,13 @@ dependencies = [
"js-sys", "js-sys",
"khronos-egl", "khronos-egl",
"libc", "libc",
"libloading 0.8.1", "libloading 0.7.4",
"log", "log",
"metal", "metal",
"naga", "naga",
"objc", "objc",
"once_cell", "once_cell",
"parking_lot 0.12.1", "parking_lot 0.11.2",
"profiling", "profiling",
"range-alloc", "range-alloc",
"raw-window-handle 0.5.2", "raw-window-handle 0.5.2",
@ -8211,7 +8211,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/IsseW/wgpu?rev=5ea160164#5ea16016402bb83b4ccd7ac8e6d4b0a2f85da6a0" source = "git+https://github.com/Imberflur/wgpu.git?tag=0.18-with-fixes-for-veloren-v1#df527ef82e2eba827eda9278caa583506a06aa87"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"js-sys", "js-sys",

View File

@ -157,13 +157,14 @@ async-trait = "0.1.42"
[patch.crates-io] [patch.crates-io]
shred = { git = "https://github.com/amethyst/shred.git", rev = "5d52c6fc390dd04c12158633e77591f6523d1f85" } shred = { git = "https://github.com/amethyst/shred.git", rev = "5d52c6fc390dd04c12158633e77591f6523d1f85" }
# This is needed because of an issue with spirv & naga in wgpu 0.18, and there's an issue # This is needed because of:
# with uint in uniforms for gl. # * an issue with spirv & naga in wgpu 0.18 (I assume this is fixed upstream but not in 0.18)
wgpu = { git = "https://github.com/IsseW/wgpu", rev = "5ea160164" } # * an issue with uint in uniforms for gl. (potentially fixed in 0.19?)
# * an issue with releasing current context on Windows opengl (fixed in 0.19.1)
# * another spirv issue: unused builtins not always being removed. (upstream PR open)
wgpu = { git = "https://github.com/Imberflur/wgpu.git", tag = "0.18-with-fixes-for-veloren-v1" }
# wgpu = { path = "../wgpu/wgpu" }
# # use the latest fixes in naga (remove when updates trickle down to wgpu-rs)
# naga = { git = "https://github.com/gfx-rs/naga.git", rev = "3a0f0144112ff621dd7f731bf455adf6cab19164" }
# naga = { path = "../naga" }
# keyboard-keynames = { git = "https://gitlab.com/Capucho/keyboard-keynames.git", rev = "7b1375ee4ea01d0e0b80c419cb27f0498e67df3a" } # keyboard-keynames = { git = "https://gitlab.com/Capucho/keyboard-keynames.git", rev = "7b1375ee4ea01d0e0b80c419cb27f0498e67df3a" }
# # Uncomment this to use a local fork of winit (for testing purposes) # # Uncomment this to use a local fork of winit (for testing purposes)
@ -174,6 +175,5 @@ wgpu = { git = "https://github.com/IsseW/wgpu", rev = "5ea160164" }
# wgpu-hal = { path = "../wgpu/wgpu-hal" } # wgpu-hal = { path = "../wgpu/wgpu-hal" }
# wgpu-core = { path = "../wgpu/wgpu-core" } # wgpu-core = { path = "../wgpu/wgpu-core" }
# wgpu-types = { path = "../wgpu/wgpu-types" } # wgpu-types = { path = "../wgpu/wgpu-types" }
# naga = { path = "../wgpu/naga" }
[patch."https://github.com/gfx-rs/naga"]
# naga = { path = "../naga" }

View File

@ -27,7 +27,6 @@ layout(location = 0) in vec3 f_pos;
// in vec3 f_chunk_pos; // in vec3 f_chunk_pos;
// #ifdef FLUID_MODE_SHINY // #ifdef FLUID_MODE_SHINY
layout(location = 1) flat in uint f_pos_norm; layout(location = 1) flat in uint f_pos_norm;
layout(location = 2) flat in float f_load_time;
// #else // #else
// const uint f_pos_norm = 0u; // const uint f_pos_norm = 0u;
// #endif // #endif

View File

@ -49,7 +49,6 @@ uniform u_locals {
layout(location = 0) out vec3 f_pos; layout(location = 0) out vec3 f_pos;
// #ifdef FLUID_MODE_SHINY // #ifdef FLUID_MODE_SHINY
layout(location = 1) flat out uint f_pos_norm; layout(location = 1) flat out uint f_pos_norm;
layout(location = 2) flat out float f_load_time;
// #if (SHADOW_MODE == SHADOW_MODE_MAP) // #if (SHADOW_MODE == SHADOW_MODE_MAP)
// out vec4 sun_pos; // out vec4 sun_pos;
@ -77,8 +76,6 @@ void main() {
f_pos = (model_mat * vec4(f_chunk_pos, 1.0)).xyz - focus_off.xyz; f_pos = (model_mat * vec4(f_chunk_pos, 1.0)).xyz - focus_off.xyz;
f_load_time = load_time;
vec3 v_pos = f_pos; vec3 v_pos = f_pos;
// Terrain 'pop-in' effect // Terrain 'pop-in' effect

View File

@ -20,8 +20,6 @@
#include <globals.glsl> #include <globals.glsl>
layout(location = 0) in vec3 f_pos;
layout(location = 0) out vec4 tgt_color; layout(location = 0) out vec4 tgt_color;
#include <sky.glsl> #include <sky.glsl>

View File

@ -4,10 +4,6 @@
layout(location = 0) in vec3 v_pos; layout(location = 0) in vec3 v_pos;
layout(location = 0) out vec3 f_pos;
void main() { void main() {
f_pos = v_pos; gl_Position = all_mat * vec4(v_pos - focus_off.xyz, 1);
gl_Position = all_mat * vec4(f_pos - focus_off.xyz, 1);
} }

View File

@ -14,6 +14,7 @@ use super::{
}; };
use common_base::{prof_span, prof_span_alloc}; use common_base::{prof_span, prof_span_alloc};
use std::sync::Arc; use std::sync::Arc;
use tracing::info;
/// All the pipelines /// All the pipelines
pub struct Pipelines { pub struct Pipelines {
@ -282,7 +283,26 @@ impl ShaderModules {
let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?; let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?; let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
options.set_optimization_level(OptimizationLevel::Zero); use std::sync::OnceLock;
static OPTS: OnceLock<bool> = OnceLock::new();
let shaderc_opts = *OPTS.get_or_init(|| {
match std::env::var("VOXYGEN_SHADERC_OPTS").as_ref().map(|s| &**s) {
Ok("0" | "no") => {
info!("Disabled optimization by shaderc.");
false
},
Ok("1" | "yes") | Ok(_) | Err(_) => {
info!("Enabled optimization by shaderc.");
true
},
}
});
if shaderc_opts {
options.set_optimization_level(OptimizationLevel::Performance);
} else {
options.set_optimization_level(OptimizationLevel::Zero);
}
options.set_forced_version_profile(430, shaderc::GlslProfile::Core); options.set_forced_version_profile(430, shaderc::GlslProfile::Core);
// options.set_generate_debug_info(); // options.set_generate_debug_info();
options.set_include_callback(move |name, _, shader_name, _| { options.set_include_callback(move |name, _, shader_name, _| {