diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..bf828c699 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,21 @@ +# Build settings for this workspace's own builds. A consumer that depends on the published crates +# never reads this file (Cargo reads the configuration of the directory it runs in). + +[build] +# kache (a compiler cache) where it is installed, plain rustc where it is not, CI included: +# `scripts/rustc-wrapper` decides per invocation. `RUSTC_WRAPPER` set in the environment replaces +# it, and an empty `RUSTC_WRAPPER=` runs rustc with no wrapper at all. +rustc-wrapper = "scripts/rustc-wrapper" + +[unstable] +profile-rustflags = true + +# rustc's parallel front end on every compile, with as many threads as the machine has cores +# (`0`). Profile rustflags are added to `RUSTFLAGS` rather than replaced by it, so the GPU lanes' +# `--cfg m2v_gpu` and CI's `-Dwarnings` keep it. `test`, `bench` and `debugger` inherit it from +# `dev` and `release`. +[profile.dev] +rustflags = ["-Zthreads=0"] + +[profile.release] +rustflags = ["-Zthreads=0"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fb3a3838..155ebadb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,8 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy + # The dated nightly and components rust-toolchain.toml names. + run: rustup toolchain install - name: Cache cargo uses: Swatinem/rust-cache@v2 diff --git a/AGENTS.md b/AGENTS.md index 279dcacf3..76f1d13ee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -156,7 +156,8 @@ has the commands. - make worktrees with `scripts/lean-tree worktree` (the observations are clones) and source snapshots with `scripts/lean-tree snapshot` (no observations unless the tree runs validation); - start each new target directory from a seed with `scripts/seed-target`; - - set `CARGO_INCREMENTAL=0` for one-shot builds; + - builds are incremental, and compile through `scripts/rustc-wrapper` (kache where it is + installed: a local cache that also carries incremental state between worktrees); - record Instruments traces through `scripts/xctrace-run`, and delete the `.trace` once exported. - `pgrep -f` and `ps | grep` match their own command line. Always bracket the first character: @@ -218,7 +219,9 @@ cargo nextest run -p metal2vulkan-conformance --all-features cargo test --workspace --all-features --doc ``` -- MSRV: `rust-version` in the crates' manifests (1.98). +- MSRV: `rust-version` in the crates' manifests (1.98). The tree builds on the dated nightly + `rust-toolchain.toml` pins, with rustc's parallel front end on every core (`-Zthreads=0`, + `.cargo/config.toml`). - Warnings are errors everywhere (CI sets `RUSTFLAGS=-Dwarnings`). Never hide one behind `#[allow(...)]`; fix it. - Features: `serde`, `ash` and `cli` (which enables `serde`). Every gate passes `--all-features`; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed97b0e41..7cd22d0e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,8 @@ they bind people too. ## Prerequisites -- Rust stable, at least the `rust-version` in the crates' manifests (1.98). +- rustup. `rust-toolchain.toml` pins the nightly this tree builds with (rustup installs it on first + use); the published crates promise the stable `rust-version` in their manifests (1.98). - [cargo-nextest](https://nexte.st): `cargo install cargo-nextest --locked`. - The external tools the tests and validation use (the libraries run none): - `llvm-as` (LLVM 21 or newer) for the `.ll` fixtures, and `llvm-dis` for validation's harvest @@ -83,7 +84,10 @@ Parallel worktrees and one-shot builds write a lot to disk. Three scripts keep t - `scripts/xctrace-run TRACE ARGS...` records with Instruments and removes the raw `instruments*.ktrace` files a recording leaves in the temp dir, an aborted one included. -Set `CARGO_INCREMENTAL=0` for a build that won't be edited and rebuilt. +Builds are incremental. Every compile goes through `scripts/rustc-wrapper`, which hands it to +[kache](https://github.com/kunobi-ninja/kache) when kache is on `PATH` (outside CI) and to rustc +otherwise; kache restores matching compiles from its local store and imports incremental state +between worktrees. `RUSTC_WRAPPER=` (empty) builds without it. ## Where tests go diff --git a/Cargo.toml b/Cargo.toml index b7aa965a2..ae81abaea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ rust-version = "1.98" license = "GPL-2.0-or-later OR LGPL-3.0-or-later" authors = ["Anees Iqbal "] repository = "https://github.com/steelbrain/metal2vulkan" -homepage = "https://github.com/steelbrain/metal2vulkan" # The external dependencies more than one crate takes, at one version each. A crate adds its own # features (and `optional`). The crates' dependencies on one another stay in their own manifests, diff --git a/crates/metal2vulkan-air/Cargo.toml b/crates/metal2vulkan-air/Cargo.toml index f7ab9491a..374f6a125 100644 --- a/crates/metal2vulkan-air/Cargo.toml +++ b/crates/metal2vulkan-air/Cargo.toml @@ -8,7 +8,6 @@ license.workspace = true authors.workspace = true description = "Read Metal AIR: the metallib container, LLVM bitcode, a typed IR, the AIR metadata ABI, intrinsics, and canonicalization" repository.workspace = true -homepage.workspace = true documentation = "https://docs.rs/metal2vulkan-air" keywords = ["metal", "air", "llvm", "bitcode", "gpu"] categories = ["compilers", "graphics", "parser-implementations"] diff --git a/crates/metal2vulkan-air/src/ir/id.rs b/crates/metal2vulkan-air/src/ir/id.rs index 77e7b4c3e..bca39d696 100644 --- a/crates/metal2vulkan-air/src/ir/id.rs +++ b/crates/metal2vulkan-air/src/ir/id.rs @@ -57,40 +57,49 @@ macro_rules! ir_id { ir_id!( /// An interned type ([`super::Type`]). - TypeId, "t" + TypeId, + "t" ); ir_id!( /// An interned constant ([`super::Constant`]). - ConstId, "c" + ConstId, + "c" ); ir_id!( /// A module-level global variable. - GlobalId, "g" + GlobalId, + "g" ); ir_id!( /// A function (definition or declaration). - FuncId, "f" + FuncId, + "f" ); ir_id!( /// A basic block within one function body. Block 0 is the entry. - BlockId, "bb" + BlockId, + "bb" ); ir_id!( /// An instruction within one function body (void instructions included). - InstId, "i" + InstId, + "i" ); ir_id!( /// A function parameter position. - ArgIdx, "a" + ArgIdx, + "a" ); ir_id!( /// A metadata node, string, or value. - MdId, "md" + MdId, + "md" ); ir_id!( /// An interned byte string (symbol names, metadata strings). Diagnostics and ABI only: no /// product decision may branch on its contents except stable `air.*`/`llvm.*` ABI keys. - Sym, "s" + Sym, + "s" ); /// A dense arena of `T` indexed by `I`. diff --git a/crates/metal2vulkan-conformance/src/attribute_coding.rs b/crates/metal2vulkan-conformance/src/attribute_coding.rs index 83aab5c3e..d7e913940 100644 --- a/crates/metal2vulkan-conformance/src/attribute_coding.rs +++ b/crates/metal2vulkan-conformance/src/attribute_coding.rs @@ -127,7 +127,7 @@ pub fn shape(name: &str) -> Option { }); } let (base, components) = match tail.as_bytes().last() { - Some(digit @ (b'2' | b'3' | b'4')) => (&tail[..tail.len() - 1], usize::from(digit - b'0')), + Some(digit @ b'2'..=b'4') => (&tail[..tail.len() - 1], usize::from(digit - b'0')), _ => (tail, 1), }; let coding = match (base, normalized) { diff --git a/crates/metal2vulkan-conformance/src/cost.rs b/crates/metal2vulkan-conformance/src/cost.rs index 057d51756..73dcc5468 100644 --- a/crates/metal2vulkan-conformance/src/cost.rs +++ b/crates/metal2vulkan-conformance/src/cost.rs @@ -231,7 +231,7 @@ pub struct PipelinesPerState { impl PipelinesPerState { /// The ratio this measurement read, where it read one. pub fn ratio(&self) -> Option { - (self.states > 0).then(|| self.pipelines as f64 / self.states as f64) + (self.states > 0).then_some(self.pipelines as f64 / self.states as f64) } /// The most pipelines this bound allows a run that created `states` states. diff --git a/crates/metal2vulkan-conformance/src/runtime_side.rs b/crates/metal2vulkan-conformance/src/runtime_side.rs index dad6b846d..f3121b323 100644 --- a/crates/metal2vulkan-conformance/src/runtime_side.rs +++ b/crates/metal2vulkan-conformance/src/runtime_side.rs @@ -6636,7 +6636,7 @@ impl RuntimeSide<'_> { )) }; let mut descriptor = RenderPipelineDescriptor::new(stage(&spec.vertex)?); - descriptor.fragment = spec.fragment.as_ref().map(&stage).transpose()?; + descriptor.fragment = spec.fragment.as_ref().map(stage).transpose()?; let apart = pipeline_fields(spec)?; descriptor.color_attachments = apart.color_attachments; descriptor.depth_format = apart.depth_format; @@ -7600,7 +7600,7 @@ fn encode_pass(command_buffer: &CommandBuffer, pass: &RenderPass, pools: &Pools) offset, instance_stride, } => { - let factors = held.map(&buffer).transpose()?; + let factors = held.map(buffer).transpose()?; encoder .set_tessellation_factor_buffer(factors, *offset, *instance_stride) .map_err(Failure::from_error)?; @@ -7617,7 +7617,7 @@ fn encode_pass(command_buffer: &CommandBuffer, pass: &RenderPass, pools: &Pools) instances, base_instance, } => { - let indices = patch_indices.map(&buffer).transpose()?; + let indices = patch_indices.map(buffer).transpose()?; encoder .draw_patches( *control_points, @@ -7641,7 +7641,7 @@ fn encode_pass(command_buffer: &CommandBuffer, pass: &RenderPass, pools: &Pools) instances, base_instance, } => { - let indices = patch_indices.map(&buffer).transpose()?; + let indices = patch_indices.map(buffer).transpose()?; encoder .draw_indexed_patches( *control_points, diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index e86e5dcfb..ad1803c59 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -5352,8 +5352,8 @@ fn the_runtime_side_forwards_every_field_of_a_pipeline_spec() { let third = made.color_attachments[2].expect("color 2"); assert_eq!(third.pixel_format, PixelFormat::R16Snorm, "color 2 format"); assert_eq!(third.write_mask, ColorWriteMask::GREEN, "color 2 mask"); - for at in 3..8 { - assert!(made.color_attachments[at].is_none(), "color {at}"); + for (at, attachment) in made.color_attachments.iter().enumerate().take(8).skip(3) { + assert!(attachment.is_none(), "color {at}"); } let vertex = made.vertex_descriptor.expect("vertex_descriptor"); diff --git a/crates/metal2vulkan-conformance/src/times.rs b/crates/metal2vulkan-conformance/src/times.rs index 4ea4f95ca..ff50424e7 100644 --- a/crates/metal2vulkan-conformance/src/times.rs +++ b/crates/metal2vulkan-conformance/src/times.rs @@ -528,7 +528,7 @@ impl TimeVerdict { pub fn ratio(&self) -> Option { match self { TimeVerdict::Within { ours, metal } | TimeVerdict::Over { ours, metal } => { - (*metal > 0).then(|| *ours as f64 / *metal as f64) + (*metal > 0).then_some(*ours as f64 / *metal as f64) } TimeVerdict::Unmeasured { .. } => None, } @@ -596,7 +596,7 @@ impl Comparison { match self { Comparison::Judged { verdict } => verdict.ratio(), Comparison::Noticed { ours, metal, .. } => { - (*metal > 0).then(|| *ours as f64 / *metal as f64) + (*metal > 0).then_some(*ours as f64 / *metal as f64) } Comparison::Apart { .. } => None, } @@ -824,7 +824,7 @@ pub struct Paired { impl Paired { /// How many times our leg's total is Metal's, where Metal's is not zero. pub fn ratio(&self) -> Option { - (self.metal.wall > 0).then(|| self.ours.wall as f64 / self.metal.wall as f64) + (self.metal.wall > 0).then_some(self.ours.wall as f64 / self.metal.wall as f64) } } diff --git a/crates/metal2vulkan-runtime/Cargo.toml b/crates/metal2vulkan-runtime/Cargo.toml index 5c458a3e1..32f1d5955 100644 --- a/crates/metal2vulkan-runtime/Cargo.toml +++ b/crates/metal2vulkan-runtime/Cargo.toml @@ -8,7 +8,6 @@ authors.workspace = true description = "The Metal API on Vulkan: Metal's objects and calls run on a Vulkan device through ash" readme = "README.md" repository.workspace = true -homepage.workspace = true documentation = "https://docs.rs/metal2vulkan-runtime" keywords = ["metal", "vulkan", "gpu", "graphics"] categories = ["graphics", "api-bindings"] diff --git a/crates/metal2vulkan-runtime/src/blit_texture.rs b/crates/metal2vulkan-runtime/src/blit_texture.rs index 829bab89d..2146f243d 100644 --- a/crates/metal2vulkan-runtime/src/blit_texture.rs +++ b/crates/metal2vulkan-runtime/src/blit_texture.rs @@ -1466,55 +1466,54 @@ impl BlitCommandEncoder { let one_extent = in_images.iter().all(|copy| copy.src.size == copy.dst.size); let samples = source.record().samples; let mut bits = Vec::new(); - for to in [into] { - match Some(&from).filter(|from| from.copies_into(&to) && !overlap && one_extent) { - Some(from) => { - let mut regions: Vec = in_images + let to = into; + match Some(&from).filter(|from| from.copies_into(&to) && !overlap && one_extent) { + Some(from) => { + let mut regions: Vec = in_images + .iter() + .map(|copy| from.region(&to, copy)) + .collect(); + // Into a multisampled float image whose NaNs the device's copy converts: + // the regions at one origin in both images by the sample planes' copies, + // which move every sample's bits; the rest, or all where those cannot run, + // copied by the device and announced. + let device = self.core().device().clone(); + if nan_clear::converting_copy(&device, to.format, samples) { + let (exact, rest): (Vec<&ImageCopyRegion>, Vec<&ImageCopyRegion>) = regions .iter() - .map(|copy| from.region(&to, copy)) - .collect(); - // Into a multisampled float image whose NaNs the device's copy converts: - // the regions at one origin in both images by the sample planes' copies, - // which move every sample's bits; the rest, or all where those cannot run, - // copied by the device and announced. - let device = self.core().device().clone(); - if nan_clear::converting_copy(&device, to.format, samples) { - let (exact, rest): (Vec<&ImageCopyRegion>, Vec<&ImageCopyRegion>) = regions - .iter() - .partition(|copy| copy.src.origin == copy.dst.origin); - let pairs: Vec<(ImageRegion, ImageRegion)> = - exact.iter().map(|copy| (copy.src, copy.dst)).collect(); - if let Some(copy) = sample_planes::BitsCopy::plan( - self.core().command_buffer(), - source, - destination, - to.format, - &pairs, - samples, - )? { - bits.push(copy); - regions = rest.into_iter().copied().collect(); - } - if !regions.is_empty() { - nan_clear::degrade_converting_copy(&device, to.format, samples, || { - format!( - "a blit copy into a multisampled {:?} texture", - destination.pixel_format() - ) - }); - } + .partition(|copy| copy.src.origin == copy.dst.origin); + let pairs: Vec<(ImageRegion, ImageRegion)> = + exact.iter().map(|copy| (copy.src, copy.dst)).collect(); + if let Some(copy) = sample_planes::BitsCopy::plan( + self.core().command_buffer(), + source, + destination, + to.format, + &pairs, + samples, + )? { + bits.push(copy); + regions = rest.into_iter().copied().collect(); } if !regions.is_empty() { - let regions: Vec = regions.iter().map(image_copy).collect(); - direct.push((from.image, to.image, regions)); - // A depth that may hold a negative value or a NaN, copied as it is. - if to.aspect == ImageAspectFlags::DEPTH { - destination.degrade_signed_depth(call); - } + nan_clear::degrade_converting_copy(&device, to.format, samples, || { + format!( + "a blit copy into a multisampled {:?} texture", + destination.pixel_format() + ) + }); + } + } + if !regions.is_empty() { + let regions: Vec = regions.iter().map(image_copy).collect(); + direct.push((from.image, to.image, regions)); + // A depth that may hold a negative value or a NaN, copied as it is. + if to.aspect == ImageAspectFlags::DEPTH { + destination.degrade_signed_depth(call); } } - None => staged.push(to), } + None => staged.push(to), } for copy in &bits { self.command_in_reading( diff --git a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs index a718a181d..ee01cc5aa 100644 --- a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs +++ b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs @@ -1759,7 +1759,7 @@ impl Device { { use std::sync::atomic::Ordering; let failing = &shared.failing_host_imports; - if (failing.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |n| n.checked_sub(1))) + if (failing.try_update(Ordering::Relaxed, Ordering::Relaxed, |n| n.checked_sub(1))) .is_ok() { return Err(Error::OutOfMemory(MemoryKind::Device)); diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 457dc5517..03048cddd 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -416,8 +416,8 @@ fn into_parts( segment.executions_at += base; if segment.host { let before = segment.at - taken; - parts.push((raws.by_ref().take(before).collect::>(), current)); - current = Vec::new(); + let finished = std::mem::take(&mut current); + parts.push((raws.by_ref().take(before).collect::>(), finished)); taken = segment.at; } segment.at -= taken; diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index 3c15db907..99357afb0 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -22,6 +22,11 @@ // Every public item says what it is and its Metal counterpart: a new undocumented one fails the // warnings-denied gates. #![warn(missing_docs)] +// The compiler's proofs of `Send` and `Sync` in this crate (`render/deferral.rs`) walk a render +// encoder's lowering through the standard library's containers, which take more levels per +// container than they did: past the default limit of 128 (`recursion_depth_exceeding_limit`). A +// program's crate keeps the default (`tests/consumer_auto_traits.rs`). +#![recursion_limit = "256"] mod address; mod address_map; diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 313f1d934..3f97a2e21 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -430,8 +430,8 @@ mod vertex_strides; #[cfg(all(test, debug_assertions, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) use bound::dynamic_compares; use bound::{Bound, EqualShapes, Now, Recorded}; -use deferral::Logged; pub(crate) use deferral::{lowering, DeferredEncoders, EndInFlight}; +use deferral::{Logged, OwnLowering}; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) use deferral::{BATCH_CALLS, HANDED_BATCHES}; pub(crate) use draw_again::KeptStorage; @@ -1379,7 +1379,7 @@ pub struct RenderCommandEncoder { /// (`RenderLoweringPolicy::AtCall`): no slot, no lock (`render/deferral.rs`). Boxed where /// it is made ([`RenderLowering::assemble`]), so neither the encoder's return nor a caller's /// move of it copies the lowering's state, thousands of bytes. - own: Option>, + own: Option, /// Else its slot of the device's, which holds its lowering, its checks at the call and its /// calls not yet lowered. logged: Option, diff --git a/crates/metal2vulkan-runtime/src/render/deferral.rs b/crates/metal2vulkan-runtime/src/render/deferral.rs index 90023fbc5..5c3a6a4b1 100644 --- a/crates/metal2vulkan-runtime/src/render/deferral.rs +++ b/crates/metal2vulkan-runtime/src/render/deferral.rs @@ -197,6 +197,37 @@ const _: () = { sent::(); }; +/// An encoder's own lowering (`RenderLoweringPolicy::AtCall`), boxed where it is made +/// ([`RenderLowering::assemble`]). +pub(super) struct OwnLowering(Box); + +// SAFETY: an `OwnLowering` is `Send` exactly when `RenderLowering` is, its one field being a box of +// one; the constant below makes the compiler prove that. Written out, as `LoweringSlot`'s are, the +// impl ends a program's crate's walk of an encoder's fields there: the walk from a +// `RenderCommandEncoder` through its own lowering ran past rustc's default recursion limit +// (`tests/consumer_auto_traits.rs`). +unsafe impl Send for OwnLowering {} + +// The compiler's proof of what `OwnLowering`'s `Send` impl rests on. +const _: () = { + const fn sent() {} + sent::(); +}; + +impl std::ops::Deref for OwnLowering { + type Target = RenderLowering; + + fn deref(&self) -> &RenderLowering { + &self.0 + } +} + +impl std::ops::DerefMut for OwnLowering { + fn deref_mut(&mut self) -> &mut RenderLowering { + &mut self.0 + } +} + /// A slot's lowering, and whether it refused a call. struct Lowerer { /// Its encoder's lowering: `None` once the encoder ended, and in a slot not taken. @@ -654,7 +685,7 @@ impl RenderCommandEncoder { let logs = device.compile_device().policy().render_lowering == RenderLoweringPolicy::Worker && lowering.grouped.is_none(); let (own, logged) = match logs { - false => (Some(lowering), None), + false => (Some(OwnLowering(lowering)), None), true => { let device = device.clone(); let command_buffer = lowering.core.command_buffer().downgrade(); @@ -845,7 +876,7 @@ impl RenderCommandEncoder { /// the end of an encoder that logged its calls name it as `endEncoding`, after its calls. pub(super) fn end(self) -> Result<(), Error> { let logged = match (self.own, self.logged) { - (Some(lowering), _) => return lowering.end_encoding(), + (Some(lowering), _) => return lowering.0.end_encoding(), (None, Some(logged)) => logged, (None, None) => return Err(internal("an encoder without its lowering")), }; diff --git a/crates/metal2vulkan-runtime/src/tests/exit_guard.rs b/crates/metal2vulkan-runtime/src/tests/exit_guard.rs index 68a62f98f..b7fc96355 100644 --- a/crates/metal2vulkan-runtime/src/tests/exit_guard.rs +++ b/crates/metal2vulkan-runtime/src/tests/exit_guard.rs @@ -1133,7 +1133,7 @@ fn the_threads_that_take_command_buffers_to_their_handlers_run_at_the_user_inter reaper.start().unwrap().reap(Box::new(Reaped(dropped))); let reaped = drops.recv_timeout(WAIT).unwrap(); reaper.stop(); - let plain = exit_guard::spawn(std::thread::Builder::new(), || qos_class_self()) + let plain = exit_guard::spawn(std::thread::Builder::new(), qos_class_self) .unwrap() .join() .unwrap(); diff --git a/crates/metal2vulkan-runtime/src/tests/image_plan.rs b/crates/metal2vulkan-runtime/src/tests/image_plan.rs index be9dcb132..2c165cba1 100644 --- a/crates/metal2vulkan-runtime/src/tests/image_plan.rs +++ b/crates/metal2vulkan-runtime/src/tests/image_plan.rs @@ -201,7 +201,7 @@ fn check_plan( // Or, with extended usage, through the view of the format's word. let word = WordAttachment::of(pf, profile).map(|w| w.word_format()); assert!( - supports(FormatUsage::ColorAttachment) || (extended && word.is_some_and(&viewable)), + supports(FormatUsage::ColorAttachment) || (extended && word.is_some_and(viewable)), "{what}" ); } diff --git a/crates/metal2vulkan-validation/src/companion/tests.rs b/crates/metal2vulkan-validation/src/companion/tests.rs index fc246ab4a..bc882c7b2 100644 --- a/crates/metal2vulkan-validation/src/companion/tests.rs +++ b/crates/metal2vulkan-validation/src/companion/tests.rs @@ -1009,11 +1009,10 @@ fn generated_companions_link_with_their_cases_in_the_engine() { &draws, "mesh_draws_fragment", ))); - for index in 0..2 { - descriptor.color_attachments[index] = - Some(metal2vulkan::pipeline::ColorAttachmentDescriptor::new( - metal2vulkan::metal::PixelFormat::RGBA32Uint, - )); + for slot in descriptor.color_attachments.iter_mut().take(2) { + *slot = Some(metal2vulkan::pipeline::ColorAttachmentDescriptor::new( + metal2vulkan::metal::PixelFormat::RGBA32Uint, + )); } let linked = device .compile_mesh_pipeline(&descriptor, &metal2vulkan::Budget::standard()) diff --git a/crates/metal2vulkan/Cargo.toml b/crates/metal2vulkan/Cargo.toml index 104bdcb1a..3bd91e142 100644 --- a/crates/metal2vulkan/Cargo.toml +++ b/crates/metal2vulkan/Cargo.toml @@ -9,7 +9,6 @@ description = "Translate Metal AIR / LLVM IR to Vulkan SPIR-V with a native Rust # The repository's README, at the root: `cargo package` puts it at the package's root. readme = "../../README.md" repository.workspace = true -homepage.workspace = true documentation = "https://docs.rs/metal2vulkan" keywords = ["metal", "air", "spir-v", "vulkan", "gpu"] categories = ["compilers", "graphics", "encoding"] diff --git a/crates/metal2vulkan/src/indirect_commands/tests/records.rs b/crates/metal2vulkan/src/indirect_commands/tests/records.rs index 43fee6396..667aa0059 100644 --- a/crates/metal2vulkan/src/indirect_commands/tests/records.rs +++ b/crates/metal2vulkan/src/indirect_commands/tests/records.rs @@ -860,11 +860,13 @@ fn a_field_written_alone_is_the_record_encoded_again() { } assert_eq!(view.buffer(stage, BINDING_COUNT), None); } - for index in 0..THREADGROUP_COUNT { - assert_eq!( - view.threadgroup_memory_length(index), - Some(record.threadgroup_memory_lengths[index]) - ); + for (index, &length) in record + .threadgroup_memory_lengths + .iter() + .enumerate() + .take(THREADGROUP_COUNT) + { + assert_eq!(view.threadgroup_memory_length(index), Some(length)); } assert_eq!(view.threadgroup_memory_length(THREADGROUP_COUNT), None); let field = draws.field(); diff --git a/crates/metal2vulkan/src/pipeline/link/tests/render.rs b/crates/metal2vulkan/src/pipeline/link/tests/render.rs index 2bad943b1..27f0f14cd 100644 --- a/crates/metal2vulkan/src/pipeline/link/tests/render.rs +++ b/crates/metal2vulkan/src/pipeline/link/tests/render.rs @@ -2887,8 +2887,8 @@ fn the_graphics_state_masks_the_colors_the_fragment_function_writes() { let p = profile("lavapipe"); let f4 = io_ty(IoNumeric::Float, 4); let mut r = RenderLinkInputs::new(); - for index in 0..4 { - r.color_attachments[index] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float)); + for slot in r.color_attachments.iter_mut().take(4) { + *slot = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float)); } let inputs = LinkInputs::Render(Box::new(r)); let va = artifact(iface(Stage::Vertex, vec![], vec![]), None); diff --git a/crates/metal2vulkan/src/tests/engine_cross_class.rs b/crates/metal2vulkan/src/tests/engine_cross_class.rs index b97b1aacc..550af27d1 100644 --- a/crates/metal2vulkan/src/tests/engine_cross_class.rs +++ b/crates/metal2vulkan/src/tests/engine_cross_class.rs @@ -1175,12 +1175,11 @@ fn integer_writes_into_narrow_floats_take_the_devices_conversion() { let img = images.into_iter().next().expect("image"); for n in 0..SIDE * SIDE { let at = img.index(0, 0, 0, [n % SIDE, n / SIDE, 0]).expect("texel"); - for c in 0..4 { + for (c, &stored) in img.texels[at].iter().enumerate().take(4) { assert_eq!( - img.texels[at][c], + stored, lane(n, c), - "{what}: texel {n} lane {c} stored {:#x}", - img.texels[at][c] + "{what}: texel {n} lane {c} stored {stored:#x}" ); } } diff --git a/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs b/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs index 7a87a6020..48154194c 100644 --- a/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs +++ b/crates/metal2vulkan/src/tests/engine_extended_range/samples.rs @@ -1512,15 +1512,13 @@ fn a_sampled_slot_joins_the_variant() { assert_eq!(named.variant, plan.variant, "{what} {name}"); } } - for (name, desc) in [("mixed", mixed)] { - match plain.plan(&dev, &sampled_state(pf, desc).shape()) { - Err(crate::error::BindError::Unsupported(u)) => assert_eq!( - u, - Unsupported::not_implemented(Feature::Format), - "{what} {name}" - ), - other => panic!("{what} {name}: {:?}", other.map(|_| ())), - } + match plain.plan(&dev, &sampled_state(pf, mixed).shape()) { + Err(crate::error::BindError::Unsupported(u)) => assert_eq!( + u, + Unsupported::not_implemented(Feature::Format), + "{what} mixed" + ), + other => panic!("{what} mixed: {:?}", other.map(|_| ())), } } } diff --git a/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs b/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs index ee18b9de7..5460bbf40 100644 --- a/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs +++ b/crates/metal2vulkan/src/tests/engine_fetch_generic_blend.rs @@ -134,8 +134,8 @@ fn attachments( let mut unwritten = ColorAttachmentDescriptor::new(PixelFormat::RGBA16Float); unwritten.write_mask = ColorWriteMask::NONE; let mut r = RenderLinkInputs::new(); - for c in 0..=color + 1 { - r.color_attachments[c] = Some(unwritten); + for slot in r.color_attachments.iter_mut().take(color + 2) { + *slot = Some(unwritten); } r.color_attachments[color] = Some(blended); r diff --git a/crates/metal2vulkan/src/tests/engine_mesh.rs b/crates/metal2vulkan/src/tests/engine_mesh.rs index 94ad2fe1e..187265384 100644 --- a/crates/metal2vulkan/src/tests/engine_mesh.rs +++ b/crates/metal2vulkan/src/tests/engine_mesh.rs @@ -920,8 +920,8 @@ fn without_the_extension_a_mesh_pipeline_draws_its_records() { let dev = device(&stem); let mut d = MeshPipelineDescriptor::new(stage(&draws, "mesh_draws_grid")); d.fragment = Some(stage(&draws, "mesh_draws_fragment")); - for i in 0..2 { - d.color_attachments[i] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + for slot in d.color_attachments.iter_mut().take(2) { + *slot = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); } let pipeline = dev .compile_mesh_pipeline(&d, &budget) @@ -1147,8 +1147,8 @@ fn object_records_draws(dev: &crate::device::Device, draws: &crate::library::Lib let mut d = MeshPipelineDescriptor::new(stage("mesh_draws_mesh")); d.object = Some(stage("mesh_draws_object")); d.fragment = Some(stage("mesh_draws_fragment")); - for i in 0..2 { - d.color_attachments[i] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + for slot in d.color_attachments.iter_mut().take(2) { + *slot = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); } let pipeline = dev .compile_mesh_pipeline(&d, &Budget::standard()) @@ -2019,8 +2019,8 @@ fn a_last_first_mesh_draw_reads_its_corners_from_the_last() { let dev = device(&stem); let mut d = MeshPipelineDescriptor::new(stage("mesh_draws_grid")); d.fragment = Some(stage("mesh_draws_fragment")); - for i in 0..2 { - d.color_attachments[i] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + for slot in d.color_attachments.iter_mut().take(2) { + *slot = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); } let base = dev .compile_mesh_pipeline(&d, &budget) diff --git a/crates/metal2vulkan/src/tests/engine_primitive_ids.rs b/crates/metal2vulkan/src/tests/engine_primitive_ids.rs index 7ee4659f5..5bf7e4cb5 100644 --- a/crates/metal2vulkan/src/tests/engine_primitive_ids.rs +++ b/crates/metal2vulkan/src/tests/engine_primitive_ids.rs @@ -83,8 +83,8 @@ fn pipeline( ) -> RenderPipelineDescriptor { let mut d = RenderPipelineDescriptor::new(StageSource::Function(function(bc, vertex))); d.fragment = fragment.map(|f| StageSource::Function(function(bc, f))); - for c in 0..colors { - d.color_attachments[c] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); + for slot in d.color_attachments.iter_mut().take(colors) { + *slot = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA32Uint)); } d } diff --git a/crates/metal2vulkan/src/tests/engine_pull_model.rs b/crates/metal2vulkan/src/tests/engine_pull_model.rs index b51929363..23eda5631 100644 --- a/crates/metal2vulkan/src/tests/engine_pull_model.rs +++ b/crates/metal2vulkan/src/tests/engine_pull_model.rs @@ -111,8 +111,8 @@ fn render( }; let mut d = RenderPipelineDescriptor::new(stage(VERTEX)); d.fragment = Some(stage(fragment)); - for i in 0..count { - d.color_attachments[i] = Some(ColorAttachmentDescriptor::new(format)); + for slot in d.color_attachments.iter_mut().take(count) { + *slot = Some(ColorAttachmentDescriptor::new(format)); } d.raster_sample_count = samples; d diff --git a/crates/metal2vulkan/tests/api_signatures.rs b/crates/metal2vulkan/tests/api_signatures.rs index d0a034b03..4cea5c20e 100644 --- a/crates/metal2vulkan/tests/api_signatures.rs +++ b/crates/metal2vulkan/tests/api_signatures.rs @@ -10,8 +10,8 @@ //! //! `scripts/api-signatures/signatures.py` derives the surface from the sources and //! `tests/api_signatures.tsv` is what it must derive. The derivation reads source text only: no -//! build, no toolchain, and no rustdoc, whose JSON surface is nightly-only while this workspace -//! is pinned to stable. So it gives the same answer under any feature set, and the run is seconds. +//! build, no toolchain, and no rustdoc, whose JSON surface is unstable and changes between +//! nightlies. So it gives the same answer under any feature set, and the run is seconds. //! //! A record is `kindkeysignature`. The kinds are the declaration itself (`struct`, //! `enum`, `fn`, `trait`, `type`, `const`, `static`), a public field or an enum variant (`field`, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index cb5e9b595..954e876b1 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,10 +1,13 @@ # The toolchain every build of this tree uses. It travels with the tree, so a worktree, a snapshot -# or a fresh clone cannot silently take whatever `stable` happens to be on the machine — which is -# how three lints that exist only in a later Rust were once reported as a broken `development`. +# or a fresh clone cannot silently take whatever toolchain happens to be the machine's default — +# which is how three lints that exist only in a later Rust were once reported as a broken +# `development`. # -# The channel is the MSRV the published crates promise in `rust-version`, so an ordinary build is -# what checks that promise rather than a separate job nobody runs. Raising it is a deliberate, -# fleet-wide step: it is a consumer-facing contract, not a local convenience. +# A dated nightly, for rustc's parallel front end (`-Zthreads`, set in `.cargo/config.toml`) and +# Cargo's profile rustflags. The date is fixed so every machine runs one rustc, clippy and rustfmt; +# moving it is a deliberate, fleet-wide step. The published crates still promise the stable +# `rust-version` in their manifests (1.98), which this build no longer checks by itself: clippy's +# `incompatible_msrv` catches a standard-library item newer than it, not a language feature. [toolchain] -channel = "1.98.1" +channel = "nightly-2026-11-03" components = ["clippy", "rustfmt"] diff --git a/scripts/api-signatures/signatures.py b/scripts/api-signatures/signatures.py index 87865b8b2..7f28bb196 100644 --- a/scripts/api-signatures/signatures.py +++ b/scripts/api-signatures/signatures.py @@ -11,8 +11,8 @@ blessing it asserts. Every verb takes `--root DIR` (the repository, the default being this script's own two directories up) and `--table FILE`. -It reads source text only: no build, no toolchain, no rustdoc, whose JSON surface is nightly-only -while this fleet is pinned to stable. So it is the same five seconds on any checkout, under any +It reads source text only: no build, no toolchain, no rustdoc, whose JSON surface is unstable and +changes between nightlies. So it is the same five seconds on any checkout, under any feature set: a `#[cfg]`-gated item is read as present, with its gate kept in the signature. The surface is the set of names a consumer may write -- the module roots the crates export, their diff --git a/scripts/device-lane/device-lane b/scripts/device-lane/device-lane index d97e0c509..2cc77ef25 100755 --- a/scripts/device-lane/device-lane +++ b/scripts/device-lane/device-lane @@ -118,7 +118,6 @@ nextest_list() { shift 3 ( cd "$repo" \ && CARGO_TARGET_DIR="$target" \ - CARGO_INCREMENTAL=0 \ RUSTFLAGS="$flags" \ cargo nextest list --workspace --all-features $profile_args \ --run-ignored all --message-format json --list-type full "$@" ) \ @@ -193,7 +192,6 @@ while IFS="$(printf '\t')" read -r name binary terms; do status=0 ( cd "$repo" \ && CARGO_TARGET_DIR="$cfg_target" \ - CARGO_INCREMENTAL=0 \ RUSTFLAGS="--cfg m2v_gpu" \ cargo nextest run --no-run --workspace --all-features $profile_args \ --hide-progress-bar -E "$expression" ) >> "$log" 2>&1 || status=$? @@ -206,7 +204,6 @@ while IFS="$(printf '\t')" read -r name binary terms; do started=$(date +%s) ( cd "$repo" \ && CARGO_TARGET_DIR="$cfg_target" \ - CARGO_INCREMENTAL=0 \ RUSTFLAGS="--cfg m2v_gpu" \ ${wrap_words:+$wrap_words} \ cargo nextest run --workspace --all-features $profile_args \ diff --git a/scripts/drm-shim.Dockerfile b/scripts/drm-shim.Dockerfile index 4336ec9b4..aee78a9ec 100644 --- a/scripts/drm-shim.Dockerfile +++ b/scripts/drm-shim.Dockerfile @@ -113,7 +113,7 @@ FROM ubuntu:26.04@sha256:da6fc2be547864451aa253836dd926da33623312df4a9a243e35dc8 # First, so nothing below runs (or compiles) while the mesa stage builds. COPY --from=mesa /opt/mesa /opt/mesa -ARG RUST_VERSION=1.98.1 +ARG RUST_VERSION=nightly-2026-11-03 ARG NEXTEST_VERSION=0.9.140 ENV DEBIAN_FRONTEND=noninteractive \ diff --git a/scripts/linux-gate.Dockerfile b/scripts/linux-gate.Dockerfile index 11ac40a85..63ccb8ff4 100644 --- a/scripts/linux-gate.Dockerfile +++ b/scripts/linux-gate.Dockerfile @@ -8,8 +8,8 @@ # already ships and the build needs (a C toolchain for linking and bundled SQLite, clang for the # tests that probe it), `vulkan-tools` (vulkaninfo), and what the two source builds below need # (git, cmake, ninja). -# - Rust: `dtolnay/rust-toolchain@stable` with rustfmt + clippy in CI; pinned here to the stable -# release current when this recipe was written. Bump RUST_VERSION when CI's stable moves. +# - Rust: the dated nightly `rust-toolchain.toml` names, with rustfmt + clippy, as in CI. Keep +# RUST_VERSION equal to that file's channel. # - cargo-nextest: `taiki-e/install-action` installs the latest in CI; pinned here by # NEXTEST_VERSION and built from crates.io with its lockfile. # - SwiftShader (Google's CPU Vulkan ICD; Ubuntu does not package it): built from source at @@ -30,7 +30,7 @@ # Changing this file changes the image tag `scripts/linux-gate` computes, so the next run rebuilds. FROM ubuntu:26.04@sha256:da6fc2be547864451aa253836dd926da33623312df4a9a243e35dc877c378a78 -ARG RUST_VERSION=1.98.1 +ARG RUST_VERSION=nightly-2026-11-03 ARG NEXTEST_VERSION=0.9.140 ENV DEBIAN_FRONTEND=noninteractive \ diff --git a/scripts/rustc-wrapper b/scripts/rustc-wrapper new file mode 100755 index 000000000..8095f347f --- /dev/null +++ b/scripts/rustc-wrapper @@ -0,0 +1,9 @@ +#!/bin/sh +# Cargo's rustc wrapper for this workspace (`.cargo/config.toml`): Cargo runs it as +# `rustc-wrapper RUSTC ARGS...`. It hands the compile to kache, a local compiler cache, where +# kache is on PATH and the build is not CI's; anywhere else it runs the compiler itself. kache is a +# tool on PATH, never a dependency, and its store stays on the machine. +if [ -z "${CI:-}" ] && command -v kache >/dev/null 2>&1; then + exec kache "$@" +fi +exec "$@"