Merge pull request #606 from mahkoh/jorth/compile-shaders
vulkan: include precompiled shaders
This commit is contained in:
commit
f1670826da
31 changed files with 425 additions and 122 deletions
|
|
@ -6,7 +6,7 @@ tasks:
|
|||
echo 'Server = https://mirrors.n-ix.net/archlinux/$repo/os/$arch' | sudo tee /etc/pacman.d/mirrorlist
|
||||
- install: |
|
||||
sudo pacman -Syu --noconfirm
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa cmake shaderc
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa
|
||||
rustup toolchain install stable
|
||||
- build: |
|
||||
cd jay
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ tasks:
|
|||
echo 'Server = https://mirrors.n-ix.net/archlinux/$repo/os/$arch' | sudo tee /etc/pacman.d/mirrorlist
|
||||
- install: |
|
||||
sudo pacman -Syu --noconfirm
|
||||
sudo pacman -S --noconfirm rustup shaderc musl
|
||||
sudo pacman -S --noconfirm rustup musl
|
||||
rustup toolchain install stable
|
||||
rustup target install x86_64-unknown-linux-musl
|
||||
- build: |
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ tasks:
|
|||
echo 'Server = https://mirrors.n-ix.net/archlinux/$repo/os/$arch' | sudo tee /etc/pacman.d/mirrorlist
|
||||
- install: |
|
||||
sudo pacman -Syu --noconfirm
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa xorg-xwayland adwaita-icon-theme libxcursor cmake shaderc
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa xorg-xwayland adwaita-icon-theme libxcursor
|
||||
rustup toolchain install stable
|
||||
- configure: |
|
||||
sudo rmmod bochs
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ tasks:
|
|||
echo 'Server = https://mirrors.n-ix.net/archlinux/$repo/os/$arch' | sudo tee /etc/pacman.d/mirrorlist
|
||||
- install: |
|
||||
sudo pacman -Syu --noconfirm
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa xorg-xwayland adwaita-icon-theme libxcursor cmake shaderc
|
||||
sudo pacman -S --noconfirm rustup libinput pango mesa xorg-xwayland adwaita-icon-theme libxcursor
|
||||
rustup toolchain install stable
|
||||
cd jay
|
||||
git submodule update --init
|
||||
|
|
|
|||
29
.github/workflows/check-spv.yml
vendored
Normal file
29
.github/workflows/check-spv.yml
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
name: check-spv
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
check-spv:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Show env
|
||||
run: |
|
||||
uname -a
|
||||
ldd --version
|
||||
- name: Install
|
||||
run: |
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
- name: Check
|
||||
run: |
|
||||
cargo run --manifest-path compile-shaders/Cargo.toml -p compile-shaders-core
|
||||
git diff --exit-code
|
||||
48
Cargo.lock
generated
48
Cargo.lock
generated
|
|
@ -293,15 +293,6 @@ version = "0.7.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.3"
|
||||
|
|
@ -641,7 +632,6 @@ dependencies = [
|
|||
"rustc-demangle",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shaderc",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tiny-skia",
|
||||
|
|
@ -784,15 +774,6 @@ dependencies = [
|
|||
"syn 2.0.96",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a6f6da007f968f9def0d65a05b187e2960183de70c160204ecfccf0ee330212"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
|
|
@ -1165,12 +1146,6 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e110b7d5a1335c2e801176c42a626a905c23eecdee104d9bdfbd6ea5f0b8368"
|
||||
|
||||
[[package]]
|
||||
name = "roxmltree"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
|
||||
|
||||
[[package]]
|
||||
name = "run-on-drop"
|
||||
version = "1.0.0"
|
||||
|
|
@ -1278,29 +1253,6 @@ dependencies = [
|
|||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaderc"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cdc8a26f751f141968dbc08fc01cfa3f4a288351f81cfd9148db41aa189f635"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"shaderc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaderc-sys"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "275f0ea572da7183c0cd0a060ba67c9fb54934523d4c9a9494ce5828c533d40b"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
"libc",
|
||||
"link-cplusplus",
|
||||
"pkg-config",
|
||||
"roxmltree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ blake3 = "1.8.2"
|
|||
repc = "0.1.1"
|
||||
anyhow = "1.0.79"
|
||||
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
|
||||
shaderc = "0.9.1"
|
||||
cc = "1.0.86"
|
||||
|
||||
#[profile.dev.build-override]
|
||||
|
|
|
|||
|
|
@ -1,58 +1,20 @@
|
|||
use {
|
||||
crate::open,
|
||||
anyhow::{Context, anyhow, bail},
|
||||
shaderc::{CompileOptions, ResolvedInclude},
|
||||
std::{io::Write, path::Path},
|
||||
};
|
||||
|
||||
const ROOT: &str = "src/gfx_apis/vulkan/shaders";
|
||||
use {anyhow::bail, std::process::Command};
|
||||
|
||||
pub fn main() -> anyhow::Result<()> {
|
||||
println!("cargo:rerun-if-changed={}", ROOT);
|
||||
compile_simple("fill.frag")?;
|
||||
compile_simple("fill.vert")?;
|
||||
compile_simple("tex.vert")?;
|
||||
compile_simple("tex.frag")?;
|
||||
compile_simple("out.vert")?;
|
||||
compile_simple("out.frag")?;
|
||||
compile_simple("legacy/fill.frag")?;
|
||||
compile_simple("legacy/fill.vert")?;
|
||||
compile_simple("legacy/tex.vert")?;
|
||||
compile_simple("legacy/tex.frag")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_simple(name: &str) -> anyhow::Result<()> {
|
||||
let out = format!("{name}.spv").replace("/", "_");
|
||||
compile_shader(name, &out).with_context(|| name.to_string())
|
||||
}
|
||||
|
||||
fn compile_shader(name: &str, out: &str) -> anyhow::Result<()> {
|
||||
let root = Path::new(ROOT).join(Path::new(name).parent().unwrap());
|
||||
let read = |path: &str| std::fs::read_to_string(root.join(path));
|
||||
let mut options = CompileOptions::new().unwrap();
|
||||
options.set_include_callback(|name, _, _, _| {
|
||||
Ok(ResolvedInclude {
|
||||
resolved_name: name.to_string(),
|
||||
content: read(name).map_err(|e| anyhow!(e).to_string())?,
|
||||
})
|
||||
});
|
||||
let stage = match Path::new(name)
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("")
|
||||
{
|
||||
"frag" => shaderc::ShaderKind::Fragment,
|
||||
"vert" => shaderc::ShaderKind::Vertex,
|
||||
n => bail!("Unknown shader stage {}", n),
|
||||
};
|
||||
let src = std::fs::read_to_string(format!("{}/{}", ROOT, name))?;
|
||||
let compiler = shaderc::Compiler::new().unwrap();
|
||||
let binary = compiler
|
||||
.compile_into_spirv(&src, stage, name, "main", Some(&options))
|
||||
.unwrap();
|
||||
let mut file = open(out)?;
|
||||
file.write_all(binary.as_binary_u8())?;
|
||||
file.flush()?;
|
||||
if !std::fs::exists("compile-shaders")? {
|
||||
return Ok(());
|
||||
}
|
||||
let code = Command::new("cargo")
|
||||
.args([
|
||||
"run",
|
||||
"--manifest-path",
|
||||
"compile-shaders/Cargo.toml",
|
||||
"-p",
|
||||
"compile-shaders-build-rs",
|
||||
])
|
||||
.status()?;
|
||||
if !code.success() {
|
||||
bail!("compile-shaders failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
1
compile-shaders/.gitignore
vendored
Normal file
1
compile-shaders/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
196
compile-shaders/Cargo.lock
generated
Normal file
196
compile-shaders/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.99"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3888aaa89e4b2a40fca9848e400f6a658a5a3978de7be858e209cafa8be9a4a0"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65193589c6404eb80b450d618eaf9a2cafaaafd57ecce47370519ef674a7bd44"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compile-shaders-build-rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"compile-shaders-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compile-shaders-compile"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"compile-shaders-core",
|
||||
"shaderc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "compile-shaders-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"blake3",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.175"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "roxmltree"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaderc"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ab2a6e36d1c1e2320c87e2b806a3e7b0dffaa67b82c14a39dad6cf7637208ae"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"shaderc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaderc-sys"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdceb85b2c6d2c27b95ffe2d341063dfded0aca8046f7f60c544bbeaeaf8bcae"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
"libc",
|
||||
"link-cplusplus",
|
||||
"pkg-config",
|
||||
"roxmltree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
3
compile-shaders/Cargo.toml
Normal file
3
compile-shaders/Cargo.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["build-rs", "compile", "core"]
|
||||
8
compile-shaders/build-rs/Cargo.toml
Normal file
8
compile-shaders/build-rs/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "compile-shaders-build-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
compile-shaders-core = { path = "../core" }
|
||||
anyhow = "1.0.99"
|
||||
25
compile-shaders/build-rs/src/main.rs
Normal file
25
compile-shaders/build-rs/src/main.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use {
|
||||
anyhow::bail,
|
||||
compile_shaders_core::{ROOT, unchanged},
|
||||
std::process::Command,
|
||||
};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
println!("cargo:rerun-if-changed={}", ROOT);
|
||||
if unchanged() {
|
||||
return Ok(());
|
||||
}
|
||||
let code = Command::new("cargo")
|
||||
.args([
|
||||
"run",
|
||||
"--manifest-path",
|
||||
"compile-shaders/Cargo.toml",
|
||||
"-p",
|
||||
"compile-shaders-compile",
|
||||
])
|
||||
.status()?;
|
||||
if !code.success() {
|
||||
bail!("compile-shaders failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
9
compile-shaders/compile/Cargo.toml
Normal file
9
compile-shaders/compile/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "compile-shaders-compile"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
compile-shaders-core = { path = "../core" }
|
||||
anyhow = "1.0.79"
|
||||
shaderc = "0.10.1"
|
||||
54
compile-shaders/compile/src/main.rs
Normal file
54
compile-shaders/compile/src/main.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use {
|
||||
anyhow::{Context, anyhow, bail},
|
||||
compile_shaders_core::{BIN, ROOT, update_hash},
|
||||
shaderc::{CompileOptions, ResolvedInclude},
|
||||
std::{fs::File, io::Write, path::Path},
|
||||
};
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
compile("fill.frag")?;
|
||||
compile("fill.vert")?;
|
||||
compile("tex.vert")?;
|
||||
compile("tex.frag")?;
|
||||
compile("out.vert")?;
|
||||
compile("out.frag")?;
|
||||
compile("legacy/fill.frag")?;
|
||||
compile("legacy/fill.vert")?;
|
||||
compile("legacy/tex.vert")?;
|
||||
compile("legacy/tex.frag")?;
|
||||
update_hash()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile(name: &str) -> anyhow::Result<()> {
|
||||
let out = format!("{name}.spv").replace("/", "_");
|
||||
compile_shader(name, &out).with_context(|| name.to_string())
|
||||
}
|
||||
|
||||
fn compile_shader(name: &str, out: &str) -> anyhow::Result<()> {
|
||||
let root = Path::new(ROOT).join(Path::new(name).parent().unwrap());
|
||||
let read = |path: &str| std::fs::read_to_string(root.join(path));
|
||||
let mut options = CompileOptions::new()?;
|
||||
options.set_include_callback(|name, _, _, _| {
|
||||
Ok(ResolvedInclude {
|
||||
resolved_name: name.to_string(),
|
||||
content: read(name).map_err(|e| anyhow!(e).to_string())?,
|
||||
})
|
||||
});
|
||||
let stage = match Path::new(name)
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("")
|
||||
{
|
||||
"frag" => shaderc::ShaderKind::Fragment,
|
||||
"vert" => shaderc::ShaderKind::Vertex,
|
||||
n => bail!("Unknown shader stage {}", n),
|
||||
};
|
||||
let src = std::fs::read_to_string(format!("{}/{}", ROOT, name))?;
|
||||
let compiler = shaderc::Compiler::new()?;
|
||||
let binary = compiler.compile_into_spirv(&src, stage, name, "main", Some(&options))?;
|
||||
let mut file = File::create(Path::new(BIN).join(out))?;
|
||||
file.write_all(binary.as_binary_u8())?;
|
||||
file.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
9
compile-shaders/core/Cargo.toml
Normal file
9
compile-shaders/core/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "compile-shaders-core"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.79"
|
||||
walkdir = "2.5.0"
|
||||
blake3 = "1.8.2"
|
||||
38
compile-shaders/core/src/lib.rs
Normal file
38
compile-shaders/core/src/lib.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use {std::fmt::Write, walkdir::WalkDir};
|
||||
|
||||
pub const ROOT: &str = "src/gfx_apis/vulkan/shaders";
|
||||
pub const BIN: &str = "src/gfx_apis/vulkan/shaders_bin";
|
||||
pub const HASH: &str = "src/gfx_apis/vulkan/shaders_hash.txt";
|
||||
|
||||
fn calculate_hash() -> anyhow::Result<String> {
|
||||
let dir = WalkDir::new(ROOT);
|
||||
let mut files = vec![];
|
||||
for file in dir {
|
||||
let file = file?;
|
||||
if file.file_type().is_file() {
|
||||
files.push(file.path().to_path_buf());
|
||||
}
|
||||
}
|
||||
files.sort();
|
||||
let mut out = String::new();
|
||||
for file in files {
|
||||
let data = std::fs::read(&file)?;
|
||||
writeln!(out, "{} {}", blake3::hash(&data).to_hex(), file.display())?;
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn unchanged() -> bool {
|
||||
let Ok(actual) = std::fs::read_to_string(HASH) else {
|
||||
return false;
|
||||
};
|
||||
let Ok(expected) = calculate_hash() else {
|
||||
return false;
|
||||
};
|
||||
actual == expected
|
||||
}
|
||||
|
||||
pub fn update_hash() -> anyhow::Result<()> {
|
||||
std::fs::write(HASH, calculate_hash()?)?;
|
||||
Ok(())
|
||||
}
|
||||
5
compile-shaders/core/src/main.rs
Normal file
5
compile-shaders/core/src/main.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use compile_shaders_core::update_hash;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
update_hash()
|
||||
}
|
||||
|
|
@ -12,9 +12,6 @@ The following libraries must be installed before compiling Jay:
|
|||
You must also have a C compiler (GCC or Clang) and the latest version of rust installed.
|
||||
You can install rust with [rustup](https://rustup.rs/).
|
||||
|
||||
It is recommended that you install shaderc.
|
||||
Otherwise it will be built from source which can take several minutes.
|
||||
|
||||
## Runtime Dependencies
|
||||
|
||||
Most of these dependencies are optional and will enable additional features.
|
||||
|
|
|
|||
|
|
@ -5,18 +5,16 @@ use {
|
|||
uapi::Packed,
|
||||
};
|
||||
|
||||
pub const FILL_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/fill.vert.spv"));
|
||||
pub const FILL_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/fill.frag.spv"));
|
||||
pub const TEX_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/tex.vert.spv"));
|
||||
pub const TEX_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/tex.frag.spv"));
|
||||
pub const OUT_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/out.vert.spv"));
|
||||
pub const OUT_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/out.frag.spv"));
|
||||
pub const LEGACY_FILL_VERT: &[u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/legacy_fill.vert.spv"));
|
||||
pub const LEGACY_FILL_FRAG: &[u8] =
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/legacy_fill.frag.spv"));
|
||||
pub const LEGACY_TEX_VERT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/legacy_tex.vert.spv"));
|
||||
pub const LEGACY_TEX_FRAG: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/legacy_tex.frag.spv"));
|
||||
pub const FILL_VERT: &[u8] = include_bytes!("shaders_bin/fill.vert.spv");
|
||||
pub const FILL_FRAG: &[u8] = include_bytes!("shaders_bin/fill.frag.spv");
|
||||
pub const TEX_VERT: &[u8] = include_bytes!("shaders_bin/tex.vert.spv");
|
||||
pub const TEX_FRAG: &[u8] = include_bytes!("shaders_bin/tex.frag.spv");
|
||||
pub const OUT_VERT: &[u8] = include_bytes!("shaders_bin/out.vert.spv");
|
||||
pub const OUT_FRAG: &[u8] = include_bytes!("shaders_bin/out.frag.spv");
|
||||
pub const LEGACY_FILL_VERT: &[u8] = include_bytes!("shaders_bin/legacy_fill.vert.spv");
|
||||
pub const LEGACY_FILL_FRAG: &[u8] = include_bytes!("shaders_bin/legacy_fill.frag.spv");
|
||||
pub const LEGACY_TEX_VERT: &[u8] = include_bytes!("shaders_bin/legacy_tex.vert.spv");
|
||||
pub const LEGACY_TEX_FRAG: &[u8] = include_bytes!("shaders_bin/legacy_tex.frag.spv");
|
||||
|
||||
pub struct VulkanShader {
|
||||
pub(super) device: Rc<VulkanDevice>,
|
||||
|
|
|
|||
BIN
src/gfx_apis/vulkan/shaders_bin/fill.frag.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/fill.frag.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/fill.vert.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/fill.vert.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_fill.frag.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_fill.frag.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_fill.vert.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_fill.vert.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_tex.frag.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_tex.frag.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_tex.vert.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/legacy_tex.vert.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/out.frag.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/out.frag.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/out.vert.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/out.vert.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/tex.frag.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/tex.frag.spv
Normal file
Binary file not shown.
BIN
src/gfx_apis/vulkan/shaders_bin/tex.vert.spv
Normal file
BIN
src/gfx_apis/vulkan/shaders_bin/tex.vert.spv
Normal file
Binary file not shown.
18
src/gfx_apis/vulkan/shaders_hash.txt
Normal file
18
src/gfx_apis/vulkan/shaders_hash.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
f49076a6465a6790c72a6d290c13d5f14c7dae8ae3eed6ca71c57424e3306f66 src/gfx_apis/vulkan/shaders/eotfs.glsl
|
||||
8a38df18851cd13884499820f26939fb7319f45d913d867f254d8118d59fb117 src/gfx_apis/vulkan/shaders/fill.common.glsl
|
||||
21c488d12aa5ad2f109ec44cb856dfe837e02ea9025b5ed64439d742c17cbf30 src/gfx_apis/vulkan/shaders/fill.frag
|
||||
4fb481d8d73afdfb0d8f077eb8665d86f06c8a32a91e44ed369ef5dff554646d src/gfx_apis/vulkan/shaders/fill.vert
|
||||
63af15c4e00587a7bb8494934c88d9874712a511217829b50f3c08fa3c461082 src/gfx_apis/vulkan/shaders/frag_spec_const.glsl
|
||||
c315a064b48dd5bdb607a6b79c30d31b6e59ffec69e93d50ab875abf97c41bbf src/gfx_apis/vulkan/shaders/legacy/fill.common.glsl
|
||||
590d061b97446fc501158609eaf098b71bc7b328c008b586ff36613ce690d618 src/gfx_apis/vulkan/shaders/legacy/fill.frag
|
||||
ad22a79e1a88a12daa40c0a2b953084c129a408297c8ca544d60e0b6001470b9 src/gfx_apis/vulkan/shaders/legacy/fill.vert
|
||||
e0a8769dd7938dd02e66db9e9048ed6bef8f8c42671f2e2c7a7976a6d498f685 src/gfx_apis/vulkan/shaders/legacy/tex.common.glsl
|
||||
0e7c72ea11671065842c8b4ad4131a7df33b427dc0ea76bf5a896546f6636cb0 src/gfx_apis/vulkan/shaders/legacy/tex.frag
|
||||
4402f7ccdbb9fb52fb6cda3aab13cf89e2980c79b541f8be0463efd64a5f98ed src/gfx_apis/vulkan/shaders/legacy/tex.vert
|
||||
3ba5d05c2b95099e5424b3ade5d1c31d431f5730b1d0b51a9fb5f8afc4ea14b4 src/gfx_apis/vulkan/shaders/out.common.glsl
|
||||
5069f619c7d722815a022e2d84720a2d8290af49a3ed49ea0cd26b52115cc39a src/gfx_apis/vulkan/shaders/out.frag
|
||||
0adc7e12328c15fb3e7e6c8b8701a182223c2f15337e14131f41dd247e697809 src/gfx_apis/vulkan/shaders/out.vert
|
||||
e22d4d3318a350def8ef19c7b27dc6a308a84c2fe9d7c02b81107f72073cd481 src/gfx_apis/vulkan/shaders/tex.common.glsl
|
||||
06993d4d882fe5c651e5ab54f0116b9622352a97f3575985076ef464b472dd39 src/gfx_apis/vulkan/shaders/tex.frag
|
||||
423cf327c9fcc4070dbf75321c1224a1589b6cf3d2f1ea5e8bd0362e1a9f3aa1 src/gfx_apis/vulkan/shaders/tex.vert
|
||||
b982f7101c22931a33b32dce3408387f3392c0f0ad0ca5852da265b0d12856bb src/gfx_apis/vulkan/shaders/tex_set.glsl
|
||||
Loading…
Add table
Add a link
Reference in a new issue