Files
metal2vulkan/crates/metal2vulkan-runtime/src/render/draw_shape.rs
T
Anees Iqbal 057b794f5b SEMANTICS 2115 / RUNTIME 2315: rate-mapped region copies record a box of regions per multi-draw
What: a draw through its region-copy variant recorded its regions 16 at a time (the device's
viewports). Each recording set 16 scissors, pushed its first region and stored DrawIndex as
ViewportIndex. On a guest frame the host step made about 4.7k such recordings a frame (Iris and
RTX 3090), while the GPU sat idle waiting for the step.

The variant's four clip distances already keep each copy to its region's pixels, as a fanned-out
copy's are kept; the per-region scissor only culled. Now:
- The vertex function draws region first + (DrawIndex / c)*nx + DrawIndex mod c from a pushed
  box (PushField::RegionBox, renamed from RegionFirst, now [first, columns]).
- It stores 0 as ViewportIndex, the recording's one viewport, so it writes every output the base
  variant wrote.
- The recording sets one viewport and its box's union scissor.
- A direct draw records a box as many regions at a time as one vkCmdDrawMultiEXT takes
  (maxMultiDrawCount - 1), its rows in order. A run records one recording per box its bounds
  reach; any other draw records the whole table in one or a few.
- Indirect draws keep one region a recording, under that region's scissor.
- The variant still needs shaderOutputViewportIndex and shaderDrawParameters; it no longer
  needs multiViewport.

Exactness: a border between two regions of a recording holds no pixel centre and no sample at
Vulkan's standard sample locations (at least 1/16 px inside a pixel, up to 8 samples), while each
copy's clip distance there is zero up to rounding. A box is recorded one column (row) at a time:
- in a pass whose custom sample positions put a sample on a pixel's left (top) edge;
- on a device without standardSampleLocations;
- in a 16-sample pass.
See render/fan_out.rs, folds.

A box's recording and the recordings of each of its regions alone run one pipeline that writes
the same outputs. They differ only in their dynamic viewport and scissor values and the integer
region each draw selects (Vulkan's Invariance appendix, Rules 2 and 4). The agreement between the
encoder's region-copy vertex function and the host step's fan-out geometry stage stays the
existing FAST-PATHS known gap, checked by running: no new near-equivalent, no new accepted
difference.

SEMANTICS_VERSION 2115 (the variant's module and push layout); ARTIFACT_FORMAT_VERSION 523 (the
PushField tag); RUNTIME_VERSION 2315 (what a region-copy draw records). Docs: rate_mapped_pass.rs,
render/fan_out.rs, bind/fan_out.rs, the translator's region-copy plan and store, docs/API.md, and
the FAST-PATHS fan-out row and known gap. docs/REFUSALS.md regenerated unchanged; api_signatures
blessed. No new Degradation kind, no WorkCounts field.

Tests:
- render/fan_out/tests.rs: run boxes, box recordings, box scissors, the fold rule.
- tests::rate_mapped_region_boxes (device test): the same two passes drawn directly (boxes) and
  indirectly (one region a recording, its own scissor), additively blended into RGBA16Float with
  a ground plane, border-crossing slivers and off-screen and w-straddling triangles, then an
  Equal pass, compared bit for bit, with the recordings counted.

Verified (lane ratemap2):
- msi m3-max-30288 at 9240cc0ea6: clippy -D warnings, all targets and features, plain, cpu_icd
  and m2v_gpu, exit 0; rustdoc -D warnings exit 0; translator touched tests 226/226; runtime
  33/33; lavapipe 13/13.
  - rate_mapped_depth_equal: 0 failing pixels in every pairing under Exact and FanOut. Without
    the ViewportIndex store, FanOut's mixed-route pairings had 2853 of 89483 (m3-max-30235).
  - rate_mapped_region_boxes: direct 3 draws in 3 recordings against indirect 3 in 624, 0 texels
    differ, Equal-pass mismatches [0, 0].
- Negative control (each clip distance widened by one pixel): rate_mapped_region_boxes fails,
  25464 texels differ, Equal-pass mismatches [11019, 0].
- The Iris GPU-time A/B (ms01, m3-max-30315, exclusive) is running; the consumer's renderer run
  at the next pin is the workload proof (rate_map_piece_gpu_nanos a frame on Iris).

Landing note: docs/API.md merged by hand with RUNTIME 2314's probe-parts sentence (both rewrote one
paragraph), and rate_mapped_pass.rs's Fan-out now says the probe runs in parts (RUNTIME 2314).
2026-11-14 14:32:33 -08:00

1100 lines
52 KiB
Rust

//! A draw's shape: what it derives from the encoder's state alone, not from what its tables bind
//! (its settings, [`ShapeInputs::settings`]; its draw state, [`ShapeInputs::draw_state`]; and its
//! `VkPipeline`), the memo that keeps it from one draw of the encoder to the next
//! ([`ShapeMemo`]), and the shapes a drawing state keeps for later encoders ([`KeptShapes`]).
//!
//! - **Inputs.** The derivation reads [`ShapeInputs`] alone: the device, what the pass's layout
//! holds of formats, depth, samples, area and tile memory (`LayoutView`, through which alone it
//! reads the layout), the encoder's state and vertex amplification, whether a visibility query
//! counts the draws, the pass's rasterization-rate map, whether the encoder records an
//! execution's commands, and the routing the encoder kept for its drawing state (a cache of a
//! function of the state and the pass's colors, which changes no piece). The encoder's scissor
//! rectangles are no input: the state holds none (`render_state::ScissorRects`), and the draw
//! state's Vulkan scissors, the one piece that reads them, are each draw's own, set again on a
//! draw state it reuses, so a draw after a new rectangle reuses its shape. Beside them each
//! piece takes the draw's own: its drawing state, assembly and whether it may draw a primitive
//! (`line_width::draws_primitives`); for the draw state its
//! variant's compiled state and what the draw's failing depth and shader-side tests make of it;
//! for the pipeline its graphics key (`DrawKey`) and variant.
//! - **Reuse.** A draw takes a piece an earlier draw of the encoder derived where every input is
//! the same: the drawing state and variant by identity (each held), the assembly, whether it
//! may draw a primitive and whether a query counts by value, and the layout, the state and the
//! amplification by version (`versioned.rs`: any mutable access moves it), but settings that
//! draw a band the translator has since refused for a draw of the state
//! (`GraphicsState::band_refused`); its pipeline where
//! each field of its key is, by value or by what it is made of ([`PipelineInputs`]). The device,
//! the rate map and whether it records an execution's commands do not change in an encoder,
//! whose memo this is; what the pieces read of the device is fixed at its
//! creation (its profile, its depth ranges, its depth bias command, its region limits). Only a
//! piece derived without a refusal is kept, and each is taken at the step of the draw that
//! derives it, so a refused draw is refused by the same step as before.
//! - **Across encoders.** A drawing state keeps the pieces its draws derived, each with the values
//! it was derived from ([`ShapeKey`]: the assembly, whether it may draw a primitive and gives the
//! pass its hidden depth and stencil, whether a query counts it and the encoder records an
//! execution's commands, the layout's facts, every field of the encoder's state but its scissor
//! rectangles, each float by its bits and the depth/stencil state by identity, and the vertex
//! amplification), its latest few ([`KEPT_SHAPES`]). A draw whose encoder's memo holds none of its
//! inputs takes the kept pieces of its own values, as the next frame's pass draws as the one
//! before it (`WorkCounts::draw_shapes_carried`), and its encoder's memo keeps them from then on:
//! the derivation reads nothing those values leave out (the device is the state's, and the rate
//! map and execution are fixed in an encoder; a rate-mapped pass takes and keeps none). A
//! pipeline is taken by its key's fields, the instance's shape and the pass's sample positions
//! by value. Values, not versions: two encoders' layouts and states are other objects.
//! - **Notices.** A derivation announces its notices once per device (`Device::degrade`): a
//! reused piece's were announced as it was derived. A piece whose derivation met a notice the
//! device announces at every occurrence (`DeviceOptions::announce_each`), or refuses at every
//! occurrence while it lowers the call (`DeviceOptions::lowering_refuses`), is not kept, so
//! each draw derives it anew and meets it again (`degradation::EachWatch`, which watches the
//! derivation itself, not a list of the kinds it may announce). A device that announces at
//! every occurrence only kinds a draw's shape does not meet reuses shapes as one that announces
//! each kind once.
//! - **What is not kept.** The pass's hidden depth and stencil a draw gives it, made for that
//! draw before its settings are looked up (`RenderCommandEncoder::needed_hidden`): the settings
//! take only whether it gives them. Nor a pipeline still being made, nor a residual form a draw
//! takes meanwhile (`render/residual.rs`), nor a mesh draw's, of its own specialization.
//! - **Checked.** A debug build derives reused settings and draw states again from the same
//! inputs and asserts them equal, those taken from another encoder too; a reused pipeline's key
//! is compared whole.
//! `WorkCounts::draw_shapes_reused` counts the draws that reused all three.
mod layout_view;
pub(super) use layout_view::{LayoutFacts, LayoutView};
use super::draw_problem;
use super::line_width::{self, LineRoute};
use super::provoking;
use super::{Assembly, DrawSettings, DrawState, Routed, RoutedColors};
use crate::amplification::Amplification;
use crate::color_reformat::{self, Routing};
use crate::degradation::Degradation;
use crate::depth_stencil::FailingDraw;
use crate::device::lock;
use crate::error::{internal, Error, RuntimeGap};
use crate::pipeline::{FixedState, GraphicsState as DrawingState};
use crate::pipeline::{RawPipeline, RenderVariant};
use crate::rate_mapped_pass::RateMappedPass;
use crate::render_pass::HIDDEN_DEPTH_FORMAT;
use crate::render_state::{self, DepthBiasRecord, EncoderState, ScissorRects, ViewportList};
use crate::render_state::{Compensation, DepthBiasEffect, WrittenDepthClamp};
use crate::render_target::PassShape;
use crate::render_values::Viewport;
use crate::sample_positions::Sixteenths;
use crate::versioned::Versioned;
use crate::Device;
use metal2vulkan::bind::BindingPlan;
use metal2vulkan::metal::{PixelFormat, PrimitiveTopologyClass, PrimitiveType, TriangleFillMode};
use metal2vulkan::pipeline::{GraphicsState, Stage};
use std::collections::{BTreeMap, BTreeSet};
use std::sync::{Arc, Mutex};
/// The encoder's part of what a draw's shape is derived from (the module docs):
/// `RenderCommandEncoder::shape_inputs`.
pub(super) struct ShapeInputs<'a> {
pub(super) device: &'a Device,
/// What it reads of the pass's layout ([`LayoutView`]).
pub(super) layout: LayoutView<'a>,
pub(super) state: &'a EncoderState,
pub(super) amplification: &'a Amplification,
/// Whether the pass's draws draw as a visibility query counts them
/// (`RenderCommandEncoder::counts_visibility`).
pub(super) counts_visibility: bool,
pub(super) rate_map: Option<&'a RateMappedPass>,
/// Whether the encoder records an execution's commands (`render/executions.rs`).
pub(super) executes: bool,
/// The routing the encoder kept as its drawing state was set: a cache of a function of the
/// state and the pass's colors alone ([`routing`](Self::routing)).
pub(super) routed: Option<&'a Routed>,
/// The versions of `layout`, `state` and `amplification` (`versioned.rs`).
pub(super) versions: [u64; 3],
}
/// Whether a draw of `pipeline` writes its colors: a fragment function, rasterizing.
pub(super) fn writes_colors(pipeline: &DrawingState) -> bool {
pipeline.descriptor().stage(Stage::Fragment).is_some()
&& !pipeline.base().graphics.rasterizer_discard
}
impl ShapeInputs<'_> {
/// How a draw of `pipeline` stores its colors into the pass's (`color_reformat::Routing`):
/// each state color into the pass color at its place in Metal's per-sample record, for a
/// state that writes colors (Metal probes); each color at its own index for one that writes
/// none. `Err(index)`, refused `AttachmentFormat(Color(index))`, where plain Metal stores part
/// of a color, or more than one, into an attachment (`color_reformat::routing`), `index` the
/// lowest color that moves. The one the encoder kept as `pipeline` was set
/// (`RenderCommandEncoder::set_render_pipeline_state`) where the pass's colors
/// are still the ones it was found for, else found again.
pub(super) fn routing(&self, pipeline: &DrawingState) -> Result<Arc<Routing>, u32> {
let pass = self.layout.formats();
match self.routed {
Some(routed) if routed.state.same(pipeline) && routed.pass == pass => {
routed.routing.clone()
}
_ => pipeline.routed(&pass, || Self::route(pipeline, &pass)),
}
}
/// [`routing`](Self::routing), found for a pass of the colors `pass`.
pub(super) fn route(
pipeline: &DrawingState,
pass: &[Option<PixelFormat>],
) -> Result<Routing, u32> {
let state = pipeline.descriptor().color_formats();
if !writes_colors(pipeline) {
return Ok(Routing::by_index(&state, pass));
}
match color_reformat::routing(&state, pass) {
Some(routing) => Ok(routing),
None => match color_reformat::misplaced(&state, pass) {
Some(index) => Err(index),
None => Ok(Routing::by_index(&state, pass)),
},
}
}
/// The pass colors a draw of `pipeline`, routed by `routing`, zeroes and the colors of its own
/// it drops: those the encoder kept as `pipeline` was set where the pass's colors are still
/// the ones they were found for (a function of the state and those colors alone, as `routing`
/// is), else found again.
pub(super) fn routed_colors(
&self,
pipeline: &DrawingState,
routing: &Routing,
) -> Arc<RoutedColors> {
match self.routed {
Some(Routed {
state,
pass,
colors: Some(colors),
..
}) if state.same(pipeline) && *pass == self.layout.formats() => Arc::clone(colors),
_ => Arc::new(self.colors_by(pipeline, routing)),
}
}
/// [`zeroed_colors`](Self::zeroed_colors) and [`dropped_colors`](Self::dropped_colors) of a
/// draw of `pipeline` routed by `routing`.
pub(super) fn colors_by(&self, pipeline: &DrawingState, routing: &Routing) -> RoutedColors {
let zeroed = self.zeroed_colors(pipeline, routing);
let dropped = self.dropped_colors(pipeline, routing, zeroed.is_empty());
RoutedColors { zeroed, dropped }
}
/// The pass's colors at no place of `pipeline`'s record (`routing`), the pass's format of
/// each by the location the draw references it at, where plain Metal zeroes them at every
/// sample a draw covers (`color_reformat::Uncovered::Zeroed`; Metal probes, probes): a draw
/// runs the variant whose fragment function writes the zero (`BindShape::zeroed_colors`). Empty
/// where Metal keeps them (a state color blended reading the destination, or writing some of
/// its channels alone), and for a mesh render pipeline's state and a state that writes no color
/// (what Metal stores there is unmeasured), which are refused such a pass.
pub(super) fn zeroed_colors(
&self,
pipeline: &DrawingState,
routing: &Routing,
) -> BTreeMap<u32, PixelFormat> {
let descriptor = pipeline.descriptor();
let colors = descriptor.color_attachments();
let zeroed = color_reformat::uncovered(colors.iter().flatten());
if descriptor.vertex().is_none()
|| !writes_colors(pipeline)
|| zeroed != color_reformat::Uncovered::Zeroed
{
return BTreeMap::new();
}
let formats = self.layout.formats();
routing
.uncovered
.iter()
.filter_map(|(&location, &index)| {
let format = (*formats.get(index as usize)?)?;
Some((location, format))
})
.collect()
}
/// The locations where `pipeline`'s fragment function's writes plain Metal drops (a Metal
/// probe): a draw runs the variant whose fragment function keeps no output there
/// (`BindShape::dropped_colors`), so its pipeline writes no location without an attachment,
/// and none into a pass color it keeps. They are the state's colors at no place of the pass's
/// record (`routing`); a pass color the draw keeps (`none_zeroed`: its `zeroed_colors` names
/// none), at whose location the state has no color; and in a routed draw each location its
/// subpass leaves out where the state has no color, which the function may write all the same.
/// Empty for a state without a fragment function, which writes no color.
fn dropped_colors(
&self,
pipeline: &DrawingState,
routing: &Routing,
none_zeroed: bool,
) -> BTreeSet<u32> {
let descriptor = pipeline.descriptor();
if descriptor.vertex().is_some_and(|d| d.fragment.is_none()) {
return BTreeSet::new();
}
let state = descriptor.color_formats();
let lacks = |location: u32| {
state
.get(location as usize)
.copied()
.flatten()
.is_none_or(|pf| pf == PixelFormat::Invalid)
};
let mut dropped = routing.dropped.clone();
if writes_colors(pipeline) && none_zeroed {
dropped.extend(routing.uncovered.keys().copied().filter(|&l| lacks(l)));
}
let left_out = (0u32..).zip(&routing.locations);
dropped.extend(
left_out
.filter(|&(l, index)| index.is_none() && lacks(l))
.map(|(l, _)| l),
);
dropped
}
/// What a draw of `pipeline` as `assembly`, which may draw a primitive where `primitives`
/// (`line_width::draws_primitives`), settles from the encoder's state before its bind state
/// ([`DrawSettings`]), as a draw settles it and as an execution's precompile at commit does
/// (`render/executions.rs`), `hidden` where the draw gives the pass its hidden depth and
/// stencil (`RenderCommandEncoder::needed_hidden`). Where the draw keeps Vulkan's clipping of
/// points, rasterizes points of a size the device bounds below Metal's, or a depth the
/// fragment function writes past Metal's clamp, that is announced once where `announce`: the
/// precompile, which draws nothing, announces nothing. Refused
/// as `call`'s draw is.
pub(super) fn settings(
&self,
call: &'static str,
(pipeline, assembly, primitives): (&DrawingState, Assembly, bool),
hidden: bool,
announce: bool,
) -> Result<DrawSettings, Error> {
let meshes = pipeline.descriptor().vertex().is_none();
// A draw of another class than the pipeline's input primitive topology class, which
// Metal's validation stops, draws its own primitives, as plain Metal draws them (a probe).
// Points rasterize nothing unless the vertex function writes a point size or the class is
// the point class, which sizes them 1 (probes 1 and 2, the vertex function run for every
// point either way): the draw runs its vertex function alone, through empty scissors.
let class = pipeline
.descriptor()
.vertex()
.map_or(PrimitiveTopologyClass::Unspecified, |d| {
d.input_primitive_topology
});
let unsized_points = matches!(assembly, Assembly::Primitives(PrimitiveType::Point))
&& class != PrimitiveTopologyClass::Point
&& !pipeline.base().graphics.writes_point_size;
let (topology, primitive_restart) = match assembly {
Assembly::Primitives(primitive_type) => {
metal2vulkan::metal::state::input_assembly(primitive_type)
}
// A private type draws its program's list, without restart (`render/restart.rs`).
Assembly::Private(program) => match program.vertices() {
2 => (metal2vulkan::vk::PrimitiveTopology::LINE_LIST, false),
_ => (metal2vulkan::vk::PrimitiveTopology::TRIANGLE_LIST, false),
},
// An emulated tessellation pipeline draws the tessellator's triangles as a list,
// which Vulkan biases as Metal biases them.
Assembly::Patches => match pipeline.base().graphics.emulated_tessellation {
Some(_) => (metal2vulkan::vk::PrimitiveTopology::TRIANGLE_LIST, false),
None => (metal2vulkan::vk::PrimitiveTopology::PATCH_LIST, false),
},
// A mesh pipeline has no input assembly. Its key takes a triangle list, which
// enables the depth bias Metal applies to triangles: Vulkan biases a mesh function's
// triangles and none of its lines or points, as Metal does. An emulated mesh
// function's synthesized vertex stage draws a list of the mesh's topology, which
// Vulkan biases alike.
Assembly::Meshes => match &pipeline.base().graphics.mesh_records {
Some(records) => (records.topology(), false),
None => (metal2vulkan::vk::PrimitiveTopology::TRIANGLE_LIST, false),
},
};
// The pass's depth and stencil: its attachment's, or the hidden ones a draw whose state
// uses depth or the stencil the pass lacks gives it from that draw on, as plain Metal
// tests such a draw (its validation stops it; `render_state.rs`).
let ds = self.layout.depth_stencil();
let depth = ds.is_some_and(|ds| ds.depth);
// A compare of `Never` without Metal's depth attachment fails every fragment (probes), the
// hidden depth's too: the draw runs as `FailingDraw` says.
let metal_depth = depth && !ds.is_some_and(|ds| ds.hidden);
let failing_state = self.state.failing_depth(metal_depth).cloned();
let max = pipeline.base().graphics.max_vertex_amplification_count;
let mut amplification = self
.amplification
.bind_state(max)
.map_err(|problem| draw_problem(call, problem))?;
// A query counts an amplified draw drawn one amplification at a time, as Metal counts
// every amplification's samples: a multiview instance's would take one per view. Over a
// rate map whose layers differ each amplification records its own slice's regions
// (`rate_mapped_pass.rs`).
amplification.one_at_a_time = self.counts_visibility
|| self
.rate_map
.as_ref()
.is_some_and(|pass| !pass.layers_alike());
// The pass's tile threadgroup memory, which the fragment function's threadgroup
// arguments read, as a tile dispatch's do (`render/tile_memory.rs`): its tiles, and the
// arguments the encoder set.
let tiles = match pipeline.reads_tile_memory() {
true => {
let tile = self.layout.tile_size()?;
Some((tile, self.layout.tile_area(tile)))
}
false => None,
};
// The viewports a Vulkan viewport cannot be, compensated by the vertex function's
// variant; a pipeline that rasterizes nothing draws through no viewport.
let base = &pipeline.base().graphics;
let device = self.device;
let native = render_state::native_depth_range(device);
// A saturating or offsetting depth bias folds into a compensated depth, or is refused
// there (`EncoderState::compensation`).
let bias = self
.state
.draw_bias(topology, device.compile_device().profile())?;
// A clamp mode one clamp of one depth collapses the Vulkan range to it where the
// fragment function reads no depth of its position (`render_state::OneDepth`).
let one_depth = render_state::OneDepth::of(device, base);
// Metal clamps each vertex's depth before the interpolation: the vertex stage's
// compensation does too where it can, natively as well (`render_state::VertexClamp`).
let vertex_clamp = render_state::VertexClamp::of(
device, self.state, base, topology, meshes, bias, announce,
);
let selects = base.writes_viewport_index;
let compensation = match base.rasterizer_discard {
true => None,
false => match self
.state
.compensation(selects, native, bias, one_depth, vertex_clamp)
{
// Natively, viewports whose clamped depths need different compensations keep
// the device's ranges, each sample clamped.
Err(Error::NotImplemented(RuntimeGap::ViewportDepthRange))
if native && vertex_clamp.takes =>
{
let unclamped = render_state::VertexClamp::default();
let kept = self
.state
.compensation(selects, native, bias, one_depth, unclamped)?;
render_state::VertexClamp::kept(
device,
self.state,
selects,
"the draw's viewports have different depth ranges, and the vertex stage \
holds one compensation",
announce,
);
kept
}
compensation => compensation?,
},
};
render_state::VertexClamp::taken(device, self.state, selects, compensation, announce);
// A fragment function that writes its depth, in depth clamp mode through a range above
// 0, clamps the depth to the range itself under a Vulkan clamp that holds 0, as Metal
// stores a negative NaN as 0 there (`render_state::written_depth_clamp`).
let written_clamp = match base.writes_depth && !base.rasterizer_discard {
true => render_state::written_depth_clamp(
device,
self.state,
base.writes_viewport_index,
topology,
base.clip_distances,
meshes,
announce,
)?,
false => None,
};
// A positive NaN it writes runs no stencil depth-failure operation, where Metal runs one:
// announced once (`render_state::announce_nan_depth_failure`).
if announce && base.writes_depth && !base.rasterizer_discard {
render_state::announce_nan_depth_failure(device, self.state);
}
// Points that rasterize, which Metal sizes none of: Metal's are undefined, and the
// runtime's none is one of its answers. Announced at the draw, which for an execution's
// command is where the runtime records it (its commit, or its host step).
if announce && unsized_points && !base.rasterizer_discard {
device.degrade(Degradation::UnsizedPoints, || {
(
format!(
"{call}: a draw of points under a pipeline state whose vertex function \
writes no point size, of the {class:?} input primitive topology class"
),
"Metal sizes no point outside the point class without a point size, and \
what it draws there is undefined"
.to_owned(),
)
});
}
// A triangle's vertices drawn as points (fill mode `Points`) take the size the vertex
// function writes where Metal draws one pixel: announced once at the draw, as above.
let triangle_points = !base.rasterizer_discard
&& base.writes_point_size
&& self.state.fill_mode() == TriangleFillMode::Points
&& matches!(
topology,
metal2vulkan::vk::PrimitiveTopology::TRIANGLE_LIST
| metal2vulkan::vk::PrimitiveTopology::TRIANGLE_STRIP
| metal2vulkan::vk::PrimitiveTopology::TRIANGLE_FAN
);
if announce && triangle_points {
device.degrade(Degradation::TrianglePointSize, || {
(
format!(
"{call}: a draw of triangles in fill mode Points under a pipeline state \
whose vertex function writes a point size"
),
"the device sizes a polygon's points by the point size the last stage \
writes (polygonModePointSize), where Metal draws one pixel"
.to_owned(),
)
});
}
// A point size the vertex or mesh function writes past the device's largest point, which
// draws at that bound: announced once at a draw that rasterizes points, a mesh draw's
// points its mesh function's (`GraphicsState::mesh_corners`), and at no other draw, whose
// primitives no point size sizes (`Device::degrade_point_size`).
let rasterizes_points = !base.rasterizer_discard
&& match assembly {
Assembly::Meshes => base.mesh_corners == Some(1),
_ => topology == metal2vulkan::vk::PrimitiveTopology::POINT_LIST,
};
if announce && rasterizes_points {
device.degrade_point_size(call, &pipeline.base().stages);
}
let compensation = written_clamp.and_then(|w| w.compensation).or(compensation);
// A draw of points takes Metal's guard band where it can, else keeps Vulkan's clipping
// of points, announced once (`render_state::guard_points`). Unsized points rasterize
// nothing, and a mesh pipeline's points are unmeasured on Metal.
let points = topology == metal2vulkan::vk::PrimitiveTopology::POINT_LIST
&& !meshes
&& !base.rasterizer_discard
&& !unsized_points;
let compensation = match points {
false => compensation,
true => render_state::guard_points(
device,
self.state,
base.writes_viewport_index,
compensation,
base.clip_distances,
self.rate_map.is_some(),
announce,
),
};
// The pass's colors the pipeline lacks, zeroed where the draw covers them, and the
// pipeline's colors the pass lacks, whose writes are dropped.
// Each by its place in Metal's per-sample record (`routing`), the draw's subpass
// referencing each pass color at the location the state's color there writes.
let routing = self
.routing(pipeline)
.map_err(|_| internal("a draw of a state its pass refuses"))?;
let routed_colors = self.routed_colors(pipeline, &routing);
// A compensated depth, which a vertex clamp takes natively too, replaces the native
// range (`clamp_draw_depth`).
let compensated = compensation.is_some_and(|c| c.depth.is_some());
let native = native && !compensated;
// How it draws its lines at the encoder's width, and a band's push: Vulkan viewport 0's
// half extent, its height negative as the Y-flipped viewport's is, the half width, and a
// triangle's band's front face (`render/line_width.rs`). A band takes its flat inputs
// from its first vertex.
let line = self.line_route(call, (pipeline, assembly, primitives), announce);
let line_band = match line {
LineRoute::Band { .. } => {
let viewports =
EncoderState::vk_viewports(&self.state.used_viewports(false)[..1], None, None);
let v = viewports[0];
line.band_push([v.width / 2.0, v.height / 2.0], self.state.vk_front_face())
}
_ => None,
};
let provoking_last =
!line.band() && provoking::natively_last(device, self.state, (pipeline, assembly));
Ok(DrawSettings {
unsized_points,
topology,
primitive_restart,
hidden,
failing_state,
amplification,
tiles,
native,
compensation,
written_clamp,
bias,
routing,
routed_colors,
provoking_last,
line,
line_band,
})
}
/// The state a draw of `graphics`, its variant's, takes statically before its depth range
/// ([`clamp_draw_depth`](Self::clamp_draw_depth)): the encoder's; a failing draw's depth and
/// stencil, masking the colors; and no stencil test where the function is the test (`shadow`, a
/// shader-side stencil).
pub(super) fn draw_fixed(
&self,
graphics: &GraphicsState,
failing: Option<&FailingDraw>,
(shadow, shader_tests): (bool, bool),
) -> Result<FixedState, Error> {
let profile = self.device.compile_device().profile();
let selects = graphics.writes_viewport_index;
// An amplification's viewport offset selects among the encoder's viewports too; on a
// device without `multiViewport` its variant stores no `ViewportIndex` (a draw there has
// one viewport), exact only while the encoder holds one.
if self.amplification.offsets_viewports() && self.state.viewport_count(true) > 1 {
EncoderState::needs_viewports(profile)?;
}
let mut fixed = self
.state
.fixed(self.state.viewport_count(selects), profile)?;
if let Some(FailingDraw::Runs(failing) | FailingDraw::Fails(failing)) = failing {
fixed.depth_stencil = metal2vulkan::metal::state::depth_stencil_state(failing);
fixed.masks_color = true;
}
// The function is the stencil test: the pass's own is off, and never writes the stencil.
if shadow {
fixed.depth_stencil.stencil_test_enable = false;
}
// The function is the depth test: the pass's own passes every fragment and never writes
// the depth, and the stencil test is off (the binder refuses a draw whose stencil test
// could drop or change anything).
if shader_tests {
let ds = &mut fixed.depth_stencil;
ds.depth_test_enable = true;
ds.depth_compare_op = metal2vulkan::vk::CompareOp::ALWAYS;
ds.depth_write_enable = false;
ds.stencil_test_enable = false;
}
Ok(fixed)
}
/// `fixed`'s depth range and clamp, for a draw of `graphics` under its settings' `native`,
/// `written_clamp`, `compensation` and `bias` ([`DrawSettings`]): a depth range past
/// `[0, 1]`, which the device takes natively, clamped, clipped or not (a clamp-mode saturated
/// depth where Metal stores it), elsewhere the vertex stage's compensation, whose clip
/// distances clip and whose Vulkan range `depthClamp` clamps to; and for a fragment function
/// that clamps its depth to the range itself, a Vulkan clamp that holds 0 and the range.
pub(super) fn clamp_draw_depth(
&self,
fixed: &mut FixedState,
graphics: &GraphicsState,
(native, written_clamp, compensation, bias): (
bool,
Option<WrittenDepthClamp>,
Option<Compensation>,
Option<DepthBiasEffect>,
),
) -> Result<(), Error> {
fixed.depth_range = match (native, written_clamp.and_then(|w| w.native)) {
(true, Some(range)) => Some(range),
(true, None) => self
.state
.depth_range(graphics.writes_viewport_index, bias)?,
(false, _) => None,
};
let depth = compensation.and_then(|c| c.depth);
fixed.depth_clamp |= fixed.depth_range.is_some() || depth.is_some();
Ok(())
}
/// The state a draw of `graphics`, its variant's, records with under `settings`
/// ([`DrawState`]: statically, or as dynamic state), through the encoder's `scissors`, failing
/// as `failing` says, its fragment
/// function the stencil test (`shadow`, a shader-side stencil) or the depth test (`tests`);
/// with the viewports in Metal's terms and the compensated
/// depth range a rate-mapped pass draws each region through (`rate_mapped_pass.rs`). A 16-bit
/// unorm depth's notice and an unclamped bias's are announced.
pub(super) fn draw_state(
&self,
graphics: &GraphicsState,
settings: &DrawSettings,
(failing, shadow, tests): (Option<&FailingDraw>, bool, bool),
scissors: &ScissorRects,
) -> Result<ShapedState, Error> {
let device = self.device;
let profile = device.compile_device().profile();
let selects = graphics.writes_viewport_index;
let topology = settings.topology;
let (native, compensation) = (settings.native, settings.compensation);
let bias_effect = settings.bias;
let mut fixed = self.draw_fixed(graphics, failing, (shadow, tests))?;
fixed.provoking_last = settings.provoking_last;
settings.line.fix(&mut fixed);
// The depth the draw renders against: the pass's attachment's, or the hidden one's,
// which Metal biases as the 32-bit float depth it is.
let depth_format = (self.layout.depth_stencil())
.and_then(|ds| ds.depth_format)
.or(settings.hidden.then_some(HIDDEN_DEPTH_FORMAT));
let bias = self.state.vk_depth_bias(topology, profile)?;
let depth_bias = DepthBiasRecord::of(&bias);
// A band of a triangle's edges is biased by its own triangles' slopes and depths
// (`render/line_width.rs`).
line_width::announce_band_bias(device, settings.line, depth_format, &bias);
// A 16-bit unorm depth, biased or not, stores Metal's codes where the driver is measured
// to (`render_state::announce_unorm_depth`).
render_state::announce_unorm_depth(device, depth_format, &fixed.depth_stencil, &bias);
// In clip mode a natively ranged device clamps a biased depth to `[0, 1]`
// (`EncoderState::depth_range`); one that stores it unclamped without that announces it.
if !graphics.rasterizer_discard {
let compensated = compensation.is_some_and(|c| c.depth.is_some());
render_state::announce_unclamped_bias(device, self.state, bias_effect, compensated);
}
// A compensated depth's Vulkan range replaces the viewports' ranges, a saturating or
// offsetting bias folded into the compensation (`EncoderState::compensation`).
let depth = compensation.and_then(|c| c.depth);
let viewports = match depth {
Some(_) => self.state.used_viewports(selects).iter().copied().collect(),
None => self
.state
.draw_viewports(selects, topology, profile, native)?,
};
let clamp = (native, settings.written_clamp, compensation, bias_effect);
self.clamp_draw_depth(&mut fixed, graphics, clamp)?;
let state = DrawState {
viewports: EncoderState::vk_viewports(
&viewports,
depth,
compensation.and_then(|c| c.guard),
),
scissors: self.state.vk_scissors(scissors, selects),
fixed,
stencil_reference: self.state.stencil_reference(),
depth_bias,
blend_color: self.state.blend_color(),
draws: 1,
region_box: None,
};
Ok(ShapedState {
state,
viewports,
depth,
})
}
}
/// A draw's state as it records it ([`DrawState`]), and what a rate-mapped pass draws each of its
/// regions through: the draw's viewports in Metal's terms, and its compensated depth range
/// ([`ShapeInputs::draw_state`]).
#[derive(Clone, PartialEq)]
pub(super) struct ShapedState {
pub(super) state: DrawState,
pub(super) viewports: ViewportList<Viewport>,
pub(super) depth: Option<[f32; 2]>,
}
/// The most entries a memo keeps: a pass's draws take a few drawing states and assemblies in turn
/// (a layer's and its shadow's; strips and indexed lists), each its own entry.
const ENTRIES: usize = 4;
/// The pieces of the encoder's draws' shapes, each with what it was derived from (the module
/// docs): an entry for each of the latest few settings' inputs, held in place, so a draw that
/// keeps one allocates nothing for it and a draw that finds one moves none.
#[derive(Default)]
pub(super) struct ShapeMemo {
/// `None` where none was kept.
entries: [Option<Entry>; ENTRIES],
/// The count of draws that found or kept an entry: an entry's id, and its last use.
ticks: u64,
}
/// The pieces derived under one draw's settings' inputs.
struct Entry {
/// Its own, which the draw that found or kept it holds ([`ShapeToken`]).
id: u64,
/// The tick of the last draw that found or kept it: the least recent goes first.
used: u64,
/// The drawing state, held: compared by identity.
pipeline: DrawingState,
assembly: Assembly,
/// Whether the draw may draw a primitive (`line_width::draws_primitives`).
primitives: bool,
/// [`ShapeInputs::versions`] and [`ShapeInputs::counts_visibility`].
versions: [u64; 3],
counts_visibility: bool,
/// Held behind one count, which the drawing state's kept shapes share ([`KeptShapes`]): a
/// draw that finds them copies none.
settings: Arc<DrawSettings>,
/// The draw state of a draw of the variant, held, which the drawing state's kept shapes
/// share.
state: Option<Arc<KeptState>>,
found: Option<Arc<FoundPipeline>>,
}
/// A draw's hold on the memo entry its settings came from or went into, where its draw state and
/// pipeline are found and kept: its place, and its id.
#[derive(Clone, Copy)]
pub(super) struct ShapeToken {
at: usize,
id: u64,
}
/// What a draw finds its `VkPipeline` by (its graphics key, `DrawKey`, and its variant), each
/// field by value or by what it is made of: its variant and plan (the plan's specialization),
/// its instance's shape (by version, else by value: another instance of the same shape, a later
/// encoder's among them, finds it), the pass's sample positions, its vertex strides (the
/// pipeline's own, none where it takes them as dynamic state), its fixed state before the
/// pipeline's dynamic states are left out, and its keyed topology. Not the pass it was made
/// against: the key names the shape (`DrawKey::pass`), and one pipeline of a key draws in every
/// pass of that shape, each compatible with the others.
pub(super) struct PipelineInputs<'k> {
pub(super) variant: &'k Arc<RenderVariant>,
pub(super) plan: &'k Arc<BindingPlan>,
pub(super) shape: &'k Versioned<PassShape>,
pub(super) sample_positions: &'k [Sixteenths],
pub(super) strides: &'k [(u32, u32)],
pub(super) fixed: FixedState,
pub(super) topology: (metal2vulkan::vk::PrimitiveTopology, bool),
}
/// A `VkPipeline` a draw found made, with what it found it by ([`PipelineInputs`], held).
struct FoundPipeline {
variant: Arc<RenderVariant>,
plan: Arc<BindingPlan>,
/// The instance's shape, by its version and its value.
shape: (u64, PassShape),
sample_positions: Vec<Sixteenths>,
/// Inline: a draw's strides are few, none where the pipeline takes them as dynamic state.
strides: ViewportList<(u32, u32)>,
fixed: FixedState,
topology: (metal2vulkan::vk::PrimitiveTopology, bool),
made: Arc<RawPipeline>,
}
impl FoundPipeline {
/// Found by `inputs` and made as `made`.
fn of(inputs: &PipelineInputs<'_>, made: &Arc<RawPipeline>) -> FoundPipeline {
FoundPipeline {
variant: Arc::clone(inputs.variant),
plan: Arc::clone(inputs.plan),
shape: (inputs.shape.version(), (**inputs.shape).clone()),
sample_positions: inputs.sample_positions.to_vec(),
strides: inputs.strides.iter().copied().collect(),
fixed: inputs.fixed,
topology: inputs.topology,
made: Arc::clone(made),
}
}
/// Whether it was found by `inputs`.
fn by(&self, inputs: &PipelineInputs<'_>) -> bool {
Arc::ptr_eq(&self.variant, inputs.variant)
&& Arc::ptr_eq(&self.plan, inputs.plan)
&& (self.shape.0 == inputs.shape.version() || self.shape.1 == **inputs.shape)
&& *self.sample_positions == *inputs.sample_positions
&& *self.strides == *inputs.strides
&& self.fixed == inputs.fixed
&& self.topology == inputs.topology
}
}
/// What a draw's settings, draw state and pipeline are derived from but its drawing state, by
/// value: its assembly, whether it may draw a primitive and gives the pass its hidden depth and
/// stencil, whether a query counts it, whether the encoder records an execution's commands, the
/// pass's [`LayoutFacts`], the encoder's state (`EncoderState::same_values`) and its vertex
/// amplification. The device is the drawing state's, and the pieces read nothing else of it
/// that changes (the module docs).
struct ShapeKey {
assembly: Assembly,
primitives: bool,
hidden: bool,
counts_visibility: bool,
executes: bool,
layout: LayoutFacts,
state: EncoderState,
amplification: Amplification,
}
impl ShapeKey {
/// The key of a draw as `assembly`, which may draw a primitive where `primitives` and gives
/// the pass its hidden depth and stencil where `hidden`, under `inputs`.
fn of(
inputs: &ShapeInputs<'_>,
(assembly, primitives): (Assembly, bool),
hidden: bool,
) -> Self {
ShapeKey {
assembly,
primitives,
hidden,
counts_visibility: inputs.counts_visibility,
executes: inputs.executes,
layout: inputs.layout.facts(),
state: inputs.state.clone(),
amplification: inputs.amplification.clone(),
}
}
/// Whether it is [`of`](Self::of) those, compared by value, `layout` the facts of `inputs`'s.
fn holds(
&self,
(inputs, layout): (&ShapeInputs<'_>, &LayoutFacts),
(assembly, primitives): (Assembly, bool),
hidden: bool,
) -> bool {
self.assembly == assembly
&& self.primitives == primitives
&& self.hidden == hidden
&& self.counts_visibility == inputs.counts_visibility
&& self.executes == inputs.executes
&& self.layout == *layout
&& self.state.same_values(inputs.state)
&& self.amplification == *inputs.amplification
}
}
/// The most shapes a drawing state keeps of those its draws derived ([`KeptShapes`]): a window
/// server's frame draws one state in a few passes of their own sizes, as a few assemblies, each
/// a shape of its own.
const KEPT_SHAPES: usize = 8;
/// The shapes the draws of one drawing state derived, each with the values it was derived from
/// ([`ShapeKey`]), held in place: at most [`KEPT_SHAPES`], the one found or kept least lately
/// giving its place to a new one. Where a draw finds no piece in its encoder's memo, it takes the
/// one of these its own values derived, as an earlier encoder's draw derived it (the module docs).
#[derive(Default)]
pub(crate) struct KeptShapes(Mutex<Kept>);
/// [`KeptShapes`]' places, and the count of the draws that found or kept one: a place's last use.
#[derive(Default)]
struct Kept {
shapes: [Option<KeptShape>; KEPT_SHAPES],
ticks: u64,
}
/// One of a drawing state's kept shapes: the pieces a draw of its key derived ([`Entry`]), each
/// behind a count the encoders' memos share.
struct KeptShape {
key: ShapeKey,
used: u64,
settings: Arc<DrawSettings>,
state: Option<Arc<KeptState>>,
found: Option<Arc<FoundPipeline>>,
}
/// A draw state a draw of the variant derived, held.
type KeptState = (Arc<RenderVariant>, ShapedState);
/// The pieces a draw takes from its drawing state's kept shapes ([`ShapeInputs::carried`]).
pub(super) struct Carried {
settings: Arc<DrawSettings>,
state: Option<Arc<KeptState>>,
found: Option<Arc<FoundPipeline>>,
}
impl Carried {
/// The settings.
pub(super) fn settings(&self) -> &Arc<DrawSettings> {
&self.settings
}
}
impl Kept {
/// The shape kept under `settings` (the very ones).
fn under(&mut self, settings: &Arc<DrawSettings>) -> Option<&mut KeptShape> {
(self.shapes.iter_mut().flatten()).find(|shape| Arc::ptr_eq(&shape.settings, settings))
}
}
impl ShapeInputs<'_> {
/// The pieces a draw of `pipeline` as `assembly`, which may draw a primitive where
/// `primitives` and gives the pass its hidden depth and stencil where `hidden`, takes from
/// the shapes the state's draws derived ([`KeptShapes`]): those of its own values, used now;
/// none in a rate-mapped pass, whose map they would read.
pub(super) fn carried(
&self,
(pipeline, assembly, primitives): (&DrawingState, Assembly, bool),
hidden: bool,
) -> Option<Carried> {
if self.rate_map.is_some() {
return None;
}
let layout = self.layout.facts();
let mut kept = lock(&pipeline.kept_shapes().0);
kept.ticks += 1;
let ticks = kept.ticks;
let shape = (kept.shapes.iter_mut().flatten()).find(|shape| {
shape
.key
.holds((self, &layout), (assembly, primitives), hidden)
&& !shape.settings.line.band_refused_by(pipeline)
})?;
shape.used = ticks;
Some(Carried {
settings: Arc::clone(&shape.settings),
state: shape.state.clone(),
found: shape.found.clone(),
})
}
/// Keep `settings`, derived for a draw of `pipeline` as `assembly`, which may draw a
/// primitive where `primitives` and gives the pass its hidden depth and stencil where
/// `hidden`, among the state's kept shapes ([`KeptShapes`]); not in a rate-mapped pass.
pub(super) fn keep_carried(
&self,
(pipeline, assembly, primitives): (&DrawingState, Assembly, bool),
hidden: bool,
settings: &Arc<DrawSettings>,
) {
if self.rate_map.is_some() {
return;
}
let key = ShapeKey::of(self, (assembly, primitives), hidden);
let mut kept = lock(&pipeline.kept_shapes().0);
kept.ticks += 1;
let used = kept.ticks;
let at = (0..KEPT_SHAPES)
.min_by_key(|&at| kept.shapes[at].as_ref().map_or(0, |shape| shape.used))
.unwrap_or_default();
kept.shapes[at] = Some(KeptShape {
key,
used,
settings: Arc::clone(settings),
state: None,
found: None,
});
}
}
impl ShapeMemo {
/// The settings an earlier draw of `pipeline` as `assembly`, which may draw a primitive where
/// `primitives`, derived under the encoder's `versions` and query count, with the token of
/// their entry, which is used now.
pub(super) fn settings(
&mut self,
(pipeline, assembly, primitives): (&DrawingState, Assembly, bool),
(versions, counts_visibility): ([u64; 3], bool),
) -> Option<(Arc<DrawSettings>, ShapeToken)> {
self.ticks += 1;
let (at, entry) = (0..).zip(&mut self.entries).find_map(|(at, entry)| {
let entry = entry.as_mut().filter(|entry| {
entry.pipeline.same(pipeline)
&& entry.assembly == assembly
&& entry.primitives == primitives
&& entry.versions == versions
&& entry.counts_visibility == counts_visibility
&& !entry.settings.line.band_refused_by(pipeline)
})?;
Some((at, entry))
})?;
entry.used = self.ticks;
let token = ShapeToken { at, id: entry.id };
Some((Arc::clone(&entry.settings), token))
}
/// Keep `settings`, derived for a draw of `pipeline` as `assembly`, which may draw a
/// primitive where `primitives`, under the encoder's `versions` and query count, in a new
/// entry, in place of the least recently used of [`ENTRIES`]: its token.
pub(super) fn keep_settings(
&mut self,
drawn: (&DrawingState, Assembly, bool),
inputs: ([u64; 3], bool),
settings: &Arc<DrawSettings>,
) -> ShapeToken {
let carried = Carried {
settings: Arc::clone(settings),
state: None,
found: None,
};
self.keep(drawn, inputs, carried)
}
/// Keep `carried`, the pieces an earlier encoder's draw derived for a draw of `pipeline` as
/// `assembly`, which may draw a primitive where `primitives` ([`ShapeInputs::carried`]),
/// under the encoder's `versions` and query count, as [`keep_settings`](Self::keep_settings)
/// keeps settings: its token.
pub(super) fn keep(
&mut self,
(pipeline, assembly, primitives): (&DrawingState, Assembly, bool),
(versions, counts_visibility): ([u64; 3], bool),
carried: Carried,
) -> ShapeToken {
self.ticks += 1;
let at = (0..ENTRIES)
.min_by_key(|&at| self.entries[at].as_ref().map_or(0, |entry| entry.used))
.unwrap_or_default();
let Carried {
settings,
state,
found,
} = carried;
self.entries[at] = Some(Entry {
id: self.ticks,
used: self.ticks,
pipeline: pipeline.clone(),
assembly,
primitives,
versions,
counts_visibility,
settings,
state,
found,
});
ShapeToken { at, id: self.ticks }
}
fn entry(&self, token: ShapeToken) -> Option<&Entry> {
(self.entries[token.at].as_ref()).filter(|entry| entry.id == token.id)
}
fn entry_mut(&mut self, token: ShapeToken) -> Option<&mut Entry> {
(self.entries[token.at].as_mut()).filter(|entry| entry.id == token.id)
}
/// The draw state a draw of `variant` derived under `token`'s settings.
pub(super) fn state(
&self,
token: ShapeToken,
variant: &Arc<RenderVariant>,
) -> Option<ShapedState> {
let (kept, state) = &**self.entry(token)?.state.as_ref()?;
Arc::ptr_eq(kept, variant).then(|| state.clone())
}
/// Keep `state`, a draw of `variant`'s derived under `token`'s settings, here and among the
/// drawing state's kept shapes where it keeps the settings.
pub(super) fn keep_state(
&mut self,
token: ShapeToken,
variant: &Arc<RenderVariant>,
state: &ShapedState,
) {
if let Some(entry) = self.entry_mut(token) {
let kept = Arc::new((Arc::clone(variant), state.clone()));
if let Some(shape) = lock(&entry.pipeline.kept_shapes().0).under(&entry.settings) {
shape.state = Some(Arc::clone(&kept));
}
entry.state = Some(kept);
}
}
/// The `VkPipeline` a draw found made by `inputs` under `token`'s settings and its variant's
/// draw state.
pub(super) fn pipeline(
&self,
token: ShapeToken,
inputs: &PipelineInputs<'_>,
) -> Option<Arc<RawPipeline>> {
let found = self.entry(token)?.found.as_ref()?;
found.by(inputs).then(|| Arc::clone(&found.made))
}
/// Keep `made`, the `VkPipeline` a draw found made by `inputs` under `token`'s settings, here
/// and among the drawing state's kept shapes where it keeps the settings.
pub(super) fn keep_pipeline(
&mut self,
token: ShapeToken,
inputs: &PipelineInputs<'_>,
made: &Arc<RawPipeline>,
) {
if let Some(entry) = self.entry_mut(token) {
let found = Arc::new(FoundPipeline::of(inputs, made));
if let Some(shape) = lock(&entry.pipeline.kept_shapes().0).under(&entry.settings) {
shape.found = Some(Arc::clone(&found));
}
entry.found = Some(found);
}
}
}