Something went wrong. Try again.
modern vulkan rust rhi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377//! Plain-data vocabulary (handles, enums, flags, constants, descs).//! ZII: zero values are reasonable defaults throughout.
use core::ffi::c_void;
use bitflags::bitflags;
// Handles
macro_rules! handle { ($name:ident) => { #[repr(transparent)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct $name(pub *mut c_void);
impl Default for $name { fn default() -> Self { Self(core::ptr::null_mut()) } } };}
handle!(TextureHandle);handle!(CommandBuffer);handle!(Semaphore);handle!(Shader);
/// Device creation parameters. ZII: `GpuDesc::default()` is a working/// configuration.#[derive(Debug, Clone, Copy, Default)]pub struct GpuDesc { /// Enable VK_LAYER_KHRONOS_validation (with sync validation) and the /// crate's own recording-time asserts. pub validation: bool, /// Bindless heap capacities, slot 0 included. 0 = default /// (4096 sampled, 1024 storage, 64 samplers). pub sampled_heap_cap: u32, pub storage_heap_cap: u32, pub sampler_heap_cap: u32,}
// Enums
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum Memory { /// Host-visible, device-local when available (ReBAR). CPU-writable. /// CAUTION: without resizable BAR the device-local+host-visible heap /// is ~256 MiB; past its budget VMA falls back to SYSTEM RAM and GPU /// reads cross PCIe (measured 6–19× pass slowdowns at 4K). Anything /// screen-sized the CPU never touches belongs in `Gpu`. #[default] Default, /// Device-local only. `Ptr::cpu` is null. Gpu, /// Host-cached readback memory. Readback,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum Queue { #[default] Main, Compute, Transfer,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum TextureType { #[default] D2, D3,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum TextureFormat { #[default] Default, Rgba8Unorm, Bgra8Unorm, Rgba8Srgb, D32Float, Rgba16Float, Rgba32Float, R8Unorm, R32Uint, R16Float, R32Float, Rg16Float,}
bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct UsageFlags: u32 { const SAMPLED = 1 << 0; const STORAGE = 1 << 1; const TRANSFER_SRC = 1 << 2; const TRANSFER_DST = 1 << 3; const COLOR_ATTACHMENT = 1 << 4; const DEPTH_STENCIL_ATTACHMENT = 1 << 5; }}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum ShaderTypeGraphics { #[default] Vertex, Fragment,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum LoadOp { #[default] Clear, Load, DontCare,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum StoreOp { #[default] Store, DontCare,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum CompareOp { #[default] Never, Less, Equal, LessEqual, Greater, NotEqual, GreaterEqual, Always,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum BlendOp { #[default] Add, Subtract, RevSubtract, Min, Max,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum BlendFactor { #[default] Zero, One, SrcColor, DstColor, OneMinusSrcColor, SrcAlpha, OneMinusSrcAlpha, OneMinusDstAlpha, DstAlpha,}
bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct DepthFlags: u32 { const READ = 1 << 0; const WRITE = 1 << 1; }}
bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct HazardFlags: u32 { const DRAW_ARGUMENTS = 1 << 0; const DESCRIPTORS = 1 << 1; const DEPTH_STENCIL = 1 << 2; const SHADER_IMAGE = 1 << 3; const SHADER_BUFFER = 1 << 4; const COLOR_ATTACHMENT = 1 << 5; }}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum Stage { #[default] Transfer, Compute, /// Indirect argument fetch for draws and dispatches 2014 the consumer /// side of `HazardFlags::DRAW_ARGUMENTS`. DrawIndirect, RasterColorOut, FragmentShader, VertexShader, EarlyFragmentTests, LateFragmentTests, All,}
bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct ColorComponentFlags: u8 { const R = 1 << 0; const G = 1 << 1; const B = 1 << 2; const A = 1 << 3; }}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum Filter { #[default] Linear, Nearest,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum AddressMode { #[default] Repeat, MirroredRepeat, ClampToEdge,}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]pub enum CullMode { /// Front faces are counter-clockwise, engine-wide. #[default] Back, Front, None,}
// Structs
#[derive(Debug, Clone, Copy, Default)]pub struct BlitRect { // offset_a == offset_b == 0 selects the full mip level. pub offset_a: [i32; 3], pub offset_b: [i32; 3], pub mip_level: u32, pub base_layer: u32, pub layer_count: u32,}
#[derive(Debug, Clone, Copy, Default)]pub struct TextureDesc { pub ty: TextureType, pub dimensions: [u32; 3], pub mip_count: u32, // 0 = 1 pub layer_count: u32, // 0 = 1 pub sample_count: u32, // 0 = 1 pub format: TextureFormat, pub usage: UsageFlags,}
#[derive(Debug, Clone, Copy, Default)]pub struct SamplerDesc { pub min_filter: Filter, pub mag_filter: Filter, pub mip_filter: Filter, pub address_mode_u: AddressMode, pub address_mode_v: AddressMode, pub address_mode_w: AddressMode, pub mip_lod_bias: f32, pub min_lod: f32, pub max_lod: f32, // 0.0 = use all lods pub max_anisotropy: f32,}
/// A subresource window onto a texture. Zero means "the natural default"/// for where the view is used: sampled views take every mip from/// `base_mip`; storage views and render attachments take exactly one/// (shader writes and rendering target a single level). Layers default/// to one; the view types on offer are non-array.#[derive(Debug, Clone, Copy, Default)]pub struct TextureViewDesc { pub ty: TextureType, pub format: TextureFormat, // Default = inherits the texture's format pub base_mip: u32, pub mip_count: u32, pub base_layer: u32, pub layer_count: u32,}
#[derive(Debug, Clone, Copy, Default)]pub struct RenderAttachment { pub texture: Texture, pub view: TextureViewDesc, pub load_op: LoadOp, pub store_op: StoreOp, /// Depth attachments clear to `clear_color[0]` (reverse-Z: 0.0 = far). pub clear_color: [f32; 4],}
/// At least one attachment (color or depth) is required. The render area/// defaults to the first attachment's mip extent; the layer count comes/// from the attachments' views.#[derive(Debug, Clone, Copy, Default)]pub struct RenderPassDesc<'a> { pub render_area_offset: [i32; 2], pub render_area_size: [u32; 2], // 0 = the first attachment's mip size pub color_attachments: &'a [RenderAttachment], pub depth_attachment: Option<RenderAttachment>,}
#[derive(Debug, Clone, Copy, Default)]pub struct Texture { pub dimensions: [u32; 3], pub format: TextureFormat, pub mip_count: u32, pub layer_count: u32, pub handle: TextureHandle,}
impl Texture { /// Extent of mip `level` (each axis halves, floor, min 1). pub fn mip_dimensions(&self, level: u32) -> [u32; 3] { self.dimensions.map(|d| (d >> level).max(1)) }}
#[derive(Debug, Clone, Copy, Default)]pub struct DepthState { pub mode: DepthFlags, pub compare: CompareOp, pub bias_enable: bool, pub bias_constant: f32, // Constant depth offset. pub bias_slope: f32, // Slope-scaled depth bias factor. pub bias_clamp: f32, // Maximum absolute bias value.}
#[derive(Debug, Clone, Copy, Default)]pub struct BlendState { pub enable: bool, pub color_op: BlendOp, pub src_color_factor: BlendFactor, pub dst_color_factor: BlendFactor, pub alpha_op: BlendOp, pub src_alpha_factor: BlendFactor, pub dst_alpha_factor: BlendFactor, pub color_write_mask: ColorComponentFlags,}
#[repr(C)]#[derive(Debug, Clone, Copy, Default)]pub struct DrawIndexedIndirectCommand { pub index_count: u32, pub instance_count: u32, pub first_index: u32, pub vertex_offset: i32, pub first_instance: u32,}
#[repr(C)]#[derive(Debug, Clone, Copy, Default)]pub struct DrawIndirectCommand { pub vertex_count: u32, pub instance_count: u32, pub first_vertex: u32, pub first_instance: u32,}
#[repr(C)]#[derive(Debug, Clone, Copy, Default)]pub struct DispatchIndirectCommand { pub num_groups_x: u32, pub num_groups_y: u32, pub num_groups_z: u32,}
#[derive(Debug, Clone, Copy, Default)]pub struct DeviceLimits { pub max_anisotropy: f32, /// Nanoseconds per GPU timestamp tick (for the profiler). pub timestamp_period: f32,}