-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
353bb96
commit 8732b84
Showing
8 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//! SPIR-V Instrinics | ||
//! | ||
//! This module is intended as a low level abstraction over SPIR-V instructions. | ||
//! These functions will typically map to a single instruction, and will perform | ||
//! no additional safety checks beyond type-checking. | ||
use crate::{scalar::Scalar, vector::Vector}; | ||
|
||
/// Extract a single, dynamically selected, component of a vector. | ||
/// | ||
/// # Safety | ||
/// Behavior is undefined if `index`’s value is greater than or equal to the | ||
/// number of components in `vector`. | ||
#[spirv_std_macros::gpu_only] | ||
#[doc(alias = "OpVectorExtractDynamic")] | ||
#[inline] | ||
pub unsafe fn vector_extract_dynamic<T: Scalar, V: Vector<T>>(vector: V, index: usize) -> T { | ||
let mut result = T::default(); | ||
|
||
asm! { | ||
"%vector = OpLoad _ {vector}", | ||
"%element = OpVectorExtractDynamic _ %vector {index}", | ||
"OpStore {element} %element", | ||
vector = in(reg) &vector, | ||
index = in(reg) index, | ||
element = in(reg) &mut result | ||
} | ||
|
||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// Abstract trait representing a SPIR-V scalar type. | ||
pub trait Scalar: Copy + Default + crate::sealed::Sealed {} | ||
|
||
impl Scalar for bool {} | ||
impl Scalar for f32 {} | ||
impl Scalar for u32 {} | ||
impl Scalar for i32 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// A marker trait used to prevent other traits from being implemented outside | ||
/// of `spirv-std`. | ||
pub trait Sealed {} | ||
|
||
impl Sealed for bool {} | ||
impl Sealed for f32 {} | ||
impl Sealed for u32 {} | ||
impl Sealed for i32 {} | ||
impl Sealed for glam::BVec2 {} | ||
impl Sealed for glam::BVec3 {} | ||
impl Sealed for glam::BVec4 {} | ||
impl Sealed for glam::Vec2 {} | ||
impl Sealed for glam::Vec3 {} | ||
impl Sealed for glam::Vec3A {} | ||
impl Sealed for glam::Vec4 {} | ||
impl Sealed for glam::UVec2 {} | ||
impl Sealed for glam::UVec3 {} | ||
impl Sealed for glam::UVec4 {} | ||
impl Sealed for glam::IVec2 {} | ||
impl Sealed for glam::IVec3 {} | ||
impl Sealed for glam::IVec4 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// Abstract trait representing a SPIR-V vector type. | ||
pub trait Vector<T: crate::scalar::Scalar>: crate::sealed::Sealed {} | ||
|
||
impl Vector<bool> for glam::BVec2 {} | ||
impl Vector<bool> for glam::BVec3 {} | ||
impl Vector<bool> for glam::BVec4 {} | ||
impl Vector<f32> for glam::Vec2 {} | ||
impl Vector<f32> for glam::Vec3 {} | ||
impl Vector<f32> for glam::Vec3A {} | ||
impl Vector<f32> for glam::Vec4 {} | ||
impl Vector<u32> for glam::UVec2 {} | ||
impl Vector<u32> for glam::UVec3 {} | ||
impl Vector<u32> for glam::UVec4 {} | ||
impl Vector<i32> for glam::IVec2 {} | ||
impl Vector<i32> for glam::IVec3 {} | ||
impl Vector<i32> for glam::IVec4 {} |