spirv_cross_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5//! Raw bindings to the C API of SPIRV-Cross.
6//!
7//! Incorrect use of `_init` functions can cause undefined behaviour.
8//!
9//! Always go through `MaybeUninit` for anything that sets an enum,
10//! then check for `i32::MAX`.
11//!
12//! `spvc_rs` functions are unstable and are meant for consumption by [spirv-cross2](https://crates.io/crates/spirv-cross2)
13//! only.
14
15mod bindings;
16
17// Because SPIRV-Cross's C API is C89, we don't have stdint,
18// but the C++ API uses sized int types.
19//
20// Since it always links to sized int types, it is safe to
21// define it as fixed sized rather than wobbly. Particularly,
22// a SPIR-V word is `uint32_t`, so it is nice to deal with `u32`
23// rather than c_uint.
24//
25// On esoteric systems, we don't expect SPIRV-Cross to be usable
26// anyways.
27mod ctypes {
28    pub type spvc_bool = bool;
29    pub type c_char = std::os::raw::c_char;
30
31    pub type c_void = ::std::os::raw::c_void;
32    pub type c_uint = u32;
33    pub type c_schar = i8;
34    pub type c_uchar = u8;
35    pub type c_short = i16;
36    pub type c_ushort = u16;
37    pub type c_int = i32;
38    pub type c_longlong = i64;
39    pub type c_ulonglong = u64;
40}
41
42pub use bindings::*;
43pub use bytemuck::{Pod, Zeroable};
44pub use num_traits::{FromPrimitive, ToPrimitive};
45
46unsafe impl Zeroable for SpvId {}
47unsafe impl Pod for SpvId {}
48
49impl From<u32> for SpvId {
50    fn from(value: u32) -> Self {
51        Self(value)
52    }
53}
54
55impl Default for MslConstexprSampler {
56    fn default() -> Self {
57        // https://github.com/KhronosGroup/SPIRV-Cross/blob/6a1fb66eef1bdca14acf7d0a51a3f883499d79f0/spirv_msl.hpp#L216
58        MslConstexprSampler {
59            coord: MslSamplerCoord::Normalized,
60            min_filter: MslSamplerFilter::Nearest,
61            mag_filter: MslSamplerFilter::Nearest,
62            mip_filter: MslSamplerMipFilter::None,
63            s_address: MslSamplerAddress::ClampToEdge,
64            t_address: MslSamplerAddress::ClampToEdge,
65            r_address: MslSamplerAddress::ClampToEdge,
66            compare_func: MslSamplerCompareFunc::Never,
67            border_color: MslSamplerBorderColor::TransparentBlack,
68            lod_clamp_min: 0.0,
69            lod_clamp_max: 1000.0,
70            max_anisotropy: 1,
71            compare_enable: false,
72            lod_clamp_enable: false,
73            anisotropy_enable: false,
74        }
75    }
76}
77
78impl Default for MslSamplerYcbcrConversion {
79    fn default() -> Self {
80        // https://github.com/KhronosGroup/SPIRV-Cross/blob/6a1fb66eef1bdca14acf7d0a51a3f883499d79f0/spirv_msl.hpp#L230
81        MslSamplerYcbcrConversion {
82            planes: 0,
83            resolution: MslFormatResolution::FormatResolution444,
84            chroma_filter: MslSamplerFilter::Nearest,
85            x_chroma_offset: MslChromaLocation::CositedEven,
86            y_chroma_offset: MslChromaLocation::CositedEven,
87            swizzle: [
88                MslComponentSwizzle::Identity,
89                MslComponentSwizzle::Identity,
90                MslComponentSwizzle::Identity,
91                MslComponentSwizzle::Identity,
92            ],
93            ycbcr_model: MslSamplerYcbcrModelConversion::RgbIdentity,
94            ycbcr_range: MslSamplerYcbcrRange::ItuFull,
95            bpc: 8,
96        }
97    }
98}
99
100macro_rules! from_u32 {
101    ($($id:ty)*) => {
102        $(impl From<u32> for $id {
103            fn from(value: u32) -> Self {
104                Self(From::from(value))
105            }
106         })*
107    };
108}
109
110from_u32! {
111    TypeId VariableId ConstantId
112}