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