diff --git a/crates/metal2vulkan-runtime/src/device/compiles.rs b/crates/metal2vulkan-runtime/src/device/compiles.rs index 85514a24b..9950148d9 100644 --- a/crates/metal2vulkan-runtime/src/device/compiles.rs +++ b/crates/metal2vulkan-runtime/src/device/compiles.rs @@ -29,7 +29,8 @@ //! where it ran before, so a lock the program holds across the creation, which the sink takes //! again, does not deadlock against the full join. A messenger the program registered itself on //! an adopted instance is not the runtime's: the driver calls it on the thread that makes the -//! call, the runtime's here. +//! call, the runtime's here. An asking thread that itself holds its call's messages (a +//! self-check's, [`holding`]) keeps those its runtime thread held, for the self-check to read. //! - **The exit guard.** The thread is one of the runtime's (`exit_guard::spawn_scoped`) and makes //! the call inside a section of its own. Where the host starts no thread, or once the process is //! exiting (the guard closed), the asking thread makes the call itself, as before. @@ -265,22 +266,27 @@ pub(super) fn held(sink: &MessageSink, message: &DebugMessage) -> bool { } /// `call`, with this thread holding the sink messages the driver raises in it ([`held`]): its -/// result, and the messages in the order raised. -fn holding(call: impl FnOnce() -> R) -> (R, Vec<(MessageSink, DebugMessage)>) { - /// Stops holding however `call` ends. - struct Clear; - impl Drop for Clear { +/// result, and the messages in the order raised, whichever thread made the driver call +/// ([`at_user_initiated`] holds a relayed call's messages here). A thread of the runtime's making +/// a call for an asking thread holds them for it; a self-check holds its own driver call's, whose +/// failure is the answer it asked for (`pipeline::objects::takes_multi_variable_dynamic`). A +/// holding inside another keeps the outer one's messages as they were. +pub(crate) fn holding(call: impl FnOnce() -> R) -> (R, Vec<(MessageSink, DebugMessage)>) { + type Messages = Option>; + /// Puts the outer holding back however `call` ends. + struct Restore(Messages); + impl Drop for Restore { fn drop(&mut self) { - let _ = HELD.try_with(|held| held.borrow_mut().take()); + let outer = self.0.take(); + let _ = HELD.try_with(|held| *held.borrow_mut() = outer); } } - HELD.with(|held| *held.borrow_mut() = Some(Vec::new())); - let clear = Clear; + let restore = Restore(HELD.with(|held| held.borrow_mut().replace(Vec::new()))); let made = call(); let messages = HELD .with(|held| held.borrow_mut().take()) .unwrap_or_default(); - drop(clear); + drop(restore); (made, messages) } @@ -318,9 +324,12 @@ pub(super) fn at_user_initiated(call: impl FnOnce() -> R + Send) -> R { match (made, asked) { (Some(((made, withheld), messages)), _) => { crate::driver_facts::withheld_for_here(withheld); - // The program's sink, on the asking thread, in the order the driver raised them. + // The program's sink, on the asking thread, in the order the driver raised them: + // held again where this thread holds its call's own ([`holding`]). for (sink, message) in messages { - sink.deliver(&message); + if !held(&sink, &message) { + sink.deliver(&message); + } } made } diff --git a/crates/metal2vulkan-runtime/src/device/mod.rs b/crates/metal2vulkan-runtime/src/device/mod.rs index 568ff74cf..3b9b5ea27 100644 --- a/crates/metal2vulkan-runtime/src/device/mod.rs +++ b/crates/metal2vulkan-runtime/src/device/mod.rs @@ -31,6 +31,7 @@ mod staging; pub(super) mod submit; pub use adopt::RawDevice; +pub(crate) use compiles::holding; pub use create::{ DebugMessage, DeviceOptions, LayerSetting, LayerSettingValue, MessageKind, MessageSeverity, MessageSink, diff --git a/crates/metal2vulkan-runtime/src/pipeline/objects.rs b/crates/metal2vulkan-runtime/src/pipeline/objects.rs index 3b6bfb648..e9975fe76 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/objects.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/objects.rs @@ -1344,6 +1344,11 @@ fn dynamic_numbers( /// module with one variable per unit view the device's storage views can declare, so any plan's /// binding is a subset of it (`bind::DynamicViewsModule`), and destroying it. A creation that /// fails, for any reason, answers no, which is what every device answered before it was asked. +/// What the driver reports inside that failed creation is its answer to the runtime's own +/// question and names none of the program's work (MoltenVK 1.4.2 reports the Metal it could not +/// compile and the failed pipeline as two errors), so the sink is handed one informational line +/// carrying those messages ([`SELF_CHECK_REFUSED`]) in place of the driver's errors; a creation +/// that succeeds hands on whatever the driver reported in it, as any other making does. /// /// The check proves the driver **compiles** the shape. A driver that compiled it and then applied /// the dynamic offset to one of its variables alone would still be wrong, and none is measured to @@ -1400,14 +1405,21 @@ fn multi_variable_dynamic_creates(device: &Device) -> Result { .layout(layout); // SAFETY: every pointer in `info` outlives the call; no pipeline cache, since the // self-check's pipeline is never made again. - let created = - unsafe { raw.create_compute_pipelines(vk::PipelineCache::null(), &[info], None) }; + let (created, heard) = crate::device::holding(|| unsafe { + raw.create_compute_pipelines(vk::PipelineCache::null(), &[info], None) + }); match created { Ok(made) => { pipeline = made.first().copied().unwrap_or(vk::Pipeline::null()); + for (sink, message) in &heard { + sink.deliver(message); + } Ok(true) } - Err(_) => Ok(false), + Err((_, result)) => { + refused_self_check(result, &heard); + Ok(false) + } } })(); // SAFETY: nothing uses the objects: no command recorded them, and the pipeline, where it was @@ -1421,6 +1433,31 @@ fn multi_variable_dynamic_creates(device: &Device) -> Result { made } +/// The id name of the informational line a device hands its sink where the driver did not make +/// the self-check's pipeline of [`takes_multi_variable_dynamic`]: the driver's result and the +/// messages it reported inside that creation, which the sink is not handed as the driver's own. +pub(crate) const SELF_CHECK_REFUSED: &str = "metal2vulkan-self-check-refused"; + +/// Tell the sink that heard the driver's messages `heard` inside the self-check's creation, +/// informationally, that the driver did not make its pipeline ([`SELF_CHECK_REFUSED`]): its +/// `result`, and those messages, by id name and text, in the order the driver raised them. A +/// creation that reported nothing says nothing, as before. +fn refused_self_check(result: vk::Result, heard: &[(crate::MessageSink, crate::DebugMessage)]) { + let Some((sink, _)) = heard.first() else { + return; + }; + let mut text = format!( + "the device does not take a set-0 buffer binding of several variables as a dynamic \ + descriptor: vkCreateComputePipelines of the self-check module answered {result:?}, \ + reporting {} message(s) of its own", + heard.len() + ); + for (_, message) in heard { + text.push_str(&format!("\n{}: {}", message.id_name, message.text)); + } + crate::driver_facts::inform_through(Some(sink), SELF_CHECK_REFUSED, text); +} + /// The device's answer of [`takes_multi_variable_dynamic`], for the check that the restriction is /// the device's and not every device's (`tests::dynamic_multi_variable`). #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] diff --git a/crates/metal2vulkan-runtime/src/tests/dynamic_multi_variable.rs b/crates/metal2vulkan-runtime/src/tests/dynamic_multi_variable.rs index ba8275ac9..cce13e701 100644 --- a/crates/metal2vulkan-runtime/src/tests/dynamic_multi_variable.rs +++ b/crates/metal2vulkan-runtime/src/tests/dynamic_multi_variable.rs @@ -16,7 +16,9 @@ //! - and the sets its dispatches take are the ones the variant's own choice calls for //! (`ComputePipelineState::set_zero_choice`): where it pushes set 0 every dispatch pushes, where //! it made the store sink's binding dynamic every dispatch after the first binds its -//! predecessor's set, and otherwise each allocates and writes its own. +//! predecessor's set, and otherwise each allocates and writes its own; +//! - and a self-check the driver refuses reaches the device's sink as at most one informational +//! line, never as the driver's errors of the runtime's own question. //! //! The device's answer is read where it bounds that choice -- a device that does not take such a //! binding has none of them dynamic -- and never as the expectation itself. The two come apart: a @@ -32,14 +34,17 @@ //! //! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). +use crate::pipeline::objects::SELF_CHECK_REFUSED; use crate::pipeline::SetZeroChoice; use crate::{ - Device, DeviceKind, DeviceOptions, PipelineOptions, ResourceOptions, ShaderCacheOptions, Size, + DebugMessage, Device, DeviceKind, DeviceOptions, MessageSeverity, MessageSink, PipelineOptions, + ResourceOptions, ShaderCacheOptions, Size, }; use metal2vulkan::device::VkExtension; use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource}; use std::collections::BTreeSet; use std::path::{Path, PathBuf}; +use std::sync::{Arc, Mutex}; struct Scratch(PathBuf); @@ -74,6 +79,11 @@ enum Pushing { } fn device(cache: &Path, pushing: Pushing) -> Device { + device_with(cache, pushing, None) +} + +/// [`device`], its messages handed to `messages`. +fn device_with(cache: &Path, pushing: Pushing, messages: Option) -> Device { let withheld: BTreeSet = match pushing { Pushing::Withheld => [VkExtension::KhrPushDescriptor].into_iter().collect(), Pushing::Enabled => BTreeSet::new(), @@ -92,6 +102,7 @@ fn device(cache: &Path, pushing: Pushing) -> Device { directory: Some(cache.to_owned()), ..ShaderCacheOptions::default() }, + messages, ..DeviceOptions::default() }; Device::system_default_with(&options).unwrap() @@ -355,6 +366,60 @@ fn a_four_variable_kernel_without_the_push_command_follows_its_budget() { } } +/// The self-check's failed creation is the device's answer to the runtime's own question, not a +/// fault of the program's work: a device whose answer is no hands its sink none of the errors the +/// driver reported inside that creation, but at most one informational line carrying them +/// (`objects::SELF_CHECK_REFUSED`, none where the driver reported nothing); a device whose answer +/// is yes hands it no such line. MoltenVK 1.4.2 on an Apple M3 Max reports two errors there (the +/// Metal it could not compile, and the pipeline), which reached the sink as errors before, failing +/// every validation lane that made a kernel of such a binding. The `DYNMULTI` line says what the +/// device answered and what its sink heard. +#[test] +fn a_refused_self_check_reaches_the_sink_as_one_informational_line() { + let heard: Arc>> = Arc::default(); + let sink = { + let heard = heard.clone(); + MessageSink::new(move |message| heard.lock().unwrap().push(message.clone())) + }; + let scratch = Scratch::new(); + let answer = { + let device = device_with(&scratch.0, Pushing::Enabled, Some(sink)); + // What the device's making reported is not the self-check's. + heard.lock().unwrap().clear(); + crate::pipeline::objects::asks_multi_variable_dynamic(&device) + }; + let heard = heard.lock().unwrap().clone(); + let refused: Vec<_> = (heard.iter()) + .filter(|message| message.id_name == SELF_CHECK_REFUSED) + .collect(); + eprintln!( + "DYNMULTI the device answered {answer}; its sink heard {} message(s), {} of them \ + `{SELF_CHECK_REFUSED}`: {:?}", + heard.len(), + refused.len(), + refused.first().map(|message| &message.text) + ); + let errors: Vec<_> = (heard.iter()) + .filter(|message| message.severity == MessageSeverity::Error) + .collect(); + assert!( + errors.is_empty(), + "the self-check's creation reached the sink as errors: {errors:#?}" + ); + match answer { + true => assert!( + refused.is_empty(), + "a device that answered yes: {refused:#?}" + ), + false => assert!( + refused.len() <= 1 + && (refused.iter()).all(|message| message.severity == MessageSeverity::Info), + "a device that answered no hands its sink at most one informational line: \ + {refused:#?}" + ), + } +} + /// The device's own answer, from a device of this test's own making, of this `pushing`: what each /// check here reads where the answer bounds the variant's choice. fn answered(pushing: Pushing) -> bool { diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index a08534f96..1aedf2df2 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -fc9fa00e43f086d68a7d1d79bcd2a09ed4a7931fcc8264c7030474dca044db94 +4a5e70f65462757327e003324a9090da1a300cfa9b32aab68f4f73ceebae6898 diff --git a/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs index 882fc335a..283424998 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs @@ -661,14 +661,14 @@ fn astc_textures_the_runtime_does_not_hold_are_refused() { let written = texture(device, pf, usage); let mut descriptor = TextureDescriptor::texture_2d(pf, SIDE.into(), SIDE.into(), false); descriptor.resource_options = ResourceOptions::shared(); - // Its heap size query is refused alike. - let answer = device.heap_texture_size_and_align(&descriptor).map(drop); + // Its heap size query answers Metal's model of the texture's blocks, which no image of + // the device decides (`Device::heap_texture_size_and_align`), while the making's refusal + // stands. + let answer = device.heap_texture_size_and_align(&descriptor); + let metal = device.metal_heap_texture_size_and_align(&descriptor); assert!( - matches!( - answer, - Err(Error::NotImplemented(RuntimeGap::DecodedHeapTexture)) - ), - "{answer:?}" + matches!((&answer, &metal), (Ok(a), Ok(Some(m))) if a == m && a.size > 0), + "the size query answered {answer:?}, Metal's model {metal:?}" ); let heap_descriptor = HeapDescriptor::new(HeapType::Placement, 1 << 16, ResourceOptions::shared()); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs b/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs index ac791d921..0a376e014 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/buffer_texture_blits.rs @@ -1037,9 +1037,12 @@ pub(super) const COLLIDING_ROWS: [Degradation; 1] = [Degradation::CollidingSurfa /// bytes being unmeasured, and announces nothing; and the same plane at 32 bytes a row, whose GPU /// rows lie 32 apart and share nothing, is made announcing no kind of its own. Each runs over an /// ordinary buffer standing for the surface and a no-copy one, and the second plane announces -/// nothing, a device announcing each kind once. The texture's reads -/// here are the CPU's own rows: every blit of such a plane is refused, the shadow's two copy -/// regions each way being the only form that holds the sharing, so a kernel is the only writer +/// nothing, a device announcing each kind once. The CPU reads and writes the plane's own rows. +/// A blit out of the plane into a buffer is served, announcing nothing of its own: it reads each +/// row at its own GPU row, a shared byte once for each row that holds it +/// ([`a_blit_out_of_a_plane_whose_gpu_rows_share_bytes_reads_each_row_at_its_own_pitch`] holds +/// its bytes over more shapes). A blit into it stays refused, a write having to settle which row +/// leaves the shared bytes where Metal settles it no one way, so a kernel is the only GPU writer /// the plane takes. #[test] fn an_iosurface_plane_whose_gpu_rows_share_bytes_is_announced() { @@ -1102,21 +1105,42 @@ fn an_iosurface_plane_whose_gpu_rows_share_bytes_is_announced() { .unwrap(); held.write(0, &written); held.check(&format!("{kind:?}: replace_region")); - // A blit addresses the GPU's rows as bytes, which no row copy holds. + // A blit out of the plane reads each buffer row at its own GPU row, 16 apart here. let out = buffer_with(&device, &vec![0xee; n]).unwrap(); + blit(&device, |e| { + e.copy_from_texture_to_buffer( + &shared, + 0, + 0, + origin([0, 0]), + size([w, h]), + &out, + 0, + row, + row * h, + BlitOption::None, + ) + .unwrap_or_else(|e| panic!("{kind:?}: a blit out of rows that share bytes: {e}")) + }); + assert_eq!( + read_buffer(&out, 0, n as u64).unwrap(), + gather(&held.model, &gpu_rows(0, row, row, h)), + "{kind:?}: a blit's read of rows that share bytes" + ); + // A blit into the plane writes the GPU's rows as bytes, which no row copy holds. let mut gap = None; blit(&device, |e| { gap = e - .copy_from_texture_to_buffer( - &shared, - 0, - 0, - origin([0, 0]), - size([w, h]), + .copy_from_buffer_to_texture( &out, 0, row, row * h, + size([w, h]), + &shared, + 0, + 0, + origin([0, 0]), BlitOption::None, ) .err(); @@ -1124,7 +1148,7 @@ fn an_iosurface_plane_whose_gpu_rows_share_bytes_is_announced() { assert_eq!( gap, Some(Error::NotImplemented(RuntimeGap::OverlappingSurfaceRows)), - "{kind:?}: a blit of rows that share bytes" + "{kind:?}: a blit into rows that share bytes" ); // The plane of the first buffer kind announces [`COLLIDING_ROWS`]; the second's // announces nothing, a device announcing each kind once. Both are the set a step diff --git a/crates/metal2vulkan-validation/src/runtime_lane/cache.rs b/crates/metal2vulkan-validation/src/runtime_lane/cache.rs index 3ca2c440a..02052e329 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/cache.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/cache.rs @@ -596,7 +596,10 @@ fn set_mode(dir: &Path, mode: u32) { /// The directory is made writable for the device to open (`Directory::open` checks that it takes /// a write and fails the creation otherwise, which is the one shader-cache error there is), and /// unwritable afterwards, which is the state a full disk or a directory someone else locked down -/// leaves. Unix only: it turns on the directory's mode bits. +/// leaves. Unix only: it turns on the directory's mode bits. A process the mode bits do not bind +/// (one running as root, as in the Linux gate's container) writes into the directory all the +/// same, so nothing is refused there: the test checks that with a file of its own first, and where +/// the write goes through it says so (`CACHE-UNWRITABLE`) and holds nothing. #[cfg(unix)] #[test] fn an_entry_that_cannot_be_written_is_announced_and_ends_nothing() { @@ -609,6 +612,17 @@ fn an_entry_that_cannot_be_written_is_announced_and_ends_nothing() { let device = validated_device(TEST_DEVICE, &messages, cache.path()).unwrap(); let build = build_dir(cache.path()); set_mode(&build, READ_ONLY_DIR); + let probe = build.join("cache-unwritable-probe"); + if std::fs::write(&probe, b"probe").is_ok() { + std::fs::remove_file(&probe).unwrap(); + set_mode(&build, 0o700); + eprintln!( + "CACHE-UNWRITABLE: this process wrote into a directory of mode {READ_ONLY_DIR:o} \ + (the mode bits do not bind it, as they do not bind root), so no entry can be \ + refused here; the test did not run" + ); + return; + } let made = pipeline_state(&device, &case); let state = match made { Ok(state) => state, diff --git a/crates/metal2vulkan-validation/src/runtime_lane/heap_layouts.rs b/crates/metal2vulkan-validation/src/runtime_lane/heap_layouts.rs index c4fdc357d..344785306 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_layouts.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_layouts.rs @@ -990,7 +990,9 @@ fn fnv(bytes: &[u8]) -> u64 { /// reads each level back from the CPU's writes of those bytes. Counted tiled, with no layout /// notice. A device whose image of the format holds other bytes than its blocks (a format it /// decodes) announces `heap-texture-untiled-layout` instead (each row's notice: the device asks -/// for each, `DeviceOptions::announce_each`). +/// for each, `DeviceOptions::announce_each`). An ASTC texture on a device without ASTC, whose +/// carrier's decoded twin would decode what the heap's bytes held, answers Metal's size and is +/// refused its making (`NotImplemented(DecodedHeapTexture)`), its `HEAPLAYOUT` line saying so. #[test] fn a_host_heap_s_block_compressed_texture_lies_as_metal_lays_it_out() { let each = |options: &mut DeviceOptions| options.announce_each = HEAP_LAYOUTS.into(); @@ -1008,15 +1010,13 @@ fn block_rows_lie_as_metal_lays_them_out(device: &Device, messages: &Messages) { return; }; let descriptor = row.descriptor(); - // A format the device has no image of is refused before any layout, and an ASTC texture - // on a device without ASTC (`RuntimeGap::DecodedHeapTexture`); an ETC2 or EAC texture on a - // device without them lies in a carrier of the same blocks (`etc.rs`). + // A format the device has no image of is refused before any layout; an ASTC texture on a + // device without ASTC is answered Metal's model of its blocks and refused its making + // (`RuntimeGap::DecodedHeapTexture`, below); an ETC2 or EAC texture on a device without + // them lies in a carrier of the same blocks (`etc.rs`). let answer = match device.heap_texture_size_and_align(&descriptor) { Ok(answer) => answer, - Err( - error @ (Error::Unsupported(_) - | Error::NotImplemented(RuntimeGap::DecodedHeapTexture)), - ) => { + Err(error @ Error::Unsupported(_)) => { eprintln!("HEAPLAYOUT {what}: refused {error:?}"); continue; } @@ -1031,7 +1031,10 @@ fn block_rows_lie_as_metal_lays_them_out(device: &Device, messages: &Messages) { let before = device.work_counts(); let texture = match heap.new_texture_at_offset(&descriptor, OFFSET) { Ok(texture) => texture, - Err(error @ Error::Unsupported(_)) => { + Err( + error @ (Error::Unsupported(_) + | Error::NotImplemented(RuntimeGap::DecodedHeapTexture)), + ) => { eprintln!("HEAPLAYOUT {what}: refused {error:?}"); continue; } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/heap_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/heap_textures.rs index be47a1210..37b337e35 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_textures.rs @@ -1297,7 +1297,10 @@ fn tiling_refusal(error: &Error) -> Option { /// the footprint **and** makes the texture, so the refusal is this crate's open gap and the /// `HEAPTEX shared no image` lines name every format and descriptor it covers. Every such format /// answers in all four swept usages, counted from that table, so one that stops answering fails -/// rather than passing as a query and a call that both refuse. +/// rather than passing as a query and a call that both refuse. An ASTC texture on a device that +/// holds it in a carrier with a decoded twin (lavapipe) answers Metal's model of its blocks and is +/// refused its making, `NotImplemented(DecodedHeapTexture)`: the twin would decode what the heap's +/// bytes held. `HEAPTEX shared decoded` lines name each. #[test] fn shared_heap_textures_are_made_or_refused_for_linear_tiling() { on_device(|device| { @@ -1326,6 +1329,7 @@ fn shared_heap_textures_are_made_or_refused_for_linear_tiling() { let mut changed_again = Vec::new(); let mut gaps = Vec::new(); let mut no_image = Vec::new(); + let mut decoded = Vec::new(); let mut check = |what: String, mut descriptor: TextureDescriptor| { descriptor.resource_options = options; let query = device.heap_texture_size_and_align(&descriptor); @@ -1426,6 +1430,19 @@ fn shared_heap_textures_are_made_or_refused_for_linear_tiling() { } no_image.push(format!("{what}: {answer:?}")); } + // An ASTC texture on a device that holds it in a carrier with a decoded twin, which + // would decode what the heap's bytes held: the query answers Metal's model of its + // blocks and the making is refused, the runtime's gap. + (Ok(answer), Err(Error::NotImplemented(RuntimeGap::DecodedHeapTexture))) => { + let pf = descriptor.pixel_format; + assert!( + !super::astc_textures::decodes_astc(device, pf), + "{what}: refused as a decoded heap texture on a device that decodes it" + ); + let metal = device.metal_heap_texture_size_and_align(&descriptor); + assert_eq!(metal, Ok(Some(answer)), "{what}: Metal's model"); + decoded.push(format!("{what}: {answer:?}")); + } (Ok(answer), Err(error)) => panic!("{what}: answered {answer:?}, made {error:?}"), (Err(error), Ok(_)) => panic!("{what}: refused {error:?} by the query alone"), (Err(query), Err(call)) => { @@ -1478,6 +1495,9 @@ fn shared_heap_textures_are_made_or_refused_for_linear_tiling() { for line in &no_image { eprintln!("HEAPTEX shared no image {line}"); } + for line in &decoded { + eprintln!("HEAPTEX shared decoded {line}"); + } eprintln!( "HEAPTEX shared on {}: {made} made ({round_trips} round trips, {} second reads \ differ, {} staging queue submissions), {} refused for linear tiling, {} answered a \ @@ -1501,13 +1521,14 @@ fn shared_heap_textures_are_made_or_refused_for_linear_tiling() { gaps.is_empty(), "colour textures refused as gaps: {gaps:#?}" ); - // Every format whose footprint its own structure decides, Metal's `NoTexture` shape - // aside, answered that footprint in all four swept usages. The count comes from the - // product's own table rather than a number here, so a footprint that stops answering - // fails this instead of passing quietly as a query and a call that both refuse. + // Every format whose footprint its own structure decides answered that footprint in all + // four swept usages, the packed 10-bit pair's `NoTexture` 0 bytes at 16 among them (the + // arm above). The count comes from the product's own table rather than a number here, so + // a footprint that stops answering fails this instead of passing quietly as a query and a + // call that both refuse. let answering = PixelFormat::ALL .iter() - .filter(|&&pf| footprint(pf).is_some_and(|shape| shape != Footprint::NoTexture)) + .filter(|&&pf| footprint(pf).is_some()) .count(); assert_eq!( no_image.len(), diff --git a/crates/metal2vulkan-validation/src/runtime_lane/kept_variants.rs b/crates/metal2vulkan-validation/src/runtime_lane/kept_variants.rs index d68282608..a417e9cc6 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/kept_variants.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/kept_variants.rs @@ -340,11 +340,16 @@ fn the_least_recently_released_variants_go_first() { on_device(|device, _| { let mut states = 0; let mut kernels = Vec::new(); - for (_, case) in cases { - let Ok(case) = case else { - continue; + for (name, case) in cases { + let case = match case { + Ok(case) => case, + Err(error) => { + eprintln!("KEPT skipped {name}: {error}"); + continue; + } }; - if pipeline_state(device, &case).is_err() { + if let Err(error) = pipeline_state(device, &case) { + eprintln!("KEPT skipped {name}: {error}"); continue; } states += 1; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/resource_ids.rs b/crates/metal2vulkan-validation/src/runtime_lane/resource_ids.rs index 1c0330d87..907a03d4f 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/resource_ids.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/resource_ids.rs @@ -102,11 +102,31 @@ pub(super) const DELAYED_DEALLOCATORS: [Degradation; 1] = [Degradation::HostDeal /// single-sample colour images bound to memory lie as Metal lays a heap texture out /// (`DriverFact::ColorImagesLieAsMetalHeapTextures`), or whose route is another than the /// optimal image bound there (`texture/heap.rs`, `Device::device_heap_layout`). -fn heap_texture_kinds(device: &Device, descriptor: &TextureDescriptor) -> BTreeSet { +/// +/// A texture the device made as a shadow of its elements in Metal's tiles in the heap's bytes +/// (`tiled`: it moved `WorkCounts::heap_textures_tiled`, the route `texture/heap.rs` takes where +/// the image it would bind there is itself a shadow or keeps a layout Metal does not, and the +/// device moves the tiles) lies as Metal lays it out at Metal's answer: it announces that shadow +/// (`shadowed-texture`) and no route or layout of an image bound there. The lavapipe of the Linux +/// gate's container takes that route for a `Private` heap's texture. +fn heap_texture_kinds( + device: &Device, + descriptor: &TextureDescriptor, + tiled: bool, +) -> BTreeSet { let answer = device.heap_texture_size_and_align(descriptor).unwrap(); let metal = device .metal_heap_texture_size_and_align(descriptor) .unwrap(); + if tiled { + return forced(&[ + ( + Degradation::HeapTextureLargerThanMetal, + metal.is_some_and(|metal| answer != metal), + ), + (Degradation::ShadowedTexture, true), + ]); + } let facts = &device.properties().driver_facts; let hides = facts.contains(&DriverFact::CompressedImagesHideAliasedWrites); let format = direct_format(descriptor.pixel_format).expect("a direct format"); @@ -618,9 +638,12 @@ fn a_texture_made_in_a_used_heap_after_a_dispatch_is_reached() { let mut descriptor = texture_descriptor(&sampling.literal, sampling.usage).unwrap(); descriptor.resource_options = ResourceOptions::private(); let mut first = sampling.forced(device); - first.extend(heap_texture_kinds(device, &descriptor)); + let unplaced = descriptor; descriptor.placement = IdPlacement::At(id); + let made = device.work_counts().heap_textures_tiled; let late = heap.new_texture(&descriptor).unwrap(); + let tiled = device.work_counts().heap_textures_tiled > made; + first.extend(heap_texture_kinds(device, &unplaced, tiled)); let upload = sampling.queue.command_buffer().unwrap(); sampling.upload(device, &upload, &late); upload.commit().unwrap(); @@ -981,6 +1004,7 @@ fn a_heap_s_token_drops_at_its_release_whatever_keeps_its_textures_images() { let texture = sampling.texture(); let mut d = texture_descriptor(&sampling.literal, sampling.usage).unwrap(); d.resource_options = ResourceOptions::private(); + let made = device.work_counts().heap_textures_tiled; for heap_type in [HeapType::Automatic, HeapType::Placement] { for case in ["through its ID", "first move"] { let dropped = Arc::new(AtomicBool::new(false)); @@ -1025,8 +1049,14 @@ fn a_heap_s_token_drops_at_its_release_whatever_keeps_its_textures_images() { assert_eq!(&output, expected, "{what}"); } } + let tiled = device.work_counts().heap_textures_tiled > made; let mut first = sampling.forced(device); - first.extend(heap_texture_kinds(device, &d)); + first.extend(heap_texture_kinds(device, &d, tiled)); + // A shadow is announced as its ID's holder once: the command that reaches it through its + // ID alone binds the heap set holding it, neither naming it nor making it resident. + if tiled { + first.insert(UNNAMED_SHADOWS[0]); + } assert_made_once(messages, &[], &first); }); } diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index df1e69072..da5b663f6 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 467; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 1668; +pub const RUNTIME_VERSION: u32 = 1669; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/docs/API.md b/docs/API.md index f8b78bc6f..9ec3df085 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1194,7 +1194,12 @@ Whatever the variables, a placement heap's `newTextureWithDescriptor:offset:` th `metal2vulkan-heap-texture-refused`, `Info` severity): the descriptor, the offset, the heap's size, options and memory, the size and alignment the size query answers the descriptor, what the making planned (the size and alignment it places the texture by, its image's route, tiling and memory -requirements) and the refusal. That text is for people, not a contract. +requirements) and the refusal. A device's self-check that the driver does not make (the one +pipeline it creates to ask whether a set-0 buffer binding of several variables may be a dynamic +descriptor, `FAST-PATHS.md`) hands the sink one line saying so, with the driver's result and the +messages it reported inside that creation (id name `metal2vulkan-self-check-refused`, `Info` +severity), in place of those messages: they answer the runtime's own question and name none of the +program's work (MoltenVK 1.4.2 reports two errors there). That text is for people, not a contract. Each entry below gives the code, its category, the `Degradation` kind (or the `PrecisionNote`) and what triggers it; a runtime kind's cost follows. The kind's rustdoc states the trigger, cost and