|
6 | 6 | use bytemuck::{Pod, Zeroable}; |
7 | 7 | use core::f32::consts::PI; |
8 | 8 | use core::ops::{Add, Mul, Sub}; |
9 | | -use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec3A, Vec4}; |
| 9 | +use spirv_std::glam::{vec2, vec3, vec4, Vec2, Vec3, Vec4}; |
10 | 10 |
|
11 | 11 | // Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but |
12 | 12 | // we tie #[no_std] above to the same condition, so it's fine. |
@@ -350,99 +350,6 @@ impl VecExt for Vec4 { |
350 | 350 | } |
351 | 351 | } |
352 | 352 |
|
353 | | -pub trait Derivative { |
354 | | - fn ddx(self) -> Self; |
355 | | - fn ddx_fine(self) -> Self; |
356 | | - fn ddx_coarse(self) -> Self; |
357 | | - fn ddy(self) -> Self; |
358 | | - fn ddy_fine(self) -> Self; |
359 | | - fn ddy_coarse(self) -> Self; |
360 | | - fn fwidth(self) -> Self; |
361 | | - fn fwidth_fine(self) -> Self; |
362 | | - fn fwidth_coarse(self) -> Self; |
363 | | -} |
364 | | - |
365 | | -#[cfg(target_arch = "spirv")] |
366 | | -macro_rules! deriv_caps { |
367 | | - (true) => { |
368 | | - core::arch::asm!("OpCapability DerivativeControl") |
369 | | - }; |
370 | | - (false) => {}; |
371 | | -} |
372 | | - |
373 | | -macro_rules! deriv_fn { |
374 | | - ($name:ident, $inst:ident, $needs_caps:tt) => { |
375 | | - fn $name(self) -> Self { |
376 | | - #[cfg(not(target_arch = "spirv"))] |
377 | | - panic!(concat!(stringify!($name), " is not supported on the CPU")); |
378 | | - #[cfg(target_arch = "spirv")] |
379 | | - unsafe { |
380 | | - let mut result = Default::default(); |
381 | | - deriv_caps!($needs_caps); |
382 | | - core::arch::asm!( |
383 | | - "%input = OpLoad typeof*{1} {1}", |
384 | | - concat!("%result = ", stringify!($inst), " typeof*{1} %input"), |
385 | | - "OpStore {0} %result", |
386 | | - in(reg) &mut result, |
387 | | - in(reg) &self, |
388 | | - ); |
389 | | - result |
390 | | - } |
391 | | - } |
392 | | - }; |
393 | | -} |
394 | | -macro_rules! deriv_impl { |
395 | | - ($ty:ty) => { |
396 | | - impl Derivative for $ty { |
397 | | - deriv_fn!(ddx, OpDPdx, false); |
398 | | - deriv_fn!(ddx_fine, OpDPdxFine, true); |
399 | | - deriv_fn!(ddx_coarse, OpDPdxCoarse, true); |
400 | | - deriv_fn!(ddy, OpDPdy, false); |
401 | | - deriv_fn!(ddy_fine, OpDPdyFine, true); |
402 | | - deriv_fn!(ddy_coarse, OpDPdyCoarse, true); |
403 | | - deriv_fn!(fwidth, OpFwidth, false); |
404 | | - deriv_fn!(fwidth_fine, OpFwidthFine, true); |
405 | | - deriv_fn!(fwidth_coarse, OpFwidthCoarse, true); |
406 | | - } |
407 | | - }; |
408 | | -} |
409 | | - |
410 | | -// "must be a scalar or vector of floating-point type. The component width must be 32 bits." |
411 | | -deriv_impl!(f32); |
412 | | -deriv_impl!(Vec2); |
413 | | -deriv_impl!(Vec3A); |
414 | | -deriv_impl!(Vec4); |
415 | | - |
416 | | -impl Derivative for Vec3 { |
417 | | - fn ddx(self) -> Self { |
418 | | - Vec3A::from(self).ddx().into() |
419 | | - } |
420 | | - fn ddx_fine(self) -> Self { |
421 | | - Vec3A::from(self).ddx_fine().into() |
422 | | - } |
423 | | - fn ddx_coarse(self) -> Self { |
424 | | - Vec3A::from(self).ddx_coarse().into() |
425 | | - } |
426 | | - fn ddy(self) -> Self { |
427 | | - Vec3A::from(self).ddy().into() |
428 | | - } |
429 | | - fn ddy_fine(self) -> Self { |
430 | | - Vec3A::from(self).ddy_fine().into() |
431 | | - } |
432 | | - fn ddy_coarse(self) -> Self { |
433 | | - Vec3A::from(self).ddy_coarse().into() |
434 | | - } |
435 | | - fn fwidth(self) -> Self { |
436 | | - Vec3A::from(self).fwidth().into() |
437 | | - } |
438 | | - fn fwidth_fine(self) -> Self { |
439 | | - Vec3A::from(self).fwidth_fine().into() |
440 | | - } |
441 | | - fn fwidth_coarse(self) -> Self { |
442 | | - Vec3A::from(self).fwidth_coarse().into() |
443 | | - } |
444 | | -} |
445 | | - |
446 | 353 | pub fn discard() { |
447 | 354 | unsafe { spirv_std::arch::demote_to_helper_invocation() } |
448 | 355 | } |
0 commit comments