diff --git a/Cargo.lock b/Cargo.lock index 4ff2e2f..e1edb02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1644,7 +1644,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_codegen_spirv" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" dependencies = [ "ahash", "ar", @@ -1674,7 +1674,7 @@ dependencies = [ [[package]] name = "rustc_codegen_spirv-types" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" dependencies = [ "rspirv", "serde", @@ -1961,7 +1961,7 @@ dependencies = [ [[package]] name = "spirv-builder" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" dependencies = [ "memchr", "raw-string", @@ -1974,7 +1974,7 @@ dependencies = [ [[package]] name = "spirv-std" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" dependencies = [ "bitflags 1.3.2", "glam", @@ -1986,7 +1986,7 @@ dependencies = [ [[package]] name = "spirv-std-macros" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" dependencies = [ "proc-macro2", "quote", @@ -1997,7 +1997,7 @@ dependencies = [ [[package]] name = "spirv-std-types" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=6e2c84d4fe64e32df4c060c5a7f3e35a32e45421#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=3417d2487f0b0066764ca74bbec2556e12c7d4fb#3417d2487f0b0066764ca74bbec2556e12c7d4fb" [[package]] name = "spirv-tools" diff --git a/Cargo.toml b/Cargo.toml index 634b2eb..2dee183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,12 +25,12 @@ ouroboros = "0.18.5" spirv-builder = { version = "*", default-features = false } [workspace] -members = ["shaders"] +members = ["shaders", "shared"] [patch.crates-io] #spirv-builder = { path = "../rust-gpu/crates/spirv-builder" } -spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" } -spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" } +spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "3417d2487f0b0066764ca74bbec2556e12c7d4fb" } +spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "3417d2487f0b0066764ca74bbec2556e12c7d4fb" } # Compile build-dependencies in release mode with diff --git a/shaders/Cargo.toml b/shaders/Cargo.toml index 69bfbc9..604f100 100644 --- a/shaders/Cargo.toml +++ b/shaders/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" crate-type = ["dylib"] [dependencies] -spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" } +spirv-std = { version = "*" } shared = { path = "../shared" } [lints] diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 31c3338..886d4d0 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -5,7 +5,7 @@ authors = [] edition = "2021" [dependencies] -spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" } +spirv-std = { version = "*" } bytemuck = { version = "1.20.0", features = ["derive"] } [lints] diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 256e938..7e270a1 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -8,8 +8,6 @@ use core::f32::consts::PI; use core::ops::{Add, Mul, Sub}; use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec3A, Vec4}; -#[cfg(target_arch = "spirv")] -use spirv_std::spirv; // Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but // we tie #[no_std] above to the same condition, so it's fine. #[cfg(target_arch = "spirv")] diff --git a/src/main.rs b/src/main.rs index 57c727b..5c0dd38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,9 @@ use futures::executor::block_on; use ouroboros::self_referencing; -use std::borrow::Cow; use std::error::Error; use std::time::Instant; use wgpu; +use wgpu::{include_spirv, include_spirv_raw}; use winit::application::ApplicationHandler; use winit::dpi::LogicalSize; use winit::event::{ElementState, MouseButton, WindowEvent}; @@ -62,6 +62,8 @@ impl Default for ShaderToyApp { } } +pub const USE_SPIRV_PASSTHROUGH: bool = true; + impl ShaderToyApp { async fn init(&mut self, event_loop: &dyn ActiveEventLoop) -> Result<(), Box> { let window_attributes = WindowAttributes::default() @@ -91,7 +93,10 @@ impl ShaderToyApp { }) .await .ok_or("No adapter found")?; - let required_features = wgpu::Features::PUSH_CONSTANTS; + let mut required_features = wgpu::Features::PUSH_CONSTANTS; + if USE_SPIRV_PASSTHROUGH { + required_features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH; + } let required_limits = wgpu::Limits { max_push_constant_size: 256, ..Default::default() @@ -107,12 +112,14 @@ impl ShaderToyApp { None, ) .await?; - let shader_bytes = include_bytes!(env!("shadertoys_shaders.spv")); - let shader_spirv: &[u32] = bytemuck::cast_slice(shader_bytes); - let shader_module = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: Some("Shader Module"), - source: wgpu::ShaderSource::SpirV(Cow::Borrowed(shader_spirv)), - }); + let shader_module = if USE_SPIRV_PASSTHROUGH { + unsafe { + device + .create_shader_module_spirv(&include_spirv_raw!(env!("shadertoys_shaders.spv"))) + } + } else { + device.create_shader_module(include_spirv!(env!("shadertoys_shaders.spv"))) + }; let swapchain_format = surface.get_capabilities(&adapter).formats[0]; let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: None,