From aae58c6acbdf14c311cd023f7219b2fdbf35fd73 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 21:49:31 -0800 Subject: [PATCH] Runtime: an upload into a 32-bit float depth is the device's copy, under a static note What: replace_region, upload_region and the blit's copy_from_buffer(_with_options) into a 32-bit float depth (Depth32Float, or Depth32Float_Stencil8's depth) no longer answer Gap::FloatDepthUpload, which is gone: each is the plain vkCmdCopyBufferToImage into the depth aspect, on every device, and carries Texture::FLOAT_DEPTH_UPLOAD_NOTE (PrecisionNote::RestrictedDepthUpload, metal2vulkan-degrade-restricted-depth-upload). A value within [0, 1] is copied exactly; one outside it is the device's, as VUID-vkCmdCopyBufferToImage-pRegions-07931 leaves it without VK_EXT_depth_range_unrestricted, which the runtime enables nowhere. No byte is read and no query chooses anything. Translator: the new note's variant, codec tag (ARTIFACT_FORMAT_VERSION 592), validation's allowance (unbounded), the conformance degradation (not native, as restricted-depth-range is not) and docs/API.md's catalogue; RestrictedDepthRange's docs name the upload note. Conformance: the rt side announces the note at each upload into a 32-bit float depth; the compare cases declare it; heap_sizes' round trip writes depths within [0, 1] for Depth32Float. --- .../src/cases/sampler_crossings.rs | 14 +- .../src/cases/sampler_filtering.rs | 4 +- .../src/degradation.rs | 5 + crates/metal2vulkan-conformance/src/replay.rs | 2 +- .../metal2vulkan-conformance/src/rt_side.rs | 60 +++-- .../src/rt_side/heap_sizes.rs | 19 +- .../src/rt_side/work.rs | 20 +- crates/metal2vulkan-runtime/README.md | 19 +- crates/metal2vulkan-runtime/src/blit.rs | 20 +- .../metal2vulkan-runtime/src/depth_stencil.rs | 9 +- crates/metal2vulkan-runtime/src/error.rs | 16 -- .../metal2vulkan-runtime/src/error/basis.rs | 1 - crates/metal2vulkan-runtime/src/tests/blit.rs | 17 +- .../src/tests/blit_options.rs | 19 +- .../src/tests/float_depth.rs | 207 ++++++++++++++++++ crates/metal2vulkan-runtime/src/tests/mod.rs | 1 + .../metal2vulkan-runtime/src/tests/texture.rs | 18 +- crates/metal2vulkan-runtime/src/texture.rs | 38 ++-- .../fixtures/public/engine/depth_fill.metal | 4 +- .../src/candidate/platform/runtime.rs | 6 +- .../src/candidate/platform/runtime_depth.rs | 5 +- .../src/candidate/tests/engine_textures.rs | 10 +- .../src/executor_contract/depth_range.rs | 7 +- .../src/observation_contract/comparison.rs | 5 +- .../observation_contract/comparison/tests.rs | 1 + .../src/requirement.rs | 18 +- crates/metal2vulkan/src/cache/codec.rs | 1 + crates/metal2vulkan/src/cache/mod.rs | 2 +- crates/metal2vulkan/src/lower/texture/slot.rs | 4 +- crates/metal2vulkan/src/pipeline/artifact.rs | 32 ++- crates/metal2vulkan/tests/api_signatures.tsv | 5 +- docs/API.md | 23 +- docs/REFUSALS.md | 6 +- 33 files changed, 441 insertions(+), 177 deletions(-) create mode 100644 crates/metal2vulkan-runtime/src/tests/float_depth.rs diff --git a/crates/metal2vulkan-conformance/src/cases/sampler_crossings.rs b/crates/metal2vulkan-conformance/src/cases/sampler_crossings.rs index e7027c1c3..20f2712ac 100644 --- a/crates/metal2vulkan-conformance/src/cases/sampler_crossings.rs +++ b/crates/metal2vulkan-conformance/src/cases/sampler_crossings.rs @@ -952,9 +952,10 @@ impl Case for SamplerCrossings { // // The `compare-filters` row's `Depth32Float` texture: on every device (no runtime enables // `VK_EXT_depth_range_unrestricted`) the comparing stage records that its texels hold no - // value outside [0, 1] (`restricted-depth-range`). Its depths all lie in [0, 1], so the - // note moves no sample: measured on MoltenVK on the M3 Max, the notices site is the whole - // of the difference. + // value outside [0, 1] (`restricted-depth-range`), and its upload carries the note of an + // upload into a 32-bit float depth (`restricted-depth-upload`). Its depths all lie in + // [0, 1], so neither note moves a sample: measured on MoltenVK on the M3 Max, the notices + // site is the whole of the difference. // // Every row samples through the runtime sampler at `[[sampler(0)]]`, which the runtime's // pipelines note as scaled (`crate::replay::pixel_sampler_scaling_notice` holds why). @@ -970,9 +971,10 @@ impl Case for SamplerCrossings { allowances.push(crate::replay::swizzled_border_notice()); } if matches!(self.family, Family::CompareFilters) { - allowances.push(crate::replay::notice_allowance( - crate::degradation::Degradation::RestrictedDepthRange.code(), - )); + use crate::degradation::Degradation as D; + for kind in [D::RestrictedDepthRange, D::RestrictedDepthUpload] { + allowances.push(crate::replay::notice_allowance(kind.code())); + } } allowances } diff --git a/crates/metal2vulkan-conformance/src/cases/sampler_filtering.rs b/crates/metal2vulkan-conformance/src/cases/sampler_filtering.rs index 360045fe6..1c2b750db 100644 --- a/crates/metal2vulkan-conformance/src/cases/sampler_filtering.rs +++ b/crates/metal2vulkan-conformance/src/cases/sampler_filtering.rs @@ -882,9 +882,11 @@ impl Case for SamplerFiltering { // A `compare` row's comparing stage records that its texels hold no value outside // [0, 1] (`restricted-depth-range`). Every texel of the family lies in [0, 1], so it moves // no sample: measured on the M3 Max, the notices site is the whole of the difference of - // each of the eight rows. + // each of the eight rows. Its texture's upload carries the note of an upload into a 32-bit + // float depth (`restricted-depth-upload`), which moves none of those texels either. if matches!(self.family, Family::Compare(_)) { named.push(notice_allowance(Degradation::RestrictedDepthRange.code())); + named.push(notice_allowance(Degradation::RestrictedDepthUpload.code())); } named } diff --git a/crates/metal2vulkan-conformance/src/degradation.rs b/crates/metal2vulkan-conformance/src/degradation.rs index 77983c431..48187ae65 100644 --- a/crates/metal2vulkan-conformance/src/degradation.rs +++ b/crates/metal2vulkan-conformance/src/degradation.rs @@ -171,6 +171,8 @@ pub enum Degradation { DeviceOcclusionCount, /// `metal2vulkan-degrade-vertex-simdgroup-grouping`. VertexSimdgroupGrouping, + /// `metal2vulkan-degrade-restricted-depth-upload`. + RestrictedDepthUpload, } impl Degradation { @@ -256,6 +258,7 @@ impl Degradation { Degradation::DeviceFragmentRuns, Degradation::DeviceOcclusionCount, Degradation::VertexSimdgroupGrouping, + Degradation::RestrictedDepthUpload, ]; /// The kind's code, `metal2vulkan-degrade-`. @@ -383,6 +386,7 @@ impl Degradation { Degradation::VertexSimdgroupGrouping => { "metal2vulkan-degrade-vertex-simdgroup-grouping" } + Degradation::RestrictedDepthUpload => "metal2vulkan-degrade-restricted-depth-upload", } } @@ -471,6 +475,7 @@ impl Degradation { PrecisionNote::DeviceFragmentRuns => Degradation::DeviceFragmentRuns, PrecisionNote::DeviceOcclusionCount => Degradation::DeviceOcclusionCount, PrecisionNote::VertexSimdgroupGrouping => Degradation::VertexSimdgroupGrouping, + PrecisionNote::RestrictedDepthUpload => Degradation::RestrictedDepthUpload, } } } diff --git a/crates/metal2vulkan-conformance/src/replay.rs b/crates/metal2vulkan-conformance/src/replay.rs index e13c21b2f..63a479431 100644 --- a/crates/metal2vulkan-conformance/src/replay.rs +++ b/crates/metal2vulkan-conformance/src/replay.rs @@ -478,7 +478,7 @@ pub fn reads_opaque_black_border(spec: &crate::case::SamplerSpec) -> bool { /// /// **What is not here**, and stays each case's to declare: a note of what the device **lacks** /// (`device-signed-zero-inf-nan`, `device-anisotropic-filter`, `device-point-size`, -/// `restricted-depth-range`), of an emulation's own precision (`grad-from-bias`, +/// `restricted-depth-range`, `restricted-depth-upload`), of an emulation's own precision (`grad-from-bias`, /// `pixel-sampler-scaling`, `bicubic-filter-arithmetic`), of a Metal form not measured or not built /// (`blended-write-rounding`, `device-interpolation`, `reduction-order`), a native answer whose /// catalogue entry states the bound the cases that read it hold it to (the device's decode of a diff --git a/crates/metal2vulkan-conformance/src/rt_side.rs b/crates/metal2vulkan-conformance/src/rt_side.rs index 2e83ab683..10e104c66 100644 --- a/crates/metal2vulkan-conformance/src/rt_side.rs +++ b/crates/metal2vulkan-conformance/src/rt_side.rs @@ -19,8 +19,9 @@ //! [`metal2vulkan_runtime::RenderPipelineState::precision_notes`]), and so do a texture of a //! block-compressed format ([`metal2vulkan_runtime::Texture::precision_note`]) and a sampler state that //! reads an opaque-black border ([`metal2vulkan_runtime::SamplerState::precision_note`]). This side -//! announces the notes of each state its case dispatched or drew with, and of each texture and -//! sampler state it made, by the codes the suite's allowances name (`metal2vulkan-degrade-`). +//! announces the notes of each state its case dispatched or drew with, of each texture and +//! sampler state it made, and of each upload into a 32-bit float depth (`upload_note`), by the +//! codes the suite's allowances name (`metal2vulkan-degrade-`). use crate::case::{ Answer, ArgumentSlot, Bindings, Failure, Handle, SamplerSpec, ShaderSource, Side, @@ -422,6 +423,22 @@ impl<'a> RtSide<'a> { keep(&mut self.textures, texture) } + /// `replace_region` of `bytes` into `texture`, with its static note where it reaches a 32-bit + /// float depth ([`upload_note`]), which [`Side::announced`] answers. + fn replace( + &mut self, + texture: &rt::Texture, + (region, level, slice): (rt::Region, u32, u32), + bytes: &[u8], + pitches: (u64, u64), + ) -> Answer<()> { + (texture.replace_region(region, level, slice, bytes.into(), pitches.0, pitches.1)) + .map_err(|error| Failure::of_rt(&error))?; + let note = upload_note(texture, rt::BlitOption::None); + self.encoder_notes.extend(note); + Ok(()) + } + fn held(&self, handle: Handle) -> Answer<&rt::Buffer> { (self.buffers.get(handle.0 as usize)) .map(|(buffer, _)| buffer) @@ -500,6 +517,17 @@ impl<'a> RtSide<'a> { } } +/// The static note of an upload into `texture` of `option`, where it reaches a 32-bit float depth: +/// `Depth32Float`'s, or `Depth32Float_Stencil8`'s under its depth option +/// ([`rt::Texture::FLOAT_DEPTH_UPLOAD_NOTE`]). +fn upload_note(texture: &rt::Texture, option: rt::BlitOption) -> Option { + let pixel_format = texture.descriptor().pixel_format; + let depth = pixel_format == PixelFormat::Depth32Float + || (pixel_format == PixelFormat::Depth32FloatStencil8 + && option == rt::BlitOption::DepthFromDepthStencil); + depth.then_some(rt::Texture::FLOAT_DEPTH_UPLOAD_NOTE) +} + /// `value` kept in `kept`, by its handle. fn keep(kept: &mut Vec, value: T) -> Handle { kept.push(value); @@ -744,7 +772,7 @@ impl Side for RtSide<'_> { origin: [0, 0, 0], size: [size[0], size[1], 1], }; - (texture.replace_region(region, 0, 0, bytes.into(), row_pitch.into(), 0)).map_err(of_rt)?; + self.replace(&texture, (region, 0, 0), bytes, (row_pitch.into(), 0))?; Ok(self.keep_texture(texture)) } @@ -1221,8 +1249,7 @@ impl Side for RtSide<'_> { origin: [0, 0, 0], size: [spec.size[0], spec.size[1], 1], }; - (texture.replace_region(region, 0, 0, bytes.into(), spec.row_pitch.into(), 0)) - .map_err(of_rt)?; + self.replace(&texture, (region, 0, 0), bytes, (spec.row_pitch.into(), 0))?; } Ok(self.keep_texture(texture)) } @@ -1294,15 +1321,9 @@ impl Side for RtSide<'_> { origin: [x, y, z], size: [w, h, d.max(1)], }; - (texture.replace_region( - region, - upload.level, - upload.slice, - upload.bytes.into(), - upload.row_pitch.into(), - upload.image_pitch.into(), - )) - .map_err(of_rt)?; + let at = (region, upload.level, upload.slice); + let pitches = (upload.row_pitch.into(), upload.image_pitch.into()); + self.replace(&texture, at, upload.bytes, pitches)?; } Ok(self.keep_texture(texture)) } @@ -1412,15 +1433,8 @@ impl Side for RtSide<'_> { origin: [0, 0, 0], size: [size[0], size[1], 1], }; - (self.held_texture(texture)?.replace_region( - region, - 0, - 0, - bytes.into(), - row_pitch.into(), - 0, - )) - .map_err(|error| Failure::of_rt(&error)) + let texture = self.held_texture(texture)?.clone(); + self.replace(&texture, (region, 0, 0), bytes, (row_pitch.into(), 0)) } fn render(&mut self, work: &[crate::render::RenderWork]) -> Answer { diff --git a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs index 432ba8e0d..ca10053f9 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs @@ -10,13 +10,15 @@ //! 2. for a Private query, a heap of `align + size` bytes takes a texture of the descriptor at //! offset `align`; //! 3. there, where the runtime moves the format's bytes, level 0's first slice written from a -//! buffer reads back unchanged. +//! buffer reads back unchanged: a `Depth32Float` slice's bytes are depths within `[0, 1]`, the +//! only ones a copy into a depth aspect keeps on every device +//! (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`), and any other's a pattern of bytes. //! //! A Shared, Managed or Memoryless query is held to the first alone: the runtime places a heap //! texture in a Private block only (`Gap::HeapTexture`), and placing the descriptor in a Private //! heap would answer another query. A query whose bytes the runtime does not move, which its copy -//! answers `Gap::TextureBytes` (depth and stencil both, or multisample) or `Gap::FloatDepthUpload` -//! (`Depth32Float`) for, is held to the first two. +//! answers `Gap::TextureBytes` (depth and stencil both, or multisample) for, is held to the first +//! two. use super::{waited_for, work, RtDevice, WAIT}; use crate::case::{Answer, Failure}; @@ -82,7 +84,12 @@ fn round_trip( level: 0, planes: 0, }); - let written: Vec = (0..level.bytes).map(|at| (at % 251) as u8 ^ 0x5a).collect(); + let written: Vec = match descriptor.pixel_format { + rt::PixelFormat::Depth32Float => (0..level.bytes / 4) + .flat_map(|at| ((at % 251) as f32 / 250.0).to_le_bytes()) + .collect(), + _ => (0..level.bytes).map(|at| (at % 251) as u8 ^ 0x5a).collect(), + }; let (source, _source_blocks) = work::buffer_of(on, level.bytes, Storage::Shared)?; work::write(&source, &written)?; let (read, _read_blocks) = work::buffer_of(on, level.bytes, Storage::Shared)?; @@ -102,9 +109,7 @@ fn round_trip( let mut encoder = command_buffer.blit_command_encoder().map_err(failed)?; match encoder.copy_from_buffer(&source, layout, extent, texture, place) { Ok(()) => {} - Err(rt::Error::Unsupported( - rt::Gap::TextureBytes { .. } | rt::Gap::FloatDepthUpload { .. }, - )) => { + Err(rt::Error::Unsupported(rt::Gap::TextureBytes { .. })) => { encoder.end_encoding(); return Ok(()); } diff --git a/crates/metal2vulkan-conformance/src/rt_side/work.rs b/crates/metal2vulkan-conformance/src/rt_side/work.rs index 642c030c1..109cbb0c1 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/work.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/work.rs @@ -364,7 +364,8 @@ fn make(on: &RtDevice, made: &[Made], resource: &Resource) -> Answer { struct Run<'a> { on: &'a RtDevice, queue: &'a rt::CommandQueue, - /// The static notes of the textures the program made. + /// The static notes of the textures the program made and of its uploads into a 32-bit float + /// depth (`super::upload_note`). notes: &'a mut BTreeSet, made: Vec, /// The program's declarations, which a [`Step::Make`] reads to make a released resource again. @@ -379,7 +380,8 @@ struct Run<'a> { } /// Run `work` on `on`'s device through `queue`, answering what it read, with the static note of -/// each texture it makes (`Texture::precision_note`) in `notes`. +/// each texture it makes (`Texture::precision_note`) and of each upload into a 32-bit float depth +/// (`super::upload_note`) in `notes`. pub(super) fn run( on: &RtDevice, queue: &rt::CommandQueue, @@ -532,7 +534,9 @@ impl Run<'_> { let option = Self::option(*plane).unwrap_or_default(); (self.encoder()?) .copy_from_buffer_with_options(&source, layout, size, &destination, to, option) - .map_err(of_rt) + .map_err(of_rt)?; + self.notes.extend(super::upload_note(&destination, option)); + Ok(()) } Step::CopyBufferToTextureWithoutOptions { buffer, @@ -558,7 +562,10 @@ impl Run<'_> { (self .encoder()? .copy_from_buffer(&source, layout, size, &destination, to)) - .map_err(of_rt) + .map_err(of_rt)?; + let option = rt::BlitOption::None; + self.notes.extend(super::upload_note(&destination, option)); + Ok(()) } Step::CopyTextureToBuffer { texture, @@ -739,7 +746,10 @@ impl Run<'_> { *bytes_per_row, *bytes_per_image, )) - .map_err(of_rt) + .map_err(of_rt)?; + let option = rt::BlitOption::None; + self.notes.extend(super::upload_note(&texture, option)); + Ok(()) } Step::GetBytes { texture, diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 01ea22202..878282fa4 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1691,10 +1691,18 @@ made, with no lock, and never rewritten for layouts. driver (101.2145) answers neither bit for any format: there a texture buffer a function writes or reads through `access::read_write` is refused, but at a slot a texture atomic updates, and one it reads through `access::read` runs. -- `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. +- An upload into a 32-bit float depth (`Depth32Float`, or the depth of `Depth32Float_Stencil8`) + by `replace_region`, `upload_region` or a blit's `copy_from_buffer` is the device's copy into + the depth aspect, on every device, under the static note `PrecisionNote::RestrictedDepthUpload` + (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). A value within `[0, 1]` is copied exactly. Metal keeps + every `float` there bit for bit, and its depth comparisons compare it unclamped: measured on an + Apple M3 Max under macOS 27.0.1, and an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 + under macOS 26.7.1, for negative values, values above 1, denormals, infinities and NaNs. Vulkan + takes no value outside `[0, 1]` into a depth aspect without `VK_EXT_depth_range_unrestricted` + (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which the floor does not require and the + runtime enables on no device, and the runtime reads no uploaded value: so on every device, + whether or not it offers the extension, a value outside `[0, 1]` is the device's own, and so is + every read, sample, comparison and copy of it. - Their bytes are not copied for a format of depth and stencil both or a multisample texture (`Gap::TextureBytes`). - `Device::pixel_format_info` answers as an Apple M3 Max under macOS 27.0.1, which describes @@ -2570,8 +2578,7 @@ while the driver's exit handler waited on a lock, with every runtime thread alre though Metal takes them: an image's offset in the `VkBuffer` shaders reach that is no multiple of a texel block's bytes, or of 4 for a depth or stencil aspect, and a row stride of no whole number of a compressed format's blocks; also what `replace_region` and `get_bytes` refuse - (`Gap::TextureBytes`, and `Gap::FloatDepthUpload` into a texture), but for a plane option's copy - of a format of depth and stencil both. + (`Gap::TextureBytes`), but for a plane option's copy of a format of depth and stencil both. - `copy_from_buffer_to_buffer` is `copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`: one `vkCmdCopyBuffer` region between the bytes shaders reach (a Managed buffer's device copy, where the device keeps one), between the same two barriers as a fill, a copy into a Shared diff --git a/crates/metal2vulkan-runtime/src/blit.rs b/crates/metal2vulkan-runtime/src/blit.rs index 58b978ff3..e1b7d87df 100644 --- a/crates/metal2vulkan-runtime/src/blit.rs +++ b/crates/metal2vulkan-runtime/src/blit.rs @@ -308,12 +308,13 @@ impl BlitCommandEncoder { /// those bytes ([`Buffer::new_texture`]) whose rows meet the region's, which Metal leaves /// undefined, copies as [`copy_from_texture`](Self::copy_from_texture) copies two textures over /// one buffer whose bytes meet: in slabs, as from the source before the copy; the region on - /// its own texels copies nothing. + /// its own texels copies nothing. Into a 32-bit float depth it carries + /// [`Texture::FLOAT_DEPTH_UPLOAD_NOTE`]. /// /// Err: [`Refusal::OtherDevice`] for another device's buffer or texture; /// [`Refusal::TextureRegion`]; [`Refusal::BufferCopyLayout`] for a layout Metal's validation /// stops; [`Gap::BufferCopyAlignment`] for one no copy command in the floor addresses; - /// [`Gap::TextureBytes`]; [`Gap::FloatDepthUpload`]; [`Gap::OverlappingCopy`], counted, for + /// [`Gap::TextureBytes`]; [`Gap::OverlappingCopy`], counted, for /// rows of a texture in place that meet the region's where no axis cuts them so, and for a /// texture placed in a heap whose memory meets the region's bytes; [`Error::Vulkan`] where the /// command buffer cannot record. @@ -333,11 +334,12 @@ impl BlitCommandEncoder { /// `toTexture:destinationSlice:destinationLevel:destinationOrigin:options:`: as /// [`copy_from_buffer`](Self::copy_from_buffer), into the aspect `option` names, one /// `vkCmdCopyBufferToImage` region of that aspect alone. Metal takes a plane option of a - /// format of depth and stencil both, and of a format of the option's aspect alone. + /// format of depth and stencil both, and of a format of the option's aspect alone. Into a + /// 32-bit float depth it carries [`Texture::FLOAT_DEPTH_UPLOAD_NOTE`]. /// /// Err: as [`copy_from_buffer`](Self::copy_from_buffer)'s; [`Gap::TextureBytes`] for a plane /// option of a format without its aspect, for `None` of a format of depth and stencil both, - /// and for a multisample texture; [`Gap::FloatDepthUpload`] for a 32-bit float depth. + /// and for a multisample texture. pub fn copy_from_buffer_with_options( &mut self, source: &Buffer, @@ -359,7 +361,7 @@ impl BlitCommandEncoder { /// [`copy_from_texture`](Self::copy_from_texture)'s do. The command buffer keeps the texture /// and the buffer until it retires. /// - /// Err: as [`copy_from_buffer`](Self::copy_from_buffer)'s, but for [`Gap::FloatDepthUpload`]. + /// Err: as [`copy_from_buffer`](Self::copy_from_buffer)'s. pub fn copy_from_texture_to_buffer( &mut self, source: &Texture, @@ -385,8 +387,7 @@ impl BlitCommandEncoder { /// `option` names, one `vkCmdCopyImageToBuffer` region of that aspect alone, as /// [`copy_from_buffer_with_options`](Self::copy_from_buffer_with_options) takes it. /// - /// Err: as [`copy_from_buffer_with_options`](Self::copy_from_buffer_with_options)'s, but for - /// [`Gap::FloatDepthUpload`]. + /// Err: as [`copy_from_buffer_with_options`](Self::copy_from_buffer_with_options)'s. pub fn copy_from_texture_to_buffer_with_options( &mut self, source: &Texture, @@ -1565,7 +1566,7 @@ impl BufferCopy { /// offset of whole texel blocks, a multiple of 4 for a depth or stencil aspect, for each image, /// and a row stride of whole blocks ([`Gap::BufferCopyAlignment`]). /// -/// Err: [`Gap::TextureBytes`]; [`Gap::FloatDepthUpload`]; [`Refusal::TextureRegion`]; +/// Err: [`Gap::TextureBytes`]; [`Refusal::TextureRegion`]; /// [`Refusal::BufferCopyLayout`]; [`Gap::BufferCopyAlignment`]. pub(crate) fn buffer_copy( texture: &Side<'_>, @@ -1579,9 +1580,6 @@ pub(crate) fn buffer_copy( let Some(unit) = texture.unit else { return Err(Error::Unsupported(Gap::TextureBytes { pixel_format })); }; - if into_image && unit.float_depth() { - return Err(Error::Unsupported(Gap::FloatDepthUpload { pixel_format })); - } let mut size = size; if size[1] == 0 && matches!( diff --git a/crates/metal2vulkan-runtime/src/depth_stencil.rs b/crates/metal2vulkan-runtime/src/depth_stencil.rs index d4b8efd0e..a68e6bc3a 100644 --- a/crates/metal2vulkan-runtime/src/depth_stencil.rs +++ b/crates/metal2vulkan-runtime/src/depth_stencil.rs @@ -109,10 +109,11 @@ impl DepthStencilState { /// /// A negative or NaN depth, which Metal's test compares by its magnitude, takes no note: the /// runtime enables no `VK_EXT_depth_range_unrestricted` and refuses a clear depth outside - /// `[0, 1]` (`RenderPassKind::ClearDepth`), a viewport's depth range past it - /// (`DrawKind::Viewport`) and a 32-bit float depth upload (`Gap::FloatDepthUpload`), so a depth - /// attachment holds such a value only where Vulkan leaves a depth past the viewport's range - /// undefined. + /// `[0, 1]` (`RenderPassKind::ClearDepth`) and a viewport's depth range past it + /// (`DrawKind::Viewport`), so a depth attachment holds such a value only where Vulkan leaves a + /// depth past the viewport's range undefined, or where an upload put one there, which is the + /// device's under the upload's own note + /// ([`Texture::FLOAT_DEPTH_UPLOAD_NOTE`](crate::Texture::FLOAT_DEPTH_UPLOAD_NOTE)). pub fn precision_note(&self) -> Option { let tests = self.inner.tests; (tests.depth_test || tests.depth_write).then_some(PrecisionNote::DepthDenormals) diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index c4d73dc4b..84160b5ea 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1231,18 +1231,6 @@ pub enum Gap { /// The texture's pixel format. pixel_format: PixelFormat, }, - /// [`Texture::replace_region`](crate::Texture::replace_region) or - /// [`BlitCommandEncoder::copy_from_buffer`](crate::BlitCommandEncoder::copy_from_buffer) 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, - }, /// [`BlitCommandEncoder::copy_from_texture`](crate::BlitCommandEncoder::copy_from_texture) /// that the floor's `vkCmdCopyImage` does not make: a multisample texture; a format of depth /// and stencil both; one pixel format held in two Vulkan formats, which the two textures' @@ -2732,10 +2720,6 @@ impl fmt::Display for Gap { 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:?}" - ), Gap::TextureCopy { source, destination, diff --git a/crates/metal2vulkan-runtime/src/error/basis.rs b/crates/metal2vulkan-runtime/src/error/basis.rs index ad1355ae7..4b9eff191 100644 --- a/crates/metal2vulkan-runtime/src/error/basis.rs +++ b/crates/metal2vulkan-runtime/src/error/basis.rs @@ -142,7 +142,6 @@ impl Gap { Gap::CubicSampler => RefusalBasis::Ours, Gap::LodClamps => RefusalBasis::Ours, Gap::TextureBytes { .. } => RefusalBasis::Ours, - Gap::FloatDepthUpload { .. } => RefusalBasis::Ours, Gap::TextureCopy { .. } => RefusalBasis::Ours, Gap::OverlappingCopy { .. } => RefusalBasis::Ours, Gap::TextureOverBuffer { .. } => RefusalBasis::Ours, diff --git a/crates/metal2vulkan-runtime/src/tests/blit.rs b/crates/metal2vulkan-runtime/src/tests/blit.rs index eef42bd90..7af32db97 100644 --- a/crates/metal2vulkan-runtime/src/tests/blit.rs +++ b/crates/metal2vulkan-runtime/src/tests/blit.rs @@ -1011,7 +1011,7 @@ fn a_layout_metal_stops_is_refused_and_one_a_copy_command_cannot_address_is_a_ga )), alignment(PixelFormat::RGBA8Unorm, 0, 16, 66) ); - // No plain copy of the image's bytes, and no upload of a 32-bit float depth. + // No plain copy of the image's bytes; a 32-bit float depth copies both ways. let mut msaa = descriptor( TextureType::Type2DMultisample, PixelFormat::RGBA8Unorm, @@ -1046,13 +1046,14 @@ fn a_layout_metal_stops_is_refused_and_one_a_copy_command_cannot_address_is_a_ga into_image, ) }; - assert_eq!( - gap(float_copy(true)), - Gap::FloatDepthUpload { - pixel_format: PixelFormat::Depth32Float - } - ); - assert!(float_copy(false).is_ok()); + for into_image in [true, false] { + let copy = buffer_copied(float_copy(into_image)); + assert_eq!( + copy.unit.aspect, + vk::ImageAspectFlags::DEPTH, + "{into_image}" + ); + } assert!(matches!( refused(buffer_copy( &rgba, diff --git a/crates/metal2vulkan-runtime/src/tests/blit_options.rs b/crates/metal2vulkan-runtime/src/tests/blit_options.rs index 085627edb..14c4ed214 100644 --- a/crates/metal2vulkan-runtime/src/tests/blit_options.rs +++ b/crates/metal2vulkan-runtime/src/tests/blit_options.rs @@ -4,9 +4,8 @@ //! texel) or the stencil (1) of `Depth32Float_Stencil8`, the depth of `Depth16Unorm` and the //! stencil of `Stencil8`, as Metal takes the option of a format of that aspect alone (the //! conformance crate's `buffer-depth-samples` rows). `None` of a format of both, a plane option of -//! a format without its aspect and one of a multisample texture are `Gap::TextureBytes`; a copy -//! into the depth of `Depth32Float_Stencil8` is `Gap::FloatDepthUpload`, as one into -//! `Depth32Float` is. +//! a format without its aspect and one of a multisample texture are `Gap::TextureBytes`; the +//! depth of `Depth32Float_Stencil8` copies both ways, as `Depth32Float`'s does. //! - Under a device cfg, on every device of the cfg's kind: a pass clears a `Depth32Float_Stencil8` //! texture's depth to 0.25 and its stencil to 0x5a; a copy of `StencilFromDepthStencil` writes a //! region's stencil from a buffer; copies of each plane option read the whole level back, the @@ -121,14 +120,12 @@ fn a_plane_option_copies_the_aspect_it_names_where_the_format_has_it() { ); } } - assert_eq!( - plane(copy(both, d32s8, 1, Depth, false)), - (A::DEPTH.as_raw(), 4) - ); - assert_eq!( - gap(copy(both, d32s8, 1, Depth, true)), - Gap::FloatDepthUpload { pixel_format: both } - ); + for into_image in [false, true] { + assert_eq!( + plane(copy(both, d32s8, 1, Depth, into_image)), + (A::DEPTH.as_raw(), 4) + ); + } } #[cfg(any(m2v_gpu, m2v_cpu_icd))] diff --git a/crates/metal2vulkan-runtime/src/tests/float_depth.rs b/crates/metal2vulkan-runtime/src/tests/float_depth.rs new file mode 100644 index 000000000..5ff0c74a8 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/float_depth.rs @@ -0,0 +1,207 @@ +//! An upload into a 32-bit float depth, under a device cfg on every device of the cfg's kind, as +//! a guest fills a shadow map's texture: a 4 by 4 `Depth32Float` texture takes 16 depths within +//! `[0, 1]`, 0.5 among them, a Private one by a blit's copy from a buffer and a Shared one by +//! `replace_region`. +//! +//! - Each texture reads back bit for bit through a blit's copy into a buffer. +//! - The owned fixture `rrp_mirror_clamp`'s `rrp_mc_compare` compares each texel through a sampler +//! state of nearest filters and `Less` at a reference below its depth, on it and above it, +//! which pass, fail and fail, as Metal compares them: measured on an Apple M3 Max, an AMD Radeon +//! Pro 5300M and an Intel UHD Graphics 630, which keep every uploaded `float` and compare it +//! unclamped. +//! - Each upload carries `Texture::FLOAT_DEPTH_UPLOAD_NOTE`, `PrecisionNote::RestrictedDepthUpload`. +//! +//! `llvm-as` assembles the fixture; without it the test skips visibly. + +#[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod on_device { + use crate::tests::command::on_device::{each_device, finished}; + use crate::tests::draw::on_device::{floats, Buffers}; + use crate::{ + Buffer, BufferLayout, CompareFunction, ComputePipelineDescriptor, DispatchType, + FunctionDescriptor, HostBytes, IndexClass, Library, PixelFormat, Region, SamplerDescriptor, + StageSource, StorageMode, TextureDescriptor, TexturePlace, TextureType, TextureUsage, + }; + use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError}; + + /// The texture's side. + const SIDE: u32 = 4; + /// How far a reference lies below or above a texel's depth: half the depths' step. + const DELTA: f32 = 1.0 / 32.0; + /// The `float4`s `rrp_mc_compare` writes a lane; the comparison with no offset is the first. + const PER_LANE: usize = 5; + + /// Texel `i`'s depth: `i / 16`, and 1.0 at the last, each exact in a `float`. + fn depth(i: u32) -> f32 { + match i { + 15 => 1.0, + _ => i as f32 / 16.0, + } + } + + /// The lanes compared: each texel's centre with a reference below its depth, on it and above + /// it, those within `[0, 1]`, and whether `Less` passes there. + fn lanes() -> Vec<([f32; 2], f32, bool)> { + let mut out = Vec::new(); + for i in 0..SIDE * SIDE { + let at = [i % SIDE, i / SIDE].map(|c| (c as f32 + 0.5) / SIDE as f32); + let d = depth(i); + for reference in [d - DELTA, d, d + DELTA] { + if (0.0..=1.0).contains(&reference) { + out.push((at, reference, reference < d)); + } + } + } + out + } + + /// A Shared buffer's bytes, as the host reads them. + fn read(buffer: &Buffer) -> Vec { + let contents = buffer.contents().expect("a Shared buffer"); + // SAFETY: the buffer is alive, `length` bytes long, and no GPU work uses it. + unsafe { std::slice::from_raw_parts(contents.as_ptr(), buffer.length() as usize) }.to_vec() + } + + #[test] + fn every_device_compares_and_reads_back_an_uploaded_float_depth() { + let library = match llvm_assemble(&engine_dir().join("rrp_mirror_clamp.ll")) { + Ok(bitcode) => Library::from_air(&bitcode).expect("the library"), + Err(AssembleError::Missing(why)) => { + eprintln!("SKIPPED: {why}"); + return; + } + Err(error) => panic!("rrp_mirror_clamp.ll: {error:?}"), + }; + let depths: Vec = (0..SIDE * SIDE).map(depth).collect(); + let bytes = floats(&depths); + let lanes = lanes(); + each_device("float_depth_upload", |name, _, device| { + let ok = |result: Result<(), crate::Error>, what: &str| { + result.unwrap_or_else(|error| panic!("{name}: {what}: {error}")) + }; + let _textures = (device.grant_indices(IndexClass::Texture, 1, 2)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let _samplers = (device.grant_indices(IndexClass::Sampler, 1, 1)) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let mut sampler = SamplerDescriptor::new(); + sampler.compare_function = CompareFunction::Less; + let sampler = (device.new_sampler_state(&sampler, 1)) + .unwrap_or_else(|error| panic!("{name}: the sampler: {error}")); + let function = library.function("rrp_mc_compare").expect("the kernel"); + let descriptor = ComputePipelineDescriptor::new(StageSource::Function( + FunctionDescriptor::new(function), + )); + let state = (device.new_compute_pipeline_state(&descriptor, |numbered| { + Ok((2..).take(numbered.len()).collect()) + })) + .unwrap_or_else(|error| panic!("{name}: the state: {error}")); + + let make = |storage, index| { + let mut d = TextureDescriptor::new( + TextureType::Type2D, + PixelFormat::Depth32Float, + SIDE, + SIDE, + ); + d.usage = TextureUsage::SHADER_READ; + d.storage_mode = storage; + (device.new_texture(&d, Some(index))) + .unwrap_or_else(|error| panic!("{name}: the texture: {error}")) + }; + let private = make(StorageMode::Private, 1); + let shared = make(StorageMode::Shared, 2); + let whole = Region { + origin: [0; 3], + size: [SIDE, SIDE, 1], + }; + let row = u64::from(4 * SIDE); + ok( + shared.replace_region(whole, 0, 0, HostBytes::from(&bytes[..]), row, row * 4), + "replace_region", + ); + + let mut buffers = Buffers::new(&device); + let source = buffers.of(&device, &bytes); + let backs = [0xee; 2].map(|fill| buffers.of(&device, &vec![fill; bytes.len()])); + let coords: Vec = (lanes.iter()) + .flat_map(|&([s, t], reference, _)| [s, t, reference, 0.0]) + .collect(); + let coords = buffers.of(&device, &floats(&coords)); + let outs = + [0, 1].map(|_| buffers.of(&device, &vec![0xee; 16 * PER_LANE * lanes.len()])); + + let queue = device.new_command_queue(1).expect("a queue"); + let command_buffer = queue.command_buffer().expect("a command buffer"); + let layout = BufferLayout { + offset: 0, + bytes_per_row: row, + bytes_per_image: row * u64::from(SIDE), + }; + let at = TexturePlace { + slice: 0, + level: 0, + origin: [0; 3], + }; + let extent = [SIDE, SIDE, 1]; + let mut blit = (command_buffer.blit_command_encoder()) + .unwrap_or_else(|error| panic!("{name}: {error}")); + ok( + blit.copy_from_buffer(&source, layout, extent, &private, at), + "the copy in", + ); + for (texture, back) in [&private, &shared].into_iter().zip(&backs) { + ok( + blit.copy_from_texture_to_buffer(texture, at, extent, back, layout), + "the copy out", + ); + } + blit.end_encoding(); + let mut encoder = + (command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder"); + encoder + .set_compute_pipeline_state(&state) + .expect("the state"); + encoder + .set_sampler_state(Some(&sampler), 0) + .expect("the sampler"); + encoder.set_buffer(Some(&coords), 0, 0).expect("the lanes"); + let count = lanes.len() as u32; + for (texture, out) in [&private, &shared].into_iter().zip(&outs) { + encoder.set_texture(Some(texture), 0).expect("the texture"); + encoder.set_buffer(Some(out), 0, 1).expect("the output"); + (encoder.dispatch_threads([count, 1, 1], [count.min(64), 1, 1])) + .unwrap_or_else(|error| panic!("{name}: the dispatch: {error}")); + } + encoder.end_encoding(); + command_buffer.commit().expect("a commit"); + finished("float depth upload", &command_buffer); + assert_eq!(command_buffer.error(), None, "{name}"); + + for (way, (back, out)) in ["blit", "replace_region"] + .iter() + .zip(backs.iter().zip(&outs)) + { + assert_eq!(read(back), bytes, "{name}: {way}: the depths read back"); + let words = read(out); + let compared = |lane: usize| { + let at = 16 * PER_LANE * lane; + f32::from_le_bytes(words[at..at + 4].try_into().expect("a word")) + }; + for (lane, &(at, reference, passes)) in lanes.iter().enumerate() { + let want = if passes { 1.0 } else { 0.0 }; + assert_eq!( + compared(lane), + want, + "{name}: {way}: reference {reference} at {at:?}" + ); + } + println!( + "{name}: {way}: {} depths read back bit for bit, {} comparisons as Metal's, \ + 0.5 compared at 0.46875 reads 1", + depths.len(), + lanes.len() + ); + } + }); + } +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index ab0ed4a08..68e4718cb 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -32,6 +32,7 @@ mod fence; mod fetch; mod filter_nest; mod first_use_sites; +mod float_depth; mod floor; mod function_tables; mod gpu_span; diff --git a/crates/metal2vulkan-runtime/src/tests/texture.rs b/crates/metal2vulkan-runtime/src/tests/texture.rs index 6c92681dc..3da5b978b 100644 --- a/crates/metal2vulkan-runtime/src/tests/texture.rs +++ b/crates/metal2vulkan-runtime/src/tests/texture.rs @@ -508,26 +508,24 @@ mod on_device { d.array_length = 2; trip(11).run(&name, &make(&d, Some(4103)), 8); - // A 32-bit float depth texture: its bytes come out, and none go in. + // A 32-bit float depth texture: depths within `[0, 1]` go in and come back bit for bit + // (any other is the device's, `Texture::FLOAT_DEPTH_UPLOAD_NOTE`). 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 written: Vec = (0..64u8) + .flat_map(|i| (f32::from(i) / 63.0).to_le_bytes()) + .collect(); + (depth.replace_region(whole, 0, 0, crate::HostBytes::from(&written[..]), 32, 256)) + .unwrap_or_else(|error| panic!("{name}: depth replace_region: {error}")); 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, crate::HostBytes::from(&read[..]), 32, 256), - Err(Error::Unsupported(Gap::FloatDepthUpload { - pixel_format: PixelFormat::Depth32Float - })) - ), - "{name}" - ); + assert_eq!(read, written, "{name}: the depth's bytes"); // 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]); diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 568c2cddc..94a352cb6 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -925,12 +925,6 @@ pub(crate) struct CopyUnit { } impl CopyUnit { - /// Whether the unit is a 32-bit float depth, which no upload takes - /// ([`Gap::FloatDepthUpload`]). - pub(crate) fn float_depth(&self) -> bool { - self.aspect == vk::ImageAspectFlags::DEPTH && self.bytes == 4 - } - /// What a copy's offset in a buffer is a multiple of: the element's bytes, and 4 for a depth /// or stencil aspect. fn offset_align(&self) -> u64 { @@ -4160,6 +4154,16 @@ impl Texture { compressed.then_some(PrecisionNote::CompressedTexelDecode) } + /// No Metal counterpart: the static note of an upload into a 32-bit float depth + /// (`Depth32Float`, or the depth of `Depth32Float_Stencil8`) by [`Texture::replace_region`], + /// [`Texture::upload_region`] or a blit's copy from a buffer + /// ([`BlitCommandEncoder::copy_from_buffer`](crate::BlitCommandEncoder::copy_from_buffer)): + /// the device's copy into the depth aspect, which Vulkan defines for a value within `[0, 1]` + /// alone (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), where Metal keeps every `float`. The + /// runtime enables no `VK_EXT_depth_range_unrestricted` and reads no uploaded value, so on + /// every device a texel uploaded outside `[0, 1]` is the device's. + pub const FLOAT_DEPTH_UPLOAD_NOTE: PrecisionNote = PrecisionNote::RestrictedDepthUpload; + /// `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 @@ -4174,13 +4178,13 @@ impl Texture { /// instead, as Metal writes a Managed texture's CPU copy, and then /// [`Texture::upload_region`] copies them into the image; nothing is staged or counted. A /// texture over a buffer ([`Buffer::new_texture`]) takes them in the buffer, which is its - /// image's memory; nothing is staged, copied or counted. + /// image's memory; nothing is staged, copied or counted. Into a 32-bit float depth it carries + /// [`Texture::FLOAT_DEPTH_UPLOAD_NOTE`]. /// /// Err: [`Refusal::InScheduledHandler`] in a scheduled handler; /// [`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; [`Limit::MemoryAllocations`] where the region's block or a staging + /// [`Refusal::TextureBytesLayout`]; [`Gap::TextureBytes`]; [`Limit::MemoryAllocations`] where the region's block or a staging /// buffer's memory would take the device past its count; [`Error::Vulkan`] where either /// cannot be made, and with `VK_ERROR_DEVICE_LOST` where the device is lost while the call /// waits; [`Error::Quiesced`]; over a Managed buffer, what [`Buffer::did_modify_range`] @@ -4203,11 +4207,6 @@ impl Texture { else { return Ok(()); }; - if copy.unit.float_depth() { - return Err(Error::Unsupported(Gap::FloatDepthUpload { - pixel_format: inner.descriptor.pixel_format, - })); - } if let Some((host, place)) = inner.named_host(region, level, slice)? { // SAFETY: `copy` checked that each row lies in `bytes`, and the texture's creation // that each row of its place lies in the named buffer. @@ -4265,14 +4264,14 @@ impl Texture { /// until it completes, so the consumer may release the texture and the buffer once the call /// returns. /// [`Texture::replace_region`] on such a texture writes the named bytes, then calls this. An - /// empty region copies nothing. + /// empty region copies nothing. Into a 32-bit float depth it carries + /// [`Texture::FLOAT_DEPTH_UPLOAD_NOTE`]. /// /// Err: [`Refusal::InScheduledHandler`] in a scheduled handler; /// [`Refusal::ManagedTextureBytes`] for a texture without named bytes, or a depth or /// stencil region whose first byte is not a multiple of 4 in the buffer; /// [`Refusal::TextureRegion`] for a level, slice or region outside the texture or off its - /// format's block grid; [`Gap::FloatDepthUpload`] for a 32-bit float depth; - /// [`Error::Quiesced`], and [`Error::Vulkan`] where the upload's command buffer cannot be + /// format's block grid; [`Error::Quiesced`], and [`Error::Vulkan`] where the upload's command buffer cannot be /// made. pub fn upload_region(&self, region: Region, level: u32, slice: u32) -> Result<(), Error> { crate::command::not_in_scheduled_handler()?; @@ -4290,11 +4289,6 @@ impl Texture { let Some((copy, bytes, place, start)) = inner.named(region, level, slice)? else { return Ok(()); }; - if copy.unit.float_depth() { - return Err(Error::Unsupported(Gap::FloatDepthUpload { - pixel_format: inner.descriptor.pixel_format, - })); - } let [bw, bh] = copy.unit.block.map(u64::from); let row_length = place.bytes_per_row / u64::from(copy.unit.bytes) * bw; let image_height = match copy.images > 1 { diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/depth_fill.metal b/crates/metal2vulkan-validation/fixtures/public/engine/depth_fill.metal index bba4ac6e2..5803855c8 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/depth_fill.metal +++ b/crates/metal2vulkan-validation/fixtures/public/engine/depth_fill.metal @@ -1,7 +1,7 @@ // metal-fast-math: off // Owned fixture: the validation executor's fill of a 32-bit float depth texture through the -// runtime, which takes no upload of one (`Gap::FloatDepthUpload`): one draw writes every texel of -// one level and slice from a buffer, as a guest fills a depth texture by rendering into it. +// runtime: one draw writes every texel of one level and slice from a buffer, as a guest fills a +// depth texture by rendering into it. // // * depth_fill_vertex: one triangle over the whole target, vertex v at clip position // (2 (v << 1 & 2) - 1, 2 (v & 2) - 1, 0, 1). diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs index b1911d835..d3c6c72a5 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime.rs @@ -1078,11 +1078,11 @@ mod tests { ExecutorError::NotSupported(NotSupported::NotEnabled(gaps)) if gaps.len() == 1 && gaps[0].starts_with("texture 1: ") )); - let depth = rt::Error::Unsupported(rt::Gap::FloatDepthUpload { - pixel_format: rt::PixelFormat::Depth32Float, + let bytes = rt::Error::Unsupported(rt::Gap::TextureBytes { + pixel_format: rt::PixelFormat::Depth32FloatStencil8, }); assert!(matches!( - runtime_error("texture 0 level 0", depth), + runtime_error("texture 0 level 0", bytes), ExecutorError::Failed(_) )); } diff --git a/crates/metal2vulkan-validation/src/candidate/platform/runtime_depth.rs b/crates/metal2vulkan-validation/src/candidate/platform/runtime_depth.rs index 46748ea63..edebf9a17 100644 --- a/crates/metal2vulkan-validation/src/candidate/platform/runtime_depth.rs +++ b/crates/metal2vulkan-validation/src/candidate/platform/runtime_depth.rs @@ -1,7 +1,6 @@ //! The fill of a 32-bit float depth texture a run through the runtime binds -//! ([`super::runtime_textures`]). The runtime takes no upload of one -//! (`metal2vulkan_runtime::Gap::FloatDepthUpload`), so the run renders the case's depths into it, -//! as a guest fills one: one command buffer holds a pass per level and slice, each one draw of the +//! ([`super::runtime_textures`]). The run renders the case's depths into it, as a guest fills one +//! by rendering: one command buffer holds a pass per level and slice, each one draw of the //! owned `depth_fill` pair over the whole level (`fixtures/public/engine/depth_fill.metal`), whose //! fragment writes the depth at each pixel from a buffer of the level's texels under an //! always-passing depth test that writes. A render write is clamped to the viewport's `[0, 1]`, so diff --git a/crates/metal2vulkan-validation/src/candidate/tests/engine_textures.rs b/crates/metal2vulkan-validation/src/candidate/tests/engine_textures.rs index 4a5d2a338..946c77d1e 100644 --- a/crates/metal2vulkan-validation/src/candidate/tests/engine_textures.rs +++ b/crates/metal2vulkan-validation/src/candidate/tests/engine_textures.rs @@ -626,11 +626,11 @@ fn an_argument_buffer_buffer_is_the_buffer_at_its_field() { } } -/// A 32-bit float depth texture, which the runtime takes no upload of (`Gap::FloatDepthUpload`): -/// through the runtime the run fills it by a draw of the owned `depth_fill` pair, and on both runs -/// `depth_fill_read` reads every depth back as authored, row 1 below row 0. A depth outside -/// `[0, 1]`, which a draw would clamp, is refused through the runtime as the requirement the case -/// checker raises from the case's literals (`ToolingRequirement::DepthOutsideUnitRange`). +/// A 32-bit float depth texture: through the runtime the run fills it by a draw of the owned +/// `depth_fill` pair, and on both runs `depth_fill_read` reads every depth back as authored, row 1 +/// below row 0. A depth outside `[0, 1]`, which a draw would clamp, is refused through the runtime +/// as the requirement the case checker raises from the case's literals +/// (`ToolingRequirement::DepthOutsideUnitRange`). #[cfg(target_os = "linux")] #[test] fn a_float_depth_texture_is_filled_by_a_draw_and_reads_back_as_authored() { diff --git a/crates/metal2vulkan-validation/src/executor_contract/depth_range.rs b/crates/metal2vulkan-validation/src/executor_contract/depth_range.rs index c0dd7a9ef..3b52fcb66 100644 --- a/crates/metal2vulkan-validation/src/executor_contract/depth_range.rs +++ b/crates/metal2vulkan-validation/src/executor_contract/depth_range.rs @@ -1,7 +1,8 @@ //! The 32-bit float depths a case gives a depth image, and whether the engine's candidate can put -//! them there as Metal holds them: Metal's `Depth32Float` texel holds any `float`, and the runtime -//! takes no upload of a 32-bit float depth (`metal2vulkan_runtime::Gap::FloatDepthUpload`), so -//! the candidate fills one by a draw, which writes depths clamped to the viewport's `[0, 1]`. A +//! them there as Metal holds them: Metal's `Depth32Float` texel holds any `float`, the runtime's +//! upload leaves a depth outside `[0, 1]` the device's +//! (`metal2vulkan_runtime::Texture::FLOAT_DEPTH_UPLOAD_NOTE`), and the candidate fills one by a +//! draw, which writes depths clamped to the viewport's `[0, 1]`. A //! case whose depth texels or initial depth hold a value outside it stops the candidate on every //! device ([`ToolingRequirement::DepthOutsideUnitRange`], the runtime's limit): it neither uploads //! the value nor clamps it silently (an answer that is not the case's). The Metal oracle runs every diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index 683aba2ac..75bafcc56 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -182,6 +182,8 @@ impl UlpTable { /// - `RestrictedDepthRange`: unbounded: without `VK_EXT_depth_range_unrestricted` a depth image /// takes no texel outside `[0, 1]`, so a comparison of one Metal holds there can answer /// otherwise. +/// - `RestrictedDepthUpload`: unbounded: a depth uploaded outside `[0, 1]` is the device's, which +/// Vulkan does not define without `VK_EXT_depth_range_unrestricted`. /// - `CubeGradientFootprint`: unbounded: Apple's approximate length and truncated level against the /// device's can select another level or filter near a boundary, which changes whole texels, not /// lanes. @@ -331,7 +333,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::DeviceLineRasterization | N::DeviceFragmentRuns | N::DeviceOcclusionCount - | N::VertexSimdgroupGrouping => Allowance::Unbounded, + | N::VertexSimdgroupGrouping + | N::RestrictedDepthUpload => Allowance::Unbounded, } } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index eaede1eb2..bd5bc7fbc 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -89,6 +89,7 @@ fn every_precision_note_has_its_table_row() { (N::DeviceFragmentRuns, Allowance::Unbounded), (N::DeviceOcclusionCount, Allowance::Unbounded), (N::VertexSimdgroupGrouping, Allowance::Unbounded), + (N::RestrictedDepthUpload, Allowance::Unbounded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan-validation/src/requirement.rs b/crates/metal2vulkan-validation/src/requirement.rs index b8514adc0..ad291b650 100644 --- a/crates/metal2vulkan-validation/src/requirement.rs +++ b/crates/metal2vulkan-validation/src/requirement.rs @@ -127,15 +127,15 @@ pub enum ToolingRequirement { /// (`executor_contract::depth_range`): a `Depth32Float` texture's texels (a texture-array /// element's or an argument buffer's texture's among them) or a depth attachment's initial /// depth holds a NaN, a negative value other than `-0.0`, or a value above 1.0, which Metal's - /// texel keeps. The runtime takes no upload of a 32-bit float depth on any device - /// (`metal2vulkan_runtime::Gap::FloatDepthUpload`, which its own texture and blit tests hold - /// both ways), and a draw, the one way a guest fills such a texture through it, writes depths - /// clamped to the viewport's `[0, 1]`: no call of the runtime puts such a value where Metal - /// holds it, so the limit is the runtime's ([`Limit::Runtime`]) and the engine's candidate - /// does not run the case. The case checker raises it from the case's literals on every device - /// (`executor_contract::case_requirements`), never a source's structure, so no census row - /// carries it. The Metal oracle runs it, so a case of it stays Metal-qualified - /// ([`Self::qualifies_on_metal`]). + /// texel keeps. The runtime's upload of a 32-bit float depth leaves such a value the device's + /// on every device (`metal2vulkan_runtime::Texture::FLOAT_DEPTH_UPLOAD_NOTE`: Vulkan defines no + /// copy of one into a depth aspect without `VK_EXT_depth_range_unrestricted`, which it does not + /// enable), and a draw writes depths clamped to the viewport's `[0, 1]`: no call of the runtime + /// puts such a value where Metal holds it on every device, so the limit is the runtime's + /// ([`Limit::Runtime`]) and the engine's candidate does not run the case. The case checker + /// raises it from the case's literals on every device (`executor_contract::case_requirements`), + /// never a source's structure, so no census row carries it. The Metal oracle runs it, so a case + /// of it stays Metal-qualified ([`Self::qualifies_on_metal`]). DepthOutsideUnitRange, /// An object or mesh function's row or case (`executor_contract::mesh`), or a case that runs a /// pipeline template of one: the engine's candidate draws no mesh render pipeline. The runtime diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index ae71f7f66..44e966ba6 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1443,6 +1443,7 @@ codec_enum! { DeviceFragmentRuns, DeviceOcclusionCount, VertexSimdgroupGrouping, + RestrictedDepthUpload, } BindingSource { Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler }, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index f4d29c40d..818484186 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 2277; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 591; +pub const ARTIFACT_FORMAT_VERSION: u32 = 592; /// The version of what this crate gives a runtime for the runs of a compiled pipeline, beside the /// compile: the device a run opens and what it enables, the Vulkan and Metal vocabularies a runtime diff --git a/crates/metal2vulkan/src/lower/texture/slot.rs b/crates/metal2vulkan/src/lower/texture/slot.rs index 42bd2bfab..cfea75716 100644 --- a/crates/metal2vulkan/src/lower/texture/slot.rs +++ b/crates/metal2vulkan/src/lower/texture/slot.rs @@ -1225,8 +1225,8 @@ fn tiled_shape(shape: ImageShape) -> bool { /// The device's comparison reads the texture's depth image, so the function records /// `PrecisionNote::RestrictedDepthRange` on every device. Its reads, samples and gathers record /// nothing: -/// the interface's `TextureSlot::access` states them, and the consumer announces an upload its -/// depth image clamps (`restricted-depth-upload`), which every read of it then reads. No module +/// the interface's `TextureSlot::access` states them, and the consumer announces an upload into +/// the depth image (`restricted-depth-upload`), which every read of it then reads. No module /// requires the extension, since every value within `[0, 1]` is exact without it. pub(crate) fn depth_comparison(cx: &mut SelectCx<'_>) { cx.precision.insert(PrecisionNote::RestrictedDepthRange); diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 7a9812de2..ab2da76c6 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -805,13 +805,13 @@ pub enum PrecisionNote { /// every device (narrowed to comparisons). Metal's `Depth32Float` texels hold any `float`, /// and the device's comparison reads them from the texture's depth image, which Vulkan gives /// no value outside `[0, 1]` without `VK_EXT_depth_range_unrestricted`, which no runtime - /// enables: a copy may take none (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), so a consumer - /// clamps its uploads, and a render write is clamped to the viewport's depth range. A - /// comparison whose texel Metal holds outside `[0, 1]` can then differ, whatever the driver is - /// measured to keep (MoltenVK). Values within `[0, 1]` are exact. A function that reads, samples or gathers a depth - /// texture without comparing records nothing: its interface's `TextureSlot::access` states - /// the use, and a consumer that uploads a value into a depth image its device clamps announces - /// that upload (docs/API.md section 5). + /// enables: a copy may take none (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), so an upload + /// of one is the device's (`RestrictedDepthUpload`), and a render write is clamped to the + /// viewport's depth range. A comparison whose texel Metal holds outside `[0, 1]` can then + /// differ, whatever the driver is measured to keep (MoltenVK). Values within `[0, 1]` are + /// exact. A function that reads, samples or gathers a depth texture without comparing records + /// nothing: its interface's `TextureSlot::access` states the use, and a consumer's upload into + /// a depth image carries its own note (`RestrictedDepthUpload`). RestrictedDepthRange, /// An explicit-gradient sample of a cube texture takes Metal's footprint in a form a Vulkan /// device reads alike, but for what is not reproduced. Metal (measured on the Apple M3 Max @@ -2074,6 +2074,24 @@ pub enum PrecisionNote { /// /// Validation derives no tolerance from it: a difference stays a noted difference for review. VertexSimdgroupGrouping, + /// An upload of bytes into a 32-bit float depth (`Depth32Float`, or the depth of + /// `Depth32Float_Stencil8`): `replaceRegion:`, a Managed texture's upload and a blit's copy + /// from a buffer, each the device's copy into the depth aspect (`vkCmdCopyBufferToImage`), on + /// every device. Metal keeps every `float` there bit for bit, negative values, values above + /// 1, denormals, infinities and NaNs among them, and its depth comparisons then compare them + /// unclamped (measured on an Apple M3 Max under macOS 27.0.1, and an AMD Radeon Pro 5300M and + /// an Intel UHD Graphics 630 under macOS 26.7.1). Vulkan takes no value outside `[0, 1]` into + /// a depth aspect without `VK_EXT_depth_range_unrestricted` + /// (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which no runtime enables: a texel uploaded + /// outside `[0, 1]` is the device's, and so is every later read, sample, comparison and copy + /// of it. A value within `[0, 1]` is copied exactly, a denormal as `DepthDenormals` says. + /// Static per operation, decided by the format and never by the bytes: no pipeline stage + /// records it; `metal2vulkan-runtime`'s texture carries it + /// (`Texture::FLOAT_DEPTH_UPLOAD_NOTE`). + /// + /// Validation derives no tolerance from it: a difference stays a mismatch, which the note + /// explains. + RestrictedDepthUpload, } /// Which lowering strategies a module used, with their word costs. diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 904020a8d..cfa6e641e 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -60,6 +60,7 @@ assoc-const metal2vulkan-runtime::RenderCommandEncoder::VISIBILITY_NOTE pub cons assoc-const metal2vulkan-runtime::ResourceUsage::READ pub const READ: ResourceUsage assoc-const metal2vulkan-runtime::ResourceUsage::SAMPLE pub const SAMPLE: ResourceUsage assoc-const metal2vulkan-runtime::ResourceUsage::WRITE pub const WRITE: ResourceUsage +assoc-const metal2vulkan-runtime::Texture::FLOAT_DEPTH_UPLOAD_NOTE pub const FLOAT_DEPTH_UPLOAD_NOTE: PrecisionNote assoc-const metal2vulkan-runtime::TextureSwizzleChannels::DEFAULT pub const DEFAULT: TextureSwizzleChannels assoc-const metal2vulkan::bind::AstcDecode::BLOCK_BYTES pub const BLOCK_BYTES: u32 assoc-const metal2vulkan::bind::indirect_commands::BufferBinding::MIN_BUFFER_ADDRESS pub const MIN_BUFFER_ADDRESS: u64 @@ -211,6 +212,7 @@ assoc-const-value metal2vulkan-runtime::RenderCommandEncoder::VISIBILITY_NOTE Pr assoc-const-value metal2vulkan-runtime::ResourceUsage::READ ResourceUsage(1) assoc-const-value metal2vulkan-runtime::ResourceUsage::SAMPLE ResourceUsage(4) assoc-const-value metal2vulkan-runtime::ResourceUsage::WRITE ResourceUsage(2) +assoc-const-value metal2vulkan-runtime::Texture::FLOAT_DEPTH_UPLOAD_NOTE PrecisionNote::RestrictedDepthUpload assoc-const-value metal2vulkan-runtime::TextureSwizzleChannels::DEFAULT TextureSwizzleChannels assoc-const-value metal2vulkan::bind::AstcDecode::BLOCK_BYTES 16 assoc-const-value metal2vulkan::bind::indirect_commands::BufferBinding::MIN_BUFFER_ADDRESS 1 <<32 @@ -8362,7 +8364,6 @@ variant metal2vulkan-runtime::Gap::CubicSampler CubicSampler variant metal2vulkan-runtime::Gap::D3d11SurfaceBuffer D3d11SurfaceBuffer variant metal2vulkan-runtime::Gap::Draw Draw { kind: DrawKind } variant metal2vulkan-runtime::Gap::FillAlignment FillAlignment { start: u64, end: u64 } -variant metal2vulkan-runtime::Gap::FloatDepthUpload FloatDepthUpload { pixel_format: PixelFormat } variant metal2vulkan-runtime::Gap::HeapTexture HeapTexture { pixel_format: PixelFormat } variant metal2vulkan-runtime::Gap::ImageblockLength ImageblockLength variant metal2vulkan-runtime::Gap::IndirectCommandBuffers IndirectCommandBuffers { kind: IndirectCommandsKind } @@ -8514,6 +8515,7 @@ variant metal2vulkan-runtime::PrecisionNote::QuadsCountedBeforeDiscard QuadsCoun variant metal2vulkan-runtime::PrecisionNote::QuadsSplitByClipping QuadsSplitByClipping variant metal2vulkan-runtime::PrecisionNote::ReductionOrder ReductionOrder variant metal2vulkan-runtime::PrecisionNote::RestrictedDepthRange RestrictedDepthRange +variant metal2vulkan-runtime::PrecisionNote::RestrictedDepthUpload RestrictedDepthUpload variant metal2vulkan-runtime::PrecisionNote::RotatedBlendRounding RotatedBlendRounding variant metal2vulkan-runtime::PrecisionNote::SharedExponentKept SharedExponentKept variant metal2vulkan-runtime::PrecisionNote::SimdgroupAccessOrder SimdgroupAccessOrder @@ -9817,6 +9819,7 @@ variant metal2vulkan::pipeline::PrecisionNote::QuadsCountedBeforeDiscard QuadsCo variant metal2vulkan::pipeline::PrecisionNote::QuadsSplitByClipping QuadsSplitByClipping variant metal2vulkan::pipeline::PrecisionNote::ReductionOrder ReductionOrder variant metal2vulkan::pipeline::PrecisionNote::RestrictedDepthRange RestrictedDepthRange +variant metal2vulkan::pipeline::PrecisionNote::RestrictedDepthUpload RestrictedDepthUpload variant metal2vulkan::pipeline::PrecisionNote::RotatedBlendRounding RotatedBlendRounding variant metal2vulkan::pipeline::PrecisionNote::SharedExponentKept SharedExponentKept variant metal2vulkan::pipeline::PrecisionNote::SimdgroupAccessOrder SimdgroupAccessOrder diff --git a/docs/API.md b/docs/API.md index dfbdc5653..8d66fff94 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1456,6 +1456,8 @@ the translated module, the pixel format, the descriptor or the state, on every d samples through a constexpr sampler whose address mode reads an opaque-black border; - `Texture::precision_note`: `CompressedTexelDecode` where the texture's own pixel format is block-compressed; +- `Texture::FLOAT_DEPTH_UPLOAD_NOTE` (`RestrictedDepthUpload`, of an upload into a 32-bit float + depth by `replace_region`, `upload_region` or a blit's `copy_from_buffer`); - `SamplerState::precision_note`: `SwizzledOpaqueBlackBorder` where an address mode reads an opaque-black border; - `DepthStencilState::precision_note`: `DepthDenormals` where the state tests or writes depth; @@ -1832,10 +1834,23 @@ bound. - `metal2vulkan-degrade-restricted-depth-range` (precision). `PrecisionNote::RestrictedDepthRange`: The device compares a depth texture's texels, on every device: without `VK_EXT_depth_range_unrestricted`, which no runtime enables, Vulkan gives a depth image no - value outside `[0, 1]`, whatever its driver is measured to keep: an upload into a 32-bit float - depth is refused (`Gap::FloatDepthUpload`), and a render write is clamped to the viewport's - depth range. A - comparison of a texel Metal holds outside `[0, 1]` can differ; one within it is exact. + value outside `[0, 1]`, whatever its driver is measured to keep: an upload of one is the + device's (`metal2vulkan-degrade-restricted-depth-upload`), and a render write is clamped to the + viewport's depth range. A comparison of a texel Metal holds outside `[0, 1]` can differ; one + within it is exact. +- `metal2vulkan-degrade-restricted-depth-upload` (precision). + `PrecisionNote::RestrictedDepthUpload`: An upload into a 32-bit float depth (`Depth32Float`, or + the depth of `Depth32Float_Stencil8`), the device's copy into the depth aspect + (`vkCmdCopyBufferToImage`), on every device. On `metal2vulkan-runtime` it is the static note + `Texture::FLOAT_DEPTH_UPLOAD_NOTE` of `replace_region`, `upload_region` and a blit's + `copy_from_buffer` into one, decided by the format, never by the bytes. Metal keeps every + `float` there bit for bit, and its comparisons compare it unclamped (measured on an Apple M3 Max + under macOS 27.0.1, and an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under macOS + 26.7.1: negative values, values above 1, denormals, infinities and NaNs). Vulkan takes no value + outside `[0, 1]` into a depth aspect without `VK_EXT_depth_range_unrestricted` + (`VUID-vkCmdCopyBufferToImage-pRegions-07931`), which no runtime enables. Cost: a depth uploaded + outside `[0, 1]` is the device's, and so is every read, sample, comparison and copy of it; one + within it is copied exactly, a denormal as `metal2vulkan-degrade-depth-denormals` says. - `metal2vulkan-degrade-cube-gradient-footprint` (precision). `PrecisionNote::CubeGradientFootprint`: An explicit-gradient sample of a cube texture takes Metal's footprint in the form Vulkan's rule reads, in every stage on every device. Cost: the diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index aa3e839f5..bc03c3525 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -33,7 +33,7 @@ Columns: | Devices below the runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Refusal` | 84 | 84 | 0 | 0 | 0 | 0 | 0 | | The runtime's `Limit` | 17 | 17 | 0 | 0 | 0 | 0 | 0 | -| The runtime's `Gap` | 33 | 33 | 0 | 0 | 0 | 0 | 0 | +| The runtime's `Gap` | 32 | 32 | 0 | 0 | 0 | 0 | 0 | ## Totals by basis @@ -46,7 +46,7 @@ Columns: | Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 | | The runtime's `Refusal` | 22 | 25 | 0 | 0 | 37 | 0 | 0 | 0 | | The runtime's `Limit` | 0 | 0 | 0 | 13 | 4 | 0 | 0 | 0 | -| The runtime's `Gap` | 0 | 0 | 0 | 3 | 30 | 0 | 0 | 0 | +| The runtime's `Gap` | 0 | 0 | 0 | 3 | 29 | 0 | 0 | 0 | ## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`) @@ -350,7 +350,6 @@ Columns: | `CubicSampler` | A sampler state whose minification or magnification filter is cubic (`Device::new_sampler_state`) | every device (a public call's own check of its arguments) | `ours`: the translator's identity domains do not filter bicubically, and Vulkan's cubic filter is not Metal's | 1: `crates/metal2vulkan-runtime/src/sampler.rs (new_sampler_state)` | `-` | | `LodClamps` | A sampler state bound with LOD clamps its samples read otherwise through (`ComputeCommandEncoder::set_sampler_state_with_lod_clamps` and the... | every device (a public call's own check of its arguments) | `ours`: no replay stream binds such clamps: every bind-time clamp the streams make reads as its state's own | 1: `crates/metal2vulkan-runtime/src/sampler.rs (clamps_at_bind)` | `-` | | `TextureBytes` | `Texture::replace_region`, `Texture::get_bytes` or a blit copy between a buffer and a texture (`BlitCommandEncoder::copy_from_buffer`) of a... | every device (a public call's own check of its arguments) | `ours`: no copy between such an image and bytes is built, nor a texture buffer's copy as a buffer copy; no recorded stream copies a texture buffer | 5: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy, 2 sites)`, `crates/metal2vulkan-runtime/src/blit.rs (with_option)` (+2) | `-` | -| `FloatDepthUpload` | `Texture::replace_region` or `BlitCommandEncoder::copy_from_buffer` 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 | 3: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/texture.rs (replace_region)` (+1) | `-` | | `TextureCopy` | `BlitCommandEncoder::copy_from_texture` that the floor's `vkCmdCopyImage` does not make | every device (a public call's own check of its arguments) | `ours`: Vulkan 1.3 copies none of these with one command; each is built when a replay stream makes one | 2: `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)`, `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` | `-` | | `OverlappingCopy` | A blit copy whose source and destination share memory where no copy command orders it as from the source before the copy, which Metal leaves... | every device (a public call's own check of its arguments) | `ours`: no copy command reads bytes it writes, `VUID-vkCmdCopyImage-pRegions-00124` and its twins; the first shapes are built, cut on two levels, when a replay stream or a walk counts one | 2: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`, `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)` | `-` | | `TextureOverBuffer` | A texture over a buffer (`Buffer::new_texture`) the runtime does not make | every device (a public call's own check of its arguments) | `ours`: the in-place linear image and the copy form take one 2D color image, and a texture buffer's view the texel-buffer offset alignment of Vulkan 1.3 | 4: `crates/metal2vulkan-runtime/src/texture.rs (check_over)`, `crates/metal2vulkan-runtime/src/texture.rs (error)` (+2) | `-` | @@ -631,7 +630,6 @@ Each refusal's sites, with the function that builds it. - `rt:Gap::CubicSampler`: `crates/metal2vulkan-runtime/src/sampler.rs (new_sampler_state)` - `rt:Gap::LodClamps`: `crates/metal2vulkan-runtime/src/sampler.rs (clamps_at_bind)` - `rt:Gap::TextureBytes`: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy, 2 sites)`; `crates/metal2vulkan-runtime/src/blit.rs (with_option)`; `crates/metal2vulkan-runtime/src/texture.rs (check_places)`; `crates/metal2vulkan-runtime/src/texture.rs (copy)` -- `rt:Gap::FloatDepthUpload`: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-runtime/src/texture.rs (replace_region)`; `crates/metal2vulkan-runtime/src/texture.rs (upload_region)` - `rt:Gap::TextureCopy`: `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)`; `crates/metal2vulkan-runtime/src/blit.rs (texture_copy)` - `rt:Gap::OverlappingCopy`: `crates/metal2vulkan-runtime/src/blit.rs (buffer_copy)`; `crates/metal2vulkan-runtime/src/blit.rs (copy_from_texture)` - `rt:Gap::TextureOverBuffer`: `crates/metal2vulkan-runtime/src/texture.rs (check_over)`; `crates/metal2vulkan-runtime/src/texture.rs (error)`; `crates/metal2vulkan-runtime/src/texture.rs (over_texel)`; `crates/metal2vulkan-runtime/src/texture.rs (texel_texture)`