Skip to main content

skia_safe/gpu/
vk.rs

1use std::{ops::Deref, ptr};
2
3use skia_bindings as sb;
4
5pub mod vulkan_backend_context;
6mod vulkan_backend_context_builder;
7mod vulkan_mutable_texture_state;
8mod vulkan_types;
9
10pub use super::ganesh::vk::vk_types::*;
11pub use vulkan_backend_context::*;
12pub use vulkan_mutable_texture_state::*;
13pub use vulkan_types::*;
14
15pub use crate::gpu::ganesh::vk::BackendDrawableInfo;
16
17//
18// Additional Vulkan re-exports and definitions.
19//
20
21pub use sb::VkBool32 as Bool32;
22pub use sb::VkBuffer as Buffer;
23pub use sb::VkChromaLocation as ChromaLocation;
24pub use sb::VkCommandBuffer as CommandBuffer;
25pub use sb::VkComponentMapping as ComponentMapping;
26pub use sb::VkComponentSwizzle as ComponentSwizzle;
27pub use sb::VkDevice as Device;
28pub use sb::VkDeviceMemory as DeviceMemory;
29pub use sb::VkDeviceSize as DeviceSize;
30pub use sb::VkExtent2D as Extent2D;
31pub use sb::VkFilter as Filter;
32pub use sb::VkFlags as Flags;
33pub use sb::VkFormat as Format;
34pub use sb::VkFormatFeatureFlags as FormatFeatureFlags;
35pub use sb::VkImage as Image;
36pub use sb::VkImageLayout as ImageLayout;
37pub use sb::VkImageTiling as ImageTiling;
38pub use sb::VkImageUsageFlags as ImageUsageFlags;
39pub use sb::VkInstance as Instance;
40pub use sb::VkOffset2D as Offset2D;
41pub use sb::VkPhysicalDevice as PhysicalDevice;
42pub use sb::VkPhysicalDeviceFeatures as PhysicalDeviceFeatures;
43pub use sb::VkPhysicalDeviceFeatures2 as PhysicalDeviceFeatures2;
44pub use sb::VkQueue as Queue;
45pub use sb::VkRect2D as Rect2D;
46pub use sb::VkRenderPass as RenderPass;
47pub use sb::VkSamplerYcbcrModelConversion as SamplerYcbcrModelConversion;
48pub use sb::VkSamplerYcbcrRange as SamplerYcbcrRange;
49pub use sb::VkSharingMode as SharingMode;
50
51pub const QUEUE_FAMILY_IGNORED: u32 = !0;
52
53//
54// VK_NULL_HANDLE and conversions.
55//
56
57#[derive(Debug)]
58pub struct NullHandle;
59pub const NULL_HANDLE: NullHandle = NullHandle;
60
61#[cfg(target_pointer_width = "64")]
62impl From<NullHandle> for Buffer {
63    fn from(_: NullHandle) -> Self {
64        ptr::null_mut()
65    }
66}
67
68impl From<NullHandle> for CommandBuffer {
69    fn from(_: NullHandle) -> Self {
70        ptr::null_mut()
71    }
72}
73
74impl From<NullHandle> for Device {
75    fn from(_: NullHandle) -> Self {
76        ptr::null_mut()
77    }
78}
79
80#[cfg(target_pointer_width = "64")]
81impl From<NullHandle> for DeviceMemory {
82    fn from(_: NullHandle) -> Self {
83        ptr::null_mut()
84    }
85}
86
87impl From<NullHandle> for Instance {
88    fn from(_: NullHandle) -> Self {
89        ptr::null_mut()
90    }
91}
92
93impl From<NullHandle> for PhysicalDevice {
94    fn from(_: NullHandle) -> Self {
95        ptr::null_mut()
96    }
97}
98
99#[cfg(target_pointer_width = "64")]
100impl From<NullHandle> for Image {
101    fn from(_: NullHandle) -> Self {
102        ptr::null_mut()
103    }
104}
105
106impl From<NullHandle> for Queue {
107    fn from(_: NullHandle) -> Self {
108        ptr::null_mut()
109    }
110}
111
112#[cfg(target_pointer_width = "64")]
113impl From<NullHandle> for RenderPass {
114    fn from(_: NullHandle) -> Self {
115        ptr::null_mut()
116    }
117}
118
119#[cfg(not(target_pointer_width = "64"))]
120impl From<NullHandle> for u64 {
121    fn from(_: NullHandle) -> Self {
122        0
123    }
124}
125
126#[repr(transparent)]
127#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
128pub struct Version(u32);
129
130impl Version {
131    pub fn new(major: usize, minor: usize, patch: usize) -> Self {
132        ((((major & 0x3ff) << 22) | ((minor & 0x3ff) << 12) | (patch & 0xfff)) as u32).into()
133    }
134
135    pub fn major(&self) -> usize {
136        (self.deref() >> 22) as _
137    }
138
139    pub fn minor(&self) -> usize {
140        ((self.deref() >> 12) & 0x3ff) as _
141    }
142
143    pub fn patch(&self) -> usize {
144        ((self.deref()) & 0xfff) as _
145    }
146}
147
148impl From<u32> for Version {
149    fn from(v: u32) -> Self {
150        Self(v)
151    }
152}
153
154impl From<(usize, usize, usize)> for Version {
155    fn from((major, minor, patch): (usize, usize, usize)) -> Self {
156        Self::new(major, minor, patch)
157    }
158}
159
160impl Deref for Version {
161    type Target = u32;
162    fn deref(&self) -> &Self::Target {
163        &self.0
164    }
165}