| 1 |
// Copyright 2017 GFX developers |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or |
| 4 |
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
| 5 |
// http://opensource.org/licenses/MIT>, at your option. This file may not be |
| 6 |
// copied, modified, or distributed except according to those terms. |
| 7 |
|
| 8 |
use super::*; |
| 9 |
|
| 10 |
use block::Block; |
| 11 |
use log::warn; |
| 12 |
use objc::runtime::{NO, YES}; |
| 13 |
|
| 14 |
use std::{ |
| 15 |
ffi::{c_char, CStr}, |
| 16 |
path::Path, |
| 17 |
ptr, |
| 18 |
}; |
| 19 |
|
| 20 |
/// Available on macOS 10.11+, iOS 8.0+, tvOS 9.0+ |
| 21 |
/// |
| 22 |
/// See <https://developer.apple.com/documentation/metal/mtlfeatureset> |
| 23 |
#[allow(non_camel_case_types)] |
| 24 |
#[deprecated( |
| 25 |
note = "Since iOS 8.0–16.0 iPadOS 8.0–16.0 macOS 10.11–13.0 Mac Catalyst 13.1–16.0 tvOS 9.0–16.0" |
| 26 |
)] |
| 27 |
#[repr(u64)] |
| 28 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 29 |
pub enum MTLFeatureSet { |
| 30 |
iOS_GPUFamily1_v1 = 0, |
| 31 |
iOS_GPUFamily2_v1 = 1, |
| 32 |
iOS_GPUFamily1_v2 = 2, |
| 33 |
iOS_GPUFamily2_v2 = 3, |
| 34 |
iOS_GPUFamily3_v1 = 4, |
| 35 |
iOS_GPUFamily1_v3 = 5, |
| 36 |
iOS_GPUFamily2_v3 = 6, |
| 37 |
iOS_GPUFamily3_v2 = 7, |
| 38 |
iOS_GPUFamily1_v4 = 8, |
| 39 |
iOS_GPUFamily2_v4 = 9, |
| 40 |
iOS_GPUFamily3_v3 = 10, |
| 41 |
iOS_GPUFamily4_v1 = 11, |
| 42 |
iOS_GPUFamily1_v5 = 12, |
| 43 |
iOS_GPUFamily2_v5 = 13, |
| 44 |
iOS_GPUFamily3_v4 = 14, |
| 45 |
iOS_GPUFamily4_v2 = 15, |
| 46 |
iOS_GPUFamily5_v1 = 16, |
| 47 |
|
| 48 |
tvOS_GPUFamily1_v1 = 30000, |
| 49 |
tvOS_GPUFamily1_v2 = 30001, |
| 50 |
tvOS_GPUFamily1_v3 = 30002, |
| 51 |
tvOS_GPUFamily2_v1 = 30003, |
| 52 |
tvOS_GPUFamily1_v4 = 30004, |
| 53 |
tvOS_GPUFamily2_v2 = 30005, |
| 54 |
|
| 55 |
macOS_GPUFamily1_v1 = 10000, |
| 56 |
macOS_GPUFamily1_v2 = 10001, |
| 57 |
// Available on macOS 10.12+ |
| 58 |
macOS_ReadWriteTextureTier2 = 10002, |
| 59 |
macOS_GPUFamily1_v3 = 10003, |
| 60 |
macOS_GPUFamily1_v4 = 10004, |
| 61 |
macOS_GPUFamily2_v1 = 10005, |
| 62 |
} |
| 63 |
|
| 64 |
/// Available on macOS 10.15+, iOS 13.0+ |
| 65 |
/// |
| 66 |
/// See <https://developer.apple.com/documentation/metal/mtlgpufamily> |
| 67 |
#[repr(i64)] |
| 68 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 69 |
#[non_exhaustive] |
| 70 |
pub enum MTLGPUFamily { |
| 71 |
Common1 = 3001, |
| 72 |
Common2 = 3002, |
| 73 |
Common3 = 3003, |
| 74 |
Apple1 = 1001, |
| 75 |
Apple2 = 1002, |
| 76 |
Apple3 = 1003, |
| 77 |
Apple4 = 1004, |
| 78 |
Apple5 = 1005, |
| 79 |
Apple6 = 1006, |
| 80 |
Apple7 = 1007, |
| 81 |
Apple8 = 1008, |
| 82 |
Apple9 = 1009, |
| 83 |
Mac1 = 2001, |
| 84 |
Mac2 = 2002, |
| 85 |
MacCatalyst1 = 4001, |
| 86 |
MacCatalyst2 = 4002, |
| 87 |
Metal3 = 5001, |
| 88 |
} |
| 89 |
|
| 90 |
/// See <https://developer.apple.com/documentation/metal/mtldevicelocation> |
| 91 |
#[repr(u64)] |
| 92 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 93 |
pub enum MTLDeviceLocation { |
| 94 |
BuiltIn = 0, |
| 95 |
Slot = 1, |
| 96 |
External = 2, |
| 97 |
Unspecified = u64::MAX, |
| 98 |
} |
| 99 |
|
| 100 |
bitflags::bitflags! { |
| 101 |
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 102 |
pub struct PixelFormatCapabilities: u32 { |
| 103 |
const Filter = 1 << 0; |
| 104 |
const Write = 1 << 1; |
| 105 |
const Color = 1 << 2; |
| 106 |
const Blend = 1 << 3; |
| 107 |
const Msaa = 1 << 4; |
| 108 |
const Resolve = 1 << 5; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
#[allow(non_camel_case_types)] |
| 113 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 114 |
enum Os { |
| 115 |
iOS, |
| 116 |
tvOS, |
| 117 |
macOS, |
| 118 |
} |
| 119 |
|
| 120 |
const KB: u32 = 1024; |
| 121 |
const MB: u32 = 1024 * KB; |
| 122 |
const GB: u32 = 1024 * MB; |
| 123 |
|
| 124 |
impl MTLFeatureSet { |
| 125 |
fn os(&self) -> Os { |
| 126 |
let value = *self as u64; |
| 127 |
if value < 10_000 { |
| 128 |
Os::iOS |
| 129 |
} else if value < 20_000 { |
| 130 |
Os::macOS |
| 131 |
} else if value >= 30_000 || value < 40_000 { |
| 132 |
Os::tvOS |
| 133 |
} else { |
| 134 |
unreachable!() |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
// returns the minor version on macos |
| 139 |
fn os_version(&self) -> u32 { |
| 140 |
use MTLFeatureSet::*; |
| 141 |
match self { |
| 142 |
iOS_GPUFamily1_v1 | iOS_GPUFamily2_v1 => 8, |
| 143 |
iOS_GPUFamily1_v2 | iOS_GPUFamily2_v2 | iOS_GPUFamily3_v1 => 9, |
| 144 |
iOS_GPUFamily1_v3 | iOS_GPUFamily2_v3 | iOS_GPUFamily3_v2 => 10, |
| 145 |
iOS_GPUFamily1_v4 | iOS_GPUFamily2_v4 | iOS_GPUFamily3_v3 | iOS_GPUFamily4_v1 => 11, |
| 146 |
iOS_GPUFamily1_v5 | iOS_GPUFamily2_v5 | iOS_GPUFamily3_v4 | iOS_GPUFamily4_v2 |
| 147 |
| iOS_GPUFamily5_v1 => 12, |
| 148 |
tvOS_GPUFamily1_v1 => 9, |
| 149 |
tvOS_GPUFamily1_v2 => 10, |
| 150 |
tvOS_GPUFamily1_v3 | tvOS_GPUFamily2_v1 => 11, |
| 151 |
tvOS_GPUFamily1_v4 | tvOS_GPUFamily2_v2 => 12, |
| 152 |
macOS_GPUFamily1_v1 => 11, |
| 153 |
macOS_GPUFamily1_v2 | macOS_ReadWriteTextureTier2 => 12, |
| 154 |
macOS_GPUFamily1_v3 => 13, |
| 155 |
macOS_GPUFamily1_v4 | macOS_GPUFamily2_v1 => 14, |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
fn gpu_family(&self) -> u32 { |
| 160 |
use MTLFeatureSet::*; |
| 161 |
match self { |
| 162 |
iOS_GPUFamily1_v1 |
| 163 |
| iOS_GPUFamily1_v2 |
| 164 |
| iOS_GPUFamily1_v3 |
| 165 |
| iOS_GPUFamily1_v4 |
| 166 |
| iOS_GPUFamily1_v5 |
| 167 |
| tvOS_GPUFamily1_v1 |
| 168 |
| tvOS_GPUFamily1_v2 |
| 169 |
| tvOS_GPUFamily1_v3 |
| 170 |
| tvOS_GPUFamily1_v4 |
| 171 |
| macOS_GPUFamily1_v1 |
| 172 |
| macOS_GPUFamily1_v2 |
| 173 |
| macOS_ReadWriteTextureTier2 |
| 174 |
| macOS_GPUFamily1_v3 |
| 175 |
| macOS_GPUFamily1_v4 => 1, |
| 176 |
iOS_GPUFamily2_v1 | iOS_GPUFamily2_v2 | iOS_GPUFamily2_v3 | iOS_GPUFamily2_v4 |
| 177 |
| iOS_GPUFamily2_v5 | tvOS_GPUFamily2_v1 | tvOS_GPUFamily2_v2 | macOS_GPUFamily2_v1 => { |
| 178 |
2 |
| 179 |
} |
| 180 |
iOS_GPUFamily3_v1 | iOS_GPUFamily3_v2 | iOS_GPUFamily3_v3 | iOS_GPUFamily3_v4 => 3, |
| 181 |
iOS_GPUFamily4_v1 | iOS_GPUFamily4_v2 => 4, |
| 182 |
iOS_GPUFamily5_v1 => 5, |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
fn version(&self) -> u32 { |
| 187 |
use MTLFeatureSet::*; |
| 188 |
match self { |
| 189 |
iOS_GPUFamily1_v1 |
| 190 |
| iOS_GPUFamily2_v1 |
| 191 |
| iOS_GPUFamily3_v1 |
| 192 |
| iOS_GPUFamily4_v1 |
| 193 |
| iOS_GPUFamily5_v1 |
| 194 |
| macOS_GPUFamily1_v1 |
| 195 |
| macOS_GPUFamily2_v1 |
| 196 |
| macOS_ReadWriteTextureTier2 |
| 197 |
| tvOS_GPUFamily1_v1 |
| 198 |
| tvOS_GPUFamily2_v1 => 1, |
| 199 |
iOS_GPUFamily1_v2 | iOS_GPUFamily2_v2 | iOS_GPUFamily3_v2 | iOS_GPUFamily4_v2 |
| 200 |
| macOS_GPUFamily1_v2 | tvOS_GPUFamily1_v2 | tvOS_GPUFamily2_v2 => 2, |
| 201 |
iOS_GPUFamily1_v3 | iOS_GPUFamily2_v3 | iOS_GPUFamily3_v3 | macOS_GPUFamily1_v3 |
| 202 |
| tvOS_GPUFamily1_v3 => 3, |
| 203 |
iOS_GPUFamily1_v4 | iOS_GPUFamily2_v4 | iOS_GPUFamily3_v4 | tvOS_GPUFamily1_v4 |
| 204 |
| macOS_GPUFamily1_v4 => 4, |
| 205 |
iOS_GPUFamily1_v5 | iOS_GPUFamily2_v5 => 5, |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
pub fn supports_metal_kit(&self) -> bool { |
| 210 |
true |
| 211 |
} |
| 212 |
|
| 213 |
pub fn supports_metal_performance_shaders(&self) -> bool { |
| 214 |
match self.os() { |
| 215 |
Os::iOS => self.gpu_family() >= 2, |
| 216 |
Os::tvOS => true, |
| 217 |
Os::macOS => self.os_version() >= 13, |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
pub fn supports_programmable_blending(&self) -> bool { |
| 222 |
self.os() != Os::macOS |
| 223 |
} |
| 224 |
|
| 225 |
pub fn supports_pvrtc_pixel_formats(&self) -> bool { |
| 226 |
self.os() != Os::macOS |
| 227 |
} |
| 228 |
|
| 229 |
pub fn supports_eac_etc_pixel_formats(&self) -> bool { |
| 230 |
self.os() != Os::macOS |
| 231 |
} |
| 232 |
|
| 233 |
pub fn supports_astc_pixel_formats(&self) -> bool { |
| 234 |
match self.os() { |
| 235 |
Os::iOS => self.gpu_family() >= 2, |
| 236 |
Os::tvOS => true, |
| 237 |
Os::macOS => false, |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
pub fn supports_linear_textures(&self) -> bool { |
| 242 |
self.os() != Os::macOS || self.os_version() >= 13 |
| 243 |
} |
| 244 |
|
| 245 |
pub fn supports_bc_pixel_formats(&self) -> bool { |
| 246 |
self.os() == Os::macOS |
| 247 |
} |
| 248 |
|
| 249 |
pub fn supports_msaa_depth_resolve(&self) -> bool { |
| 250 |
match self.os() { |
| 251 |
Os::iOS => self.gpu_family() >= 3, |
| 252 |
Os::tvOS => self.gpu_family() >= 2, |
| 253 |
Os::macOS => false, |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
pub fn supports_counting_occlusion_query(&self) -> bool { |
| 258 |
match self.os() { |
| 259 |
Os::iOS => self.gpu_family() >= 3, |
| 260 |
Os::tvOS => self.gpu_family() >= 2, |
| 261 |
Os::macOS => true, |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
pub fn supports_base_vertex_instance_drawing(&self) -> bool { |
| 266 |
match self.os() { |
| 267 |
Os::iOS => self.gpu_family() >= 3, |
| 268 |
Os::tvOS => self.gpu_family() >= 2, |
| 269 |
Os::macOS => true, |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
pub fn supports_indirect_buffers(&self) -> bool { |
| 274 |
match self.os() { |
| 275 |
Os::iOS => self.gpu_family() >= 3, |
| 276 |
Os::tvOS => self.gpu_family() >= 2, |
| 277 |
Os::macOS => true, |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
pub fn supports_cube_map_texture_arrays(&self) -> bool { |
| 282 |
match self.os() { |
| 283 |
Os::iOS => self.gpu_family() >= 4, |
| 284 |
Os::tvOS => false, |
| 285 |
Os::macOS => true, |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
pub fn supports_texture_barriers(&self) -> bool { |
| 290 |
self.os() == Os::macOS |
| 291 |
} |
| 292 |
|
| 293 |
pub fn supports_layered_rendering(&self) -> bool { |
| 294 |
match self.os() { |
| 295 |
Os::iOS => self.gpu_family() >= 5, |
| 296 |
Os::tvOS => false, |
| 297 |
Os::macOS => true, |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
pub fn supports_tessellation(&self) -> bool { |
| 302 |
match self.os() { |
| 303 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 10, |
| 304 |
Os::tvOS => self.gpu_family() >= 2, |
| 305 |
Os::macOS => self.os_version() >= 12, |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
pub fn supports_resource_heaps(&self) -> bool { |
| 310 |
match self.os() { |
| 311 |
Os::iOS => self.os_version() >= 10, |
| 312 |
Os::tvOS => self.os_version() >= 10, |
| 313 |
Os::macOS => self.os_version() >= 13, |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
pub fn supports_memoryless_render_targets(&self) -> bool { |
| 318 |
match self.os() { |
| 319 |
Os::iOS => self.os_version() >= 10, |
| 320 |
Os::tvOS => self.os_version() >= 10, |
| 321 |
Os::macOS => false, |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
pub fn supports_function_specialization(&self) -> bool { |
| 326 |
match self.os() { |
| 327 |
Os::iOS => self.os_version() >= 10, |
| 328 |
Os::tvOS => self.os_version() >= 10, |
| 329 |
Os::macOS => self.os_version() >= 12, |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
pub fn supports_function_buffer_read_writes(&self) -> bool { |
| 334 |
match self.os() { |
| 335 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 10, |
| 336 |
Os::tvOS => self.gpu_family() >= 2, |
| 337 |
Os::macOS => self.os_version() >= 12, |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
pub fn supports_function_texture_read_writes(&self) -> bool { |
| 342 |
match self.os() { |
| 343 |
Os::iOS => self.gpu_family() >= 4, |
| 344 |
Os::tvOS => false, |
| 345 |
Os::macOS => self.os_version() >= 12, |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
pub fn supports_array_of_textures(&self) -> bool { |
| 350 |
match self.os() { |
| 351 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 10, |
| 352 |
Os::tvOS => self.gpu_family() >= 2, |
| 353 |
Os::macOS => self.os_version() >= 13, |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
pub fn supports_array_of_samplers(&self) -> bool { |
| 358 |
match self.os() { |
| 359 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 11, |
| 360 |
Os::tvOS => self.gpu_family() >= 2, |
| 361 |
Os::macOS => self.os_version() >= 12, |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
pub fn supports_stencil_texture_views(&self) -> bool { |
| 366 |
match self.os() { |
| 367 |
Os::iOS => self.os_version() >= 10, |
| 368 |
Os::tvOS => self.os_version() >= 10, |
| 369 |
Os::macOS => self.os_version() >= 12, |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
pub fn supports_depth_16_pixel_format(&self) -> bool { |
| 374 |
self.os() == Os::macOS && self.os_version() >= 12 |
| 375 |
} |
| 376 |
|
| 377 |
pub fn supports_extended_range_pixel_formats(&self) -> bool { |
| 378 |
match self.os() { |
| 379 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 10, |
| 380 |
Os::tvOS => self.gpu_family() >= 2, |
| 381 |
Os::macOS => false, |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
pub fn supports_wide_color_pixel_format(&self) -> bool { |
| 386 |
match self.os() { |
| 387 |
Os::iOS => self.os_version() >= 11, |
| 388 |
Os::tvOS => self.os_version() >= 11, |
| 389 |
Os::macOS => self.os_version() >= 13, |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
pub fn supports_combined_msaa_store_and_resolve_action(&self) -> bool { |
| 394 |
match self.os() { |
| 395 |
Os::iOS => self.gpu_family() >= 3 && self.os_version() >= 10, |
| 396 |
Os::tvOS => self.gpu_family() >= 2, |
| 397 |
Os::macOS => self.os_version() >= 12, |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
pub fn supports_deferred_store_action(&self) -> bool { |
| 402 |
match self.os() { |
| 403 |
Os::iOS => self.os_version() >= 10, |
| 404 |
Os::tvOS => self.os_version() >= 10, |
| 405 |
Os::macOS => self.os_version() >= 12, |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
pub fn supports_msaa_blits(&self) -> bool { |
| 410 |
match self.os() { |
| 411 |
Os::iOS => self.os_version() >= 10, |
| 412 |
Os::tvOS => self.os_version() >= 10, |
| 413 |
Os::macOS => true, |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
pub fn supports_srgb_writes(&self) -> bool { |
| 418 |
match self.os() { |
| 419 |
Os::iOS => self.gpu_family() >= 3 || (self.gpu_family() >= 2 && self.version() >= 3), |
| 420 |
Os::tvOS => self.os_version() >= 10, |
| 421 |
Os::macOS => self.gpu_family() >= 2, |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
pub fn supports_16_bit_unsigned_integer_coordinates(&self) -> bool { |
| 426 |
match self.os() { |
| 427 |
Os::iOS => self.os_version() >= 10, |
| 428 |
Os::tvOS => self.os_version() >= 10, |
| 429 |
Os::macOS => self.os_version() >= 12, |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
pub fn supports_extract_insert_and_reverse_bits(&self) -> bool { |
| 434 |
match self.os() { |
| 435 |
Os::iOS => self.os_version() >= 10, |
| 436 |
Os::tvOS => self.os_version() >= 10, |
| 437 |
Os::macOS => self.os_version() >= 12, |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
pub fn supports_simd_barrier(&self) -> bool { |
| 442 |
match self.os() { |
| 443 |
Os::iOS => self.os_version() >= 10, |
| 444 |
Os::tvOS => self.os_version() >= 10, |
| 445 |
Os::macOS => self.os_version() >= 13, |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
pub fn supports_sampler_max_anisotropy(&self) -> bool { |
| 450 |
match self.os() { |
| 451 |
Os::iOS => self.os_version() >= 10, |
| 452 |
Os::tvOS => self.os_version() >= 10, |
| 453 |
Os::macOS => self.os_version() >= 13, |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
pub fn supports_sampler_lod_clamp(&self) -> bool { |
| 458 |
match self.os() { |
| 459 |
Os::iOS => self.os_version() >= 10, |
| 460 |
Os::tvOS => self.os_version() >= 10, |
| 461 |
Os::macOS => self.os_version() >= 13, |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
pub fn supports_border_color(&self) -> bool { |
| 466 |
self.os() == Os::macOS && self.os_version() >= 12 |
| 467 |
} |
| 468 |
|
| 469 |
pub fn supports_dual_source_blending(&self) -> bool { |
| 470 |
match self.os() { |
| 471 |
Os::iOS => self.os_version() >= 11, |
| 472 |
Os::tvOS => self.os_version() >= 11, |
| 473 |
Os::macOS => self.os_version() >= 12, |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
pub fn supports_argument_buffers(&self) -> bool { |
| 478 |
match self.os() { |
| 479 |
Os::iOS => self.os_version() >= 11, |
| 480 |
Os::tvOS => self.os_version() >= 11, |
| 481 |
Os::macOS => self.os_version() >= 13, |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
pub fn supports_programmable_sample_positions(&self) -> bool { |
| 486 |
match self.os() { |
| 487 |
Os::iOS => self.os_version() >= 11, |
| 488 |
Os::tvOS => self.os_version() >= 11, |
| 489 |
Os::macOS => self.os_version() >= 13, |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
pub fn supports_uniform_type(&self) -> bool { |
| 494 |
match self.os() { |
| 495 |
Os::iOS => self.os_version() >= 11, |
| 496 |
Os::tvOS => self.os_version() >= 11, |
| 497 |
Os::macOS => self.os_version() >= 13, |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
pub fn supports_imageblocks(&self) -> bool { |
| 502 |
self.os() == Os::iOS && self.gpu_family() >= 4 |
| 503 |
} |
| 504 |
|
| 505 |
pub fn supports_tile_shaders(&self) -> bool { |
| 506 |
self.os() == Os::iOS && self.gpu_family() >= 4 |
| 507 |
} |
| 508 |
|
| 509 |
pub fn supports_imageblock_sample_coverage_control(&self) -> bool { |
| 510 |
self.os() == Os::iOS && self.gpu_family() >= 4 |
| 511 |
} |
| 512 |
|
| 513 |
pub fn supports_threadgroup_sharing(&self) -> bool { |
| 514 |
self.os() == Os::iOS && self.gpu_family() >= 4 |
| 515 |
} |
| 516 |
|
| 517 |
pub fn supports_post_depth_coverage(&self) -> bool { |
| 518 |
self.os() == Os::iOS && self.gpu_family() >= 4 |
| 519 |
} |
| 520 |
|
| 521 |
pub fn supports_quad_scoped_permute_operations(&self) -> bool { |
| 522 |
match self.os() { |
| 523 |
Os::iOS => self.gpu_family() >= 4, |
| 524 |
Os::tvOS => false, |
| 525 |
Os::macOS => self.os_version() >= 13, |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
pub fn supports_raster_order_groups(&self) -> bool { |
| 530 |
match self.os() { |
| 531 |
Os::iOS => self.gpu_family() >= 4, |
| 532 |
Os::tvOS => false, |
| 533 |
Os::macOS => self.os_version() >= 13, |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
pub fn supports_non_uniform_threadgroup_size(&self) -> bool { |
| 538 |
match self.os() { |
| 539 |
Os::iOS => self.gpu_family() >= 4, |
| 540 |
Os::tvOS => false, |
| 541 |
Os::macOS => self.os_version() >= 13, |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
pub fn supports_multiple_viewports(&self) -> bool { |
| 546 |
match self.os() { |
| 547 |
Os::iOS => self.gpu_family() >= 5, |
| 548 |
Os::tvOS => false, |
| 549 |
Os::macOS => self.os_version() >= 13, |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
pub fn supports_device_notifications(&self) -> bool { |
| 554 |
self.os() == Os::macOS && self.os_version() >= 13 |
| 555 |
} |
| 556 |
|
| 557 |
pub fn supports_stencil_feedback(&self) -> bool { |
| 558 |
match self.os() { |
| 559 |
Os::iOS => self.gpu_family() >= 5, |
| 560 |
Os::tvOS => false, |
| 561 |
Os::macOS => self.gpu_family() >= 2, |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
pub fn supports_stencil_resolve(&self) -> bool { |
| 566 |
match self.os() { |
| 567 |
Os::iOS => self.gpu_family() >= 5, |
| 568 |
Os::tvOS => false, |
| 569 |
Os::macOS => self.gpu_family() >= 2, |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
pub fn supports_binary_archive(&self) -> bool { |
| 574 |
match self.os() { |
| 575 |
Os::iOS => self.gpu_family() >= 3, |
| 576 |
Os::tvOS => self.gpu_family() >= 3, |
| 577 |
Os::macOS => self.gpu_family() >= 1, |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
pub fn max_vertex_attributes(&self) -> u32 { |
| 582 |
31 |
| 583 |
} |
| 584 |
|
| 585 |
pub fn max_buffer_argument_entries(&self) -> u32 { |
| 586 |
31 |
| 587 |
} |
| 588 |
|
| 589 |
pub fn max_texture_argument_entries(&self) -> u32 { |
| 590 |
if self.os() == Os::macOS { |
| 591 |
128 |
| 592 |
} else { |
| 593 |
31 |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
pub fn max_sampler_state_argument_entries(&self) -> u32 { |
| 598 |
16 |
| 599 |
} |
| 600 |
|
| 601 |
pub fn max_threadgroup_memory_argument_entries(&self) -> u32 { |
| 602 |
31 |
| 603 |
} |
| 604 |
|
| 605 |
pub fn max_inlined_constant_data_buffers(&self) -> u32 { |
| 606 |
if self.os() == Os::macOS { |
| 607 |
14 |
| 608 |
} else { |
| 609 |
31 |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
pub fn max_inline_constant_buffer_length(&self) -> u32 { |
| 614 |
4 * KB |
| 615 |
} |
| 616 |
|
| 617 |
pub fn max_threads_per_threadgroup(&self) -> u32 { |
| 618 |
if self.os() == Os::macOS || self.gpu_family() >= 4 { |
| 619 |
1024 |
| 620 |
} else { |
| 621 |
512 |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
pub fn max_total_threadgroup_memory_allocation(&self) -> u32 { |
| 626 |
match (self.os(), self.gpu_family()) { |
| 627 |
(Os::iOS, 5) => 64 * KB, |
| 628 |
(Os::iOS, 4) => { |
| 629 |
if self.os_version() >= 12 { |
| 630 |
64 * KB |
| 631 |
} else { |
| 632 |
32 * KB |
| 633 |
} |
| 634 |
} |
| 635 |
(Os::iOS, 3) => 16 * KB, |
| 636 |
(Os::iOS, _) => 16 * KB - 32, |
| 637 |
(Os::tvOS, 1) => 16 * KB - 32, |
| 638 |
(Os::tvOS, _) => 16 * KB, |
| 639 |
(Os::macOS, _) => 32 * KB, |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
pub fn max_total_tile_memory_allocation(&self) -> u32 { |
| 644 |
if self.os() == Os::iOS && self.gpu_family() == 4 { |
| 645 |
32 * KB |
| 646 |
} else { |
| 647 |
0 |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
pub fn threadgroup_memory_length_alignment(&self) -> u32 { |
| 652 |
16 |
| 653 |
} |
| 654 |
|
| 655 |
pub fn max_constant_buffer_function_memory_allocation(&self) -> Option<u32> { |
| 656 |
if self.os() == Os::macOS { |
| 657 |
Some(64 * KB) |
| 658 |
} else { |
| 659 |
None |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
pub fn max_fragment_inputs(&self) -> u32 { |
| 664 |
if self.os() == Os::macOS { |
| 665 |
32 |
| 666 |
} else { |
| 667 |
60 |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
pub fn max_fragment_input_components(&self) -> u32 { |
| 672 |
if self.os() == Os::macOS { |
| 673 |
128 |
| 674 |
} else { |
| 675 |
60 |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
pub fn max_function_constants(&self) -> u32 { |
| 680 |
match self.os() { |
| 681 |
Os::iOS if self.os_version() >= 11 => 65536, |
| 682 |
Os::tvOS if self.os_version() >= 10 => 65536, |
| 683 |
Os::macOS if self.os_version() >= 12 => 65536, |
| 684 |
_ => 0, |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
pub fn max_tessellation_factor(&self) -> u32 { |
| 689 |
if self.supports_tessellation() { |
| 690 |
match self.os() { |
| 691 |
Os::iOS if self.gpu_family() >= 5 => 64, |
| 692 |
Os::iOS => 16, |
| 693 |
Os::tvOS => 16, |
| 694 |
Os::macOS => 64, |
| 695 |
} |
| 696 |
} else { |
| 697 |
0 |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
pub fn max_viewports_and_scissor_rectangles(&self) -> u32 { |
| 702 |
if self.supports_multiple_viewports() { |
| 703 |
16 |
| 704 |
} else { |
| 705 |
1 |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
pub fn max_raster_order_groups(&self) -> u32 { |
| 710 |
if self.supports_raster_order_groups() { |
| 711 |
8 |
| 712 |
} else { |
| 713 |
0 |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
pub fn max_buffer_length(&self) -> u32 { |
| 718 |
#[allow(clippy::identity_op)] |
| 719 |
if self.os() == Os::macOS && self.os_version() >= 12 { |
| 720 |
1 * GB |
| 721 |
} else { |
| 722 |
256 * MB |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
pub fn min_buffer_offset_alignment(&self) -> u32 { |
| 727 |
if self.os() == Os::macOS { |
| 728 |
256 |
| 729 |
} else { |
| 730 |
4 |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
pub fn max_1d_texture_size(&self) -> u32 { |
| 735 |
match (self.os(), self.gpu_family()) { |
| 736 |
(Os::iOS, 1) | (Os::iOS, 2) => { |
| 737 |
if self.version() <= 2 { |
| 738 |
4096 |
| 739 |
} else { |
| 740 |
8192 |
| 741 |
} |
| 742 |
} |
| 743 |
(Os::tvOS, 1) => 8192, |
| 744 |
_ => 16384, |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
pub fn max_2d_texture_size(&self) -> u32 { |
| 749 |
match (self.os(), self.gpu_family()) { |
| 750 |
(Os::iOS, 1) | (Os::iOS, 2) => { |
| 751 |
if self.version() <= 2 { |
| 752 |
4096 |
| 753 |
} else { |
| 754 |
8192 |
| 755 |
} |
| 756 |
} |
| 757 |
(Os::tvOS, 1) => 8192, |
| 758 |
_ => 16384, |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
pub fn max_cube_map_texture_size(&self) -> u32 { |
| 763 |
match (self.os(), self.gpu_family()) { |
| 764 |
(Os::iOS, 1) | (Os::iOS, 2) => { |
| 765 |
if self.version() <= 2 { |
| 766 |
4096 |
| 767 |
} else { |
| 768 |
8192 |
| 769 |
} |
| 770 |
} |
| 771 |
(Os::tvOS, 1) => 8192, |
| 772 |
_ => 16384, |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
pub fn max_3d_texture_size(&self) -> u32 { |
| 777 |
2048 |
| 778 |
} |
| 779 |
|
| 780 |
pub fn max_array_layers(&self) -> u32 { |
| 781 |
2048 |
| 782 |
} |
| 783 |
|
| 784 |
pub fn copy_texture_buffer_alignment(&self) -> u32 { |
| 785 |
match (self.os(), self.gpu_family()) { |
| 786 |
(Os::iOS, 1) | (Os::iOS, 2) | (Os::tvOS, 1) => 64, |
| 787 |
(Os::iOS, _) | (Os::tvOS, _) => 16, |
| 788 |
(Os::macOS, _) => 256, |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
/// If this function returns `None` but linear textures are supported, |
| 793 |
/// the buffer alignment can be discovered via API query |
| 794 |
pub fn new_texture_buffer_alignment(&self) -> Option<u32> { |
| 795 |
match self.os() { |
| 796 |
Os::iOS => { |
| 797 |
if self.os_version() >= 11 { |
| 798 |
None |
| 799 |
} else if self.gpu_family() == 3 { |
| 800 |
Some(16) |
| 801 |
} else { |
| 802 |
Some(64) |
| 803 |
} |
| 804 |
} |
| 805 |
Os::tvOS => { |
| 806 |
if self.os_version() >= 11 { |
| 807 |
None |
| 808 |
} else { |
| 809 |
Some(64) |
| 810 |
} |
| 811 |
} |
| 812 |
Os::macOS => None, |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
pub fn max_color_render_targets(&self) -> u32 { |
| 817 |
if self.os() == Os::iOS && self.gpu_family() == 1 { |
| 818 |
4 |
| 819 |
} else { |
| 820 |
8 |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
pub fn max_point_primitive_size(&self) -> u32 { |
| 825 |
511 |
| 826 |
} |
| 827 |
|
| 828 |
pub fn max_total_color_render_target_size(&self) -> Option<u32> { |
| 829 |
match (self.os(), self.gpu_family()) { |
| 830 |
(Os::iOS, 1) => Some(128), |
| 831 |
(Os::iOS, 2) | (Os::iOS, 3) => Some(256), |
| 832 |
(Os::iOS, _) => Some(512), |
| 833 |
(Os::tvOS, _) => Some(256), |
| 834 |
(Os::macOS, _) => None, |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
pub fn max_visibility_query_offset(&self) -> u32 { |
| 839 |
64 * KB - 8 |
| 840 |
} |
| 841 |
|
| 842 |
pub fn a8_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 843 |
PixelFormatCapabilities::Filter |
| 844 |
} |
| 845 |
|
| 846 |
pub fn r8_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 847 |
PixelFormatCapabilities::all() |
| 848 |
} |
| 849 |
|
| 850 |
pub fn r8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 851 |
if self.os() == Os::macOS { |
| 852 |
PixelFormatCapabilities::empty() |
| 853 |
} else if self.supports_srgb_writes() { |
| 854 |
PixelFormatCapabilities::all() |
| 855 |
} else { |
| 856 |
!PixelFormatCapabilities::Write |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
pub fn r8_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 861 |
if self.os() == Os::iOS && self.gpu_family() == 1 { |
| 862 |
!PixelFormatCapabilities::Resolve |
| 863 |
} else { |
| 864 |
PixelFormatCapabilities::all() |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
pub fn r8_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 869 |
PixelFormatCapabilities::Write |
| 870 |
| PixelFormatCapabilities::Color |
| 871 |
| PixelFormatCapabilities::Msaa |
| 872 |
} |
| 873 |
|
| 874 |
pub fn r8_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 875 |
PixelFormatCapabilities::Write |
| 876 |
| PixelFormatCapabilities::Color |
| 877 |
| PixelFormatCapabilities::Msaa |
| 878 |
} |
| 879 |
|
| 880 |
pub fn r16_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 881 |
if self.os() != Os::macOS { |
| 882 |
!PixelFormatCapabilities::Resolve |
| 883 |
} else { |
| 884 |
PixelFormatCapabilities::all() |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
pub fn r16_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 889 |
if self.os() != Os::macOS { |
| 890 |
!PixelFormatCapabilities::Resolve |
| 891 |
} else { |
| 892 |
PixelFormatCapabilities::all() |
| 893 |
} |
| 894 |
} |
| 895 |
|
| 896 |
pub fn r16_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 897 |
PixelFormatCapabilities::Write |
| 898 |
| PixelFormatCapabilities::Color |
| 899 |
| PixelFormatCapabilities::Msaa |
| 900 |
} |
| 901 |
|
| 902 |
pub fn r16_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 903 |
PixelFormatCapabilities::Write |
| 904 |
| PixelFormatCapabilities::Color |
| 905 |
| PixelFormatCapabilities::Msaa |
| 906 |
} |
| 907 |
|
| 908 |
pub fn r16_float_capabilities(&self) -> PixelFormatCapabilities { |
| 909 |
PixelFormatCapabilities::all() |
| 910 |
} |
| 911 |
|
| 912 |
pub fn rg8_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 913 |
PixelFormatCapabilities::all() |
| 914 |
} |
| 915 |
|
| 916 |
pub fn rg8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 917 |
if self.os() == Os::macOS { |
| 918 |
PixelFormatCapabilities::empty() |
| 919 |
} else if self.supports_srgb_writes() { |
| 920 |
PixelFormatCapabilities::all() |
| 921 |
} else { |
| 922 |
!PixelFormatCapabilities::Write |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
pub fn rg8_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 927 |
if self.os() == Os::iOS && self.gpu_family() == 1 { |
| 928 |
!PixelFormatCapabilities::Resolve |
| 929 |
} else { |
| 930 |
PixelFormatCapabilities::all() |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
pub fn rg8_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 935 |
PixelFormatCapabilities::Write |
| 936 |
| PixelFormatCapabilities::Color |
| 937 |
| PixelFormatCapabilities::Msaa |
| 938 |
} |
| 939 |
|
| 940 |
pub fn rg8_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 941 |
PixelFormatCapabilities::Write |
| 942 |
| PixelFormatCapabilities::Color |
| 943 |
| PixelFormatCapabilities::Msaa |
| 944 |
} |
| 945 |
|
| 946 |
pub fn b5_g6_r5_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 947 |
if self.os() == Os::macOS { |
| 948 |
PixelFormatCapabilities::empty() |
| 949 |
} else { |
| 950 |
!PixelFormatCapabilities::Write |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
pub fn a1_bgr5_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 955 |
if self.os() == Os::macOS { |
| 956 |
PixelFormatCapabilities::empty() |
| 957 |
} else { |
| 958 |
!PixelFormatCapabilities::Write |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
pub fn abgr4_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 963 |
if self.os() == Os::macOS { |
| 964 |
PixelFormatCapabilities::empty() |
| 965 |
} else { |
| 966 |
!PixelFormatCapabilities::Write |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
pub fn bgr5_a1_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 971 |
if self.os() == Os::macOS { |
| 972 |
PixelFormatCapabilities::empty() |
| 973 |
} else { |
| 974 |
!PixelFormatCapabilities::Write |
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
pub fn r32_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 979 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 980 |
PixelFormatCapabilities::Color |
| 981 |
} else if self.os() == Os::macOS { |
| 982 |
PixelFormatCapabilities::Color |
| 983 |
| PixelFormatCapabilities::Write |
| 984 |
| PixelFormatCapabilities::Msaa |
| 985 |
} else { |
| 986 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
pub fn r32_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 991 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 992 |
PixelFormatCapabilities::Color |
| 993 |
} else if self.os() == Os::macOS { |
| 994 |
PixelFormatCapabilities::Color |
| 995 |
| PixelFormatCapabilities::Write |
| 996 |
| PixelFormatCapabilities::Msaa |
| 997 |
} else { |
| 998 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 999 |
} |
| 1000 |
} |
| 1001 |
|
| 1002 |
pub fn r32_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1003 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 1004 |
PixelFormatCapabilities::Color |
| 1005 |
| PixelFormatCapabilities::Blend |
| 1006 |
| PixelFormatCapabilities::Msaa |
| 1007 |
} else if self.os() == Os::macOS { |
| 1008 |
PixelFormatCapabilities::all() |
| 1009 |
} else { |
| 1010 |
PixelFormatCapabilities::Write |
| 1011 |
| PixelFormatCapabilities::Color |
| 1012 |
| PixelFormatCapabilities::Blend |
| 1013 |
| PixelFormatCapabilities::Msaa |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
pub fn rg16_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1018 |
if self.os() == Os::macOS { |
| 1019 |
PixelFormatCapabilities::all() |
| 1020 |
} else { |
| 1021 |
!PixelFormatCapabilities::Resolve |
| 1022 |
} |
| 1023 |
} |
| 1024 |
|
| 1025 |
pub fn rg16_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1026 |
if self.os() == Os::macOS { |
| 1027 |
PixelFormatCapabilities::all() |
| 1028 |
} else { |
| 1029 |
!PixelFormatCapabilities::Resolve |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
pub fn rg16_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1034 |
PixelFormatCapabilities::Write |
| 1035 |
| PixelFormatCapabilities::Color |
| 1036 |
| PixelFormatCapabilities::Msaa |
| 1037 |
} |
| 1038 |
|
| 1039 |
pub fn rg16_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 1040 |
PixelFormatCapabilities::Write |
| 1041 |
| PixelFormatCapabilities::Color |
| 1042 |
| PixelFormatCapabilities::Msaa |
| 1043 |
} |
| 1044 |
|
| 1045 |
pub fn rg16_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1046 |
PixelFormatCapabilities::all() |
| 1047 |
} |
| 1048 |
|
| 1049 |
pub fn rgba8_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1050 |
PixelFormatCapabilities::all() |
| 1051 |
} |
| 1052 |
|
| 1053 |
pub fn rgba8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 1054 |
if self.supports_srgb_writes() { |
| 1055 |
PixelFormatCapabilities::all() |
| 1056 |
} else { |
| 1057 |
!PixelFormatCapabilities::Write |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
pub fn rgba8_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1062 |
if self.os() == Os::iOS && self.gpu_family() == 1 { |
| 1063 |
!PixelFormatCapabilities::Resolve |
| 1064 |
} else { |
| 1065 |
PixelFormatCapabilities::all() |
| 1066 |
} |
| 1067 |
} |
| 1068 |
|
| 1069 |
pub fn rgba8_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1070 |
PixelFormatCapabilities::Write |
| 1071 |
| PixelFormatCapabilities::Color |
| 1072 |
| PixelFormatCapabilities::Msaa |
| 1073 |
} |
| 1074 |
|
| 1075 |
pub fn rgba8_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 1076 |
PixelFormatCapabilities::Write |
| 1077 |
| PixelFormatCapabilities::Color |
| 1078 |
| PixelFormatCapabilities::Msaa |
| 1079 |
} |
| 1080 |
|
| 1081 |
pub fn bgra8_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1082 |
PixelFormatCapabilities::all() |
| 1083 |
} |
| 1084 |
|
| 1085 |
pub fn bgra8_unorm_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 1086 |
if self.supports_srgb_writes() { |
| 1087 |
PixelFormatCapabilities::all() |
| 1088 |
} else { |
| 1089 |
!PixelFormatCapabilities::Write |
| 1090 |
} |
| 1091 |
} |
| 1092 |
|
| 1093 |
pub fn rgb10_a2_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1094 |
let supports_writes = match self.os() { |
| 1095 |
Os::iOS => self.gpu_family() >= 3, |
| 1096 |
Os::tvOS => self.gpu_family() >= 2, |
| 1097 |
Os::macOS => true, |
| 1098 |
}; |
| 1099 |
if supports_writes { |
| 1100 |
PixelFormatCapabilities::all() |
| 1101 |
} else { |
| 1102 |
!PixelFormatCapabilities::Write |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
pub fn rgb10_a2_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1107 |
let supports_writes = match self.os() { |
| 1108 |
Os::iOS => self.gpu_family() >= 3, |
| 1109 |
Os::tvOS => self.gpu_family() >= 2, |
| 1110 |
Os::macOS => true, |
| 1111 |
}; |
| 1112 |
if supports_writes { |
| 1113 |
PixelFormatCapabilities::Write |
| 1114 |
| PixelFormatCapabilities::Color |
| 1115 |
| PixelFormatCapabilities::Msaa |
| 1116 |
} else { |
| 1117 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Msaa |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
pub fn rg11_b10_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1122 |
let supports_writes = match self.os() { |
| 1123 |
Os::iOS => self.gpu_family() >= 3, |
| 1124 |
Os::tvOS => self.gpu_family() >= 2, |
| 1125 |
Os::macOS => true, |
| 1126 |
}; |
| 1127 |
if supports_writes { |
| 1128 |
PixelFormatCapabilities::all() |
| 1129 |
} else { |
| 1130 |
!PixelFormatCapabilities::Write |
| 1131 |
} |
| 1132 |
} |
| 1133 |
|
| 1134 |
pub fn rgb9_e5_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1135 |
if self.os() == Os::macOS { |
| 1136 |
PixelFormatCapabilities::Filter |
| 1137 |
} else { |
| 1138 |
let supports_writes = match self.os() { |
| 1139 |
Os::iOS => self.gpu_family() >= 3, |
| 1140 |
Os::tvOS => self.gpu_family() >= 2, |
| 1141 |
Os::macOS => false, |
| 1142 |
}; |
| 1143 |
if supports_writes { |
| 1144 |
PixelFormatCapabilities::all() |
| 1145 |
} else { |
| 1146 |
!PixelFormatCapabilities::Write |
| 1147 |
} |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
pub fn rg32_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1152 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 1153 |
PixelFormatCapabilities::Color |
| 1154 |
} else if self.os() == Os::macOS { |
| 1155 |
PixelFormatCapabilities::Color |
| 1156 |
| PixelFormatCapabilities::Write |
| 1157 |
| PixelFormatCapabilities::Msaa |
| 1158 |
} else { |
| 1159 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
pub fn rg32_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 1164 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 1165 |
PixelFormatCapabilities::Color |
| 1166 |
} else if self.os() == Os::macOS { |
| 1167 |
PixelFormatCapabilities::Color |
| 1168 |
| PixelFormatCapabilities::Write |
| 1169 |
| PixelFormatCapabilities::Msaa |
| 1170 |
} else { |
| 1171 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 1172 |
} |
| 1173 |
} |
| 1174 |
|
| 1175 |
pub fn rg32_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1176 |
if self.os() == Os::macOS { |
| 1177 |
PixelFormatCapabilities::all() |
| 1178 |
} else if self.os() == Os::iOS && self.os_version() == 8 { |
| 1179 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Blend |
| 1180 |
} else { |
| 1181 |
PixelFormatCapabilities::Write |
| 1182 |
| PixelFormatCapabilities::Color |
| 1183 |
| PixelFormatCapabilities::Blend |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
pub fn rgba16_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1188 |
if self.os() == Os::macOS { |
| 1189 |
PixelFormatCapabilities::all() |
| 1190 |
} else { |
| 1191 |
!PixelFormatCapabilities::Write |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
pub fn rgba16_snorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1196 |
if self.os() == Os::macOS { |
| 1197 |
PixelFormatCapabilities::all() |
| 1198 |
} else { |
| 1199 |
!PixelFormatCapabilities::Write |
| 1200 |
} |
| 1201 |
} |
| 1202 |
|
| 1203 |
pub fn rgba16_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1204 |
PixelFormatCapabilities::Write |
| 1205 |
| PixelFormatCapabilities::Color |
| 1206 |
| PixelFormatCapabilities::Msaa |
| 1207 |
} |
| 1208 |
|
| 1209 |
pub fn rgba16_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 1210 |
PixelFormatCapabilities::Write |
| 1211 |
| PixelFormatCapabilities::Color |
| 1212 |
| PixelFormatCapabilities::Msaa |
| 1213 |
} |
| 1214 |
|
| 1215 |
pub fn rgba16_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1216 |
PixelFormatCapabilities::all() |
| 1217 |
} |
| 1218 |
|
| 1219 |
pub fn rgba32_uint_capabilities(&self) -> PixelFormatCapabilities { |
| 1220 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 1221 |
PixelFormatCapabilities::Color |
| 1222 |
} else if self.os() == Os::macOS { |
| 1223 |
PixelFormatCapabilities::Color |
| 1224 |
| PixelFormatCapabilities::Write |
| 1225 |
| PixelFormatCapabilities::Msaa |
| 1226 |
} else { |
| 1227 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
pub fn rgba32_sint_capabilities(&self) -> PixelFormatCapabilities { |
| 1232 |
if self.os() == Os::iOS && self.os_version() == 8 { |
| 1233 |
PixelFormatCapabilities::Color |
| 1234 |
} else if self.os() == Os::macOS { |
| 1235 |
PixelFormatCapabilities::Color |
| 1236 |
| PixelFormatCapabilities::Write |
| 1237 |
| PixelFormatCapabilities::Msaa |
| 1238 |
} else { |
| 1239 |
PixelFormatCapabilities::Color | PixelFormatCapabilities::Write |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
pub fn rgba32_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1244 |
if self.os() == Os::macOS { |
| 1245 |
PixelFormatCapabilities::all() |
| 1246 |
} else if self.os() == Os::iOS && self.version() == 8 { |
| 1247 |
PixelFormatCapabilities::Color |
| 1248 |
} else { |
| 1249 |
PixelFormatCapabilities::Write | PixelFormatCapabilities::Color |
| 1250 |
} |
| 1251 |
} |
| 1252 |
|
| 1253 |
pub fn pvrtc_pixel_formats_capabilities(&self) -> PixelFormatCapabilities { |
| 1254 |
if self.supports_pvrtc_pixel_formats() { |
| 1255 |
PixelFormatCapabilities::Filter |
| 1256 |
} else { |
| 1257 |
PixelFormatCapabilities::empty() |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
pub fn eac_etc_pixel_formats_capabilities(&self) -> PixelFormatCapabilities { |
| 1262 |
if self.supports_eac_etc_pixel_formats() { |
| 1263 |
PixelFormatCapabilities::Filter |
| 1264 |
} else { |
| 1265 |
PixelFormatCapabilities::empty() |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
pub fn astc_pixel_formats_capabilities(&self) -> PixelFormatCapabilities { |
| 1270 |
if self.supports_astc_pixel_formats() { |
| 1271 |
PixelFormatCapabilities::Filter |
| 1272 |
} else { |
| 1273 |
PixelFormatCapabilities::empty() |
| 1274 |
} |
| 1275 |
} |
| 1276 |
|
| 1277 |
pub fn bc_pixel_formats_capabilities(&self) -> PixelFormatCapabilities { |
| 1278 |
if self.supports_bc_pixel_formats() { |
| 1279 |
PixelFormatCapabilities::Filter |
| 1280 |
} else { |
| 1281 |
PixelFormatCapabilities::empty() |
| 1282 |
} |
| 1283 |
} |
| 1284 |
|
| 1285 |
pub fn gbgr422_capabilities(&self) -> PixelFormatCapabilities { |
| 1286 |
PixelFormatCapabilities::Filter |
| 1287 |
} |
| 1288 |
|
| 1289 |
pub fn bgrg422_capabilities(&self) -> PixelFormatCapabilities { |
| 1290 |
PixelFormatCapabilities::Filter |
| 1291 |
} |
| 1292 |
|
| 1293 |
pub fn depth16_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1294 |
if self.supports_depth_16_pixel_format() { |
| 1295 |
PixelFormatCapabilities::Filter |
| 1296 |
| PixelFormatCapabilities::Msaa |
| 1297 |
| PixelFormatCapabilities::Resolve |
| 1298 |
} else { |
| 1299 |
PixelFormatCapabilities::empty() |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
pub fn depth32_float_capabilities(&self) -> PixelFormatCapabilities { |
| 1304 |
if self.os() == Os::macOS { |
| 1305 |
PixelFormatCapabilities::Filter |
| 1306 |
| PixelFormatCapabilities::Msaa |
| 1307 |
| PixelFormatCapabilities::Resolve |
| 1308 |
} else if self.supports_msaa_depth_resolve() { |
| 1309 |
PixelFormatCapabilities::Msaa | PixelFormatCapabilities::Resolve |
| 1310 |
} else { |
| 1311 |
PixelFormatCapabilities::Msaa |
| 1312 |
} |
| 1313 |
} |
| 1314 |
|
| 1315 |
pub fn stencil8_capabilities(&self) -> PixelFormatCapabilities { |
| 1316 |
PixelFormatCapabilities::Msaa |
| 1317 |
} |
| 1318 |
|
| 1319 |
pub fn depth24_unorm_stencil8_capabilities(&self) -> PixelFormatCapabilities { |
| 1320 |
if self.os() == Os::macOS { |
| 1321 |
PixelFormatCapabilities::Filter |
| 1322 |
| PixelFormatCapabilities::Msaa |
| 1323 |
| PixelFormatCapabilities::Resolve |
| 1324 |
} else { |
| 1325 |
PixelFormatCapabilities::empty() |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
pub fn depth32_float_stencil8_capabilities(&self) -> PixelFormatCapabilities { |
| 1330 |
if self.os() == Os::macOS { |
| 1331 |
PixelFormatCapabilities::Filter |
| 1332 |
| PixelFormatCapabilities::Msaa |
| 1333 |
| PixelFormatCapabilities::Resolve |
| 1334 |
} else if self.supports_msaa_depth_resolve() { |
| 1335 |
PixelFormatCapabilities::Msaa | PixelFormatCapabilities::Resolve |
| 1336 |
} else { |
| 1337 |
PixelFormatCapabilities::Msaa |
| 1338 |
} |
| 1339 |
} |
| 1340 |
|
| 1341 |
pub fn x24_stencil8_capabilities(&self) -> PixelFormatCapabilities { |
| 1342 |
if self.os() == Os::macOS { |
| 1343 |
PixelFormatCapabilities::Msaa |
| 1344 |
} else { |
| 1345 |
PixelFormatCapabilities::empty() |
| 1346 |
} |
| 1347 |
} |
| 1348 |
|
| 1349 |
pub fn x32_stencil8_capabilities(&self) -> PixelFormatCapabilities { |
| 1350 |
PixelFormatCapabilities::Msaa |
| 1351 |
} |
| 1352 |
|
| 1353 |
pub fn bgra10_xr_capabilities(&self) -> PixelFormatCapabilities { |
| 1354 |
if self.supports_extended_range_pixel_formats() { |
| 1355 |
PixelFormatCapabilities::all() |
| 1356 |
} else { |
| 1357 |
PixelFormatCapabilities::empty() |
| 1358 |
} |
| 1359 |
} |
| 1360 |
|
| 1361 |
pub fn bgra10_xr_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 1362 |
if self.supports_extended_range_pixel_formats() { |
| 1363 |
PixelFormatCapabilities::all() |
| 1364 |
} else { |
| 1365 |
PixelFormatCapabilities::empty() |
| 1366 |
} |
| 1367 |
} |
| 1368 |
|
| 1369 |
pub fn bgr10_xr_capabilities(&self) -> PixelFormatCapabilities { |
| 1370 |
if self.supports_extended_range_pixel_formats() { |
| 1371 |
PixelFormatCapabilities::all() |
| 1372 |
} else { |
| 1373 |
PixelFormatCapabilities::empty() |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
pub fn bgr10_xr_srgb_capabilities(&self) -> PixelFormatCapabilities { |
| 1378 |
if self.supports_extended_range_pixel_formats() { |
| 1379 |
PixelFormatCapabilities::all() |
| 1380 |
} else { |
| 1381 |
PixelFormatCapabilities::empty() |
| 1382 |
} |
| 1383 |
} |
| 1384 |
|
| 1385 |
pub fn bgr10_a2_unorm_capabilities(&self) -> PixelFormatCapabilities { |
| 1386 |
if self.supports_wide_color_pixel_format() { |
| 1387 |
if self.os() == Os::macOS { |
| 1388 |
!PixelFormatCapabilities::Write |
| 1389 |
} else { |
| 1390 |
PixelFormatCapabilities::all() |
| 1391 |
} |
| 1392 |
} else { |
| 1393 |
PixelFormatCapabilities::empty() |
| 1394 |
} |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
/// See <https://developer.apple.com/documentation/metal/mtlargumentbufferstier> |
| 1399 |
#[repr(u64)] |
| 1400 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 1401 |
pub enum MTLArgumentBuffersTier { |
| 1402 |
Tier1 = 0, |
| 1403 |
Tier2 = 1, |
| 1404 |
} |
| 1405 |
|
| 1406 |
/// See <https://developer.apple.com/documentation/metal/mtlreadwritetexturetier> |
| 1407 |
#[repr(u64)] |
| 1408 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 1409 |
pub enum MTLReadWriteTextureTier { |
| 1410 |
TierNone = 0, |
| 1411 |
Tier1 = 1, |
| 1412 |
Tier2 = 2, |
| 1413 |
} |
| 1414 |
|
| 1415 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1416 |
/// |
| 1417 |
/// See <https://developer.apple.com/documentation/metal/mtlcountersamplingpoint> |
| 1418 |
#[repr(u64)] |
| 1419 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 1420 |
pub enum MTLCounterSamplingPoint { |
| 1421 |
AtStageBoundary = 0, |
| 1422 |
AtDrawBoundary = 1, |
| 1423 |
AtDispatchBoundary = 2, |
| 1424 |
AtTileDispatchBoundary = 3, |
| 1425 |
AtBlitBoundary = 4, |
| 1426 |
} |
| 1427 |
|
| 1428 |
/// Only available on (macos(11.0), macCatalyst(14.0), ios(13.0)) |
| 1429 |
/// Kinda a long name! |
| 1430 |
/// |
| 1431 |
/// See <https://developer.apple.com/documentation/metal/mtlsparsetextureregionalignmentmode> |
| 1432 |
#[repr(u64)] |
| 1433 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 1434 |
pub enum MTLSparseTextureRegionAlignmentMode { |
| 1435 |
Outward = 0, |
| 1436 |
Inward = 1, |
| 1437 |
} |
| 1438 |
|
| 1439 |
bitflags::bitflags! { |
| 1440 |
/// Options that determine how Metal prepares the pipeline. |
| 1441 |
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 1442 |
pub struct MTLPipelineOption: NSUInteger { |
| 1443 |
/// Do not provide any reflection information. |
| 1444 |
const None = 0; |
| 1445 |
/// An option that requests argument information for buffers, textures, and threadgroup memory. |
| 1446 |
const ArgumentInfo = 1 << 0; |
| 1447 |
/// An option that requests detailed buffer type information for buffer arguments. |
| 1448 |
const BufferTypeInfo = 1 << 1; |
| 1449 |
/// An option that specifies that Metal should create the pipeline state object only if the |
| 1450 |
/// compiled shader is present inside the binary archive. |
| 1451 |
/// |
| 1452 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1453 |
const FailOnBinaryArchiveMiss = 1 << 2; |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
/// See <https://developer.apple.com/documentation/metal/mtlaccelerationstructuresizes> |
| 1458 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
| 1459 |
#[repr(C)] |
| 1460 |
pub struct MTLAccelerationStructureSizes { |
| 1461 |
pub acceleration_structure_size: NSUInteger, |
| 1462 |
pub build_scratch_buffer_size: NSUInteger, |
| 1463 |
pub refit_scratch_buffer_size: NSUInteger, |
| 1464 |
} |
| 1465 |
|
| 1466 |
#[cfg_attr(feature = "link", link(name = "Metal", kind = "framework"))] |
| 1467 |
extern "C" { |
| 1468 |
fn MTLCreateSystemDefaultDevice() -> *mut MTLDevice; |
| 1469 |
#[cfg(not(any(target_os = "ios", target_os = "visionos")))] |
| 1470 |
fn MTLCopyAllDevices() -> *mut Object; //TODO: Array |
| 1471 |
} |
| 1472 |
|
| 1473 |
#[allow(non_camel_case_types)] |
| 1474 |
type dispatch_data_t = *mut Object; |
| 1475 |
#[allow(non_camel_case_types)] |
| 1476 |
pub type dispatch_queue_t = *mut Object; |
| 1477 |
#[allow(non_camel_case_types)] |
| 1478 |
type dispatch_block_t = *const Block<(), ()>; |
| 1479 |
|
| 1480 |
const DISPATCH_DATA_DESTRUCTOR_DEFAULT: dispatch_block_t = ptr::null(); |
| 1481 |
|
| 1482 |
#[cfg_attr( |
| 1483 |
all( |
| 1484 |
feature = "link", |
| 1485 |
any(target_os = "macos", target_os = "ios", target_os = "visionos") |
| 1486 |
), |
| 1487 |
link(name = "System", kind = "dylib") |
| 1488 |
)] |
| 1489 |
#[cfg_attr( |
| 1490 |
all( |
| 1491 |
feature = "link", |
| 1492 |
not(any(target_os = "macos", target_os = "ios", target_os = "visionos")) |
| 1493 |
), |
| 1494 |
link(name = "dispatch", kind = "dylib") |
| 1495 |
)] |
| 1496 |
#[allow(improper_ctypes)] |
| 1497 |
extern "C" { |
| 1498 |
static mut _dispatch_main_q: Object; |
| 1499 |
|
| 1500 |
fn dispatch_data_create( |
| 1501 |
buffer: *const std::ffi::c_void, |
| 1502 |
size: crate::c_size_t, |
| 1503 |
queue: dispatch_queue_t, |
| 1504 |
destructor: dispatch_block_t, |
| 1505 |
) -> dispatch_data_t; |
| 1506 |
fn dispatch_release(object: dispatch_data_t); // actually dispatch_object_t |
| 1507 |
} |
| 1508 |
|
| 1509 |
/*type MTLNewLibraryCompletionHandler = extern fn(library: id, error: id); |
| 1510 |
type MTLNewRenderPipelineStateCompletionHandler = extern fn(renderPipelineState: id, error: id); |
| 1511 |
type MTLNewRenderPipelineStateWithReflectionCompletionHandler = extern fn(renderPipelineState: id, reflection: id, error: id); |
| 1512 |
type MTLNewComputePipelineStateCompletionHandler = extern fn(computePipelineState: id, error: id); |
| 1513 |
type MTLNewComputePipelineStateWithReflectionCompletionHandler = extern fn(computePipelineState: id, reflection: id, error: id);*/ |
| 1514 |
|
| 1515 |
/// See <https://developer.apple.com/documentation/metal/mtldevice> |
| 1516 |
pub enum MTLDevice {} |
| 1517 |
|
| 1518 |
foreign_obj_type! { |
| 1519 |
type CType = MTLDevice; |
| 1520 |
pub struct Device; |
| 1521 |
} |
| 1522 |
|
| 1523 |
impl Device { |
| 1524 |
pub fn system_default() -> Option<Self> { |
| 1525 |
// `MTLCreateSystemDefaultDevice` may return null if Metal is not supported |
| 1526 |
unsafe { |
| 1527 |
MTLCreateSystemDefaultDevice() |
| 1528 |
.as_mut() |
| 1529 |
.map(|x| Self(x.into())) |
| 1530 |
} |
| 1531 |
} |
| 1532 |
|
| 1533 |
pub fn all() -> Vec<Self> { |
| 1534 |
#[cfg(any(target_os = "ios", target_os = "visionos"))] |
| 1535 |
{ |
| 1536 |
Self::system_default().into_iter().collect() |
| 1537 |
} |
| 1538 |
#[cfg(not(any(target_os = "ios", target_os = "visionos")))] |
| 1539 |
unsafe { |
| 1540 |
let array = MTLCopyAllDevices(); |
| 1541 |
let count: NSUInteger = msg_send![array, count]; |
| 1542 |
let ret = (0..count) |
| 1543 |
.map(|i| msg_send![array, objectAtIndex: i]) |
| 1544 |
// The elements of this array are references---we convert them to owned references |
| 1545 |
// (which just means that we increment the reference count here, and it is |
| 1546 |
// decremented in the `Drop` impl for `Device`) |
| 1547 |
.map(|device: *mut Object| msg_send![device, retain]) |
| 1548 |
.collect(); |
| 1549 |
let () = msg_send![array, release]; |
| 1550 |
ret |
| 1551 |
} |
| 1552 |
} |
| 1553 |
} |
| 1554 |
|
| 1555 |
impl DeviceRef { |
| 1556 |
pub fn name(&self) -> &str { |
| 1557 |
unsafe { |
| 1558 |
let name = msg_send![self, name]; |
| 1559 |
crate::nsstring_as_str(name) |
| 1560 |
} |
| 1561 |
} |
| 1562 |
|
| 1563 |
#[cfg(feature = "private")] |
| 1564 |
pub unsafe fn vendor(&self) -> &str { |
| 1565 |
let name = msg_send![self, vendorName]; |
| 1566 |
crate::nsstring_as_str(name) |
| 1567 |
} |
| 1568 |
|
| 1569 |
#[cfg(feature = "private")] |
| 1570 |
pub unsafe fn family_name(&self) -> &str { |
| 1571 |
let name = msg_send![self, familyName]; |
| 1572 |
crate::nsstring_as_str(name) |
| 1573 |
} |
| 1574 |
|
| 1575 |
pub fn registry_id(&self) -> u64 { |
| 1576 |
unsafe { msg_send![self, registryID] } |
| 1577 |
} |
| 1578 |
|
| 1579 |
pub fn location(&self) -> MTLDeviceLocation { |
| 1580 |
unsafe { msg_send![self, location] } |
| 1581 |
} |
| 1582 |
|
| 1583 |
pub fn location_number(&self) -> NSUInteger { |
| 1584 |
unsafe { msg_send![self, locationNumber] } |
| 1585 |
} |
| 1586 |
|
| 1587 |
pub fn max_threadgroup_memory_length(&self) -> NSUInteger { |
| 1588 |
unsafe { msg_send![self, maxThreadgroupMemoryLength] } |
| 1589 |
} |
| 1590 |
|
| 1591 |
pub fn max_threads_per_threadgroup(&self) -> MTLSize { |
| 1592 |
unsafe { msg_send![self, maxThreadsPerThreadgroup] } |
| 1593 |
} |
| 1594 |
|
| 1595 |
pub fn is_low_power(&self) -> bool { |
| 1596 |
unsafe { msg_send_bool![self, isLowPower] } |
| 1597 |
} |
| 1598 |
|
| 1599 |
pub fn is_headless(&self) -> bool { |
| 1600 |
unsafe { msg_send_bool![self, isHeadless] } |
| 1601 |
} |
| 1602 |
|
| 1603 |
pub fn is_removable(&self) -> bool { |
| 1604 |
unsafe { msg_send_bool![self, isRemovable] } |
| 1605 |
} |
| 1606 |
|
| 1607 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1608 |
pub fn supports_raytracing(&self) -> bool { |
| 1609 |
unsafe { msg_send_bool![self, supportsRaytracing] } |
| 1610 |
} |
| 1611 |
|
| 1612 |
pub fn has_unified_memory(&self) -> bool { |
| 1613 |
unsafe { msg_send![self, hasUnifiedMemory] } |
| 1614 |
} |
| 1615 |
|
| 1616 |
pub fn recommended_max_working_set_size(&self) -> u64 { |
| 1617 |
unsafe { msg_send![self, recommendedMaxWorkingSetSize] } |
| 1618 |
} |
| 1619 |
|
| 1620 |
pub fn max_transfer_rate(&self) -> u64 { |
| 1621 |
unsafe { msg_send![self, maxTransferRate] } |
| 1622 |
} |
| 1623 |
|
| 1624 |
pub fn supports_feature_set(&self, feature: MTLFeatureSet) -> bool { |
| 1625 |
unsafe { msg_send_bool![self, supportsFeatureSet: feature] } |
| 1626 |
} |
| 1627 |
|
| 1628 |
pub fn supports_family(&self, family: MTLGPUFamily) -> bool { |
| 1629 |
unsafe { msg_send_bool![self, supportsFamily: family] } |
| 1630 |
} |
| 1631 |
|
| 1632 |
pub fn supports_vertex_amplification_count(&self, count: NSUInteger) -> bool { |
| 1633 |
unsafe { msg_send_bool![self, supportsVertexAmplificationCount: count] } |
| 1634 |
} |
| 1635 |
|
| 1636 |
pub fn supports_texture_sample_count(&self, count: NSUInteger) -> bool { |
| 1637 |
unsafe { msg_send_bool![self, supportsTextureSampleCount: count] } |
| 1638 |
} |
| 1639 |
|
| 1640 |
pub fn supports_shader_barycentric_coordinates(&self) -> bool { |
| 1641 |
unsafe { msg_send_bool![self, supportsShaderBarycentricCoordinates] } |
| 1642 |
} |
| 1643 |
|
| 1644 |
pub fn supports_function_pointers(&self) -> bool { |
| 1645 |
unsafe { msg_send_bool![self, supportsFunctionPointers] } |
| 1646 |
} |
| 1647 |
|
| 1648 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1649 |
pub fn supports_dynamic_libraries(&self) -> bool { |
| 1650 |
unsafe { msg_send_bool![self, supportsDynamicLibraries] } |
| 1651 |
} |
| 1652 |
|
| 1653 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1654 |
pub fn supports_counter_sampling(&self, sampling_point: MTLCounterSamplingPoint) -> bool { |
| 1655 |
unsafe { msg_send_bool![self, supportsCounterSampling: sampling_point] } |
| 1656 |
} |
| 1657 |
|
| 1658 |
pub fn d24_s8_supported(&self) -> bool { |
| 1659 |
unsafe { msg_send_bool![self, isDepth24Stencil8PixelFormatSupported] } |
| 1660 |
} |
| 1661 |
|
| 1662 |
pub fn new_fence(&self) -> Fence { |
| 1663 |
unsafe { msg_send![self, newFence] } |
| 1664 |
} |
| 1665 |
|
| 1666 |
pub fn new_command_queue(&self) -> CommandQueue { |
| 1667 |
unsafe { msg_send![self, newCommandQueue] } |
| 1668 |
} |
| 1669 |
|
| 1670 |
pub fn new_command_queue_with_max_command_buffer_count( |
| 1671 |
&self, |
| 1672 |
count: NSUInteger, |
| 1673 |
) -> CommandQueue { |
| 1674 |
unsafe { msg_send![self, newCommandQueueWithMaxCommandBufferCount: count] } |
| 1675 |
} |
| 1676 |
|
| 1677 |
pub fn new_default_library(&self) -> Library { |
| 1678 |
unsafe { msg_send![self, newDefaultLibrary] } |
| 1679 |
} |
| 1680 |
|
| 1681 |
pub fn new_library_with_source( |
| 1682 |
&self, |
| 1683 |
src: &str, |
| 1684 |
options: &CompileOptionsRef, |
| 1685 |
) -> Result<Library, String> { |
| 1686 |
let source = nsstring_from_str(src); |
| 1687 |
unsafe { |
| 1688 |
let mut err: *mut Object = ptr::null_mut(); |
| 1689 |
let library: *mut MTLLibrary = msg_send![self, newLibraryWithSource:source |
| 1690 |
options:options |
| 1691 |
error:&mut err]; |
| 1692 |
if !err.is_null() { |
| 1693 |
let desc: *mut Object = msg_send![err, localizedDescription]; |
| 1694 |
let compile_error: *const c_char = msg_send![desc, UTF8String]; |
| 1695 |
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned(); |
| 1696 |
if library.is_null() { |
| 1697 |
return Err(message); |
| 1698 |
} else { |
| 1699 |
warn!("Shader warnings: {}", message); |
| 1700 |
} |
| 1701 |
} |
| 1702 |
|
| 1703 |
assert!(!library.is_null()); |
| 1704 |
Ok(Library::from_ptr(library)) |
| 1705 |
} |
| 1706 |
} |
| 1707 |
|
| 1708 |
pub fn new_library_with_file<P: AsRef<Path>>(&self, file: P) -> Result<Library, String> { |
| 1709 |
let filename = nsstring_from_str(file.as_ref().to_string_lossy().as_ref()); |
| 1710 |
unsafe { |
| 1711 |
let library: *mut MTLLibrary = try_objc! { err => |
| 1712 |
msg_send![self, newLibraryWithFile:filename.as_ref() |
| 1713 |
error:&mut err] |
| 1714 |
}; |
| 1715 |
Ok(Library::from_ptr(library)) |
| 1716 |
} |
| 1717 |
} |
| 1718 |
|
| 1719 |
pub fn new_library_with_data(&self, library_data: &[u8]) -> Result<Library, String> { |
| 1720 |
unsafe { |
| 1721 |
// SAFETY: |
| 1722 |
// `library_data` does not necessarily outlive the dispatch data |
| 1723 |
// in which it will be contained (since the dispatch data will be |
| 1724 |
// contained in the MTLLibrary returned by this function). |
| 1725 |
// |
| 1726 |
// To prevent the MTLLibrary from referencing the data outside of |
| 1727 |
// its lifetime, we use DISPATCH_DATA_DESTRUCTOR_DEFAULT as the |
| 1728 |
// destructor block, which will make `dispatch_data_create` copy |
| 1729 |
// the buffer for us automatically. |
| 1730 |
let data = dispatch_data_create( |
| 1731 |
library_data.as_ptr().cast(), |
| 1732 |
library_data.len() as crate::c_size_t, |
| 1733 |
&raw mut _dispatch_main_q, |
| 1734 |
DISPATCH_DATA_DESTRUCTOR_DEFAULT, |
| 1735 |
); |
| 1736 |
|
| 1737 |
let library: *mut MTLLibrary = try_objc! { err => |
| 1738 |
msg_send![self, newLibraryWithData:data |
| 1739 |
error:&mut err] |
| 1740 |
}; |
| 1741 |
dispatch_release(data); |
| 1742 |
Ok(Library::from_ptr(library)) |
| 1743 |
} |
| 1744 |
} |
| 1745 |
|
| 1746 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1747 |
pub fn new_dynamic_library(&self, library: &LibraryRef) -> Result<DynamicLibrary, String> { |
| 1748 |
unsafe { |
| 1749 |
let mut err: *mut Object = ptr::null_mut(); |
| 1750 |
let dynamic_library: *mut MTLDynamicLibrary = msg_send![self, newDynamicLibrary:library |
| 1751 |
error:&mut err]; |
| 1752 |
if !err.is_null() { |
| 1753 |
// FIXME: copy pasta |
| 1754 |
let desc: *mut Object = msg_send![err, localizedDescription]; |
| 1755 |
let compile_error: *const c_char = msg_send![desc, UTF8String]; |
| 1756 |
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned(); |
| 1757 |
Err(message) |
| 1758 |
} else { |
| 1759 |
Ok(DynamicLibrary::from_ptr(dynamic_library)) |
| 1760 |
} |
| 1761 |
} |
| 1762 |
} |
| 1763 |
|
| 1764 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1765 |
pub fn new_dynamic_library_with_url(&self, url: &URLRef) -> Result<DynamicLibrary, String> { |
| 1766 |
unsafe { |
| 1767 |
let mut err: *mut Object = ptr::null_mut(); |
| 1768 |
let dynamic_library: *mut MTLDynamicLibrary = msg_send![self, newDynamicLibraryWithURL:url |
| 1769 |
error:&mut err]; |
| 1770 |
if !err.is_null() { |
| 1771 |
// FIXME: copy pasta |
| 1772 |
let desc: *mut Object = msg_send![err, localizedDescription]; |
| 1773 |
let compile_error: *const c_char = msg_send![desc, UTF8String]; |
| 1774 |
let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned(); |
| 1775 |
Err(message) |
| 1776 |
} else { |
| 1777 |
Ok(DynamicLibrary::from_ptr(dynamic_library)) |
| 1778 |
} |
| 1779 |
} |
| 1780 |
} |
| 1781 |
|
| 1782 |
/// Only available on (macos(11.0), ios(14.0)) |
| 1783 |
pub fn new_binary_archive_with_descriptor( |
| 1784 |
&self, |
| 1785 |
descriptor: &BinaryArchiveDescriptorRef, |
| 1786 |
) -> Result<BinaryArchive, String> { |
| 1787 |
unsafe { |
| 1788 |
let mut err: *mut Object = ptr::null_mut(); |
| 1789 |
let binary_archive: *mut MTLBinaryArchive = msg_send![self, newBinaryArchiveWithDescriptor:descriptor |
| 1790 |
error:&mut err]; |
| 1791 |
if !err.is_null() { |
| 1792 |
// TODO: copy pasta |
| 1793 |
let desc: *mut Object = msg_send![err, localizedDescription]; |
| 1794 |
let c_msg: *const c_char = msg_send![desc, UTF8String]; |
| 1795 |
let message = CStr::from_ptr(c_msg).to_string_lossy().into_owned(); |
| 1796 |
Err(message) |
| 1797 |
} else { |
| 1798 |
Ok(BinaryArchive::from_ptr(binary_archive)) |
| 1799 |
} |
| 1800 |
} |
| 1801 |
} |
| 1802 |
|
| 1803 |
/// Synchronously creates a render pipeline state object and associated reflection information. |
| 1804 |
pub fn new_render_pipeline_state_with_reflection( |
| 1805 |
&self, |
| 1806 |
descriptor: &RenderPipelineDescriptorRef, |
| 1807 |
reflection_options: MTLPipelineOption, |
| 1808 |
) -> Result<(RenderPipelineState, RenderPipelineReflection), String> { |
| 1809 |
unsafe { |
| 1810 |
let mut reflection: *mut Object = ptr::null_mut(); |
| 1811 |
let pipeline_state: *mut MTLRenderPipelineState = try_objc! { err => |
| 1812 |
msg_send![self, newRenderPipelineStateWithDescriptor:descriptor |
| 1813 |
options:reflection_options |
| 1814 |
reflection:&mut reflection |
| 1815 |
error:&mut err] |
| 1816 |
}; |
| 1817 |
|
| 1818 |
let state = RenderPipelineState::from_ptr(pipeline_state); |
| 1819 |
|
| 1820 |
let () = msg_send![reflection, retain]; |
| 1821 |
let reflection = RenderPipelineReflection::from_ptr(reflection as _); |
| 1822 |
|
| 1823 |
Ok((state, reflection)) |
| 1824 |
} |
| 1825 |
} |
| 1826 |
|
| 1827 |
pub fn new_render_pipeline_state( |
| 1828 |
&self, |
| 1829 |
descriptor: &RenderPipelineDescriptorRef, |
| 1830 |
) -> Result<RenderPipelineState, String> { |
| 1831 |
unsafe { |
| 1832 |
let pipeline_state: *mut MTLRenderPipelineState = try_objc! { err => |
| 1833 |
msg_send![self, newRenderPipelineStateWithDescriptor:descriptor |
| 1834 |
error:&mut err] |
| 1835 |
}; |
| 1836 |
|
| 1837 |
Ok(RenderPipelineState::from_ptr(pipeline_state)) |
| 1838 |
} |
| 1839 |
} |
| 1840 |
|
| 1841 |
/// Only available on (macos(13.0), ios(16.0)) |
| 1842 |
pub fn new_mesh_render_pipeline_state_with_reflection( |
| 1843 |
&self, |
| 1844 |
descriptor: &MeshRenderPipelineDescriptorRef, |
| 1845 |
reflection_options: MTLPipelineOption, |
| 1846 |
) -> Result<(RenderPipelineState, RenderPipelineReflection), String> { |
| 1847 |
unsafe { |
| 1848 |
let mut reflection: *mut Object = ptr::null_mut(); |
| 1849 |
let pipeline_state: *mut MTLRenderPipelineState = try_objc! { err => |
| 1850 |
msg_send![self, newRenderPipelineStateWithMeshDescriptor:descriptor |
| 1851 |
options:reflection_options |
| 1852 |
reflection:&mut reflection |
| 1853 |
error:&mut err] |
| 1854 |
}; |
| 1855 |
|
| 1856 |
let state = RenderPipelineState::from_ptr(pipeline_state); |
| 1857 |
|
| 1858 |
let () = msg_send![reflection, retain]; |
| 1859 |
let reflection = RenderPipelineReflection::from_ptr(reflection as _); |
| 1860 |
|
| 1861 |
Ok((state, reflection)) |
| 1862 |
} |
| 1863 |
} |
| 1864 |
|
| 1865 |
/// Only available on (macos(13.0), ios(16.0)) |
| 1866 |
pub fn new_mesh_render_pipeline_state( |
| 1867 |
&self, |
| 1868 |
descriptor: &MeshRenderPipelineDescriptorRef, |
| 1869 |
) -> Result<RenderPipelineState, String> { |
| 1870 |
unsafe { |
| 1871 |
let pipeline_state: *mut MTLRenderPipelineState = try_objc! { err => |
| 1872 |
msg_send![self, newRenderPipelineStateWithMeshDescriptor:descriptor |
| 1873 |
error:&mut err] |
| 1874 |
}; |
| 1875 |
|
| 1876 |
Ok(RenderPipelineState::from_ptr(pipeline_state)) |
| 1877 |
} |
| 1878 |
} |
| 1879 |
|
| 1880 |
pub fn new_compute_pipeline_state_with_function( |
| 1881 |
&self, |
| 1882 |
function: &FunctionRef, |
| 1883 |
) -> Result<ComputePipelineState, String> { |
| 1884 |
unsafe { |
| 1885 |
let pipeline_state: *mut MTLComputePipelineState = try_objc! { err => |
| 1886 |
msg_send![self, newComputePipelineStateWithFunction:function |
| 1887 |
error:&mut err] |
| 1888 |
}; |
| 1889 |
|
| 1890 |
Ok(ComputePipelineState::from_ptr(pipeline_state)) |
| 1891 |
} |
| 1892 |
} |
| 1893 |
|
| 1894 |
pub fn new_compute_pipeline_state( |
| 1895 |
&self, |
| 1896 |
descriptor: &ComputePipelineDescriptorRef, |
| 1897 |
) -> Result<ComputePipelineState, String> { |
| 1898 |
unsafe { |
| 1899 |
let pipeline_state: *mut MTLComputePipelineState = try_objc! { err => |
| 1900 |
msg_send![self, newComputePipelineStateWithDescriptor:descriptor |
| 1901 |
error:&mut err] |
| 1902 |
}; |
| 1903 |
|
| 1904 |
Ok(ComputePipelineState::from_ptr(pipeline_state)) |
| 1905 |
} |
| 1906 |
} |
| 1907 |
|
| 1908 |
/// Synchronously creates a compute pipeline state object and associated reflection information, |
| 1909 |
/// using a compute pipeline descriptor. |
| 1910 |
pub fn new_compute_pipeline_state_with_reflection( |
| 1911 |
&self, |
| 1912 |
descriptor: &ComputePipelineDescriptorRef, |
| 1913 |
reflection_options: MTLPipelineOption, |
| 1914 |
) -> Result<(ComputePipelineState, ComputePipelineReflection), String> { |
| 1915 |
unsafe { |
| 1916 |
let mut reflection: *mut Object = ptr::null_mut(); |
| 1917 |
let pipeline_state: *mut MTLComputePipelineState = try_objc! { err => |
| 1918 |
msg_send![self, newComputePipelineStateWithDescriptor:descriptor |
| 1919 |
options:reflection_options |
| 1920 |
reflection:&mut reflection |
| 1921 |
error:&mut err] |
| 1922 |
}; |
| 1923 |
|
| 1924 |
let state = ComputePipelineState::from_ptr(pipeline_state); |
| 1925 |
|
| 1926 |
let () = msg_send![reflection, retain]; |
| 1927 |
let reflection = ComputePipelineReflection::from_ptr(reflection as _); |
| 1928 |
|
| 1929 |
Ok((state, reflection)) |
| 1930 |
} |
| 1931 |
} |
| 1932 |
|
| 1933 |
pub fn new_buffer(&self, length: u64, options: MTLResourceOptions) -> Buffer { |
| 1934 |
unsafe { |
| 1935 |
msg_send![self, newBufferWithLength:length |
| 1936 |
options:options] |
| 1937 |
} |
| 1938 |
} |
| 1939 |
|
| 1940 |
pub fn new_buffer_with_bytes_no_copy( |
| 1941 |
&self, |
| 1942 |
bytes: *const std::ffi::c_void, |
| 1943 |
length: NSUInteger, |
| 1944 |
options: MTLResourceOptions, |
| 1945 |
deallocator: Option<&Block<(*const std::ffi::c_void, NSUInteger), ()>>, |
| 1946 |
) -> Buffer { |
| 1947 |
unsafe { |
| 1948 |
msg_send![self, newBufferWithBytesNoCopy:bytes |
| 1949 |
length:length |
| 1950 |
options:options |
| 1951 |
deallocator:deallocator] |
| 1952 |
} |
| 1953 |
} |
| 1954 |
|
| 1955 |
pub fn new_buffer_with_data( |
| 1956 |
&self, |
| 1957 |
bytes: *const std::ffi::c_void, |
| 1958 |
length: NSUInteger, |
| 1959 |
options: MTLResourceOptions, |
| 1960 |
) -> Buffer { |
| 1961 |
unsafe { |
| 1962 |
msg_send![self, newBufferWithBytes:bytes |
| 1963 |
length:length |
| 1964 |
options:options] |
| 1965 |
} |
| 1966 |
} |
| 1967 |
|
| 1968 |
pub fn new_counter_sample_buffer_with_descriptor( |
| 1969 |
&self, |
| 1970 |
descriptor: &CounterSampleBufferDescriptorRef, |
| 1971 |
) -> Result<CounterSampleBuffer, String> { |
| 1972 |
unsafe { |
| 1973 |
let counter_sample_buffer: *mut MTLCounterSampleBuffer = try_objc! { err => |
| 1974 |
msg_send![self, newCounterSampleBufferWithDescriptor: descriptor error:&mut err] |
| 1975 |
}; |
| 1976 |
|
| 1977 |
assert!(!counter_sample_buffer.is_null()); |
| 1978 |
Ok(CounterSampleBuffer::from_ptr(counter_sample_buffer)) |
| 1979 |
} |
| 1980 |
} |
| 1981 |
|
| 1982 |
pub fn new_indirect_command_buffer_with_descriptor( |
| 1983 |
&self, |
| 1984 |
descriptor: &IndirectCommandBufferDescriptorRef, |
| 1985 |
max_command_count: NSUInteger, |
| 1986 |
options: MTLResourceOptions, |
| 1987 |
) -> IndirectCommandBuffer { |
| 1988 |
unsafe { |
| 1989 |
msg_send![self, newIndirectCommandBufferWithDescriptor:descriptor |
| 1990 |
maxCommandCount:max_command_count |
| 1991 |
options:options] |
| 1992 |
} |
| 1993 |
} |
| 1994 |
|
| 1995 |
pub fn new_texture(&self, descriptor: &TextureDescriptorRef) -> Texture { |
| 1996 |
unsafe { msg_send![self, newTextureWithDescriptor: descriptor] } |
| 1997 |
} |
| 1998 |
|
| 1999 |
pub fn new_sampler(&self, descriptor: &SamplerDescriptorRef) -> SamplerState { |
| 2000 |
unsafe { msg_send![self, newSamplerStateWithDescriptor: descriptor] } |
| 2001 |
} |
| 2002 |
|
| 2003 |
pub fn new_depth_stencil_state( |
| 2004 |
&self, |
| 2005 |
descriptor: &DepthStencilDescriptorRef, |
| 2006 |
) -> DepthStencilState { |
| 2007 |
unsafe { msg_send![self, newDepthStencilStateWithDescriptor: descriptor] } |
| 2008 |
} |
| 2009 |
|
| 2010 |
pub fn argument_buffers_support(&self) -> MTLArgumentBuffersTier { |
| 2011 |
unsafe { msg_send![self, argumentBuffersSupport] } |
| 2012 |
} |
| 2013 |
|
| 2014 |
pub fn read_write_texture_support(&self) -> MTLReadWriteTextureTier { |
| 2015 |
unsafe { msg_send![self, readWriteTextureSupport] } |
| 2016 |
} |
| 2017 |
|
| 2018 |
pub fn raster_order_groups_supported(&self) -> bool { |
| 2019 |
unsafe { msg_send_bool![self, rasterOrderGroupsSupported] } |
| 2020 |
} |
| 2021 |
|
| 2022 |
/// Only available on (macos(11.0), ios(14.0)) |
| 2023 |
pub fn supports_32bit_float_filtering(&self) -> bool { |
| 2024 |
unsafe { msg_send_bool![self, supports32BitFloatFiltering] } |
| 2025 |
} |
| 2026 |
|
| 2027 |
/// Only available on (macos(11.0), ios(14.0)) |
| 2028 |
pub fn supports_32bit_MSAA(&self) -> bool { |
| 2029 |
unsafe { msg_send_bool![self, supports32BitMSAA] } |
| 2030 |
} |
| 2031 |
|
| 2032 |
/// Only available on (macos(11.0), ios(14.0)) |
| 2033 |
pub fn supports_query_texture_LOD(&self) -> bool { |
| 2034 |
unsafe { msg_send_bool![self, supportsQueryTextureLOD] } |
| 2035 |
} |
| 2036 |
|
| 2037 |
/// Only available on (macos(11.0), ios(14.0)) |
| 2038 |
pub fn supports_BC_texture_compression(&self) -> bool { |
| 2039 |
unsafe { msg_send_bool![self, supportsBCTextureCompression] } |
| 2040 |
} |
| 2041 |
|
| 2042 |
/// Only available on (macos(11.0), ios(14.0)) |
| 2043 |
pub fn supports_pull_model_interpolation(&self) -> bool { |
| 2044 |
unsafe { msg_send_bool![self, supportsPullModelInterpolation] } |
| 2045 |
} |
| 2046 |
|
| 2047 |
pub fn new_argument_encoder( |
| 2048 |
&self, |
| 2049 |
arguments: &ArrayRef<ArgumentDescriptor>, |
| 2050 |
) -> ArgumentEncoder { |
| 2051 |
unsafe { msg_send![self, newArgumentEncoderWithArguments: arguments] } |
| 2052 |
} |
| 2053 |
|
| 2054 |
pub fn new_heap(&self, descriptor: &HeapDescriptorRef) -> Heap { |
| 2055 |
unsafe { msg_send![self, newHeapWithDescriptor: descriptor] } |
| 2056 |
} |
| 2057 |
|
| 2058 |
pub fn new_event(&self) -> Event { |
| 2059 |
unsafe { msg_send![self, newEvent] } |
| 2060 |
} |
| 2061 |
|
| 2062 |
pub fn new_shared_event(&self) -> SharedEvent { |
| 2063 |
unsafe { msg_send![self, newSharedEvent] } |
| 2064 |
} |
| 2065 |
|
| 2066 |
pub fn heap_buffer_size_and_align( |
| 2067 |
&self, |
| 2068 |
length: NSUInteger, |
| 2069 |
options: MTLResourceOptions, |
| 2070 |
) -> MTLSizeAndAlign { |
| 2071 |
unsafe { msg_send![self, heapBufferSizeAndAlignWithLength: length options: options] } |
| 2072 |
} |
| 2073 |
|
| 2074 |
/// Only available on macos(13.0), ios(16.0) |
| 2075 |
pub fn heap_acceleration_structure_size_and_align_with_size( |
| 2076 |
&self, |
| 2077 |
size: NSUInteger, |
| 2078 |
) -> MTLSizeAndAlign { |
| 2079 |
unsafe { msg_send![self, heapAccelerationStructureSizeAndAlignWithSize: size] } |
| 2080 |
} |
| 2081 |
|
| 2082 |
pub fn heap_texture_size_and_align( |
| 2083 |
&self, |
| 2084 |
descriptor: &TextureDescriptorRef, |
| 2085 |
) -> MTLSizeAndAlign { |
| 2086 |
unsafe { msg_send![self, heapTextureSizeAndAlignWithDescriptor: descriptor] } |
| 2087 |
} |
| 2088 |
|
| 2089 |
pub fn minimum_linear_texture_alignment_for_pixel_format( |
| 2090 |
&self, |
| 2091 |
format: MTLPixelFormat, |
| 2092 |
) -> NSUInteger { |
| 2093 |
unsafe { msg_send![self, minimumLinearTextureAlignmentForPixelFormat: format] } |
| 2094 |
} |
| 2095 |
|
| 2096 |
pub fn minimum_texture_buffer_alignment_for_pixel_format( |
| 2097 |
&self, |
| 2098 |
format: MTLPixelFormat, |
| 2099 |
) -> NSUInteger { |
| 2100 |
unsafe { msg_send![self, minimumTextureBufferAlignmentForPixelFormat: format] } |
| 2101 |
} |
| 2102 |
|
| 2103 |
pub fn max_argument_buffer_sampler_count(&self) -> NSUInteger { |
| 2104 |
unsafe { msg_send![self, maxArgumentBufferSamplerCount] } |
| 2105 |
} |
| 2106 |
|
| 2107 |
pub fn current_allocated_size(&self) -> NSUInteger { |
| 2108 |
unsafe { msg_send![self, currentAllocatedSize] } |
| 2109 |
} |
| 2110 |
|
| 2111 |
/// Only available on (macos(10.14), ios(12.0), tvos(12.0)) |
| 2112 |
pub fn max_buffer_length(&self) -> NSUInteger { |
| 2113 |
unsafe { msg_send![self, maxBufferLength] } |
| 2114 |
} |
| 2115 |
|
| 2116 |
pub fn acceleration_structure_sizes_with_descriptor( |
| 2117 |
&self, |
| 2118 |
desc: &AccelerationStructureDescriptorRef, |
| 2119 |
) -> MTLAccelerationStructureSizes { |
| 2120 |
unsafe { msg_send![self, accelerationStructureSizesWithDescriptor: desc] } |
| 2121 |
} |
| 2122 |
|
| 2123 |
pub fn new_acceleration_structure_with_size(&self, size: NSUInteger) -> AccelerationStructure { |
| 2124 |
unsafe { msg_send![self, newAccelerationStructureWithSize: size] } |
| 2125 |
} |
| 2126 |
|
| 2127 |
pub fn sample_timestamps(&self, cpu_timestamp: &mut u64, gpu_timestamp: &mut u64) { |
| 2128 |
unsafe { msg_send![self, sampleTimestamps: cpu_timestamp gpuTimestamp: gpu_timestamp] } |
| 2129 |
} |
| 2130 |
|
| 2131 |
pub fn counter_sets(&self) -> Vec<CounterSet> { |
| 2132 |
unsafe { |
| 2133 |
let counter_sets: *mut Object = msg_send![self, counterSets]; |
| 2134 |
let count: NSUInteger = msg_send![counter_sets, count]; |
| 2135 |
(0..count) |
| 2136 |
.map(|i| { |
| 2137 |
let csp: *mut MTLCounterSet = msg_send![counter_sets, objectAtIndex: i]; |
| 2138 |
let () = msg_send![csp, retain]; |
| 2139 |
CounterSet::from_ptr(csp) |
| 2140 |
}) |
| 2141 |
.collect() |
| 2142 |
} |
| 2143 |
} |
| 2144 |
} |