#[cfg(any(feature = "serde", test))]
use serde::{Deserialize, Serialize};
use crate::{link_to_wgpu_docs, link_to_wgpu_item};
#[cfg(doc)]
use crate::Features;
#[doc = link_to_wgpu_docs!(["`RenderPass::draw`"]: "struct.RenderPass.html#method.draw")]
#[doc = link_to_wgpu_item!(struct VertexBufferLayout)]
#[doc = link_to_wgpu_docs!(["`step_mode`"]: "struct.VertexBufferLayout.html#structfield.step_mode")]
#[doc = link_to_wgpu_docs!(["`attributes`"]: "struct.VertexBufferLayout.html#structfield.attributes")]
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum VertexStepMode {
#[default]
Vertex = 0,
Instance = 1,
}
#[doc = link_to_wgpu_docs!(["`vertex_attr_array!`"]: "macro.vertex_attr_array.html")]
#[doc = link_to_wgpu_item!(struct VertexBufferLayout)]
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct VertexAttribute {
pub format: VertexFormat,
pub offset: crate::BufferAddress,
pub shader_location: crate::ShaderLocation,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", 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(feature = "serde", serde(rename = "unorm10-10-10-2"))]
Unorm10_10_10_2 = 43,
#[cfg_attr(feature = "serde", 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!(),
}
}
}