From 165c88bd74cc81603c65166b9ab7dbcb21610a6d Mon Sep 17 00:00:00 2001 From: Isse Date: Sun, 7 Jan 2024 17:51:44 +0100 Subject: [PATCH] patch wgpu to 18.2 --- Cargo.lock | 93 ++++++---- Cargo.toml | 1 + voxygen/Cargo.toml | 9 +- voxygen/src/menu/server_info/mod.rs | 3 +- voxygen/src/render/error.rs | 15 +- voxygen/src/render/renderer.rs | 2 +- .../src/render/renderer/pipeline_creation.rs | 161 ++++++++++-------- voxygen/src/render/texture.rs | 2 +- 8 files changed, 173 insertions(+), 113 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64623d09aa..35a2472712 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3149,9 +3149,9 @@ checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -3635,9 +3635,8 @@ dependencies = [ [[package]] name = "naga" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61d829abac9f5230a85d8cc83ec0879b4c09790208ae25b5ea031ef84562e071" +version = "0.14.2" +source = "git+https://github.com/gfx-rs/wgpu?rev=daedf03f0617aab6b3ab7380132dc9cb07f62d32#daedf03f0617aab6b3ab7380132dc9cb07f62d32" dependencies = [ "bit-set", "bitflags 2.4.0", @@ -3646,6 +3645,7 @@ dependencies = [ "indexmap 2.0.0", "log", "num-traits", + "petgraph 0.6.4", "pp-rs", "rustc-hash", "serde", @@ -5218,6 +5218,15 @@ version = "0.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "082f11ffa03bbef6c2c6ea6bea1acafaade2fd9050ae0234ab44a2153742b058" +[[package]] +name = "roxmltree" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921904a62e410e37e215c40381b7117f830d9d89ba60ab5236170541dd25646b" +dependencies = [ + "xmlparser", +] + [[package]] name = "rstar" version = "0.10.0" @@ -5667,6 +5676,25 @@ dependencies = [ "digest", ] +[[package]] +name = "shaderc" +version = "0.8.0" +source = "git+https://github.com/pythonesque/shaderc-rs?rev=f2605a02062834019bedff911aee2fd2998c49f9#f2605a02062834019bedff911aee2fd2998c49f9" +dependencies = [ + "libc", + "shaderc-sys", +] + +[[package]] +name = "shaderc-sys" +version = "0.8.0" +source = "git+https://github.com/pythonesque/shaderc-rs?rev=f2605a02062834019bedff911aee2fd2998c49f9#f2605a02062834019bedff911aee2fd2998c49f9" +dependencies = [ + "cmake", + "libc", + "roxmltree", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -7268,6 +7296,7 @@ dependencies = [ "rodio", "ron", "serde", + "shaderc", "slab", "specs", "strum", @@ -7490,9 +7519,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -7500,9 +7529,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -7550,9 +7579,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote 1.0.33", "wasm-bindgen-macro-support", @@ -7560,9 +7589,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2 1.0.66", "quote 1.0.33", @@ -7573,9 +7602,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-encoder" @@ -7848,9 +7877,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", @@ -7869,8 +7898,7 @@ dependencies = [ [[package]] name = "wgpu" version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e7d227c9f961f2061c26f4cb0fbd4df0ef37e056edd0931783599d6c94ef24" +source = "git+https://github.com/gfx-rs/wgpu?rev=daedf03f0617aab6b3ab7380132dc9cb07f62d32#daedf03f0617aab6b3ab7380132dc9cb07f62d32" dependencies = [ "arrayvec", "cfg-if 1.0.0", @@ -7878,7 +7906,7 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle 0.5.2", "serde", @@ -7894,9 +7922,8 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "837e02ddcdc6d4a9b56ba4598f7fd4202a7699ab03f6ef4dcdebfad2c966aea6" +version = "0.18.1" +source = "git+https://github.com/gfx-rs/wgpu?rev=daedf03f0617aab6b3ab7380132dc9cb07f62d32#daedf03f0617aab6b3ab7380132dc9cb07f62d32" dependencies = [ "arrayvec", "bit-vec", @@ -7904,7 +7931,7 @@ dependencies = [ "codespan-reporting", "log", "naga", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle 0.5.2", "ron", @@ -7919,9 +7946,8 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e30b9a8155c83868e82a8c5d3ce899de6c3961d2ef595de8fc168a1677fc2d8" +version = "0.18.1" +source = "git+https://github.com/gfx-rs/wgpu?rev=daedf03f0617aab6b3ab7380132dc9cb07f62d32#daedf03f0617aab6b3ab7380132dc9cb07f62d32" dependencies = [ "android_system_properties", "arrayvec", @@ -7940,13 +7966,13 @@ dependencies = [ "js-sys", "khronos-egl", "libc", - "libloading 0.8.0", + "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", @@ -7973,8 +7999,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d5ed5f0edf0de351fe311c53304986315ce866f394a2e6df0c4b3c70774bcdd" +source = "git+https://github.com/gfx-rs/wgpu?rev=daedf03f0617aab6b3ab7380132dc9cb07f62d32#daedf03f0617aab6b3ab7380132dc9cb07f62d32" dependencies = [ "bitflags 2.4.0", "js-sys", @@ -8455,6 +8480,12 @@ version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47430998a7b5d499ccee752b41567bc3afc57e1327dc855b1a2aa44ce29b5fa1" +[[package]] +name = "xmlparser" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" + [[package]] name = "yasna" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 717cea797c..2e67774794 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -162,6 +162,7 @@ vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986 # ntapi 3.7 fails to compile under windows due to the bug https://github.com/MSxDOS/ntapi/pull/12 ntapi = { git = "https://github.com/MSxDOS/ntapi.git", rev = "9f56b149c9e25796739157c0fce3e0007a7de6eb" } shred = { git = "https://github.com/amethyst/shred.git", rev = "5d52c6fc390dd04c12158633e77591f6523d1f85" } +wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "daedf03f0617aab6b3ab7380132dc9cb07f62d32" } # [patch."https://github.com/gfx-rs/gfx"] # gfx-hal = { git = "https://github.com/Imberflur/gfx.git", tag = "veloren-fixes-v1" } diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 0d468e8ccc..d3a6eac248 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -29,13 +29,14 @@ tracy = ["common-frontend/tracy", "client/tracy"] tracy-memory = ["tracy"] # enables heap profiling with tracy plugins = ["client/plugins", "common-assets/plugins"] egui-ui = ["voxygen-egui", "egui", "egui_wgpu_backend", "egui_winit_platform"] +shaderc-from-source = ["shaderc/build-from-source"] discord = ["discord-sdk"] bin_img-export = ["common-assets"] # We don't ship egui with published release builds so a separate feature is required that excludes it. default-publish = ["singleplayer", "native-dialog", "plugins", "discord", "simd"] # Temp for bug on current wgpu version that has access violation in vulkan when constructing egui pipeline -default-no-egui = ["default-publish", "hot-reloading"] +default-no-egui = ["default-publish", "hot-reloading", "shaderc-from-source"] default = ["default-no-egui", "egui-ui"] [dependencies] @@ -56,9 +57,13 @@ voxygen-egui = {package = "veloren-voxygen-egui", path = "egui", optional = true # Graphics winit = {version = "0.28.6", features = ["serde"]} -wgpu = { version = "=0.18.0", features = ["trace", "glsl"] } +# naga has an issue for spirv in wgpu 18.0 +wgpu = { version = "=0.18.0", default-features = false, features = ["trace", "spirv", "glsl"] } wgpu-profiler = "0.15.0" bytemuck = { version="1.7", features=["derive"] } +# shaderc = "0.8.0" +# Working around a current bug in shaderc that causes it to use the system installation even if we specify compile from source +shaderc = { git = "https://github.com/pythonesque/shaderc-rs", rev = "f2605a02062834019bedff911aee2fd2998c49f9" } # cmake crate used by shaderc, newer version 0.1.46 uses a new cmake command that is not available in our CI cmake version # see https://github.com/alexcrichton/cmake-rs/issues/131 cmake = "=0.1.45" diff --git a/voxygen/src/menu/server_info/mod.rs b/voxygen/src/menu/server_info/mod.rs index 9ff08f298d..b37afe2bdd 100644 --- a/voxygen/src/menu/server_info/mod.rs +++ b/voxygen/src/menu/server_info/mod.rs @@ -233,7 +233,8 @@ impl PlayState for ServerInfoState { fn render(&self, drawer: &mut Drawer<'_>, _: &Settings) { // Draw the UI to the screen. - let mut third_pass = drawer.third_pass(); + let mut third_pass = drawer.prepare_third_pass(); + let mut third_pass = third_pass.drawer(); if let Some(mut ui_drawer) = third_pass.draw_ui() { self.ui.render(&mut ui_drawer); }; diff --git a/voxygen/src/render/error.rs b/voxygen/src/render/error.rs index 01cd27fea3..b55cf16d4c 100644 --- a/voxygen/src/render/error.rs +++ b/voxygen/src/render/error.rs @@ -7,7 +7,7 @@ pub enum RenderError { CustomError(String), CouldNotFindAdapter, ErrorInitializingCompiler, - // ShaderError(String, shaderc::Error), + ShaderError(String, shaderc::Error), ProfilerCreationError(wgpu_profiler::CreationError), } @@ -27,10 +27,10 @@ impl fmt::Debug for RenderError { Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(), Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(), Self::ErrorInitializingCompiler => f.debug_tuple("ErrorInitializingCompiler").finish(), - // Self::ShaderError(shader_name, err) => write!( - // f, - // "\"{shader_name}\" shader failed to compile due to the following error: {err}", - // ), + Self::ShaderError(shader_name, err) => write!( + f, + "\"{shader_name}\" shader failed to compile due to the following error: {err}", + ), RenderError::ProfilerCreationError(err) => write!(f, "Profiler creation error: {err}"), } } @@ -47,3 +47,8 @@ impl From for RenderError { impl From for RenderError { fn from(err: wgpu::SurfaceError) -> Self { Self::SurfaceError(err) } } +impl From<(&str, shaderc::Error)> for RenderError { + fn from((shader_name, err): (&str, shaderc::Error)) -> Self { + Self::ShaderError(shader_name.into(), err) + } +} diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 1c538f7289..ff15ff398a 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -550,7 +550,7 @@ impl Renderer { .map_err(RenderError::ProfilerCreationError)?; #[cfg(feature = "egui-ui")] - let egui_renderpass = egui_wgpu_backend::RenderPass::new(&*device, format, 1); + let egui_renderpass = egui_wgpu_backend::RenderPass::new(&device, format, 1); Ok(Self { device, diff --git a/voxygen/src/render/renderer/pipeline_creation.rs b/voxygen/src/render/renderer/pipeline_creation.rs index c991255356..680cc272a2 100644 --- a/voxygen/src/render/renderer/pipeline_creation.rs +++ b/voxygen/src/render/renderer/pipeline_creation.rs @@ -164,6 +164,7 @@ impl ShaderModules { has_shadow_views: bool, ) -> Result { prof_span!(_guard, "ShaderModules::new"); + use shaderc::{CompileOptions, Compiler, OptimizationLevel, ResolvedInclude, ShaderKind}; let constants = shaders.get("include.constants").unwrap(); let globals = shaders.get("include.globals").unwrap(); @@ -279,32 +280,45 @@ impl ShaderModules { }) .unwrap(); - let defines = wgpu::naga::FastHashMap::from_iter([ - ("constants.glsl".to_string(), constants.clone()), - ("globals.glsl".to_string(), globals.0.to_owned()), - ("shadows.glsl".to_string(), shadows.0.to_owned()), - ( - "rain_occlusion.glsl".to_string(), - rain_occlusion.0.to_owned(), - ), - ("sky.glsl".to_string(), sky.0.to_owned()), - ("light.glsl".to_string(), light.0.to_owned()), - ("srgb.glsl".to_string(), srgb.0.to_owned()), - ("random.glsl".to_string(), random.0.to_owned()), - ("lod.glsl".to_string(), lod.0.to_owned()), - ("anti-aliasing.glsl".to_string(), anti_alias.0.to_owned()), - ("cloud.glsl".to_string(), cloud.0.to_owned()), - ("point_glow.glsl".to_string(), point_glow.0.to_owned()), - ("fxaa.glsl".to_string(), fxaa.0.to_owned()), - ]); + let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?; + let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?; + options.set_optimization_level(OptimizationLevel::Zero); + options.set_forced_version_profile(430, shaderc::GlslProfile::Core); + // options.set_generate_debug_info(); + options.set_include_callback(move |name, _, shader_name, _| { + Ok(ResolvedInclude { + resolved_name: name.to_string(), + content: match name { + "constants.glsl" => constants.clone(), + "globals.glsl" => globals.0.to_owned(), + "shadows.glsl" => shadows.0.to_owned(), + "rain_occlusion.glsl" => rain_occlusion.0.to_owned(), + "sky.glsl" => sky.0.to_owned(), + "light.glsl" => light.0.to_owned(), + "srgb.glsl" => srgb.0.to_owned(), + "random.glsl" => random.0.to_owned(), + "lod.glsl" => lod.0.to_owned(), + "anti-aliasing.glsl" => anti_alias.0.to_owned(), + "cloud.glsl" => cloud.0.to_owned(), + "point_glow.glsl" => point_glow.0.to_owned(), + "fxaa.glsl" => fxaa.0.to_owned(), + other => { + return Err(format!( + "Include {} in {} is not defined", + other, shader_name + )); + }, + }, + }) + }); - let create_shader = |name, stage| { + let mut create_shader = |name, kind| { let glsl = &shaders .get(name) .unwrap_or_else(|| panic!("Can't retrieve shader: {}", name)) .0; let file_name = format!("{}.glsl", name); - create_shader_module(device, defines.clone(), glsl, stage, &file_name) + create_shader_module(device, &mut compiler, glsl, kind, &file_name, &options) }; let selected_fluid_shader = ["fluid-frag.", match pipeline_modes.fluid { @@ -313,69 +327,68 @@ impl ShaderModules { }] .concat(); - use wgpu::naga::ShaderStage; Ok(Self { - skybox_vert: create_shader("skybox-vert", ShaderStage::Vertex)?, - skybox_frag: create_shader("skybox-frag", ShaderStage::Fragment)?, - debug_vert: create_shader("debug-vert", ShaderStage::Vertex)?, - debug_frag: create_shader("debug-frag", ShaderStage::Fragment)?, - figure_vert: create_shader("figure-vert", ShaderStage::Vertex)?, - figure_frag: create_shader("figure-frag", ShaderStage::Fragment)?, - terrain_vert: create_shader("terrain-vert", ShaderStage::Vertex)?, - terrain_frag: create_shader("terrain-frag", ShaderStage::Fragment)?, - fluid_vert: create_shader("fluid-vert", ShaderStage::Vertex)?, - fluid_frag: create_shader(&selected_fluid_shader, ShaderStage::Fragment)?, - sprite_vert: create_shader("sprite-vert", ShaderStage::Vertex)?, - sprite_frag: create_shader("sprite-frag", ShaderStage::Fragment)?, - lod_object_vert: create_shader("lod-object-vert", ShaderStage::Vertex)?, - lod_object_frag: create_shader("lod-object-frag", ShaderStage::Fragment)?, - particle_vert: create_shader("particle-vert", ShaderStage::Vertex)?, - particle_frag: create_shader("particle-frag", ShaderStage::Fragment)?, - rope_vert: create_shader("rope-vert", ShaderStage::Vertex)?, - rope_frag: create_shader("rope-frag", ShaderStage::Fragment)?, - trail_vert: create_shader("trail-vert", ShaderStage::Vertex)?, - trail_frag: create_shader("trail-frag", ShaderStage::Fragment)?, - ui_vert: create_shader("ui-vert", ShaderStage::Vertex)?, - ui_frag: create_shader("ui-frag", ShaderStage::Fragment)?, - premultiply_alpha_vert: create_shader("premultiply-alpha-vert", ShaderStage::Vertex)?, - premultiply_alpha_frag: create_shader("premultiply-alpha-frag", ShaderStage::Fragment)?, - lod_terrain_vert: create_shader("lod-terrain-vert", ShaderStage::Vertex)?, - lod_terrain_frag: create_shader("lod-terrain-frag", ShaderStage::Fragment)?, - clouds_vert: create_shader("clouds-vert", ShaderStage::Vertex)?, - clouds_frag: create_shader("clouds-frag", ShaderStage::Fragment)?, + skybox_vert: create_shader("skybox-vert", ShaderKind::Vertex)?, + skybox_frag: create_shader("skybox-frag", ShaderKind::Fragment)?, + debug_vert: create_shader("debug-vert", ShaderKind::Vertex)?, + debug_frag: create_shader("debug-frag", ShaderKind::Fragment)?, + figure_vert: create_shader("figure-vert", ShaderKind::Vertex)?, + figure_frag: create_shader("figure-frag", ShaderKind::Fragment)?, + terrain_vert: create_shader("terrain-vert", ShaderKind::Vertex)?, + terrain_frag: create_shader("terrain-frag", ShaderKind::Fragment)?, + fluid_vert: create_shader("fluid-vert", ShaderKind::Vertex)?, + fluid_frag: create_shader(&selected_fluid_shader, ShaderKind::Fragment)?, + sprite_vert: create_shader("sprite-vert", ShaderKind::Vertex)?, + sprite_frag: create_shader("sprite-frag", ShaderKind::Fragment)?, + lod_object_vert: create_shader("lod-object-vert", ShaderKind::Vertex)?, + lod_object_frag: create_shader("lod-object-frag", ShaderKind::Fragment)?, + particle_vert: create_shader("particle-vert", ShaderKind::Vertex)?, + particle_frag: create_shader("particle-frag", ShaderKind::Fragment)?, + rope_vert: create_shader("rope-vert", ShaderKind::Vertex)?, + rope_frag: create_shader("rope-frag", ShaderKind::Fragment)?, + trail_vert: create_shader("trail-vert", ShaderKind::Vertex)?, + trail_frag: create_shader("trail-frag", ShaderKind::Fragment)?, + ui_vert: create_shader("ui-vert", ShaderKind::Vertex)?, + ui_frag: create_shader("ui-frag", ShaderKind::Fragment)?, + premultiply_alpha_vert: create_shader("premultiply-alpha-vert", ShaderKind::Vertex)?, + premultiply_alpha_frag: create_shader("premultiply-alpha-frag", ShaderKind::Fragment)?, + lod_terrain_vert: create_shader("lod-terrain-vert", ShaderKind::Vertex)?, + lod_terrain_frag: create_shader("lod-terrain-frag", ShaderKind::Fragment)?, + clouds_vert: create_shader("clouds-vert", ShaderKind::Vertex)?, + clouds_frag: create_shader("clouds-frag", ShaderKind::Fragment)?, dual_downsample_filtered_frag: create_shader( "dual-downsample-filtered-frag", - ShaderStage::Fragment, + ShaderKind::Fragment, )?, - dual_downsample_frag: create_shader("dual-downsample-frag", ShaderStage::Fragment)?, - dual_upsample_frag: create_shader("dual-upsample-frag", ShaderStage::Fragment)?, - postprocess_vert: create_shader("postprocess-vert", ShaderStage::Vertex)?, - postprocess_frag: create_shader("postprocess-frag", ShaderStage::Fragment)?, - blit_vert: create_shader("blit-vert", ShaderStage::Vertex)?, - blit_frag: create_shader("blit-frag", ShaderStage::Fragment)?, + dual_downsample_frag: create_shader("dual-downsample-frag", ShaderKind::Fragment)?, + dual_upsample_frag: create_shader("dual-upsample-frag", ShaderKind::Fragment)?, + postprocess_vert: create_shader("postprocess-vert", ShaderKind::Vertex)?, + postprocess_frag: create_shader("postprocess-frag", ShaderKind::Fragment)?, + blit_vert: create_shader("blit-vert", ShaderKind::Vertex)?, + blit_frag: create_shader("blit-frag", ShaderKind::Fragment)?, point_light_shadows_vert: create_shader( "point-light-shadows-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, light_shadows_directed_vert: create_shader( "light-shadows-directed-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, light_shadows_figure_vert: create_shader( "light-shadows-figure-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, light_shadows_debug_vert: create_shader( "light-shadows-debug-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, rain_occlusion_directed_vert: create_shader( "rain-occlusion-directed-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, rain_occlusion_figure_vert: create_shader( "rain-occlusion-figure-vert", - ShaderStage::Vertex, + ShaderKind::Vertex, )?, }) } @@ -383,14 +396,19 @@ impl ShaderModules { fn create_shader_module( device: &wgpu::Device, - defines: wgpu::naga::FastHashMap, + compiler: &mut shaderc::Compiler, source: &str, - stage: wgpu::naga::ShaderStage, + kind: shaderc::ShaderKind, file_name: &str, + options: &shaderc::CompileOptions, ) -> Result { prof_span!(_guard, "create_shader_modules"); use std::borrow::Cow; + let spv = compiler + .compile_into_spirv(source, kind, file_name, "main", Some(options)) + .map_err(|e| (file_name, e))?; + // Uncomment me to dump shaders to files // // std::fs::create_dir_all("dumpped-shaders").expect("Couldn't create shader @@ -405,14 +423,13 @@ fn create_shader_module( // .expect("Couldn't write shader out"); // let label = [file_name, "\n\n", source].concat(); - Ok(device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: Some(file_name), - source: wgpu::ShaderSource::Glsl { - shader: Cow::Borrowed(source), - stage, - defines, - }, - })) + #[allow(unsafe_code)] + Ok(unsafe { + device.create_shader_module_unchecked(wgpu::ShaderModuleDescriptor { + label: Some(file_name), + source: wgpu::ShaderSource::SpirV(Cow::Borrowed(spv.as_binary())), + }) + }) } /// Things needed to create a pipeline diff --git a/voxygen/src/render/texture.rs b/voxygen/src/render/texture.rs index 1a4a52e6a3..82f9a96e27 100644 --- a/voxygen/src/render/texture.rs +++ b/voxygen/src/render/texture.rs @@ -195,7 +195,7 @@ impl Texture { /// Update a texture with the given data (used for updating the glyph cache /// texture). pub fn update(&self, queue: &wgpu::Queue, offset: [u32; 2], size: [u32; 2], data: &[u8]) { - let bytes_per_pixel = self.format.block_size(None).unwrap() as u32; + let bytes_per_pixel = self.format.block_size(None).unwrap(); debug_assert_eq!( data.len(),