Merge branch 'imbris/shaderc-opt' into 'master'

Fix issue with missing capability when enabling shaderc optimizations

Closes #1936

See merge request veloren/veloren!4322
This commit is contained in:
Imbris 2024-02-15 17:25:12 +00:00
commit 8e62c17a81
8 changed files with 33 additions and 31 deletions

18
Cargo.lock generated
View File

@ -3863,7 +3863,7 @@ dependencies = [
[[package]]
name = "naga"
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 = [
"bit-set",
"bitflags 2.4.2",
@ -8110,7 +8110,7 @@ dependencies = [
[[package]]
name = "wgpu"
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 = [
"arrayvec",
"cfg-if 1.0.0",
@ -8118,7 +8118,7 @@ dependencies = [
"js-sys",
"log",
"naga",
"parking_lot 0.12.1",
"parking_lot 0.11.2",
"profiling",
"raw-window-handle 0.5.2",
"serde",
@ -8135,7 +8135,7 @@ dependencies = [
[[package]]
name = "wgpu-core"
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 = [
"arrayvec",
"bit-vec",
@ -8143,7 +8143,7 @@ dependencies = [
"codespan-reporting",
"log",
"naga",
"parking_lot 0.12.1",
"parking_lot 0.11.2",
"profiling",
"raw-window-handle 0.5.2",
"ron",
@ -8159,7 +8159,7 @@ dependencies = [
[[package]]
name = "wgpu-hal"
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 = [
"android_system_properties",
"arrayvec",
@ -8178,13 +8178,13 @@ dependencies = [
"js-sys",
"khronos-egl",
"libc",
"libloading 0.8.1",
"libloading 0.7.4",
"log",
"metal",
"naga",
"objc",
"once_cell",
"parking_lot 0.12.1",
"parking_lot 0.11.2",
"profiling",
"range-alloc",
"raw-window-handle 0.5.2",
@ -8211,7 +8211,7 @@ dependencies = [
[[package]]
name = "wgpu-types"
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 = [
"bitflags 2.4.2",
"js-sys",

View File

@ -157,13 +157,14 @@ async-trait = "0.1.42"
[patch.crates-io]
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
# with uint in uniforms for gl.
wgpu = { git = "https://github.com/IsseW/wgpu", rev = "5ea160164" }
# This is needed because of:
# * an issue with spirv & naga in wgpu 0.18 (I assume this is fixed upstream but not in 0.18)
# * 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" }
# # 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-core = { path = "../wgpu/wgpu-core" }
# 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;
// #ifdef FLUID_MODE_SHINY
layout(location = 1) flat in uint f_pos_norm;
layout(location = 2) flat in float f_load_time;
// #else
// const uint f_pos_norm = 0u;
// #endif

View File

@ -49,7 +49,6 @@ uniform u_locals {
layout(location = 0) out vec3 f_pos;
// #ifdef FLUID_MODE_SHINY
layout(location = 1) flat out uint f_pos_norm;
layout(location = 2) flat out float f_load_time;
// #if (SHADOW_MODE == SHADOW_MODE_MAP)
// 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_load_time = load_time;
vec3 v_pos = f_pos;
// Terrain 'pop-in' effect

View File

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

View File

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

View File

@ -563,4 +563,6 @@ pub enum ExperimentalShader {
Cinematic,
/// Glittering snow.
SnowGlitter,
/// Disables any optimizations done via shaderc.
DisableShadercOptimization,
}

View File

@ -6,14 +6,15 @@ use super::{
blit, bloom, clouds, debug, figure, fluid, lod_object, lod_terrain, particle,
postprocess, rope, shadow, skybox, sprite, terrain, trail, ui,
},
AaMode, BloomMode, CloudMode, FluidMode, LightingMode, PipelineModes, ReflectionMode,
RenderError, ShadowMode,
AaMode, BloomMode, CloudMode, ExperimentalShader, FluidMode, LightingMode, PipelineModes,
ReflectionMode, RenderError, ShadowMode,
},
shaders::Shaders,
ImmutableLayouts, Layouts,
};
use common_base::{prof_span, prof_span_alloc};
use std::sync::Arc;
use tracing::info;
/// All the pipelines
pub struct Pipelines {
@ -282,7 +283,16 @@ impl ShaderModules {
let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
options.set_optimization_level(OptimizationLevel::Zero);
let shaderc_opts = !pipeline_modes
.experimental_shaders
.contains(&ExperimentalShader::DisableShadercOptimization);
if shaderc_opts {
options.set_optimization_level(OptimizationLevel::Performance);
info!("Enabled optimization by shaderc.");
} else {
options.set_optimization_level(OptimizationLevel::Zero);
info!("Disabled optimization by shaderc.");
}
options.set_forced_version_profile(430, shaderc::GlslProfile::Core);
// options.set_generate_debug_info();
options.set_include_callback(move |name, _, shader_name, _| {