Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
23 changes: 15 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<dyn Error>> {
let window_attributes = WindowAttributes::default()
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down