diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 12f111006..c4f102a01 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -4,8 +4,8 @@ The Metal API on Vulkan, with one path for every device. It replaces `metal2vulk takes its name when it does; until then it is unpublished. Its public API so far: the instance and the device, memory blocks and the buffers in them, the -grants of texture and sampler indices, command queues, command buffers and events, the device's -counters, and `floor`, the check of a Vulkan device against the floor below. +grants of texture and sampler indices, textures, command queues, command buffers and events, the +device's counters, and `floor`, the check of a Vulkan device against the floor below. ## Instance and device @@ -139,7 +139,76 @@ made, with no lock, and never rewritten for layouts. one index valid in both texture arrays; other textures 4,096 to 65,535; samplers 1 to 3,999. Index 0 is nil and never granted. A range that is empty or leaves its class's is `Limit::IndexRange`, and one holding an index granted already `Refusal::IndicesGranted`. - `Device::release_indices` returns a grant; one not granted is `Refusal::IndicesNotGranted`. + `Device::release_indices` returns a grant; one not granted is `Refusal::IndicesNotGranted`, and + one where an object still lives `Refusal::IndicesInUse`. +- An index holds one object at a time: making one where another lives is `Refusal::IndexInUse`, + and at an index not granted `Refusal::IndicesNotGranted`. The index is free again once the + object's last handle is gone, and with it the last command buffer that used it; its elements + read their default again from then. + +## Textures + +- `Device::new_texture(descriptor, index)` is `newTextureWithDescriptor:` at `index`: an + optimal-tiling image of the descriptor in device-local memory of its own (a dedicated + allocation), its contents undefined, as Metal's are. `index` is given exactly where shaders + reach the texture, shader-read or shader-write usage (`Refusal::TextureIndex` otherwise), from + a live grant of the class the usage picks: `IndexClass::StorageTexture` with shader-write + usage, else `IndexClass::Texture`. `TextureUsage` with no bits is Metal's unknown usage: shader + read and write, render target and pixel-format view. +- The image's usage is the descriptor's plus transfer source and destination. Its home layout is + general where it has a storage element, shader-read-only where shaders only read it, and the + attachment layout where only render passes use it. Its elements of set 1 are written before the + call returns, with that layout, and never rewritten; the upload moves the image from undefined + to home ahead of every command buffer committed after the call. +- The sampled element's view is the format's, through its component mapping with the + descriptor's swizzle composed over it; a depth or stencil format's view takes its depth, else + its stencil. The storage element is written where the usage has shader write and the device + stores the format through a storage image declared without a format; its view maps each + channel to itself. +- A format is made where the translator's format table maps it for the usage on the device + (`vk_format`) to the format itself or to one whose view gives Metal's values (a swizzled or + rotated view, alpha held in red, an RGBX format, a depth or stencil aspect of a combined + format), and the device's image format query takes the image. Elsewhere it is + `Gap::TextureFormat`: the shaders of the identity domains read a texture through its view alone, + so a format whose texels the shader converts (extended range, bfloat, YCbCr, decoded, + copies-only, 24-bit depth held as 32-bit float) is not made. Past the query's extent, layers or + sample counts it is `Limit::TextureSize` or `Limit::TextureSamples`. +- Refused as Metal refuses each descriptor (`Refusal::TextureZeroExtent`, + `TextureExtentForType`, `TextureCubeNotSquare`, `TextureArrayLength`, `TextureLevelCount`, + `TextureSampleCount`, `TextureSwizzleWithWrites`). Texture buffers (`Gap::TextureBuffer`) and + Memoryless storage (`Gap::MemorylessTexture`) are not built. +- `Texture::gpu_resource_id` is its index (0 without one) and the translator's `TextureWord` of + its format and swizzle (`docs/RESOURCE-ID.md`), so the guest computes the ID itself. +- `Texture::replace_region` and `Texture::get_bytes` take a Shared or Managed texture + (`Refusal::TextureBytesPrivate` otherwise), a region inside a level and slice on the format's + block grid (`Refusal::TextureRegion`), and rows and images apart as Metal's calls take them, + a compressed format's rows being rows of blocks (`Refusal::TextureBytesLayout` where they + overlap or the bytes are too few). `replace_region` copies the bytes into a staging buffer + before it returns, and the upload copies them into the image, leaving home for the transfer + layout and coming back, ahead of every command buffer committed after the call. `get_bytes` + records the copy out into the upload, submits it at once, waits for it and copies the bytes + out; as in Metal, the program has waited for the work that writes the texture. +- A texture holds the device. Once its last handle and the last command buffer that used it are + gone, its elements read null and its index is free at once; the reaper frees its image once the + last upload that moves or copies it has retired. `Gauges::textures` counts images until then, + `Gauges::descriptor_slots` the indices held. + +### Known gaps of textures + +- `replace_region` and `get_bytes` go through a staging buffer: a copy Metal does not make, in + memory of its own for each call, counted in `Metrics::bytes_copied`. +- A texture whose format the device does not store through a storage image without a format has + no storage element, so a shader write through its index is dropped, as a write to a nil + texture is. +- `replace_region` takes no bytes into a 32-bit float depth (`Gap::FloatDepthUpload`): Metal + keeps any `float` there, Vulkan copies no depth outside `[0, 1]` into a depth aspect without + `VK_EXT_depth_range_unrestricted` (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which the floor + does not require, and no recorded stream uploads one. +- Their bytes are not copied for a format of depth and stencil both or a multisample texture + (`Gap::TextureBytes`). +- A texture's memory is device-local; where the device has none left, the call fails + (`Error::Vulkan`). +- Texture views, heap textures and textures over a swapchain image are not built yet. ## Queues, command buffers and events @@ -218,7 +287,9 @@ that touch blocks first. - Values the runtime reads back from GPU-written memory decide nothing beyond the reading command buffer's own results (`src/readback.rs`; a rule test holds every such read there). The sites: the two timestamp queries of a command buffer, which decide only its `gpu_start_time`, through - arithmetic defined for every value and never later than its `gpu_end_time`. The parameter ring + arithmetic defined for every value and never later than its `gpu_end_time`; and + `Texture::get_bytes`'s copy out of its staging buffer, whose bytes reach only the caller's + buffer, at offsets and lengths from the call's checked region. The parameter ring and an indirect dispatch's arguments are read only by the GPU: the runtime writes the ring and never reads it back, and never reads the arguments. - Guest processes are not isolated from each other. One device serves every guest process, and diff --git a/crates/metal2vulkan-rt/src/arrays.rs b/crates/metal2vulkan-rt/src/arrays.rs index 73cbb46d4..afef596d5 100644 --- a/crates/metal2vulkan-rt/src/arrays.rs +++ b/crates/metal2vulkan-rt/src/arrays.rs @@ -92,34 +92,92 @@ impl IndexGrant { } } -/// The indices granted, one bit per index of each class's array. -pub(crate) struct Grants { - granted: [Vec; 3], +/// No Metal counterpart: `MTLResourceID`, a texture's or a sampler state's `gpuResourceID`: its +/// index in the low word and the translator's word in the high (`docs/RESOURCE-ID.md`). The guest +/// computes the word from the Metal descriptor alone, so it needs no round trip for it. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub struct ResourceId { + /// The index in its class's arrays; 0 for nil. + pub index: u32, + /// The word: a texture's `TextureWord`, a sampler's `SamplerWord`. + pub word: u32, } -impl Grants { - pub(crate) fn new() -> Grants { - let words = |len: u32| vec![0; len.div_ceil(64) as usize]; - Grants { - granted: [ - words(SAMPLED_IMAGES), - words(STORAGE_IMAGES), - words(SAMPLERS), - ], - } +impl ResourceId { + /// `MTLResourceID`'s 64-bit value: `index | word << 32`. + pub fn to_bits(self) -> u64 { + u64::from(self.index) | u64::from(self.word) << 32 + } +} + +/// One bit per index of a class's array. +struct Bits(Vec); + +impl Bits { + fn new(len: u32) -> Bits { + Bits(vec![0; len.div_ceil(64) as usize]) } - fn bit(&self, class: IndexClass, index: u32) -> bool { - self.granted[class.slot()][(index / 64) as usize] & (1 << (index % 64)) != 0 + fn get(&self, index: u32) -> bool { + self.0[(index / 64) as usize] & (1 << (index % 64)) != 0 } - fn set(&mut self, class: IndexClass, index: u32, on: bool) { - let word = &mut self.granted[class.slot()][(index / 64) as usize]; + fn put(&mut self, index: u32, on: bool) { + let word = &mut self.0[(index / 64) as usize]; match on { true => *word |= 1 << (index % 64), false => *word &= !(1 << (index % 64)), } } +} + +/// The indices granted, and of those the indices an object lives at, one bit per index of each +/// class's array. +pub(crate) struct Grants { + granted: [Bits; 3], + occupied: [Bits; 3], +} + +impl Grants { + pub(crate) fn new() -> Grants { + let bits = || { + [ + Bits::new(SAMPLED_IMAGES), + Bits::new(STORAGE_IMAGES), + Bits::new(SAMPLERS), + ] + }; + Grants { + granted: bits(), + occupied: bits(), + } + } + + fn bit(&self, class: IndexClass, index: u32) -> bool { + self.granted[class.slot()].get(index) + } + + fn set(&mut self, class: IndexClass, index: u32, on: bool) { + self.granted[class.slot()].put(index, on); + } + + /// Takes `index` of `class` for an object, where it is granted and no object lives there. + pub(crate) fn occupy(&mut self, class: IndexClass, index: u32) -> Result<(), Error> { + if !class.range().contains(&index) || !self.bit(class, index) { + return Err(Error::Refused(Refusal::IndicesNotGranted { class, index })); + } + let occupied = &mut self.occupied[class.slot()]; + if occupied.get(index) { + return Err(Error::Refused(Refusal::IndexInUse { class, index })); + } + occupied.put(index, true); + Ok(()) + } + + /// Gives back `index` of `class`, which [`Grants::occupy`] took. + pub(crate) fn vacate(&mut self, class: IndexClass, index: u32) { + self.occupied[class.slot()].put(index, false); + } /// Grants `first..first + count` of `class` where the range is inside the class's and none of /// it is granted. @@ -154,7 +212,7 @@ impl Grants { Ok(grant) } - /// Returns `grant`, where every index of it is granted. + /// Returns `grant`, where every index of it is granted and no object lives at one. pub(crate) fn release(&mut self, grant: IndexGrant) -> Result<(), Error> { let IndexGrant { class, .. } = grant; let range = class.range(); @@ -170,6 +228,10 @@ impl Grants { if let Some(index) = missing { return Err(Error::Refused(Refusal::IndicesNotGranted { class, index })); } + let occupied = &self.occupied[class.slot()]; + if let Some(index) = grant.indices().find(|&index| occupied.get(index)) { + return Err(Error::Refused(Refusal::IndicesInUse { class, index })); + } for index in grant.indices() { self.set(class, index, false); } @@ -185,6 +247,8 @@ pub(crate) struct Arrays { layout: vk::DescriptorSetLayout, /// The pool of the one set, which destroying it frees. pool: vk::DescriptorPool, + /// The one set. + set: vk::DescriptorSet, /// The default sampler of the plain and integer-texture arrays. pub(crate) plain: vk::Sampler, /// The default sampler of the comparison array. @@ -215,6 +279,58 @@ impl Arrays { [self.empty, self.layout] } + /// Writes a texture's elements at `index` of `class`: the sampled-texture array's with + /// `sampled` and its layout, and for a storage-capable texture the storage-texture array's + /// with `storage`; a null descriptor where a view is `None`. + /// + /// # Safety + /// + /// The caller owns the elements (the index is occupied for it, or is being vacated by it), and + /// each view is live and of the device, of an image in that layout whenever work uses it. + pub(crate) unsafe fn write_texture( + &self, + device: &ash::Device, + class: IndexClass, + index: u32, + sampled: Option<(vk::ImageView, vk::ImageLayout)>, + storage: Option, + ) { + let (view, layout) = sampled.unwrap_or(( + vk::ImageView::null(), + vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + )); + let sampled = [vk::DescriptorImageInfo::default() + .image_view(view) + .image_layout(layout)]; + let storage = [vk::DescriptorImageInfo::default() + .image_view(storage.unwrap_or_default()) + .image_layout(vk::ImageLayout::GENERAL)]; + let writes = [ + write( + self.set, + SAMPLED_BINDING, + vk::DescriptorType::SAMPLED_IMAGE, + &sampled, + ) + .dst_array_element(index), + write( + self.set, + STORAGE_BINDING, + vk::DescriptorType::STORAGE_IMAGE, + &storage, + ) + .dst_array_element(index), + ]; + let count = match class { + IndexClass::StorageTexture => 2, + _ => 1, + }; + // SAFETY: the caller's contract; the bindings are update-after-bind and + // update-unused-while-pending, so elements of other owners may be written meanwhile, and + // a null image view is a null descriptor under `nullDescriptor`. + unsafe { device.update_descriptor_sets(&writes[..count], &[]) }; + } + /// Destroys set 1. /// /// # Safety @@ -351,6 +467,7 @@ impl Made { empty, layout, pool, + set, plain, compare, grants: Mutex::new(Grants::new()), @@ -402,18 +519,6 @@ unsafe fn fill( let samplers = |sampler| vec![vk::DescriptorImageInfo::default().sampler(sampler); SAMPLERS as usize]; let (plains, compares) = (samplers(plain), samplers(compare)); - fn write( - set: vk::DescriptorSet, - binding: u32, - ty: vk::DescriptorType, - infos: &[vk::DescriptorImageInfo], - ) -> vk::WriteDescriptorSet<'_> { - vk::WriteDescriptorSet::default() - .dst_set(set) - .dst_binding(binding) - .descriptor_type(ty) - .image_info(infos) - } let writes = [ write( set, @@ -451,6 +556,20 @@ unsafe fn fill( unsafe { device.update_descriptor_sets(&writes, &[]) }; } +/// The write of `infos` into `binding` of `set`, from its first element. +fn write( + set: vk::DescriptorSet, + binding: u32, + ty: vk::DescriptorType, + infos: &[vk::DescriptorImageInfo], +) -> vk::WriteDescriptorSet<'_> { + vk::WriteDescriptorSet::default() + .dst_set(set) + .dst_binding(binding) + .descriptor_type(ty) + .image_info(infos) +} + impl Device { /// No Metal counterpart: grants the consumer `first..first + count` of `class`, the range it /// names, so the resource IDs it chooses from it reproduce in replay. A texture or a sampler @@ -472,7 +591,9 @@ impl Device { /// No Metal counterpart: returns a grant [`Device::grant_indices`] made, so its indices may be /// granted again. /// - /// Err: [`Refusal::IndicesNotGranted`] where one of its indices is not granted. + /// Err: [`Refusal::IndicesNotGranted`] where one of its indices is not granted; + /// [`Refusal::IndicesInUse`] where a texture or a sampler state lives at one, until its last + /// handle is gone. pub fn release_indices(&self, grant: IndexGrant) -> Result<(), Error> { lock(&self.core().arrays.grants).release(grant) } diff --git a/crates/metal2vulkan-rt/src/counters.rs b/crates/metal2vulkan-rt/src/counters.rs index adb554ed6..131102c9b 100644 --- a/crates/metal2vulkan-rt/src/counters.rs +++ b/crates/metal2vulkan-rt/src/counters.rs @@ -30,6 +30,10 @@ pub(crate) enum Metric { pub(crate) enum Gauge { /// [`Gauges::buffers`]. Buffers, + /// [`Gauges::textures`]. + Textures, + /// [`Gauges::descriptor_slots`]. + DescriptorSlots, /// [`Gauges::pipelines`]. Pipelines, /// [`Gauges::blocks`]. @@ -110,6 +114,11 @@ impl Counters { a.first_use_wait_max_nanos.fetch_max(nanos, Relaxed); } + /// `bytes` more copied for a call ([`Metrics::bytes_copied`]). + pub(crate) fn copied(&self, bytes: u64) { + self.atomics.bytes_copied.fetch_add(bytes, Relaxed); + } + /// One more live resource of `gauge`'s kind. pub(crate) fn rise(&self, gauge: Gauge) { self.gauge(gauge).fetch_add(1, Relaxed); @@ -124,6 +133,8 @@ impl Counters { let a = &self.atomics; match gauge { Gauge::Buffers => &a.buffers, + Gauge::Textures => &a.textures, + Gauge::DescriptorSlots => &a.descriptor_slots, Gauge::Pipelines => &a.pipelines, Gauge::Blocks => &a.blocks, Gauge::CommandBuffers => &a.command_buffers, @@ -215,7 +226,7 @@ pub struct Metrics { pub struct Gauges { /// Buffers. pub buffers: u64, - /// Textures, views included. + /// Textures: each one's image, its views and its memory, until the reaper frees them. pub textures: u64, /// Sampler states. pub samplers: u64, @@ -223,7 +234,7 @@ pub struct Gauges { pub pipelines: u64, /// Command buffers not yet retired. pub command_buffers: u64, - /// Occupied entries of the descriptor arrays. + /// Occupied indices of set 1's arrays: one for each texture made at an index. pub descriptor_slots: u64, /// Live `VkDeviceMemory` allocations: blocks the consumer holds, blocks ready or idle in the /// pool, and the runtime's own. diff --git a/crates/metal2vulkan-rt/src/device.rs b/crates/metal2vulkan-rt/src/device.rs index 05c549cec..551dfd50c 100644 --- a/crates/metal2vulkan-rt/src/device.rs +++ b/crates/metal2vulkan-rt/src/device.rs @@ -135,6 +135,9 @@ pub(crate) struct Core { consumer_features: Vec, pub(crate) queues: Queues, pub(crate) memory_types: floor::MemoryTypes, + /// The device-local memory types, one bit each: a texture's image takes the first its + /// requirements allow. + pub(crate) device_local: u32, unified_memory: bool, pub(crate) counters: Counters, /// What the device's timestamps count. @@ -371,6 +374,13 @@ impl Device { let max_block_len = vulkan11 .max_memory_allocation_size .min(vulkan13.max_buffer_size); + let device_local = (0u32..) + .zip(capabilities.memory.memory_types_as_slice()) + .filter(|(_, kind)| { + kind.property_flags + .contains(vk::MemoryPropertyFlags::DEVICE_LOCAL) + }) + .fold(0, |bits, (index, _)| bits | 1 << index); let core = Arc::new(Core { instance, @@ -381,6 +391,7 @@ impl Device { consumer_features, queues: Queues { runtime, present }, memory_types, + device_local, unified_memory, counters, ticks, @@ -875,6 +886,23 @@ pub(crate) struct ComputeLimits { impl Core { /// The memory type of a class's blocks. + /// What the device makes of an image of `info`'s format, type, tiling, usage and flags; + /// `None` where it makes none. + pub(crate) fn image_format_properties( + &self, + info: &vk::PhysicalDeviceImageFormatInfo2<'_>, + ) -> Option { + let mut properties = vk::ImageFormatProperties2::default(); + // SAFETY: the physical device is the instance's, which is Vulkan 1.3. + unsafe { + self.instance + .vk() + .get_physical_device_image_format_properties2(self.physical, info, &mut properties) + } + .ok() + .map(|()| properties.image_format_properties) + } + pub(crate) fn memory_type(&self, class: MemoryClass) -> u32 { match class { MemoryClass::Private => self.memory_types.private, diff --git a/crates/metal2vulkan-rt/src/error.rs b/crates/metal2vulkan-rt/src/error.rs index b1c6281dd..3a46dd6b6 100644 --- a/crates/metal2vulkan-rt/src/error.rs +++ b/crates/metal2vulkan-rt/src/error.rs @@ -4,6 +4,7 @@ use crate::arrays::IndexClass; use crate::floor::BelowFloor; use crate::memory::BlockId; use ash::vk; +use metal2vulkan::metal::PixelFormat; use std::{fmt, io}; /// What a failing call returns. @@ -160,6 +161,118 @@ pub enum Refusal { /// The first index of the range that is not granted. index: u32, }, + /// A texture at an index where a texture lives already + /// ([`Device::new_texture`](crate::Device::new_texture)). Metal has no counterpart: Metal + /// chooses its resource IDs itself. + /// + /// Basis: ours (an index names one object at a time, and its elements are that object's). + IndexInUse { + /// The class of the index. + class: IndexClass, + /// The index. + index: u32, + }, + /// A release of a grant while a texture lives at one of its indices + /// ([`Device::release_indices`](crate::Device::release_indices)). Metal has no counterpart. + /// + /// Basis: ours (an object's index stays granted while the object lives). + IndicesInUse { + /// The class of the index. + class: IndexClass, + /// The first index of the grant where an object lives. + index: u32, + }, + /// A texture whose usage shaders reach (read or write) made without an index, or one of no + /// such usage made with one ([`Device::new_texture`](crate::Device::new_texture)). Metal has + /// no counterpart: Metal gives every texture a resource ID itself. + /// + /// Basis: ours (an index is an element of set 1's texture arrays, which only shaders read). + TextureIndex { + /// The index given. + index: Option, + }, + /// A texture with a width, height or depth of 0. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts + /// "MTLTextureDescriptor has width of zero", and the same for a height of zero). + TextureZeroExtent, + /// A texture with a height other than 1 of a 1D type, or a depth other than 1 of a type that + /// is not 3D. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts "the texture type + /// MTLTextureType1D requires that height is 1", and the same for a 2D texture of depth 2). + TextureExtentForType, + /// A cube texture whose width and height differ. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts + /// "MTLTextureDescriptor width must equal height for cube textures"). + TextureCubeNotSquare, + /// A texture with an array length of 0, or other than 1 of a type that is not an array. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts + /// "MTLTextureDescriptor has arrayLength of zero", where an array length of 2 is made). + TextureArrayLength { + /// The array length asked for. + array_length: u32, + }, + /// A texture with a mipmap level count of 0, more than its full chain's, or more than 1 of a + /// multisample or 1D type. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts "requests 5 + /// mipmap levels, but the dimensions (8, 8, 1) can only support a maxiumum of 4 levels", and + /// the same for 0). + TextureLevelCount { + /// The levels asked for. + levels: u32, + /// The most the type and extent take. + max: u32, + }, + /// A texture with a sample count of 0, or other than 1 of a type that is not multisample. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts "has sampleCount + /// set but is using a type that does not allow sampleCount" for 0 and for 2 of a 2D texture). + TextureSampleCount { + /// The sample count asked for. + sample_count: u32, + }, + /// A texture with a swizzle other than each channel from itself and shader-write or + /// render-target usage. + /// + /// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: plain Metal asserts "Texture swizzling + /// is not compatable with MTLTextureUsageShaderWrite", where a swizzle of read usage alone is + /// made). + TextureSwizzleWithWrites, + /// [`Texture::replace_region`](crate::Texture::replace_region) or + /// [`Texture::get_bytes`](crate::Texture::get_bytes) of a Private or Memoryless texture. + /// + /// Basis: metal-documented (Apple's documentation of `MTLStorageModePrivate`: "The resource is + /// accessible only to the GPU."). + TextureBytesPrivate, + /// [`Texture::replace_region`](crate::Texture::replace_region) or + /// [`Texture::get_bytes`](crate::Texture::get_bytes) of a level or slice past the texture's, + /// or of a region that leaves the level or is off the format's block grid. + /// + /// Basis: ours (no texel of the texture is there to copy). + TextureRegion { + /// The level asked for. + level: u32, + /// The slice asked for. + slice: u32, + }, + /// [`Texture::replace_region`](crate::Texture::replace_region) or + /// [`Texture::get_bytes`](crate::Texture::get_bytes) with rows closer than a row of the + /// region, images closer than an image of it, or bytes too few for it. + /// + /// Basis: ours (the call would read or write past the bytes it is given, or one texel's + /// bytes over another's). + TextureBytesLayout { + /// The bytes from one row's start to the next's. + bytes_per_row: u64, + /// The bytes from one image's start to the next's. + bytes_per_image: u64, + /// The bytes given. + len: u64, + }, } /// A Metal feature the runtime does not build yet, with what it was asked. Each is refused until a @@ -214,6 +327,46 @@ pub enum Gap { /// The threadgroup size asked for. threads_per_threadgroup: [u32; 3], }, + /// A texture of `Memoryless` storage, which only render passes use. + /// + /// Basis: ours (render passes are not built). + MemorylessTexture, + /// A texture buffer (`MTLTextureTypeTextureBuffer`). + /// + /// Basis: ours (no texel-buffer array; no replay stream uses one). + TextureBuffer, + /// A texture of a pixel format the runtime makes no image of on this device for the + /// descriptor's usage: the device's format query lacks the format or one of the usages, or + /// the format's texels need a conversion in the shader that the translator's identity domains + /// do not make (an extended-range, bfloat, YCbCr, decoded or copies-only format, and 24-bit + /// depth held as 32-bit float depth). + /// + /// Basis: ours (the device's format query, or the identity domains' shaders read every + /// texture through its view alone). + TextureFormat { + /// The pixel format asked for. + pixel_format: PixelFormat, + }, + /// [`Texture::replace_region`](crate::Texture::replace_region) or + /// [`Texture::get_bytes`](crate::Texture::get_bytes) of a texture whose image is no plain + /// copy of Metal's bytes in one aspect: a format of depth and stencil both, or a multisample + /// texture. + /// + /// Basis: ours (no copy between such an image and bytes is built). + TextureBytes { + /// The texture's pixel format. + pixel_format: PixelFormat, + }, + /// [`Texture::replace_region`](crate::Texture::replace_region) into a 32-bit float depth + /// (`Depth32Float`). Metal keeps any `float` there; Vulkan copies no depth outside `[0, 1]` + /// into a depth aspect without `VK_EXT_depth_range_unrestricted`, which the floor does not + /// require (the Intel devices measured lack it), and no recorded stream uploads one. + /// + /// Basis: ours (no upload of a 32-bit float depth is built). + FloatDepthUpload { + /// The texture's pixel format. + pixel_format: PixelFormat, + }, } /// A limit a call ran into, with what it was asked. @@ -283,6 +436,30 @@ pub enum Limit { /// How many indices. count: u32, }, + /// A texture whose extent or array layers are past what the device makes of its format, + /// type, usage and sample count. A cube's layers are six a cube. + /// + /// Basis: device (the image format query's `maxExtent` and `maxArrayLayers`). + TextureSize { + /// The extent asked for. + extent: [u32; 3], + /// The array layers asked for. + layers: u32, + /// The device's most. + max_extent: [u32; 3], + /// The device's most layers. + max_layers: u32, + }, + /// A multisample texture of a sample count the device does not make for its format, type and + /// usage. + /// + /// Basis: device (the image format query's `sampleCounts`). + TextureSamples { + /// The sample count asked for. + sample_count: u32, + /// The counts the device makes, one bit each (`VkSampleCountFlags`). + counts: u32, + }, } impl Error { @@ -348,6 +525,54 @@ impl fmt::Display for Refusal { Refusal::IndicesNotGranted { class, index } => { write!(f, "{class:?} index {index} is not granted") } + Refusal::IndexInUse { class, index } => { + write!(f, "an object lives at {class:?} index {index} already") + } + Refusal::IndicesInUse { class, index } => { + write!(f, "an object lives at {class:?} index {index} of the grant") + } + Refusal::TextureIndex { index: Some(index) } => write!( + f, + "a texture no shader reaches takes no index, and {index} was given" + ), + Refusal::TextureIndex { index: None } => { + f.write_str("a texture shaders read or write takes an index, and none was given") + } + Refusal::TextureZeroExtent => f.write_str("a texture has a width, height or depth of 0"), + Refusal::TextureExtentForType => { + f.write_str("the texture's height or depth is not 1 where its type needs 1") + } + Refusal::TextureCubeNotSquare => f.write_str("a cube texture's width and height differ"), + Refusal::TextureArrayLength { array_length } => write!( + f, + "an array length of {array_length} does not suit the texture's type" + ), + Refusal::TextureLevelCount { levels, max } => write!( + f, + "{levels} mipmap levels are none or past the texture's {max}" + ), + Refusal::TextureSampleCount { sample_count } => write!( + f, + "a sample count of {sample_count} does not suit the texture's type" + ), + Refusal::TextureSwizzleWithWrites => { + f.write_str("a swizzled texture takes no shader-write or render-target usage") + } + Refusal::TextureBytesPrivate => { + f.write_str("the CPU reaches no Private or Memoryless texture") + } + Refusal::TextureRegion { level, slice } => write!( + f, + "the region of level {level}, slice {slice} is not inside the texture" + ), + Refusal::TextureBytesLayout { + bytes_per_row, + bytes_per_image, + len, + } => write!( + f, + "rows {bytes_per_row} and images {bytes_per_image} bytes apart in {len} bytes do not hold the region" + ), } } } @@ -375,6 +600,20 @@ impl fmt::Display for Gap { f, "a grid of {threads_per_grid:?} threads in threadgroups of {threads_per_threadgroup:?} ends in partial threadgroups, which this kernel's variant does not run" ), + Gap::MemorylessTexture => f.write_str("Memoryless textures are not built"), + Gap::TextureBuffer => f.write_str("texture buffers are not built"), + Gap::TextureFormat { pixel_format } => write!( + f, + "no texture of {pixel_format:?} is made on this device for the usage" + ), + Gap::TextureBytes { pixel_format } => write!( + f, + "bytes are not copied to or from this texture of {pixel_format:?}" + ), + Gap::FloatDepthUpload { pixel_format } => write!( + f, + "bytes are not uploaded into the 32-bit float depth of this texture of {pixel_format:?}" + ), } } } @@ -405,6 +644,22 @@ impl fmt::Display for Limit { f, "{count} {class:?} indices from {first} are none or leave the class's range" ), + Limit::TextureSize { + extent, + layers, + max_extent, + max_layers, + } => write!( + f, + "a texture of {extent:?} in {layers} layers is past the device's {max_extent:?} in {max_layers}" + ), + Limit::TextureSamples { + sample_count, + counts, + } => write!( + f, + "a sample count of {sample_count} is not among the device's ({counts:#x})" + ), } } } diff --git a/crates/metal2vulkan-rt/src/lib.rs b/crates/metal2vulkan-rt/src/lib.rs index efe8bd878..3513b4a20 100644 --- a/crates/metal2vulkan-rt/src/lib.rs +++ b/crates/metal2vulkan-rt/src/lib.rs @@ -33,9 +33,10 @@ mod ring; mod submit; #[cfg(test)] mod tests; +mod texture; mod times; -pub use arrays::{IndexClass, IndexGrant}; +pub use arrays::{IndexClass, IndexGrant, ResourceId}; pub use buffer::Buffer; pub use command::{CommandBuffer, CommandBufferError, CommandBufferStatus}; pub use counters::{Counters, Gauges, Metrics}; @@ -48,6 +49,11 @@ pub use instance::{Instance, PhysicalDevice}; pub use memory::{BlockId, BlockInfo, BlockMappings, MemoryClass, BLOCK_LEN}; /// `MTLLibrary`: the translator's, read from AIR or a metallib. pub use metal2vulkan::library::Library; +/// `MTLPixelFormat`, `MTLTextureType`, `MTLTextureUsage` and `MTLTextureSwizzleChannels` with its +/// `MTLTextureSwizzle`: the translator's. +pub use metal2vulkan::metal::{ + PixelFormat, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, +}; /// `MTLComputePipelineDescriptor`, its kernel, and a pipeline's precision notes: the /// translator's. pub use metal2vulkan::pipeline::{ @@ -55,4 +61,5 @@ pub use metal2vulkan::pipeline::{ }; pub use pipeline::ComputePipelineState; pub use queue::CommandQueue; +pub use texture::{Region, StorageMode, Texture, TextureDescriptor}; pub use times::host_time; diff --git a/crates/metal2vulkan-rt/src/readback.rs b/crates/metal2vulkan-rt/src/readback.rs index 3800869cc..47f434ec3 100644 --- a/crates/metal2vulkan-rt/src/readback.rs +++ b/crates/metal2vulkan-rt/src/readback.rs @@ -27,3 +27,30 @@ pub(crate) unsafe fn timestamps( }; read.ok().map(|()| (values[0], values[1])) } + +/// Copies `rows` (each an offset in `bytes` and one in `staging`) of `row` bytes from a staging +/// buffer the GPU copied a texture's bytes into, for `Texture::get_bytes`. +/// +/// Bound: the bytes only reach the caller's buffer as the texture's bytes; the offsets and the +/// length come from the call's checked region, never from the bytes, and the read does not wait. +/// +/// # Safety +/// +/// `staging` maps at least `offset + row` bytes for each row's staging offset, the copy into it +/// completed and its writes are visible to the host, and each row's offset plus `row` lies in +/// `bytes`. +pub(crate) unsafe fn texels( + staging: *const u8, + bytes: &mut [u8], + rows: impl Iterator, + row: usize, +) { + for (to, from) in rows { + // SAFETY: by the caller. + unsafe { + staging + .add(from) + .copy_to_nonoverlapping(bytes.as_mut_ptr().add(to), row) + }; + } +} diff --git a/crates/metal2vulkan-rt/src/reaper.rs b/crates/metal2vulkan-rt/src/reaper.rs index e55a12f2a..2fe043736 100644 --- a/crates/metal2vulkan-rt/src/reaper.rs +++ b/crates/metal2vulkan-rt/src/reaper.rs @@ -48,6 +48,17 @@ pub(crate) enum Free { Pipeline(vk::Pipeline), /// The shader module of a dropped pipeline state. ShaderModule(vk::ShaderModule), + /// A dropped texture's views, image and memory; the textures and blocks gauges fall with it. + Texture { + views: [Option; 2], + image: vk::Image, + memory: vk::DeviceMemory, + }, + /// A staging buffer of texture bytes, and its memory; the blocks gauge falls with it. + Staging { + buffer: vk::Buffer, + memory: vk::DeviceMemory, + }, } impl Reaper { @@ -148,6 +159,32 @@ fn free(core: &Core, object: Free) { } // SAFETY: its pipelines are made, and no more will be. Free::ShaderModule(module) => unsafe { device.destroy_shader_module(module, None) }, + Free::Texture { + views, + image, + memory, + } => { + // SAFETY: no pending work uses them: every command buffer and upload that used the + // texture held it until it retired, and its elements of set 1 are null. + unsafe { + for view in views.into_iter().flatten() { + device.destroy_image_view(view, None); + } + device.destroy_image(image, None); + device.free_memory(memory, None); + } + core.counters.fall(Gauge::Textures); + core.counters.fall(Gauge::Blocks); + } + Free::Staging { buffer, memory } => { + // SAFETY: the upload that copied through it retired, and no reader holds its mapping; + // freeing the memory unmaps it. + unsafe { + device.destroy_buffer(buffer, None); + device.free_memory(memory, None); + } + core.counters.fall(Gauge::Blocks); + } } } diff --git a/crates/metal2vulkan-rt/src/submit.rs b/crates/metal2vulkan-rt/src/submit.rs index a2cd66f1d..ea65461ba 100644 --- a/crates/metal2vulkan-rt/src/submit.rs +++ b/crates/metal2vulkan-rt/src/submit.rs @@ -11,6 +11,7 @@ use crate::fill; use crate::memory::Block; use crate::queue::QueueInner; use crate::record::{self, Reach, Recorder}; +use crate::texture::{Image, Staging}; use crate::times; use ash::vk; use std::collections::VecDeque; @@ -65,6 +66,10 @@ pub(crate) struct Upload { /// What an upload keeps until it retires. pub(crate) enum Held { Block(Arc), + /// A texture's image the upload moves to its home layout or copies bytes to or from. + Texture(Arc), + /// The staging buffer of such a copy. + Staging(Arc), } impl Held { @@ -72,6 +77,9 @@ impl Held { fn is(&self, other: &Held) -> bool { match (self, other) { (Held::Block(a), Held::Block(b)) => Arc::ptr_eq(a, b), + (Held::Texture(a), Held::Texture(b)) => Arc::ptr_eq(a, b), + (Held::Staging(a), Held::Staging(b)) => Arc::ptr_eq(a, b), + _ => false, } } } diff --git a/crates/metal2vulkan-rt/src/tests/arrays.rs b/crates/metal2vulkan-rt/src/tests/arrays.rs index d538090d3..7ddd6b854 100644 --- a/crates/metal2vulkan-rt/src/tests/arrays.rs +++ b/crates/metal2vulkan-rt/src/tests/arrays.rs @@ -7,8 +7,8 @@ //! is granted again. //! - Under a device cfg, on every device of the cfg's kind, the device writes every element of //! set 1 its default at creation, and holds two `VkSampler`s for it; grants work through the -//! device; making and destroying a second set 1 is timed and reported, and its two samplers -//! are gone after it. +//! device; `Device::new`, and making and destroying a second set 1, are timed and reported, +//! and the second set's two samplers are gone after it. use crate::arrays::Grants; use crate::error::{Error, Limit, Refusal}; @@ -123,8 +123,11 @@ mod on_device { "the loader lists no device of this cfg's kind" ); for (name, physical) in devices { + let opened = Instant::now(); let device = Device::new(&physical, DeviceOptions::default()) .unwrap_or_else(|error| panic!("{name}: {error}")); + let micros = opened.elapsed().as_micros(); + println!("M2V-MATRIX device_new/{name} {micros} us"); let counters = device.counters(); assert_eq!(counters.gauges().device_samplers, 2, "{name}"); let grant = device diff --git a/crates/metal2vulkan-rt/src/tests/mod.rs b/crates/metal2vulkan-rt/src/tests/mod.rs index 711c19d58..eed0bcd40 100644 --- a/crates/metal2vulkan-rt/src/tests/mod.rs +++ b/crates/metal2vulkan-rt/src/tests/mod.rs @@ -13,6 +13,7 @@ mod null_descriptor; mod one_path; mod push_window; mod readback; +mod texture; mod translate; /// This crate's directory: the test process's `CARGO_MANIFEST_DIR` where it holds the crate's diff --git a/crates/metal2vulkan-rt/src/tests/texture.rs b/crates/metal2vulkan-rt/src/tests/texture.rs new file mode 100644 index 000000000..3ca89884a --- /dev/null +++ b/crates/metal2vulkan-rt/src/tests/texture.rs @@ -0,0 +1,496 @@ +//! Textures: their shapes, their indices, their views' component mappings, and on devices their +//! bytes. +//! +//! - A descriptor Metal stops is refused, each rule by its own refusal: a zero extent, a height +//! or depth the type does not take, a cube that is not square, an array length or sample count +//! the type does not take, and levels past the full chain (one for 1D and multisample types). +//! - An index is taken by one object at a time: taking it again is `Refusal::IndexInUse`, taking +//! one not granted `Refusal::IndicesNotGranted`, and a grant is not released while an object +//! lives at one of its indices (`Refusal::IndicesInUse`); vacated, it is taken and released +//! again. +//! - A view's components are Metal's swizzle over the format's own mapping: zero and one stay, +//! and a channel source reads through the format's mapping. +//! - Under a device cfg, on every device of the cfg's kind: bytes written with `replace_region` +//! read back with `get_bytes`, the same, for a level of a 2D texture, rows apart at a pitch with +//! padding, a 3D region two images deep, a slice of an array, a cube's face, a depth texture, +//! and a block-compressed texture where the device makes one; padding in the caller's bytes is +//! left alone. A Private texture's bytes are refused. A texture's ID is its index and its +//! format's word. An index is taken while its texture lives and free once it is gone, and its +//! grant is released only then. The gauges of textures, descriptor slots and blocks come back to +//! zero with the device, and the copies are counted in `bytes_copied`. + +use crate::arrays::Grants; +use crate::error::{Error, Refusal}; +use crate::texture::{components, shape}; +use crate::{IndexClass, PixelFormat, TextureDescriptor, TextureType}; +use ash::vk; +use metal2vulkan::metal::{TextureSwizzle, TextureSwizzleChannels}; + +/// The refusal of `result`. +fn refused(result: Result) -> Refusal { + match result { + Err(Error::Refused(refusal)) => refusal, + Err(other) => panic!("not a refusal: {other}"), + Ok(_) => panic!("not a refusal: it was made"), + } +} + +#[test] +fn each_shape_metal_stops_is_refused() { + let base = TextureDescriptor::new(TextureType::Type2D, PixelFormat::RGBA8Unorm, 8, 8); + let with = |f: fn(&mut TextureDescriptor)| { + let mut d = base; + f(&mut d); + refused(shape(&d)) + }; + assert_eq!(with(|d| d.width = 0), Refusal::TextureZeroExtent); + assert_eq!(with(|d| d.depth = 0), Refusal::TextureZeroExtent); + assert_eq!(with(|d| d.depth = 2), Refusal::TextureExtentForType); + assert_eq!( + with(|d| { + d.texture_type = TextureType::Type1D; + d.height = 2; + }), + Refusal::TextureExtentForType + ); + assert_eq!( + with(|d| { + d.texture_type = TextureType::Cube; + d.height = 4; + }), + Refusal::TextureCubeNotSquare + ); + assert_eq!( + with(|d| d.array_length = 2), + Refusal::TextureArrayLength { array_length: 2 } + ); + assert_eq!( + with(|d| { + d.texture_type = TextureType::Type2DArray; + d.array_length = 0; + }), + Refusal::TextureArrayLength { array_length: 0 } + ); + assert_eq!( + with(|d| d.sample_count = 4), + Refusal::TextureSampleCount { sample_count: 4 } + ); + assert_eq!( + with(|d| d.mipmap_level_count = 5), + Refusal::TextureLevelCount { levels: 5, max: 4 } + ); + assert_eq!( + with(|d| d.mipmap_level_count = 0), + Refusal::TextureLevelCount { levels: 0, max: 4 } + ); + assert_eq!( + with(|d| { + d.texture_type = TextureType::Type2DMultisample; + d.sample_count = 4; + d.mipmap_level_count = 2; + }), + Refusal::TextureLevelCount { levels: 2, max: 1 } + ); + // What Metal makes passes: a full chain, a cube array's six layers a cube, a 3D extent. + let mut d = base; + d.mipmap_level_count = 4; + assert!(shape(&d).is_ok()); + d = base; + d.texture_type = TextureType::CubeArray; + d.array_length = 2; + assert_eq!(shape(&d).map(|s| s.layers).ok(), Some(12)); + d = base; + d.texture_type = TextureType::Type3D; + d.depth = 16; + d.mipmap_level_count = 5; + assert!(shape(&d).is_ok()); +} + +#[test] +fn an_index_holds_one_object_at_a_time() { + let mut grants = Grants::new(); + let grant = grants + .grant(IndexClass::Texture, 4096, 4) + .expect("the grant"); + assert!(grants.occupy(IndexClass::Texture, 4097).is_ok()); + assert_eq!( + refused(grants.occupy(IndexClass::Texture, 4097)), + Refusal::IndexInUse { + class: IndexClass::Texture, + index: 4097 + } + ); + assert_eq!( + refused(grants.occupy(IndexClass::Texture, 4100)), + Refusal::IndicesNotGranted { + class: IndexClass::Texture, + index: 4100 + } + ); + assert_eq!( + refused(grants.occupy(IndexClass::StorageTexture, 4097)), + Refusal::IndicesNotGranted { + class: IndexClass::StorageTexture, + index: 4097 + } + ); + assert_eq!( + refused(grants.release(grant)), + Refusal::IndicesInUse { + class: IndexClass::Texture, + index: 4097 + } + ); + grants.vacate(IndexClass::Texture, 4097); + assert!(grants.occupy(IndexClass::Texture, 4097).is_ok()); + grants.vacate(IndexClass::Texture, 4097); + assert!(grants.release(grant).is_ok()); +} + +#[test] +fn a_views_components_are_the_swizzle_over_the_formats_mapping() { + use vk::ComponentSwizzle as C; + let mapping = |r, g, b, a| vk::ComponentMapping { r, g, b, a }; + // `ash`'s mapping has no `PartialEq`: compare its four parts. + let parts = + |m: Option| m.map(|m| [m.r, m.g, m.b, m.a].map(|c| c.as_raw())); + let components = |m, swizzle| parts(components(m, swizzle)); + let identity = vk::ComponentMapping::default(); + assert_eq!( + components(identity, TextureSwizzleChannels::DEFAULT), + parts(Some(mapping(C::R, C::G, C::B, C::A))) + ); + let swizzle = TextureSwizzleChannels::new( + TextureSwizzle::Blue, + TextureSwizzle::Zero, + TextureSwizzle::One, + TextureSwizzle::Red, + ); + assert_eq!( + components(identity, swizzle), + parts(Some(mapping(C::B, C::ZERO, C::ONE, C::R))) + ); + // `A8Unorm` held in red: Metal's alpha is the image's red. + let alpha_in_red = mapping(C::ZERO, C::ZERO, C::ZERO, C::R); + let alpha_everywhere = TextureSwizzleChannels::new( + TextureSwizzle::Alpha, + TextureSwizzle::Alpha, + TextureSwizzle::Red, + TextureSwizzle::One, + ); + assert_eq!( + components(alpha_in_red, alpha_everywhere), + parts(Some(mapping(C::R, C::R, C::ZERO, C::ONE))) + ); +} + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use super::refused; + use crate::tests::devices_of_the_cfgs_kind; + use crate::{ + Device, DeviceOptions, Error, Gap, IndexClass, Instance, PixelFormat, Refusal, Region, + StorageMode, Texture, TextureDescriptor, TextureType, TextureUsage, + }; + use metal2vulkan::metal::resource_word::TextureWord; + use metal2vulkan::metal::TextureSwizzleChannels; + + /// A byte pattern of `len` bytes, different at every offset of one call and between calls. + fn pattern(len: usize, seed: u8) -> Vec { + (0..len) + .map(|i| (i as u8).wrapping_mul(31).wrapping_add(seed)) + .collect() + } + + /// One round trip: `bytes_per_row` and `bytes_per_image` apart, the region's rows of `row` + /// bytes, `rows` of them in each of `images`. + struct Trip { + region: Region, + level: u32, + slice: u32, + row: usize, + rows: usize, + images: usize, + bytes_per_row: usize, + bytes_per_image: usize, + } + + impl Trip { + fn len(&self) -> usize { + (self.images - 1) * self.bytes_per_image + + (self.rows - 1) * self.bytes_per_row + + self.row + } + + /// Whether `offset` is a byte of the region's rows. + fn holds(&self, offset: usize) -> bool { + let image = offset / self.bytes_per_image.max(1); + let within = offset - image * self.bytes_per_image; + let row = within / self.bytes_per_row.max(1); + image < self.images && row < self.rows && within - row * self.bytes_per_row < self.row + } + + /// Writes the pattern, reads it back into bytes of another pattern, and checks the + /// region's bytes came back and the padding is untouched. + fn run(&self, name: &str, texture: &Texture, seed: u8) { + let len = self.len(); + let written = pattern(len, seed); + texture + .replace_region( + self.region, + self.level, + self.slice, + &written, + self.bytes_per_row as u64, + self.bytes_per_image as u64, + ) + .unwrap_or_else(|error| panic!("{name}: replace_region: {error}")); + let mut read = pattern(len, seed.wrapping_add(7)); + let before = read.clone(); + texture + .get_bytes( + &mut read, + self.bytes_per_row as u64, + self.bytes_per_image as u64, + self.region, + self.level, + self.slice, + ) + .unwrap_or_else(|error| panic!("{name}: get_bytes: {error}")); + for offset in 0..len { + let want = match self.holds(offset) { + true => written[offset], + false => before[offset], + }; + assert_eq!( + read[offset], + want, + "{name}: {:?} byte {offset}", + texture.descriptor().pixel_format + ); + } + } + } + + fn descriptor( + texture_type: TextureType, + pixel_format: PixelFormat, + extent: [u32; 3], + ) -> TextureDescriptor { + let mut d = TextureDescriptor::new(texture_type, pixel_format, extent[0], extent[1]); + d.depth = extent[2]; + d + } + + /// Bytes go in and come back on every shape, the IDs and indices follow their textures, and + /// every gauge comes back to zero. + #[test] + fn every_device_round_trips_texture_bytes() { + let instance = Instance::new(&[]).expect("an instance at the floor"); + let devices = devices_of_the_cfgs_kind(&instance); + assert!( + !devices.is_empty(), + "the loader lists no device of this cfg's kind" + ); + for (name, physical) in devices { + let device = Device::new(&physical, DeviceOptions::default()) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let counters = device.counters(); + let sampled = device + .grant_indices(IndexClass::Texture, 4096, 16) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let storage = device + .grant_indices(IndexClass::StorageTexture, 1, 16) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let make = |d: &TextureDescriptor, index| { + device + .new_texture(d, index) + .unwrap_or_else(|error| panic!("{name}: {d:?}: {error}")) + }; + + // A level of a 2D texture, rows at a pitch with padding. + let mut d = descriptor(TextureType::Type2D, PixelFormat::RGBA8Unorm, [13, 7, 1]); + d.mipmap_level_count = 3; + let rgba = make(&d, Some(4096)); + assert_eq!(rgba.gpu_resource_id().index, 4096); + assert_eq!( + Some(TextureWord(rgba.gpu_resource_id().word)), + TextureWord::of(PixelFormat::RGBA8Unorm, TextureSwizzleChannels::DEFAULT) + ); + Trip { + region: Region { + origin: [1, 0, 0], + size: [5, 3, 1], + }, + level: 1, + slice: 0, + row: 20, + rows: 3, + images: 1, + bytes_per_row: 28, + bytes_per_image: 84, + } + .run(&name, &rgba, 1); + + // A storage-capable half-float texture, Managed. + let mut d = descriptor(TextureType::Type2D, PixelFormat::RGBA16Float, [9, 5, 1]); + d.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; + d.storage_mode = StorageMode::Managed; + let half = make(&d, Some(1)); + Trip { + region: Region { + origin: [0, 0, 0], + size: [9, 5, 1], + }, + level: 0, + slice: 0, + row: 72, + rows: 5, + images: 1, + bytes_per_row: 72, + bytes_per_image: 360, + } + .run(&name, &half, 2); + + // A 3D region two images deep. + let d = descriptor(TextureType::Type3D, PixelFormat::R32Float, [4, 4, 3]); + let volume = make(&d, Some(4097)); + Trip { + region: Region { + origin: [1, 1, 1], + size: [3, 2, 2], + }, + level: 0, + slice: 0, + row: 12, + rows: 2, + images: 2, + bytes_per_row: 16, + bytes_per_image: 40, + } + .run(&name, &volume, 3); + + // A slice of an array, and a cube's last face. + let mut d = descriptor(TextureType::Type2DArray, PixelFormat::R8Unorm, [4, 4, 1]); + d.array_length = 3; + let array = make(&d, Some(4098)); + let face = Region { + origin: [0, 0, 0], + size: [4, 4, 1], + }; + let trip = |slice| Trip { + region: face, + level: 0, + slice, + row: 4, + rows: 4, + images: 1, + bytes_per_row: 4, + bytes_per_image: 16, + }; + trip(2).run(&name, &array, 4); + let d = descriptor(TextureType::Cube, PixelFormat::R8Unorm, [4, 4, 1]); + let cube = make(&d, Some(4099)); + trip(5).run(&name, &cube, 5); + + // A 32-bit float depth texture: its bytes come out, and none go in. + let d = descriptor(TextureType::Type2D, PixelFormat::Depth32Float, [8, 8, 1]); + let depth = make(&d, Some(4100)); + let whole = Region { + origin: [0; 3], + size: [8, 8, 1], + }; + let mut read = vec![0u8; 256]; + depth + .get_bytes(&mut read, 32, 256, whole, 0, 0) + .unwrap_or_else(|error| panic!("{name}: depth get_bytes: {error}")); + assert!( + matches!( + depth.replace_region(whole, 0, 0, &read, 32, 256), + Err(Error::Unsupported(Gap::FloatDepthUpload { + pixel_format: PixelFormat::Depth32Float + })) + ), + "{name}" + ); + + // A block-compressed texture, where the device makes one: rows of 4 x 4 blocks. + let d = descriptor(TextureType::Type2D, PixelFormat::BC1RGBA, [8, 8, 1]); + match device.new_texture(&d, Some(4101)) { + Ok(bc1) => Trip { + region: Region { + origin: [4, 0, 0], + size: [4, 8, 1], + }, + level: 0, + slice: 0, + row: 8, + rows: 2, + images: 1, + bytes_per_row: 8, + bytes_per_image: 16, + } + .run(&name, &bc1, 7), + Err(Error::Unsupported(Gap::TextureFormat { .. })) => { + println!("{name}: no BC1 texture on this device") + } + Err(error) => panic!("{name}: BC1: {error}"), + } + + // A Private texture's bytes are the GPU's alone. + let mut d = descriptor(TextureType::Type2D, PixelFormat::RGBA8Unorm, [4, 4, 1]); + d.storage_mode = StorageMode::Private; + let private = make(&d, Some(4102)); + assert_eq!( + refused(private.replace_region(face, 0, 0, &[0; 64], 16, 64)), + Refusal::TextureBytesPrivate, + "{name}" + ); + + // An index holds its texture until it is gone, and its grant waits for it. + assert_eq!( + refused(device.new_texture(&d, Some(4102))), + Refusal::IndexInUse { + class: IndexClass::Texture, + index: 4102 + }, + "{name}" + ); + assert_eq!( + refused(device.new_texture(&d, None)), + Refusal::TextureIndex { index: None }, + "{name}" + ); + assert_eq!( + refused(device.release_indices(sampled)), + Refusal::IndicesInUse { + class: IndexClass::Texture, + index: 4096 + }, + "{name}" + ); + // Seven live at their indices; a dropped texture's image may wait for its upload. + let gauges = counters.gauges(); + assert_eq!(gauges.descriptor_slots, 7, "{name}"); + assert!(gauges.textures >= 7, "{name}: {gauges:?}"); + drop(private); + make(&d, Some(4102)); + drop((rgba, half, volume, array, cube, depth)); + device + .release_indices(sampled) + .unwrap_or_else(|error| panic!("{name}: {error}")); + device + .release_indices(storage) + .unwrap_or_else(|error| panic!("{name}: {error}")); + assert_eq!(counters.gauges().descriptor_slots, 0, "{name}"); + assert!(counters.metrics().bytes_copied > 0, "{name}"); + drop(device); + let gauges = counters.gauges(); + assert_eq!( + (gauges.textures, gauges.descriptor_slots, gauges.blocks), + (0, 0, 0), + "{name}" + ); + } + } +} diff --git a/crates/metal2vulkan-rt/src/texture.rs b/crates/metal2vulkan-rt/src/texture.rs new file mode 100644 index 000000000..a700151db --- /dev/null +++ b/crates/metal2vulkan-rt/src/texture.rs @@ -0,0 +1,1219 @@ +//! Textures: optimal images in memory of their own, each written into set 1's texture arrays at +//! the index the consumer names, in one home layout for its life. +//! +//! A texture's image has the descriptor's usage plus transfer source and destination, since Metal +//! lets the CPU and blits reach any texture. Its home layout is the one its descriptors name, and +//! the image leaves it only inside a copy: general where a shader may write it, shader-read-only +//! where shaders only read it, the attachment layout where only render passes use it. The upload +//! moves a new image from undefined to home ahead of every command buffer committed after +//! [`Device::new_texture`] returns. +//! +//! Shaders under the translator's identity domains read a texture through its view alone, so a +//! texture is made only where its view gives Metal's values: its format directly, or through the +//! view's component mapping. A storage element is written only where the device stores the format +//! through a storage image declared without a format. + +use crate::arrays::{IndexClass, ResourceId}; +use crate::counters::Gauge; +use crate::device::{lock, Core, Device}; +use crate::error::{Error, Gap, Limit, Refusal}; +use crate::memory::{Mapping, MemoryClass}; +use crate::reaper::{Free, Job}; +use crate::submit::Held; +use ash::vk; +use metal2vulkan::device::FormatUsage; +use metal2vulkan::metal::format::{self as formats, FormatEmulation}; +use metal2vulkan::metal::resource_word::TextureWord; +use metal2vulkan::metal::{ + PixelFormat, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, +}; +use std::sync::Arc; + +/// `MTLStorageMode` of a texture. Shared, Managed and Private textures are all device images; +/// Shared and Managed differ from Private only in that [`Texture::replace_region`] and +/// [`Texture::get_bytes`] take them. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum StorageMode { + /// `MTLStorageModeShared`. + Shared, + /// `MTLStorageModeManaged`. + Managed, + /// `MTLStorageModePrivate`. + Private, + /// `MTLStorageModeMemoryless`: refused, [`Gap::MemorylessTexture`]. + Memoryless, +} + +/// `MTLTextureDescriptor`: the fields the runtime reads. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct TextureDescriptor { + /// `textureType`. `TextureBuffer` is refused, [`Gap::TextureBuffer`]. + pub texture_type: TextureType, + /// `pixelFormat`. + pub pixel_format: PixelFormat, + /// `width`, in texels. + pub width: u32, + /// `height`, in texels; 1 for a 1D texture. + pub height: u32, + /// `depth`, in texels; 1 for a texture that is not 3D. + pub depth: u32, + /// `mipmapLevelCount`. + pub mipmap_level_count: u32, + /// `sampleCount`. + pub sample_count: u32, + /// `arrayLength`: the slices of an array type (a cube array's cubes); 1 otherwise. + pub array_length: u32, + /// `usage`. `Unknown` (no bits) is taken as Metal takes it: shader read, shader write, + /// render target and pixel-format view. + pub usage: TextureUsage, + /// `storageMode`. + pub storage_mode: StorageMode, + /// `swizzle`: each channel's source as shaders read it. + pub swizzle: TextureSwizzleChannels, +} + +impl TextureDescriptor { + /// `textureDescriptorWithPixelFormat:width:height:mipmapped:NO` of `texture_type`: depth, + /// levels, samples and array length 1, usage `ShaderRead`, storage Shared, and each channel + /// from itself, as Metal's defaults are. + pub fn new( + texture_type: TextureType, + pixel_format: PixelFormat, + width: u32, + height: u32, + ) -> TextureDescriptor { + TextureDescriptor { + texture_type, + pixel_format, + width, + height, + depth: 1, + mipmap_level_count: 1, + sample_count: 1, + array_length: 1, + usage: TextureUsage::SHADER_READ, + storage_mode: StorageMode::Shared, + swizzle: TextureSwizzleChannels::DEFAULT, + } + } +} + +/// `MTLRegion`: an origin and a size in texels, `[x, y, z]`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub struct Region { + /// The first texel. + pub origin: [u32; 3], + /// The texels on each axis. + pub size: [u32; 3], +} + +/// `MTLTexture`: an optimal-tiling `VkImage` in device-local memory of its own, its views, and the +/// elements of set 1 at its index. +/// +/// A cheap handle: clones share one texture. The texture holds the device. Once its last handle +/// is gone, and with it the last command buffer that used it, its elements of set 1 read null +/// again and its index is free; the reaper frees its image once the last upload that moves or +/// copies it has retired too. +#[derive(Clone)] +pub struct Texture { + inner: Arc, +} + +struct TextureInner { + device: Device, + descriptor: TextureDescriptor, + image: Arc, + /// The layout the image is in outside a copy, which its elements name. + home: vk::ImageLayout, + /// Every aspect of the image's format, which a change of layout names. + aspects: vk::ImageAspectFlags, + /// How bytes move between the image and the CPU; `None` where no copy is built. + unit: Option, + /// Its class and index; `None` for a texture no shader reaches. + index: Option<(IndexClass, u32)>, + word: u32, +} + +/// A texture's Vulkan objects: its image, its memory and its views. The texture and each upload +/// that moves or copies it hold them; the reaper frees them once the last is gone. +pub(crate) struct Image { + core: Arc, + image: vk::Image, + memory: vk::DeviceMemory, + /// The view of the sampled-texture array's element, where shaders read the texture. + sampled: Option, + /// The view of the storage-texture array's element, where shaders write it and the device + /// stores its format through a storage image without a format. + storage: Option, +} + +impl Drop for Image { + fn drop(&mut self) { + self.core.reaper.give(Job::Free(Free::Texture { + views: [self.sampled, self.storage], + image: self.image, + memory: self.memory, + })); + } +} + +/// The unit of a copy between an image and bytes: the aspect, an element's bytes and the texels +/// an element covers. +#[derive(Clone, Copy)] +struct CopyUnit { + aspect: vk::ImageAspectFlags, + bytes: u32, + block: [u32; 2], +} + +impl CopyUnit { + /// Whether the unit is a 32-bit float depth, which no upload takes + /// ([`Gap::FloatDepthUpload`]). + fn float_depth(&self) -> bool { + self.aspect == vk::ImageAspectFlags::DEPTH && self.bytes == 4 + } +} + +/// The texture's shape, from its descriptor. +pub(crate) struct Shape { + image_type: vk::ImageType, + flags: vk::ImageCreateFlags, + view_type: vk::ImageViewType, + extent: [u32; 3], + pub(crate) layers: u32, +} + +impl Drop for TextureInner { + fn drop(&mut self) { + let core = self.device.core(); + if let Some((class, index)) = self.index { + // SAFETY: the texture owns its elements until it vacates the index below, and no + // work that reads them is pending: each command buffer that used the texture held it + // until it retired. + unsafe { + core.arrays + .write_texture(&core.device, class, index, None, None) + }; + lock(&core.arrays.grants).vacate(class, index); + core.counters.fall(Gauge::DescriptorSlots); + } + } +} + +impl Device { + /// `newTextureWithDescriptor:`, at `index`: an optimal image of the descriptor in device-local + /// memory of its own, its contents undefined, as Metal's are. `index` is given exactly where + /// shaders reach the texture (shader-read or shader-write usage), and is then an index of a + /// live grant of the class the usage picks: [`IndexClass::StorageTexture`] with shader-write + /// usage, else [`IndexClass::Texture`]. The texture's elements of set 1 are written before + /// the call returns, and its image moved to its home layout ahead of every command buffer + /// committed after it. + /// + /// A swizzle composes with the view's own component mapping. Shader-write usage writes the + /// storage element where the device stores the format through a storage image without a + /// format; elsewhere the texture has none, and a write through its index is dropped as + /// through a nil texture. + /// + /// Err: what Metal refuses ([`Refusal::TextureZeroExtent`], [`Refusal::TextureExtentForType`], + /// [`Refusal::TextureCubeNotSquare`], [`Refusal::TextureArrayLength`], + /// [`Refusal::TextureLevelCount`], [`Refusal::TextureSampleCount`], + /// [`Refusal::TextureSwizzleWithWrites`]); [`Refusal::TextureIndex`]; + /// [`Refusal::IndicesNotGranted`] and [`Refusal::IndexInUse`] for an index not granted or + /// taken; [`Limit::TextureSize`] and [`Limit::TextureSamples`] past the device's; + /// [`Gap::TextureFormat`], [`Gap::TextureBuffer`] and [`Gap::MemorylessTexture`]; + /// [`Error::Vulkan`] where the image or its memory cannot be made; [`Error::Quiesced`]. + pub fn new_texture( + &self, + descriptor: &TextureDescriptor, + index: Option, + ) -> Result { + let d = *descriptor; + let shape = shape(&d)?; + if d.storage_mode == StorageMode::Memoryless { + return Err(Error::Unsupported(Gap::MemorylessTexture)); + } + let usage = match d.usage.is_empty() { + true => { + TextureUsage::SHADER_READ + | TextureUsage::SHADER_WRITE + | TextureUsage::RENDER_TARGET + | TextureUsage::PIXEL_FORMAT_VIEW + } + false => d.usage, + }; + if d.swizzle != TextureSwizzleChannels::DEFAULT + && usage.intersects(TextureUsage::SHADER_WRITE | TextureUsage::RENDER_TARGET) + { + return Err(Error::Refused(Refusal::TextureSwizzleWithWrites)); + } + let reached = usage.intersects(TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE); + if reached != index.is_some() { + return Err(Error::Refused(Refusal::TextureIndex { index })); + } + let class = match usage.contains(TextureUsage::SHADER_WRITE) { + true => IndexClass::StorageTexture, + false => IndexClass::Texture, + }; + let core = self.core(); + let plan = plan(core, &d, usage, &shape)?; + let index = match index { + Some(index) => { + lock(&core.arrays.grants).occupy(class, index)?; + core.counters.rise(Gauge::DescriptorSlots); + Some((class, index)) + } + None => None, + }; + // SAFETY: the device is live, and `plan` was checked against its image format query. + let made = unsafe { make(core, &d, &shape, &plan) }; + let (image, memory, sampled, storage) = match made { + Ok(made) => made, + Err(error) => { + if let Some((class, index)) = index { + lock(&core.arrays.grants).vacate(class, index); + core.counters.fall(Gauge::DescriptorSlots); + } + return Err(error); + } + }; + core.counters.rise(Gauge::Textures); + core.counters.rise(Gauge::Blocks); + let objects = Arc::new(Image { + core: Arc::clone(core), + image, + memory, + sampled, + storage, + }); + let inner = TextureInner { + device: self.clone(), + descriptor: d, + image: Arc::clone(&objects), + home: plan.home, + aspects: plan.aspects, + unit: plan.unit, + index, + word: plan.word, + }; + if let Some((class, index)) = index { + // SAFETY: the index is occupied for the texture, whose views are live; its image is + // in its home layout whenever work uses it, the upload below going first. + unsafe { + core.arrays.write_texture( + &core.device, + class, + index, + sampled.map(|view| (view, plan.home)), + storage, + ) + }; + } + let range = whole(plan.aspects); + core.work + .upload(core, [Held::Texture(objects)], |device, command| { + let barrier = vk::ImageMemoryBarrier2::default() + .src_stage_mask(vk::PipelineStageFlags2::NONE) + .src_access_mask(vk::AccessFlags2::NONE) + .dst_stage_mask(vk::PipelineStageFlags2::ALL_COMMANDS) + .dst_access_mask(vk::AccessFlags2::MEMORY_READ | vk::AccessFlags2::MEMORY_WRITE) + .old_layout(vk::ImageLayout::UNDEFINED) + .new_layout(plan.home) + .src_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .dst_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .image(image) + .subresource_range(range); + let barriers = [barrier]; + let dependency = vk::DependencyInfo::default().image_memory_barriers(&barriers); + // SAFETY: the upload's command buffer is recording, under the work lock; the image + // is the device's and held by the upload. + unsafe { device.cmd_pipeline_barrier2(command, &dependency) }; + })?; + Ok(Texture { + inner: Arc::new(inner), + }) + } +} + +/// What a texture is made of, decided before anything is made. +struct Plan { + format: vk::Format, + usage: vk::ImageUsageFlags, + samples: vk::SampleCountFlags, + /// The sampled view's component mapping and aspect, where shaders read the texture. + sampled: Option<(vk::ComponentMapping, vk::ImageAspectFlags)>, + /// Whether the texture has a storage view. + storage: bool, + home: vk::ImageLayout, + aspects: vk::ImageAspectFlags, + unit: Option, + word: u32, +} + +/// Checks a descriptor's shape as Metal does. +pub(crate) fn shape(d: &TextureDescriptor) -> Result { + use TextureType as T; + let (image_type, flags) = + formats::image_type(d.texture_type).ok_or(Error::Unsupported(Gap::TextureBuffer))?; + let view_type = + formats::image_view_type(d.texture_type).ok_or(Error::Unsupported(Gap::TextureBuffer))?; + let refused = |refusal| Err(Error::Refused(refusal)); + if d.width == 0 || d.height == 0 || d.depth == 0 { + return refused(Refusal::TextureZeroExtent); + } + let (one_d, three_d) = ( + matches!(d.texture_type, T::Type1D | T::Type1DArray), + d.texture_type == T::Type3D, + ); + if (one_d && d.height != 1) || (!three_d && d.depth != 1) { + return refused(Refusal::TextureExtentForType); + } + let cube = matches!(d.texture_type, T::Cube | T::CubeArray); + if cube && d.width != d.height { + return refused(Refusal::TextureCubeNotSquare); + } + let array = matches!( + d.texture_type, + T::Type1DArray | T::Type2DArray | T::CubeArray | T::Type2DMultisampleArray + ); + if d.array_length == 0 || (!array && d.array_length != 1) { + return refused(Refusal::TextureArrayLength { + array_length: d.array_length, + }); + } + let multisample = matches!( + d.texture_type, + T::Type2DMultisample | T::Type2DMultisampleArray + ); + if d.sample_count == 0 || (!multisample && d.sample_count != 1) { + return refused(Refusal::TextureSampleCount { + sample_count: d.sample_count, + }); + } + let max = match multisample || one_d { + true => 1, + false => 32 - d.width.max(d.height).max(d.depth).leading_zeros(), + }; + if d.mipmap_level_count == 0 || d.mipmap_level_count > max { + return refused(Refusal::TextureLevelCount { + levels: d.mipmap_level_count, + max, + }); + } + let layers = + match cube { + true => d.array_length.checked_mul(6).ok_or(Error::Refused( + Refusal::TextureArrayLength { + array_length: d.array_length, + }, + ))?, + false => d.array_length, + }; + Ok(Shape { + image_type: image_type.into(), + flags: flags.into(), + view_type: view_type.into(), + extent: [d.width, d.height, d.depth], + layers, + }) +} + +/// Decides the image, its views and its home layout, and checks them against the device's image +/// format query. +fn plan( + core: &Core, + d: &TextureDescriptor, + usage: TextureUsage, + shape: &Shape, +) -> Result { + let pf = d.pixel_format; + let gap = || Error::Unsupported(Gap::TextureFormat { pixel_format: pf }); + let word = TextureWord::of(pf, d.swizzle).ok_or_else(gap)?.0; + let profile = core.translator.profile(); + let mapping = + formats::vk_format(pf, &formats::texture_usages(pf, usage), profile).map_err(|_| gap())?; + // The forms whose view gives Metal's values with no conversion in the shader. + let viewed = matches!( + mapping.emulation, + FormatEmulation::Direct + | FormatEmulation::SwizzledView + | FormatEmulation::AlphaInRed + | FormatEmulation::RotatedView + | FormatEmulation::XChannel + | FormatEmulation::DepthInCombined + | FormatEmulation::StencilInCombined + ); + if !viewed { + return Err(gap()); + } + let block = mapping.format.block().ok_or_else(gap)?; + let format: vk::Format = mapping.format.into(); + let metal_aspects: vk::ImageAspectFlags = mapping.aspects.into(); + let mut aspects = vk::ImageAspectFlags::empty(); + if block.depth.is_some() { + aspects |= vk::ImageAspectFlags::DEPTH; + } + if block.stencil.is_some() { + aspects |= vk::ImageAspectFlags::STENCIL; + } + if aspects.is_empty() { + aspects = vk::ImageAspectFlags::COLOR; + } + let read = usage.contains(TextureUsage::SHADER_READ); + let storage = usage.contains(TextureUsage::SHADER_WRITE) + && mapping.emulation == FormatEmulation::Direct + && profile.supports_format(mapping.format, FormatUsage::StorageImage) + && profile.supports_format(mapping.format, FormatUsage::StorageImageWriteWithoutFormat); + let render = usage.contains(TextureUsage::RENDER_TARGET); + let mut image_usage = vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST; + if read { + image_usage |= vk::ImageUsageFlags::SAMPLED; + } + if storage { + image_usage |= vk::ImageUsageFlags::STORAGE; + } + if render { + image_usage |= match metal_aspects + .intersects(vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL) + { + true => vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT, + false => vk::ImageUsageFlags::COLOR_ATTACHMENT, + }; + } + let home = match (storage, read, render) { + (true, _, _) => vk::ImageLayout::GENERAL, + (false, true, _) => vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + (false, false, true) => vk::ImageLayout::ATTACHMENT_OPTIMAL, + (false, false, false) => vk::ImageLayout::GENERAL, + }; + let samples = vk::SampleCountFlags::from_raw(d.sample_count); + let info = vk::PhysicalDeviceImageFormatInfo2::default() + .format(format) + .ty(shape.image_type) + .tiling(vk::ImageTiling::OPTIMAL) + .usage(image_usage) + .flags(shape.flags); + let properties = core.image_format_properties(&info).ok_or_else(gap)?; + let max = properties.max_extent; + let max_extent = [max.width, max.height, max.depth]; + if shape.extent.iter().zip(max_extent).any(|(&e, m)| e > m) + || shape.layers > properties.max_array_layers + { + return Err(Error::Limit(Limit::TextureSize { + extent: shape.extent, + layers: shape.layers, + max_extent, + max_layers: properties.max_array_layers, + })); + } + if !d.sample_count.is_power_of_two() || !properties.sample_counts.contains(samples) { + return Err(Error::Limit(Limit::TextureSamples { + sample_count: d.sample_count, + counts: properties.sample_counts.as_raw(), + })); + } + // A sampled view selects one aspect: depth where the format has it, else stencil. + let view_aspect = if metal_aspects.contains(vk::ImageAspectFlags::DEPTH) { + vk::ImageAspectFlags::DEPTH + } else if metal_aspects.contains(vk::ImageAspectFlags::STENCIL) { + vk::ImageAspectFlags::STENCIL + } else { + vk::ImageAspectFlags::COLOR + }; + let unit = copy_unit(pf, format, metal_aspects, block.size, d.sample_count); + let sampled = match read { + true => Some(( + components(mapping.components.into(), d.swizzle).ok_or_else(gap)?, + view_aspect, + )), + false => None, + }; + Ok(Plan { + format, + usage: image_usage, + samples, + sampled, + storage, + home, + aspects, + unit, + word, + }) +} + +/// The unit of a copy of `pf`'s bytes, held in `format`: a color format's element (its texel, or +/// a compressed format's block), a depth format's depth, a stencil format's byte. `None` for a +/// format of depth and stencil both, a depth the device holds in other bits, and a multisample +/// texture. +fn copy_unit( + pf: PixelFormat, + format: vk::Format, + metal_aspects: vk::ImageAspectFlags, + element: u32, + samples: u32, +) -> Option { + use vk::ImageAspectFlags as A; + if samples != 1 { + return None; + } + let (aspect, bytes) = match metal_aspects { + A::COLOR => (A::COLOR, element), + A::DEPTH => match format { + vk::Format::D32_SFLOAT | vk::Format::D32_SFLOAT_S8_UINT => (A::DEPTH, 4), + vk::Format::D16_UNORM | vk::Format::D16_UNORM_S8_UINT => (A::DEPTH, 2), + _ => return None, + }, + A::STENCIL => (A::STENCIL, 1), + _ => return None, + }; + Some(CopyUnit { + aspect, + bytes, + block: formats::block_extent(pf).unwrap_or([1, 1]), + }) +} + +/// The view's component mapping: Metal's `swizzle` over the format's own `mapping`; `None` for a +/// swizzle source this crate does not know. +pub(crate) fn components( + mapping: vk::ComponentMapping, + swizzle: TextureSwizzleChannels, +) -> Option { + use vk::ComponentSwizzle as C; + let own = [mapping.r, mapping.g, mapping.b, mapping.a]; + let base = |channel: usize| match own[channel] { + C::IDENTITY => [C::R, C::G, C::B, C::A][channel], + other => other, + }; + let pick = |source: TextureSwizzle| match source { + TextureSwizzle::Zero => Some(C::ZERO), + TextureSwizzle::One => Some(C::ONE), + TextureSwizzle::Red => Some(base(0)), + TextureSwizzle::Green => Some(base(1)), + TextureSwizzle::Blue => Some(base(2)), + TextureSwizzle::Alpha => Some(base(3)), + _ => None, + }; + Some(vk::ComponentMapping { + r: pick(swizzle.red)?, + g: pick(swizzle.green)?, + b: pick(swizzle.blue)?, + a: pick(swizzle.alpha)?, + }) +} + +/// Every level and layer of an image of `aspects`. +fn whole(aspects: vk::ImageAspectFlags) -> vk::ImageSubresourceRange { + vk::ImageSubresourceRange { + aspect_mask: aspects, + base_mip_level: 0, + level_count: vk::REMAINING_MIP_LEVELS, + base_array_layer: 0, + layer_count: vk::REMAINING_ARRAY_LAYERS, + } +} + +/// The image, its memory and its views: the sampled view and the storage view. +type Objects = ( + vk::Image, + vk::DeviceMemory, + Option, + Option, +); + +/// Makes the image, binds it to memory of its own, and makes its views. +/// +/// # Safety +/// +/// `core`'s device is live, and `plan` was checked against its image format query for `shape`. +unsafe fn make( + core: &Core, + d: &TextureDescriptor, + shape: &Shape, + plan: &Plan, +) -> Result { + let mut made = Made::default(); + // SAFETY: the caller's contract; what was made is destroyed where a later step fails. + let objects = unsafe { made.make(core, d, shape, plan) }; + if objects.is_err() { + // SAFETY: nothing else holds what was made: no descriptor and no command names it. + unsafe { made.destroy(&core.device) }; + } + objects +} + +/// What [`make`] has made so far. +#[derive(Default)] +struct Made { + image: Option, + memory: Option, + views: Vec, +} + +impl Made { + /// # Safety + /// + /// As [`make`]. + unsafe fn make( + &mut self, + core: &Core, + d: &TextureDescriptor, + shape: &Shape, + plan: &Plan, + ) -> Result { + let device = &core.device; + let [width, height, depth] = shape.extent; + let info = vk::ImageCreateInfo::default() + .flags(shape.flags) + .image_type(shape.image_type) + .format(plan.format) + .extent(vk::Extent3D { + width, + height, + depth, + }) + .mip_levels(d.mipmap_level_count) + .array_layers(shape.layers) + .samples(plan.samples) + .tiling(vk::ImageTiling::OPTIMAL) + .usage(plan.usage) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .initial_layout(vk::ImageLayout::UNDEFINED); + // SAFETY: the caller's contract: the device makes such an image. + let image = + unsafe { device.create_image(&info, None) }.map_err(Error::vulkan("vkCreateImage"))?; + self.image = Some(image); + // SAFETY: the image is the device's. + let requirements = unsafe { device.get_image_memory_requirements(image) }; + let bits = requirements.memory_type_bits; + // Vulkan gives every image of no external handle type a device-local type. + let local = bits & core.device_local; + let memory_type = match local { + 0 => bits.trailing_zeros(), + _ => local.trailing_zeros(), + }; + let mut dedicated = vk::MemoryDedicatedAllocateInfo::default().image(image); + let allocate = vk::MemoryAllocateInfo::default() + .allocation_size(requirements.size) + .memory_type_index(memory_type) + .push_next(&mut dedicated); + // SAFETY: the type is one the image's requirements allow, and the allocation its own. + let memory = unsafe { device.allocate_memory(&allocate, None) } + .map_err(Error::vulkan("vkAllocateMemory"))?; + self.memory = Some(memory); + // SAFETY: the allocation is the image's size, of a type its requirements allow. + unsafe { device.bind_image_memory(image, memory, 0) } + .map_err(Error::vulkan("vkBindImageMemory"))?; + let mut view = |components, aspect| { + let info = vk::ImageViewCreateInfo::default() + .image(image) + .view_type(shape.view_type) + .format(plan.format) + .components(components) + .subresource_range(whole(aspect)); + // SAFETY: the image is bound, of the view's format, and has the view's usage. + let view = unsafe { device.create_image_view(&info, None) } + .map_err(Error::vulkan("vkCreateImageView"))?; + self.views.push(view); + Ok::<_, Error>(view) + }; + let sampled = match plan.sampled { + Some((components, aspect)) => Some(view(components, aspect)?), + None => None, + }; + let storage = match plan.storage { + true => Some(view( + vk::ComponentMapping::default(), + vk::ImageAspectFlags::COLOR, + )?), + false => None, + }; + Ok((image, memory, sampled, storage)) + } + + /// # Safety + /// + /// Nothing else holds what was made. + unsafe fn destroy(&self, device: &ash::Device) { + // SAFETY: the caller's contract. + unsafe { + for &view in &self.views { + device.destroy_image_view(view, None); + } + if let Some(image) = self.image { + device.destroy_image(image, None); + } + if let Some(memory) = self.memory { + device.free_memory(memory, None); + } + } + } +} + +/// A copy between the texture and bytes, checked: the subresource, the region and how its rows +/// lie in the bytes. +struct Transfer { + unit: CopyUnit, + level: u32, + /// The array layer; 0 for a 3D texture. + layer: u32, + offset: vk::Offset3D, + extent: vk::Extent3D, + /// One row of elements' bytes. + row: u64, + /// Rows of elements in an image. + rows: u64, + /// Images (a 3D region's depth). + images: u64, + bytes_per_row: u64, + bytes_per_image: u64, +} + +impl Transfer { + /// The staging buffer's bytes: the region's rows, packed. + fn len(&self) -> u64 { + self.row * self.rows * self.images + } + + /// Each row's offset in the caller's bytes and in the staging buffer. + fn rows(&self) -> impl Iterator + '_ { + (0..self.images).flat_map(move |image| { + (0..self.rows).map(move |row| { + ( + (image * self.bytes_per_image + row * self.bytes_per_row) as usize, + ((image * self.rows + row) * self.row) as usize, + ) + }) + }) + } + + fn buffer_image_copy(&self) -> vk::BufferImageCopy { + vk::BufferImageCopy { + buffer_offset: 0, + buffer_row_length: 0, + buffer_image_height: 0, + image_subresource: vk::ImageSubresourceLayers { + aspect_mask: self.unit.aspect, + mip_level: self.level, + base_array_layer: self.layer, + layer_count: 1, + }, + image_offset: self.offset, + image_extent: self.extent, + } + } +} + +impl TextureInner { + /// Checks a copy of `region` of `level` and `slice` with `len` bytes, rows `bytes_per_row` + /// and images `bytes_per_image` apart. `None` for an empty region, which copies nothing. + fn copy( + &self, + region: Region, + level: u32, + slice: u32, + len: u64, + bytes_per_row: u64, + bytes_per_image: u64, + ) -> Result, Error> { + let d = &self.descriptor; + if matches!( + d.storage_mode, + StorageMode::Private | StorageMode::Memoryless + ) { + return Err(Error::Refused(Refusal::TextureBytesPrivate)); + } + let unit = self.unit.ok_or(Error::Unsupported(Gap::TextureBytes { + pixel_format: d.pixel_format, + }))?; + let outside = || Error::Refused(Refusal::TextureRegion { level, slice }); + let three_d = d.texture_type == TextureType::Type3D; + let slices = match d.texture_type { + TextureType::Cube | TextureType::CubeArray => d.array_length * 6, + _ => d.array_length, + }; + if level >= d.mipmap_level_count || slice >= slices { + return Err(outside()); + } + let extent = [d.width, d.height, d.depth].map(|e| (e >> level).max(1)); + let [bw, bh] = unit.block; + let block = [bw, bh, 1]; + for axis in 0..3 { + let (origin, size) = (region.origin[axis], region.size[axis]); + let end = origin.checked_add(size).ok_or_else(outside)?; + let on_grid = + origin % block[axis] == 0 && (size % block[axis] == 0 || end == extent[axis]); + if end > extent[axis] || !on_grid { + return Err(outside()); + } + } + if region.size.contains(&0) { + return Ok(None); + } + let [width, height, depth] = region.size; + let row = u64::from(width.div_ceil(bw)) * u64::from(unit.bytes); + let rows = u64::from(height.div_ceil(bh)); + let images = u64::from(depth); + let image_span = (rows - 1) + .checked_mul(bytes_per_row) + .and_then(|span| span.checked_add(row)); + let span = image_span.and_then(|image_span| { + (images - 1) + .checked_mul(bytes_per_image) + .and_then(|span| span.checked_add(image_span)) + }); + let fits = (rows == 1 || bytes_per_row >= row) + && (images == 1 || image_span.is_some_and(|image_span| bytes_per_image >= image_span)) + && span.is_some_and(|span| span <= len); + if !fits { + return Err(Error::Refused(Refusal::TextureBytesLayout { + bytes_per_row, + bytes_per_image, + len, + })); + } + let [x, y, z] = region.origin; + Ok(Some(Transfer { + unit, + level, + layer: match three_d { + true => 0, + false => slice, + }, + offset: vk::Offset3D { + x: x as i32, + y: y as i32, + z: z as i32, + }, + extent: vk::Extent3D { + width, + height, + depth, + }, + row, + rows, + images, + bytes_per_row, + bytes_per_image, + })) + } + + /// Records `copy` between the staging buffer and the image, `to_image` for a replace: the + /// subresource leaves home for the transfer layout and comes back, and a read's bytes are + /// made visible to the host. + /// + /// # Safety + /// + /// `command` is recording under the work lock, and the upload holds the image and `staging`. + unsafe fn record( + &self, + device: &ash::Device, + command: vk::CommandBuffer, + copy: &Transfer, + staging: vk::Buffer, + to_image: bool, + ) { + use vk::AccessFlags2 as Access; + use vk::PipelineStageFlags2 as Stage; + let (layout, access) = match to_image { + true => ( + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + Access::TRANSFER_WRITE, + ), + false => (vk::ImageLayout::TRANSFER_SRC_OPTIMAL, Access::TRANSFER_READ), + }; + let range = vk::ImageSubresourceRange { + aspect_mask: self.aspects, + base_mip_level: copy.level, + level_count: 1, + base_array_layer: copy.layer, + layer_count: 1, + }; + let barrier = |old, new, src: (Stage, Access), dst: (Stage, Access)| { + vk::ImageMemoryBarrier2::default() + .src_stage_mask(src.0) + .src_access_mask(src.1) + .dst_stage_mask(dst.0) + .dst_access_mask(dst.1) + .old_layout(old) + .new_layout(new) + .src_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .dst_queue_family_index(vk::QUEUE_FAMILY_IGNORED) + .image(self.image.image) + .subresource_range(range) + }; + let anything = ( + Stage::ALL_COMMANDS, + Access::MEMORY_READ | Access::MEMORY_WRITE, + ); + let away = [barrier( + self.home, + layout, + (Stage::ALL_COMMANDS, Access::MEMORY_WRITE), + (Stage::COPY, access), + )]; + let written = match to_image { + true => Access::TRANSFER_WRITE, + false => Access::NONE, + }; + let home = [barrier(layout, self.home, (Stage::COPY, written), anything)]; + let host = [vk::MemoryBarrier2::default() + .src_stage_mask(Stage::COPY) + .src_access_mask(Access::TRANSFER_WRITE) + .dst_stage_mask(Stage::HOST) + .dst_access_mask(Access::HOST_READ)]; + let back = vk::DependencyInfo::default().image_memory_barriers(&home); + let back = match to_image { + true => back, + false => back.memory_barriers(&host), + }; + let regions = [copy.buffer_image_copy()]; + // SAFETY: the caller's contract; the subresource is in `layout` between the barriers. + unsafe { + device.cmd_pipeline_barrier2( + command, + &vk::DependencyInfo::default().image_memory_barriers(&away), + ); + match to_image { + true => device.cmd_copy_buffer_to_image( + command, + staging, + self.image.image, + layout, + ®ions, + ), + false => device.cmd_copy_image_to_buffer( + command, + self.image.image, + layout, + staging, + ®ions, + ), + } + device.cmd_pipeline_barrier2(command, &back); + } + } +} + +impl Texture { + /// `gpuResourceID`: its index (0 for a texture no shader reaches) and the translator's + /// `TextureWord` of its pixel format and swizzle. + pub fn gpu_resource_id(&self) -> ResourceId { + ResourceId { + index: self.inner.index.map_or(0, |(_, index)| index), + word: self.inner.word, + } + } + + /// `textureType`, `pixelFormat`, `width` and the rest, as made. + pub fn descriptor(&self) -> &TextureDescriptor { + &self.inner.descriptor + } + + /// `replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:`: the bytes of + /// `region` of `level` and `slice` (a 3D texture's slice is 0), rows `bytes_per_row` and + /// images `bytes_per_image` apart in `bytes`, a compressed format's rows being rows of + /// blocks. The bytes go to a staging buffer before the call returns, and the upload copies + /// them into the image ahead of every command buffer committed after it, so the call is + /// ordered as Metal's CPU write is. Counted in [`Metrics::bytes_copied`]. An empty region + /// copies nothing. + /// + /// Err: [`Refusal::TextureBytesPrivate`]; [`Refusal::TextureRegion`] for a level, slice or + /// region outside the texture or off its format's block grid; + /// [`Refusal::TextureBytesLayout`]; [`Gap::TextureBytes`]; [`Gap::FloatDepthUpload`] for a + /// 32-bit float depth; [`Error::Vulkan`] where the staging buffer cannot be made; + /// [`Error::Quiesced`]. + /// + /// [`Metrics::bytes_copied`]: crate::Metrics::bytes_copied + pub fn replace_region( + &self, + region: Region, + level: u32, + slice: u32, + bytes: &[u8], + bytes_per_row: u64, + bytes_per_image: u64, + ) -> Result<(), Error> { + let inner = &self.inner; + let len = bytes.len() as u64; + let Some(copy) = inner.copy(region, level, slice, len, bytes_per_row, bytes_per_image)? + else { + return Ok(()); + }; + if copy.unit.float_depth() { + return Err(Error::Unsupported(Gap::FloatDepthUpload { + pixel_format: inner.descriptor.pixel_format, + })); + } + let core = inner.device.core(); + let staging = Arc::new(Staging::new(core, copy.len())?); + let row = copy.row as usize; + for (from, to) in copy.rows() { + // SAFETY: `copy` checked that each row lies in `bytes`, and the staging buffer holds + // every row packed; no one else has the staging buffer yet. + unsafe { + bytes + .as_ptr() + .add(from) + .copy_to_nonoverlapping(staging.mapping.get().as_ptr().add(to), row) + }; + } + core.counters.copied(copy.len()); + let buffer = staging.buffer; + core.work.upload( + core, + [ + Held::Texture(Arc::clone(&inner.image)), + Held::Staging(staging), + ], + // SAFETY: recording under the work lock, the upload holding the image and the + // staging buffer. + |device, command| unsafe { inner.record(device, command, ©, buffer, true) }, + ) + } + + /// `getBytes:bytesPerRow:bytesPerImage:fromRegion:mipmapLevel:slice:`: the image's bytes of + /// `region` of `level` and `slice`, laid out in `bytes` as [`Texture::replace_region`] takes + /// them. The upload copies them to a staging buffer, the call submits it at once and waits + /// for it, and copies them out. Metal's contract holds: the program has waited for the work + /// that writes the texture. Counted in [`Metrics::bytes_copied`]. + /// + /// Err: as [`Texture::replace_region`]; [`Error::Vulkan`] with `VK_ERROR_DEVICE_LOST` where + /// the device is lost first. + /// + /// [`Metrics::bytes_copied`]: crate::Metrics::bytes_copied + pub fn get_bytes( + &self, + bytes: &mut [u8], + bytes_per_row: u64, + bytes_per_image: u64, + region: Region, + level: u32, + slice: u32, + ) -> Result<(), Error> { + let inner = &self.inner; + let len = bytes.len() as u64; + let Some(copy) = inner.copy(region, level, slice, len, bytes_per_row, bytes_per_image)? + else { + return Ok(()); + }; + let core = inner.device.core(); + let staging = Arc::new(Staging::new(core, copy.len())?); + let buffer = staging.buffer; + core.work.upload( + core, + [ + Held::Texture(Arc::clone(&inner.image)), + Held::Staging(Arc::clone(&staging)), + ], + // SAFETY: as in `replace_region`. + |device, command| unsafe { inner.record(device, command, ©, buffer, false) }, + )?; + let value = core.work.flush(); + core.done.wait(core, value)?; + // SAFETY: the staging buffer holds every row packed, the copy into it completed and its + // writes are visible to the host; `copy` checked that each row lies in `bytes`. + unsafe { + crate::readback::texels( + staging.mapping.get().as_ptr(), + bytes, + copy.rows(), + copy.row as usize, + ) + }; + core.counters.copied(copy.len()); + Ok(()) + } +} + +/// A host-visible buffer of a copy's bytes, in memory of its own of the Shared type, mapped for +/// its life. The reaper frees it once its last holder, the upload that copies through it among +/// them, is gone. +pub(crate) struct Staging { + core: Arc, + buffer: vk::Buffer, + memory: vk::DeviceMemory, + mapping: Mapping, +} + +impl Staging { + /// A staging buffer of `len` bytes. + fn new(core: &Arc, len: u64) -> Result { + let device = &core.device; + let info = vk::BufferCreateInfo::default() + .size(len) + .usage(vk::BufferUsageFlags::TRANSFER_SRC | vk::BufferUsageFlags::TRANSFER_DST) + .sharing_mode(vk::SharingMode::EXCLUSIVE); + // SAFETY: the device is live. + let buffer = unsafe { device.create_buffer(&info, None) } + .map_err(Error::vulkan("vkCreateBuffer"))?; + // SAFETY: the buffer is the device's. + let requirements = unsafe { device.get_buffer_memory_requirements(buffer) }; + let allocate = vk::MemoryAllocateInfo::default() + .allocation_size(requirements.size) + .memory_type_index(core.memory_type(MemoryClass::Shared)); + // SAFETY: the Shared type serves a buffer of every usage, so one of fewer too. + let memory = match unsafe { device.allocate_memory(&allocate, None) } { + Ok(memory) => memory, + Err(result) => { + // SAFETY: the buffer is unused. + unsafe { device.destroy_buffer(buffer, None) }; + return Err(Error::Vulkan { + call: "vkAllocateMemory", + result, + }); + } + }; + // SAFETY: the allocation is the buffer's size, of a type it allows; the memory is + // host-visible and not mapped. + let mapped = unsafe { + device + .bind_buffer_memory(buffer, memory, 0) + .map_err(Error::vulkan("vkBindBufferMemory")) + .and_then(|()| { + device + .map_memory(memory, 0, vk::WHOLE_SIZE, vk::MemoryMapFlags::empty()) + .map_err(Error::vulkan("vkMapMemory")) + }) + }; + let pointer = match mapped { + Ok(pointer) => pointer, + Err(error) => { + // SAFETY: nothing uses them. + unsafe { + device.destroy_buffer(buffer, None); + device.free_memory(memory, None); + } + return Err(error); + } + }; + // A successful map gives a non-null address. + let Some(pointer) = std::ptr::NonNull::new(pointer.cast::()) else { + // SAFETY: nothing uses them. + unsafe { + device.destroy_buffer(buffer, None); + device.free_memory(memory, None); + } + return Err(Error::Vulkan { + call: "vkMapMemory", + result: vk::Result::ERROR_MEMORY_MAP_FAILED, + }); + }; + core.counters.rise(Gauge::Blocks); + Ok(Staging { + core: Arc::clone(core), + buffer, + memory, + mapping: Mapping::new(pointer), + }) + } +} + +impl Drop for Staging { + fn drop(&mut self) { + self.core.reaper.give(Job::Free(Free::Staging { + buffer: self.buffer, + memory: self.memory, + })); + } +} diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index de9495740..efc674b10 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -46,6 +46,7 @@ assoc-const metal2vulkan-air::metal::DataType::ALL pub const ALL: [DataType; 17] assoc-const metal2vulkan-rt::ResourceUsage::READ pub const READ: ResourceUsage assoc-const metal2vulkan-rt::ResourceUsage::SAMPLE pub const SAMPLE: ResourceUsage assoc-const metal2vulkan-rt::ResourceUsage::WRITE pub const WRITE: ResourceUsage +assoc-const metal2vulkan-rt::TextureSwizzleChannels::DEFAULT pub const DEFAULT: TextureSwizzleChannels assoc-const metal2vulkan-runtime::AddressModeMap::IDENTITY pub const IDENTITY: AddressModeMap assoc-const metal2vulkan-runtime::FeatureRow::ALL pub const ALL: [FeatureRow; 144] assoc-const metal2vulkan-runtime::FormatCapabilities::NONE pub const NONE: FormatCapabilities @@ -573,6 +574,7 @@ assoc-const-value metal2vulkan-air::metal::DataType::ALL [DataType::Float32, Dat assoc-const-value metal2vulkan-rt::ResourceUsage::READ ResourceUsage(1) assoc-const-value metal2vulkan-rt::ResourceUsage::SAMPLE ResourceUsage(4) assoc-const-value metal2vulkan-rt::ResourceUsage::WRITE ResourceUsage(2) +assoc-const-value metal2vulkan-rt::TextureSwizzleChannels::DEFAULT TextureSwizzleChannels assoc-const-value metal2vulkan-runtime::AddressModeMap::IDENTITY AddressModeMap assoc-const-value metal2vulkan-runtime::FeatureRow::ALL [FeatureRow::MetalKit, FeatureRow::MetalPerformanceShaders, FeatureRow::ProgrammableBlending, FeatureRow::SeparateDepthStencilAttachments, FeatureRow::PvrtcPixelFormats, FeatureRow::EacEtcPixelFormats, FeatureRow::AstcPixelFormats, FeatureRow::BcPixelFormats, FeatureRow::CompressedVolumeTextureFormats, FeatureRow::ExtendedRangePixelFormats, FeatureRow::WideColorPixelFormat, FeatureRow::Depth16PixelFormat, FeatureRow::LinearTextures, FeatureRow::MsaaDepthResolve, FeatureRow::ArrayOfTexturesRead, FeatureRow::ArrayOfTexturesWrite, FeatureRow::CubeMapTextureArrays, FeatureRow::StencilTextureViews, FeatureRow::ArrayOfSamplers, FeatureRow::SamplerMaxAnisotropy, FeatureRow::SamplerLodClamp, FeatureRow::SamplerCompareFunctions, FeatureRow::UnsignedShortCoordinates, FeatureRow::BorderColor, FeatureRow::CountingOcclusionQuery, FeatureRow::BaseVertexInstanceDrawing, FeatureRow::LayeredRendering, FeatureRow::LayeredRenderingToMultisampleTextures, FeatureRow::MemorylessRenderTargets, FeatureRow::DualSourceBlending, FeatureRow::StoreAndMultisampleResolve, FeatureRow::MsaaBlits, FeatureRow::ProgrammableSamplePositions, FeatureRow::DeferredStoreAction, FeatureRow::MemoryBarriers, FeatureRow::IcbComputeMemoryBarriers, FeatureRow::IcbRenderMemoryBarriers, FeatureRow::Tessellation, FeatureRow::IndirectTessellationArguments, FeatureRow::IcbTessellation, FeatureRow::ResourceHeaps, FeatureRow::FunctionSpecialization, FeatureRow::ReadWriteBuffers, FeatureRow::ReadWriteTextures, FeatureRow::ExtractInsertReverseBits, FeatureRow::SimdBarrier, FeatureRow::IndirectDrawDispatchArguments, FeatureRow::ArgumentBuffersTier1, FeatureRow::ArgumentBuffersTier2, FeatureRow::IcbRendering, FeatureRow::IcbCompute, FeatureRow::UniformType, FeatureRow::Imageblocks, FeatureRow::TileShaders, FeatureRow::ImageblockSampleCoverageControl, FeatureRow::PostDepthCoverage, FeatureRow::QuadPermute, FeatureRow::QuadBallot, FeatureRow::QuadReduction, FeatureRow::SimdPermute, FeatureRow::SimdReduction, FeatureRow::SimdMatrixMultiply, FeatureRow::RasterOrderGroups, FeatureRow::NonuniformThreadgroupSize, FeatureRow::MultipleViewports, FeatureRow::StencilFeedback, FeatureRow::StencilResolve, FeatureRow::NonsquareTileDispatch, FeatureRow::TextureSwizzle, FeatureRow::PlacementHeap, FeatureRow::PrimitiveId, FeatureRow::BarycentricCoordinates, FeatureRow::ReadWriteCubeMapTextures, FeatureRow::SparseTextures, FeatureRow::SparseDepthStencilTextures, FeatureRow::VariableRasterizationRate, FeatureRow::VertexAmplification, FeatureRow::Int64Math, FeatureRow::LossyTextureCompression, FeatureRow::SimdShiftAndFill, FeatureRow::RenderDynamicLibraries, FeatureRow::ComputeDynamicLibraries, FeatureRow::MeshShading, FeatureRow::IndirectMeshDrawArguments, FeatureRow::IcbMeshDraws, FeatureRow::MetalFxSpatialUpscaling, FeatureRow::MetalFxTemporalUpscaling, FeatureRow::MetalFxFrameInterpolation, FeatureRow::MetalFxDenoisedUpscaling, FeatureRow::FastResourceLoading, FeatureRow::RayTracingCompute, FeatureRow::RayTracingRender, FeatureRow::FloatAtomics, FeatureRow::TextureAtomics, FeatureRow::Int64Atomics, FeatureRow::QueryTextureLod, FeatureRow::BinaryArchives, FeatureRow::FunctionPointersCompute, FeatureRow::FunctionPointersRender, FeatureRow::DepthCompareBiasAndGradient, FeatureRow::NonprivateDepthStencilTextures, FeatureRow::DynamicAttributeStride, FeatureRow::PackedFloatAttributeFormats, FeatureRow::BFloat, FeatureRow::RelaxedMath, FeatureRow::GlobalBuiltinsAndBindings, FeatureRow::CoherentMemory, FeatureRow::ShaderValidation, FeatureRow::ShaderLogging, FeatureRow::ResidencySets, FeatureRow::RowMajorAccelerationStructures, FeatureRow::PerComponentMotionInterpolation, FeatureRow::IntersectionResultStorage, FeatureRow::VisibilityCountAccumulation, FeatureRow::ArgumentTables, FeatureRow::CommandAllocators, FeatureRow::DecoupledQueuesAndCommandBuffers, FeatureRow::TextureViewPools, FeatureRow::CommandBarriers, FeatureRow::PlacementSparseBuffers, FeatureRow::PlacementSparseTextures, FeatureRow::CompilationContexts, FeatureRow::PipelineDatasetSerialization, FeatureRow::FlexibleRenderPipelineState, FeatureRow::ColorAttachmentMapping, FeatureRow::MachineLearningEncoding, FeatureRow::Tensors, FeatureRow::PerformanceCounterHeaps, FeatureRow::AddressDrivenAccelerationStructureBuilds, FeatureRow::AccelerationStructureBuildOptions, FeatureRow::IntersectionFunctionBuffers, FeatureRow::SamplerMinMaxReduction, FeatureRow::SamplerLodBias, FeatureRow::PreRasterVertexValues, FeatureRow::DepthBoundsTesting, FeatureRow::IcbRasterAndDepthStencilState, FeatureRow::CubeMapAtomics, FeatureRow::UniversalTextureCompression, FeatureRow::AcquireReleaseAtomics, FeatureRow::BlockTextureReads, FeatureRow::ClampToEdgeTextureReads, FeatureRow::IntegerCoordinateOffsets, FeatureRow::TextureBarriers, FeatureRow::DeviceNotifications] assoc-const-value metal2vulkan-runtime::FormatCapabilities::NONE FormatCapabilities(0) @@ -1405,6 +1407,7 @@ enum metal2vulkan-rt::PrecisionNote #[cfg_attr(feature = "serde", derive(serde:: enum metal2vulkan-rt::Refusal #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Refusal enum metal2vulkan-rt::Resource #[derive(Clone, Copy)] #[non_exhaustive] pub enum Resource<'a> enum metal2vulkan-rt::StageSource #[derive(Clone, Debug, PartialEq, Eq)] pub enum StageSource +enum metal2vulkan-rt::StorageMode #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum StorageMode enum metal2vulkan-rt::floor::Missing #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Missing enum metal2vulkan-runtime::AddressPlacement #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum AddressPlacement enum metal2vulkan-runtime::AppleOnly #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum AppleOnly @@ -2262,6 +2265,25 @@ field metal2vulkan-rt::RawDevice.device pub device: &'a ash::Device field metal2vulkan-rt::RawDevice.instance pub instance: &'a ash::Instance field metal2vulkan-rt::RawDevice.physical_device pub physical_device: vk::PhysicalDevice field metal2vulkan-rt::RawDevice.queue_family_index pub queue_family_index: u32 +field metal2vulkan-rt::Region.origin pub origin: [u32; 3] +field metal2vulkan-rt::Region.size pub size: [u32; 3] +field metal2vulkan-rt::ResourceId.index pub index: u32 +field metal2vulkan-rt::ResourceId.word pub word: u32 +field metal2vulkan-rt::TextureDescriptor.array_length pub array_length: u32 +field metal2vulkan-rt::TextureDescriptor.depth pub depth: u32 +field metal2vulkan-rt::TextureDescriptor.height pub height: u32 +field metal2vulkan-rt::TextureDescriptor.mipmap_level_count pub mipmap_level_count: u32 +field metal2vulkan-rt::TextureDescriptor.pixel_format pub pixel_format: PixelFormat +field metal2vulkan-rt::TextureDescriptor.sample_count pub sample_count: u32 +field metal2vulkan-rt::TextureDescriptor.storage_mode pub storage_mode: StorageMode +field metal2vulkan-rt::TextureDescriptor.swizzle pub swizzle: TextureSwizzleChannels +field metal2vulkan-rt::TextureDescriptor.texture_type pub texture_type: TextureType +field metal2vulkan-rt::TextureDescriptor.usage pub usage: TextureUsage +field metal2vulkan-rt::TextureDescriptor.width pub width: u32 +field metal2vulkan-rt::TextureSwizzleChannels.alpha pub alpha: TextureSwizzle +field metal2vulkan-rt::TextureSwizzleChannels.blue pub blue: TextureSwizzle +field metal2vulkan-rt::TextureSwizzleChannels.green pub green: TextureSwizzle +field metal2vulkan-rt::TextureSwizzleChannels.red pub red: TextureSwizzle field metal2vulkan-rt::floor::BelowFloor.missing pub missing: Vec field metal2vulkan-rt::floor::Capabilities.buffer_int64_atomics pub buffer_int64_atomics: bool field metal2vulkan-rt::floor::Capabilities.extensions pub extensions: Vec<&'static CStr> @@ -5982,6 +6004,10 @@ macro-decl metal2vulkan-air::ir::Sym ir_id! Sym macro-decl metal2vulkan-air::ir::TypeId id_type! TypeId macro-decl metal2vulkan-air::ir::TypeId ir_id! TypeId macro-decl metal2vulkan-air::metal::DataType metal_enum! DataType +macro-decl metal2vulkan-rt::PixelFormat metal_enum! PixelFormat +macro-decl metal2vulkan-rt::TextureSwizzle metal_enum! TextureSwizzle +macro-decl metal2vulkan-rt::TextureType metal_enum! TextureType +macro-decl metal2vulkan-rt::TextureUsage metal_flags! TextureUsage macro-decl metal2vulkan-runtime::Degradation degradations! Degradation macro-decl metal2vulkan::metal::ArgumentBuffersTier metal_enum! ArgumentBuffersTier macro-decl metal2vulkan::metal::AttributeFormat metal_enum! AttributeFormat @@ -6200,6 +6226,341 @@ macro-member metal2vulkan-air::metal::DataType::UShort3 UShort3 = 43, "MTLDataTy macro-member metal2vulkan-air::metal::DataType::UShort4 UShort4 = 44, "MTLDataTypeUShort4"; macro-member metal2vulkan-air::metal::DataType::VisibleFunctionTable VisibleFunctionTable = 115, "MTLDataTypeVisibleFunctionTable"; macro-member metal2vulkan-air::metal::DataType::aliases aliases +macro-member metal2vulkan-rt::PixelFormat::A1BGR5Unorm A1BGR5Unorm = 41, "MTLPixelFormatA1BGR5Unorm"; +macro-member metal2vulkan-rt::PixelFormat::A8Unorm A8Unorm = 1, "MTLPixelFormatA8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::ABGR4Unorm ABGR4Unorm = 42, "MTLPixelFormatABGR4Unorm"; +macro-member metal2vulkan-rt::PixelFormat::ARGB8Unorm ARGB8Unorm = 84, "MTLPixelFormatARGB8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::ARGB8UnormSRGB ARGB8UnormSRGB = 85, "MTLPixelFormatARGB8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x10HDR ASTC10x10HDR = 234, "MTLPixelFormatASTC_10x10_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x10LDR ASTC10x10LDR = 216, "MTLPixelFormatASTC_10x10_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x10SRGB ASTC10x10SRGB = 198, "MTLPixelFormatASTC_10x10_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x5HDR ASTC10x5HDR = 231, "MTLPixelFormatASTC_10x5_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x5LDR ASTC10x5LDR = 213, "MTLPixelFormatASTC_10x5_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x5SRGB ASTC10x5SRGB = 195, "MTLPixelFormatASTC_10x5_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x6HDR ASTC10x6HDR = 232, "MTLPixelFormatASTC_10x6_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x6LDR ASTC10x6LDR = 214, "MTLPixelFormatASTC_10x6_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x6SRGB ASTC10x6SRGB = 196, "MTLPixelFormatASTC_10x6_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x8HDR ASTC10x8HDR = 233, "MTLPixelFormatASTC_10x8_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x8LDR ASTC10x8LDR = 215, "MTLPixelFormatASTC_10x8_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC10x8SRGB ASTC10x8SRGB = 197, "MTLPixelFormatASTC_10x8_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x10HDR ASTC12x10HDR = 235, "MTLPixelFormatASTC_12x10_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x10LDR ASTC12x10LDR = 217, "MTLPixelFormatASTC_12x10_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x10SRGB ASTC12x10SRGB = 199, "MTLPixelFormatASTC_12x10_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x12HDR ASTC12x12HDR = 236, "MTLPixelFormatASTC_12x12_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x12LDR ASTC12x12LDR = 218, "MTLPixelFormatASTC_12x12_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC12x12SRGB ASTC12x12SRGB = 200, "MTLPixelFormatASTC_12x12_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x2HDR ASTC4x2HDR = 221, "MTLPixelFormatASTC_4x2_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x2LDR ASTC4x2LDR = 203, "MTLPixelFormatASTC_4x2_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x2SRGB ASTC4x2SRGB = 185, "MTLPixelFormatASTC_4x2_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x4HDR ASTC4x4HDR = 222, "MTLPixelFormatASTC_4x4_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x4LDR ASTC4x4LDR = 204, "MTLPixelFormatASTC_4x4_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC4x4SRGB ASTC4x4SRGB = 186, "MTLPixelFormatASTC_4x4_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x4HDR ASTC5x4HDR = 223, "MTLPixelFormatASTC_5x4_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x4LDR ASTC5x4LDR = 205, "MTLPixelFormatASTC_5x4_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x4SRGB ASTC5x4SRGB = 187, "MTLPixelFormatASTC_5x4_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x5HDR ASTC5x5HDR = 224, "MTLPixelFormatASTC_5x5_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x5LDR ASTC5x5LDR = 206, "MTLPixelFormatASTC_5x5_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC5x5SRGB ASTC5x5SRGB = 188, "MTLPixelFormatASTC_5x5_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x5HDR ASTC6x5HDR = 225, "MTLPixelFormatASTC_6x5_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x5LDR ASTC6x5LDR = 207, "MTLPixelFormatASTC_6x5_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x5SRGB ASTC6x5SRGB = 189, "MTLPixelFormatASTC_6x5_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x6HDR ASTC6x6HDR = 226, "MTLPixelFormatASTC_6x6_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x6LDR ASTC6x6LDR = 208, "MTLPixelFormatASTC_6x6_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC6x6SRGB ASTC6x6SRGB = 190, "MTLPixelFormatASTC_6x6_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x4HDR ASTC8x4HDR = 227, "MTLPixelFormatASTC_8x4_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x4LDR ASTC8x4LDR = 209, "MTLPixelFormatASTC_8x4_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x4SRGB ASTC8x4SRGB = 191, "MTLPixelFormatASTC_8x4_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x5HDR ASTC8x5HDR = 228, "MTLPixelFormatASTC_8x5_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x5LDR ASTC8x5LDR = 210, "MTLPixelFormatASTC_8x5_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x5SRGB ASTC8x5SRGB = 192, "MTLPixelFormatASTC_8x5_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x6HDR ASTC8x6HDR = 229, "MTLPixelFormatASTC_8x6_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x6LDR ASTC8x6LDR = 211, "MTLPixelFormatASTC_8x6_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x6SRGB ASTC8x6SRGB = 193, "MTLPixelFormatASTC_8x6_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x8HDR ASTC8x8HDR = 230, "MTLPixelFormatASTC_8x8_HDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x8LDR ASTC8x8LDR = 212, "MTLPixelFormatASTC_8x8_LDR"; +macro-member metal2vulkan-rt::PixelFormat::ASTC8x8SRGB ASTC8x8SRGB = 194, "MTLPixelFormatASTC_8x8_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::AnyDepth AnyDepth = 651, "MTLPixelFormatAnyDepth"; +macro-member metal2vulkan-rt::PixelFormat::AnyStencil AnyStencil = 652, "MTLPixelFormatAnyStencil"; +macro-member metal2vulkan-rt::PixelFormat::B5G6R5Unorm B5G6R5Unorm = 40, "MTLPixelFormatB5G6R5Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BC1RGBA BC1RGBA = 130, "MTLPixelFormatBC1_RGBA"; +macro-member metal2vulkan-rt::PixelFormat::BC1RGBASRGB BC1RGBASRGB = 131, "MTLPixelFormatBC1_RGBA_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BC2RGBA BC2RGBA = 132, "MTLPixelFormatBC2_RGBA"; +macro-member metal2vulkan-rt::PixelFormat::BC2RGBASRGB BC2RGBASRGB = 133, "MTLPixelFormatBC2_RGBA_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BC3RGBA BC3RGBA = 134, "MTLPixelFormatBC3_RGBA"; +macro-member metal2vulkan-rt::PixelFormat::BC3RGBASRGB BC3RGBASRGB = 135, "MTLPixelFormatBC3_RGBA_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BC4RSnorm BC4RSnorm = 141, "MTLPixelFormatBC4_RSnorm"; +macro-member metal2vulkan-rt::PixelFormat::BC4RUnorm BC4RUnorm = 140, "MTLPixelFormatBC4_RUnorm"; +macro-member metal2vulkan-rt::PixelFormat::BC5RGSnorm BC5RGSnorm = 143, "MTLPixelFormatBC5_RGSnorm"; +macro-member metal2vulkan-rt::PixelFormat::BC5RGUnorm BC5RGUnorm = 142, "MTLPixelFormatBC5_RGUnorm"; +macro-member metal2vulkan-rt::PixelFormat::BC6HRGBFloat BC6HRGBFloat = 150, "MTLPixelFormatBC6H_RGBFloat"; +macro-member metal2vulkan-rt::PixelFormat::BC6HRGBUfloat BC6HRGBUfloat = 151, "MTLPixelFormatBC6H_RGBUfloat"; +macro-member metal2vulkan-rt::PixelFormat::BC7RGBAUnorm BC7RGBAUnorm = 152, "MTLPixelFormatBC7_RGBAUnorm"; +macro-member metal2vulkan-rt::PixelFormat::BC7RGBAUnormSRGB BC7RGBAUnormSRGB = 153, "MTLPixelFormatBC7_RGBAUnorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGR10A2Unorm BGR10A2Unorm = 94, "MTLPixelFormatBGR10A2Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BGR10A2UnormPQ BGR10A2UnormPQ = 629, "MTLPixelFormatBGR10A2Unorm_PQ"; +macro-member metal2vulkan-rt::PixelFormat::BGR10A2UnormSRGB BGR10A2UnormSRGB = 628, "MTLPixelFormatBGR10A2Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGR10XR BGR10XR = 554, "MTLPixelFormatBGR10_XR"; +macro-member metal2vulkan-rt::PixelFormat::BGR10XRSRGB BGR10XRSRGB = 555, "MTLPixelFormatBGR10_XR_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGR5A1Unorm BGR5A1Unorm = 43, "MTLPixelFormatBGR5A1Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10Uint BGRA10Uint = 637, "MTLPixelFormatBGRA10Uint"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UintPACKED BGRA10UintPACKED = 630, "MTLPixelFormatBGRA10Uint_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10Unorm BGRA10Unorm = 638, "MTLPixelFormatBGRA10Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormHLG BGRA10UnormHLG = 640, "MTLPixelFormatBGRA10Unorm_HLG"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormPACKED BGRA10UnormPACKED = 633, "MTLPixelFormatBGRA10Unorm_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormPACKEDHLG BGRA10UnormPACKEDHLG = 635, "MTLPixelFormatBGRA10Unorm_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormPACKEDPQ BGRA10UnormPACKEDPQ = 636, "MTLPixelFormatBGRA10Unorm_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormPACKEDSRGB BGRA10UnormPACKEDSRGB = 634, "MTLPixelFormatBGRA10Unorm_PACKED_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormPQ BGRA10UnormPQ = 641, "MTLPixelFormatBGRA10Unorm_PQ"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10UnormSRGB BGRA10UnormSRGB = 639, "MTLPixelFormatBGRA10Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10XR BGRA10XR = 552, "MTLPixelFormatBGRA10_XR"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10XRPACKED BGRA10XRPACKED = 631, "MTLPixelFormatBGRA10_XR_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10XRPACKEDSRGB BGRA10XRPACKEDSRGB = 632, "MTLPixelFormatBGRA10_XR_PACKED_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGRA10XRSRGB BGRA10XRSRGB = 553, "MTLPixelFormatBGRA10_XR_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGRA4Unorm BGRA4Unorm = 44, "MTLPixelFormatBGRA4Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BGRA8Unorm BGRA8Unorm = 80, "MTLPixelFormatBGRA8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::BGRA8UnormSRGB BGRA8UnormSRGB = 81, "MTLPixelFormatBGRA8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::BGRG422 BGRG422 = 241, "MTLPixelFormatBGRG422"; +macro-member metal2vulkan-rt::PixelFormat::Depth16Unorm Depth16Unorm = 250, "MTLPixelFormatDepth16Unorm"; +macro-member metal2vulkan-rt::PixelFormat::Depth24UnormStencil8 Depth24UnormStencil8 = 255, "MTLPixelFormatDepth24Unorm_Stencil8"; +macro-member metal2vulkan-rt::PixelFormat::Depth32Float Depth32Float = 252, "MTLPixelFormatDepth32Float"; +macro-member metal2vulkan-rt::PixelFormat::Depth32FloatStencil8 Depth32FloatStencil8 = 260, "MTLPixelFormatDepth32Float_Stencil8"; +macro-member metal2vulkan-rt::PixelFormat::EACR11Snorm EACR11Snorm = 172, "MTLPixelFormatEAC_R11Snorm"; +macro-member metal2vulkan-rt::PixelFormat::EACR11Unorm EACR11Unorm = 170, "MTLPixelFormatEAC_R11Unorm"; +macro-member metal2vulkan-rt::PixelFormat::EACRG11Snorm EACRG11Snorm = 176, "MTLPixelFormatEAC_RG11Snorm"; +macro-member metal2vulkan-rt::PixelFormat::EACRG11Unorm EACRG11Unorm = 174, "MTLPixelFormatEAC_RG11Unorm"; +macro-member metal2vulkan-rt::PixelFormat::EACRGBA8 EACRGBA8 = 178, "MTLPixelFormatEAC_RGBA8"; +macro-member metal2vulkan-rt::PixelFormat::EACRGBA8SRGB EACRGBA8SRGB = 179, "MTLPixelFormatEAC_RGBA8_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ETC2RGB8 ETC2RGB8 = 180, "MTLPixelFormatETC2_RGB8"; +macro-member metal2vulkan-rt::PixelFormat::ETC2RGB8A1 ETC2RGB8A1 = 182, "MTLPixelFormatETC2_RGB8A1"; +macro-member metal2vulkan-rt::PixelFormat::ETC2RGB8A1SRGB ETC2RGB8A1SRGB = 183, "MTLPixelFormatETC2_RGB8A1_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::ETC2RGB8SRGB ETC2RGB8SRGB = 181, "MTLPixelFormatETC2_RGB8_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::GBGR422 GBGR422 = 240, "MTLPixelFormatGBGR422"; +macro-member metal2vulkan-rt::PixelFormat::Invalid Invalid = 0, "MTLPixelFormatInvalid"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGB2BPP PVRTCRGB2BPP = 160, "MTLPixelFormatPVRTC_RGB_2BPP"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGB2BPPSRGB PVRTCRGB2BPPSRGB = 161, "MTLPixelFormatPVRTC_RGB_2BPP_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGB4BPP PVRTCRGB4BPP = 162, "MTLPixelFormatPVRTC_RGB_4BPP"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGB4BPPSRGB PVRTCRGB4BPPSRGB = 163, "MTLPixelFormatPVRTC_RGB_4BPP_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGBA2BPP PVRTCRGBA2BPP = 164, "MTLPixelFormatPVRTC_RGBA_2BPP"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGBA2BPPSRGB PVRTCRGBA2BPPSRGB = 165, "MTLPixelFormatPVRTC_RGBA_2BPP_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGBA4BPP PVRTCRGBA4BPP = 166, "MTLPixelFormatPVRTC_RGBA_4BPP"; +macro-member metal2vulkan-rt::PixelFormat::PVRTCRGBA4BPPSRGB PVRTCRGBA4BPPSRGB = 167, "MTLPixelFormatPVRTC_RGBA_4BPP_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::PixelFormat PixelFormat = "MTLPixelFormat" +macro-member metal2vulkan-rt::PixelFormat::R10UintPACKED R10UintPACKED = 643, "MTLPixelFormatR10Uint_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::R10UintX6 R10UintX6 = 642, "MTLPixelFormatR10Uint_X6"; +macro-member metal2vulkan-rt::PixelFormat::R10UnormPACKED R10UnormPACKED = 588, "MTLPixelFormatR10Unorm_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::R10UnormX6 R10UnormX6 = 576, "MTLPixelFormatR10Unorm_X6"; +macro-member metal2vulkan-rt::PixelFormat::R10UnormX6HLG R10UnormX6HLG = 621, "MTLPixelFormatR10Unorm_X6_HLG"; +macro-member metal2vulkan-rt::PixelFormat::R10UnormX6PQ R10UnormX6PQ = 606, "MTLPixelFormatR10Unorm_X6_PQ"; +macro-member metal2vulkan-rt::PixelFormat::R10UnormX6SRGB R10UnormX6SRGB = 577, "MTLPixelFormatR10Unorm_X6_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::R12UintPACKED R12UintPACKED = 647, "MTLPixelFormatR12Uint_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::R12UintX4 R12UintX4 = 646, "MTLPixelFormatR12Uint_X4"; +macro-member metal2vulkan-rt::PixelFormat::R12UnormX4 R12UnormX4 = 603, "MTLPixelFormatR12Unorm_X4"; +macro-member metal2vulkan-rt::PixelFormat::R12UnormX4HLG R12UnormX4HLG = 622, "MTLPixelFormatR12Unorm_X4_HLG"; +macro-member metal2vulkan-rt::PixelFormat::R12UnormX4PQ R12UnormX4PQ = 604, "MTLPixelFormatR12Unorm_X4_PQ"; +macro-member metal2vulkan-rt::PixelFormat::R16Bfloat R16Bfloat = 26, "MTLPixelFormatR16Bfloat"; +macro-member metal2vulkan-rt::PixelFormat::R16Float R16Float = 25, "MTLPixelFormatR16Float"; +macro-member metal2vulkan-rt::PixelFormat::R16Sint R16Sint = 24, "MTLPixelFormatR16Sint"; +macro-member metal2vulkan-rt::PixelFormat::R16Snorm R16Snorm = 22, "MTLPixelFormatR16Snorm"; +macro-member metal2vulkan-rt::PixelFormat::R16Uint R16Uint = 23, "MTLPixelFormatR16Uint"; +macro-member metal2vulkan-rt::PixelFormat::R16Unorm R16Unorm = 20, "MTLPixelFormatR16Unorm"; +macro-member metal2vulkan-rt::PixelFormat::R32Float R32Float = 55, "MTLPixelFormatR32Float"; +macro-member metal2vulkan-rt::PixelFormat::R32Sint R32Sint = 54, "MTLPixelFormatR32Sint"; +macro-member metal2vulkan-rt::PixelFormat::R32Uint R32Uint = 53, "MTLPixelFormatR32Uint"; +macro-member metal2vulkan-rt::PixelFormat::R8Sint R8Sint = 14, "MTLPixelFormatR8Sint"; +macro-member metal2vulkan-rt::PixelFormat::R8Snorm R8Snorm = 12, "MTLPixelFormatR8Snorm"; +macro-member metal2vulkan-rt::PixelFormat::R8Uint R8Uint = 13, "MTLPixelFormatR8Uint"; +macro-member metal2vulkan-rt::PixelFormat::R8Unorm R8Unorm = 10, "MTLPixelFormatR8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::R8UnormSRGB R8UnormSRGB = 11, "MTLPixelFormatR8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RG10UintPACKED RG10UintPACKED = 645, "MTLPixelFormatRG10Uint_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RG10UintX12 RG10UintX12 = 644, "MTLPixelFormatRG10Uint_X12"; +macro-member metal2vulkan-rt::PixelFormat::RG10UnormPACKED RG10UnormPACKED = 589, "MTLPixelFormatRG10Unorm_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RG10UnormX12 RG10UnormX12 = 578, "MTLPixelFormatRG10Unorm_X12"; +macro-member metal2vulkan-rt::PixelFormat::RG10UnormX12SRGB RG10UnormX12SRGB = 579, "MTLPixelFormatRG10Unorm_X12_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RG11B10Float RG11B10Float = 92, "MTLPixelFormatRG11B10Float"; +macro-member metal2vulkan-rt::PixelFormat::RG12UintPACKED RG12UintPACKED = 649, "MTLPixelFormatRG12Uint_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RG12UintX8 RG12UintX8 = 648, "MTLPixelFormatRG12Uint_X8"; +macro-member metal2vulkan-rt::PixelFormat::RG12UnormX8 RG12UnormX8 = 605, "MTLPixelFormatRG12Unorm_X8"; +macro-member metal2vulkan-rt::PixelFormat::RG16Bfloat RG16Bfloat = 66, "MTLPixelFormatRG16Bfloat"; +macro-member metal2vulkan-rt::PixelFormat::RG16Float RG16Float = 65, "MTLPixelFormatRG16Float"; +macro-member metal2vulkan-rt::PixelFormat::RG16Sint RG16Sint = 64, "MTLPixelFormatRG16Sint"; +macro-member metal2vulkan-rt::PixelFormat::RG16Snorm RG16Snorm = 62, "MTLPixelFormatRG16Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RG16Uint RG16Uint = 63, "MTLPixelFormatRG16Uint"; +macro-member metal2vulkan-rt::PixelFormat::RG16Unorm RG16Unorm = 60, "MTLPixelFormatRG16Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RG32Float RG32Float = 105, "MTLPixelFormatRG32Float"; +macro-member metal2vulkan-rt::PixelFormat::RG32Sint RG32Sint = 104, "MTLPixelFormatRG32Sint"; +macro-member metal2vulkan-rt::PixelFormat::RG32Uint RG32Uint = 103, "MTLPixelFormatRG32Uint"; +macro-member metal2vulkan-rt::PixelFormat::RG8Sint RG8Sint = 34, "MTLPixelFormatRG8Sint"; +macro-member metal2vulkan-rt::PixelFormat::RG8Snorm RG8Snorm = 32, "MTLPixelFormatRG8Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RG8Uint RG8Uint = 33, "MTLPixelFormatRG8Uint"; +macro-member metal2vulkan-rt::PixelFormat::RG8Unorm RG8Unorm = 30, "MTLPixelFormatRG8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RG8UnormSRGB RG8UnormSRGB = 31, "MTLPixelFormatRG8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RGB104202P RGB104202P = 543, "MTLPixelFormatRGB10_420_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB104202PPACKED RGB104202PPACKED = 546, "MTLPixelFormatRGB10_420_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RGB104222P RGB104222P = 544, "MTLPixelFormatRGB10_422_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB104222PPACKED RGB104222PPACKED = 547, "MTLPixelFormatRGB10_422_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RGB104442P RGB104442P = 545, "MTLPixelFormatRGB10_444_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB104442PPACKED RGB104442PPACKED = 548, "MTLPixelFormatRGB10_444_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A2Uint RGB10A2Uint = 91, "MTLPixelFormatRGB10A2Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A2Unorm RGB10A2Unorm = 90, "MTLPixelFormatRGB10A2Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A2UnormHLG RGB10A2UnormHLG = 623, "MTLPixelFormatRGB10A2Unorm_HLG"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A2UnormPQ RGB10A2UnormPQ = 587, "MTLPixelFormatRGB10A2Unorm_PQ"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A2UnormSRGB RGB10A2UnormSRGB = 586, "MTLPixelFormatRGB10A2Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82P RGB10A82P = 624, "MTLPixelFormatRGB10A8_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82PHLG RGB10A82PHLG = 627, "MTLPixelFormatRGB10A8_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82PPQ RGB10A82PPQ = 626, "MTLPixelFormatRGB10A8_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82PSRGB RGB10A82PSRGB = 625, "MTLPixelFormatRGB10A8_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82PXR10 RGB10A82PXR10 = 550, "MTLPixelFormatRGB10A8_2P_XR10"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A82PXR10SRGB RGB10A82PXR10SRGB = 551, "MTLPixelFormatRGB10A8_2P_XR10_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RGB10A8Uint2P RGB10A8Uint2P = 650, "MTLPixelFormatRGB10A8Uint_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Bfloat RGB16Bfloat = 100, "MTLPixelFormatRGB16Bfloat"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Float RGB16Float = 99, "MTLPixelFormatRGB16Float"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Sint RGB16Sint = 98, "MTLPixelFormatRGB16Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Snorm RGB16Snorm = 96, "MTLPixelFormatRGB16Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Uint RGB16Uint = 97, "MTLPixelFormatRGB16Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGB16Unorm RGB16Unorm = 95, "MTLPixelFormatRGB16Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGB32Float RGB32Float = 122, "MTLPixelFormatRGB32Float"; +macro-member metal2vulkan-rt::PixelFormat::RGB32Sint RGB32Sint = 121, "MTLPixelFormatRGB32Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGB32Uint RGB32Uint = 120, "MTLPixelFormatRGB32Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGB84202P RGB84202P = 540, "MTLPixelFormatRGB8_420_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB84222P RGB84222P = 541, "MTLPixelFormatRGB8_422_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB84442P RGB84442P = 542, "MTLPixelFormatRGB8_444_2P"; +macro-member metal2vulkan-rt::PixelFormat::RGB8Sint RGB8Sint = 48, "MTLPixelFormatRGB8Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGB8Snorm RGB8Snorm = 46, "MTLPixelFormatRGB8Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RGB8Uint RGB8Uint = 47, "MTLPixelFormatRGB8Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGB8Unorm RGB8Unorm = 45, "MTLPixelFormatRGB8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGB9E5Float RGB9E5Float = 93, "MTLPixelFormatRGB9E5Float"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Bfloat RGBA16Bfloat = 116, "MTLPixelFormatRGBA16Bfloat"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Float RGBA16Float = 115, "MTLPixelFormatRGBA16Float"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16FloatXR RGBA16FloatXR = 556, "MTLPixelFormatRGBA16Float_XR"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Sint RGBA16Sint = 114, "MTLPixelFormatRGBA16Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Snorm RGBA16Snorm = 112, "MTLPixelFormatRGBA16Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Uint RGBA16Uint = 113, "MTLPixelFormatRGBA16Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA16Unorm RGBA16Unorm = 110, "MTLPixelFormatRGBA16Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBA32Float RGBA32Float = 125, "MTLPixelFormatRGBA32Float"; +macro-member metal2vulkan-rt::PixelFormat::RGBA32Sint RGBA32Sint = 124, "MTLPixelFormatRGBA32Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA32Uint RGBA32Uint = 123, "MTLPixelFormatRGBA32Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA8Sint RGBA8Sint = 74, "MTLPixelFormatRGBA8Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA8Snorm RGBA8Snorm = 72, "MTLPixelFormatRGBA8Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBA8Uint RGBA8Uint = 73, "MTLPixelFormatRGBA8Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBA8Unorm RGBA8Unorm = 70, "MTLPixelFormatRGBA8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBA8UnormSRGB RGBA8UnormSRGB = 71, "MTLPixelFormatRGBA8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::RGBX16Float RGBX16Float = 315, "MTLPixelFormatRGBX16Float"; +macro-member metal2vulkan-rt::PixelFormat::RGBX16Sint RGBX16Sint = 314, "MTLPixelFormatRGBX16Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX16Uint RGBX16Uint = 313, "MTLPixelFormatRGBX16Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX32Float RGBX32Float = 325, "MTLPixelFormatRGBX32Float"; +macro-member metal2vulkan-rt::PixelFormat::RGBX32Sint RGBX32Sint = 324, "MTLPixelFormatRGBX32Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX32Uint RGBX32Uint = 323, "MTLPixelFormatRGBX32Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX8Sint RGBX8Sint = 304, "MTLPixelFormatRGBX8Sint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX8Snorm RGBX8Snorm = 302, "MTLPixelFormatRGBX8Snorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBX8Uint RGBX8Uint = 303, "MTLPixelFormatRGBX8Uint"; +macro-member metal2vulkan-rt::PixelFormat::RGBX8Unorm RGBX8Unorm = 300, "MTLPixelFormatRGBX8Unorm"; +macro-member metal2vulkan-rt::PixelFormat::RGBX8UnormSRGB RGBX8UnormSRGB = 301, "MTLPixelFormatRGBX8Unorm_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::Stencil8 Stencil8 = 253, "MTLPixelFormatStencil8"; +macro-member metal2vulkan-rt::PixelFormat::Unspecialized Unspecialized = 263, "MTLPixelFormatUnspecialized"; +macro-member metal2vulkan-rt::PixelFormat::X24Stencil8 X24Stencil8 = 262, "MTLPixelFormatX24_Stencil8"; +macro-member metal2vulkan-rt::PixelFormat::X32Stencil8 X32Stencil8 = 261, "MTLPixelFormatX32_Stencil8"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202P YCBCR104202P = 505, "MTLPixelFormatYCBCR10_420_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PHLG YCBCR104202PHLG = 608, "MTLPixelFormatYCBCR10_420_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPACKED YCBCR104202PPACKED = 508, "MTLPixelFormatYCBCR10_420_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPACKEDHLG YCBCR104202PPACKEDHLG = 611, "MTLPixelFormatYCBCR10_420_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPACKEDPQ YCBCR104202PPACKEDPQ = 567, "MTLPixelFormatYCBCR10_420_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPACKEDSRGB YCBCR104202PPACKEDSRGB = 528, "MTLPixelFormatYCBCR10_420_2P_PACKED_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPACKEDXR YCBCR104202PPACKEDXR = 594, "MTLPixelFormatYCBCR10_420_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PPQ YCBCR104202PPQ = 564, "MTLPixelFormatYCBCR10_420_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PSRGB YCBCR104202PSRGB = 525, "MTLPixelFormatYCBCR10_420_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104202PXR YCBCR104202PXR = 591, "MTLPixelFormatYCBCR10_420_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222P YCBCR104222P = 506, "MTLPixelFormatYCBCR10_422_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PHLG YCBCR104222PHLG = 609, "MTLPixelFormatYCBCR10_422_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPACKED YCBCR104222PPACKED = 509, "MTLPixelFormatYCBCR10_422_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPACKEDHLG YCBCR104222PPACKEDHLG = 612, "MTLPixelFormatYCBCR10_422_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPACKEDPQ YCBCR104222PPACKEDPQ = 568, "MTLPixelFormatYCBCR10_422_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPACKEDSRGB YCBCR104222PPACKEDSRGB = 529, "MTLPixelFormatYCBCR10_422_2P_PACKED_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPACKEDXR YCBCR104222PPACKEDXR = 595, "MTLPixelFormatYCBCR10_422_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PPQ YCBCR104222PPQ = 565, "MTLPixelFormatYCBCR10_422_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PSRGB YCBCR104222PSRGB = 526, "MTLPixelFormatYCBCR10_422_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104222PXR YCBCR104222PXR = 592, "MTLPixelFormatYCBCR10_422_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104441P YCBCR104441P = 504, "MTLPixelFormatYCBCR10_444_1P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104441PHLG YCBCR104441PHLG = 607, "MTLPixelFormatYCBCR10_444_1P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104441PPQ YCBCR104441PPQ = 563, "MTLPixelFormatYCBCR10_444_1P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104441PSRGB YCBCR104441PSRGB = 524, "MTLPixelFormatYCBCR10_444_1P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104441PXR YCBCR104441PXR = 590, "MTLPixelFormatYCBCR10_444_1P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442P YCBCR104442P = 507, "MTLPixelFormatYCBCR10_444_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PHLG YCBCR104442PHLG = 610, "MTLPixelFormatYCBCR10_444_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPACKED YCBCR104442PPACKED = 510, "MTLPixelFormatYCBCR10_444_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPACKEDHLG YCBCR104442PPACKEDHLG = 613, "MTLPixelFormatYCBCR10_444_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPACKEDPQ YCBCR104442PPACKEDPQ = 569, "MTLPixelFormatYCBCR10_444_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPACKEDSRGB YCBCR104442PPACKEDSRGB = 530, "MTLPixelFormatYCBCR10_444_2P_PACKED_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPACKEDXR YCBCR104442PPACKEDXR = 596, "MTLPixelFormatYCBCR10_444_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PPQ YCBCR104442PPQ = 566, "MTLPixelFormatYCBCR10_444_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PSRGB YCBCR104442PSRGB = 527, "MTLPixelFormatYCBCR10_444_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR104442PXR YCBCR104442PXR = 593, "MTLPixelFormatYCBCR10_444_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202P YCBCR124202P = 570, "MTLPixelFormatYCBCR12_420_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PHLG YCBCR124202PHLG = 615, "MTLPixelFormatYCBCR12_420_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PPACKED YCBCR124202PPACKED = 580, "MTLPixelFormatYCBCR12_420_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PPACKEDHLG YCBCR124202PPACKEDHLG = 618, "MTLPixelFormatYCBCR12_420_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PPACKEDPQ YCBCR124202PPACKEDPQ = 583, "MTLPixelFormatYCBCR12_420_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PPACKEDXR YCBCR124202PPACKEDXR = 600, "MTLPixelFormatYCBCR12_420_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PPQ YCBCR124202PPQ = 573, "MTLPixelFormatYCBCR12_420_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124202PXR YCBCR124202PXR = 597, "MTLPixelFormatYCBCR12_420_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222P YCBCR124222P = 571, "MTLPixelFormatYCBCR12_422_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PHLG YCBCR124222PHLG = 616, "MTLPixelFormatYCBCR12_422_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PPACKED YCBCR124222PPACKED = 581, "MTLPixelFormatYCBCR12_422_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PPACKEDHLG YCBCR124222PPACKEDHLG = 619, "MTLPixelFormatYCBCR12_422_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PPACKEDPQ YCBCR124222PPACKEDPQ = 584, "MTLPixelFormatYCBCR12_422_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PPACKEDXR YCBCR124222PPACKEDXR = 601, "MTLPixelFormatYCBCR12_422_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PPQ YCBCR124222PPQ = 574, "MTLPixelFormatYCBCR12_422_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124222PXR YCBCR124222PXR = 598, "MTLPixelFormatYCBCR12_422_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442P YCBCR124442P = 572, "MTLPixelFormatYCBCR12_444_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PHLG YCBCR124442PHLG = 617, "MTLPixelFormatYCBCR12_444_2P_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PPACKED YCBCR124442PPACKED = 582, "MTLPixelFormatYCBCR12_444_2P_PACKED"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PPACKEDHLG YCBCR124442PPACKEDHLG = 620, "MTLPixelFormatYCBCR12_444_2P_PACKED_HLG"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PPACKEDPQ YCBCR124442PPACKEDPQ = 585, "MTLPixelFormatYCBCR12_444_2P_PACKED_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PPACKEDXR YCBCR124442PPACKEDXR = 602, "MTLPixelFormatYCBCR12_444_2P_PACKED_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PPQ YCBCR124442PPQ = 575, "MTLPixelFormatYCBCR12_444_2P_PQ"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR124442PXR YCBCR124442PXR = 599, "MTLPixelFormatYCBCR12_444_2P_XR"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84202P YCBCR84202P = 500, "MTLPixelFormatYCBCR8_420_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84202PSRGB YCBCR84202PSRGB = 520, "MTLPixelFormatYCBCR8_420_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84221P YCBCR84221P = 501, "MTLPixelFormatYCBCR8_422_1P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84221PREV YCBCR84221PREV = 562, "MTLPixelFormatYCBCR8_422_1P_REV"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84221PSRGB YCBCR84221PSRGB = 521, "MTLPixelFormatYCBCR8_422_1P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84222P YCBCR84222P = 502, "MTLPixelFormatYCBCR8_422_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84222PSRGB YCBCR84222PSRGB = 522, "MTLPixelFormatYCBCR8_422_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84442P YCBCR84442P = 503, "MTLPixelFormatYCBCR8_444_2P"; +macro-member metal2vulkan-rt::PixelFormat::YCBCR84442PSRGB YCBCR84442PSRGB = 523, "MTLPixelFormatYCBCR8_444_2P_sRGB"; +macro-member metal2vulkan-rt::PixelFormat::YCBCRA84441P YCBCRA84441P = 560, "MTLPixelFormatYCBCRA8_444_1P"; +macro-member metal2vulkan-rt::PixelFormat::aliases aliases +macro-member metal2vulkan-rt::TextureSwizzle::Alpha Alpha = 5, "MTLTextureSwizzleAlpha"; +macro-member metal2vulkan-rt::TextureSwizzle::Blue Blue = 4, "MTLTextureSwizzleBlue"; +macro-member metal2vulkan-rt::TextureSwizzle::Green Green = 3, "MTLTextureSwizzleGreen"; +macro-member metal2vulkan-rt::TextureSwizzle::One One = 1, "MTLTextureSwizzleOne"; +macro-member metal2vulkan-rt::TextureSwizzle::Red Red = 2, "MTLTextureSwizzleRed"; +macro-member metal2vulkan-rt::TextureSwizzle::TextureSwizzle TextureSwizzle = "MTLTextureSwizzle" +macro-member metal2vulkan-rt::TextureSwizzle::Zero Zero = 0, "MTLTextureSwizzleZero"; +macro-member metal2vulkan-rt::TextureSwizzle::aliases aliases +macro-member metal2vulkan-rt::TextureType::Cube Cube = 5, "MTLTextureTypeCube"; +macro-member metal2vulkan-rt::TextureType::CubeArray CubeArray = 6, "MTLTextureTypeCubeArray"; +macro-member metal2vulkan-rt::TextureType::TextureBuffer TextureBuffer = 9, "MTLTextureTypeTextureBuffer"; +macro-member metal2vulkan-rt::TextureType::TextureType TextureType = "MTLTextureType" +macro-member metal2vulkan-rt::TextureType::Type1D Type1D = 0, "MTLTextureType1D"; +macro-member metal2vulkan-rt::TextureType::Type1DArray Type1DArray = 1, "MTLTextureType1DArray"; +macro-member metal2vulkan-rt::TextureType::Type2D Type2D = 2, "MTLTextureType2D"; +macro-member metal2vulkan-rt::TextureType::Type2DArray Type2DArray = 3, "MTLTextureType2DArray"; +macro-member metal2vulkan-rt::TextureType::Type2DMultisample Type2DMultisample = 4, "MTLTextureType2DMultisample"; +macro-member metal2vulkan-rt::TextureType::Type2DMultisampleArray Type2DMultisampleArray = 8, "MTLTextureType2DMultisampleArray"; +macro-member metal2vulkan-rt::TextureType::Type3D Type3D = 7, "MTLTextureType3D"; +macro-member metal2vulkan-rt::TextureType::aliases aliases +macro-member metal2vulkan-rt::TextureUsage::BLOCK_WRITES_ONLY BLOCK_WRITES_ONLY = 0x10000, "MTLTextureUsageBlockWritesOnly"; +macro-member metal2vulkan-rt::TextureUsage::NO_CONCURRENT_ACCESS NO_CONCURRENT_ACCESS = 0x4000, "MTLTextureUsageNoConcurrentAccess"; +macro-member metal2vulkan-rt::TextureUsage::PIXEL_FORMAT_VIEW PIXEL_FORMAT_VIEW = 0x10, "MTLTextureUsagePixelFormatView"; +macro-member metal2vulkan-rt::TextureUsage::RENDER_TARGET RENDER_TARGET = 0x4, "MTLTextureUsageRenderTarget"; +macro-member metal2vulkan-rt::TextureUsage::SHADER_ATOMIC SHADER_ATOMIC = 0x20, "MTLTextureUsageShaderAtomic"; +macro-member metal2vulkan-rt::TextureUsage::SHADER_READ SHADER_READ = 0x1, "MTLTextureUsageShaderRead"; +macro-member metal2vulkan-rt::TextureUsage::SHADER_WRITE SHADER_WRITE = 0x2, "MTLTextureUsageShaderWrite"; +macro-member metal2vulkan-rt::TextureUsage::TextureUsage TextureUsage = "MTLTextureUsage" +macro-member metal2vulkan-rt::TextureUsage::UNKNOWN UNKNOWN = 0x0, "MTLTextureUsageUnknown"; +macro-member metal2vulkan-rt::TextureUsage::VIDEO VIDEO = 0x8000, "MTLTextureUsageVideo"; +macro-member metal2vulkan-rt::TextureUsage::aliases aliases +macro-member metal2vulkan-rt::TextureUsage::dropped dropped macro-member metal2vulkan-runtime::Degradation::AbsentArgumentRead AbsentArgumentRead = "absent-argument-read", Precision, macro-member metal2vulkan-runtime::Degradation::AmplificationDraws AmplificationDraws = "amplification-draws", Performance, macro-member metal2vulkan-runtime::Degradation::AnisotropicFilter AnisotropicFilter = "anisotropic-filter"; @@ -8372,8 +8733,11 @@ macro-template metal2vulkan-air::vk_bit! ( $(#[$meta:meta])* $name:ident($raw:ty macro-template metal2vulkan-air::vk_enum! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [$name] = &[$($name::$konst),*]; const NAMES: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn from_raw(raw: $raw) -> $name { $name(raw) } pub const fn as_raw(self) -> $raw { self.0 } pub fn name(self) -> Option<&'static str> { Self::NAMES.iter().find(|(v, _)| *v == self).map(|(_, n)| *n) } pub fn is_known(self) -> bool { self.name().is_some() } pub fn from_name(name: &str) -> Option<$name> { Self::NAMES .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { match self.name() { Some(name) => f.write_str(name), None => write!(f, "{}({})", $vk, self.0), } } } }; macro-template metal2vulkan-air::vk_flags! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn empty() -> $name { $name(0) } pub const fn from_raw(raw: $raw) -> $name { $name(raw) } pub const fn as_raw(self) -> $raw { self.0 } pub const fn is_empty(self) -> bool { self.0 == 0 } pub const fn contains(self, other: $name) -> bool { self.0 & other.0 == other.0 } pub const fn intersects(self, other: $name) -> bool { self.0 & other.0 != 0 } pub const fn union(self, other: $name) -> $name { $name(self.0 | other.0) } pub const fn intersection(self, other: $name) -> $name { $name(self.0 & other.0) } pub const fn difference(self, other: $name) -> $name { $name(self.0 & !other.0) } pub const fn known_bits() -> $name { let mut bits: $raw = 0; let mut i = 0; while i < Self::KNOWN.len() { let v = Self::KNOWN[i].0 .0; if v.count_ones() == 1 { bits |= v; } i += 1; } $name(bits) } pub fn name(self) -> Option<&'static str> { Self::KNOWN.iter().find(|(v, _)| *v == self).map(|(_, n)| *n) } pub fn from_name(name: &str) -> Option<$name> { Self::KNOWN .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::ops::BitOr for $name { type Output = $name; fn bitor(self, rhs: $name) -> $name { self.union(rhs) } } impl ::std::ops::BitOrAssign for $name { fn bitor_assign(&mut self, rhs: $name) { *self = self.union(rhs); } } impl ::std::ops::BitAnd for $name { type Output = $name; fn bitand(self, rhs: $name) -> $name { self.intersection(rhs) } } impl ::std::ops::BitAndAssign for $name { fn bitand_assign(&mut self, rhs: $name) { *self = self.intersection(rhs); } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { if let Some(name) = self.name() { return f.write_str(name); } let mut rest = self.0; let mut first = true; for (v, n) in Self::KNOWN { if v.0.count_ones() == 1 && rest & v.0 != 0 { if !first { f.write_str(" | ")?; } f.write_str(n)?; rest &= !v.0; first = false; } } if rest != 0 || first { if !first { f.write_str(" | ")?; } write!(f, "{:#x}", rest)?; } Ok(()) } } }; macro-template metal2vulkan-rt::exposures! ($($exposure:expr => [$($feature:ident),* $(,)?];)*) => { impl VkFeature { pub const ALL: &'static [VkFeature] = &[$($(VkFeature::$feature),*),*]; pub fn exposure(self) -> Exposure { match self { $($(VkFeature::$feature)|* => $exposure,)* } } } }; +macro-template metal2vulkan-rt::flag_set! ( $(#[$doc:meta])* $name:ident { $($(#[$fdoc:meta])* $flag:ident = $bit:expr),* $(,)? } $(#[$all:meta])* ALL ) => { $(#[$doc])* #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct $name(u8); impl $name { pub const NONE: $name = $name(0); $($(#[$fdoc])* pub const $flag: $name = $name($bit);)* $(#[$all])* pub const ALL: &'static [($name, &'static str)] = &[$(($name::$flag, stringify!($flag))),*]; pub const fn union(self, other: $name) -> $name { $name(self.0 | other.0) } pub const fn contains(self, other: $name) -> bool { self.0 & other.0 == other.0 } #[cfg(test)] pub const fn bits(self) -> u8 { self.0 } } }; macro-template metal2vulkan-rt::id_type! ($(#[$doc:meta])* $name:ident) => { $(#[$doc])* #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $name(pub u32); impl $name { pub const fn new(index: u32) -> $name { $name(index) } pub const fn index(self) -> usize { self.0 as usize } } }; +macro-template metal2vulkan-rt::ir_id! ($(#[$doc:meta])* $name:ident, $prefix:literal) => { $(#[$doc])* #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $name(u32); impl $name { pub const fn new(index: u32) -> $name { $name(index) } pub const fn raw(self) -> u32 { self.0 } } impl Idx for $name { fn from_index(index: usize) -> Option<$name> { u32::try_from(index).ok().map($name::new) } fn index(self) -> usize { self.raw() as usize } } impl fmt::Debug for $name { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, concat!($prefix, "{}"), self.0) } } }; macro-template metal2vulkan-rt::metal_enum! ( $(#[$meta:meta])* $name:ident = $metal:literal { $($(#[$vmeta:meta])* $variant:ident = $value:literal, $mname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(u32)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum $name { $( #[doc = concat!("`", $mname, "`.")] $(#[$vmeta])* $variant = $value, )* } impl $name { pub const METAL_NAME: &'static str = $metal; pub const ALL: &'static [$name] = &[$($name::$variant),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn as_raw(self) -> u32 { self as u32 } pub const fn name(self) -> &'static str { match self { $($name::$variant => $mname,)* } } pub fn from_name(name: &str) -> Option<$name> { Self::ALL .iter() .copied() .find(|v| v.name() == name) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl From<$name> for u32 { fn from(value: $name) -> u32 { value.as_raw() } } impl TryFrom for $name { type Error = $crate::error::Error; fn try_from(value: u32) -> Result<$name, $crate::error::Error> { match value { $($value => Ok($name::$variant),)* _ => Err($crate::metal::unknown($metal, value)), } } } }; +macro-template metal2vulkan-rt::metal_enum! ( $(#[$meta:meta])* $name:ident = $metal:literal { $($variant:ident = $value:literal, $mname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(u32)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum $name { $( #[doc = concat!("`", $mname, "`.")] $variant = $value, )* } impl $name { pub const METAL_NAME: &'static str = $metal; pub const ALL: &'static [$name] = &[$($name::$variant),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn as_raw(self) -> u32 { self as u32 } pub const fn name(self) -> &'static str { match self { $($name::$variant => $mname,)* } } pub fn from_name(name: &str) -> Option<$name> { Self::ALL .iter() .copied() .find(|v| v.name() == name) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl From<$name> for u32 { fn from(value: $name) -> u32 { value.as_raw() } } impl TryFrom for $name { type Error = $crate::error::Error; fn try_from(value: u32) -> Result<$name, $crate::error::Error> { match value { $($value => Ok($name::$variant),)* _ => Err($crate::error::Error::InvalidRequest( $crate::error::RequestError::UnknownEnumValue { ty: $metal, value }, )), } } } }; macro-template metal2vulkan-rt::metal_flags! ( $(#[$meta:meta])* $name:ident = $metal:literal { $($konst:ident = $value:literal, $mname:literal;)* } aliases { $($alias:literal => $target:ident;)* } dropped { $($dropped:literal;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(try_from = "u32", into = "u32"))] pub struct $name(u32); impl $name { $( #[doc = concat!("`", $mname, "`.")] pub const $konst: $name = $name($value); )* pub const METAL_NAME: &'static str = $metal; pub const KNOWN: &'static [($name, &'static str)] = &[$(($name::$konst, $mname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const ALL_KNOWN: $name = $name(0 $(| $value)*); pub const DROPPED: u32 = 0 $(| $dropped)*; pub const fn empty() -> $name { $name(0) } pub const fn as_raw(self) -> u32 { self.0 } pub const fn is_empty(self) -> bool { self.0 == 0 } pub const fn without_dropped(self) -> $name { $name(self.0 & !Self::DROPPED) } pub const fn contains(self, other: $name) -> bool { self.0 & other.0 == other.0 } pub const fn intersects(self, other: $name) -> bool { self.0 & other.0 != 0 } pub const fn union(self, other: $name) -> $name { $name(self.0 | other.0) } pub const fn intersection(self, other: $name) -> $name { $name(self.0 & other.0) } pub const fn difference(self, other: $name) -> $name { $name(self.0 & !other.0) } pub fn from_name(name: &str) -> Option<$name> { Self::KNOWN .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl From<$name> for u32 { fn from(value: $name) -> u32 { value.as_raw() } } impl TryFrom for $name { type Error = $crate::error::Error; fn try_from(value: u32) -> Result<$name, $crate::error::Error> { if value & !($name::ALL_KNOWN.0 | $name::DROPPED) == 0 { Ok($name(value)) } else { Err($crate::metal::unknown($metal, value)) } } } impl ::std::ops::BitOr for $name { type Output = $name; fn bitor(self, rhs: $name) -> $name { self.union(rhs) } } impl ::std::ops::BitOrAssign for $name { fn bitor_assign(&mut self, rhs: $name) { *self = self.union(rhs); } } impl ::std::ops::BitAnd for $name { type Output = $name; fn bitand(self, rhs: $name) -> $name { self.intersection(rhs) } } impl ::std::ops::BitAndAssign for $name { fn bitand_assign(&mut self, rhs: $name) { *self = self.intersection(rhs); } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { if let Some((_, name)) = Self::KNOWN.iter().find(|(v, _)| v == self) { return f.write_str(name); } let mut rest = self.0; let mut first = true; for (v, n) in Self::KNOWN { if v.0.count_ones() == 1 && rest & v.0 != 0 { if !first { f.write_str(" | ")?; } f.write_str(n)?; rest &= !v.0; first = false; } } if rest != 0 || first { if !first { f.write_str(" | ")?; } write!(f, "{:#x}", rest)?; } Ok(()) } } }; macro-template metal2vulkan-rt::vk_bit! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal in $flags:ident { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(try_from = "u32", into = "u32"))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [$name] = &[$($name::$konst),*]; const NAMES: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn from_raw(raw: $raw) -> Option<$name> { let mut i = 0; while i < Self::KNOWN.len() { if Self::KNOWN[i].0 == raw { return Some(Self::KNOWN[i]); } i += 1; } None } pub const fn from_flags(flags: $flags) -> Option<$name> { Self::from_raw(flags.as_raw()) } pub const fn as_raw(self) -> $raw { self.0 } pub const fn flags(self) -> $flags { $flags::from_raw(self.0) } pub fn name(self) -> &'static str { Self::NAMES .iter() .find(|(v, _)| *v == self) .map(|(_, n)| *n) .expect("a single-bit value is always a named bit") } pub fn from_name(name: &str) -> Option<$name> { Self::NAMES .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::convert::TryFrom<$raw> for $name { type Error = $raw; fn try_from(raw: $raw) -> Result<$name, $raw> { $name::from_raw(raw).ok_or(raw) } } impl From<$name> for $raw { fn from(bit: $name) -> $raw { bit.0 } } impl From<$name> for $flags { fn from(bit: $name) -> $flags { bit.flags() } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { f.write_str(self.name()) } } }; macro-template metal2vulkan-rt::vk_enum! ( $(#[$meta:meta])* $name:ident($raw:ty) = $vk:literal { $($konst:ident = $value:literal, $vkname:literal;)* } aliases { $($alias:literal => $target:ident;)* } ) => { $(#[$meta])* #[repr(transparent)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(transparent))] pub struct $name($raw); impl $name { $( #[doc = concat!("`", $vkname, "`.")] pub const $konst: $name = $name($value); )* pub const VK_NAME: &'static str = $vk; pub const KNOWN: &'static [$name] = &[$($name::$konst),*]; const NAMES: &'static [($name, &'static str)] = &[$(($name::$konst, $vkname)),*]; const ALIASES: &'static [(&'static str, $name)] = &[$(($alias, $name::$target)),*]; pub const fn from_raw(raw: $raw) -> $name { $name(raw) } pub const fn as_raw(self) -> $raw { self.0 } pub fn name(self) -> Option<&'static str> { Self::NAMES.iter().find(|(v, _)| *v == self).map(|(_, n)| *n) } pub fn is_known(self) -> bool { self.name().is_some() } pub fn from_name(name: &str) -> Option<$name> { Self::NAMES .iter() .find(|(_, n)| *n == name) .map(|(v, _)| *v) .or_else(|| Self::ALIASES.iter().find(|(n, _)| *n == name).map(|(_, v)| *v)) } } impl ::std::fmt::Debug for $name { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { match self.name() { Some(name) => f.write_str(name), None => write!(f, "{}({})", $vk, self.0), } } } }; @@ -8819,6 +9183,7 @@ method metal2vulkan-rt::Device::new_buffer pub fn new_buffer(&self, block: Block method metal2vulkan-rt::Device::new_command_queue pub fn new_command_queue(&self, max_command_buffer_count: u32) -> Result method metal2vulkan-rt::Device::new_event pub fn new_event(&self) -> Result method metal2vulkan-rt::Device::new_shared_event pub fn new_shared_event(&self) -> Result +method metal2vulkan-rt::Device::new_texture pub fn new_texture(&self, descriptor: &TextureDescriptor, index: Option) -> Result method metal2vulkan-rt::Device::quiesce pub fn quiesce(&self, timeout: Duration) -> bool method metal2vulkan-rt::Device::raw pub fn raw(&self) -> RawDevice<'_> method metal2vulkan-rt::Device::release_block pub fn release_block(&self, block: BlockId) -> Result<(), Error> @@ -8857,11 +9222,20 @@ method metal2vulkan-rt::PhysicalDevice::check pub fn check(&self) -> Result vk::PhysicalDevice method metal2vulkan-rt::PrecisionNote::of_float_operator pub fn of_float_operator(op: AirBin, width: FloatWidth, fmf: FastMath, p: &DeviceProfile, math: EntryMath) -> Option> method metal2vulkan-rt::PrecisionNote::of_math_call pub fn of_math_call(call: Math, fmf: FastMath, p: &DeviceProfile, math: EntryMath) -> Option> +method metal2vulkan-rt::ResourceId::to_bits pub fn to_bits(self) -> u64 method metal2vulkan-rt::SharedEvent::as_event pub fn as_event(&self) -> &Event method metal2vulkan-rt::SharedEvent::notify_listener pub fn notify_listener(&self, value: u64, listener: impl FnOnce(u64) + Send + 'static) -> Result<(), Error> method metal2vulkan-rt::SharedEvent::set_signaled_value pub fn set_signaled_value(&self, value: u64) method metal2vulkan-rt::SharedEvent::signaled_value pub fn signaled_value(&self) -> u64 method metal2vulkan-rt::SharedEvent::wait_until_signaled_value pub fn wait_until_signaled_value(&self, value: u64, timeout: Duration) -> bool +method metal2vulkan-rt::Texture::descriptor pub fn descriptor(&self) -> &TextureDescriptor +method metal2vulkan-rt::Texture::get_bytes pub fn get_bytes(&self, bytes: &mut [u8], bytes_per_row: u64, bytes_per_image: u64, region: Region, level: u32, slice: u32) -> Result<(), Error> +method metal2vulkan-rt::Texture::gpu_resource_id pub fn gpu_resource_id(&self) -> ResourceId +method metal2vulkan-rt::Texture::replace_region pub fn replace_region(&self, region: Region, level: u32, slice: u32, bytes: &[u8], bytes_per_row: u64, bytes_per_image: u64) -> Result<(), Error> +method metal2vulkan-rt::TextureDescriptor::new pub fn new(texture_type: TextureType, pixel_format: PixelFormat, width: u32, height: u32) -> TextureDescriptor +method metal2vulkan-rt::TextureSwizzleChannels::compose pub fn compose(self, format: crate::vk::ComponentMapping) -> crate::vk::ComponentMapping +method metal2vulkan-rt::TextureSwizzleChannels::is_default pub fn is_default(self) -> bool +method metal2vulkan-rt::TextureSwizzleChannels::new pub fn new(red: TextureSwizzle, green: TextureSwizzle, blue: TextureSwizzle, alpha: TextureSwizzle) -> TextureSwizzleChannels method metal2vulkan-runtime::AddressModeMap::constexpr_mode pub fn constexpr_mode(&self, from: SamplerAddressMode) -> Option method metal2vulkan-runtime::AddressModeMap::is_identity pub fn is_identity(&self) -> bool method metal2vulkan-runtime::AddressModeMap::mode pub fn mode(&self, from: SamplerAddressMode) -> SamplerAddressMode @@ -10899,8 +11273,13 @@ struct metal2vulkan-rt::Library #[derive(Clone, Debug, PartialEq, Eq)] #[non_exh struct metal2vulkan-rt::Metrics #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct Metrics struct metal2vulkan-rt::PhysicalDevice #[derive(Clone)] pub struct PhysicalDevice struct metal2vulkan-rt::RawDevice #[non_exhaustive] pub struct RawDevice<'a> +struct metal2vulkan-rt::Region #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct Region +struct metal2vulkan-rt::ResourceId #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct ResourceId struct metal2vulkan-rt::ResourceUsage #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ResourceUsage(u32) struct metal2vulkan-rt::SharedEvent #[derive(Clone)] pub struct SharedEvent +struct metal2vulkan-rt::Texture #[derive(Clone)] pub struct Texture +struct metal2vulkan-rt::TextureDescriptor #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct TextureDescriptor +struct metal2vulkan-rt::TextureSwizzleChannels #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextureSwizzleChannels struct metal2vulkan-rt::floor::BelowFloor #[derive(Clone, Debug, PartialEq, Eq)] pub struct BelowFloor struct metal2vulkan-rt::floor::Capabilities pub struct Capabilities struct metal2vulkan-rt::floor::Features #[derive(Clone, Copy, Default)] pub struct Features @@ -11451,6 +11830,7 @@ trait-impl metal2vulkan-rt::Gap impl fmt::Display impl fmt::Display for Gap trait-impl metal2vulkan-rt::Limit impl fmt::Display impl fmt::Display for Limit trait-impl metal2vulkan-rt::Refusal impl fmt::Display impl fmt::Display for Refusal trait-impl metal2vulkan-rt::ResourceUsage impl BitOr impl BitOr for ResourceUsage +trait-impl metal2vulkan-rt::TextureSwizzleChannels impl Default impl Default for TextureSwizzleChannels trait-impl metal2vulkan-rt::floor::BelowFloor impl fmt::Display impl fmt::Display for BelowFloor trait-impl metal2vulkan-rt::floor::BelowFloor impl std::error::Error impl std::error::Error for BelowFloor trait-impl metal2vulkan-rt::floor::Missing impl fmt::Display impl fmt::Display for Missing @@ -12777,10 +13157,15 @@ variant metal2vulkan-rt::Error::Thread Thread(io::Error) variant metal2vulkan-rt::Error::Translation Translation(metal2vulkan::error::Error) variant metal2vulkan-rt::Error::Unsupported Unsupported(Gap) variant metal2vulkan-rt::Error::Vulkan Vulkan { call: &'static str, result: vk::Result } +variant metal2vulkan-rt::Gap::FloatDepthUpload FloatDepthUpload { pixel_format: PixelFormat } variant metal2vulkan-rt::Gap::IndirectCommandBuffers IndirectCommandBuffers variant metal2vulkan-rt::Gap::KernelInput KernelInput +variant metal2vulkan-rt::Gap::MemorylessTexture MemorylessTexture variant metal2vulkan-rt::Gap::PartialSimdgroups PartialSimdgroups { threads_per_threadgroup: [u32; 3], width: u32 } variant metal2vulkan-rt::Gap::PartialThreadgroups PartialThreadgroups { threads_per_grid: [u32; 3], threads_per_threadgroup: [u32; 3] } +variant metal2vulkan-rt::Gap::TextureBuffer TextureBuffer +variant metal2vulkan-rt::Gap::TextureBytes TextureBytes { pixel_format: PixelFormat } +variant metal2vulkan-rt::Gap::TextureFormat TextureFormat { pixel_format: PixelFormat } variant metal2vulkan-rt::IndexClass::Sampler Sampler variant metal2vulkan-rt::IndexClass::StorageTexture StorageTexture variant metal2vulkan-rt::IndexClass::Texture Texture @@ -12788,6 +13173,8 @@ variant metal2vulkan-rt::Limit::BlockIds BlockIds variant metal2vulkan-rt::Limit::BlockLen BlockLen { len: u64, max: u64 } variant metal2vulkan-rt::Limit::BytesLength BytesLength { len: u64, max: u64 } variant metal2vulkan-rt::Limit::IndexRange IndexRange { class: IndexClass, first: u32, count: u32 } +variant metal2vulkan-rt::Limit::TextureSamples TextureSamples { sample_count: u32, counts: u32 } +variant metal2vulkan-rt::Limit::TextureSize TextureSize { extent: [u32; 3], layers: u32, max_extent: [u32; 3], max_layers: u32 } variant metal2vulkan-rt::Limit::ThreadgroupMemory ThreadgroupMemory { length: u64, max: u32 } variant metal2vulkan-rt::Limit::ThreadgroupShape ThreadgroupShape { size: [u32; 3], max: [u32; 3] } variant metal2vulkan-rt::MemoryClass::Private Private @@ -12876,17 +13263,34 @@ variant metal2vulkan-rt::Refusal::BufferPastBlock BufferPastBlock { offset: u64, variant metal2vulkan-rt::Refusal::Committed Committed variant metal2vulkan-rt::Refusal::EmptyBuffer EmptyBuffer variant metal2vulkan-rt::Refusal::EncoderOpen EncoderOpen +variant metal2vulkan-rt::Refusal::IndexInUse IndexInUse { class: IndexClass, index: u32 } variant metal2vulkan-rt::Refusal::IndicesGranted IndicesGranted { class: IndexClass, index: u32 } +variant metal2vulkan-rt::Refusal::IndicesInUse IndicesInUse { class: IndexClass, index: u32 } variant metal2vulkan-rt::Refusal::IndicesNotGranted IndicesNotGranted { class: IndexClass, index: u32 } variant metal2vulkan-rt::Refusal::IndirectOffset IndirectOffset { offset: u64, length: u64 } variant metal2vulkan-rt::Refusal::NoBufferAtIndex NoBufferAtIndex { index: u32 } variant metal2vulkan-rt::Refusal::NoCommandBuffers NoCommandBuffers variant metal2vulkan-rt::Refusal::NoPipeline NoPipeline variant metal2vulkan-rt::Refusal::OtherDevice OtherDevice +variant metal2vulkan-rt::Refusal::TextureArrayLength TextureArrayLength { array_length: u32 } +variant metal2vulkan-rt::Refusal::TextureBytesLayout TextureBytesLayout { bytes_per_row: u64, bytes_per_image: u64, len: u64 } +variant metal2vulkan-rt::Refusal::TextureBytesPrivate TextureBytesPrivate +variant metal2vulkan-rt::Refusal::TextureCubeNotSquare TextureCubeNotSquare +variant metal2vulkan-rt::Refusal::TextureExtentForType TextureExtentForType +variant metal2vulkan-rt::Refusal::TextureIndex TextureIndex { index: Option } +variant metal2vulkan-rt::Refusal::TextureLevelCount TextureLevelCount { levels: u32, max: u32 } +variant metal2vulkan-rt::Refusal::TextureRegion TextureRegion { level: u32, slice: u32 } +variant metal2vulkan-rt::Refusal::TextureSampleCount TextureSampleCount { sample_count: u32 } +variant metal2vulkan-rt::Refusal::TextureSwizzleWithWrites TextureSwizzleWithWrites +variant metal2vulkan-rt::Refusal::TextureZeroExtent TextureZeroExtent variant metal2vulkan-rt::Refusal::ThreadgroupSize ThreadgroupSize { size: [u32; 3], max: u32 } variant metal2vulkan-rt::Resource::Buffer Buffer(&'a Buffer) variant metal2vulkan-rt::StageSource::Compiled Compiled(CompiledFunction) variant metal2vulkan-rt::StageSource::Function Function(FunctionDescriptor) +variant metal2vulkan-rt::StorageMode::Managed Managed +variant metal2vulkan-rt::StorageMode::Memoryless Memoryless +variant metal2vulkan-rt::StorageMode::Private Private +variant metal2vulkan-rt::StorageMode::Shared Shared variant metal2vulkan-rt::floor::Missing::Extension Extension(&'static CStr) variant metal2vulkan-rt::floor::Missing::Feature Feature { structure: &'static str, member: String } variant metal2vulkan-rt::floor::Missing::Limit Limit { name: &'static str, device: u32, needed: u32 } diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 501b7aa5d..47eb5a6c2 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -37,9 +37,9 @@ Columns: | What a call did wrong | 73 | 73 | 0 | 0 | 0 | 0 | 0 | | What a call did wrong, in detail | 174 | 157 | 0 | 0 | 0 | 0 | 0 | | Devices below the new runtime's floor | 6 | 6 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 13 | 13 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Limit` | 6 | 6 | 0 | 0 | 0 | 0 | 0 | -| The new runtime's `Gap` | 4 | 4 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 26 | 26 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Limit` | 8 | 8 | 0 | 0 | 0 | 0 | 0 | +| The new runtime's `Gap` | 9 | 9 | 0 | 0 | 0 | 0 | 0 | ## Totals by basis @@ -55,9 +55,9 @@ Columns: | What a call did wrong | 22 | 3 | 5 | 0 | 18 | 8 | 17 | 0 | | What a call did wrong, in detail | 60 | 26 | 23 | 0 | 39 | 26 | 0 | 0 | | Devices below the new runtime's floor | 0 | 0 | 0 | 6 | 0 | 0 | 0 | 0 | -| The new runtime's `Refusal` | 2 | 5 | 0 | 0 | 6 | 0 | 0 | 0 | -| The new runtime's `Limit` | 0 | 0 | 0 | 3 | 3 | 0 | 0 | 0 | -| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 4 | 0 | 0 | 0 | +| The new runtime's `Refusal` | 9 | 6 | 0 | 0 | 11 | 0 | 0 | 0 | +| The new runtime's `Limit` | 0 | 0 | 0 | 5 | 3 | 0 | 0 | 0 | +| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 9 | 0 | 0 | 0 | ## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`) @@ -624,7 +624,20 @@ Columns: | `ThreadgroupSize` | A threadgroup of no threads, or of more than the pipeline state's `maxTotalThreadsPerThreadgroup` | every device (a public call's own check of its arguments) | `metal-documented`: a threadgroup's threads total at most the state's `maxTotalThreadsPerThreadgroup` | 2: `crates/metal2vulkan-rt/src/encoder.rs (dispatch, 2 sites)` | `-` | | `IndirectOffset` | An indirect dispatch's argument offset that is not a multiple of 4, or that leaves fewer than 12 bytes (three 32-bit counts) in the buffer | every device (a public call's own check of its arguments) | `ours`: `vkCmdDispatchIndirect` reads three 32-bit counts at a 4-byte aligned offset inside the buffer | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)` | `-` | | `IndicesGranted` | A grant of an index already granted (`Device::grant_indices`) | every device (a public call's own check of its arguments) | `ours`: each index has one grant, so each resource ID names one object | 1: `crates/metal2vulkan-rt/src/arrays.rs (grant)` | `-` | -| `IndicesNotGranted` | A release of an index that is not granted (`Device::release_indices`) | every device (a public call's own check of its arguments) | `ours`: a grant is returned once | 1: `crates/metal2vulkan-rt/src/arrays.rs (release)` | `-` | +| `IndicesNotGranted` | A release of an index that is not granted (`Device::release_indices`) | every device (a public call's own check of its arguments) | `ours`: a grant is returned once | 2: `crates/metal2vulkan-rt/src/arrays.rs (occupy)`, `crates/metal2vulkan-rt/src/arrays.rs (release)` | `-` | +| `IndexInUse` | A texture at an index where a texture lives already (`Device::new_texture`) | every device (a public call's own check of its arguments) | `ours`: an index names one object at a time, and its elements are that object's | 1: `crates/metal2vulkan-rt/src/arrays.rs (occupy)` | `-` | +| `IndicesInUse` | A release of a grant while a texture lives at one of its indices (`Device::release_indices`) | every device (a public call's own check of its arguments) | `ours`: an object's index stays granted while the object lives | 1: `crates/metal2vulkan-rt/src/arrays.rs (release)` | `-` | +| `TextureIndex` | A texture whose usage shaders reach (read or write) made without an index, or one of no such usage made with one (`Device::new_texture`) | every device (a public call's own check of its arguments) | `ours`: an index is an element of set 1's texture arrays, which only shaders read | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` | `-` | +| `TextureZeroExtent` | A texture with a width, height or depth of 0 | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "MTLTextureDescriptor has width of zero", and the same for a height of zero | 1: `crates/metal2vulkan-rt/src/texture.rs (shape)` | `-` | +| `TextureExtentForType` | A texture with a height other than 1 of a 1D type, or a depth other than 1 of a type that is not 3D | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "the texture type MTLTextureType1D requires that height is 1", and the same for a 2D texture of depth 2 | 1: `crates/metal2vulkan-rt/src/texture.rs (shape)` | `-` | +| `TextureCubeNotSquare` | A cube texture whose width and height differ | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "MTLTextureDescriptor width must equal height for cube textures" | 1: `crates/metal2vulkan-rt/src/texture.rs (shape)` | `-` | +| `TextureArrayLength` | A texture with an array length of 0, or other than 1 of a type that is not an array | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "MTLTextureDescriptor has arrayLength of zero", where an array length of 2 is made | 2: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` | `-` | +| `TextureLevelCount` | A texture with a mipmap level count of 0, more than its full chain's, or more than 1 of a multisample or 1D type | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "requests 5 mipmap levels, but the dimensions (8, 8, 1) can only support a maxiumum of 4 levels", and the same for 0 | 1: `crates/metal2vulkan-rt/src/texture.rs (shape)` | `-` | +| `TextureSampleCount` | A texture with a sample count of 0, or other than 1 of a type that is not multisample | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "has sampleCount set but is using a type that does not allow sampleCount" for 0 and for 2 of a 2D texture | 1: `crates/metal2vulkan-rt/src/texture.rs (shape)` | `-` | +| `TextureSwizzleWithWrites` | A texture with a swizzle other than each channel from itself and shader-write or render-target usage | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "Texture swizzling is not compatable with MTLTextureUsageShaderWrite", where a swizzle of read usage alone is made | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` | `-` | +| `TextureBytesPrivate` | `Texture::replace_region` or `Texture::get_bytes` of a Private or Memoryless texture | every device (a public call's own check of its arguments) | `metal-documented`: Apple's documentation of `MTLStorageModePrivate`: "The resource is accessible only to the GPU." | 1: `crates/metal2vulkan-rt/src/texture.rs (copy)` | `-` | +| `TextureRegion` | `Texture::replace_region` or `Texture::get_bytes` of a level or slice past the texture's, or of a region that leaves the level or is off the... | every device (a public call's own check of its arguments) | `ours`: no texel of the texture is there to copy | 1: `crates/metal2vulkan-rt/src/texture.rs (copy)` | `-` | +| `TextureBytesLayout` | `Texture::replace_region` or `Texture::get_bytes` with rows closer than a row of the region, images closer than an image of it, or bytes too few... | every device (a public call's own check of its arguments) | `ours`: the call would read or write past the bytes it is given, or one texel's bytes over another's | 1: `crates/metal2vulkan-rt/src/texture.rs (copy)` | `-` | ## 12. The new runtime's `Limit` (`Error::Limit(Limit)`) @@ -636,6 +649,8 @@ Columns: | `ThreadgroupMemory` | A dispatch whose threadgroup memory, the kernel's own and the lengths set (each rounded up to 16 bytes), is past the device's... | at the device's limit | `device`: the device's `maxComputeSharedMemorySize` | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` | | `BytesLength` | `setBytes` data longer than one parameter ring chunk | every device (a public call's own check of its arguments) | `ours`: a ring chunk is 64 KiB | 1: `crates/metal2vulkan-rt/src/encoder.rs (set_bytes)` | `-` | | `IndexRange` | A grant of no indices, or one past its class's range (`Device::grant_indices`, [`IndexClass::range`]) | every device (a public call's own check of its arguments) | `ours`: the descriptor arrays are 65,536 sampled textures, 4,096 storage textures and 4,000 samplers of each use, and index 0 is nil | 1: `crates/metal2vulkan-rt/src/arrays.rs (grant)` | `-` | +| `TextureSize` | A texture whose extent or array layers are past what the device makes of its format, type, usage and sample count | at the device's limit | `device`: the image format query's `maxExtent` and `maxArrayLayers` | 1: `crates/metal2vulkan-rt/src/texture.rs (plan)` | `-` | +| `TextureSamples` | A multisample texture of a sample count the device does not make for its format, type and usage | at the device's limit | `device`: the image format query's `sampleCounts` | 1: `crates/metal2vulkan-rt/src/texture.rs (plan)` | `-` | ## 13. The new runtime's `Gap` (`Error::Unsupported(Gap)`) @@ -645,6 +660,11 @@ Columns: | `KernelInput` | A kernel that reads something the compute encoder does not supply yet | every device (a public call's own check of its arguments) | `ours`: the encoder binds buffers alone | 1: `crates/metal2vulkan-rt/src/pipeline.rs (gap)` | `-` | | `PartialSimdgroups` | A dispatch whose threadgroup is not whole SIMD groups of a kernel whose tier runs each SIMD group as one subgroup of `width` threads (a pinned... | every device (a public call's own check of its arguments) | `ours`: no emulated-SIMD-group module | 1: `crates/metal2vulkan-rt/src/pipeline.rs (emulated_kernel)` | `-` | | `PartialThreadgroups` | `dispatchThreads` with a grid that is not a whole number of threadgroups on some axis, of a kernel that observes its threadgroup partition and... | every device (a public call's own check of its arguments) | `ours`: the translator's partial-threadgroups variant does not take the emulated SIMD-group tier, nor a vote word past the workgroup memory | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` | +| `MemorylessTexture` | A texture of `Memoryless` storage, which only render passes use | every device (a public call's own check of its arguments) | `ours`: render passes are not built | 1: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` | `-` | +| `TextureBuffer` | A texture buffer (`MTLTextureTypeTextureBuffer`) | every device (a public call's own check of its arguments) | `ours`: no texel-buffer array; no replay stream uses one | 2: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` | `-` | +| `TextureFormat` | A texture of a pixel format the runtime makes no image of on this device for the descriptor's usage | every device (a public call's own check of its arguments) | `ours`: the device's format query, or the identity domains' shaders read every texture through its view alone | 1: `crates/metal2vulkan-rt/src/texture.rs (plan)` | `-` | +| `TextureBytes` | `Texture::replace_region` or `Texture::get_bytes` of a texture whose image is no plain copy of Metal's bytes in one aspect | every device (a public call's own check of its arguments) | `ours`: no copy between such an image and bytes is built | 1: `crates/metal2vulkan-rt/src/texture.rs (copy)` | `-` | +| `FloatDepthUpload` | `Texture::replace_region` into a 32-bit float depth (`Depth32Float`) | every device (a public call's own check of its arguments) | `ours`: no upload of a 32-bit float depth is built | 1: `crates/metal2vulkan-rt/src/texture.rs (replace_region)` | `-` | ## Appendix: every site @@ -1144,15 +1164,35 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::ThreadgroupSize`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch, 2 sites)` - `rt:Refusal::IndirectOffset`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)` - `rt:Refusal::IndicesGranted`: `crates/metal2vulkan-rt/src/arrays.rs (grant)` -- `rt:Refusal::IndicesNotGranted`: `crates/metal2vulkan-rt/src/arrays.rs (release)` +- `rt:Refusal::IndicesNotGranted`: `crates/metal2vulkan-rt/src/arrays.rs (occupy)`; `crates/metal2vulkan-rt/src/arrays.rs (release)` +- `rt:Refusal::IndexInUse`: `crates/metal2vulkan-rt/src/arrays.rs (occupy)` +- `rt:Refusal::IndicesInUse`: `crates/metal2vulkan-rt/src/arrays.rs (release)` +- `rt:Refusal::TextureIndex`: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` +- `rt:Refusal::TextureZeroExtent`: `crates/metal2vulkan-rt/src/texture.rs (shape)` +- `rt:Refusal::TextureExtentForType`: `crates/metal2vulkan-rt/src/texture.rs (shape)` +- `rt:Refusal::TextureCubeNotSquare`: `crates/metal2vulkan-rt/src/texture.rs (shape)` +- `rt:Refusal::TextureArrayLength`: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` +- `rt:Refusal::TextureLevelCount`: `crates/metal2vulkan-rt/src/texture.rs (shape)` +- `rt:Refusal::TextureSampleCount`: `crates/metal2vulkan-rt/src/texture.rs (shape)` +- `rt:Refusal::TextureSwizzleWithWrites`: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` +- `rt:Refusal::TextureBytesPrivate`: `crates/metal2vulkan-rt/src/texture.rs (copy)` +- `rt:Refusal::TextureRegion`: `crates/metal2vulkan-rt/src/texture.rs (copy)` +- `rt:Refusal::TextureBytesLayout`: `crates/metal2vulkan-rt/src/texture.rs (copy)` - `rt:Limit::BlockLen`: `crates/metal2vulkan-rt/src/memory.rs (dedicated_len)` - `rt:Limit::BlockIds`: `crates/metal2vulkan-rt/src/memory.rs (number)` - `rt:Limit::ThreadgroupShape`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` - `rt:Limit::ThreadgroupMemory`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` - `rt:Limit::BytesLength`: `crates/metal2vulkan-rt/src/encoder.rs (set_bytes)` - `rt:Limit::IndexRange`: `crates/metal2vulkan-rt/src/arrays.rs (grant)` +- `rt:Limit::TextureSize`: `crates/metal2vulkan-rt/src/texture.rs (plan)` +- `rt:Limit::TextureSamples`: `crates/metal2vulkan-rt/src/texture.rs (plan)` - `rt:Gap::IndirectCommandBuffers`: `crates/metal2vulkan-rt/src/pipeline.rs (new_compute_pipeline_state)` - `rt:Gap::KernelInput`: `crates/metal2vulkan-rt/src/pipeline.rs (gap)` - `rt:Gap::PartialSimdgroups`: `crates/metal2vulkan-rt/src/pipeline.rs (emulated_kernel)` - `rt:Gap::PartialThreadgroups`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` +- `rt:Gap::MemorylessTexture`: `crates/metal2vulkan-rt/src/texture.rs (new_texture)` +- `rt:Gap::TextureBuffer`: `crates/metal2vulkan-rt/src/texture.rs (shape, 2 sites)` +- `rt:Gap::TextureFormat`: `crates/metal2vulkan-rt/src/texture.rs (plan)` +- `rt:Gap::TextureBytes`: `crates/metal2vulkan-rt/src/texture.rs (copy)` +- `rt:Gap::FloatDepthUpload`: `crates/metal2vulkan-rt/src/texture.rs (replace_region)`