1use skia_bindings::{
2 self as sb, skgpu_VulkanAlloc, skgpu_VulkanBackendMemory, skgpu_VulkanYcbcrConversionInfo,
3};
4
5use crate::{gpu::vk, prelude::*};
6
7#[deprecated(since = "0.76.0", note = "Use BackendMemory")]
8pub type GraphicsBackendMemory = skgpu_VulkanBackendMemory;
9pub type BackendMemory = skgpu_VulkanBackendMemory;
10
11#[repr(C)]
12#[derive(Copy, Clone, Debug)]
13pub struct Alloc {
14 pub memory: vk::DeviceMemory,
15 pub offset: vk::DeviceSize,
16 pub size: vk::DeviceSize,
17 pub flags: AllocFlag,
18 pub backend_memory: BackendMemory,
19 uses_system_heap: bool,
20}
21unsafe_send_sync!(Alloc);
22
23native_transmutable!(skgpu_VulkanAlloc, Alloc);
24
25impl Default for Alloc {
26 fn default() -> Self {
27 Self {
28 memory: vk::NULL_HANDLE.into(),
29 offset: 0,
30 size: 0,
31 flags: AllocFlag::empty(),
32 backend_memory: 0,
33 uses_system_heap: false,
34 }
35 }
36}
37
38impl PartialEq for Alloc {
39 fn eq(&self, other: &Self) -> bool {
40 unsafe { sb::C_VulkanAlloc_Equals(self.native(), other.native()) }
41 }
42}
43
44bitflags! {
45 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
46 pub struct AllocFlag : u32 {
47 const NONCOHERENT = sb::skgpu_VulkanAlloc_Flag::kNoncoherent_Flag as _;
48 const MAPPABLE = sb::skgpu_VulkanAlloc_Flag::kMappable_Flag as _;
49 const LAZILY_ALLOCATED = sb::skgpu_VulkanAlloc_Flag::kLazilyAllocated_Flag as _;
50 }
51}
52
53impl Alloc {
54 pub unsafe fn from_device_memory(
57 memory: vk::DeviceMemory,
58 offset: vk::DeviceSize,
59 size: vk::DeviceSize,
60 flags: AllocFlag,
61 ) -> Alloc {
62 Alloc {
63 memory,
64 offset,
65 size,
66 flags,
67 backend_memory: 0,
68 uses_system_heap: false,
69 }
70 }
71}
72
73#[derive(Copy, Clone, Eq, Debug)]
74#[repr(C)]
75pub struct YcbcrConversionInfo {
76 pub format: vk::Format,
77 pub external_format: u64,
78 pub ycbcr_model: vk::SamplerYcbcrModelConversion,
79 pub ycbcr_range: vk::SamplerYcbcrRange,
80 pub x_chroma_offset: vk::ChromaLocation,
81 pub y_chroma_offset: vk::ChromaLocation,
82 pub chroma_filter: vk::Filter,
83 pub force_explicit_reconstruction: vk::Bool32,
84 pub components: vk::ComponentMapping,
85 pub format_features: vk::FormatFeatureFlags,
86
87 sampler_filter_must_match_chroma_filter: bool,
88 supports_linear_filter: bool,
89}
90
91native_transmutable!(skgpu_VulkanYcbcrConversionInfo, YcbcrConversionInfo);
92
93impl PartialEq for YcbcrConversionInfo {
94 fn eq(&self, other: &Self) -> bool {
95 unsafe { sb::C_VulkanYcbcrConversionInfo_Equals(self.native(), other.native()) }
96 }
97}
98
99impl Default for YcbcrConversionInfo {
100 fn default() -> Self {
101 Self {
102 format: vk::Format::UNDEFINED,
103 external_format: 0,
104 ycbcr_model: vk::SamplerYcbcrModelConversion::RGB_IDENTITY,
105 ycbcr_range: vk::SamplerYcbcrRange::ITU_FULL,
106 x_chroma_offset: vk::ChromaLocation::COSITED_EVEN,
107 y_chroma_offset: vk::ChromaLocation::COSITED_EVEN,
108 chroma_filter: vk::Filter::NEAREST,
109 force_explicit_reconstruction: 0,
110 components: vk::ComponentMapping {
111 r: vk::ComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY,
112 g: vk::ComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY,
113 b: vk::ComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY,
114 a: vk::ComponentSwizzle::VK_COMPONENT_SWIZZLE_IDENTITY,
115 },
116 format_features: 0,
117 sampler_filter_must_match_chroma_filter: true,
118 supports_linear_filter: false,
119 }
120 }
121}
122
123impl YcbcrConversionInfo {
124 #[allow(clippy::too_many_arguments)]
125 pub fn new_with_external_format(
126 external_format: u64,
127 ycbcr_model: vk::SamplerYcbcrModelConversion,
128 ycbcr_range: vk::SamplerYcbcrRange,
129 x_chroma_offset: vk::ChromaLocation,
130 y_chroma_offset: vk::ChromaLocation,
131 chroma_filter: vk::Filter,
132 force_explicit_reconstruction: vk::Bool32,
133 components: vk::ComponentMapping,
134 external_format_features: vk::FormatFeatureFlags,
135 ) -> Self {
136 Self::construct(|ci| unsafe {
137 sb::C_VulkanYcbcrConversionInfo_Construct_ExternalFormat(
138 ci,
139 external_format,
140 ycbcr_model,
141 ycbcr_range,
142 x_chroma_offset,
143 y_chroma_offset,
144 chroma_filter,
145 force_explicit_reconstruction,
146 components,
147 external_format_features,
148 )
149 })
150 }
151
152 #[allow(clippy::too_many_arguments)]
153 pub fn new_with_format(
154 format: vk::Format,
155 ycbcr_model: vk::SamplerYcbcrModelConversion,
156 ycbcr_range: vk::SamplerYcbcrRange,
157 x_chroma_offset: vk::ChromaLocation,
158 y_chroma_offset: vk::ChromaLocation,
159 chroma_filter: vk::Filter,
160 force_explicit_reconstruction: vk::Bool32,
161 components: vk::ComponentMapping,
162 format_features: vk::FormatFeatureFlags,
163 ) -> Self {
164 Self::construct(|ci| unsafe {
165 sb::C_VulkanYcbcrConversionInfo_Construct_Format(
166 ci,
167 format,
168 ycbcr_model,
169 ycbcr_range,
170 x_chroma_offset,
171 y_chroma_offset,
172 chroma_filter,
173 force_explicit_reconstruction,
174 components,
175 format_features,
176 )
177 })
178 }
179 pub fn is_valid(&self) -> bool {
180 self.ycbcr_model != vk::SamplerYcbcrModelConversion::RGB_IDENTITY
181 || self.has_external_format()
182 }
183
184 pub fn format(&self) -> vk::Format {
185 self.format
186 }
187
188 pub fn has_external_format(&self) -> bool {
189 self.external_format != 0
190 }
191
192 pub fn external_format(&self) -> u64 {
193 self.external_format
194 }
195
196 pub fn model(&self) -> vk::SamplerYcbcrModelConversion {
197 self.ycbcr_model
198 }
199
200 pub fn range(&self) -> vk::SamplerYcbcrRange {
201 self.ycbcr_range
202 }
203
204 pub fn x_chroma_offset(&self) -> vk::ChromaLocation {
205 self.x_chroma_offset
206 }
207
208 pub fn y_chroma_offset(&self) -> vk::ChromaLocation {
209 self.y_chroma_offset
210 }
211
212 pub fn chroma_filter(&self) -> vk::Filter {
213 self.chroma_filter
214 }
215
216 pub fn force_explicit_reconstruction(&self) -> vk::Bool32 {
217 self.force_explicit_reconstruction
218 }
219
220 pub fn components(&self) -> vk::ComponentMapping {
221 self.components
222 }
223
224 pub fn supports_linear_filter(&self) -> bool {
225 self.supports_linear_filter
226 }
227}