diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index d6806c40b..f4bd194f4 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -470,21 +470,21 @@ draw whose vertices or indices complete no primitive of its type draws nothing, The band is the pipeline's band variant, through a tessellation control and evaluation stage the translator adds (docs/API.md section 4): two triangles over each line's parallelogram, and for a -triangle in fill mode `Lines` its three edges' parallelograms, which face as the triangle does -under the draw's cull mode, front face and depth bias. A strip, loop or fan is drawn as the list of -its primitives. The band's depth bias is the device's, of each band triangle's own slope and -depths, where Metal biases the edges by the triangle's: announced `wide-edge-depth-bias` under a -slope factor, or a constant factor over a float depth. Neither route draws, so the nearest width -takes: a mesh draw's lines and edges and a tessellated patch draw's edges the device's lines do not -draw (1 pixel wide on MoltenVK), lines and edges on a device without `tessellationShader` whose -lines do not draw them or of a pipeline state whose band variant the translator refuses (a vertex -function that selects a slice or viewport, barycentric weights, synthesized geometry, multiview; -the state's first band asks), an amplified band, and every wide line in an execution or a -rasterization-rate-mapped pass, whose width Metal's answer is not measured for. Refused -`NotImplemented(RuntimeGap::WideLines)`: a strip's band whose list of primitives the runtime cannot -draw; and `Unsupported` (`Feature::WideLines`) for a draw whose own band variant the translator -refuses where the state's first band compiled (a varying the draw's variant adds past the -evaluation stage's outputs), after which the state's draws take the nearest width. +triangle in fill mode `Lines` its three edges' parallelograms, which face as the triangle does under +the draw's cull mode, front face and depth bias. A strip, loop or fan is drawn as the list of its +primitives. The band's depth bias is the device's, of each band triangle's own slope and depths, +where Metal biases the edges by the triangle's: announced `wide-edge-depth-bias` under a slope +factor, or a constant factor over a float depth. Neither route draws, so the nearest width takes: a +mesh draw's lines and edges and a tessellated patch draw's edges the device's lines do not draw (1 +pixel wide on MoltenVK), lines and edges on a device without `tessellationShader` whose lines do not +draw them or of a pipeline state whose band variant the translator refuses (a vertex function that +selects a slice or viewport, barycentric weights, synthesized geometry, multiview; the state's first +band asks), a draw whose own band variant the translator refuses where the state's first band +compiled (a varying or push data the draw's variant adds past the evaluation stage's outputs or +`maxPushConstantsSize`; the state's later draws of the primitive take the nearest width too), an +amplified band, and every wide line in an execution or a rasterization-rate-mapped pass, whose width +Metal's answer is not measured for. Refused `NotImplemented(RuntimeGap::WideLines)`: a strip's band +whose list of primitives the runtime cannot draw. docs/FAST-PATHS.md records the choice and the known gaps. ## GPU families diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 20eb62dce..7a9afd6b9 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2063,7 +2063,8 @@ degradations! { /// tessellated patch draw's edges, which the band does not draw, where the device's lines /// do not draw the width (every such draw on a device without `wideLines`, MoltenVK among /// them); lines and edges on a device without `tessellationShader` whose lines do not draw - /// them, or of a pipeline state whose band variant the translator refuses; a band under + /// them, or of a pipeline state or a draw whose band variant the translator refuses (and + /// the state's later draws of a draw so refused); a band under /// vertex amplification above 1; and every line in a rasterization-rate-mapped pass or of /// an execution's command, whose width Metal's answer is not measured for. The reason /// names which, and both widths. diff --git a/crates/metal2vulkan-runtime/src/pipeline/render.rs b/crates/metal2vulkan-runtime/src/pipeline/render.rs index 25c94ffab..b6a67f8ac 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/render.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/render.rs @@ -2309,8 +2309,8 @@ impl GraphicsState { } /// The translator refused a draw's band variant of `primitive`, past the one - /// [`band_refused`](Self::band_refused) compiled: the state's later draws of it take the - /// nearest width. + /// [`band_refused`](Self::band_refused) compiled: that draw, routed again, and the state's + /// later draws of it take the nearest width (`render/line_width.rs`). pub(crate) fn refuse_band(&self, primitive: BandPrimitive) { lock(&self.0.band_refusals)[band_index(primitive)] = Some(true); } diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index 02f171764..25c34e93b 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -899,6 +899,28 @@ struct DrawSettings { line_band: Option<(metal2vulkan::pipeline::BandPrimitive, [f32; 4])>, } +/// How a draw is drawn from the encoder's call (`RenderCommandEncoder::routed_draw`): what its +/// lines' route (`DrawSettings::line`) decides beside its settings. +struct RoutedDraw { + /// Its last provoking vertex (`render/provoking.rs`), and the variant's forms of it. + provoking: provoking::Provoking, + provoking_forms: ProvokingForms, + /// Its strip or private type drawn as its list (`render/restart.rs`), and its private type's + /// form (`PrivateForm`). + restarted: Option, + private: PrivateForm, + /// The assembly it draws: its list's where it is listed. + assembly: Assembly, + settings: DrawSettings, + /// The pass's hidden depth and stencil it gives (`RenderCommandEncoder::needed_hidden`). + hidden: Option, + /// Its settings' entry in the encoder's memo (`render/draw_shape.rs`), `None` where they are + /// not kept. + shape_token: Option, + /// The index type its de-indexed variant reads ([`primitive_id_indices`]). + primitive_id_indices: Option, +} + /// The render encoder state one draw takes, statically or as dynamic state, in Vulkan's terms /// (`render_state.rs`). #[derive(Clone)] @@ -7251,30 +7273,7 @@ impl RenderLowering { // the device's lines at the nearest width they draw (`render/line_width.rs`); a draw of no // complete primitive as every line. let primitives = line_width::draws_primitives(assembly, &draw); - let line = (self.shape_inputs()).line_route(call, (&pipeline, assembly, primitives), false); - let provoking = self.provoking(call, &pipeline, (assembly, line.band()), &draw); - let provoking_forms = provoking.forms(assembly, &pipeline); - let restarted = self.restarted(assembly, &draw, (provoking, line)); - let private = match (assembly, restarted) { - (Assembly::Private(program), _) => PrivateForm::of(&pipeline, program, &draw), - (_, Some(_)) => PrivateForm::listed(&draw), - (_, None) => PrivateForm::default(), - }; - let assembly = restarted.map_or(assembly, |r| r.assembly()); - // Its settings, and the memo entry its draw state and pipeline are found and kept in - // (`render/draw_shape.rs`). - let (settings, hidden, shape_token) = - self.shaped_settings(call, &pipeline, (assembly, primitives))?; - // A direct indexed draw of a pipeline that writes the primitive ID runs its de-indexed - // variant; a restarted strip's list keeps the strip's indices, which it does not run. - let primitive_id_indices = match restarted { - None => primitive_id_indices(&pipeline, &draw), - Some(_) => None, - }; - let (topology, primitive_restart) = (settings.topology, settings.primitive_restart); - let unsized_points = settings.unsized_points; - let (native, compensation) = (settings.native, settings.compensation); - let hidden_depth = settings.hidden; + let mut routed = self.routed_draw(call, &pipeline, (assembly, primitives), &draw)?; let (_, stencil) = self.layout.aspects(); let max = pipeline.base().graphics.max_vertex_amplification_count; let function_tables = pipeline.function_tables(); @@ -7293,11 +7292,12 @@ impl RenderLowering { [&self.vertex, &self.object, &self.mesh], &pipeline.base().interface, )?; - self.degrade_kept_colors(&pipeline, &settings.routing); + // Its routing is the same whatever its lines' route (`ShapeInputs::routing`). + self.degrade_kept_colors(&pipeline, &routed.settings.routing); // The pass colors the draw renders through views of other formats, in an instance of // its own (`next_instance`). Refused (`NotImplemented(IndirectRenderCommands)`) for an // execution's command, whose runs' framebuffers are the pass's. - let reformats = self.reformats(&pipeline, &settings.routing)?; + let reformats = self.reformats(&pipeline, &routed.settings.routing)?; if self.replaying && !reformats.is_empty() { return Err(Error::NotImplemented(RuntimeGap::IndirectRenderCommands)); } @@ -7313,23 +7313,53 @@ impl RenderLowering { // Its runtime samplers' address modes as the textures they sample map them: what it // settles under, and binds with. let sampler_maps = self.sampler_maps(&pipeline, &pass_start)?; + let settled = loop { + let settled = self.settle_draw( + live, + ( + &pipeline, + &routed.settings, + routed.primitive_id_indices, + routed.private, + routed.provoking_forms, + ), + (&pass_start, &sampler_maps), + (&mut argument_samplers, &mut unlisted), + (&function_tables, &mut snapshot), + ); + // A band variant the translator refuses for the draw's own shape, past the one the + // state compiled for its first band: the draw takes the nearest width, routed again, + // as the state's later draws of the primitive do (`render/line_width.rs`). Routed + // again, it draws no band of the primitive, so it settles once more at most. + let refused = settled + .as_ref() + .err() + .and_then(|e| routed.settings.line.refused(e)); + let Some(primitive) = refused else { + break settled?; + }; + pipeline.refuse_band(primitive); + routed = self.routed_draw(call, &pipeline, (assembly, primitives), &draw)?; + }; let Settled { shape, variant, plan, - } = self.settle_draw( - live, - ( - &pipeline, - &settings, - primitive_id_indices, - private, - provoking_forms, - ), - (&pass_start, &sampler_maps), - (&mut argument_samplers, &mut unlisted), - (&function_tables, &mut snapshot), - )?; + } = settled; + let RoutedDraw { + provoking, + restarted, + private, + assembly, + settings, + hidden, + shape_token, + .. + } = routed; + let (topology, primitive_restart) = (settings.topology, settings.primitive_restart); + let unsized_points = settings.unsized_points; + let (native, compensation) = (settings.native, settings.compensation); + let hidden_depth = settings.hidden; let planes = |form: &ExtendedRange| matches!(form, ExtendedRange::Planes { .. }); if plan.variant.extended_range.values().any(planes) { self.core.device().shared().counts.two_plane_draw(); @@ -9698,6 +9728,51 @@ impl RenderLowering { .settings(call, (pipeline, assembly, true), hidden, announce) } + /// How the encoder's `call` of `assembly` (which may draw a primitive where `primitives`) + /// draws `draw` of `pipeline` ([`RoutedDraw`]): its lines' route at the encoder's width + /// (`render/line_width.rs`), its last provoking vertex (`render/provoking.rs`), a strip or + /// private type as its list (`render/restart.rs`), and its settings + /// ([`shaped_settings`](Self::shaped_settings)). + fn routed_draw( + &mut self, + call: &'static str, + pipeline: &DrawingState, + (assembly, primitives): (Assembly, bool), + draw: &DrawCall, + ) -> Result { + let line = (self.shape_inputs()).line_route(call, (pipeline, assembly, primitives), false); + let provoking = self.provoking(call, pipeline, (assembly, line.band()), draw); + let provoking_forms = provoking.forms(assembly, pipeline); + let restarted = self.restarted(assembly, draw, (provoking, line)); + let private = match (assembly, restarted) { + (Assembly::Private(program), _) => PrivateForm::of(pipeline, program, draw), + (_, Some(_)) => PrivateForm::listed(draw), + (_, None) => PrivateForm::default(), + }; + let assembly = restarted.map_or(assembly, |r| r.assembly()); + // Its settings, and the memo entry its draw state and pipeline are found and kept in + // (`render/draw_shape.rs`). + let (settings, hidden, shape_token) = + self.shaped_settings(call, pipeline, (assembly, primitives))?; + // A direct indexed draw of a pipeline that writes the primitive ID runs its de-indexed + // variant; a restarted strip's list keeps the strip's indices, which it does not run. + let primitive_id_indices = match restarted { + None => primitive_id_indices(pipeline, draw), + Some(_) => None, + }; + Ok(RoutedDraw { + provoking, + provoking_forms, + restarted, + private, + assembly, + settings, + hidden, + shape_token, + primitive_id_indices, + }) + } + /// A draw's settings ([`draw_settings`](Self::draw_settings), of a draw of `assembly` that may /// draw a primitive where `primitives`), with the hidden depth and /// stencil it gives the pass: those an earlier draw of the encoder derived from the same @@ -9850,17 +9925,9 @@ impl RenderLowering { let shape = live.shape(counts, |state| pipeline.kept_shape(state)); // Through what the pipeline state settled lately (`GraphicsState::settle_shape`). let settled = match pipeline.settle_shape(&shape, self.forms) { - // A band variant the translator refuses for the draw's shape, past the one the - // state compiled for its first band: refused, and the state's later draws take - // the nearest width (`render/line_width.rs`). - Err(Error::Unsupported(refused)) - if refused.feature == metal2vulkan::error::Feature::WideLines => - { - if let Some((primitive, _)) = settings.line_band { - pipeline.refuse_band(primitive); - } - return Err(Error::Unsupported(refused)); - } + // A band variant the translator refuses for the draw's shape: the caller routes + // the draw again (`LineRoute::refused`). + Err(refused) if settings.line.refused(&refused).is_some() => return Err(refused), // A variant that reads through snapshots the compile or bind layer refuses: the // draw takes the split (`render/snapshot.rs`). Err(Error::Unsupported(_) | Error::Bind(BindError::Unsupported(_))) diff --git a/crates/metal2vulkan-runtime/src/render/line_width.rs b/crates/metal2vulkan-runtime/src/render/line_width.rs index 7a173237e..52d50e6c3 100644 --- a/crates/metal2vulkan-runtime/src/render/line_width.rs +++ b/crates/metal2vulkan-runtime/src/render/line_width.rs @@ -68,10 +68,11 @@ //! clamped into `lineWidthRange` where it enables `wideLines`, else 1), where neither route above //! draws `w'`, announced (`Degradation::LinesAtNearestWidth`, with why): a mesh draw's lines and //! edges, and a tessellated patch draw's edges, which the band does not draw; lines and edges -//! without `tessellationShader`, or of a pipeline state whose band variant the translator -//! refuses (`pipeline::link::band`: a vertex function that selects a slice or viewport, a -//! fragment function that reads barycentric weights, synthesized geometry, multiview, stages -//! past `maxTessellationEvaluationOutputComponents`); a band under vertex amplification above 1 +//! without `tessellationShader`, or of a pipeline state or a draw whose band variant the +//! translator refuses (`pipeline::link::band`: a vertex function that selects a slice or +//! viewport, a fragment function that reads barycentric weights, synthesized geometry, +//! multiview, stages past `maxTessellationEvaluationOutputComponents` or push data past +//! `maxPushConstantsSize`); a band under vertex amplification above 1 //! (its viewports); and every line drawn in a rasterization-rate-mapped pass or as an //! execution's command, whose width Metal's answer is not measured for. Without `wideLines` they //! are 1 pixel wide whatever `w'`. @@ -79,9 +80,13 @@ //! A pipeline state's band variant of each primitive is compiled when a draw first takes it, under //! the state's base key; where the translator refuses it, the state's draws of that primitive take //! the nearest width from then on (`GraphicsState::band_refused`). A draw whose own variant the -//! translator refuses past that (a varying the draw's variant adds that takes the band's stages -//! past `maxTessellationEvaluationOutputComponents`) is refused with the translator's -//! `Unsupported(WideLines)`, and the state's later draws take the nearest width. +//! translator refuses past that (a varying or push data the draw's variant adds, such as a +//! shader-side depth test's window depth and depth range, that takes the band's stages past +//! `maxTessellationEvaluationOutputComponents` or `maxPushConstantsSize`) takes the nearest width +//! too, routed again ([`LineRoute::refused`]), and so do the state's later draws of the primitive +//! (`GraphicsState::refuse_band`): the refusal is kept per state and primitive, as the state's own +//! is, since a draw's variant key follows from its bind shape, which its route sets. Both are +//! announced alike (`Degradation::LinesAtNearestWidth`, the translator's refusal as the reason). //! //! Refused (`NotImplemented(RuntimeGap::WideLines)`): a strip's band whose list of primitives the //! runtime cannot draw (`render/restart.rs`, as for a list of the last provoking vertex). @@ -94,9 +99,11 @@ use super::draw_shape::ShapeInputs; use super::{Assembly, RenderLowering}; use crate::degradation::Degradation; +use crate::error::Error; use crate::pipeline::{FixedState, GraphicsState as DrawingState}; use metal2vulkan::bind::{DrawCall, RewriteProgram}; use metal2vulkan::device::{DeviceProfile, VkFeature, WideLinePolicy}; +use metal2vulkan::error::Feature; use metal2vulkan::metal::state::DepthBias; use metal2vulkan::metal::{PixelFormat, PrimitiveType, TriangleFillMode}; use metal2vulkan::pipeline::{BandPrimitive, LineBandState}; @@ -152,7 +159,8 @@ pub(super) enum Unrouted { Unbanded, /// No `tessellationShader`, which the band needs. Untessellated, - /// The pipeline state's band variant, which the translator refuses. + /// The pipeline state's band variant, or a draw's of it, which the translator refuses + /// (the module docs). Refused, /// Vertex amplification above 1, whose views the band does not draw. Amplified, @@ -193,6 +201,22 @@ impl LineRoute { matches!(self, LineRoute::Band { primitive, .. } if pipeline.refused_band(primitive)) } + /// The primitive of the band the route draws where `error`, the answer for the draw's + /// variant, is the translator's refusal of it (`Unsupported(WideLines)`, + /// `pipeline::link::band`): the draw takes the nearest width instead, as the state's later + /// draws of the primitive do (the module docs). `None` for every other route and answer, which + /// stands. + pub(super) fn refused(self, error: &Error) -> Option { + match (self, error) { + (LineRoute::Band { primitive, .. }, Error::Unsupported(refused)) + if refused.feature == Feature::WideLines => + { + Some(primitive) + } + _ => None, + } + } + /// The band's push (`BindState::line_band`) through a Vulkan viewport 0 of half extent /// `(sx, sy)`, drawn under front face `front_face`: its half extent, the half width, and for a /// triangle's edges 1 under a clockwise front face, -1 under a counter-clockwise one @@ -461,9 +485,9 @@ fn announce_nearest_lines( Unrouted::Untessellated => ("lines or edges", "the band needs tessellationShader"), Unrouted::Refused => ( "lines or edges", - "the translator refuses the pipeline state's band (a vertex function that selects \ - a slice or viewport, a fragment function that reads barycentric weights, or stages \ - past the device's limits)", + "the translator refuses the pipeline state's band, or a draw's of it (a vertex \ + function that selects a slice or viewport, a fragment function that reads \ + barycentric weights, or stages past the device's limits)", ), Unrouted::Amplified => ( "lines or edges", diff --git a/crates/metal2vulkan-runtime/src/render/line_width/tests.rs b/crates/metal2vulkan-runtime/src/render/line_width/tests.rs index 71ed425fd..913c73f6e 100644 --- a/crates/metal2vulkan-runtime/src/render/line_width/tests.rs +++ b/crates/metal2vulkan-runtime/src/render/line_width/tests.rs @@ -2,9 +2,11 @@ //! primitive (`render/line_width.rs`). use super::{drawn, draws_primitives, route, Assembly, Drawn, LineRoute, LineWidth, Unrouted}; +use crate::error::{Error, RuntimeGap}; use metal2vulkan::bind::{DrawCall, IndexBufferRef, IndirectRef, RewriteProgram}; -use metal2vulkan::device::WideLinePolicy; use metal2vulkan::device::{Device, DeviceDescription, DevicePolicy, DeviceProfile, VkFeature}; +use metal2vulkan::device::{VkLimit, WideLinePolicy}; +use metal2vulkan::error::{Capability, Feature, Unsupported}; use metal2vulkan::metal::{PrimitiveType, TriangleFillMode}; use metal2vulkan::pipeline::BandPrimitive; use metal2vulkan::vk; @@ -353,6 +355,102 @@ fn each_device_routes_each_width_as_its_lines_allow() { } } +/// A draw whose own band variant the translator refuses (`Unsupported(WideLines)`: not +/// implemented, or a limit such as `maxTessellationEvaluationOutputComponents` a varying of the +/// draw's variant passes) takes the nearest width, routed again as a draw of a state whose band is +/// refused (`LineRoute::refused`), never failing: on every committed device profile, under both +/// `WideLinePolicy` values, for lines and a triangle's edges at each width the band draws. Routed +/// again it draws no band, so the draw settles again once at most. Any other answer stands, and a +/// route other than the band takes no refusal. +#[test] +fn a_draw_whose_band_the_translator_refuses_takes_the_nearest_width() { + let refusals = [ + Error::Unsupported(Unsupported::not_implemented(Feature::WideLines)), + Error::Unsupported(Unsupported::needs( + Feature::WideLines, + Capability::Limit { + limit: VkLimit::MaxTessellationEvaluationOutputComponents, + required: 128, + available: 124, + }, + )), + ]; + let others = [ + Error::Unsupported(Unsupported::not_implemented(Feature::Tessellation)), + Error::NotImplemented(RuntimeGap::WideLines), + ]; + let edges = drawn( + Assembly::Primitives(PrimitiveType::Triangle), + TriangleFillMode::Lines, + false, + None, + true, + ); + let lines = drawn( + Assembly::Primitives(PrimitiveType::Line), + TriangleFillMode::Fill, + false, + None, + true, + ); + let mut bands = 0; + for stem in [ + "amd-780m-radv", + "amd-rdna3-radv", + "intel-arl-anv", + "lavapipe", + "nvidia-rtx5080-laptop", + "moltenvk-m3", + "swiftshader", + "vk12-floor", + "roadmap-2022", + "lunarg-desktop-baseline-2023", + "amd-780m-hawkpoint-radv", + ] { + let device = device(stem); + let profile = device.profile(); + for policy in [WideLinePolicy::Device, WideLinePolicy::Exact] { + for drawn in [lines, edges] { + for w in [0.0, 0.5, 1.0, 1.5, 2.5, 8.0625, 16.0] { + let width = LineWidth::of(w); + let at = + |refused| route(profile, policy, width, drawn, Default::default(), refused); + let what = format!("{stem}, {policy:?}, {drawn:?} at {w}"); + let first = at(false); + for other in &others { + assert_eq!(first.refused(other), None, "{what}: {other:?}"); + } + let LineRoute::Band { primitive, .. } = first else { + for refusal in &refusals { + assert_eq!(first.refused(refusal), None, "{what}: {first:?}"); + } + continue; + }; + bands += 1; + for refusal in &refusals { + assert_eq!(first.refused(refusal), Some(primitive), "{what}"); + } + // Routed again: the device's lines where they draw the width, else the + // nearest width, the translator's refusal the reason; no band. + let again = at(true); + let nearest = LineRoute::Nearest { + width: nearest(profile, width.pixels()), + why: Unrouted::Refused, + }; + assert!( + again == nearest || matches!(again, LineRoute::Device { .. }), + "{what}: routed again {again:?}" + ); + for refusal in &refusals { + assert_eq!(again.refused(refusal), None, "{what}: {again:?}"); + } + } + } + } + } + assert!(bands > 0, "no profile drew a band"); +} + /// A direct draw whose vertices or indices complete no primitive of its type draws nothing at /// any width, as Metal's: of every line and triangle type and each private one, list or strip, /// indexed or not, of one instance or several, in either fill mode. One primitive's vertices diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index 6403ed38a..54ff31c95 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -dafe34c277fdec83e28cf8c721587b419297c0907d2b3cb1bf35cd67b4833d18 +79fe4b2f43826a11d87c327a5338b5b50389b837440b9d3efe0f8f8a16fa9524 diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index e5175d857..ee9380dee 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 480; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 1716; +pub const RUNTIME_VERSION: u32 = 1717; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/docs/API.md b/docs/API.md index 98a164da9..5208bb064 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2746,7 +2746,8 @@ bound. `lineWidthRange` where the device enables `wideLines`, else 1. That is a mesh draw's lines and edges and a tessellated patch draw's edges where the device's lines do not draw the width (every such draw on MoltenVK), lines and edges on a device without `tessellationShader` whose lines do - not draw them or of a pipeline state whose band variant the translator refuses, a band under + not draw them or of a pipeline state or a draw whose band variant the translator refuses (and + the state's later draws of a draw so refused), a band under vertex amplification above 1, and every line in a rasterization-rate-mapped pass or of an execution's command, whose width Metal's answer is not measured for. The reason names which, and both widths. Cost: the lines are drawn at another width than Metal's: thinner (1 pixel without diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 1d58546a8..4f8bb62b3 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -39,7 +39,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 only samples or reads (no `RenderTarget`, `ShaderWrite` or `ShaderAtomic` usage) 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) is a linear image aliasing the pages in place, where the device's own check shows that the image's first move, which Vulkan lets read and write every byte bound to it (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), leaves every byte alone while the CPU writes beside it: a deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's ruling (`in_place.rs`). The check runs once per driver, release and runtime, per class of pages, on a thread of its own, its verdict kept in the shader cache's directory; a texture made before its class's verdict is a shadow. A texture whose usage renders or writes, a check that failed or made no image, and a pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`). | `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; a driver whose first move changed a byte outside every round's window would undo a CPU write made meanwhile. 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 | | 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. 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): 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`). 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 | All at once: `DevicePolicy::exact_answers()` sets every switch above; each row states its own cost. @@ -840,27 +840,27 @@ driver's. Each is open work. neither pixel is required; both choices conform and there is no Vulkan control over the tie, so this is the driver's and not ours. RADV and ANV unrun. -- **Lines under Apple's `setLineWidth:` at a width other than 1 that neither route draws as - Metal** (`render/line_width.rs`). Drawn by the device's own lines at the nearest width they - draw (1 pixel without `wideLines`), announced `lines-at-nearest-width`: a mesh draw's lines and - edges and a tessellated patch draw's edges where the device's own lines do not draw the width - (every such draw on MoltenVK), lines and edges on a device without `tessellationShader` whose - lines do not draw them or of a pipeline state whose band variant the translator does not build - (a vertex function that selects a slice or viewport, barycentric weights, synthesized geometry, - multiview), an amplified band, and any wide line in an execution or a rasterization-rate-mapped - pass. A band of a triangle's edges takes the device's depth bias of each band triangle, where - Metal biases by the triangle's slope and largest depth exponent: announced - `wide-edge-depth-bias` under a slope factor or a constant over a float depth. Refused - (`RuntimeGap::WideLines`): a strip's band whose list of primitives the runtime cannot draw; and - (`Unsupported`) a draw whose own band variant the translator refuses where the state's first - band compiled, the state's later draws taking the nearest width. Not announced: the band is cut - at the near and far planes where its triangles are, which can differ from Metal's clipped - segment by part of a pixel there, and a triangle that crosses the near plane is drawn as its - edges' visible parts, with no edge along the plane (Metal's unmeasured); what a line's band's - fragments read (varyings and depth across the width) is not compared with Metal's; and at width - 1 in a multisampled pass the runtime's lines are its ordinary ones (Bresenham's where the device - offers them) where Metal draws the parallelogram at the sample positions (MoltenVK's are Metal's - own). +- **Lines under Apple's `setLineWidth:` at a width other than 1 that neither route draws as Metal** + (`render/line_width.rs`). Drawn by the device's own lines at the nearest width they draw (1 pixel + without `wideLines`), announced `lines-at-nearest-width`: a mesh draw's lines and edges and a + tessellated patch draw's edges where the device's own lines do not draw the width (every such draw + on MoltenVK), lines and edges on a device without `tessellationShader` whose lines do not draw + them or of a pipeline state whose band variant the translator does not build (a vertex function + that selects a slice or viewport, barycentric weights, synthesized geometry, multiview), a draw + whose own band variant the translator refuses where the state's first band compiled (a varying or + push data the draw's variant adds past the evaluation stage's outputs or `maxPushConstantsSize`) + and the state's later draws of its primitive, an amplified band, and any wide line in an execution + or a rasterization-rate-mapped pass. A band of a triangle's edges takes the device's depth bias of + each band triangle, where Metal biases by the triangle's slope and largest depth exponent: + announced `wide-edge-depth-bias` under a slope factor or a constant over a float depth. Refused + (`RuntimeGap::WideLines`): a strip's band whose list of primitives the runtime cannot draw. Not + announced: the band is cut at the near and far planes where its triangles are, which can differ + from Metal's clipped segment by part of a pixel there, and a triangle that crosses the near plane + is drawn as its edges' visible parts, with no edge along the plane (Metal's unmeasured); what a + line's band's fragments read (varyings and depth across the width) is not compared with Metal's; + and at width 1 in a multisampled pass the runtime's lines are its ordinary ones (Bresenham's where + the device offers them) where Metal draws the parallelogram at the sample positions (MoltenVK's + are Metal's own). - **A heap multisample texture's sample moves on a GPU of 20 GiB or less**: a command queue keeps the images such moves go through up to a sixty-fourth of the device's largest device-local heap