#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
pub mod glsl;
pub mod hlsl;
pub mod msl;
pub mod spv;
#[cfg(not(docsrs))]
#[macro_export]
macro_rules! link_to_wgpu_docs {
([$reference:expr]: $url_path:expr) => {
concat!("[", $reference, "]: ../wgpu/", $url_path)
};
(../ [$reference:expr]: $url_path:expr) => {
concat!("[", $reference, "]: ../../wgpu/", $url_path)
};
}
#[cfg(docsrs)]
#[macro_export]
macro_rules! link_to_wgpu_docs {
($(../)? [$reference:expr]: $url_path:expr) => {
concat!(
"[",
$reference,
"]: /wgpu/",
env!("CARGO_PKG_VERSION_MAJOR"),
"/wgpu/",
$url_path
)
};
}
#[macro_export]
macro_rules! link_to_wgpu_item {
($kind:ident $name:ident) => {
$crate::link_to_wgpu_docs!(
[concat!("`", stringify!($name), "`")]: concat!(stringify!($kind), ".", stringify!($name), ".html")
)
};
}
#[cfg(not(docsrs))]
#[macro_export]
macro_rules! link_to_wgc_docs {
([$reference:expr]: $url_path:expr) => {
concat!("[", $reference, "]: ../wgpu_core/", $url_path)
};
(../ [$reference:expr]: $url_path:expr) => {
concat!("[", $reference, "]: ../../wgpu_core/", $url_path)
};
}
#[cfg(docsrs)]
#[macro_export]
macro_rules! link_to_wgc_docs {
($(../)? [$reference:expr]: $url_path:expr) => {
concat!(
"[",
$reference,
"]: /wgpu_core/",
env!("CARGO_PKG_VERSION_MAJOR"),
"/wgpu_core/",
$url_path
)
};
}
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum ShaderStage {
Vertex,
Task,
Mesh,
Fragment,
Compute,
RayGeneration,
Miss,
AnyHit,
ClosestHit,
}
impl ShaderStage {
pub const fn compute_like(self) -> bool {
match self {
Self::Vertex | Self::Fragment => false,
Self::Compute | Self::Task | Self::Mesh => true,
Self::RayGeneration | Self::AnyHit | Self::ClosestHit | Self::Miss => false,
}
}
pub const fn mesh_like(self) -> bool {
matches!(self, Self::Task | Self::Mesh)
}
}
pub type FastHashMap<K, T> =
hashbrown::HashMap<K, T, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
pub type FastHashSet<K> =
hashbrown::HashSet<K, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
pub type FastIndexSet<K> =
indexmap::IndexSet<K, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
pub type FastIndexMap<K, V> =
indexmap::IndexMap<K, V, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct ResourceBinding {
pub group: u32,
pub binding: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct TaskDispatchLimits {
pub max_mesh_workgroups_per_dim: u32,
pub max_mesh_workgroups_total: u32,
}
#[repr(u32)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg_attr(
any(feature = "serialize", feature = "deserialize"),
serde(rename_all = "lowercase")
)]
pub enum VertexFormat {
Uint8 = 0,
Uint8x2 = 1,
Uint8x4 = 2,
Sint8 = 3,
Sint8x2 = 4,
Sint8x4 = 5,
Unorm8 = 6,
Unorm8x2 = 7,
Unorm8x4 = 8,
Snorm8 = 9,
Snorm8x2 = 10,
Snorm8x4 = 11,
Uint16 = 12,
Uint16x2 = 13,
Uint16x4 = 14,
Sint16 = 15,
Sint16x2 = 16,
Sint16x4 = 17,
Unorm16 = 18,
Unorm16x2 = 19,
Unorm16x4 = 20,
Snorm16 = 21,
Snorm16x2 = 22,
Snorm16x4 = 23,
Float16 = 24,
Float16x2 = 25,
Float16x4 = 26,
Float32 = 27,
Float32x2 = 28,
Float32x3 = 29,
Float32x4 = 30,
Uint32 = 31,
Uint32x2 = 32,
Uint32x3 = 33,
Uint32x4 = 34,
Sint32 = 35,
Sint32x2 = 36,
Sint32x3 = 37,
Sint32x4 = 38,
Float64 = 39,
Float64x2 = 40,
Float64x3 = 41,
Float64x4 = 42,
#[cfg_attr(
any(feature = "serialize", feature = "deserialize"),
serde(rename = "unorm10-10-10-2")
)]
Unorm10_10_10_2 = 43,
#[cfg_attr(
any(feature = "serialize", feature = "deserialize"),
serde(rename = "unorm8x4-bgra")
)]
Unorm8x4Bgra = 44,
}
impl VertexFormat {
#[must_use]
pub const fn size(&self) -> u64 {
match self {
Self::Uint8 | Self::Sint8 | Self::Unorm8 | Self::Snorm8 => 1,
Self::Uint8x2
| Self::Sint8x2
| Self::Unorm8x2
| Self::Snorm8x2
| Self::Uint16
| Self::Sint16
| Self::Unorm16
| Self::Snorm16
| Self::Float16 => 2,
Self::Uint8x4
| Self::Sint8x4
| Self::Unorm8x4
| Self::Snorm8x4
| Self::Uint16x2
| Self::Sint16x2
| Self::Unorm16x2
| Self::Snorm16x2
| Self::Float16x2
| Self::Float32
| Self::Uint32
| Self::Sint32
| Self::Unorm10_10_10_2
| Self::Unorm8x4Bgra => 4,
Self::Uint16x4
| Self::Sint16x4
| Self::Unorm16x4
| Self::Snorm16x4
| Self::Float16x4
| Self::Float32x2
| Self::Uint32x2
| Self::Sint32x2
| Self::Float64 => 8,
Self::Float32x3 | Self::Uint32x3 | Self::Sint32x3 => 12,
Self::Float32x4 | Self::Uint32x4 | Self::Sint32x4 | Self::Float64x2 => 16,
Self::Float64x3 => 24,
Self::Float64x4 => 32,
}
}
#[must_use]
pub const fn min_acceleration_structure_vertex_stride(&self) -> u64 {
match self {
Self::Float16x2 | Self::Snorm16x2 => 4,
Self::Float32x3 => 12,
Self::Float32x2 => 8,
Self::Float16x4 | Self::Snorm16x4 => 6,
_ => unreachable!(),
}
}
#[must_use]
pub const fn acceleration_structure_stride_alignment(&self) -> u64 {
match self {
Self::Float16x4 | Self::Float16x2 | Self::Snorm16x4 | Self::Snorm16x2 => 2,
Self::Float32x2 | Self::Float32x3 => 4,
_ => unreachable!(),
}
}
}