diff --git a/crates/metal2vulkan-conformance/src/cases/astc_textures.rs b/crates/metal2vulkan-conformance/src/cases/astc_textures.rs index 95f32c982..962e71cc6 100644 --- a/crates/metal2vulkan-conformance/src/cases/astc_textures.rs +++ b/crates/metal2vulkan-conformance/src/cases/astc_textures.rs @@ -497,10 +497,15 @@ impl Case for AstcTextures { // 14 HDR rows, which that card makes through the same carrier and twin since the HDR // decode, have not run there since: their declaration counts as unchecked until a run on // a device without unified memory announces it. + // Where the device holds the format's block itself, `metal2vulkan-rt` keeps the blocks in + // an image of it and reads the device's decode of them, the static note it announces as + // `compressed-texel-decode` for every block-compressed texture it makes. A declaration + // and not a tolerance: no ASTC bound is stated, so every texel still compares exactly. let mut all = vec![ crate::replay::shared_memory_notice(), crate::replay::notice_allowance(Degradation::CarriedDecodedTwin.code()), crate::replay::notice_allowance(Degradation::CpuBlockDecode.code()), + crate::replay::notice_allowance(Degradation::CompressedTexelDecode.code()), ]; // An sRGB form's twin holds Metal's own 8-bit codes, which its slots decode through Metal's // table, so its texels compare exactly and it names nothing further. A linear format's diff --git a/crates/metal2vulkan-conformance/src/cases/compressed_decode.rs b/crates/metal2vulkan-conformance/src/cases/compressed_decode.rs index 80b82db66..962f1fbd6 100644 --- a/crates/metal2vulkan-conformance/src/cases/compressed_decode.rs +++ b/crates/metal2vulkan-conformance/src/cases/compressed_decode.rs @@ -25,17 +25,18 @@ //! lane uses, kept. //! //! **The device's decode is the answer.** A BC texture keeps no decoded twin: every device samples -//! its own BC image through its own decode, and one whose driver is not measured to decode a -//! format as Metal does announces `compressed-texel-decode`, one of the device's native answers the -//! suite declares for every case ([`crate::replay::NATIVE_NOTES`]). Like every native note it -//! loosens no value, so where such a device's texels differ from Metal's the site is a -//! `known-gaps.tsv` row of that venue naming the note and whether its stated bound covers the -//! difference. On MoltenVK, whose driver has both facts, every texel compares exactly. +//! its own BC image through its own decode, announced `compressed-texel-decode` where the runtime +//! makes it (the old runtime on a driver not measured to decode the format as Metal does; +//! `metal2vulkan-rt` for every block-compressed texture, its static note). Each round's texels are +//! loosened by the largest difference that notice's catalogue entry (docs/API.md) states for the +//! format's family on any driver, justified by the notice alone ([`CompressedDecode::decode_bound`]): +//! a texel past it is the notice's claim failing, a divergence. On MoltenVK, whose driver has both +//! facts, the old runtime announces nothing and every texel compares exactly. //! //! Nothing here can fault a GPU: one compute pass a round, one read-only texture, one buffer, one //! thread a texel inside the texture, no loop and no sampling. -use crate::allowance::Allowance; +use crate::allowance::{Allowance, Justification, Loosening}; use crate::case::{call, made, Abort, Bindings, Case, Failure, Input, MetalSource, Side}; use crate::fixture::{Fixture, METAL_TEXT, RUNTIME_TEXT}; use crate::recording::ShaderRef; @@ -44,6 +45,7 @@ use crate::transcript::{ Aspect, ByteLayout, Digest, Element, Gaps, Node, Observed, Region, Sites, Value, }; use metal2vulkan::metal::PixelFormat; +use metal2vulkan_runtime::Degradation; /// The fixture whose kernel reads a texture's texels as floats. const FIXTURE: &str = "format_scout"; @@ -230,6 +232,26 @@ impl CompressedDecode { TextureRequest::read_2d(self.format().format, SIDE, SIDE).loaded(uploads) } + /// The largest difference from Metal's texel that `compressed-texel-decode`'s catalogue entry + /// (docs/API.md) states for the format's family, the largest of the drivers it names: a BC1 + /// or BC2 channel 4/255 and BC3's 6/255 (its alpha), a BC4 or BC5 channel 7.4/255 and a signed + /// one 0.065, all on NVIDIA. An sRGB form's colour is the device's sRGB decode of a code within + /// 4/255 of Metal's, so its bound is that decode's largest step over 4/255, at the top of the + /// curve, which also covers its alpha. + fn decode_bound(&self) -> f64 { + let format = self.format(); + if model::srgb(format.format) { + let decode = |value: f64| ((value + 0.055) / 1.055).powf(2.4); + return decode(1.0) - decode(1.0 - 4.0 / 255.0); + } + match format.kind { + Kind::Bc1 | Kind::Bc2 => 4.0 / 255.0, + Kind::Bc3 => 6.0 / 255.0, + Kind::Channels { signed: false, .. } => 7.4 / 255.0, + Kind::Channels { signed: true, .. } => 0.065, + } + } + /// The bytes a row of blocks takes: four blocks of a 16-texel row. fn row_pitch(&self) -> u32 { 4 * self.format().kind.block_bytes() as u32 @@ -270,13 +292,14 @@ impl Case for CompressedDecode { } fn allowances(&self) -> Vec { - // A driver not measured to decode this format as Metal does reads the device's decode of - // the texture's own BC image, announced `compressed-texel-decode`, and a texel's `float` - // value is the device's conversion of its decoded codes, announced - // `device-texel-conversion`: both native notes the suite declares for every case. They - // loosen no texel, and a texel they move is a `known-gaps.tsv` row of the venue. On a - // device whose sampler is Metal's neither fires, and every texel compares exactly there - // too. + // The device's decode of the texture's own blocks, announced `compressed-texel-decode` + // where the runtime makes it, declared at the notices site, moves a texel by up to the + // largest difference its catalogue entry states for the format's family: each round's + // texels are loosened by that number and no further, justified by the notice, so a run + // past it is the notice's claim failing. A texel's `float` value is + // also the device's conversion of its decoded codes (`device-texel-conversion`), which + // loosens nothing. Where neither runtime announces the decode, every texel compares + // exactly. // Every row reads its answer back through a `Shared` buffer, so on a device without // unified memory the runtime announces `shared-in-system-memory` // (`crate::replay::shared_memory_notice` holds the whole reason). It declares the @@ -288,7 +311,18 @@ impl Case for CompressedDecode { // nothing else (replay-nvidia.log). On MoltenVK, where // the chip's GPU shares the CPU's memory, it cannot fire at all, which is why no // recording of this suite declares it. - vec![crate::replay::shared_memory_notice()] + let mut all = vec![ + crate::replay::shared_memory_notice(), + crate::replay::notice_allowance(Degradation::CompressedTexelDecode.code()), + ]; + for round in 0..ROUNDS { + all.push(Allowance::new( + format!("case/round/{round}/texels"), + Loosening::Absolute(self.decode_bound()), + Justification::notice(Degradation::CompressedTexelDecode), + )); + } + all } fn shaders(&self) -> Result, String> { diff --git a/crates/metal2vulkan-conformance/src/cases/compressed_moves.rs b/crates/metal2vulkan-conformance/src/cases/compressed_moves.rs index f6203bc55..5b3c95704 100644 --- a/crates/metal2vulkan-conformance/src/cases/compressed_moves.rs +++ b/crates/metal2vulkan-conformance/src/cases/compressed_moves.rs @@ -842,12 +842,13 @@ pub fn out_tight( } /// The notices a BC case may name as justifying its notices site: the `Shared` buffer each row -/// reads its answer back through, which a device without unified memory announces. +/// reads its answer back through, which a device without unified memory announces, and the +/// device's decode of the texture's blocks. /// /// A BC texture keeps no decoded twin on any venue: the device holds every BC format in its own -/// compressed form and decodes it itself, and where its driver is not measured to decode a format -/// as Metal does the runtime announces `compressed-texel-decode`, one of the device's native -/// answers the suite declares for every case ([`crate::replay::NATIVE_NOTES`]). Every block still +/// compressed form and decodes it itself, which the runtime announces as +/// `compressed-texel-decode` where it makes it (the old runtime where the driver is not measured +/// to decode a format as Metal does, `metal2vulkan-rt` for every such texture). Every block still /// compares exactly: the only site these loosen is the set of notices, which Metal holds empty. /// /// What is **not** here: `staged-texture-copy`. Our `replaceRegion:` into a compressed texture does @@ -867,9 +868,10 @@ pub fn block_allowances() -> Vec { // field and nothing else (replay-nvidia.log). On MoltenVK, where // the chip's GPU shares the CPU's memory, it cannot fire at all, which is why no // recording of this suite declares it. - vec![crate::replay::notice_allowance( - Degradation::SharedInSystemMemory.code(), - )] + vec![ + crate::replay::notice_allowance(Degradation::SharedInSystemMemory.code()), + crate::replay::notice_allowance(Degradation::CompressedTexelDecode.code()), + ] } /// The case for one format. diff --git a/crates/metal2vulkan-conformance/src/cases/compressed_views.rs b/crates/metal2vulkan-conformance/src/cases/compressed_views.rs index 2263ddaf7..e455b5f97 100644 --- a/crates/metal2vulkan-conformance/src/cases/compressed_views.rs +++ b/crates/metal2vulkan-conformance/src/cases/compressed_views.rs @@ -410,9 +410,8 @@ impl Case for CompressedViews { fn allowances(&self) -> Vec { // The same notices the first lane's cases name, for the same reason and from the same // measurement: one mechanism, not two. A view of a BC texture reads the device's decode - // of its blocks, which the runtime announces as `compressed-texel-decode` where the - // driver is not measured to make Metal's: one of the suite's native notes - // ([`crate::replay::NATIVE_NOTES`]), declared for every case. + // of its blocks, which the runtime announces as `compressed-texel-decode` where it makes + // it. crate::cases::compressed_moves::block_allowances() } diff --git a/crates/metal2vulkan-conformance/src/cases/etc_textures.rs b/crates/metal2vulkan-conformance/src/cases/etc_textures.rs index abe3edcfc..3ff1cf193 100644 --- a/crates/metal2vulkan-conformance/src/cases/etc_textures.rs +++ b/crates/metal2vulkan-conformance/src/cases/etc_textures.rs @@ -325,10 +325,15 @@ impl Case for EtcTextures { // nothing else (replay-nvidia.log). On MoltenVK, where // the chip's GPU shares the CPU's memory, it cannot fire at all, which is why no // recording of this suite declares it. + // Where the device holds the format's block itself, `metal2vulkan-rt` keeps the blocks in + // an image of it and reads the device's decode of them, the static note it announces as + // `compressed-texel-decode` for every block-compressed texture it makes. A declaration + // and not a tolerance: no ETC2 or EAC bound is stated, so every texel still compares exactly. let mut all = vec![ crate::replay::shared_memory_notice(), crate::replay::notice_allowance(Degradation::CarriedDecodedTwin.code()), crate::replay::notice_allowance(Degradation::CpuBlockDecode.code()), + crate::replay::notice_allowance(Degradation::CompressedTexelDecode.code()), ]; // An 8-bit format's twin holds Metal's own codes, and the `float` the function answers is // the **device's** conversion of a code (`device-texel-conversion`; lavapipe multiplies by diff --git a/crates/metal2vulkan-conformance/src/cases/read_write_tiers.rs b/crates/metal2vulkan-conformance/src/cases/read_write_tiers.rs index 96edfff0c..985522c4e 100644 --- a/crates/metal2vulkan-conformance/src/cases/read_write_tiers.rs +++ b/crates/metal2vulkan-conformance/src/cases/read_write_tiers.rs @@ -447,10 +447,17 @@ impl Case for ReadWriteDescriptors { // The tables name block-compressed formats, which a device with no Vulkan format for one // makes through a decoded twin carried beside the blocks, and the runtime says so: a // performance notice at the notices site alone, every answer of the tables still - // compared. Measured firing on llvmpipe (LLVM 21.1.8). - vec![crate::replay::notice_allowance( - metal2vulkan_runtime::Degradation::CarriedDecodedTwin.code(), - )] + // compared. Measured firing on llvmpipe (LLVM 21.1.8). A texture of such a format the + // device holds itself announces the device's decode of its blocks + // (`compressed-texel-decode`), at the notices site alone too: the tables read no texel. + vec![ + crate::replay::notice_allowance( + metal2vulkan_runtime::Degradation::CarriedDecodedTwin.code(), + ), + crate::replay::notice_allowance( + metal2vulkan_runtime::Degradation::CompressedTexelDecode.code(), + ), + ] } fn inputs(&self) -> Result, String> { diff --git a/crates/metal2vulkan-conformance/src/cases/texture_descriptor_pairs.rs b/crates/metal2vulkan-conformance/src/cases/texture_descriptor_pairs.rs index 2a70c2db7..4f6e902aa 100644 --- a/crates/metal2vulkan-conformance/src/cases/texture_descriptor_pairs.rs +++ b/crates/metal2vulkan-conformance/src/cases/texture_descriptor_pairs.rs @@ -593,6 +593,11 @@ impl Case for DescriptorPairs { named.push(crate::replay::notice_allowance( metal2vulkan_runtime::Degradation::CarriedDecodedTwin.code(), )); + // A compressed texture the device holds itself announces the device's decode of its + // blocks (`compressed-texel-decode`), which the row never reads either. + named.push(crate::replay::notice_allowance( + metal2vulkan_runtime::Degradation::CompressedTexelDecode.code(), + )); } if self.name == STORAGE { // The storage table names `Shared` among the modes it crosses, so this row alone diff --git a/crates/metal2vulkan-conformance/src/replay.rs b/crates/metal2vulkan-conformance/src/replay.rs index da3eaa80e..c9d066d82 100644 --- a/crates/metal2vulkan-conformance/src/replay.rs +++ b/crates/metal2vulkan-conformance/src/replay.rs @@ -509,8 +509,7 @@ pub fn set_past_layout_notice() -> crate::allowance::Allowance { /// the device's own depth conversion and depth test (`unorm-depth-rounding`, `depth-denormals`, /// `signed-depth-test`); /// - **texel, vertex and colour conversions**: `device-texel-conversion`, -/// `half-texel-conversion`, `srgb-texel-decode`, the device's decode of a BC texture's blocks -/// (`compressed-texel-decode`), the device's fixed-function conversion of a +/// `half-texel-conversion`, `srgb-texel-decode`, the device's fixed-function conversion of a /// normalized vertex attribute (`device-vertex-conversion`), `device-color-conversion`; /// - **sampling and filtering**: `device-sampling`, `device-sample-level`, the device's filter of a /// generated mipmap chain (`device-filtered-mipmaps`), and Metal's own sampler filtering a @@ -537,7 +536,10 @@ pub fn set_past_layout_notice() -> crate::allowance::Allowance { /// `restricted-depth-range`), of an emulation's own precision (`decoded-texel-precision`, /// `grad-from-bias`, `pixel-sampler-scaling`, `bicubic-filter-arithmetic`), of a Metal form not /// measured or not built (`blended-write-rounding`, `unmeasured-resolve`, `device-interpolation`, -/// `reduction-order`), and every performance or validity notice. +/// `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 block-compressed texture's blocks, +/// `compressed-texel-decode`, which only a case that makes such a texture can announce), and every +/// performance or validity notice. /// /// **It declares the notice, and nothing about a value.** Each entry loosens the notices site /// alone, exactly as a case's own [`notice_allowance`] does, so every value of every case still @@ -570,7 +572,6 @@ pub const NATIVE_NOTES: &[metal2vulkan_runtime::Degradation] = { D::DeviceTexelConversion, D::HalfTexelConversion, D::SrgbTexelDecode, - D::CompressedTexelDecode, D::DeviceVertexConversion, D::DeviceColorConversion, D::DeviceSampling, diff --git a/crates/metal2vulkan-conformance/src/rt_side.rs b/crates/metal2vulkan-conformance/src/rt_side.rs index 9a76290e3..285ae2b55 100644 --- a/crates/metal2vulkan-conformance/src/rt_side.rs +++ b/crates/metal2vulkan-conformance/src/rt_side.rs @@ -18,9 +18,10 @@ //! //! The runtime announces no degrade notice: where a kernel's answers may differ from Metal's, its //! state carries static precision notes ([`metal2vulkan_rt::ComputePipelineState::precision_notes`], -//! [`metal2vulkan_rt::RenderPipelineState::precision_notes`]). This side announces the notes of -//! each state its case dispatched or drew with, by the codes the suite's allowances name -//! (`metal2vulkan-degrade-`). +//! [`metal2vulkan_rt::RenderPipelineState::precision_notes`]), and so does a texture of a +//! block-compressed format ([`metal2vulkan_rt::Texture::precision_note`]). This side announces the +//! notes of each state its case dispatched or drew with, and of each texture it made, by the codes +//! the suite's allowances name (`metal2vulkan-degrade-`). use crate::case::{ Answer, Bindings, Failure, Handle, SamplerSpec, ShaderSource, Side, StageInRegion, StageInput, @@ -363,7 +364,8 @@ pub struct RtSide<'a> { drawn: BTreeSet, /// The static notes of what a pass the case encoded set beside its pipeline states: a depth /// bias other than 0 (`RenderCommandEncoder::DEPTH_BIAS_NOTE`) and each depth-stencil state's - /// (`DepthStencilState::precision_note`), which [`Side::announced`] answers too. + /// (`DepthStencilState::precision_note`); and of each texture the case made + /// (`Texture::precision_note`), which [`Side::announced`] answers too. encoder_notes: BTreeSet, } @@ -398,6 +400,13 @@ impl<'a> RtSide<'a> { Ok(self.queue.as_ref().expect("made above")) } + /// Keep `texture` as the case's, with the static note it carries (`Texture::precision_note`: + /// the device's decode of a block-compressed format), which [`Side::announced`] answers. + fn keep_texture(&mut self, texture: rt::Texture) -> Handle { + self.encoder_notes.extend(texture.precision_note()); + keep(&mut self.textures, texture) + } + fn held(&self, handle: Handle) -> Answer<&rt::Buffer> { (self.buffers.get(handle.0 as usize)) .map(|(buffer, _)| buffer) @@ -624,7 +633,7 @@ impl Side for RtSide<'_> { size: [size[0], size[1], 1], }; (texture.replace_region(region, 0, 0, bytes, row_pitch.into(), 0)).map_err(of_rt)?; - Ok(keep(&mut self.textures, texture)) + Ok(self.keep_texture(texture)) } fn read_texture(&mut self, texture: Handle, size: [u32; 2], row_pitch: u32) -> Answer> { @@ -678,7 +687,7 @@ impl Side for RtSide<'_> { let texture = (self.on.device.new_texture(&descriptor, index)) .map_err(|error| Failure::of_rt(&error))?; let facts = texture_facts(&texture); - keep(&mut self.textures, texture); + self.keep_texture(texture); Ok(Some(facts)) } @@ -697,7 +706,7 @@ impl Side for RtSide<'_> { let made = buffer.new_texture(&descriptor, index, request.offset, request.bytes_per_row); let texture = made.map_err(|error| Failure::of_rt(&error))?; let facts = texture_facts(&texture); - keep(&mut self.textures, texture); + self.keep_texture(texture); Ok(facts) } @@ -731,9 +740,10 @@ impl Side for RtSide<'_> { fn makes_texture(&mut self, query: &crate::texture_query::HeapTextureQuery) -> Answer { let descriptor = queried(query); let index = self.on.texture_index(descriptor.usage); - (self.on.device.new_texture(&descriptor, index)) - .map(|_| true) - .map_err(|error| Failure::of_rt(&error)) + let texture = (self.on.device.new_texture(&descriptor, index)) + .map_err(|error| Failure::of_rt(&error))?; + self.encoder_notes.extend(texture.precision_note()); + Ok(true) } /// `newHeapWithDescriptor:` as the runtime's consumer makes a heap: a block of the heap's size @@ -921,7 +931,7 @@ impl Side for RtSide<'_> { ), } .map_err(|error| Failure::of_rt(&error))?; - Ok(keep(&mut self.textures, view)) + Ok(self.keep_texture(view)) } /// The view's shape and swizzle, read of its descriptor; its parent's facts are the @@ -1060,7 +1070,7 @@ impl Side for RtSide<'_> { (texture.replace_region(region, 0, 0, bytes, spec.row_pitch.into(), 0)) .map_err(of_rt)?; } - Ok(keep(&mut self.textures, texture)) + Ok(self.keep_texture(texture)) } /// The call the request names: the device's `newTextureWithDescriptor:`, the buffer's @@ -1139,14 +1149,17 @@ impl Side for RtSide<'_> { )) .map_err(of_rt)?; } - Ok(keep(&mut self.textures, texture)) + Ok(self.keep_texture(texture)) } /// The program on the runtime, as the old runtime's side runs it (`rt_side::work`); a - /// program that generates mipmaps announces the blit encoder's static note of them. + /// program that generates mipmaps announces the blit encoder's static note of them, and one + /// that makes a texture its static note. fn work(&mut self, work: &crate::work::Work) -> Answer { let on = self.on; - let done = work::run(on, self.queue()?, work)?; + self.queue()?; + let queue = self.queue.as_ref().expect("made above"); + let done = work::run(on, queue, work, &mut self.encoder_notes)?; let mipmaps = |step: &crate::work::Step| matches!(step, crate::work::Step::GenerateMipmaps { .. }); if work.steps.iter().any(mipmaps) { diff --git a/crates/metal2vulkan-conformance/src/rt_side/render.rs b/crates/metal2vulkan-conformance/src/rt_side/render.rs index 3222cab2a..8724f0a56 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/render.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/render.rs @@ -140,7 +140,7 @@ impl RtSide<'_> { let buffer = self.held(over.buffer)?; let texture = (buffer.new_texture(&descriptor, index, over.offset, over.bytes_per_row)) .map_err(of_rt)?; - return Ok(keep(&mut self.textures, texture)); + return Ok(self.keep_texture(texture)); } descriptor.storage_mode = match spec.shared { true => rt::StorageMode::Shared, @@ -163,7 +163,7 @@ impl RtSide<'_> { let index = (spec.shader_read || spec.shader_write) .then(|| self.on.next_index(rt::IndexClass::Texture)); let texture = (self.on.device.new_texture(&descriptor, index)).map_err(of_rt)?; - Ok(keep(&mut self.textures, texture)) + Ok(self.keep_texture(texture)) } /// `newRenderPipelineStateWithDescriptor:error:` of the descriptor the old runtime's side diff --git a/crates/metal2vulkan-conformance/src/rt_side/work.rs b/crates/metal2vulkan-conformance/src/rt_side/work.rs index 1c3a82335..f43ca42d5 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/work.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/work.rs @@ -21,6 +21,7 @@ use crate::work::{Clear, Done, Plane, Rect, Resource, Step, TextureKind, Texture use metal2vulkan::metal::PixelFormat; use metal2vulkan_devtools::{engine_dir, llvm_assemble}; use metal2vulkan_rt as rt; +use std::collections::BTreeSet; /// A typed error of the runtime as the failure it records. fn of_rt(error: rt::Error) -> Failure { @@ -122,6 +123,16 @@ enum Made { Released, } +impl Made { + /// A texture's static note (`Texture::precision_note`); no other resource carries one. + fn precision_note(&self) -> Option { + match self { + Made::Texture(texture) => texture.precision_note(), + _ => None, + } + } +} + /// A read-back the device runs before its bytes are answered. struct Pending { /// The read's place among the program's reads. @@ -354,6 +365,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. + notes: &'a mut BTreeSet, made: Vec, /// The program's declarations, which a [`Step::Make`] reads to make a released resource again. resources: &'a [Resource], @@ -366,15 +379,24 @@ struct Run<'a> { statuses: Vec, } -/// Run `work` on `on`'s device through `queue`, answering what it read. -pub(super) fn run(on: &RtDevice, queue: &rt::CommandQueue, work: &Work) -> Answer { +/// 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`. +pub(super) fn run( + on: &RtDevice, + queue: &rt::CommandQueue, + work: &Work, + notes: &mut BTreeSet, +) -> Answer { let mut made: Vec = Vec::with_capacity(work.resources.len()); for (at, resource) in work.resources.iter().enumerate() { - made.push(make(on, &made, resource).map_err(|failure| failure.at_resource(at))?); + let one = make(on, &made, resource).map_err(|failure| failure.at_resource(at))?; + notes.extend(one.precision_note()); + made.push(one); } let mut state = Run { on, queue, + notes, made, resources: &work.resources, kernels: work.kernels, @@ -787,6 +809,7 @@ impl Run<'_> { let declared = (self.resources.get(at)) .ok_or_else(|| Failure::named("NoSuchResource", format!("resource {at}")))?; let one = make(self.on, &self.made, declared)?; + self.notes.extend(one.precision_note()); self.made[at] = one; Ok(()) } diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index afdebc97d..a869c47db 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -687,6 +687,14 @@ made, with no lock, and never rewritten for layouts. every texture an index, and this one has none, so its `gpu_resource_id` answers index 0 and a slot that binds it reads Metal's nil texture. `new_texture` still refuses a texture shaders reach made without an index (`Refusal::TextureIndex`). +- A texture or view whose own pixel format is block-compressed (BC1 to BC7, and the ASTC, ETC2 + and EAC formats where the device makes them) holds its blocks in an image of that format, and a + read, sample or gather of its texels is the device's decode of them (an sRGB form's code through + the device's sRGB decode), where Metal interpolates a block's endpoints with 6-bit weights: the + static note `PrecisionNote::CompressedTexelDecode` (`Texture::precision_note`), decided by the + pixel format alone on every device. Its blocks' bytes, copies and sizes are Metal's. The + largest differences measured are in docs/API.md's catalogue + (`metal2vulkan-degrade-compressed-texel-decode`). - `Device::pixel_format_info(raw)` is `MTLPixelFormatGetInfoForDevice` (Apple SPI): Metal's description of a raw pixel format value, its name, Apple's flags word, cast class and four words (a block's bytes and extent for a format of blocks), as an Apple M3 Max answers it under diff --git a/crates/metal2vulkan-rt/src/tests/view.rs b/crates/metal2vulkan-rt/src/tests/view.rs index c8b626995..a71f6b87d 100644 --- a/crates/metal2vulkan-rt/src/tests/view.rs +++ b/crates/metal2vulkan-rt/src/tests/view.rs @@ -13,7 +13,9 @@ //! comes back to zero with the device, the views' image views among them. A view of a Managed //! texture writes the texture's own named bytes. A command buffer keeps a view it uses after its //! parent, as Metal's retains every object its encoders use: released while the command buffer -//! is pending, the view keeps its image views and its element of set 1 until it retires. +//! is pending, the view keeps its image views and its element of set 1 until it retires. A texture +//! or view of a block-compressed pixel format carries the static note of its decode +//! (`PrecisionNote::CompressedTexelDecode`), one of another format none. #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod on_device { @@ -24,9 +26,9 @@ mod on_device { use crate::tests::command::on_device::{each_device, finished, shared_event, within}; use crate::{ Buffer, BufferLayout, BytesPlace, CommandQueue, Device, Error, Gap, IndexClass, - MemoryClass, PixelFormat, Refusal, Region, StorageMode, Texture, TextureDescriptor, - TexturePlace, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, - TextureViewKind, + MemoryClass, PixelFormat, PrecisionNote, Refusal, Region, StorageMode, Texture, + TextureDescriptor, TexturePlace, TextureSwizzle, TextureSwizzleChannels, TextureType, + TextureUsage, TextureViewKind, }; use metal2vulkan::metal::resource_word::TextureWord; @@ -366,6 +368,57 @@ mod on_device { }); } + /// A texture of a block-compressed pixel format answers the static note of its decode, and so + /// does its view in its sRGB sibling, decided by the format alone; an uncompressed texture and + /// its view answer none. Each compressed format counts where the device makes it, and each + /// device makes at least one. + #[test] + fn every_device_notes_the_decode_of_a_block_compressed_texture_and_its_views() { + each_device("compressed_decode_note", |name, _, device| { + let note = Some(PrecisionNote::CompressedTexelDecode); + let made = |pixel_format| { + let mut d = TextureDescriptor::new(TextureType::Type2D, pixel_format, 8, 8); + d.usage = TextureUsage::SHADER_READ; + device.new_texture(&d, None) + }; + let view = |texture: &Texture, pixel_format| { + (texture.new_texture_view(pixel_format, TextureType::Type2D, 0..1, 0..1, None)) + .unwrap_or_else(|error| panic!("{name}: a {pixel_format:?} view: {error}")) + }; + let compressed = [ + (PixelFormat::BC1RGBA, PixelFormat::BC1RGBASRGB), + (PixelFormat::BC7RGBAUnorm, PixelFormat::BC7RGBAUnormSRGB), + (PixelFormat::ETC2RGB8, PixelFormat::ETC2RGB8SRGB), + (PixelFormat::ASTC4x4LDR, PixelFormat::ASTC4x4SRGB), + ]; + let mut noted = Vec::new(); + for (pixel_format, srgb) in compressed { + let texture = match made(pixel_format) { + Ok(texture) => texture, + Err(Error::Unsupported(Gap::TextureFormat { .. })) => continue, + Err(error) => panic!("{name}: a {pixel_format:?} texture: {error}"), + }; + assert_eq!(texture.precision_note(), note, "{name}: {pixel_format:?}"); + assert_eq!( + view(&texture, srgb).precision_note(), + note, + "{name}: {srgb:?}" + ); + noted.push(pixel_format); + } + assert!( + !noted.is_empty(), + "{name}: no block-compressed texture made" + ); + eprintln!("{name}: the decode note on {noted:?} and their sRGB views"); + let plain = (made(PixelFormat::RGBA8Unorm)) + .unwrap_or_else(|error| panic!("{name}: an RGBA8Unorm texture: {error}")); + assert_eq!(plain.precision_note(), None, "{name}: RGBA8Unorm"); + let plain_view = view(&plain, PixelFormat::RGBA8UnormSRGB); + assert_eq!(plain_view.precision_note(), None, "{name}: RGBA8UnormSRGB"); + }); + } + #[test] fn every_device_views_a_managed_texture_s_named_bytes() { each_device("managed texture views", |name, _, device| { diff --git a/crates/metal2vulkan-rt/src/texture.rs b/crates/metal2vulkan-rt/src/texture.rs index 63acc196a..0a7c78a9d 100644 --- a/crates/metal2vulkan-rt/src/texture.rs +++ b/crates/metal2vulkan-rt/src/texture.rs @@ -47,6 +47,7 @@ use metal2vulkan::metal::resource_word::TextureWord; use metal2vulkan::metal::{ PixelFormat, TextureSwizzle, TextureSwizzleChannels, TextureType, TextureUsage, }; +use metal2vulkan::pipeline::PrecisionNote; use std::ops::Range; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; @@ -3569,6 +3570,16 @@ impl Texture { &self.inner.descriptor } + /// No Metal counterpart: the static note of a read, sample or gather of its texels, where its + /// own pixel format is block-compressed ([`PrecisionNote::CompressedTexelDecode`]: a texel is + /// the device's decode of its blocks, where Metal interpolates with 6-bit weights); `None` for + /// any other format. Decided by the pixel format alone, on every device: a view answers by + /// its own format, and its blocks' bytes, copies and sizes are Metal's either way. + pub fn precision_note(&self) -> Option { + let compressed = formats::block_extent(self.inner.descriptor.pixel_format).is_some(); + compressed.then_some(PrecisionNote::CompressedTexelDecode) + } + /// `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 diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 6787bbc5a..63e7a4ff8 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -245,8 +245,10 @@ macro_rules! degradations { /// profile of `Device::from_queries` records, announces this runtime's kind for the /// same codes, [`Degradation::SnormMinimumKept`]; [`PrecisionNote::DepthDenormals`], /// which `metal2vulkan-rt`'s depth-stencil state carries, announces - /// [`Degradation::DepthDenormals`]; and [`PrecisionNote::DeviceFilteredMipmaps`], which - /// its blit encoder carries, [`Degradation::DeviceFilteredMipmaps`]. + /// [`Degradation::DepthDenormals`]; [`PrecisionNote::DeviceFilteredMipmaps`], which its + /// blit encoder carries, [`Degradation::DeviceFilteredMipmaps`]; and + /// [`PrecisionNote::CompressedTexelDecode`], which its block-compressed textures carry, + /// [`Degradation::CompressedTexelDecode`]. pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* @@ -254,6 +256,7 @@ macro_rules! degradations { PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, PrecisionNote::DeviceFilteredMipmaps => Degradation::DeviceFilteredMipmaps, + PrecisionNote::CompressedTexelDecode => Degradation::CompressedTexelDecode, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index 0747308f5..b5a4e483b 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -347,7 +347,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::SnormMinimumKept | N::DeviceDepthBias | N::DepthDenormals - | N::DeviceFilteredMipmaps => Allowance::Unbounded, + | N::DeviceFilteredMipmaps + | N::CompressedTexelDecode => 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 8735944ee..65c6cf833 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -86,6 +86,7 @@ fn every_precision_note_has_its_table_row() { (N::DeviceDepthBias, Allowance::Unbounded), (N::DepthDenormals, Allowance::Unbounded), (N::DeviceFilteredMipmaps, Allowance::Unbounded), + (N::CompressedTexelDecode, Allowance::Unbounded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index cb1842c2d..60a3265a3 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1539,6 +1539,7 @@ codec_enum! { DepthDenormals, DeviceFilteredMipmaps, TessellationFractionalSpacing, + CompressedTexelDecode, } 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 a84e3d844..1bd00ccfe 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -72,7 +72,7 @@ pub const SEMANTICS_VERSION: u32 = 2186; /// 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 = 543; +pub const ARTIFACT_FORMAT_VERSION: u32 = 544; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 97803d139..4f61a71cb 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2488,6 +2488,19 @@ pub enum PrecisionNote { /// Validation derives no tolerance from it: a difference stays a mismatch, which the note /// explains. DeviceFilteredMipmaps, + /// A texture, or a view, whose own pixel format is block-compressed (BC1 to BC7, and the ASTC, + /// ETC2 and EAC formats where the device makes them): a read, sample or gather of its texels + /// answers the device's decode of its blocks (an sRGB form's code through the device's sRGB + /// decode), where Metal interpolates a block's endpoints with 6-bit weights. Its blocks' + /// bytes, copies and sizes are Metal's. Static per texture, decided by its pixel format alone + /// on every device: no pipeline stage records it; `metal2vulkan-rt`'s texture carries it + /// (`Texture::precision_note`). `metal2vulkan-runtime` announces the same difference as its + /// `compressed-texel-decode` kind, for a BC texture on a driver not measured to decode its + /// format as Metal does, which this note announces too. + /// + /// Validation derives no tolerance from it: a difference stays a mismatch, which the note + /// explains. + CompressedTexelDecode, } /// The math mode of an entry's module, which decides, on a device whose `float` functions are diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index a70b41843..aa7484972 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -235,6 +235,7 @@ fn notes() -> Vec<(&'static str, Ledger)> { DeviceDepthBias, DepthDenormals, DeviceFilteredMipmaps, + CompressedTexelDecode, ], } } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index af0fd878a..807e8bdfe 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -9132,7 +9132,7 @@ macro-template metal2vulkan-rt::vk_bit! ( $(#[$meta:meta])* $name:ident($raw:ty) 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), } } } }; macro-template metal2vulkan-rt::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-runtime::commands! ( v1_0 { $($v0:ident $f0:ident $n0:literal ($($a0:ident: $t0:ty),*) $(-> $r0:ty)?;)* } v1_3 { $($v3:ident $f3:ident $n3:literal ($($a3:ident: $t3:ty),*) $(-> $r3:ty)?;)* } extension { $($ve:ident $fe:ident $ne:literal ($($ae:ident: $te:ty),*) $(-> $re:ty)?;)* } ) => { #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub(crate) enum Command { $($v0,)* $($v3,)* $($ve,)* } impl Command { pub(crate) const ALL: &'static [Command] = &[ $(Command::$v0,)* $(Command::$v3,)* $(Command::$ve,)* ]; pub(crate) const COUNT: usize = Command::ALL.len(); pub(crate) fn name(self) -> &'static CStr { match self { $(Command::$v0 => $n0,)* $(Command::$v3 => $n3,)* $(Command::$ve => $ne,)* } } } #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct CommandsRecorded { $( #[doc = concat!("The calls of `", stringify!($v0), "`.")] pub $f0: u64, )* $( #[doc = concat!("The calls of `", stringify!($v3), "`.")] pub $f3: u64, )* $( #[doc = concat!("The calls of `", stringify!($ve), "`.")] pub $fe: u64, )* } impl CommandsRecorded { fn read(shards: &[Shard; SHARDS + 1]) -> CommandsRecorded { let sum = |command: Command| { let counts = shards.iter().map(|shard| &shard.0[command as usize]); counts.map(|count| count.load(Ordering::Relaxed)).sum() }; CommandsRecorded { $($f0: sum(Command::$v0),)* $($f3: sum(Command::$v3),)* $($fe: sum(Command::$ve),)* } } } struct Real { $($f0: [AtomicPtr; SLOTS],)* $($f3: [AtomicPtr; SLOTS],)* $($fe: [AtomicPtr; SLOTS],)* } static REAL: Real = Real { $($f0: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* $($f3: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* $($fe: [const { AtomicPtr::new(std::ptr::null_mut()) }; SLOTS],)* }; commands!(@thunks $($v0 $f0 $n0 ($($a0: $t0),*) $(-> $r0)?;)*); commands!(@thunks $($v3 $f3 $n3 ($($a3: $t3),*) $(-> $r3)?;)*); commands!(@thunks $($ve $fe $ne ($($ae: $te),*) $(-> $re)?;)*); pub(super) fn thunk(command: Command) -> *const c_void { match command { $(Command::$v0 => $f0:: as *const c_void,)* $(Command::$v3 => $f3:: as *const c_void,)* $(Command::$ve => $fe:: as *const c_void,)* } } pub(super) fn store(index: usize, command: Command, real: *const c_void) { let real = real.cast_mut(); match command { $(Command::$v0 => REAL.$f0[index].store(real, Ordering::Release),)* $(Command::$v3 => REAL.$f3[index].store(real, Ordering::Release),)* $(Command::$ve => REAL.$fe[index].store(real, Ordering::Release),)* } } pub(super) fn real(index: usize, command: Command) -> *const c_void { let real = match command { $(Command::$v0 => REAL.$f0[index].load(Ordering::Acquire),)* $(Command::$v3 => REAL.$f3[index].load(Ordering::Acquire),)* $(Command::$ve => REAL.$fe[index].load(Ordering::Acquire),)* }; real.cast_const() } pub(super) fn clear(index: usize) { $(REAL.$f0[index].store(std::ptr::null_mut(), Ordering::Release);)* $(REAL.$f3[index].store(std::ptr::null_mut(), Ordering::Release);)* $(REAL.$fe[index].store(std::ptr::null_mut(), Ordering::Release);)* } pub(super) fn route_tables( v1_0: &mut ash::DeviceFnV1_0, v1_3: &mut ash::DeviceFnV1_3, ) { $( store(S, Command::$v0, v1_0.$f0 as *const c_void); v1_0.$f0 = $f0::; )* $( store(S, Command::$v3, v1_3.$f3 as *const c_void); v1_3.$f3 = $f3::; )* } }; (@thunks $($v:ident $f:ident $n:literal ($($a:ident: $t:ty),*) $(-> $r:ty)?;)*) => { $( unsafe extern "system" fn $f( command_buffer: vk::CommandBuffer, $($a: $t,)* ) $(-> $r)? { let at = held(); crate::shards::add(at, &COUNTS[S][at].0[Command::$v as usize], 1); let real = REAL.$f[S].load(Ordering::Acquire); if real.is_null() { missing($n); } unsafe { let real = std::mem::transmute::< *mut c_void, unsafe extern "system" fn(vk::CommandBuffer, $($t,)*) $(-> $r)?, >(real); real(command_buffer, $($a,)*) } } )* }; -macro-template metal2vulkan-runtime::degradations! ( runtime { $( $(#[doc = $doc:literal])* $kind:ident = $code:literal, $category:ident, $cost:literal; )* } notes { $( $(#[doc = $note_doc:literal])* $note:ident = $note_code:literal; )* } ) => { #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Degradation { $($(#[doc = $doc])* $kind,)* $( #[doc = concat!( "A pipeline stage records [`PrecisionNote::", stringify!($note), "`]." )] $(#[doc = $note_doc])* $note, )* } impl Degradation { pub const ALL: &'static [Degradation] = &[$(Degradation::$kind,)* $(Degradation::$note,)*]; pub const fn code(self) -> &'static str { match self { $(Degradation::$kind => concat!("metal2vulkan-degrade-", $code),)* $(Degradation::$note => concat!("metal2vulkan-degrade-", $note_code),)* } } pub const fn category(self) -> DegradationCategory { match self { $(Degradation::$kind => DegradationCategory::$category,)* $(Degradation::$note => DegradationCategory::Precision,)* } } pub const fn cost(self) -> &'static str { match self { $(Degradation::$kind => $cost,)* $(Degradation::$note => NOTE_COST,)* } } pub const fn precision_note(self) -> Option { match self { $(Degradation::$kind => None,)* $(Degradation::$note => Some(PrecisionNote::$note),)* } } pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* PrecisionNote::CappedLodBias => Degradation::CappedLodBias, PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, PrecisionNote::DeviceFilteredMipmaps => Degradation::DeviceFilteredMipmaps, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } } } } }; +macro-template metal2vulkan-runtime::degradations! ( runtime { $( $(#[doc = $doc:literal])* $kind:ident = $code:literal, $category:ident, $cost:literal; )* } notes { $( $(#[doc = $note_doc:literal])* $note:ident = $note_code:literal; )* } ) => { #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Degradation { $($(#[doc = $doc])* $kind,)* $( #[doc = concat!( "A pipeline stage records [`PrecisionNote::", stringify!($note), "`]." )] $(#[doc = $note_doc])* $note, )* } impl Degradation { pub const ALL: &'static [Degradation] = &[$(Degradation::$kind,)* $(Degradation::$note,)*]; pub const fn code(self) -> &'static str { match self { $(Degradation::$kind => concat!("metal2vulkan-degrade-", $code),)* $(Degradation::$note => concat!("metal2vulkan-degrade-", $note_code),)* } } pub const fn category(self) -> DegradationCategory { match self { $(Degradation::$kind => DegradationCategory::$category,)* $(Degradation::$note => DegradationCategory::Precision,)* } } pub const fn cost(self) -> &'static str { match self { $(Degradation::$kind => $cost,)* $(Degradation::$note => NOTE_COST,)* } } pub const fn precision_note(self) -> Option { match self { $(Degradation::$kind => None,)* $(Degradation::$note => Some(PrecisionNote::$note),)* } } pub const fn from_precision_note(note: PrecisionNote) -> Degradation { match note { $(PrecisionNote::$note => Degradation::$note,)* PrecisionNote::CappedLodBias => Degradation::CappedLodBias, PrecisionNote::SnormMinimumKept => Degradation::SnormMinimumKept, PrecisionNote::DepthDenormals => Degradation::DepthDenormals, PrecisionNote::DeviceFilteredMipmaps => Degradation::DeviceFilteredMipmaps, PrecisionNote::CompressedTexelDecode => Degradation::CompressedTexelDecode, PrecisionNote::DeviceReconvergence => { Degradation::ImplementationDefinedReconvergence } } } } }; macro-template metal2vulkan-runtime::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-runtime::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-runtime::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 } } }; @@ -9724,6 +9724,7 @@ method metal2vulkan-rt::Texture::get_bytes pub fn get_bytes(&self, bytes: &mut [ method metal2vulkan-rt::Texture::gpu_resource_id pub fn gpu_resource_id(&self) -> ResourceId method metal2vulkan-rt::Texture::new_texture_view pub fn new_texture_view(&self, pixel_format: PixelFormat, texture_type: TextureType, levels: Range, slices: Range, index: Option) -> Result method metal2vulkan-rt::Texture::new_texture_view_with_swizzle pub fn new_texture_view_with_swizzle(&self, pixel_format: PixelFormat, texture_type: TextureType, levels: Range, slices: Range, swizzle: TextureSwizzleChannels, index: Option) -> Result +method metal2vulkan-rt::Texture::precision_note pub fn precision_note(&self) -> Option 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::Texture::upload_region pub fn upload_region(&self, region: Region, level: u32, slice: u32) -> Result<(), Error> method metal2vulkan-rt::TextureDescriptor::new pub fn new(texture_type: TextureType, pixel_format: PixelFormat, width: u32, height: u32) -> TextureDescriptor @@ -13788,6 +13789,7 @@ variant metal2vulkan-rt::PrecisionNote::BlendedWriteRounding BlendedWriteRoundin variant metal2vulkan-rt::PrecisionNote::CappedLodBias CappedLodBias variant metal2vulkan-rt::PrecisionNote::ClippedCoverageSplit ClippedCoverageSplit variant metal2vulkan-rt::PrecisionNote::ColorAttachmentGroups ColorAttachmentGroups +variant metal2vulkan-rt::PrecisionNote::CompressedTexelDecode CompressedTexelDecode variant metal2vulkan-rt::PrecisionNote::ComputedSampleDepth ComputedSampleDepth variant metal2vulkan-rt::PrecisionNote::CoverageReadsRoundedAlpha CoverageReadsRoundedAlpha variant metal2vulkan-rt::PrecisionNote::CubeGradientFootprint CubeGradientFootprint @@ -16743,6 +16745,7 @@ variant metal2vulkan::pipeline::PrecisionNote::BlendedWriteRounding BlendedWrite variant metal2vulkan::pipeline::PrecisionNote::CappedLodBias CappedLodBias variant metal2vulkan::pipeline::PrecisionNote::ClippedCoverageSplit ClippedCoverageSplit variant metal2vulkan::pipeline::PrecisionNote::ColorAttachmentGroups ColorAttachmentGroups +variant metal2vulkan::pipeline::PrecisionNote::CompressedTexelDecode CompressedTexelDecode variant metal2vulkan::pipeline::PrecisionNote::ComputedSampleDepth ComputedSampleDepth variant metal2vulkan::pipeline::PrecisionNote::CoverageReadsRoundedAlpha CoverageReadsRoundedAlpha variant metal2vulkan::pipeline::PrecisionNote::CubeGradientFootprint CubeGradientFootprint diff --git a/docs/API.md b/docs/API.md index 67c6e15f1..dbace5123 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4006,16 +4006,23 @@ bound. where Metal's sees the nil buffer's offset as its address; neither holds a buffer, so only the address's value differs. - `metal2vulkan-degrade-compressed-texel-decode` (precision). `CompressedTexelDecode`: A texture of - a BC format (`BC1_RGBA` to `BC7_RGBAUnorm_sRGB`) made on a device whose driver is not measured to + a block-compressed format, where the runtime makes it. On `metal2vulkan-runtime`, a texture of a + BC format (`BC1_RGBA` to `BC7_RGBAUnorm_sRGB`) made on a device whose driver is not measured to decode its texels as Metal does (BC1 to BC3 `DriverFact::ColorBlockDecodeIsMetals`: MoltenVK on Apple's GPUs, RADV on the 780M and the RX 7900 XTX; BC4 and BC5 `DriverFact::ChannelBlockDecodeIsMetals`: MoltenVK on Apple's GPUs; BC6H `DriverFact::Bc6hBlockDecodeIsMetals` and BC7 `DriverFact::Bc7BlockDecodeIsMetals`: MoltenVK on Apple's GPUs, NVIDIA's on the RTX 3090 and RTX 5080 Laptop GPU, RADV on the 780M, ANV on the Iris - Xe of Raptor Lake-P, and lavapipe's BC6H). The texture's image is its own BC image, which the - device samples through its own decode: no BC texture keeps a decoded twin. The bounds are the + Xe of Raptor Lake-P, and lavapipe's BC6H). On `metal2vulkan-rt` it is the static note + `PrecisionNote::CompressedTexelDecode` of every texture or view whose own pixel format is + block-compressed (BC1 to BC7, and the ASTC, ETC2 and EAC formats where the device makes them; + `Texture::precision_note`), on every device, with no driver fact. The texture's image is its + own image of that format, which the device samples through its own decode: no BC texture keeps a + decoded twin. The bounds are the largest differences from Metal's texels measured on random blocks of every format; a driver not - named is unmeasured, and validation derives no tolerance from them. + named is unmeasured. Validation derives no tolerance from them; the conformance suite's BC1 to + BC5 decode cases hold each texel to its family's largest bound on any driver (an sRGB form's to + the sRGB decode's largest step over 4/255), justified by the notice alone. Cost: a read, sample or gather of its texels answers the device's decode of its blocks (an sRGB form's code through the device's sRGB decode), where Metal interpolates with 6-bit weights: a BC1 to BC3 channel up to 4/255 off Metal's on NVIDIA (615.71.09, the RTX 3090 and RTX 5080 Laptop diff --git a/docs/CONFORMANCE-COVERAGE.md b/docs/CONFORMANCE-COVERAGE.md index c00d64ffa..7ea4b0c59 100644 --- a/docs/CONFORMANCE-COVERAGE.md +++ b/docs/CONFORMANCE-COVERAGE.md @@ -536,8 +536,8 @@ An implemented container no case's Metal leg touches. These are the families of | cases whose Metal answer is `metal_run` | 1201 | | cases whose Metal answer is `carried` | 80 | | cases whose Metal answer is `never_returned` | 4 | -| modules that loosen a measured value | 12 | -| tolerances in all | 13 | +| modules that loosen a measured value | 13 | +| tolerances in all | 14 | | modules declaring a notice (loosening no value) | 136 | | loosenings used | `Unchecked`, `Absolute`, `AnyOf`, `Nonzero` | | justifications named | `Degradation`, `AcceptedDifference`, `WithoutCompression` | @@ -581,7 +581,7 @@ Each case module: the cases it holds, the `Side` methods it calls, and how many | `command_buffer_facts` | 1 | 1 | every field | 29 | | `command_queues` | 1 | 1 | every field | 5 | | `compressed_blits` | 4 | 4 | every field | 49 | -| `compressed_decode` | 10 | 10 | every field | 43 | +| `compressed_decode` | 10 | 10 | 1 tolerance(s): `Degradation` | 43 | | `compressed_moves` | 14 | 14 | every field | 41 | | `compressed_views` | 14 | 14 | every field | 48 | | `compute_encoder_commands` | 8 | 8 | every field | 66 |