From de5a77cc064100352081ca016ccd34ca1d46ccf9 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 8 Nov 2026 21:49:25 -0800 Subject: [PATCH] Wide lines: no device's own lines are taken as Metal's parallelogram RADV fails wide_lines_draw_metal_s_parallelograms and its exact-answers twin at the lane's "scattered lines width 2.5, fragments" map, 628 pixels where Metal's has 622: on the Radeon RX 7900 XTX (homelab-gem10-1, m3-max-10724) and on the 780M (homelab-um870-1, its only GPU, m3-max-10773), at this branch's base and at development alike. The runtime took RADV's lines as Metal's there, unannounced: RADV is the one driver of the committed profiles stating non-strict parallelogram lines (strictLines unset, nonStrictWideLinesUseParallelogram set), and 2.5 lies on its 1/8 granularity above 1, so the route was the device's lines under both policies. Cause, measured: a probe on the XTX (m3-max-10800, a scratch branch, never merged) drew each of the 48 scattered lines alone and printed its pixels. 21 of them lie a row or a column off Metal's parallelogram at an end: one more past the first vertex, one fewer before the last. A model of Metal's rule (endpoints on the 1/256 subpixel grid, the parallelogram whose minor-axis edges are w' long through them, the ends not extended, pixel centres by the top-left rule) reproduces Metal's map pixel for pixel; the XTX's ends fit no constant shift of it. Vulkan leaves where a non-strict wide line's ends fall to the implementation, and no driver is measured to place them as Metal does. Change: the device route has no exact form any more (render/line_width.rs route). Every draw the device's own lines take is announced device-wide-lines, the notice naming "parallelograms, whose ends and endpoints' snap the driver places as it draws them" where the width is on the grid above 1, and under WideLinePolicy::Exact (exact_answers) the band draws it wherever the device has tessellationShader. On RADV, widths above 1 on the 1/8 grid move from silent device lines to announced device lines under the default, and to the band under exact answers. No other profile changes route: lavapipe and NVIDIA (strict) and ANV (not stated as parallelograms) were announced already. Tests: the runtime's route table reads A or B where it read E for the three RADV profiles (Cell:: Exact removed). The validation lane drops LineFacts::draws_as_metal, and asserts per case that the draws of the device's own lines announce device-wide-lines one for one, which fails without this change on RADV (width 2.5 drawn by the device's lines with no notice); the edges test asserts the notice at each device-line draw. Docs: render/line_width.rs's module docs, DeviceWideLines' rustdoc and docs/API.md's entry and policy text, WideLinePolicy's and DevicePolicy::wide_lines' docs, the runtime README's route table (its "exactly Metal's" row folded into the announced one), docs/FAST-PATHS.md's row (no device's lines are taken as Metal's; the cost adds a row or a column at an end), docs/RUNTIME-PORTING.md's SetLineWidth row. The announced cost string is unchanged. Notices: one device-wide-lines per device (once per kind, unless announce_each names it) on a RADV run that draws wide lines only at widths above 1 on the 1/8 grid, where it announced nothing; a run that already drew a width below 1 or off the grid announced it already. Needs the runtime-sources pin and a RUNTIME_VERSION (the orchestrator's numbers). Verified: cargo fmt. The XTX, 780M, lavapipe and M3 runs follow through potluck. (cherry picked from commit be88ae03f199d5a485abcc546d0d52b181290e7b) --- crates/metal2vulkan-runtime/README.md | 3 +- .../metal2vulkan-runtime/src/degradation.rs | 13 +- .../src/render/line_width.rs | 68 +++++----- .../src/render/line_width/tests.rs | 37 +++-- .../src/runtime_lane/line_widths.rs | 128 ++++++++---------- crates/metal2vulkan/src/device/policy.rs | 34 ++--- crates/metal2vulkan/src/tests/fast_paths.rs | 2 +- docs/API.md | 35 ++--- docs/FAST-PATHS.md | 2 +- docs/RUNTIME-PORTING.md | 2 +- 10 files changed, 153 insertions(+), 171 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 8a9d24ac6..7c2f38279 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -768,8 +768,7 @@ draw whose vertices or indices complete no primitive of its type draws nothing, | Device | Route | |---|---| -| `wideLines`, non-strict, parallelogram wide lines, `w' > 1` on the granularity | Its own lines, exactly Metal's | -| `wideLines`, its lines otherwise (strict, not stated as parallelograms, `w' < 1`, off the granularity) | Its own lines, announced `device-wide-lines` (`WideLinePolicy::Device`, the default); under `WideLinePolicy::Exact` (`DevicePolicy::exact_answers()`) the band | +| `wideLines`, `w'` in `lineWidthRange` and above 0 | Its own lines, announced `device-wide-lines` (`WideLinePolicy::Device`, the default): no device's are taken as Metal's, a driver's parallelograms included, whose ends the driver places; under `WideLinePolicy::Exact` (`DevicePolicy::exact_answers()`) the band | | No `wideLines` (MoltenVK), `w'` outside `lineWidthRange`, or `w' = 0` | The band | | What neither draws | Its own lines at the width nearest Metal's they draw (clamped into `lineWidthRange` and put on the nearer step of `lineWidthGranularity`'s grid from its bottom, never 0; 1 without `wideLines`), announced `lines-at-nearest-width` | diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index ec3ebf306..a49f2f920 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2268,12 +2268,15 @@ degradations! { or a box"; /// A draw of lines at a width other than 1 (Apple's `setLineWidth:`), or of a triangle's /// edges in fill mode `Lines` or of a mesh draw, drawn by the device's own lines - /// (`render/line_width.rs`) where they are not Metal's parallelogram: strict lines (the - /// rectangle the width spans across the segment, square ends), lines Vulkan does not state - /// as parallelograms (`nonStrictWideLinesUseParallelogram` unset, or a width below 1), or a - /// width off the device's `lineWidthGranularity`, which rounds it. Under + /// (`render/line_width.rs`), which no device's are taken to draw as Metal's + /// parallelogram: strict lines (the rectangle the width spans across the segment, square + /// ends), lines Vulkan does not state as parallelograms + /// (`nonStrictWideLinesUseParallelogram` unset, or a width below 1), a width off the + /// device's `lineWidthGranularity`, which rounds it, and a driver's parallelograms, whose + /// ends and endpoints' snap are the driver's (RADV on the Radeon RX 7900 XTX draws 21 of + /// 48 scattered lines at width 2.5 a row or a column off Metal's at an end). Under /// `WideLinePolicy::Exact` a draw of lines or of a triangle's edges takes the band variant - /// there instead, on a device with `tessellationShader`. + /// instead, on a device with `tessellationShader`. DeviceWideLines = "device-wide-lines", Precision, "the lines can cover pixels Metal's parallelogram does not, and miss others, at each \ end and along each edge"; diff --git a/crates/metal2vulkan-runtime/src/render/line_width.rs b/crates/metal2vulkan-runtime/src/render/line_width.rs index 8b1c4f143..9c088918d 100644 --- a/crates/metal2vulkan-runtime/src/render/line_width.rs +++ b/crates/metal2vulkan-runtime/src/render/line_width.rs @@ -47,13 +47,17 @@ //! Metal draws as nothing ([`draws_primitives`]); an indirect draw's count is the GPU's, so it //! takes its route as any other. //! - **Device**: the device's own lines at `w'` (`lineWidth`), where it enables `wideLines` and -//! `w'` lies in its `lineWidthRange` and above 0. Exact where they are Metal's parallelogram: -//! `strictLines` unset, `nonStrictWideLinesUseParallelogram` set (Vulkan states the shape only -//! for widths above 1), and `w'` on `lineWidthGranularity` from the range's bottom. Elsewhere -//! the device's line differs (a strict device's rectangle covers the pixels within half the -//! width of the segment across it, square ends; a Bresenham one's columns; a width rounded to -//! the granularity): announced (`Degradation::DeviceWideLines`), or under -//! `WideLinePolicy::Exact` the band below, where it can draw. +//! `w'` lies in its `lineWidthRange` and above 0, announced as the device's +//! (`Degradation::DeviceWideLines`), or under `WideLinePolicy::Exact` the band below, where it +//! can draw. They are not taken as Metal's anywhere: a strict device's rectangle covers the +//! pixels within half the width of the segment across it, square ends; a Bresenham one's columns; +//! a width off `lineWidthGranularity`'s grid is rounded to it; and a driver's non-strict +//! parallelogram (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set), Metal's shape +//! above a width of 1, ends where the driver places it and snaps its endpoints as the driver +//! rounds, which no driver is measured to do as Metal does. RADV, the one driver of the committed +//! profiles that states the parallelogram, draws 21 of the lane's 48 scattered lines at width 2.5 +//! on the Radeon RX 7900 XTX a row or a column off Metal's at an end +//! (`runtime_lane::line_widths`): one more past the first vertex, one fewer before the last. //! - **Band**: the pipeline's band variant (`VariantKey::line_band`, the translator's //! `pipeline::link::band`), through a tessellation control and evaluation stage //! (`tessellationShader`): two triangles per line over Metal's parallelogram, and per triangle in @@ -152,9 +156,9 @@ impl LineWidth { pub(super) enum LineRoute { /// As every line the runtime draws: Metal's width 1, or a draw of no lines. Plain, - /// The device's own lines `width` pixels wide (`lineWidth`), Metal's width, which differ from - /// Metal's parallelogram where `differs` (announced). - Device { width: f32, differs: bool }, + /// The device's own lines `width` pixels wide (`lineWidth`), Metal's width, the device's + /// shape rather than Metal's parallelogram (announced). + Device { width: f32 }, /// The pipeline's band variant of `primitive`, `half` pixels to each side of each segment. Band { half: f32, primitive: BandPrimitive }, /// The device's own lines `width` pixels wide, the width nearest Metal's they draw, where @@ -193,7 +197,7 @@ impl LineRoute { pub(super) fn fix(self, fixed: &mut FixedState) { match self { LineRoute::Plain => {} - LineRoute::Device { width, .. } | LineRoute::Nearest { width, .. } => { + LineRoute::Device { width } | LineRoute::Nearest { width, .. } => { fixed.line_width = width.to_bits() } LineRoute::Band { primitive, .. } => { @@ -361,27 +365,13 @@ fn route( return nearest(Unrouted::Executed); } let drawable = wide_lines && w > 0.0 && (low..=high).contains(&w); - // On the granularity's grid from the range's bottom: the widths the device draws without - // rounding. - let on_grid = granularity > 0.0 && { - let steps = (w - low) / granularity; - steps == steps.round() - }; - let exact = drawable - && !limits.strict_lines - && limits.non_strict_wide_lines_use_parallelogram - && w > 1.0 - && on_grid; let tessellates = enabled.features.contains(&VkFeature::TessellationShader); // Where the band can draw the draw's lines or edges. let band = drawn .banded() .filter(|_| tessellates && !amplifies && !refused); - if exact || (drawable && (policy == WideLinePolicy::Device || band.is_none())) { - return LineRoute::Device { - width: w, - differs: !exact, - }; + if drawable && (policy == WideLinePolicy::Device || band.is_none()) { + return LineRoute::Device { width: w }; } let Some(primitive) = band else { return nearest(match drawn.banded() { @@ -415,10 +405,9 @@ fn drawn_width(w: f32, [low, high]: [f32; 2], granularity: f32) -> f32 { impl ShapeInputs<'_> { /// The route `call`'s draw of `pipeline` as `assembly` draws its lines by at the encoder's /// width (the module docs), of a draw that may draw a primitive where `primitives` - /// ([`draws_primitives`]); announcing a device line that differs from Metal's, one at the - /// nearest width, the device's lines at width 1 on a driver whose ties are not measured to be - /// Metal's, and the band on a driver whose subpixel snap is not measured to be Metal's, where - /// `announce`. + /// ([`draws_primitives`]); announcing the device's own lines, lines at the nearest width, the + /// device's lines at width 1 on a driver whose ties are not measured to be Metal's, and the + /// band on a driver whose subpixel snap is not measured to be Metal's, where `announce`. pub(super) fn line_route( &self, call: &'static str, @@ -456,7 +445,7 @@ impl ShapeInputs<'_> { route => route, }; match route { - LineRoute::Device { differs: true, .. } if announce => { + LineRoute::Device { .. } if announce => { announce_device_lines(self.device, call, width.pixels()); } LineRoute::Nearest { width: drawn, why } if announce => { @@ -511,17 +500,26 @@ fn announce_subpixel_snap(device: &crate::Device, call: &'static str) { }); } -/// Announce `call`'s draw of lines `w` pixels wide by the device's own lines, which differ from -/// Metal's parallelogram there (the module docs). +/// Announce `call`'s draw of lines `w` pixels wide by the device's own lines, the device's shape +/// rather than Metal's parallelogram (the module docs). fn announce_device_lines(device: &crate::Device, call: &'static str, w: f32) { let limits = device.compile_device().profile().limits(); let [low, high] = limits.line_width_range_bits.map(f32::from_bits); let granularity = f32::from_bits(limits.line_width_granularity_bits); let parallelogram = limits.non_strict_wide_lines_use_parallelogram; + // On the granularity's grid from the range's bottom: the widths the device draws without + // rounding. + let on_grid = granularity > 0.0 && { + let steps = (w - low) / granularity; + steps == steps.round() + }; let shape = match (limits.strict_lines, parallelogram) { (true, _) => "strict lines, the rectangle the width spans across the segment", (false, true) if w < 1.0 => "lines, whose shape below a width of 1 Vulkan leaves to it", - (false, true) => "lines, which round the width to their granularity", + (false, true) if !on_grid => "lines, which round the width to their granularity", + (false, true) => { + "parallelograms, whose ends and endpoints' snap the driver places as it draws them" + } (false, false) => "lines, which Vulkan does not state as parallelograms", }; device.degrade(Degradation::DeviceWideLines, || { diff --git a/crates/metal2vulkan-runtime/src/render/line_width/tests.rs b/crates/metal2vulkan-runtime/src/render/line_width/tests.rs index f33168f26..7c6b47419 100644 --- a/crates/metal2vulkan-runtime/src/render/line_width/tests.rs +++ b/crates/metal2vulkan-runtime/src/render/line_width/tests.rs @@ -16,8 +16,6 @@ use metal2vulkan::vk; enum Cell { /// `P`: as every line, at width 1. Plain, - /// `E`: the device's own lines, exactly Metal's parallelogram. - Exact, /// `A`: the device's own lines, announced as differing. Announced, /// `B`: the band. @@ -33,7 +31,6 @@ impl Cell { row.split_whitespace() .map(|code| match code { "P" => Cell::Plain, - "E" => Cell::Exact, "A" => Cell::Announced, "B" => Cell::Band, "T" => Cell::Nearest(Unrouted::Untessellated), @@ -108,12 +105,9 @@ fn cell( refused, ) { LineRoute::Plain => Cell::Plain, - LineRoute::Device { width, differs } => { + LineRoute::Device { width } => { assert_eq!(width, w); - match differs { - false => Cell::Exact, - true => Cell::Announced, - } + Cell::Announced } LineRoute::Band { half, primitive } => { assert_eq!(half, if w == 0.0 { 1.0 / 32.0 } else { w / 2.0 }); @@ -148,25 +142,26 @@ fn each_device_routes_each_width_as_its_lines_allow() { // (profile, widths, lines and edges Device, lines and edges Exact, mesh lines and patch // edges, amplified lines and edges) let table: [(&str, &[f32], [&str; 4]); 11] = [ - // wideLines, [0, 8] by 1/8, non-strict parallelograms, tessellation. + // wideLines, [0, 8] by 1/8, non-strict parallelograms (not taken as Metal's), + // tessellation. ( "amd-780m-radv", &[0.0, 0.5, 1.0, 1.5, 2.125, 2.0625, 8.0, 8.0625, 16.0], [ - "B A P E E A E B B", - "B B P E E B E B B", - "U A P E E A E U U", - "V A P E E A E V V", + "B A P A A A A B B", + "B B P B B B B B B", + "U A P A A A A U U", + "V A P A A A A V V", ], ), ( "amd-rdna3-radv", &[0.0, 0.5, 1.0, 1.5, 2.125, 2.0625, 8.0, 8.0625, 16.0], [ - "B A P E E A E B B", - "B B P E E B E B B", - "U A P E E A E U U", - "V A P E E A E V V", + "B A P A A A A B B", + "B B P B B B B B B", + "U A P A A A A U U", + "V A P A A A A V V", ], ), // wideLines, [0, 8] by 1/128, not stated as parallelograms. @@ -223,10 +218,10 @@ fn each_device_routes_each_width_as_its_lines_allow() { "amd-780m-hawkpoint-radv", &[0.0, 0.5, 1.0, 1.5, 2.125, 2.0625, 8.0, 8.0625, 16.0], [ - "B A P E E A E B B", - "B B P E E B E B B", - "U A P E E A E U U", - "V A P E E A E V V", + "B A P A A A A B B", + "B B P B B B B B B", + "U A P A A A A U U", + "V A P A A A A V V", ], ), ]; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/line_widths.rs b/crates/metal2vulkan-validation/src/runtime_lane/line_widths.rs index 1cbb41541..a72b13630 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/line_widths.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/line_widths.rs @@ -26,24 +26,24 @@ //! The work counts show which route each draw took (`WorkCounts::line_band_draws`, //! `device_wide_line_draws`, `nearest_width_line_draws`): every draw at a width other than 1 takes //! one of the three, and on a device without `wideLines` that tessellates, a line and a triangle's -//! edges take the band. A draw the device's own lines draw otherwise than Metal is announced -//! (`device-wide-lines`, at every occurrence here) and left unchecked; under -//! `DevicePolicy::exact_answers()` no draw is, where the device has `tessellationShader`. The band -//! of a triangle's edges under a depth bias that can bias them otherwise than Metal is announced -//! (`wide-edge-depth-bias`) and left unchecked. What neither the device's lines nor the band draw -//! (lines and edges without `tessellationShader` the device's lines do not draw, and those of a -//! pipeline state whose band the translator refuses) runs the device's lines at the nearest width -//! they draw, announced (`lines-at-nearest-width`) and counted at each draw; where that width is 1 -//! it is compared with Metal's map of the same geometry at width 1. A draw the device's lines draw -//! at width 1 on a driver not measured to break a tie at a vertex two pixels' diamonds share as -//! Metal does (`DriverFact::LineTiesAreMetals`: the RTX 5080 Laptop GPU draws the lane's strip's -//! diagonal a row higher, and lavapipe, Mesa 26.2.4, leaves out its first pixel) is announced -//! (`device-line-ties`) and left unchecked, and only there. A draw the band draws on a driver not -//! measured to snap a vertex half a step off its 1/256-pixel subpixel grid as Metal snaps a line's -//! endpoint (`DriverFact::SubpixelSnapIsMetals`: the RTX 5080 Laptop GPU and lavapipe draw the -//! lines offset from rows of centres by `(r - 32) / 512` a row lower) is announced -//! (`device-subpixel-snap`) and, where a vertex lies half a step off the grid, left unchecked; -//! every other such case is compared as any other. +//! edges take the band. A draw the device's own lines draw is announced (`device-wide-lines`, at +//! every occurrence here) and left unchecked, as the runtime takes no device's lines as Metal's; +//! under `DevicePolicy::exact_answers()` no draw is, where the device has `tessellationShader`. The +//! band of a triangle's edges under a depth bias that can bias them otherwise than Metal is +//! announced (`wide-edge-depth-bias`) and left unchecked. What neither the device's lines nor the +//! band draw (lines and edges without `tessellationShader` the device's lines do not draw, and +//! those of a pipeline state whose band the translator refuses) runs the device's lines at the +//! nearest width they draw, announced (`lines-at-nearest-width`) and counted at each draw; where +//! that width is 1 it is compared with Metal's map of the same geometry at width 1. A draw the +//! device's lines draw at width 1 on a driver not measured to break a tie at a vertex two pixels' +//! diamonds share as Metal does (`DriverFact::LineTiesAreMetals`: the RTX 5080 Laptop GPU draws the +//! lane's strip's diagonal a row higher, and lavapipe, Mesa 26.2.4, leaves out its first pixel) is +//! announced (`device-line-ties`) and left unchecked, and only there. A draw the band draws on a +//! driver not measured to snap a vertex half a step off its 1/256-pixel subpixel grid as Metal +//! snaps a line's endpoint (`DriverFact::SubpixelSnapIsMetals`: the RTX 5080 Laptop GPU and +//! lavapipe draw the lines offset from rows of centres by `(r - 32) / 512` a row lower) is +//! announced (`device-subpixel-snap`) and, where a vertex lies half a step off the grid, left +//! unchecked; every other such case is compared as any other. //! Nothing is refused. A draw of //! no complete primitive (the consumer's triangles of 1 and 2 vertices, by vertices and by //! indices, under the last provoking vertex) draws nothing and takes no route. Not covered: @@ -72,9 +72,9 @@ use std::collections::BTreeMap; const MEASURED: &str = include_str!("line_widths_m3_max.txt"); /// The kinds the lane's runs take: a draw of lines at a width other than 1 that the device's own -/// lines draw otherwise than Metal's parallelogram, one they draw at the nearest width they draw -/// where neither they nor the band draw Metal's, and a band of a triangle's edges under a depth -/// bias the device computes otherwise than Metal. +/// lines draw, one they draw at the nearest width they draw where neither they nor the band draw +/// Metal's, and a band of a triangle's edges under a depth bias the device computes otherwise than +/// Metal. pub(super) const WIDE_LINES: [Degradation; 3] = [ Degradation::DeviceWideLines, Degradation::LinesAtNearestWidth, @@ -199,17 +199,15 @@ fn metal_width(width: f32) -> f32 { } /// What the device's lines draw: whether it enables `wideLines` and `tessellationShader`, its -/// `lineWidthRange` and `lineWidthGranularity`, whether its lines are strict and its non-strict -/// wide lines parallelograms, and whether its policy draws a width its lines draw otherwise than -/// Metal by the band (`WideLinePolicy::Exact`, the lane's devices' `exact_answers`). +/// `lineWidthRange` and `lineWidthGranularity`, and whether its policy draws a width its lines +/// draw by the band (`WideLinePolicy::Exact`, the lane's devices' `exact_answers`): the runtime +/// takes no device's lines as Metal's (`render/line_width.rs`). #[derive(Clone, Copy, Debug)] struct LineFacts { wide_lines: bool, tessellates: bool, range: [f32; 2], granularity: f32, - strict: bool, - parallelograms: bool, exact_policy: bool, /// The driver breaks a tie at a vertex two pixels' diamonds share as Metal does. ties: bool, @@ -229,33 +227,16 @@ impl LineFacts { tessellates: has(VkFeature::TessellationShader), range: limits.line_width_range_bits.map(f32::from_bits), granularity: f32::from_bits(limits.line_width_granularity_bits), - strict: limits.strict_lines, - parallelograms: limits.non_strict_wide_lines_use_parallelogram, exact_policy: compile.policy().wide_lines == WideLinePolicy::Exact, ties: (device.properties().driver_facts).contains(&DriverFact::LineTiesAreMetals), snaps: (device.properties().driver_facts).contains(&DriverFact::SubpixelSnapIsMetals), } } - /// Whether the device's own lines draw Metal's `width` as Metal's parallelogram: non-strict - /// parallelograms above 1, on the granularity's grid from the range's bottom (the runtime's - /// docs, written apart from it). - fn draws_as_metal(self, width: f32) -> bool { - let w = metal_width(width); - let steps = (w - self.range[0]) / self.granularity; - self.draws(width) - && !self.strict - && self.parallelograms - && w > 1.0 - && self.granularity > 0.0 - && steps == steps.round() - } - - /// Whether a draw of `width` takes the device's own lines: where they draw it, as Metal's - /// parallelogram or under `WideLinePolicy::Device`, or with no band to draw it (no - /// `tessellationShader`). + /// Whether a draw of `width` takes the device's own lines: where they draw it, under + /// `WideLinePolicy::Device` or with no band to draw it (no `tessellationShader`). fn device_route(self, width: f32) -> bool { - self.draws(width) && (self.draws_as_metal(width) || !self.exact_policy || !self.tessellates) + self.draws(width) && (!self.exact_policy || !self.tessellates) } /// The width nearest the one Metal draws for `width` (1/16 at 0) that the device's lines @@ -1349,7 +1330,7 @@ struct Found { edges_matched: usize, /// Of `edges`, those left unchecked as announced line ties or subpixel snaps. edges_unchecked: usize, - /// Cases a device line drew otherwise than Metal, announced: left unchecked. + /// Cases the device's own lines drew, announced: left unchecked. announced: usize, /// Cases of a band of edges whose depth bias can differ from Metal's, announced: left /// unchecked. @@ -1455,13 +1436,13 @@ fn printed(drawn: &Drawn, shot: &Shot, check: Check, blocks: &[String]) -> Vec Found { let cache = ScratchCache::new().unwrap(); let messages = Messages::default(); @@ -1542,11 +1523,16 @@ fn run(policy: DevicePolicy) -> Found { if !wide_lines { assert_eq!(own, 0, "{name}: {key}: device lines without wideLines"); } - // Each draw at the nearest width announces it here, and only those. + // Each draw at the nearest width announces it here, and only those; and each draw of + // the device's own lines its lines, and only those. assert_eq!( announced_nearest as u64, nearest, "{name}: {key}: nearest-width draws and their notices" ); + assert_eq!( + announced as u64, own, + "{name}: {key}: the device's line draws and their notices" + ); if matches!(check, Check::Lane(_) | Check::Map) { assert!( drawn.green.iter().all(|&g| g == 0), @@ -1726,18 +1712,16 @@ fn run(policy: DevicePolicy) -> Found { } /// Every case under the default policy: the device's own lines where they draw the width, -/// announced where they draw it otherwise than Metal, else the band, a triangle's edges as a -/// line's. +/// announced, else the band, a triangle's edges as a line's. #[test] fn wide_lines_draw_metal_s_parallelograms() { let found = run(DevicePolicy::default()); assert!(found.matched > 0, "{found:?}"); let facts = found.facts.unwrap(); - // On a device that tessellates nothing is drawn at the nearest width, and where its own - // lines differ from Metal's at no width drawn (none without `wideLines`: MoltenVK), every - // case is drawn as Metal's, the edges at their width too, but a band of edges under a depth - // bias that can differ and the cases the driver's ties and snap leave unchecked, edges among - // them. + // On a device that tessellates nothing is drawn at the nearest width, and where no draw + // takes its own lines (without `wideLines`: MoltenVK), every case is drawn as Metal's, the + // edges at their width too, but a band of edges under a depth bias that can differ and the + // cases the driver's ties and snap leave unchecked, edges among them. if facts.tessellates { assert_eq!(found.nearest, 0, "{found:?}"); } @@ -1759,8 +1743,8 @@ fn wide_lines_draw_metal_s_parallelograms() { } } -/// Every case under `DevicePolicy::exact_answers()`: the band wherever the device's lines differ -/// from Metal's, so no draw of lines or edges is announced as the device's lines on a device with +/// Every case under `DevicePolicy::exact_answers()`: the band wherever the device's lines would +/// draw, so no draw of lines or edges is announced as the device's lines on a device with /// `tessellationShader`, and every case, a triangle's edges' included, is Metal's but those of a /// band of edges under a depth bias that can differ and those the driver's ties and snap leave /// unchecked (`device-line-ties`, `device-subpixel-snap`). @@ -1919,12 +1903,12 @@ fn a_draw_of_no_complete_primitive_draws_nothing() { } /// A whole triangle's edges in fill mode `Lines`, drawn twice. At width 4: by the device's own -/// lines where they draw width 4 as Metal does, or where they draw it otherwise under -/// `WideLinePolicy::Device` (announced; the lane's devices take `exact_answers`, whose band draws -/// it), compared with Metal's where they draw it as Metal does; else as the band, silent; as Metal's edges at width 4, pixel for pixel. Without `tessellationShader`, at -/// width 2: by the device's own lines where they draw it, else by them at the nearest width they -/// draw, announced and counted at each draw, at width 1 (no `wideLines`: MoltenVK) as Metal's -/// edges at width 1. +/// lines where they draw width 4 under `WideLinePolicy::Device` (announced at each draw and left +/// unchecked; the lane's devices take `exact_answers`, whose band draws it), else as the band, +/// silent, as Metal's edges at width 4, pixel for pixel. Without `tessellationShader`, at width 2: +/// by the device's own lines where they draw it (announced at each draw and left unchecked), else +/// by them at the nearest width they draw, announced and counted at each draw, at width 1 (no +/// `wideLines`: MoltenVK) as Metal's edges at width 1. #[test] fn edges_draw_as_bands_or_at_the_nearest_width() { let triangle = [4.0, 4.0, 28.0, 4.0, 16.0, 28.0]; @@ -1963,8 +1947,8 @@ fn edges_draw_as_bands_or_at_the_nearest_width() { // The width drawn, where it is Metal's map's. let drawn_at = match (facts.device_route(width), tessellated) { (true, _) => { - assert_eq!((routes, nearest), ([0, 1, 0], 0), "{what}"); - (differs == 0).then_some(width) + assert_eq!((routes, differs, nearest), ([0, 1, 0], 1, 0), "{what}"); + None } (false, true) => { assert_eq!((routes, differs, nearest), ([1, 0, 0], 0, 0), "{what}"); diff --git a/crates/metal2vulkan/src/device/policy.rs b/crates/metal2vulkan/src/device/policy.rs index 4c3b8aae7..50a33bc70 100644 --- a/crates/metal2vulkan/src/device/policy.rs +++ b/crates/metal2vulkan/src/device/policy.rs @@ -83,11 +83,12 @@ pub struct DevicePolicy { /// each such command records as nothing. 4.5 s by default (as the creation wait, above). Unread /// under `Exact`. The runtime's alone: no emitted code changes. pub pipeline_commit_wait: Duration, - /// Whether a line Apple's `setLineWidth:` widens, at a width the device's own lines draw - /// otherwise than Metal (strict lines, lines that are not parallelograms, a width off the - /// device's granularity or below 1), is the device's own line at that width (the default) or - /// the pipeline's band variant, two triangles that cover Metal's parallelogram. The runtime's - /// choice alone: no emitted code of a pipeline changes, the band being a variant of its own. + /// Whether a line Apple's `setLineWidth:` widens, at a width the device's own lines draw (which + /// no device's are taken to draw as Metal's: strict lines, lines that are not parallelograms, a + /// width off the device's granularity or below 1, a driver's parallelograms, whose ends the + /// driver places), is the device's own line at that width (the default) or the pipeline's band + /// variant, two triangles that cover Metal's parallelogram. The runtime's choice alone: no + /// emitted code of a pipeline changes, the band being a variant of its own. pub wide_lines: WideLinePolicy, /// Whether a blit or fill through a `BGRA10_XR` or `BGRA10_XR_sRGB` texture Metal keeps /// losslessly compressed keeps the texels' bytes (the default) or writes Metal's canonical @@ -425,21 +426,22 @@ pub enum PipelineWaitPolicy { Exact, } -/// Which lines draw a line Apple's `setLineWidth:` widens (a width other than 1, quantized as -/// Metal quantizes it), where the device's own lines draw that width otherwise than Metal's -/// parallelogram: its lines are strict (rectangles), or not parallelograms -/// (`nonStrictWideLinesUseParallelogram` unset or unknown), or the width is off the device's -/// `lineWidthGranularity` (which rounds it) or below 1 (where Vulkan promises no shape). Where the -/// device's lines draw the width as Metal does, they draw it under either value; where they cannot -/// draw it at all (no `wideLines`, or a width outside `lineWidthRange`), and at width 0, the band -/// draws it under either value. The runtime's choice alone: no emitted code changes. +/// Which lines draw a line Apple's `setLineWidth:` widens (a width other than 1, quantized as Metal +/// quantizes it) where the device's own lines draw that width, which no device's are taken to draw +/// as Metal's parallelogram: strict lines (rectangles), lines not stated as parallelograms +/// (`nonStrictWideLinesUseParallelogram` unset or unknown), a width off the device's +/// `lineWidthGranularity` (which rounds it) or below 1 (where Vulkan promises no shape), and a +/// driver's parallelograms, whose ends and endpoints' snap are the driver's. Where they cannot draw +/// it at all (no `wideLines`, or a width outside `lineWidthRange`), and at width 0, the band draws +/// it under either value. The runtime's choice alone: no emitted code changes. #[non_exhaustive] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum WideLinePolicy { - /// The device's own line at the width (the default): its rectangle, its Bresenham columns, or - /// its width rounded to the granularity, which can cover pixels Metal's parallelogram does not - /// and miss others. Announced `device-wide-lines` at the first such draw. + /// The device's own line at the width (the default): its rectangle, its Bresenham columns, its + /// width rounded to the granularity, or its parallelogram's ends, which can cover pixels + /// Metal's parallelogram does not and miss others. Announced `device-wide-lines` at the first + /// such draw. #[default] Device, /// The pipeline's band variant (needs `tessellationShader`): each line two triangles over diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index c848b169a..19279ffcf 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -536,7 +536,7 @@ fn the_runtime_s_wide_lines_choice_keys_no_profile() { } /// `DevicePolicy::exact_answers()` draws a wide line as Metal's parallelogram where the device's -/// own line differs, and the default draws the device's own. +/// own lines would draw it, and the default draws the device's own. #[test] fn exact_answers_draw_wide_lines_as_metal_s_parallelogram() { assert_eq!(DevicePolicy::UNTRUSTED.wide_lines, WideLinePolicy::Device); diff --git a/docs/API.md b/docs/API.md index 04d8e44b8..e096efc8a 100644 --- a/docs/API.md +++ b/docs/API.md @@ -206,16 +206,15 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`: recording. `pipeline_waits = PipelineWaitPolicy::Exact`, which `exact_answers()` selects, makes the predicted pipeline before the creation returns, as Metal compiles there, and waits for every draw's and dispatch's until made. -- **A wide line the device's own** (`WideLinePolicy::Device`, the default; the runtime's choice, - no pipeline's code differs). A line Apple's `setLineWidth:` widens, and a triangle's edge in fill - mode `Lines`, is drawn by the device's own lines wherever it draws the width (`wideLines`, - inside `lineWidthRange`), exact where they are Metal's parallelogram (`strictLines` unset, - `nonStrictWideLinesUseParallelogram` set, the width on `lineWidthGranularity` and above 1), - announced `device-wide-lines` where not. `wide_lines = WideLinePolicy::Exact`, which - `exact_answers()` selects, draws those as the pipeline's band variant instead (section 4), on a - device with `tessellationShader`. Every other width other than 1 is the band under either value, - and what neither draws the device's lines at the nearest width they draw, announced - `lines-at-nearest-width` (the runtime's README, line widths). +- **A wide line the device's own** (`WideLinePolicy::Device`, the default; the runtime's choice, no + pipeline's code differs). A line Apple's `setLineWidth:` widens, and a triangle's edge in fill + mode `Lines`, is drawn by the device's own lines wherever it draws the width (`wideLines`, inside + `lineWidthRange`), announced `device-wide-lines`: no device's lines are taken as Metal's + parallelogram, a driver's parallelograms included (their ends are the driver's). `wide_lines = + WideLinePolicy::Exact`, which `exact_answers()` selects, draws those as the pipeline's band + variant instead (section 4), on a device with `tessellationShader`. Every other width other than 1 + is the band under either value, and what neither draws the device's lines at the nearest width + they draw, announced `lines-at-nearest-width` (the runtime's README, line widths). - **A compressed extended-range texture's blits keep the bytes** (`ExtendedRangeBlitPolicy::Kept`, the default; the runtime's choice, no pipeline differs). Metal's GPU blit into, out of or between `BGRA10_XR` or `BGRA10_XR_sRGB` textures it keeps losslessly compressed @@ -3301,13 +3300,15 @@ bound. draw nothing, and some a few of the points or a box. - `metal2vulkan-degrade-device-wide-lines` (precision). `DeviceWideLines`: A draw of lines at a width other than 1 (Apple's `setLineWidth:`), or of a triangle's edges in fill mode `Lines` or of - a mesh draw, drawn by the device's own lines where they are not Metal's parallelogram: strict - lines (the rectangle the width spans across the segment, square ends), lines Vulkan does not - state as parallelograms (`nonStrictWideLinesUseParallelogram` unset, or a width below 1), or a - width off the device's `lineWidthGranularity`, which rounds it. Under `WideLinePolicy::Exact` a - draw of lines or of a triangle's edges takes the band variant there instead, on a device with - `tessellationShader`. Cost: the lines can cover pixels Metal's parallelogram does not, and miss - others, at each end and along each edge. + a mesh draw, drawn by the device's own lines, which no device's are taken to draw as Metal's + parallelogram: strict lines (the rectangle the width spans across the segment, square ends), lines + Vulkan does not state as parallelograms (`nonStrictWideLinesUseParallelogram` unset, or a width + below 1), a width off the device's `lineWidthGranularity`, which rounds it, and a driver's + parallelograms, whose ends and endpoints' snap are the driver's (RADV on the Radeon RX 7900 XTX + draws 21 of 48 scattered lines at width 2.5 a row or a column off Metal's at an end). Under + `WideLinePolicy::Exact` a draw of lines or of a triangle's edges takes the band variant instead, + on a device with `tessellationShader`. Cost: the lines can cover pixels Metal's parallelogram does + not, and miss others, at each end and along each edge. - `metal2vulkan-degrade-lines-at-nearest-width` (precision). `LinesAtNearestWidth`: A draw of lines at a width other than 1 (Apple's `setLineWidth:`), or of a triangle's edges in fill mode `Lines` or of a mesh draw, that neither the device's own lines at that width nor the band variant draws, diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index efbb85f78..61a259198 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -40,7 +40,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X | A chain of `half` additions, subtractions and products on a device without `shaderFloat16` (vk12-floor, SwiftShader, Pascal; capability emulation: the module computes each in `float` and rounds it by the device's `OpQuantizeToF16`): an operation whose flags hold `contract` and `reassoc` and whose result only such operations read is held at `float` precision unrounded, so the chain rounds where a value leaves it (a store, an output, a conversion, a comparison, a call, a phi, a vector move, an operation without both flags), one quantize per exit instead of one per operation (`lower::arith::half_chain`). A device with `shaderFloat16` computes `half` alike under either value. | `half_chains = HalfChainPolicy::AtExits` | `half_chains = HalfChainPolicy::EachOperation`: every operation's result rounded to `half`, as the AIR computes it | The result may differ from the rounded operations' by the roundings the chain skips, each within half a unit in the last place of a `half` at its step, compounded along the chain; a value inside the chain past `half`'s range (65504) stays finite where the rounded operations reach infinity. Within the AIR's flags, which let a compiler regroup and fuse such operations. `FastMathRewrites` (`fast-math-rewrites`) | Not timed. Size on vk12-floor (the fixtures' SPIR-V words, the default against the accurate form): `hfb_filter_bank` 121,270 against 131,766 (1,024 quantizes against 2,464), `grd_half_many_samples` 82,019 against 84,627, `nan_half_fast` 9,808 against 9,832 | | A texture that samples, reads, renders into it or is written through a shader (`ShaderWrite` or `ShaderAtomic` usage, of texels of 1, 2, 4, 8 or 16 bytes) over host pages (a no-copy buffer's, or a no-copy heap's buffer's, imported by their pointer or as dma-bufs; or a buffer in fresh pages; or a copied host buffer's copy of them, `copied.rs`, its image bound in the copy's memory where the check passed for the pages, and for the copy's fresh pages or, for a `DRM_FORMAT_MOD_LINEAR` image in memory the device allocates, its pooled memory, `WorkCounts::copied_textures_in_place`) is a linear image aliasing the pages in place, where the device makes the image (its format and usage linear, at the pages' pitch) and its own check shows that the operations Vulkan lets read and write every byte bound to it leave every byte alone while the CPU writes beside it: the image's first move (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), and for one that renders a render pass's load and store operations and its moves into `ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT` and back, and for one a shader writes a kernel's storage writes of its texels (which of a linear image a driver may widen past a texel), each access checked apart (a shader's writes of 1- or 2-byte texels apart from those of wider ones, which a driver may store through a wider access), and each apart for texels that share a line of the device's memory (`nonCoherentAtomSize`, "the size and alignment in bytes that bounds concurrent access to host-mapped device memory") with bytes beside them and for texels that share none (their start, their end and, with bytes between rows, each row's start and end on a line; `in_place::RowEnds`): a byte changed beside texels that share none fails both, one changed beside texels that share one fails those alone (the Iris Xe, ANV, Mesa 26.2.6, whose clear and store, and draws, write back whole the 64-byte line that holds a row's last texels, fails renders, and writes, for rows that end inside a line, a byte between rows changed, and passes both for rows that end on one: a 3840x2160 `BGRA8Unorm` surface's 15360-byte rows are 240 lines each). A kernel's writes of a texture over a buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and end on a line, its buffer holding the last row to its pitch, take a verdict of their own from the same rounds, which a round that changed only bytes of its rows' padding (after a row's last texel, before its pitch, the last row's included) passes (`in_place::Padding`, `Access::BufferWrites`): Metal leaves those bytes to the GPU there (an Intel UHD Graphics 630 under macOS 26.7.1 wrote older values back over the CPU's writes to them under a kernel's writes of a texture over a buffer, the last row's included, where an M3 Max under macOS 27.0.1 and a Radeon Pro 5300M kept them, and all three kept them under draws, clears and stores and over IOSurfaces; `crates/metal2vulkan-conformance/probes/row_padding_writes.m`), and the rule follows the x86 Macs' envelope (docs/API.md, section 10, **Kernels**), so the Iris Xe's written textures over a buffer take the image in place whatever their rows' ends. A deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's rulings (2026-10-26, and 2026-10-27 and 2026-11-07 for render targets and written textures: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it, on a discrete GPU too; `in_place.rs`). A texture over a buffer of the runtime's pooled memory whose rows the device's own linear image lays out otherwise (a padded pitch the driver does not take: ANV lays linear rows tight; rows apart only over a buffer that declares them unobserved, `BufferDescriptor::padding_unobserved`) is, by the same rule, a `DRM_FORMAT_MOD_LINEAR` image at Metal's pitch bound in the buffer's memory where the device makes one (no external memory, which Vulkan allows: `VUID-VkImageCreateInfo-tiling-02261`, `VUID-vkBindImageMemory-image-01445`), made `UNDEFINED` (`VUID-VkImageCreateInfo-initialLayout-12478`), whose first move the check's pooled class judges (`PagesClass::Pooled`: a buffer of that memory, its images at Metal's pitch alone; `WorkCounts::pooled_pitched_images`); a texture made before that class's verdict is a shadow that moves to that image once the verdict passes, as one over host pages moves in place (below; `WorkCounts::pooled_textures_moved_in_place`, `pooled_texture_shadows_freed_after_move`). A texture over a buffer whose memory the runtime exports (`exported_memory.rs`: a block that exportable buffers of one handle type share) is, by the same rule, the device's linear image or that `DRM_FORMAT_MOD_LINEAR` image made for the memory's handle type, which an image bound there must name (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), whose first move the check's exported classes judge, one per handle type (`PagesClass::ExportedFd`, `PagesClass::ExportedDmaBuf`: an exportable buffer of that handle type, its textures taking the product's image), a texture made before their verdicts moving to it once they pass as over the pooled memory; a shadow, its notice naming why, where the memory is a buffer's dedicated allocation (`VUID-vkBindImageMemory-memory-10926`) or the device's image format query (`VkPhysicalDeviceExternalImageFormatInfo`) takes the handle type for no such image without a dedicated allocation. A texture that renders over a buffer that declares its padding unobserved, its rows each to its pitch sharing no line with bytes past them, takes the verdict of renders that lets a byte of its rows' padding change (`Access::UnobservedRenders`, `Padding::Unobserved`), which the renders' own rounds give as the writes' give theirs: the declaration lets a pass's load and store write those bytes (the Iris Xe's clear and store write back the 64-byte line that holds a row's last texels whole), and a byte past the last row's pitch, or a texel, fails it. The check runs once per driver and driver version (its record named by the driver and the check's own version, not the runtime release), per class of pages, access and row ends, on a thread of its own, the verdicts it measured kept in the shader cache's directory with those it could not check for a cause that lasts for the driver (the device lacks an extension, a feature, an import, a format or an image of the shape), while one it could not check for a cause that may pass (pages or memory not made, an import refused, its writer thread not started, a move or the stores that failed) is checked again by the next device, its reason noted; a texture made before its verdict is a shadow, made without waiting for the check (its rounds take seconds on some devices and builds; `host_texture_shadows_check_pending`), and moves in place once its class's verdicts pass, at the commit of the device's only uncommitted command buffer, with no copy (`host_textures_moved_in_place`), its shadow's image freed once the command buffer that took the move completed (`host_texture_shadows_freed_after_move`), or, where a view made before the move presents it, a shadow made over it holds it as its truth, or the texture is untracked, once those and the texture went. A texture a shader writes of texels of a width no check stores (none of 1, 2, 4, 8 and 16 bytes), a check that failed or made no image, and a format, usage or pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`, those that render and those a shader writes counted apart in `host_texture_shadows_render_target` and `host_texture_shadows_shader_write`). On a discrete GPU a `Shared` texture and an IOSurface's are in place too, read across the bus, never copied to the device's memory for speed; a `Managed` texture over a no-copy buffer's bytes that only samples or reads, over memory that carries a log of its writes, is a device copy instead (`WorkCounts::device_copy_textures`), the GPU's copy of the two Metal keeps of a `Managed` resource on a Mac with a discrete GPU, its copies in only the rows the log reports changed. | `host_page_textures = HostPageTexturePolicy::InPlace` | `host_page_textures = HostPageTexturePolicy::Shadow`: every texture over host pages a shadow, its texels copied in before each command buffer that uses it and merged back after each write (the host-pages bullet under **Costs of matching Metal**) | Exact where the driver keeps what its check showed: the check covers texels, the bytes between rows and those after the image, of 1, 2, 4, 8 and 16-byte texels and a 3840x2160 surface, three rounds each, for an image that reads and one that renders (its pass a clear at load and a store, then a draw over its last column in a pass that loads and stores it; a resolve into it is not among the rounds), the CPU writing beside the texels sweep after sweep until each step completed, so that a device that writes back bytes it read beside them, wherever in the step, puts back an older value the check finds, and, for one a shader writes, of 4, 8 and 16-byte texels, rows apart (of widths no multiple of 4 and odd heights among them) or tight, and 1920x1080, and apart of 1- and 2-byte texels, rows apart at a 256-byte pitch (of rows that end inside a 4-byte word and odd heights) or tight, and 1024x64, each texel stored by a kernel through an unsigned-integer view (a program's atomics, and its stores through a float view, are not among the rounds); a driver whose operations changed a byte outside every round's window would undo a CPU write made meanwhile. A kernel's writes of a texture over a buffer whose padding is free may change that padding, as an x86 Mac's GPU's do (above). Not announced where the check passed. A CPU write reaches the image's reads as it reaches the buffer's (Host Write Ordering Guarantees) | See **Costs of matching Metal** (host pages): the shadow copies a sampled 3840x2160 surface in whole each command buffer, and a render target's shadow copies it in, keeps it and merges it back at each render pass instance | | A render or compute state's creation hands the driver's making of its predicted pipeline (`pipeline/predicted.rs`, `pipeline/dispatch_making.rs`) to the runtime's pool, kept by the state as a draw's or dispatch's making is, and waits for it `pipeline_creation_wait` at most; a committed command buffer's recordings wait until its commit plus `pipeline_commit_wait` at most, one deadline its commands share, for its draws' and dispatches' (a compute encoder's, a render pass's tile dispatches) pipelines still being made (the scheduler wakes at the bound, `StepWaits::until`), an execution's replayed draws (`render/pending.rs`) among them, whose pipelines the commit's settle hands to the pool (a device replay's, one recording for every command, waits until made under either value), then record each such command as nothing: a draw's barriers and visibility query, a dispatch's barrier (a tile dispatch's copies into its scratch and back), no draw or dispatch, the command buffer running on without error. The making goes on, and the command buffers after it draw and dispatch with the pipeline once made. Metal compiles inside `newRenderPipelineState`, so no draw of a made state waits or is dropped; a host that creates a state inside a command buffer's encoding (the consumer creates a guest's state at an execution's first lookup of it) held that execution through the driver's whole compile: 11.59 s inside one execution on an M2 Pro (MoltenVK 1.4.2, a cold Metal compiler service; a sample of such a stall finds the compile's thread waiting in `MVKMetalCompiler::compile` for Metal's compiler), past the guest's 10 s FIFO check, which ended the guest's task. Each bound is 4.5 s: a creation and a commit may fall in one step of the guest's FIFO (a task's jobs run one after another, and a draw's own variant waits under its command buffer's bound), and no runtime call waits for both, so one step waits 9 s at most for makings, under that 10 s check. A creation waits on no command buffer's deadline and a `commit` on no creation's; a `commit` waits until its own deadline at most (it records there what it can, an execution of render commands the CPU writes among them), every other recording on the scheduler's thread, a host step's on one of the steps' threads. Made until made under either value, in the call that makes them: a draw that records nothing, one in a pass of custom sample positions and one recorded again into another instance of its pass (each in the draw's call or an execution's replay), a device replay's draws (in its `commit`), and a failed making made again (`PipelineWaitPolicy`'s docs). The runtime's: no pipeline differs. | `pipeline_waits = PipelineWaitPolicy::Bounded`, `pipeline_creation_wait = 4.5 s`, `pipeline_commit_wait = 4.5 s` | `pipeline_waits = PipelineWaitPolicy::Exact`: the creation makes its predicted pipeline before it returns (a render state's first key on its own thread, the rest on the pool, joined; a compute state's on its own thread), an execution's settle makes its replayed draws' pipelines at the commit, and a command buffer waits for each draw's and dispatch's pipeline until it is made | A draw whose pipeline was still being made `pipeline_commit_wait` after its command buffer's commit renders nothing in that command buffer (only there: later ones draw it), where Metal's renders: content drawn once (a layer, a glyph cache) stays without it until redrawn. A creation returns after `pipeline_creation_wait` at most with its making in flight (`WorkCounts::creations_left_making`). `DrawDroppedStillMaking` (`draw-dropped-still-making`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `CommandBuffer::dropped_draw` names the first with `VK_TIMEOUT`; `WorkCounts::draws_dropped_still_making`; `deferred_calls::a_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` and `under_the_exact_wait_a_held_making_holds_its_command_buffer_until_it_lands`. A dispatch whose pipeline was still being made then writes nothing in that command buffer, where Metal's runs: `DispatchDroppedStillMaking` (`dispatch-dropped-still-making`), `WorkCounts::dispatches_dropped_still_making`, the first named by `dropped_draw`; `deferred_calls::a_dispatch_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing`, `a_compute_state_s_creation_waits_its_bound_for_its_predicted_making` and `a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` | No GPU cost. The exact form holds the creating thread, and the command buffer, for the whole compile: up to 11.59 s on the M2 Pro's cold boot (that boot's 2,483 render state creations, translation included: 300 over 16 ms, 151 over 100 ms, 14 over 250 ms, 3 over 1 s, the longest 11.59 s, 5.82 s and 1.17 s), where the default holds a creation for 4.5 s at most and a command buffer for 4.5 s from its commit, which drops the draws of the compiles that outlast those (2 of that boot's 2,483 were over 4.5 s) for the command buffers committed before they land; bounds of 1 s dropped 39 draws in a cold boot on the M2 Pro, and the guest's menu bar, drawn once, stayed half drawn | -| A line Apple's `setLineWidth:` widens (`w' = floor(16 w) / 16`, other than 1), and a triangle's edge in fill mode `Lines`, is drawn by the device's own lines at `w'` wherever it draws that width (`wideLines`, `w'` in `lineWidthRange` and above 0), where Metal draws the parallelogram Vulkan's non-strict wide lines may be (`render/line_width.rs`). They are exactly it on a non-strict device whose wide lines are parallelograms (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set) at a width above 1 on its `lineWidthGranularity`, unannounced there; elsewhere they differ: a strict device's rectangle with square ends (lavapipe, NVIDIA), lines Vulkan does not state as parallelograms (ANV, and every width below 1), a width rounded to the granularity. A mesh draw's lines and edges and a tessellated patch draw's edges take the device's lines under either value, the band not drawing them (at the nearest width they draw where they do not draw `w'`, announced `lines-at-nearest-width`: a known gap below). The runtime's: no pipeline's code differs. | `wide_lines = WideLinePolicy::Device` | `wide_lines = WideLinePolicy::Exact`: a draw of lines or edges the device's lines draw otherwise than Metal is the pipeline's band variant (`VariantKey::line_band`, `pipeline::link::band`) on a device with `tessellationShader` (the device's lines where it has none, or where the translator refuses the state's band or the draw's): two triangles over each line's parallelogram, and each triangle's three edges' parallelograms facing as the triangle, through a tessellation control and evaluation stage; every other width other than 1 is the band under either value | The lines can cover pixels the parallelogram does not, and miss others, at each end and along each edge: up to half the width past each end (square ends), and a rounded width. `DeviceWideLines` (`device-wide-lines`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `WorkCounts::device_wide_line_draws`, `line_band_draws`, `nearest_width_line_draws`; `runtime_lane::line_widths` (the band matches Metal's maps of lines and of triangles' edges, their facing, culling, flat inputs, primitive IDs and depth on MoltenVK under both values, which has no `wideLines`; a band of edges under a depth bias is announced `wide-edge-depth-bias`) | Not measured. Expected from the band's form: a second pipeline variant made for each render state that draws such lines or edges (its two synthesized stages), each line tessellated as a patch of two control points into four corners and each triangle as a patch of three into 21 triangles (12 degenerate), and a strip, loop or fan drawn as the list of its primitives | +| A line Apple's `setLineWidth:` widens (`w' = floor(16 w) / 16`, other than 1), and a triangle's edge in fill mode `Lines`, is drawn by the device's own lines at `w'` wherever it draws that width (`wideLines`, `w'` in `lineWidthRange` and above 0), where Metal draws the parallelogram Vulkan's non-strict wide lines may be (`render/line_width.rs`). No device's are taken as it, announced on every device: a strict device's rectangle with square ends (lavapipe, NVIDIA), lines Vulkan does not state as parallelograms (ANV, and every width below 1), a width rounded to the granularity, and a driver's parallelograms (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set), whose ends the driver places (RADV on the Radeon RX 7900 XTX draws 21 of `runtime_lane::line_widths`'s 48 scattered lines at width 2.5 a row or a column off Metal's at an end). A mesh draw's lines and edges and a tessellated patch draw's edges take the device's lines under either value, the band not drawing them (at the nearest width they draw where they do not draw `w'`, announced `lines-at-nearest-width`: a known gap below). The runtime's: no pipeline's code differs. | `wide_lines = WideLinePolicy::Device` | `wide_lines = WideLinePolicy::Exact`: a draw of lines or edges the device's lines draw is the pipeline's band variant (`VariantKey::line_band`, `pipeline::link::band`) on a device with `tessellationShader` (the device's lines where it has none, or where the translator refuses the state's band or the draw's): two triangles over each line's parallelogram, and each triangle's three edges' parallelograms facing as the triangle, through a tessellation control and evaluation stage; every other width other than 1 is the band under either value | The lines can cover pixels the parallelogram does not, and miss others, at each end and along each edge: up to half the width past each end (square ends), a rounded width, and a row or a column at an end (a driver's parallelograms). `DeviceWideLines` (`device-wide-lines`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `WorkCounts::device_wide_line_draws`, `line_band_draws`, `nearest_width_line_draws`; `runtime_lane::line_widths` (the band matches Metal's maps of lines and of triangles' edges, their facing, culling, flat inputs, primitive IDs and depth on MoltenVK under both values, which has no `wideLines`; a band of edges under a depth bias is announced `wide-edge-depth-bias`) | Not measured. Expected from the band's form: a second pipeline variant made for each render state that draws such lines or edges (its two synthesized stages), each line tessellated as a patch of two control points into four corners and each triangle as a patch of three into 21 triangles (12 degenerate), and a strip, loop or fan drawn as the list of its primitives | | A blit or fill through a `BGRA10_XR` or `BGRA10_XR_sRGB` texture Metal keeps losslessly compressed (`allowGPUOptimizedContents`, 16 texels or more a side, neither `ShaderWrite` nor `PixelFormatView` usage, one sample, not over a buffer) is the device's copy, which keeps the bytes it moves, on every device: Metal's GPU blit into, out of or between such textures moves the texels through its compression, which writes each 16-bit field's low six bits cleared and the alpha code clamped to `[384, 894]`, and its fill clears the low six bits alone (an Apple M3 Max under macOS 27.0.1, every direction, storage mode, usage and size that decides the compression; CPU copies keep the bytes on Metal too). A pass's draws through such an attachment are the device-gap row below. The runtime's choice: no pipeline differs (`compressed_blit.rs`). | `extended_range_blits = ExtendedRangeBlitPolicy::Kept` | `extended_range_blits = ExtendedRangeBlitPolicy::Canonical`: after a blit writes such a texture's region, or a blit out of one writes a buffer's words, a texture over a buffer's or another texture's, a compute dispatch (`bind::extended_canonical_module`, `extended_canonical.rs`) rewrites the texels it wrote in Metal's encoding: in place in a buffer's bytes, an image's through a scratch buffer, a copy out and back around the dispatch; a fill's texel is encoded before it is written. A buffer whose words the device cannot bind (an offset or pitch off 4 bytes, a region past `maxStorageBufferRange`) and a texture over a buffer whose rows share bytes keep the bytes under either value, announced | Bytes no Metal write left (uploaded, CPU-copied or kernel-written texels: a field's low six bits, an alpha code outside `[384, 894]`) keep what Metal's blit would rewrite; a texel reads the same value either way, its low six bits unread and its alpha read clamped. `ExtendedRangeBitsKept` (`extended-range-bits-kept`), once per device; under `Canonical` not for the blits it makes exact; `runtime_lane::compressed_blits` (both values on MoltenVK), the conformance cases `compressed-blits-bgra10xr` and `compressed-blits-bgra10xr-srgb` | Measured, `Canonical` against `Kept`, on `Private` `BGRA10_XR` textures Metal keeps compressed (the sRGB twin and fills not measured), 256x256 and 2048x2048, one whole-texture blit a command buffer: p50 of 300 blits a run, the two values interleaved in one process, three runs a host. RTX 5080 Laptop (NVIDIA 615.71.09, the command buffer's GPU time): a buffer into the texture 23.5 against 11.5 us and 761 against 244 us from a `Private` buffer, 42 against 30 us and 1,945 against 1,176 us from a `Shared` one; the texture into a `Private` buffer 14.1 against 11.2 us and 287 against 246 us, into a `Shared` one, whose words the dispatch rewrites in system memory, 66 against 27 us and 3,386 against 1,182 us; texture into texture 22.5 against 9.7 us and 630 against 80 us. Apple M3 Max (MoltenVK 1.4.2, whose GPU times are the host's, so per blit of 16 in one command buffer), the same blits: into the texture +38 to +57 us and +536 to +548 us, out of it into a buffer +15 us and +84 to +94 us, texture into texture +46 to +48 us and +535 to +541 us. Every figure is above its `Kept` one in every run, by more than the runs' spread (under 1 us on the 5080): measurable at both sizes on both hosts. Into an image a blit adds a copy out into a scratch buffer of the region's size, the dispatch, a copy back and the barriers between them; into a buffer the dispatch and a barrier. The scratch is made without zeros, since the copy out writes every byte the dispatch and the copy back read; the figures above were taken while it was zeroed first, by a command buffer of its own (a fill on the 5080, a copy on MoltenVK). CPU from the command buffer's making through its commit, a blit alone: +1 to +3 us on the M3 Max, +1 to +127 us on the 5080, whose host other builds loaded; 16 blits into 2048x2048 images in one command buffer hold 16 scratch buffers of 32 MiB, and encoding each costs 141 to 165 us (5080) and 286 to 356 us (M3 Max), new memory blocks among it, against 2 to 6 us under `Kept`. Nothing for a texture Metal keeps uncompressed or of another format | | A colour attachment of a texture's own image (not over a buffer's bytes, not memoryless, resolving nothing) that a pass stores `DontCare` is stored as the driver stores it: `DONT_CARE` on a driver measured to keep one of Metal's two answers or to store as Metal's own (`DriverFact::DontCareStoreIsOneOfMetals`, `DontCareStoreIsMetals`), else `STORE`, the rendered texels (`render_target.rs`). Metal's documentation leaves the contents open (`MTLStoreAction.dontCare`: "You need to assume that GPU discarded the texture's contents"); Apple's GPU leaves the texels the attachment held before the pass, the pass's clear and draws both gone (the conformance case `pass-sequence-color-actions`, an M3 Max under macOS 27.0.1, eight runs alike), or the rendered ones where its tiler overflows. A pass MoltenVK runs as one instance is handed to Metal's own `DontCare` under either value. | `dont_care_colors = DontCareColorPolicy::Driver` | `dont_care_colors = DontCareColorPolicy::Kept`: the pass renders through a backing its command queue keeps, one image of the attachment's shape, into which a `Load` copies the texels first, and nothing is copied back, so the texture keeps its earlier texels exactly (`kept_bytes.rs`, `WorkCounts::kept_texels_passes`); where a format makes no such image, the pass stores as under `Driver`, announced | Under `Driver`, the attachment holds the rendered texels (`STORE`: NVIDIA, lavapipe) or what the driver's `DONT_CARE` leaves (RADV, ANV: measured to be one of Metal's two answers), where Metal's holds the earlier texels unless its tiler overflows. `DontCareStore` (`dont-care-store`), once per device; under `Kept` not for the passes it keeps; `runtime_lane::dont_care_stores` (both values), the conformance case `pass-sequence-color-actions` | Measured, `Kept` against the same pass stored `Store`, one pass of one draw over an `RGBA8Unorm` texture a command buffer, commit to completion, the median of 300 interleaved (a scratch measurement, `rows3_cost`): RTX 5080 Laptop (NVIDIA 615.71.09), a `Load` pass 19 µs more at 1920x1080 and 10 µs at 256x256 (16 µs and 7 µs of GPU time), a `Clear` pass 3 µs; lavapipe (llvmpipe, LLVM 23.1.4), a `Load` pass 0.5 to 0.8 ms more at 1920x1080 and 30 µs at 256x256, a `Clear` pass within the runs' spread. Memory: one backing image of the attachment's shape per command queue | | A linear sample of a two-plane YCbCr texture whose planes a function reads in place (`YCBCR8_420_2P`, `YCBCR10_420_2P` through a uniform texel buffer over their codes, on an integrated GPU or a CPU device; `lower::sampler::in_place`), through a sampler that addresses no border on either plane axis, with no texel offset placed by a parent's size, is Vulkan's Y′CbCr model of the codes, as the device's own conversion with a linear chroma filter computes it: the four luma codes around the point and the four chroma pairs around the same point of the chroma plane (Metal's midpoint siting) blended bilinearly, then the surface's range and matrix (Metal's coefficients) in `float`, each channel clamped into `[0, 1]`: eight fetches. A runtime sampler's word decides as the function runs. A nearest sample, a border mode, a parent-placed offset and a gather are Metal's under either value. | `ycbcr_in_place_reads = YCbCrInPlacePolicy::Model` | `ycbcr_in_place_reads = YCbCrInPlacePolicy::Exact`: every tap Metal's texel (its chroma weighted 9/3/3/1 and rounded to a code, the fixed-point conversion), and the sample Metal's sum of the four taps' steps on the grid `2048`: twenty fetches and four conversions | The model reconstructs each channel at the point where Metal converts four taps and sums them: within the `float` arithmetic's rounding of the model (checked against an `f64` model on the CPU interpreter, `engine_ycbcr_in_place`), it differs from Metal's by the chroma the taps reconstruct, by Metal's roundings to a code and to `1/2048`, and where a tap's channel leaves `[0, 1]`, which Metal clamps before it sums. `HalfSampleFilter` / `FloatSampleFilter` under the bound converted 4:2:0 format, announced `ycbcr-filter-not-exact` | Radeon 780M (RADV): a 3840 x 2160 `YCBCR10_420_2P` frame sampled linearly into a 3840 x 2160 `BGRA8Unorm` target, GPU time per frame (median of 60): 6.4-6.9 ms under the exact form (`runtime_lane::video_frames`) | diff --git a/docs/RUNTIME-PORTING.md b/docs/RUNTIME-PORTING.md index d016dcff4..a39d22b91 100644 --- a/docs/RUNTIME-PORTING.md +++ b/docs/RUNTIME-PORTING.md @@ -414,7 +414,7 @@ narrow refusal that the call's rustdoc describes. | `SetFragmentTexture` | `setFragmentTexture:atIndex:` | `RenderCommandEncoder::set_fragment_texture` | | `SetFragmentTextures` | `setFragmentTextures:withRange:` | `RenderCommandEncoder::set_fragment_textures` | | `SetFrontFacingWinding` | `setFrontFacingWinding:` | `RenderCommandEncoder::set_front_facing_winding` | -| `SetLineWidth` | `setLineWidth:` (SPI) | `RenderCommandEncoder::set_line_width`: every width accepted, quantized as Metal does; drawn by the device's lines where they draw it (announced `device-wide-lines` where not Metal's parallelogram) or as the band variant; what neither draws (a triangle's edges, a line without `tessellationShader`, a rate-mapped pass's or an execution's lines) by the device's lines at the nearest width they draw, announced `lines-at-nearest-width` (the runtime's README, line widths) *(partial)* | +| `SetLineWidth` | `setLineWidth:` (SPI) | `RenderCommandEncoder::set_line_width`: every width accepted, quantized as Metal does; drawn by the device's lines where they draw it (announced `device-wide-lines`, no device's taken as Metal's parallelogram) or as the band variant; what neither draws (a triangle's edges, a line without `tessellationShader`, a rate-mapped pass's or an execution's lines) by the device's lines at the nearest width they draw, announced `lines-at-nearest-width` (the runtime's README, line widths) *(partial)* | | `SetPointSize` | `setPointSize:` (SPI) | `RenderCommandEncoder::set_point_size`: a no-op, as on Metal | | `SetProvokingVertexMode` | `setProvokingVertexMode:` (SPI) | `RenderCommandEncoder::set_provoking_vertex_mode`: modes 0 and 1 drawn as Metal draws them; every other mode, which Metal draws a third way, drawn as 1 (patches as 0), each draw Metal's third way draws otherwise announced (`provoking-vertex-unmatched`) *(partial)* | | `SetRenderPipelineState` | `setRenderPipelineState:` | `RenderCommandEncoder::set_render_pipeline_state` |