shaders
This commit is contained in:
parent
bd7d03c98b
commit
adfc1f4b3e
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,4 +2,5 @@
|
|||
/test-roms
|
||||
/bootrom
|
||||
/wavs
|
||||
/profiles
|
||||
/profiles
|
||||
/gb-emu/shaders
|
||||
|
|
125
Cargo.lock
generated
125
Cargo.lock
generated
|
@ -344,16 +344,6 @@ version = "0.1.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"byte-tools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-sys"
|
||||
version = "0.1.0-beta.1"
|
||||
|
@ -379,12 +369,6 @@ version = "3.13.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.1"
|
||||
|
@ -536,15 +520,6 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cocoa"
|
||||
version = "0.20.2"
|
||||
|
@ -931,15 +906,6 @@ version = "0.11.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f"
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
|
@ -1000,18 +966,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fake-simd"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.0"
|
||||
|
@ -1176,7 +1130,7 @@ dependencies = [
|
|||
"futures",
|
||||
"gb-emu-lib",
|
||||
"gilrs",
|
||||
"glsl-to-spirv",
|
||||
"naga 0.13.0",
|
||||
"nokhwa",
|
||||
"pixels",
|
||||
"raw-window-handle",
|
||||
|
@ -1200,15 +1154,6 @@ dependencies = [
|
|||
"serde_with",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d00328cedcac5e81c683e5620ca6a30756fc23027ebf9bff405c0e8da1fbb7e"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
|
@ -1279,17 +1224,6 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glsl-to-spirv"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28caebc98746d507603a2d3df66dcbe04e41d4febad0320f3eec1ef72b6bbef1"
|
||||
dependencies = [
|
||||
"cmake",
|
||||
"sha2",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "goblin"
|
||||
version = "0.6.1"
|
||||
|
@ -1889,6 +1823,26 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "naga"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1ceaaa4eedaece7e4ec08c55c640ba03dbb73fb812a6570a59bcf1930d0f70e"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"bitflags 2.3.3",
|
||||
"codespan-reporting",
|
||||
"hexf-parse",
|
||||
"indexmap 1.9.3",
|
||||
"log",
|
||||
"num-traits",
|
||||
"rustc-hash",
|
||||
"spirv",
|
||||
"termcolor",
|
||||
"thiserror",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nanorand"
|
||||
version = "0.7.0"
|
||||
|
@ -2772,18 +2726,6 @@ dependencies = [
|
|||
"syn 2.0.26",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"byte-tools",
|
||||
"digest",
|
||||
"fake-simd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.1.0"
|
||||
|
@ -2898,19 +2840,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"fastrand",
|
||||
"redox_syscall",
|
||||
"rustix 0.38.4",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.2.0"
|
||||
|
@ -3044,12 +2973,6 @@ version = "0.19.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "ultraviolet"
|
||||
version = "0.9.1"
|
||||
|
@ -3341,7 +3264,7 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
"js-sys",
|
||||
"log",
|
||||
"naga",
|
||||
"naga 0.11.1",
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
|
@ -3367,7 +3290,7 @@ dependencies = [
|
|||
"codespan-reporting",
|
||||
"fxhash",
|
||||
"log",
|
||||
"naga",
|
||||
"naga 0.11.1",
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
|
@ -3405,7 +3328,7 @@ dependencies = [
|
|||
"libloading 0.7.4",
|
||||
"log",
|
||||
"metal 0.24.0",
|
||||
"naga",
|
||||
"naga 0.11.1",
|
||||
"objc",
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
|
|
|
@ -6,12 +6,7 @@ edition = "2021"
|
|||
[features]
|
||||
default = ["vulkan"]
|
||||
pixels = ["dep:pixels", "dep:bytemuck"]
|
||||
vulkan = [
|
||||
"dep:ash",
|
||||
"dep:ash-window",
|
||||
"dep:raw-window-handle",
|
||||
"dep:glsl-to-spirv",
|
||||
]
|
||||
vulkan = ["dep:ash", "dep:ash-window", "dep:raw-window-handle", "dep:naga"]
|
||||
camera = ["dep:nokhwa", "dep:send_wrapper"]
|
||||
|
||||
[dependencies]
|
||||
|
@ -36,4 +31,4 @@ ash-window = { git = "https://github.com/ash-rs/ash", optional = true }
|
|||
raw-window-handle = { version = "0.5", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
glsl-to-spirv = { version = "0.1.7", optional = true }
|
||||
naga = { version = "0.13", optional = true, features = ["wgsl-in", "spv-out"] }
|
||||
|
|
44
gb-emu/build.rs
Normal file
44
gb-emu/build.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders";
|
||||
const SHADER_OUT_DIR: &str = "shaders";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg(feature = "vulkan")]
|
||||
{
|
||||
println!("cargo:rerun-if-changed={}", SHADER_SRC_DIR);
|
||||
std::fs::create_dir_all(SHADER_OUT_DIR)?;
|
||||
|
||||
for shader in std::fs::read_dir(SHADER_SRC_DIR)?.filter_map(|v| v.ok()) {
|
||||
if shader.file_type()?.is_file() {
|
||||
let in_path = shader.path();
|
||||
if in_path
|
||||
.extension()
|
||||
.is_some_and(|e| e.to_string_lossy() == "wgsl")
|
||||
{
|
||||
let out_path = format!(
|
||||
"{}/{}.spv",
|
||||
SHADER_OUT_DIR,
|
||||
in_path.file_stem().unwrap().to_string_lossy()
|
||||
);
|
||||
let module = naga::front::wgsl::parse_str(&std::fs::read_to_string(in_path)?)?;
|
||||
|
||||
let info = naga::valid::Validator::new(Default::default(), Default::default())
|
||||
.validate(&module)?;
|
||||
|
||||
let spv =
|
||||
naga::back::spv::write_vec(&module, &info, &Default::default(), None)?;
|
||||
|
||||
let compiled =
|
||||
spv.iter()
|
||||
.fold(Vec::with_capacity(spv.len() * 4), |mut v, w| {
|
||||
v.extend_from_slice(&w.to_le_bytes());
|
||||
v
|
||||
});
|
||||
|
||||
std::fs::write(out_path, compiled.as_slice())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
26
gb-emu/src/renderer/vulkan/shaders/shader.wgsl
Normal file
26
gb-emu/src/renderer/vulkan/shaders/shader.wgsl
Normal file
|
@ -0,0 +1,26 @@
|
|||
struct VsOutput {
|
||||
@location(0) tex_coord_out: vec2<f32>,
|
||||
@builtin(position) position: vec4<f32>,
|
||||
}
|
||||
|
||||
struct Locals {
|
||||
transform: mat4x4<f32>,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_main(
|
||||
@location(0) position: vec2<f32>,
|
||||
) -> VsOutput {
|
||||
var out: VsOutput;
|
||||
out.tex_coord_out = fma(position, vec2<f32>(0.5, -0.5), vec2<f32>(0.5, 0.5));
|
||||
out.position = vec4<f32>(position, 0.0, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var tex: texture_2d<f32>;
|
||||
@group(0) @binding(1) var tex_sampler: sampler;
|
||||
|
||||
@fragment
|
||||
fn fs_main(@location(0) coord: vec2<f32>) -> @location(0) vec4<f32> {
|
||||
return textureSample(tex, tex_sampler, coord);
|
||||
}
|
|
@ -10,6 +10,8 @@ use winit::window::Window;
|
|||
// https://github.com/ash-rs/ash/blob/master/examples/src/lib.rs
|
||||
// https://github.com/ash-rs/ash/blob/master/examples/src/bin/texture.rs
|
||||
|
||||
const SHADER: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/shader.spv"));
|
||||
|
||||
pub struct WindowData {
|
||||
scale_factor: u32,
|
||||
|
||||
|
@ -420,7 +422,6 @@ pub fn record_submit_commandbuffer<F: FnOnce(&Device, vk::CommandBuffer)>(
|
|||
signal_semaphores: &[vk::Semaphore],
|
||||
f: F,
|
||||
) {
|
||||
|
||||
unsafe {
|
||||
device
|
||||
.wait_for_fences(&[command_buffer_reuse_fence], true, std::u64::MAX)
|
||||
|
|
Loading…
Reference in a new issue