mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Replace shaderc with naga
This commit is contained in:
parent
a2e0426d45
commit
446d93dda0
81
Cargo.lock
generated
81
Cargo.lock
generated
@ -2023,7 +2023,7 @@ dependencies = [
|
|||||||
"khronos-egl",
|
"khronos-egl",
|
||||||
"libloading 0.7.0",
|
"libloading 0.7.0",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"parking_lot 0.11.1",
|
"parking_lot 0.11.1",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"spirv_cross",
|
"spirv_cross",
|
||||||
@ -2047,7 +2047,7 @@ dependencies = [
|
|||||||
"gfx-hal",
|
"gfx-hal",
|
||||||
"log",
|
"log",
|
||||||
"metal",
|
"metal",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"objc",
|
"objc",
|
||||||
"parking_lot 0.11.1",
|
"parking_lot 0.11.1",
|
||||||
"profiling",
|
"profiling",
|
||||||
@ -2070,7 +2070,7 @@ dependencies = [
|
|||||||
"inplace_it",
|
"inplace_it",
|
||||||
"libloading 0.7.0",
|
"libloading 0.7.0",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"objc",
|
"objc",
|
||||||
"parking_lot 0.11.1",
|
"parking_lot 0.11.1",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
@ -2085,7 +2085,7 @@ version = "0.8.0"
|
|||||||
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
|
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
@ -2175,6 +2175,16 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glsl-include"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "daa2afb1631e7ab4543e0dde0e3fc68bb49c58fee89c07f30a26553b1f684ab6"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glyph_brush"
|
name = "glyph_brush"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
@ -3191,6 +3201,22 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "naga"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "git+https://github.com/gfx-rs/naga.git?rev=2069ea698f4ff570c7d065b899f16a88725aca85#2069ea698f4ff570c7d065b899f16a88725aca85"
|
||||||
|
dependencies = [
|
||||||
|
"bit-set",
|
||||||
|
"bitflags",
|
||||||
|
"codespan-reporting",
|
||||||
|
"fxhash",
|
||||||
|
"log",
|
||||||
|
"num-traits",
|
||||||
|
"pp-rs",
|
||||||
|
"spirv",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-dialog"
|
name = "native-dialog"
|
||||||
version = "0.5.5"
|
version = "0.5.5"
|
||||||
@ -3912,6 +3938,15 @@ dependencies = [
|
|||||||
"rand 0.8.4",
|
"rand 0.8.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pp-rs"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-xid 0.2.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.10"
|
version = "0.2.10"
|
||||||
@ -4837,26 +4872,6 @@ version = "0.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
|
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shaderc"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "50b8aeaae10b9bda5cba66736a7e265f67698e912e1cc6a4678acba286e22be9"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"shaderc-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shaderc-sys"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5b12d7c62d6732884c9dfab587503fa3a795b108df152415a89da23812d4737e"
|
|
||||||
dependencies = [
|
|
||||||
"cmake",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -5112,6 +5127,16 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spirv"
|
||||||
|
version = "0.2.0+1.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spirv_cross"
|
name = "spirv_cross"
|
||||||
version = "0.23.1"
|
version = "0.23.1"
|
||||||
@ -6146,6 +6171,7 @@ dependencies = [
|
|||||||
"bytemuck",
|
"bytemuck",
|
||||||
"chrono",
|
"chrono",
|
||||||
"chumsky",
|
"chumsky",
|
||||||
|
"codespan-reporting",
|
||||||
"conrod_core",
|
"conrod_core",
|
||||||
"conrod_winit",
|
"conrod_winit",
|
||||||
"copy_dir",
|
"copy_dir",
|
||||||
@ -6163,6 +6189,7 @@ dependencies = [
|
|||||||
"enum-iterator",
|
"enum-iterator",
|
||||||
"euc",
|
"euc",
|
||||||
"gilrs",
|
"gilrs",
|
||||||
|
"glsl-include",
|
||||||
"glyph_brush",
|
"glyph_brush",
|
||||||
"guillotiere",
|
"guillotiere",
|
||||||
"hashbrown 0.11.2",
|
"hashbrown 0.11.2",
|
||||||
@ -6172,6 +6199,7 @@ dependencies = [
|
|||||||
"itertools 0.10.1",
|
"itertools 0.10.1",
|
||||||
"keyboard-keynames",
|
"keyboard-keynames",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"naga 0.6.0",
|
||||||
"native-dialog",
|
"native-dialog",
|
||||||
"num 0.4.0",
|
"num 0.4.0",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
@ -6182,7 +6210,6 @@ dependencies = [
|
|||||||
"rodio",
|
"rodio",
|
||||||
"ron",
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
"shaderc",
|
|
||||||
"specs",
|
"specs",
|
||||||
"specs-idvs",
|
"specs-idvs",
|
||||||
"strum",
|
"strum",
|
||||||
@ -6763,7 +6790,7 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"parking_lot 0.11.1",
|
"parking_lot 0.11.1",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"serde",
|
"serde",
|
||||||
@ -6795,7 +6822,7 @@ dependencies = [
|
|||||||
"gpu-alloc",
|
"gpu-alloc",
|
||||||
"gpu-descriptor",
|
"gpu-descriptor",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga 0.4.0",
|
||||||
"parking_lot 0.11.1",
|
"parking_lot 0.11.1",
|
||||||
"profiling",
|
"profiling",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
|
@ -136,9 +136,8 @@ nativeBuildInputs = ["pkg-config"]
|
|||||||
vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" }
|
vek = { git = "https://gitlab.com/veloren/vek.git", branch = "fix_intrinsics2" }
|
||||||
# patch wgpu so we can use wgpu-profiler crate
|
# patch wgpu so we can use wgpu-profiler crate
|
||||||
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "a92b8549a8e2cb9dac781bafc5ed32828f3caf46" }
|
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "a92b8549a8e2cb9dac781bafc5ed32828f3caf46" }
|
||||||
|
naga = { git = "https://github.com/gfx-rs/naga.git", rev = "2069ea698f4ff570c7d065b899f16a88725aca85" }
|
||||||
|
|
||||||
# # 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" }
|
|
||||||
# # use the latest fixes in gfx (remove when updates trickle down to wgpu-rs)
|
# # use the latest fixes in gfx (remove when updates trickle down to wgpu-rs)
|
||||||
# gfx-hal = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
|
# gfx-hal = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
|
||||||
# gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
|
# gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
layout(set = 0, binding = 0)
|
layout(set = 0, binding = 0)
|
||||||
uniform texture2D t_src_color;
|
uniform texture2D t_src_color;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
layout(location = 0) out vec2 uv;
|
layout(location = 0) out vec2 uv;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <globals.glsl>
|
#include <globals.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <globals.glsl>
|
#include <globals.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
layout(set = 0, binding = 0)
|
layout(set = 0, binding = 0)
|
||||||
uniform texture2D t_src_color;
|
uniform texture2D t_src_color;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
layout(set = 0, binding = 0)
|
layout(set = 0, binding = 0)
|
||||||
uniform texture2D t_src_color;
|
uniform texture2D t_src_color;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
layout(set = 0, binding = 0)
|
layout(set = 0, binding = 0)
|
||||||
uniform texture2D t_src_color;
|
uniform texture2D t_src_color;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#define FIGURE_SHADER
|
#define FIGURE_SHADER
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -98,8 +98,5 @@ vec4 rand_perm_4(vec4 pos) {
|
|||||||
|
|
||||||
vec3 smooth_rand(vec3 pos, float lerp_axis) {
|
vec3 smooth_rand(vec3 pos, float lerp_axis) {
|
||||||
return vec3(snoise(vec4(pos, lerp_axis)), snoise(vec4(pos + 400.0, lerp_axis)), snoise(vec4(pos + 1000.0, lerp_axis)));
|
return vec3(snoise(vec4(pos, lerp_axis)), snoise(vec4(pos + 400.0, lerp_axis)), snoise(vec4(pos + 1000.0, lerp_axis)));
|
||||||
vec3 r0 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(lerp_axis));
|
|
||||||
vec3 r1 = rand_perm_3(vec3(pos.x, pos.y, pos.z) + floor(lerp_axis + 1.0));
|
|
||||||
return r0 + (r1 - r0) * fract(lerp_axis);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
// #extension ARB_texture_storage : enable
|
// #extension ARB_texture_storage : enable
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
// #extension ARB_texture_storage : enable
|
// #extension ARB_texture_storage : enable
|
||||||
|
|
||||||
#define FIGURE_SHADER
|
#define FIGURE_SHADER
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// However, in the future we might apply some depth transforms here.
|
// However, in the future we might apply some depth transforms here.
|
||||||
|
|
||||||
#version 420 core
|
#version 460 core
|
||||||
// #extension ARB_texture_storage : enable
|
// #extension ARB_texture_storage : enable
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
// #extension ARB_texture_storage : enable
|
// #extension ARB_texture_storage : enable
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
// #extension GL_ARB_texture_storage : require
|
// #extension GL_ARB_texture_storage : require
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <constants.glsl>
|
#include <constants.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <globals.glsl>
|
#include <globals.glsl>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#version 420 core
|
#version 460 core
|
||||||
|
|
||||||
#include <globals.glsl>
|
#include <globals.glsl>
|
||||||
|
|
||||||
|
@ -55,7 +55,9 @@ winit = {version = "0.25.0", features = ["serde"]}
|
|||||||
wgpu = { version = "=0.8.0", features = ["trace", "cross"] }
|
wgpu = { version = "=0.8.0", features = ["trace", "cross"] }
|
||||||
wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" }
|
wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" }
|
||||||
bytemuck = { version="1.4", features=["derive"] }
|
bytemuck = { version="1.4", features=["derive"] }
|
||||||
shaderc = "0.6.2"
|
naga = { version = "=0.6.0", features = ["glsl-in", "glsl-validate", "spv-out", "codespan-reporting"] }
|
||||||
|
glsl-include = "0.3.1"
|
||||||
|
codespan-reporting = "0.11.1"
|
||||||
|
|
||||||
# Ui
|
# Ui
|
||||||
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
|
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
|
||||||
|
@ -6,11 +6,13 @@ pub enum RenderError {
|
|||||||
SwapChainError(wgpu::SwapChainError),
|
SwapChainError(wgpu::SwapChainError),
|
||||||
CustomError(String),
|
CustomError(String),
|
||||||
CouldNotFindAdapter,
|
CouldNotFindAdapter,
|
||||||
ErrorInitializingCompiler,
|
GlslIncludeError(String, glsl_include::Error),
|
||||||
ShaderError(String, shaderc::Error),
|
ParserError(String),
|
||||||
|
ValidationError(String, naga::valid::ValidationError),
|
||||||
|
SpirvError(String, naga::back::spv::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::fmt;
|
use std::{error::Error, fmt};
|
||||||
impl fmt::Debug for RenderError {
|
impl fmt::Debug for RenderError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
@ -25,12 +27,56 @@ impl fmt::Debug for RenderError {
|
|||||||
.finish(),
|
.finish(),
|
||||||
Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(),
|
Self::CustomError(err) => f.debug_tuple("CustomError").field(err).finish(),
|
||||||
Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(),
|
Self::CouldNotFindAdapter => f.debug_tuple("CouldNotFindAdapter").finish(),
|
||||||
Self::ErrorInitializingCompiler => f.debug_tuple("ErrorInitializingCompiler").finish(),
|
Self::GlslIncludeError(shader_name, err) => write!(
|
||||||
Self::ShaderError(shader_name, err) => write!(
|
|
||||||
f,
|
f,
|
||||||
"\"{}\" shader failed to compile due to the following error: {}",
|
"\"{}\" shader contains invalid include directives: {}",
|
||||||
shader_name, err
|
shader_name, err
|
||||||
),
|
),
|
||||||
|
Self::ParserError(shader_name) => {
|
||||||
|
write!(f, "\"{}\" shader failed to parse", shader_name)
|
||||||
|
},
|
||||||
|
Self::ValidationError(shader_name, err) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"\"{}\" shader failed to validate due to the following error: {}",
|
||||||
|
shader_name, err
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let mut e = err.source();
|
||||||
|
if e.is_some() {
|
||||||
|
writeln!(f, ": ")?;
|
||||||
|
} else {
|
||||||
|
writeln!(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(source) = e {
|
||||||
|
writeln!(f, "\t{}", source)?;
|
||||||
|
e = source.source();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Self::SpirvError(shader_name, err) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"\"{}\" shader failed to emit due to the following error: {}",
|
||||||
|
shader_name, err
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let mut e = err.source();
|
||||||
|
if e.is_some() {
|
||||||
|
writeln!(f, ": ")?;
|
||||||
|
} else {
|
||||||
|
writeln!(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(source) = e {
|
||||||
|
writeln!(f, "\t{}", source)?;
|
||||||
|
e = source.source();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,8 +93,19 @@ impl From<wgpu::SwapChainError> for RenderError {
|
|||||||
fn from(err: wgpu::SwapChainError) -> Self { Self::SwapChainError(err) }
|
fn from(err: wgpu::SwapChainError) -> Self { Self::SwapChainError(err) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(&str, shaderc::Error)> for RenderError {
|
impl From<(&str, glsl_include::Error)> for RenderError {
|
||||||
fn from((shader_name, err): (&str, shaderc::Error)) -> Self {
|
fn from((shader_name, err): (&str, glsl_include::Error)) -> Self {
|
||||||
Self::ShaderError(shader_name.into(), err)
|
Self::GlslIncludeError(shader_name.into(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(&str, naga::valid::ValidationError)> for RenderError {
|
||||||
|
fn from((shader_name, err): (&str, naga::valid::ValidationError)) -> Self {
|
||||||
|
Self::ValidationError(shader_name.into(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<(&str, naga::back::spv::Error)> for RenderError {
|
||||||
|
fn from((shader_name, err): (&str, naga::back::spv::Error)) -> Self {
|
||||||
|
Self::SpirvError(shader_name.into(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ use pipeline_creation::{
|
|||||||
IngameAndShadowPipelines, InterfacePipelines, PipelineCreation, Pipelines, ShadowPipelines,
|
IngameAndShadowPipelines, InterfacePipelines, PipelineCreation, Pipelines, ShadowPipelines,
|
||||||
};
|
};
|
||||||
use shaders::Shaders;
|
use shaders::Shaders;
|
||||||
|
|
||||||
use shadow_map::{ShadowMap, ShadowMapRenderer};
|
use shadow_map::{ShadowMap, ShadowMapRenderer};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -13,6 +13,39 @@ use super::{
|
|||||||
use common_base::prof_span;
|
use common_base::prof_span;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
/// Shader compiler
|
||||||
|
pub struct Compiler {
|
||||||
|
glsl: naga::front::glsl::Parser,
|
||||||
|
validator: naga::valid::Validator,
|
||||||
|
spirv: naga::back::spv::Writer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Compiler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
use naga::{
|
||||||
|
back::spv,
|
||||||
|
front::glsl,
|
||||||
|
valid::{Capabilities, ValidationFlags, Validator},
|
||||||
|
};
|
||||||
|
|
||||||
|
let glsl = glsl::Parser::default();
|
||||||
|
let validator = Validator::new(ValidationFlags::all(), Capabilities::all());
|
||||||
|
let options = spv::Options {
|
||||||
|
flags: spv::WriterFlags::DEBUG,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let spirv = spv::Writer::new(&options)
|
||||||
|
// Only happens if the options are invalid
|
||||||
|
.expect("Failed to create spirv emitter");
|
||||||
|
|
||||||
|
Compiler {
|
||||||
|
glsl,
|
||||||
|
validator,
|
||||||
|
spirv,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// All the pipelines
|
/// All the pipelines
|
||||||
pub struct Pipelines {
|
pub struct Pipelines {
|
||||||
pub debug: debug::DebugPipeline,
|
pub debug: debug::DebugPipeline,
|
||||||
@ -131,7 +164,6 @@ impl ShaderModules {
|
|||||||
has_shadow_views: bool,
|
has_shadow_views: bool,
|
||||||
) -> Result<Self, RenderError> {
|
) -> Result<Self, RenderError> {
|
||||||
prof_span!(_guard, "ShaderModules::new");
|
prof_span!(_guard, "ShaderModules::new");
|
||||||
use shaderc::{CompileOptions, Compiler, OptimizationLevel, ResolvedInclude, ShaderKind};
|
|
||||||
|
|
||||||
let constants = shaders.get("include.constants").unwrap();
|
let constants = shaders.get("include.constants").unwrap();
|
||||||
let globals = shaders.get("include.globals").unwrap();
|
let globals = shaders.get("include.globals").unwrap();
|
||||||
@ -216,41 +248,30 @@ impl ShaderModules {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut compiler = Compiler::new().ok_or(RenderError::ErrorInitializingCompiler)?;
|
let mut context = glsl_include::Context::new();
|
||||||
let mut options = CompileOptions::new().ok_or(RenderError::ErrorInitializingCompiler)?;
|
context.include("constants.glsl", &constants);
|
||||||
options.set_optimization_level(OptimizationLevel::Performance);
|
context.include("globals.glsl", &globals.0);
|
||||||
options.set_forced_version_profile(430, shaderc::GlslProfile::Core);
|
context.include("shadows.glsl", &shadows.0);
|
||||||
options.set_include_callback(move |name, _, shader_name, _| {
|
context.include("sky.glsl", &sky.0);
|
||||||
Ok(ResolvedInclude {
|
context.include("light.glsl", &light.0);
|
||||||
resolved_name: name.to_string(),
|
context.include("srgb.glsl", &srgb.0);
|
||||||
content: match name {
|
context.include("random.glsl", &random.0);
|
||||||
"constants.glsl" => constants.clone(),
|
context.include("lod.glsl", &lod.0);
|
||||||
"globals.glsl" => globals.0.to_owned(),
|
context.include("anti-aliasing.glsl", &anti_alias.0);
|
||||||
"shadows.glsl" => shadows.0.to_owned(),
|
context.include("cloud.glsl", &cloud.0);
|
||||||
"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(),
|
|
||||||
other => {
|
|
||||||
return Err(format!(
|
|
||||||
"Include {} in {} is not defined",
|
|
||||||
other, shader_name
|
|
||||||
));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut create_shader = |name, kind| {
|
let mut compiler = Compiler::new();
|
||||||
|
|
||||||
|
let mut create_shader = |name, stage| {
|
||||||
let glsl = &shaders
|
let glsl = &shaders
|
||||||
.get(name)
|
.get(name)
|
||||||
.unwrap_or_else(|| panic!("Can't retrieve shader: {}", name))
|
.unwrap_or_else(|| panic!("Can't retrieve shader: {}", name))
|
||||||
.0;
|
.0;
|
||||||
let file_name = format!("{}.glsl", name);
|
let file_name = format!("{}.glsl", name);
|
||||||
create_shader_module(device, &mut compiler, glsl, kind, &file_name, &options)
|
let source = context
|
||||||
|
.expand(glsl)
|
||||||
|
.map_err(|err| (file_name.as_str(), err))?;
|
||||||
|
create_shader_module(device, &file_name, &source, stage, &mut compiler)
|
||||||
};
|
};
|
||||||
|
|
||||||
let selected_fluid_shader = ["fluid-frag.", match pipeline_modes.fluid {
|
let selected_fluid_shader = ["fluid-frag.", match pipeline_modes.fluid {
|
||||||
@ -260,47 +281,50 @@ impl ShaderModules {
|
|||||||
.concat();
|
.concat();
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
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)?,
|
|
||||||
particle_vert: create_shader("particle-vert", ShaderKind::Vertex)?,
|
|
||||||
particle_frag: create_shader("particle-frag", ShaderKind::Fragment)?,
|
|
||||||
ui_vert: create_shader("ui-vert", ShaderKind::Vertex)?,
|
|
||||||
ui_frag: create_shader("ui-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: create_shader(
|
||||||
"dual-downsample-filtered-frag",
|
"dual-downsample-filtered-frag",
|
||||||
ShaderKind::Fragment,
|
naga::ShaderStage::Fragment,
|
||||||
)?,
|
)?,
|
||||||
dual_downsample_frag: create_shader("dual-downsample-frag", ShaderKind::Fragment)?,
|
dual_downsample_frag: create_shader(
|
||||||
dual_upsample_frag: create_shader("dual-upsample-frag", ShaderKind::Fragment)?,
|
"dual-downsample-frag",
|
||||||
postprocess_vert: create_shader("postprocess-vert", ShaderKind::Vertex)?,
|
naga::ShaderStage::Fragment,
|
||||||
postprocess_frag: create_shader("postprocess-frag", ShaderKind::Fragment)?,
|
)?,
|
||||||
blit_vert: create_shader("blit-vert", ShaderKind::Vertex)?,
|
dual_upsample_frag: create_shader("dual-upsample-frag", naga::ShaderStage::Fragment)?,
|
||||||
blit_frag: create_shader("blit-frag", ShaderKind::Fragment)?,
|
skybox_vert: create_shader("skybox-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
skybox_frag: create_shader("skybox-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
debug_vert: create_shader("debug-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
debug_frag: create_shader("debug-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
figure_vert: create_shader("figure-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
figure_frag: create_shader("figure-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
terrain_vert: create_shader("terrain-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
terrain_frag: create_shader("terrain-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
fluid_vert: create_shader("fluid-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
fluid_frag: create_shader(&selected_fluid_shader, naga::ShaderStage::Fragment)?,
|
||||||
|
sprite_vert: create_shader("sprite-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
sprite_frag: create_shader("sprite-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
particle_vert: create_shader("particle-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
particle_frag: create_shader("particle-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
ui_vert: create_shader("ui-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
ui_frag: create_shader("ui-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
lod_terrain_vert: create_shader("lod-terrain-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
lod_terrain_frag: create_shader("lod-terrain-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
clouds_vert: create_shader("clouds-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
clouds_frag: create_shader("clouds-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
postprocess_vert: create_shader("postprocess-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
postprocess_frag: create_shader("postprocess-frag", naga::ShaderStage::Fragment)?,
|
||||||
|
blit_vert: create_shader("blit-vert", naga::ShaderStage::Vertex)?,
|
||||||
|
blit_frag: create_shader("blit-frag", naga::ShaderStage::Fragment)?,
|
||||||
point_light_shadows_vert: create_shader(
|
point_light_shadows_vert: create_shader(
|
||||||
"point-light-shadows-vert",
|
"point-light-shadows-vert",
|
||||||
ShaderKind::Vertex,
|
naga::ShaderStage::Vertex,
|
||||||
)?,
|
)?,
|
||||||
light_shadows_directed_vert: create_shader(
|
light_shadows_directed_vert: create_shader(
|
||||||
"light-shadows-directed-vert",
|
"light-shadows-directed-vert",
|
||||||
ShaderKind::Vertex,
|
naga::ShaderStage::Vertex,
|
||||||
)?,
|
)?,
|
||||||
light_shadows_figure_vert: create_shader(
|
light_shadows_figure_vert: create_shader(
|
||||||
"light-shadows-figure-vert",
|
"light-shadows-figure-vert",
|
||||||
ShaderKind::Vertex,
|
naga::ShaderStage::Vertex,
|
||||||
)?,
|
)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -308,23 +332,57 @@ impl ShaderModules {
|
|||||||
|
|
||||||
fn create_shader_module(
|
fn create_shader_module(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
compiler: &mut shaderc::Compiler,
|
|
||||||
source: &str,
|
|
||||||
kind: shaderc::ShaderKind,
|
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
options: &shaderc::CompileOptions,
|
source: &str,
|
||||||
|
stage: naga::ShaderStage,
|
||||||
|
compiler: &mut Compiler,
|
||||||
) -> Result<wgpu::ShaderModule, RenderError> {
|
) -> Result<wgpu::ShaderModule, RenderError> {
|
||||||
prof_span!(_guard, "create_shader_modules");
|
prof_span!(_guard, "create_shader_modules");
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
let spv = compiler
|
use codespan_reporting::{
|
||||||
.compile_into_spirv(source, kind, file_name, "main", Some(options))
|
diagnostic::{Diagnostic, Label},
|
||||||
.map_err(|e| (file_name, e))?;
|
files::SimpleFile,
|
||||||
|
term::{
|
||||||
|
self,
|
||||||
|
termcolor::{ColorChoice, StandardStream},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use naga::front::glsl;
|
||||||
|
|
||||||
|
// Parse
|
||||||
|
let options = glsl::Options::from(stage);
|
||||||
|
let module = compiler.glsl.parse(&options, source).map_err(|errors| {
|
||||||
|
let files = SimpleFile::new(file_name, source);
|
||||||
|
let config = codespan_reporting::term::Config::default();
|
||||||
|
let writer = StandardStream::stderr(ColorChoice::Auto);
|
||||||
|
|
||||||
|
for err in errors {
|
||||||
|
let diagnostic = Diagnostic::error()
|
||||||
|
.with_message(err.kind.to_string())
|
||||||
|
.with_labels(vec![Label::primary((), err.meta)]);
|
||||||
|
|
||||||
|
let _ = term::emit(&mut writer.lock(), &config, &files, &diagnostic);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderError::ParserError(file_name.to_string())
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
let info = compiler
|
||||||
|
.validator
|
||||||
|
.validate(&module)
|
||||||
|
.map_err(|err| (file_name, err))?;
|
||||||
|
|
||||||
|
// Emit
|
||||||
|
let mut spv = Vec::new();
|
||||||
|
compiler
|
||||||
|
.spirv
|
||||||
|
.write(&module, &info, &mut spv)
|
||||||
|
.map_err(|err| (file_name, err))?;
|
||||||
|
|
||||||
let label = [file_name, "\n\n", source].concat();
|
|
||||||
Ok(device.create_shader_module(&wgpu::ShaderModuleDescriptor {
|
Ok(device.create_shader_module(&wgpu::ShaderModuleDescriptor {
|
||||||
label: Some(&label),
|
label: Some(file_name),
|
||||||
source: wgpu::ShaderSource::SpirV(Cow::Borrowed(spv.as_binary())),
|
source: wgpu::ShaderSource::SpirV(spv.into()),
|
||||||
flags: wgpu::ShaderFlags::empty(),
|
flags: wgpu::ShaderFlags::empty(),
|
||||||
// TODO: renable // flags: wgpu::ShaderFlags::VALIDATION,
|
// TODO: renable // flags: wgpu::ShaderFlags::VALIDATION,
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user