Draw a split depth/stencil resolve's drawn aspect into its own texture

Metal resolves separate Depth32Float and Stencil8 textures with the
depth filter Min or Max beside the stencil filter Sample0, each into its
own resolve texture. On a device with no MIN or MAX depth resolve mode
(lavapipe) the runtime draws the picked depth after the pass, but a
split resolve (aspects resolving into different textures) refused any
drawn aspect NotImplemented(DepthStencilResolve): the draws wrote the
first step's scratch image, whose copy takes that step's aspect alone.

Now a split resolve draws its drawn aspect into that aspect's own
resolve texture (or a scratch image copied there, Destination::attach),
held as the resolve's drawn_into, which drawn_target prefers; the other
aspect resolves in its subpass step as before. Both aspects drawn, each
into its own texture, stays refused. The image separate textures render
through is made sampled where such a resolve may be drawn
(resolve::may_draw, which shares the filter-to-mode choice with
depth_stencil through aspect_modes), since the draws read its samples.

The ledger's two llvmpipe rows of resolve-stencil-under-depth-filters
(Sample0 under Min and Max) go. The lane test
split_depth_and_stencil_resolves_are_metals now expects every case but
both-aspects-drawn to be built and to hold Metal's answers; before this
change sep_min, sep_max, two_min, two_max and slices_max were refused
on lavapipe. Verified on lavapipe: the lane test and the conformance
replay (see the tip report).

(cherry picked from commit c2b4cbc80bf7f8f209d02ecbd5e5aec186b04d96)
This commit is contained in:
Anees Iqbal committed 2026-11-07 07:28:20 -08:00
1 parent 394b4db3f6
commit 0d368fbfe7
7 files changed
+192 -80

No files matched your search

@@ -466,8 +466,6 @@ pixel-samplers-rgba16f-nearest-zero NVIDIA GeForce RTX 5080 Laptop GPU divergent
pixel-samplers-rgba8-nearest-border NVIDIA GeForce RTX 5080 Laptop GPU divergent case/output/norm the digest is a0a4cd79e2609250f0131240bdb85e230771e5052b8ae7ed2f9af30c4a901a72 on Metal and 0bb6048885147595223412eb6b3369c9ae2cdd83510b150fb734948e2884d338 here Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized sampler state of the same filter and address mode inside an argument buffer, sampled at the coordinate divided by the texture's size, which the runtime hands to the device's own sampler. What moves is the nearest-texel selection and not the filtering: the three `nearest` cases of each format diverge at this site and the `linear` ones do not. The texture is 5 by 3 -- a power of two on neither axis -- so a coordinate divided by the size lands within an ulp of a texel boundary at many of the 800 coordinates, and the `zero` and `border` address modes answer the same digest as each other on both sides, so the out-of-bounds answer is not in it. Under the native-arithmetic contract the device's sampler is the answer: `device-sampling` records that a nearest sample within the device's sub-texel precision of a texel boundary may read the neighbouring texel (0.1% of the deviation probe's coordinates on NVIDIA), and validation derives no tolerance from it. Which coordinates differ is not established by this run, which compares the site as a digest. Open: an element-by-element read of the site against the note's recorded bound.
pixel-samplers-rgba8-nearest-edge NVIDIA GeForce RTX 5080 Laptop GPU divergent case/output/norm the digest is 250024876cde0c2f67dccea354f400d28c94b6cd9634aae0b38c6354f35070b7 on Metal and 16b3b152937584db1b758a9d91f52b38e45226e1ff49847051a506836f4b4963 here Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized sampler state of the same filter and address mode inside an argument buffer, sampled at the coordinate divided by the texture's size, which the runtime hands to the device's own sampler. What moves is the nearest-texel selection and not the filtering: the three `nearest` cases of each format diverge at this site and the `linear` ones do not. The texture is 5 by 3 -- a power of two on neither axis -- so a coordinate divided by the size lands within an ulp of a texel boundary at many of the 800 coordinates, and the `zero` and `border` address modes answer the same digest as each other on both sides, so the out-of-bounds answer is not in it. Under the native-arithmetic contract the device's sampler is the answer: `device-sampling` records that a nearest sample within the device's sub-texel precision of a texel boundary may read the neighbouring texel (0.1% of the deviation probe's coordinates on NVIDIA), and validation derives no tolerance from it. Which coordinates differ is not established by this run, which compares the site as a digest. Open: an element-by-element read of the site against the note's recorded bound.
pixel-samplers-rgba8-nearest-zero NVIDIA GeForce RTX 5080 Laptop GPU divergent case/output/norm the digest is a0a4cd79e2609250f0131240bdb85e230771e5052b8ae7ed2f9af30c4a901a72 on Metal and 0bb6048885147595223412eb6b3369c9ae2cdd83510b150fb734948e2884d338 here Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized sampler state of the same filter and address mode inside an argument buffer, sampled at the coordinate divided by the texture's size, which the runtime hands to the device's own sampler. What moves is the nearest-texel selection and not the filtering: the three `nearest` cases of each format diverge at this site and the `linear` ones do not. The texture is 5 by 3 -- a power of two on neither axis -- so a coordinate divided by the size lands within an ulp of a texel boundary at many of the 800 coordinates, and the `zero` and `border` address modes answer the same digest as each other on both sides, so the out-of-bounds answer is not in it. Under the native-arithmetic contract the device's sampler is the answer: `device-sampling` records that a nearest sample within the device's sub-texel precision of a texel boundary may read the neighbouring texel (0.1% of the deviation probe's coordinates on NVIDIA), and validation derives no tolerance from it. Which coordinates differ is not established by this run, which compares the site as a digest. Open: an element-by-element read of the site against the note's recorded bound.
resolve-stencil-under-depth-filters llvmpipe refused case/pieces/pass:MTLMultisampleStencilResolveFilterSample0/MTLMultisampleDepthResolveFilterMax Err(Error::NotImplemented("not implemented in the runtime yet: DepthStencilResolve")) Metal resolves a multisampled depth/stencil attachment with the stencil filter `MTLMultisampleStencilResolveFilterSample0` under the depth filter `Min` or `Max`, and we refuse it `NotImplemented(DepthStencilResolve)`. Ours is not a device refusal dressed up: crates/metal2vulkan-runtime/src/resolve.rs states in its own words that a filter the device's resolve modes lack -- `supportedDepthResolveModes`, `supportedStencilResolveModes`, or the other aspect's modes where a subpass resolving one aspect must name the same mode for both, read off the compile device's description as `VkProperty::{DepthResolveMode, StencilResolveMode, IndependentResolveNone, IndependentResolve}` -- is 'not built', and names the exact path in the same sentence: a resolve DRAW, which the module already uses for other unresolvable pairs and which needs no resolve mode from the device at all. So the gap is work not done rather than a capability missing, which is what makes it ours under the owner's rule that what Metal allows we must allow. This venue is a device with no independent resolve of the two aspects, so the `Sample0` stencil filter cannot be named beside a `Min` or `Max` depth one; the case's other filter pairs run here, so it is these two cells. The fix belongs in resolve.rs: reach the resolve draw for a filter pair the device's modes cannot state, as the module does where `DepthResolvedSample` follows `Min` or `Max` on a sampled attachment. Open: runtime work, on the orchestrator's todo list.
resolve-stencil-under-depth-filters llvmpipe refused case/pieces/pass:MTLMultisampleStencilResolveFilterSample0/MTLMultisampleDepthResolveFilterMin Err(Error::NotImplemented("not implemented in the runtime yet: DepthStencilResolve")) Metal resolves a multisampled depth/stencil attachment with the stencil filter `MTLMultisampleStencilResolveFilterSample0` under the depth filter `Min` or `Max`, and we refuse it `NotImplemented(DepthStencilResolve)`. Ours is not a device refusal dressed up: crates/metal2vulkan-runtime/src/resolve.rs states in its own words that a filter the device's resolve modes lack -- `supportedDepthResolveModes`, `supportedStencilResolveModes`, or the other aspect's modes where a subpass resolving one aspect must name the same mode for both, read off the compile device's description as `VkProperty::{DepthResolveMode, StencilResolveMode, IndependentResolveNone, IndependentResolve}` -- is 'not built', and names the exact path in the same sentence: a resolve DRAW, which the module already uses for other unresolvable pairs and which needs no resolve mode from the device at all. So the gap is work not done rather than a capability missing, which is what makes it ours under the owner's rule that what Metal allows we must allow. This venue is a device with no independent resolve of the two aspects, so the `Sample0` stencil filter cannot be named beside a `Min` or `Max` depth one; the case's other filter pairs run here, so it is these two cells. The fix belongs in resolve.rs: reach the resolve draw for a filter pair the device's modes cannot state, as the module does where `DepthResolvedSample` follows `Min` or `Max` on a sampled attachment. Open: runtime work, on the orchestrator's todo list.
sparse-mapping-a-slice-past-the-textures * divergent case/read/4 256 elements differ (U32), the largest difference 1010580540 Plain Metal TAKES a sparse mapping update whose slice is past the texture's own slices (its own API validation layer refuses the call) and binds the page it charges at an address its own page layout derives. Measured on this M3 Max (macOS 27.0.1, build 26A434) from this case's own committed recording, 3 runs and one outcome, over a two-slice 256x256 nine-level R32Float sparse texture whose level 0 holds 4 by 4 of Metal's 16-KiB tiles with two tiles of each slice mapped and filled with four distinct bytes: after a Map of one tile of slice 2 and an Unmap of another, a 16 by 16 texel block at texel (0, 16) of slice 0's tile (0, 0), 256 of its 4,096 words, reads 0xFFFFFFFF (Metal's unwritten pattern on this chip, probes/sparse_unmapped_blit.m), every other word of the four tiles its own fill. The runtime charges its heap's usedSize the same page (this case's used-size sites compare) and maps nothing there, so no texel moves, which is the whole of this site's difference. It is an accepted difference, not mirrored: docs/API.md section 10, Heaps and memory, 'A sparse mapping update of a slice past the texture's own maps nothing'. Vulkan binds nothing past an image's layers (VUID-VkSparseImageMemoryBindInfo-subresource-01723), and the address Metal's page lands at is not derivable from what is measured. Scoped to every venue: the runtime maps nothing for the slice before any device is consulted. Open: nothing in the product.
#
# The device's own answers on llvmpipe in cases that hold no other row on this venue (see the
Can't render this file because it is too large.
@@ -4170,7 +4170,7 @@ impl Device {
let reason = if resolve.split {
format!(
"its depth ({}) and its stencil ({}) resolve into different textures, \
each through a scratch image of its own",
each a subpass resolves through a scratch image of its own",
resolve_mode(resolve.depth_mode),
resolve_mode(resolve.stencil_mode)
)
@@ -52,6 +52,10 @@
//! its layers, each texture's from its slice, and the copies move every layer; the copies' draws,
//! each of one layer, run once per layer.
//!
//! - **A resolve drawn after the pass** (`depth_stencil_resolve.rs`: a `Min` or `Max` depth on a
//! device without the mode) reads the scratch image's samples, so the image is sampled where
//! such a resolve may run and the device samples its format (`resolve::may_draw`).
//!
//! Refused: a device without the combined format as a depth/stencil attachment that copies both
//! ways (and, where the scratch image is read back by draws, is sampled), or, for multisampled
//! aspects copied through colour images, without a matching colour format it renders to and
@@ -296,12 +300,14 @@ fn by_draws(device: &Device, samples: u32, aspect: ImageAspectFlags) -> bool {
}
/// The scratch image `separate`'s pass renders into, as its depth/stencil target, whose depth and
/// stencil aspects load with `loads` and store with `stores`. Refused as the module docs say.
/// stencil aspects load with `loads` and store with `stores`, and whose samples a resolve drawn
/// after the pass may read where `drawn` (`resolve::may_draw`). Refused as the module docs say.
pub(super) fn scratch(
maker: &CommandBuffer,
separate: &Separate,
loads: [LoadAction; 2],
stores: [StoreAction; 2],
drawn: bool,
) -> Result<Target, Error> {
let device = maker.device();
// The first texture: both have the pass's samples and layers, and the scratch image the
@@ -415,6 +421,14 @@ pub(super) fn scratch(
FormatUsage::SampledImage,
)?;
}
// A resolve drawn after the pass reads the samples too, where the device samples the format;
// elsewhere that resolve is refused (`depth_stencil_resolve::draws_run`).
let sampled = read_scratch
|| (drawn
&& multisampled
&& facts
.optimal(format)
.contains(FormatFeatureFlags2::SAMPLED_IMAGE));
let samples = samples_flag;
let [width, height] = extent;
// The descriptor states the image's size and samples; its pixel format is the depth
@@ -454,7 +468,7 @@ pub(super) fn scratch(
usage: ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT
| ImageUsageFlags::TRANSFER_SRC
| ImageUsageFlags::TRANSFER_DST
| if read_scratch {
| if sampled {
ImageUsageFlags::SAMPLED
} else {
ImageUsageFlags::empty()
@@ -2194,11 +2194,13 @@ fn depth_stencil(
depth: None,
stencil: t.clone(),
};
// No depth, so no resolve drawn after the pass (`resolve::may_draw`).
let scratch = depth_stencil_scratch::scratch(
maker,
&separate,
[depth_load, s.load_action],
[d.store_action, s.store_action],
false,
)?;
(scratch, Some(separate))
}
@@ -2220,11 +2222,21 @@ fn depth_stencil(
depth: Some(a.clone()),
stencil: b.clone(),
};
// A resolve drawn after the pass reads the scratch image's samples.
let drawn = resolve::may_draw(
device,
a.format,
Wanted::of(true, &d.resolve_texture, (0, 0, 0), d.store_action).as_ref(),
Wanted::of(true, &s.resolve_texture, (0, 0, 0), s.store_action).as_ref(),
d.depth_resolve_filter,
s.stencil_resolve_filter,
);
let scratch = depth_stencil_scratch::scratch(
maker,
&separate,
[depth_load, s.load_action],
[d.store_action, s.store_action],
drawn,
)?;
(scratch, Some(separate))
}
+122 -51
View File
@@ -206,7 +206,7 @@
//! device's description states them (`VkProperty::{DepthResolveMode, StencilResolveMode,
//! IndependentResolveNone, IndependentResolve}`), for which a resolve draw is the exact path; and
//! `DepthResolvedSample` after `Min` or `Max` of an attachment whose image is not sampled, or
//! whose stencil the draws cannot write; and a split resolve (below) with an aspect drawn after
//! whose stencil the draws cannot write; and a split resolve (below) with both aspects drawn after
//! the pass.
//!
//! **Split resolves**. Where the aspects resolve into different textures (separate depth and
@@ -215,8 +215,12 @@
//! is checked against the attachment that names it, and each aspect resolves in a subpass of its
//! own (the first in the draws' subpass, the second in a later pass) into a scratch image of the
//! attachment's format, whose aspect alone is copied into its texture after the pass through a
//! staging buffer, as one aspect at a time does. An aspect the pass does not resolve keeps its
//! resolve texture's texels. Announced as `one-aspect-resolve`.
//! staging buffer, as one aspect at a time does. An aspect drawn after the pass (a `Min` or `Max`
//! depth on a device without the mode, or a `DepthResolvedSample` stencil after either) is drawn
//! into its own resolve texture, or into a scratch image copied there, from the attachment's
//! samples: separate textures' from the image they render through, which is then sampled
//! (`depth_stencil_scratch::scratch`). An aspect the pass does not resolve keeps its resolve
//! texture's texels. Announced as `one-aspect-resolve`.
use super::attachment_stand_in::{self, Cause, StandIn};
use super::blit::{reads, writes, TRANSFER};
@@ -364,7 +368,8 @@ pub(super) struct DepthStencilResolve {
/// resolved aspect is drawn.
pub(super) steps: Vec<ResolveStep>,
/// The resolve attachment the draws write where no step resolves into one (every resolved
/// aspect drawn): the resolve texture's level and slice, or a scratch image copied there.
/// aspect drawn), or where the aspects resolve into different textures (`split`): the drawn
/// aspect's resolve texture's level and slice, or a scratch image copied there.
pub(super) drawn_into: Option<Resolve>,
/// Its aspects resolve into different textures (separate ones, or two for one combined
/// texture): each step resolves one aspect into a scratch image copied into its own.
@@ -377,13 +382,12 @@ impl DepthStencilResolve {
picked(self.depth_mode, self.stencil_mode)
}
/// The resolve attachment the drawn aspects are written into: the first step's, or the
/// draws' own.
/// The resolve attachment the drawn aspects are written into: the draws' own, or the first
/// step's.
pub(super) fn drawn_target(&self) -> Option<&Resolve> {
self.steps
.first()
.map(|step| &step.resolve)
.or(self.drawn_into.as_ref())
self.drawn_into
.as_ref()
.or(self.steps.first().map(|step| &step.resolve))
}
/// Each resolve attachment it writes, with the aspects of the resolve texture written there
@@ -834,33 +838,12 @@ pub(super) fn depth_stencil(
// fragment depth stores the picked value unchanged (`depth_copy::copies_exactly`).
let exact_depth = super::depth_copy::copies_exactly(device, source.format)
&& super::depth_copy::copies_exactly(device, destination.target.format);
let pick_or = |mode: ResolveMode, pick: DepthPick| match exact_depth
&& !modes.depth.contains(mode.vk())
{
true => ResolveMode::Picked(pick),
false => mode,
};
let depth_mode = if depth_resolves {
match depth_filter {
MultisampleDepthResolveFilter::Sample0 => ResolveMode::SampleZero,
MultisampleDepthResolveFilter::Min => pick_or(ResolveMode::Min, DepthPick::Min),
MultisampleDepthResolveFilter::Max => pick_or(ResolveMode::Max, DepthPick::Max),
}
} else {
ResolveMode::None
};
let stencil_mode = match (stencil_resolves, stencil_filter) {
(false, _) => ResolveMode::None,
(true, MultisampleStencilResolveFilter::Sample0) => ResolveMode::SampleZero,
// The stencil of the sample the depth filter takes, the depth resolved or not: sample
// 0's after `Sample0`; after `Min` or `Max` no Vulkan mode states it, so it is drawn
// after the pass, picking Metal's sample (`depth_stencil_resolve.rs`).
(true, MultisampleStencilResolveFilter::DepthResolvedSample) => match depth_filter {
MultisampleDepthResolveFilter::Sample0 => ResolveMode::SampleZero,
MultisampleDepthResolveFilter::Min => ResolveMode::Picked(DepthPick::Min),
MultisampleDepthResolveFilter::Max => ResolveMode::Picked(DepthPick::Max),
},
};
let (depth_mode, stencil_mode) = aspect_modes(
&modes,
exact_depth,
(depth_resolves, depth_filter),
(stencil_resolves, stencil_filter),
);
let subpass_stencil = stencil_mode.in_subpass();
// A drawn depth's subpass mode is free, as the draws overwrite it: `NONE`, or `SAMPLE_ZERO`
// where the device pairs no `NONE` with the stencil's mode (lavapipe), which spares the
@@ -881,18 +864,36 @@ pub(super) fn depth_stencil(
// Every resolved aspect drawn: no subpass resolves, and the draws write their own resolve
// attachment.
let (mut steps, drawn_into) = if split {
// A split resolve resolves each aspect into a scratch image of `source` in a subpass of
// its own, and copies that aspect alone into its texture after the pass. An aspect drawn
// after the pass writes the first step's attachment, which a split resolve does not
// copy whole: not built.
if picked(depth_mode, stencil_mode).is_some() {
return Err(Error::NotImplemented(RuntimeGap::DepthStencilResolve));
}
// A split resolve resolves each aspect a subpass resolves into a scratch image of
// `source` in a subpass of its own, and copies that aspect alone into its texture after
// the pass; an aspect drawn after the pass is drawn into its own texture (or a scratch
// image copied there). Both aspects drawn, each into its own texture: not built.
let usage = ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT;
let drawn = match (depth_mode, stencil_mode) {
(ResolveMode::Picked(_), ResolveMode::Picked(_)) => {
return Err(Error::NotImplemented(RuntimeGap::DepthStencilResolve));
}
(ResolveMode::Picked(_), _) => depth_destination.clone(),
(_, ResolveMode::Picked(_)) => stencil_destination.clone(),
_ => None,
};
let drawn_into = match drawn {
Some(drawn) => Some(drawn.attach(maker, source, usage, false)?),
None => None,
};
let aspects = [
(depth_mode, ImageAspectFlags::DEPTH, depth_destination),
(stencil_mode, ImageAspectFlags::STENCIL, stencil_destination),
(
depth_mode.in_subpass(),
ImageAspectFlags::DEPTH,
depth_destination,
),
(
subpass_stencil,
ImageAspectFlags::STENCIL,
stencil_destination,
),
];
(split_steps(maker, source, aspects, &modes)?, None)
(split_steps(maker, source, aspects, &modes)?, drawn_into)
} else if subpass_depth == none && subpass_stencil == none {
let usage = ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT;
(
@@ -910,10 +911,13 @@ pub(super) fn depth_stencil(
)?;
(steps, None)
};
// A drawn aspect is written into the first step's resolve attachment, which then holds it
// too (a scratch image's copy takes it), or into the draws' own.
if let (Some((_, aspects)), Some(step)) = (picked(depth_mode, stencil_mode), steps.first_mut())
{
// A drawn aspect is written into the draws' own resolve attachment, or else into the first
// step's, which then holds it too (a scratch image's copy takes it).
if let (Some((_, aspects)), Some(step), None) = (
picked(depth_mode, stencil_mode),
steps.first_mut(),
&drawn_into,
) {
step.aspects |= aspects;
}
let resolve = DepthStencilResolve {
@@ -932,6 +936,73 @@ pub(super) fn depth_stencil(
Ok(Some(resolve))
}
/// Each aspect's mode as Metal's filters state it on a device with `modes`, `ResolveMode::None`
/// for an aspect that does not resolve (`depth.0`, `stencil.0`): `Sample0`, `Min` and `Max` are
/// `SAMPLE_ZERO`, `MIN` and `MAX`, a `Min` or `Max` depth the device has no mode for picked by
/// the draws after the pass where they store it unchanged (`exact_depth`,
/// `depth_copy::copies_exactly`); a `DepthResolvedSample` stencil is sample 0's after `Sample0`,
/// and picked after `Min` or `Max`, which no Vulkan mode states, the depth resolved or not.
fn aspect_modes(
modes: &ResolveModes,
exact_depth: bool,
(depth_resolves, depth_filter): (bool, MultisampleDepthResolveFilter),
(stencil_resolves, stencil_filter): (bool, MultisampleStencilResolveFilter),
) -> (ResolveMode, ResolveMode) {
let pick_or = |mode: ResolveMode, pick: DepthPick| match exact_depth
&& !modes.depth.contains(mode.vk())
{
true => ResolveMode::Picked(pick),
false => mode,
};
let depth = match (depth_resolves, depth_filter) {
(false, _) => ResolveMode::None,
(true, MultisampleDepthResolveFilter::Sample0) => ResolveMode::SampleZero,
(true, MultisampleDepthResolveFilter::Min) => pick_or(ResolveMode::Min, DepthPick::Min),
(true, MultisampleDepthResolveFilter::Max) => pick_or(ResolveMode::Max, DepthPick::Max),
};
let stencil = match (stencil_resolves, stencil_filter) {
(false, _) => ResolveMode::None,
(true, MultisampleStencilResolveFilter::Sample0) => ResolveMode::SampleZero,
(true, MultisampleStencilResolveFilter::DepthResolvedSample) => match depth_filter {
MultisampleDepthResolveFilter::Sample0 => ResolveMode::SampleZero,
MultisampleDepthResolveFilter::Min => ResolveMode::Picked(DepthPick::Min),
MultisampleDepthResolveFilter::Max => ResolveMode::Picked(DepthPick::Max),
},
};
(depth, stencil)
}
/// Whether the resolve of a depth/stencil attachment whose depth is of `format` (`depth` and
/// `stencil` its descriptors' resolves, under `depth_filter` and `stencil_filter`) may be drawn
/// after the pass on `device`, the draws reading the attachment's samples through sampled views
/// (`depth_stencil_resolve.rs`): the image the runtime renders separate textures through then
/// takes `SAMPLED` usage (`depth_stencil_scratch::scratch`). It answers before the pass's store
/// actions and resolve textures are checked, so it errs toward yes: an `Unknown` store action
/// may resolve, and [`depth_stencil`] decides by the resolve texture's format too.
pub(super) fn may_draw(
device: &Device,
format: Format,
depth: Option<&Wanted<'_>>,
stencil: Option<&Wanted<'_>>,
depth_filter: MultisampleDepthResolveFilter,
stencil_filter: MultisampleStencilResolveFilter,
) -> bool {
let may_resolve = |wanted: Option<&Wanted<'_>>| {
wanted.is_some_and(|w| {
w.texture.is_some() && (w.store.resolves() || w.store == StoreAction::Unknown)
})
};
let modes = ResolveModes::of(device.compile_device().profile());
let exact_depth = super::depth_copy::copies_exactly(device, format);
let (depth, stencil) = aspect_modes(
&modes,
exact_depth,
(may_resolve(depth), depth_filter),
(may_resolve(stencil), stencil_filter),
);
picked(depth, stencil).is_some()
}
/// The pick of the aspects of `depth` and `stencil` mode drawn after the pass, and which: `None`
/// where neither is.
fn picked(depth: ResolveMode, stencil: ResolveMode) -> Option<(DepthPick, ImageAspectFlags)> {
@@ -2143,10 +2143,11 @@ enum Split {
/// keeping its texels, which Metal's debug layer stops and plain Metal runs; two slices of one
/// array likewise, a Metal probe on the M3 Max and an M4). The samples are those of a Metal probe
/// on an M4 (depths 0.5, 0.1, 0.9 and 0.3, stencils 20 to 23); each resolve texture holds depth
/// 0.75 and stencil 7 before the pass. A stencil drawn after the pass (`DepthResolvedSample` after
/// `Min` or `Max`, or a depth the device has no mode for) is `NotImplemented(DepthStencilResolve)`
/// in a split resolve, as is a pair of modes the device lacks; a device that refuses the separate
/// textures' sample copies prints its refusal.
/// 0.75 and stencil 7 before the pass. An aspect drawn after the pass (a stencil by
/// `DepthResolvedSample` after `Min` or `Max`, or a depth the device has no mode for) is drawn
/// into its own resolve texture, printed as a "drawn:" line; both aspects drawn is
/// `NotImplemented(DepthStencilResolve)` in a split resolve, as is a pair of modes the device
/// lacks; a device that refuses the separate textures' sample copies prints its refusal.
#[test]
fn split_depth_and_stencil_resolves_are_metals() {
use MultisampleDepthResolveFilter as D;
@@ -2290,7 +2291,29 @@ fn split_depth_and_stencil_resolves_are_metals() {
Split::Separate => (PixelFormat::Depth32Float, PixelFormat::Stencil8),
Split::TwoTextures | Split::TwoSlices => (combined, combined),
};
let depth_msaa = lane.msaa(depth_pf);
// A drawn aspect: a depth picked where the device has no mode for it, or a stencil
// picked by depth after `Min` or `Max`, each drawn from the samples, read through
// sampled views (separate textures' through the image they render through, which the
// runtime makes sampled).
let depth_mode = depth.map(|_| match depth_filter {
D::Sample0 => Mode::SAMPLE_ZERO,
D::Min => Mode::MIN,
D::Max => Mode::MAX,
other => panic!("{name}: a filter the cases do not name: {other:?}"),
});
let depth_drawn = depth_mode.is_some_and(&drawn);
let stencil_drawn = stencil.is_some()
&& stencil_filter == S::DepthResolvedSample
&& depth_filter != D::Sample0;
let depth_msaa = match split {
Split::Separate => lane.msaa(depth_pf),
_ if depth_drawn || stencil_drawn => lane.texture(
depth_pf,
MSAA,
TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ,
),
_ => lane.msaa(depth_pf),
};
let stencil_msaa = match split {
Split::Separate => lane.msaa(stencil_pf),
Split::TwoTextures | Split::TwoSlices => depth_msaa.clone(),
@@ -2357,22 +2380,18 @@ fn split_depth_and_stencil_resolves_are_metals() {
h.push(mask);
}
});
// Each resolved aspect in a subpass of its own; a drawn one is not built here.
let depth_mode = depth.map(|_| match depth_filter {
D::Sample0 => Mode::SAMPLE_ZERO,
D::Min => Mode::MIN,
D::Max => Mode::MAX,
other => panic!("{name}: a filter the cases do not name: {other:?}"),
});
let picked = (depth_mode.is_some_and(&drawn))
|| (stencil.is_some()
&& stencil_filter == S::DepthResolvedSample
&& depth.is_some()
&& depth_filter != D::Sample0);
let stencil_mode = stencil.map(|_| Mode::SAMPLE_ZERO);
let built = !picked
&& device_resolves(depth_mode, None, true)
&& device_resolves(None, stencil_mode, true);
// Each aspect a subpass resolves in a subpass of its own, and one drawn into its own
// texture after the pass; both drawn is not built here.
let subpass_depth = depth_mode.filter(|_| !depth_drawn);
let subpass_stencil = stencil
.map(|_| Mode::SAMPLE_ZERO)
.filter(|_| !stencil_drawn);
let built = !(depth_drawn && stencil_drawn)
&& device_resolves(subpass_depth, None, true)
&& device_resolves(None, subpass_stencil, true);
if built && (depth_drawn || stencil_drawn) {
eprintln!("drawn: {name}: the depth {depth_drawn}, the stencil {stencil_drawn}");
}
// The separate textures' scratch image, and its copies, are made before the resolve.
match (built, ran) {
(_, Err(Error::Unsupported(u))) if split == Split::Separate => {
+1 -3
View File
@@ -44,7 +44,7 @@ Its limits, measured rather than asserted:
| committed recordings | 1229 |
| distinct SDK items the Metal leg reaches, of any status | 820 |
| of those, reached only where this cannot name the family | 3 |
| ledger rows (a case whose gap is recorded) | 2600 |
| ledger rows (a case whose gap is recorded) | 2598 |
| declared crossings of the option space (pairs put to Metal at once) | 26 |
| declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 |
@@ -2614,8 +2614,6 @@ A case whose difference from Metal is recorded rather than compared away. The le
| `pixel-samplers-rgba8-nearest-border` | Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized… |
| `pixel-samplers-rgba8-nearest-edge` | Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized… |
| `pixel-samplers-rgba8-nearest-zero` | Metal's 800 sampled results of this case's `norm` source digest to one value and ours to another; the row holds both. `norm` is the case's control: a normalized… |
| `resolve-stencil-under-depth-filters` | Metal resolves a multisampled depth/stencil attachment with the stencil filter `MTLMultisampleStencilResolveFilterSample0` under the depth filter `Min` or `Max`… |
| `resolve-stencil-under-depth-filters` | Metal resolves a multisampled depth/stencil attachment with the stencil filter `MTLMultisampleStencilResolveFilterSample0` under the depth filter `Min` or `Max`… |
| `sparse-mapping-a-slice-past-the-textures` | Plain Metal TAKES a sparse mapping update whose slice is past the texture's own slices (its own API validation layer refuses the call) and binds the page it cha… |
| `argb8-targets-unblended` | An unblended colour write into an 8-bit unorm attachment (`RGBA8Unorm`, and `ARGB8Unorm` through its byte rotation, which moves by the same count): Metal's stor… |
| `argb8-targets-unblended` | An unblended colour write into an 8-bit unorm attachment (`RGBA8Unorm`, and `ARGB8Unorm` through its byte rotation, which moves by the same count): Metal's stor… |