Skip to content

Commit

Permalink
Precompile shaders offline, add shader makefile
Browse files Browse the repository at this point in the history
+ makes shaderc dependency optional
+ removes requirement of distributing builtin shaders
+ speeds up engine startup time
  • Loading branch information
Frizi committed May 19, 2019
1 parent 59cef95 commit fdc3e54
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ examples/assets/large/**/*.dds filter=lfs diff=lfs merge=lfs -text
examples/assets/large/**/*.glb filter=lfs diff=lfs merge=lfs -text
examples/assets/large/**/*.bin filter=lfs diff=lfs merge=lfs -text
examples/assets/large/**/*.jpg filter=lfs diff=lfs merge=lfs -text
amethyst_rendy/compiled/**/*.spv filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ server = [
"network"
]
no-slow-safety-checks = ["amethyst_rendy/no-slow-safety-checks"]
shader-compiler = ["amethyst_rendy/shader-compiler"]

[workspace]
members = [
Expand Down
5 changes: 3 additions & 2 deletions amethyst_rendy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hibitset = "0.5.4"
lazy_static = "1.3"
log = "0.4"
palette = { version = "0.4", features = ["serde"] }
rendy = { git = "https://github.com/amethyst/rendy.git", features = ["full", "empty", "serde-1"] }
rendy = { git = "https://github.com/amethyst/rendy.git", features = ["command", "descriptor", "factory", "frame", "graph", "memory", "mesh", "shader", "resource", "texture", "util", "wsi", "empty", "mesh-obj", "texture-image", "texture-palette", "serde-1"] }
# rendy = { git = "https://github.com/frizi/rendy.git", branch = "fence-reset", features = ["full", "empty", "serde-1"] }
# rendy = { path = "../../rendy/rendy/", features = ["full", "empty", "serde-1"] }
ron = "0.4"
Expand All @@ -42,4 +42,5 @@ metal = ["rendy/metal"]
vulkan = ["rendy/vulkan"]
profiler = [ "thread_profiler/thread_profiler", "rendy/profiler" ]
nightly = [ "amethyst_core/nightly", "shred/nightly" ]
no-slow-safety-checks = ["rendy/no-slow-safety-checks"]
no-slow-safety-checks = ["rendy/no-slow-safety-checks"]
shader-compiler = ["rendy/shader-compiler"]
26 changes: 26 additions & 0 deletions amethyst_rendy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

GLSLC = $(shell ./find_glslc.sh)
ifeq "$(GLSLC)" ""
break;
endif

FLAGS = -c -g

SHADERS=$(wildcard shaders/**/*)
COMP_SHADERS = $(patsubst shaders/%,compiled/%.spv,$(SHADERS))
COMP_DISASMS = $(patsubst shaders/%,compiled/%.spvasm,$(SHADERS))

all: $(COMP_SHADERS) $(COMP_DISASMS)

compiled/%.spv: shaders/%
mkdir -p $(dir $@)
$(GLSLC) -MD -c -g -O -o $@ $<

compiled/%.spvasm: shaders/%
mkdir -p $(dir $@)
$(GLSLC) -MD -S -g -O -o $@ $<

clean:
rm compiled/**/*.spv compiled/**/*.spvasm compiled/**/*.d

.PHONY: all clean
2 changes: 2 additions & 0 deletions amethyst_rendy/compiled/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.spvasm
*.d
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/debug_lines.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/flat.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/pbr.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/shaded.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/skybox.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/fragment/sprite.frag.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/debug_lines.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/pos_norm_tang_tex.vert.spv
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/pos_norm_tex.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/pos_norm_tex_skin.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/pos_tex.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/pos_tex_skin.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/skybox.vert.spv
Git LFS file not shown
3 changes: 3 additions & 0 deletions amethyst_rendy/compiled/vertex/sprite.vert.spv
Git LFS file not shown
22 changes: 22 additions & 0 deletions amethyst_rendy/find_glslc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cd "${0%/*}"
set -e

BIN=""

if [ -e "$(which glslc)" ]; then
BIN="$(which glslc)"
elif [ -e "$(which glslc.exe)" ]; then
# support WSL
BIN="$(which glslc.exe)"
else
>&2 echo "Cannot find glslc binary. Make sure you have VulkanSDK installed and added to PATH."
exit 1
fi

echo "$BIN"

# for SHADER in $(find shaders -type f -name "*.vert" -o -name "*.frag"); do
# echo $SHADER
# "$BIN" -MD -c -g -O "$SHADER" -o "$SHADER.spv"
# "$BIN" -S -g -O "$SHADER" -o "$SHADER.spvasm"
# done
144 changes: 61 additions & 83 deletions amethyst_rendy/src/pass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,118 +8,96 @@ mod skybox;

pub use self::{base_3d::*, debug_lines::*, flat::*, flat2d::*, pbr::*, shaded::*, skybox::*};

use rendy::shader::{ShaderKind, SourceLanguage, SpirvShader, StaticShaderInfo};
use rendy::{hal::pso::ShaderStageFlags, shader::SpirvShader};

lazy_static::lazy_static! {
static ref POS_TEX_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_tex.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_TEX_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_tex.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref POS_TEX_SKIN_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_tex_skin.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_TEX_SKIN_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_tex_skin.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref POS_NORM_TEX_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_norm_tex.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_NORM_TEX_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_norm_tex.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref POS_NORM_TEX_SKIN_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_norm_tex_skin.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_NORM_TEX_SKIN_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_norm_tex_skin.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref POS_NORM_TANG_TEX_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_norm_tang_tex.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_NORM_TANG_TEX_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_norm_tang_tex.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref POS_NORM_TANG_TEX_SKIN_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pos_norm_tang_tex_skin.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref POS_NORM_TANG_TEX_SKIN_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/pos_norm_tang_tex_skin.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref FLAT_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/flat.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
static ref FLAT_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/flat.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();
);

static ref SHADED_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/shaded.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
static ref SHADED_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/shaded.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();
);

static ref PBR_SKINNED_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/pbr_skinned.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref PBR_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/pbr.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();
);

static ref PBR_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/pbr.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
static ref SPRITE_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/sprite.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref SPRITE_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/sprite.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref SPRITE_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/sprite.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();
);

static ref SPRITE_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/sprite.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
static ref SKYBOX_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/skybox.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref SKYBOX_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/skybox.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref SKYBOX_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/skybox.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();
);

static ref SKYBOX_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/skybox.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
static ref DEBUG_LINES_VERTEX: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/vertex/debug_lines.vert.spv").to_vec(),
ShaderStageFlags::VERTEX,
"main",
).precompile().unwrap();
);

static ref DEBUG_LINES_VERTEX: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/vertex/debug_lines.vert"),
ShaderKind::Vertex,
SourceLanguage::GLSL,
static ref DEBUG_LINES_FRAGMENT: SpirvShader = SpirvShader::new(
include_bytes!("../../compiled/fragment/debug_lines.frag.spv").to_vec(),
ShaderStageFlags::FRAGMENT,
"main",
).precompile().unwrap();

static ref DEBUG_LINES_FRAGMENT: SpirvShader = StaticShaderInfo::new(
concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/fragment/debug_lines.frag"),
ShaderKind::Fragment,
SourceLanguage::GLSL,
"main",
).precompile().unwrap();
);
}

0 comments on commit fdc3e54

Please sign in to comment.