diff --git a/Cargo.lock b/Cargo.lock index 58ad005..3f6a7b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,7 +1688,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_codegen_spirv" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" dependencies = [ "ahash", "ar", @@ -1718,7 +1718,7 @@ dependencies = [ [[package]] name = "rustc_codegen_spirv-types" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" dependencies = [ "rspirv", "serde", @@ -2005,7 +2005,7 @@ dependencies = [ [[package]] name = "spirv-builder" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" dependencies = [ "memchr", "raw-string", @@ -2018,7 +2018,7 @@ dependencies = [ [[package]] name = "spirv-std" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" dependencies = [ "bitflags 1.3.2", "glam", @@ -2030,7 +2030,7 @@ dependencies = [ [[package]] name = "spirv-std-macros" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" dependencies = [ "proc-macro2", "quote", @@ -2041,7 +2041,7 @@ dependencies = [ [[package]] name = "spirv-std-types" version = "0.9.0" -source = "git+https://github.com/Rust-GPU/rust-gpu?rev=ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834#ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68#0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" [[package]] name = "spirv-tools" diff --git a/Cargo.toml b/Cargo.toml index a40f280..6683f46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,8 @@ spirv-builder.workspace = true members = ["shaders", "shared"] [workspace.dependencies] -spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834", default-features = false } -spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "ac0c7035d53ae0bf87fbff12cc8ad4e6f6628834" } +spirv-builder = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68", default-features = false } +spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "0b37696e9f5edde8fa0c1363a88e6c8cb8e6ff68" } # Compile build-dependencies in release mode with # the same settings as regular dependencies. diff --git a/shaders/src/filtering_procedurals.rs b/shaders/src/filtering_procedurals.rs index 103f7f0..f278391 100644 --- a/shaders/src/filtering_procedurals.rs +++ b/shaders/src/filtering_procedurals.rs @@ -19,6 +19,7 @@ //! */ //! ``` +use spirv_std::arch::Derivative; use shared::*; use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; @@ -400,8 +401,8 @@ impl Inputs { uvw = tex_coords(pos); // calc texture sampling footprint - ddx_uvw = uvw + uvw.ddx(); - ddy_uvw = uvw + uvw.ddy(); + ddx_uvw = uvw + uvw.dfdx(); + ddy_uvw = uvw + uvw.dfdy(); } // shading let mate: Vec3; diff --git a/shaders/src/skyline.rs b/shaders/src/skyline.rs index c756de0..bb0c5ad 100644 --- a/shaders/src/skyline.rs +++ b/shaders/src/skyline.rs @@ -11,6 +11,7 @@ //! */ //! ``` +use spirv_std::arch::Derivative; use crate::SampleCube; use shared::*; use spirv_std::glam::{vec2, vec3, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; @@ -770,8 +771,8 @@ impl State { let mut window_ref: f32 = 0.0; // texture map the sides of buildings if (normal.y < 0.1) && (dist_and_mat.y == 0.0) { - let posdx: Vec3 = pos.ddx(); - let posdy: Vec3 = pos.ddy(); + let posdx: Vec3 = pos.dfdx(); + let posdy: Vec3 = pos.dfdy(); let _pos_grad: Vec3 = posdx * hash21(uv) + posdy * hash21(uv * 7.6543); // Quincunx antialias the building texture and normal map. @@ -930,7 +931,7 @@ impl State { if dist_and_mat.y >= 100.0 { let mut yfade: f32 = 0.01_f32.max(1.0_f32.min(ref_.y * 100.0)); // low-res way of making lines at the edges of car windows. Not sure I like it. - yfade *= saturate(1.0 - (window_mask.ddx() * window_mask.ddy()).abs() * 250.995); + yfade *= saturate(1.0 - (window_mask.dfdx() * window_mask.dfdy()).abs() * 250.995); final_color += self.get_env_map_skyline(ref_, self.sun_dir, pos.y - 1.5) * 0.3 * yfade diff --git a/shared/src/lib.rs b/shared/src/lib.rs index 7e270a1..06bcf84 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -6,7 +6,7 @@ use bytemuck::{Pod, Zeroable}; use core::f32::consts::PI; use core::ops::{Add, Mul, Sub}; -use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec3A, Vec4}; +use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec4}; // 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. @@ -350,107 +350,6 @@ impl VecExt for Vec4 { } } -pub trait Derivative { - fn ddx(self) -> Self; - fn ddx_fine(self) -> Self; - fn ddx_coarse(self) -> Self; - fn ddy(self) -> Self; - fn ddy_fine(self) -> Self; - fn ddy_coarse(self) -> Self; - fn fwidth(self) -> Self; - fn fwidth_fine(self) -> Self; - fn fwidth_coarse(self) -> Self; -} - -#[cfg(target_arch = "spirv")] -macro_rules! deriv_caps { - (true) => { - core::arch::asm!("OpCapability DerivativeControl") - }; - (false) => {}; -} - -macro_rules! deriv_fn { - ($name:ident, $inst:ident, $needs_caps:tt) => { - fn $name(self) -> Self { - #[cfg(not(target_arch = "spirv"))] - panic!(concat!(stringify!($name), " is not supported on the CPU")); - #[cfg(target_arch = "spirv")] - unsafe { - let mut result = Default::default(); - deriv_caps!($needs_caps); - core::arch::asm!( - "%input = OpLoad typeof*{1} {1}", - concat!("%result = ", stringify!($inst), " typeof*{1} %input"), - "OpStore {0} %result", - in(reg) &mut result, - in(reg) &self, - ); - result - } - } - }; -} -macro_rules! deriv_impl { - ($ty:ty) => { - impl Derivative for $ty { - deriv_fn!(ddx, OpDPdx, false); - deriv_fn!(ddx_fine, OpDPdxFine, true); - deriv_fn!(ddx_coarse, OpDPdxCoarse, true); - deriv_fn!(ddy, OpDPdy, false); - deriv_fn!(ddy_fine, OpDPdyFine, true); - deriv_fn!(ddy_coarse, OpDPdyCoarse, true); - deriv_fn!(fwidth, OpFwidth, false); - deriv_fn!(fwidth_fine, OpFwidthFine, true); - deriv_fn!(fwidth_coarse, OpFwidthCoarse, true); - } - }; -} - -// "must be a scalar or vector of floating-point type. The component width must be 32 bits." -deriv_impl!(f32); -deriv_impl!(Vec2); -deriv_impl!(Vec3A); -deriv_impl!(Vec4); - -impl Derivative for Vec3 { - fn ddx(self) -> Self { - Vec3A::from(self).ddx().into() - } - fn ddx_fine(self) -> Self { - Vec3A::from(self).ddx_fine().into() - } - fn ddx_coarse(self) -> Self { - Vec3A::from(self).ddx_coarse().into() - } - fn ddy(self) -> Self { - Vec3A::from(self).ddy().into() - } - fn ddy_fine(self) -> Self { - Vec3A::from(self).ddy_fine().into() - } - fn ddy_coarse(self) -> Self { - Vec3A::from(self).ddy_coarse().into() - } - fn fwidth(self) -> Self { - Vec3A::from(self).fwidth().into() - } - fn fwidth_fine(self) -> Self { - Vec3A::from(self).fwidth_fine().into() - } - fn fwidth_coarse(self) -> Self { - Vec3A::from(self).fwidth_coarse().into() - } -} - pub fn discard() { - #[cfg(target_arch = "spirv")] - unsafe { - use core::arch::asm; - asm!( - "OpExtension \"SPV_EXT_demote_to_helper_invocation\"", - "OpCapability DemoteToHelperInvocationEXT", - "OpDemoteToHelperInvocationEXT" - ); - } + unsafe { spirv_std::arch::demote_to_helper_invocation() } }