Take new textures' pattern reads at the commit, in commit order, not as encoded

What: a command buffer now logs its commands' reads and writes of noted new textures
(`fresh_unwritten.rs`'s FreshLog: pass loads, clears, resolves, blit writes and reads, shader
reads, and a pass's load of a signed-depth pattern) in encode order, and its commit replays the
log against the device's record under one lock, before the scheduler sees it, announcing
`fresh-pattern-zeroed`, `device-nan-encoding` (a fresh texture's converted NaNs) and
`signed-depth-test` (a loaded signed-NaN depth pattern) there. A command buffer dropped
uncommitted takes nothing; a refused commit's log is discarded. With no noted texture a command
reads one flag and logs nothing, and a commit reads it once.

Why: the record followed encode order, so a queue's command buffers encoded out of commit order
(the consumer's host encodes one queue on several threads, then commits in order) announced a
read Metal never makes (a load after a committed-earlier clear, encoded first: a precision note
the consumer makes fatal) and missed one it makes (a load before a committed-later clear, encoded
after it: the texture read zero where Metal reads its pattern, unannounced). Metal runs a queue's
command buffers in commit order.

Tests: runtime_lane::parallel_encodes::a_fresh_texture_s_pattern_notice_follows_the_commit_order
runs two command buffers of depth-only passes (4-sample and single-sample Depth32Float,
clear-then-load and load-then-clear) serially and with the later-committed one encoded whole
first on another thread, and requires the same notices both ways and Metal's reads of the
pattern. Before the fix it failed on the M3 Max (MoltenVK 1.4.2): 1 notice instead of 0, and 0
instead of 1. The same module's a_shadowed_texture_keeps_each_command_buffer_s_bytes (a texture
over a Private buffer at 48-byte rows, eight command buffers on four threads) checks every
copy and read against its own command buffer's words and prints the copies in.

Docs: fresh_unwritten.rs's Observed and Order bullets, the FreshPatternZeroed and SignedDepthTest
declarations, docs/API.md's catalogue entries.

Verified on the M3 Max under --cfg m2v_gpu: the new test passes; so do runtime_lane's
fresh_writes, fresh_contents, depth_denormals, degrade_notices, made_at_creation, texture_blits,
renders, sample_copies, nan_resolves, buffer_depth_samples, compressed_blits, color_fills,
color_writes, cross_class_storage and half_* modules, and the runtime's tests::fresh_unwritten
and tests::heap_tiled (118 tests); degradation_catalogue passes. clippy -D warnings clean for the
runtime crate (plain).

(cherry picked from commit 95d7bdf6dc8c6e411114b2d9a8203ea1e4970168)
This commit is contained in:
Anees Iqbal committed 2026-11-02 23:52:36 -08:00
1 parent 87cdea9b49
commit 48ec97832d
10 files changed
+745 -136

No files matched your search

@@ -1118,7 +1118,7 @@ impl BlitCommandEncoder {
texture: &Texture,
written: Vec<(vk::ImageAspectFlags, Written)>,
) -> Result<(), Error> {
FreshUnwritten::wrote(self.core().device(), texture, &written)?;
FreshUnwritten::wrote(self.core().command_buffer(), texture, &written)?;
let written = || written.into_iter().map(|(_, texels)| texels).collect();
match Scrub::of(texture, written) {
Some(scrub) => self.core().defer(Deferred::SparseScrub(Arc::new(scrub))),
@@ -79,6 +79,7 @@ use super::error::{
use super::event::{EventRef, EventShared, SharedEvent};
use super::execution::Execution;
use super::exit_guard::{self, Call};
use super::fresh_unwritten::{FreshLog, FreshUnwritten};
use super::function_table::TableSnapshot;
use super::gpu_pools::{IndexPool, PoolKind, PoolLease};
use super::gpu_time::{self, KernelTimes, Life, Placement, Stamped, Times};
@@ -285,6 +286,9 @@ pub(super) struct CommandBufferShared {
/// Whether a batch of it is held in the scheduler's group, and whether a thread waits for its
/// completion: a group kept past a pass goes at once once one does (`group.rs`).
group_hold: AtomicU8,
/// Its commands' reads and writes of new textures' unwritten patterns, in encode order, which
/// its commit takes (`fresh_unwritten.rs`). Apart from the state: its encoders log into it.
fresh: FreshLog,
}
/// The word [`CommandBufferShared::status`] holds for `status`: its raw value.
@@ -1909,6 +1913,7 @@ impl CommandBuffer {
status: AtomicU8::new(status_word(CommandBufferStatus::NotEnqueued)),
error: OnceLock::new(),
group_hold: AtomicU8::new(0),
fresh: FreshLog::default(),
}))
}
@@ -1939,6 +1944,12 @@ impl CommandBuffer {
&self.0.queue
}
/// The log its commit takes of its commands' reads and writes of new textures' unwritten
/// patterns (`fresh_unwritten.rs`).
pub(crate) fn fresh_log(&self) -> &FreshLog {
&self.0.fresh
}
/// The state, locked.
/// Note `work` of an encoder it ended, which its scheduling hands to the device's identifier
/// allocations ([`UniqueIdentifiers::scheduled`](crate::unique_identifier::UniqueIdentifiers::scheduled)).
@@ -3019,6 +3030,9 @@ impl CommandBuffer {
// Its host steps' instances take their numbers from here, in the program's call, before
// the scheduler can run one.
let _ = self.0.step_numbers.set(StepNumbers::reserve());
// Its reads and writes of new textures' patterns, in commit order: announced in the
// committing call, before the scheduler sees it (`fresh_unwritten.rs`).
FreshUnwritten::commit(device, &self.0.fresh, run != CommitRun::Refused);
// The scheduler's lock is taken before a command buffer's, never under it.
device
.shared()
@@ -800,7 +800,9 @@ degradations! {
/// a clear leaves to the device), or an image holding other bytes than Metal's texel. The
/// texture reads zero there. Announced where a command first reads a texel of that content
/// no clear, resolve or blit covered (a pass that loads it, a blit or a shader that reads
/// it), not as the texture is made (`fresh_unwritten.rs`).
/// it), in the order the command buffers are committed, whatever order or thread they were
/// encoded in: at the commit of the command buffer that holds the read, not as the
/// texture is made (`fresh_unwritten.rs`).
FreshPatternZeroed = "fresh-pattern-zeroed", Precision,
"the new texture reads zero where Metal reads its fixed pattern until a write";
/// An indexed draw from an index offset at or past its index buffer's length draws index
@@ -2004,9 +2006,10 @@ degradations! {
/// depth writes stores each texel no fragment wrote without its sign (probe `depthstore`).
/// Vulkan's compares the stored value as it is, and its pass keeps it. Announced at a write
/// that may give a render target's depth such a value (a `replace_region` whose bytes hold
/// one, a blit into its depth, a pass's written NaN clear), or at the pass that loads a new
/// texture's pattern (a NaN with the sign set) before a write covered it
/// (`fresh_unwritten.rs`), on a device that keeps such a value there
/// one, a blit into its depth, a pass's written NaN clear), or at the commit of the command
/// buffer of a pass that loads a new texture's pattern (a NaN with the sign set) before a
/// write covered it in commit order (`fresh_unwritten.rs`), on a device that keeps such a
/// value there
/// (`VK_EXT_depth_range_unrestricted` enabled, or
/// `DriverFact::DepthImageKeepsValuesOutsideUnitRange`; elsewhere `restricted-depth-upload`
/// is announced). A device whose depth test compares magnitudes as Metal's
+9 -40
View File
@@ -36,7 +36,7 @@ use super::deferred::{Deferred, StepInputs};
use super::dirty_pages::CopyInGate;
use super::error::{internal, invalid, vulkan, CommandBufferError, Error, Problem};
use super::execution::Execution;
use super::fresh_unwritten::FreshRead;
use super::fresh_unwritten::{FreshRead, FreshUnwritten};
use super::heap::Heap;
use super::index_bounds::{BoundsRunRequest, BoundsSlot};
use super::index_rewrite::{
@@ -58,7 +58,7 @@ use super::shadow_merge::ShadowMerge;
use super::sparse::encoder::SparseUpdate;
use super::texture::decoded_twin::TwinWrite;
use super::texture::kept_image::KeptLease;
use super::tracker::{Barrier, EncoderUses, Reach, Summary, Use, UseRange};
use super::tracker::{Barrier, EncoderUses, Reach, Summary, Use};
use super::unique_identifier::ScheduledWork;
use super::used_resources::EncoderKind;
use super::Device;
@@ -1018,8 +1018,9 @@ impl EncoderCore {
/// touches (`tracker::Reach::Named`): a blit encoder's command, a shadow's copy. In an
/// ordered encoder it orders after the earlier such commands per key and range alone, and
/// after every untracked access of the others. It reads the boxes `reads` of textures'
/// images (a blit's sources): a read of a new texture's unwritten pattern there is announced
/// only where a box reaches an unwritten texel (`fresh_unwritten.rs`); its other reads as
/// images (a blit's sources): a read of a new texture's unwritten pattern there is announced,
/// at the commit, only where a box reaches an unwritten texel (`fresh_unwritten.rs`); its
/// other reads as
/// `command`'s.
pub(super) fn command_named(
&mut self,
@@ -1106,7 +1107,7 @@ impl EncoderCore {
return None;
}
// A command reading a new texture's levels that read zero where Metal reads its pattern,
// before a clear covered them, announces it (`fresh_unwritten.rs`).
// before a clear covered them, announces it at its commit (`fresh_unwritten.rs`).
self.observe_fresh(uses, reads);
// Hazard tracking takes the uses with their buffers' host memory's; the keys kept and
// held are the uses' own.
@@ -1125,42 +1126,10 @@ impl EncoderCore {
Some(barrier)
}
/// Announce `fresh-pattern-zeroed` for each texture `uses` read in a level and layer still
/// unwritten since it was made (`fresh_unwritten.rs`): a blit's, a shader's or an input
/// attachment's read. An attachment's own reads are its pass's load, which the pass decides
/// as it begins (`FreshUnwritten::begin_pass`). A use of a texture `reads` names boxes of is
/// read in those boxes alone.
/// Log for the commit each texture `uses` read in a level and layer, where a new texture's
/// unwritten pattern may lie (`FreshUnwritten::observe_reads`).
fn observe_fresh(&self, uses: &[Use<ResourceKey>], reads: &[FreshRead]) {
let device = self.device();
let fresh = &device.shared().fresh;
if !fresh.any() {
return;
}
let attachment = vk::AccessFlags2::COLOR_ATTACHMENT_READ
| vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ;
let reading = |used: &&Use<ResourceKey>| !(used.read.access & !attachment).is_empty();
for used in uses.iter().filter(reading) {
if let UseRange::Image {
aspects,
levels,
layers,
} = &used.range
{
let mut boxes = reads.iter().filter(|read| read.key == used.key).peekable();
let notice = match boxes.peek().is_some() {
true => boxes.find_map(|read| {
fresh.observed_within(read.key, read.aspects, &read.texels)
}),
false => {
let (levels, layers) = (levels.clone(), layers.clone());
fresh.observed(used.key, *aspects, levels, layers)
}
};
if let Some(notice) = notice {
device.degrade_fresh_pattern(notice);
}
}
}
FreshUnwritten::observe_reads(self.command_buffer(), uses, reads);
}
/// `uses` with a use of the host memory's key beside each use of a no-copy buffer that
@@ -1,20 +1,20 @@
//! New textures that read zero where Metal reads its fixed pattern, announced where a command
//! first observes that content.
//! that runs first observes that content.
//!
//! Where the device cannot write a new compressed `Private` texture's pattern exactly
//! (`Device::fresh_patterned`), the texture reads zero in those levels instead. The difference is
//! only seen if something reads those levels before a write covers them. Nearly every
//! multisampled depth target is cleared before anything reads it. So the texture announces
//! `fresh-pattern-zeroed` only at the first command that reads one of those subresources while it
//! is still unwritten, not when it is made.
//! `fresh-pattern-zeroed` only at the first command, in the order the commands run, that reads one
//! of those subresources while it is still unwritten, not when it is made.
//!
//! - **Unwritten.** Each pattern level of each image layer starts unwritten, in each aspect the
//! image holds. The tracker keeps, per level, layer and aspect, the boxes of texels no write has
//! covered yet, so writes of parts that together cover the level write it as one whole write
//! does. What counts as a write of a box:
//! - a render pass's clear of an attachment, over the pass's render area in the attachment's
//! layers (a 3D attachment's depth planes), in each aspect it clears, as its encoder ends
//! ([`FreshUnwritten::cleared`]; as its encoder ends, not as it is made). Where the pass
//! layers (a 3D attachment's depth planes), in each aspect it clears, logged as its encoder
//! ends ([`FreshUnwritten::cleared`]; as its encoder ends, not as it is made). Where the pass
//! renders the attachment through another image (a stand-in copied to and from it, separate
//! depth and stencil textures' scratch), the clear reaches the texture only by the copy back,
//! so it counts only where the pass stores that aspect: a `DontCare` store leaves the texture's
@@ -32,17 +32,27 @@
//! or trims to one, so what stays unwritten still holds every texel no write covered (a read may
//! then be announced that an unbounded record would not, never the reverse).
//! - **Observed.** A pass that loads an unwritten subresource (`Load`, of any aspect) observes it
//! as its encoder is made, where its render area reaches an unwritten texel of that aspect; a
//! command whose uses read one otherwise observes it as it is encoded (`EncoderCore`'s
//! `command_reaching` and `note_reaching`) where an unwritten texel lies in the levels, layers
//! and aspects it reads: a blit from it, a shader that samples, reads or fetches it, an input
//! attachment. An attachment's own reads (blending, the depth and stencil tests) are its
//! load's, which its pass decided. The device announces the kind there, inside the program's
//! call, naming the texture and the reason, and stops tracking the texture.
//! - **Order.** The state follows the order commands are encoded in, which is the order they run
//! in except across command buffers committed out of encoding order.
//! - **Cheap.** With no such texture live, a command checks one flag. A texture's entry goes when
//! every subresource is written, when it is announced, or when the texture is released.
//! (logged as its encoder is made, [`FreshUnwritten::begin_pass`]) where its render area reaches
//! an unwritten texel of that aspect; a command whose uses read one otherwise observes it (logged
//! as it is encoded, `EncoderCore`'s `command_reaching` and `note_reaching`) where an unwritten
//! texel lies in the levels, layers and aspects it reads: a blit from it, a shader that samples,
//! reads or fetches it, an input attachment. An attachment's own reads (blending, the depth and
//! stencil tests) are its load's, which its pass decided. The device announces the kind at the
//! commit of the command buffer whose command observed it, inside that program call, naming the
//! texture and the reason, and stops tracking the texture.
//! - **Order: the commit order.** Metal runs a queue's command buffers in commit order, whatever
//! order they were encoded in, on however many threads. So a command buffer logs its commands'
//! writes and reads of noted textures in the order they were encoded ([`FreshLog`]), and its
//! commit takes the log ([`FreshUnwritten::commit`], before the scheduler sees it): the record
//! follows the commits, one command buffer's reads and writes at a time. A pass that loads a
//! texture after a pass of a command buffer committed before it cleared it observes nothing,
//! though it was encoded first, and one that loads it before a clear committed after it
//! announces it, whichever was encoded first. A command buffer dropped uncommitted takes
//! nothing, nor does a refused commit's, which runs nothing; the log of one committed as failed
//! is taken whole, as its encoders were encoded.
//! - **Cheap.** With no such texture live, a command checks one flag and logs nothing, and a commit
//! checks it once. A texture's entry goes when every subresource is written, when it is
//! announced, or when the texture is released.
//!
//! A new multisampled float texture whose pattern holds a NaN is noted alike where the device
//! writes the pattern by a copy that converts the NaNs (`nan_clear::converting_copy`): its samples
@@ -54,10 +64,11 @@
//! depth test compares the stored value's magnitude, which lies above every depth, and a pass with
//! depth writes stores it without its sign (our probe `fd32`, the M3 Max under macOS 27.0.1). A
//! command's read observes nothing of it. A pass that loads its depth where its attachment's level
//! reaches an unwritten texel ([`FreshUnwritten::loads_signed_depth`]) announces it as a write that
//! may store such a value does (`signed-depth-test`, where the device's test is not Metal's), and
//! the texture is no longer noted.
//! reaches an unwritten texel ([`FreshUnwritten::loads_signed_depth`], weighed at its commit as any
//! read) announces it as a write that may store such a value does (`signed-depth-test`, where the
//! device's test is not Metal's), and the texture is no longer noted.
use super::command_buffer::CommandBuffer;
use super::device::lock;
use super::error::Error;
use super::key_hash::KeyMap;
@@ -68,9 +79,9 @@ use super::resource::ResourceKey;
use super::sparse::emulated::Written;
use super::texture::Texture;
use super::texture_descriptor::TextureLayout;
use super::tracker::{Access, UseRange};
use super::tracker::{Access, Use, UseRange};
use super::Device;
use ash::vk::ImageAspectFlags;
use ash::vk::{self, ImageAspectFlags};
use metal2vulkan::vk::{Format, ImageType};
use std::ops::Range;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -80,9 +91,58 @@ use std::sync::Mutex;
/// observed or written whole yet (the module docs).
#[derive(Default)]
pub(super) struct FreshUnwritten {
/// Whether any texture is noted: without one, a command checks nothing.
/// Whether any texture is noted: without one, a command logs nothing and a commit takes
/// nothing.
any: AtomicBool,
textures: Mutex<KeyMap<ResourceKey, Unwritten>>,
/// Held while a commit takes its command buffer's log ([`FreshUnwritten::commit`]), so each
/// command buffer's reads and writes apply together, in the order of the commits.
commits: Mutex<()>,
}
/// A command buffer's reads and writes of noted textures, in the order its commands were
/// encoded, which its commit takes ([`FreshUnwritten::commit`], the module docs' **Order**):
/// logged only while a texture is noted. A leaf lock, apart from the command buffer's state.
#[derive(Default)]
pub(crate) struct FreshLog {
events: Mutex<Vec<FreshEvent>>,
}
/// One entry of a [`FreshLog`].
enum FreshEvent {
/// `aspects` of `texels` of the texture `key` written ([`FreshUnwritten::written`]).
Written {
key: ResourceKey,
aspects: ImageAspectFlags,
texels: Written,
},
/// A read of `aspects` of `texels` ([`FreshUnwritten::observed_within`]).
Read {
key: ResourceKey,
aspects: ImageAspectFlags,
texels: Written,
},
/// A read of `aspects` of `levels` and `layers`, any texel ([`FreshUnwritten::observed`]).
ReadRange {
key: ResourceKey,
aspects: ImageAspectFlags,
levels: Range<u32>,
layers: Range<u32>,
},
/// A pass's load of the depth of `texels` of `texture`, whose image's key is `key`
/// ([`FreshUnwritten::loaded_signed_depth`]).
LoadsDepth {
key: ResourceKey,
texels: Written,
texture: Texture,
},
}
impl FreshLog {
/// Log `events`, in order.
fn push(&self, events: impl IntoIterator<Item = FreshEvent>) {
lock(&self.events).extend(events);
}
}
/// A noted texture: which texels of each aspect of its pattern levels' layers no write has
@@ -406,83 +466,198 @@ impl FreshUnwritten {
Some(notice)
}
/// A render pass of `layout` begins (the module docs): each attachment's texture, a noted
/// one, is read over the render area in its layers in each aspect it loads (`Load`),
/// announced where that reaches an unwritten texel. The texture is the attachment's own
/// where the pass renders it through another image: a stand-in's own texture, and separate
/// depth and stencil textures, each in its aspect. Its clears are counted as it ends
/// ([`cleared`](Self::cleared)).
pub(super) fn begin_pass(device: &Device, layout: &PassLayout) -> Result<(), Error> {
/// The command buffer whose log is `log` commits (`command_buffer/mod.rs`'s `commit_now`,
/// before its queue's scheduler sees it, in the order its queue runs it): where `runs` (all
/// but a refused commit, whose commands run nothing), its reads and writes of noted textures
/// apply to the record in the order they were encoded, as one, and each read that reached an
/// unwritten texel is announced once the record's locks are free, in the committing call (the
/// module docs' **Order**). One atomic read where no texture is noted; the log goes with the
/// command buffer.
pub(crate) fn commit(device: &Device, log: &FreshLog, runs: bool) {
let fresh = &device.shared().fresh;
if !fresh.any() {
return Ok(());
return;
}
for (target, aspects) in pass_targets(layout, |aspect| aspect.load == LoadAction::Load) {
let texels = pass_texels(target, layout.extent)?;
let Some(key) = image_key(&target.texture, &texels)? else {
let events = lock(&log.events).split_off(0);
if !runs || events.is_empty() {
return;
}
let mut zeroed = Vec::new();
let mut signed = Vec::new();
{
let _turn = lock(&fresh.commits);
for event in &events {
match event {
FreshEvent::Written {
key,
aspects,
texels,
} => fresh.written(*key, *aspects, texels),
FreshEvent::Read {
key,
aspects,
texels,
} => zeroed.extend(fresh.observed_within(*key, *aspects, texels)),
FreshEvent::ReadRange {
key,
aspects,
levels,
layers,
} => {
let (levels, layers) = (levels.clone(), layers.clone());
zeroed.extend(fresh.observed(*key, *aspects, levels, layers));
}
FreshEvent::LoadsDepth {
key,
texels,
texture,
} => {
if fresh.loaded_signed_depth(*key, texels) {
signed.push(texture);
}
}
}
}
}
for notice in zeroed {
device.degrade_fresh_pattern(notice);
}
for texture in signed {
texture.degrade_signed_depth("new_texture");
}
}
/// A command of `maker`'s reads each texture `uses` read in a level and layer (a blit's, a
/// shader's or an input attachment's read), logged for the commit: in the boxes `reads` names
/// of it where it names any, else any texel of those levels and layers. An attachment's own
/// reads are its pass's load, which the pass decides as it begins
/// ([`begin_pass`](Self::begin_pass)).
pub(super) fn observe_reads(
maker: &CommandBuffer,
uses: &[Use<ResourceKey>],
reads: &[FreshRead],
) {
if !maker.device().shared().fresh.any() {
return;
}
let attachment = vk::AccessFlags2::COLOR_ATTACHMENT_READ
| vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ;
let reading = |used: &&Use<ResourceKey>| !(used.read.access & !attachment).is_empty();
let mut events = Vec::new();
for used in uses.iter().filter(reading) {
let UseRange::Image {
aspects,
levels,
layers,
} = &used.range
else {
continue;
};
if let Some(notice) = fresh.observed_within(key, aspects, &texels) {
device.degrade_fresh_pattern(notice);
let mut boxes = reads.iter().filter(|read| read.key == used.key).peekable();
match boxes.peek().is_some() {
true => events.extend(boxes.map(|read| FreshEvent::Read {
key: read.key,
aspects: read.aspects,
texels: read.texels.clone(),
})),
false => events.push(FreshEvent::ReadRange {
key: used.key,
aspects: *aspects,
levels: levels.clone(),
layers: layers.clone(),
}),
}
}
maker.fresh_log().push(events);
}
/// A render pass of `layout` begins in `maker` (the module docs): each attachment's texture,
/// a noted one, is read over the render area in its layers in each aspect it loads (`Load`),
/// logged for the commit. The texture is the attachment's own where the pass renders it
/// through another image: a stand-in's own texture, and separate depth and stencil textures,
/// each in its aspect. Its clears are logged as it ends ([`cleared`](Self::cleared)).
pub(super) fn begin_pass(maker: &CommandBuffer, layout: &PassLayout) -> Result<(), Error> {
if !maker.device().shared().fresh.any() {
return Ok(());
}
let mut events = Vec::new();
for (target, aspects) in pass_targets(layout, |aspect| aspect.load == LoadAction::Load) {
let texels = pass_texels(target, layout.extent)?;
if let Some(key) = image_key(&target.texture, &texels)? {
events.push(FreshEvent::Read {
key,
aspects,
texels,
});
}
}
maker.fresh_log().push(events);
Ok(())
}
/// A render pass of `maker`'s being planned loads the depth of `target`, its depth
/// attachment (the module docs), logged for the commit: where the attachment's texture is a
/// [`FreshKind::SignedDepth`] one with an unwritten texel in the attachment's level and
/// layers then, the commit announces `signed-depth-test` for it, and it is no longer noted.
/// The whole level is weighed, as the render area is not decided yet.
pub(super) fn loads_signed_depth(maker: &CommandBuffer, target: &Target) -> Result<(), Error> {
if !maker.device().shared().fresh.any() {
return Ok(());
}
let texels = pass_texels(target, [u32::MAX; 2])?;
if let Some(key) = image_key(&target.texture, &texels)? {
maker.fresh_log().push([FreshEvent::LoadsDepth {
key,
texels,
texture: target.texture.clone(),
}]);
}
Ok(())
}
/// A render pass being planned loads the depth of `target`, its depth attachment (the module
/// docs): whether the attachment's texture is a [`FreshKind::SignedDepth`] one with an
/// unwritten texel in the attachment's level and layers, after which it is no longer noted.
/// The whole level is weighed, as the render area is not decided yet.
pub(super) fn loads_signed_depth(device: &Device, target: &Target) -> Result<bool, Error> {
let fresh = &device.shared().fresh;
if !fresh.any() {
return Ok(false);
}
let texels = pass_texels(target, [u32::MAX; 2])?;
Ok(match image_key(&target.texture, &texels)? {
Some(key) => fresh.loaded_signed_depth(key, &texels),
None => false,
})
}
/// A render pass of `layout` ends (its layout as the pass decided it, before its `DontCare`
/// loads take clears, `clear_reach.rs`): each attachment's texture is written over the
/// render area in its layers in each aspect the pass clears, where the clear reaches it: an
/// attachment the pass renders itself, or one it renders through another image (a stand-in
/// copied to and from it, separate depth and stencil textures' scratch) where the pass
/// stores that aspect, whose copy back writes it. Where such a pass does not store it
/// (`DontCare`), or renders through a backing nothing copies back, the texture keeps its
/// texels, as Metal keeps them, and stays unwritten.
pub(super) fn cleared(device: &Device, layout: &PassLayout) -> Result<(), Error> {
let fresh = &device.shared().fresh;
if !fresh.any() {
/// A render pass of `maker`'s, of `layout`, ends (its layout as the pass decided it, before
/// its `DontCare` loads take clears, `clear_reach.rs`): each attachment's texture is written
/// over the render area in its layers in each aspect the pass clears, where the clear
/// reaches it, logged for the commit: an attachment the pass renders itself, or one it
/// renders through another image (a stand-in copied to and from it, separate depth and
/// stencil textures' scratch) where the pass stores that aspect, whose copy back writes it.
/// Where such a pass does not store it (`DontCare`), or renders through a backing nothing
/// copies back, the texture keeps its texels, as Metal keeps them, and stays unwritten.
pub(super) fn cleared(maker: &CommandBuffer, layout: &PassLayout) -> Result<(), Error> {
if !maker.device().shared().fresh.any() {
return Ok(());
}
let clears = |aspect: &Aspect| aspect.load == LoadAction::Clear && aspect.reaches;
let mut events = Vec::new();
for (target, aspects) in pass_targets(layout, clears) {
let texels = pass_texels(target, layout.extent)?;
if let Some(key) = image_key(&target.texture, &texels)? {
fresh.written(key, aspects, &texels);
events.push(FreshEvent::Written {
key,
aspects,
texels,
});
}
}
maker.fresh_log().push(events);
Ok(())
}
/// A render pass ended whose resolves are `resolved` (each resolve attachment, with the
/// aspects of the resolve texture it writes), over its render area `extent` from the origin:
/// each writes those aspects of the resolve texture's level and layers over the render area
/// (the attachment's and the texture it is copied into), and the whole level where Metal
/// writes the clear color past the attachment (`Resolve::clear`), as Metal's resolve stores
/// them.
/// A render pass of `maker`'s ended whose resolves are `resolved` (each resolve attachment,
/// with the aspects of the resolve texture it writes), over its render area `extent` from the
/// origin, logged for the commit: each writes those aspects of the resolve texture's level and
/// layers over the render area (the attachment's and the texture it is copied into), and the
/// whole level where Metal writes the clear color past the attachment (`Resolve::clear`), as
/// Metal's resolve stores them.
pub(super) fn resolved(
device: &Device,
maker: &CommandBuffer,
resolved: &[(&Resolve, metal2vulkan::vk::ImageAspectFlags)],
extent: [u32; 2],
) -> Result<(), Error> {
let fresh = &device.shared().fresh;
if !fresh.any() {
if !maker.device().shared().fresh.any() {
return Ok(());
}
let mut events = Vec::new();
for (resolve, aspects) in resolved {
let copied = resolve
.copy_to
@@ -495,29 +670,40 @@ impl FreshUnwritten {
texels.size[1] = u32::MAX;
}
if let Some(key) = image_key(&target.texture, &texels)? {
fresh.written(key, (*aspects).into(), &texels);
events.push(FreshEvent::Written {
key,
aspects: (*aspects).into(),
texels,
});
}
}
}
maker.fresh_log().push(events);
Ok(())
}
/// A blit wrote `written` of `texture`: each the aspects it wrote and a box (in the image's
/// levels and layers), every sample of a multisampled texture alike (the module docs).
/// A blit of `maker`'s wrote `written` of `texture`: each the aspects it wrote and a box (in
/// the image's levels and layers), every sample of a multisampled texture alike (the module
/// docs), logged for the commit.
pub(super) fn wrote(
device: &Device,
maker: &CommandBuffer,
texture: &Texture,
written: &[(ImageAspectFlags, Written)],
) -> Result<(), Error> {
let fresh = &device.shared().fresh;
if !fresh.any() {
if !maker.device().shared().fresh.any() {
return Ok(());
}
let mut events = Vec::new();
for (aspects, texels) in written {
if let Some(key) = image_key(texture, texels)? {
fresh.written(key, *aspects, texels);
events.push(FreshEvent::Written {
key,
aspects: *aspects,
texels: texels.clone(),
});
}
}
maker.fresh_log().push(events);
Ok(())
}
+3 -3
View File
@@ -1872,7 +1872,7 @@ impl CommandBuffer {
core.hold_bytes(render_target::attachment_bytes(whole));
// The pass's loads read a new texture's unwritten texels (`fresh_unwritten.rs`): the
// descriptor's loads, before a pass of several groups loads a `DontCare` depth or stencil.
FreshUnwritten::begin_pass(device, whole)?;
FreshUnwritten::begin_pass(core.command_buffer(), whole)?;
render_pass::degrade_depth_clear(device, whole);
if groups > 1 {
color_groups::settle_depth_stencil(&mut layout);
@@ -4356,7 +4356,7 @@ impl RenderLowering {
// The pass's clears write a new texture's unwritten texels where they reach it: through
// another image only where the pass stores the aspect, whose copy back writes it
// (`fresh_unwritten.rs`). Before its `DontCare` loads take clears below.
FreshUnwritten::cleared(&device, &layout)?;
FreshUnwritten::cleared(core.command_buffer(), &layout)?;
let count = instances.len();
// The tiles the pass's draws reach, as far as the host decides them, before the
// `DontCare` loads below become `Clear` loads (`clear_reach.rs`): where they reach the
@@ -5597,7 +5597,7 @@ impl RenderLowering {
}
// The resolve textures' texels the pass's resolves wrote are no longer a new texture's
// unwritten pattern (`fresh_unwritten.rs`).
FreshUnwritten::resolved(&device, &resolved, layout.extent)?;
FreshUnwritten::resolved(core.command_buffer(), &resolved, layout.extent)?;
// The pass's one instance, where nothing recorded restarts a driver's Metal pass.
let whole = (shapes.len() == 1 && unbroken).then(|| WholePass {
shape: &shapes[0],
@@ -2145,12 +2145,10 @@ fn depth_stencil(
false => d.load_action,
};
// A new texture's depth pattern, a NaN with the sign set, that the pass loads before a write
// covered it: Metal's test compares its magnitude, the device's the value as it is
// (`fresh_unwritten.rs`).
// covered it: Metal's test compares its magnitude, the device's the value as it is. Logged
// for the commit, which weighs it in commit order and announces it (`fresh_unwritten.rs`).
if let Some(target) = depth.as_ref().filter(|_| d.load_action == LoadAction::Load) {
if FreshUnwritten::loads_signed_depth(device, target)? {
target.texture.degrade_signed_depth("new_texture");
}
FreshUnwritten::loads_signed_depth(maker, target)?;
}
let clear_depth = match nan {
Some(NanDepth::Cleared(value)) => value,
@@ -631,6 +631,8 @@ mod pack_conversions;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod padded_loads;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod parallel_encodes;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod pass_start_reads;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
mod patch_culls;
@@ -0,0 +1,434 @@
//! Command buffers of one queue encoded on several threads out of commit order, then committed in
//! order, on the device the cfg selects under the validation layer, where the runtime keeps
//! state per resource as commands are encoded rather than as they are submitted
//! (`parity::sequences::parallel` holds the sequences' bytes, hazards and notices):
//!
//! - **A new texture's pattern** (`runtime::fresh_unwritten`): a new 4-sample `Depth32Float`
//! reads zero where Metal reads its pattern (every device notes one: no clear writes a NaN),
//! announced as `fresh-pattern-zeroed` where a command first reads it unwritten; a
//! single-sample one reads zero, or holds Metal's signed NaN pattern, announced as
//! `signed-depth-test` at a load before a write where the device's depth test is not Metal's.
//! Metal's answer follows the commit order: a pass that loads it after a committed-earlier pass
//! cleared it reads the clear, and one that loads it before a committed-later clear reads the
//! pattern. Each case runs its two command buffers serially, then with the later-committed one
//! encoded whole first on another thread, and requires the same notices of both (the kinds
//! announced at every occurrence, one fresh texture a run).
//! - **A shadowed texture's carry** (`runtime::shadow`'s `ShadowCarry`): a texture over a
//! `Private` buffer at rows 48 bytes apart (32 bytes of texels: no linear image aliases it on a
//! device whose row pitch is another) written by a kernel, its buffer copied out by a blit, then
//! read by a kernel, in each of eight command buffers on four threads. Every copy and read
//! holds its own command buffer's words. A command buffer's later encoder takes the image its
//! earlier one left holding the truth, unless another encoder that used it ended in between,
//! which encoding on several threads makes likely: then it copies the truth in again. The
//! copies in are printed beside the serial run's, as `PARALLEL-SHADOW` lines.
use super::{
buffer_with, layer_reported_nothing_at_all, read_buffer, validated_device_with, Messages,
ScratchCache, WAIT,
};
use crate::air_library::AirLibrary as _;
use crate::gpu::TEST_DEVICE;
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
use metal2vulkan_devtools::{engine_dir, llvm_assemble};
use metal2vulkan_runtime::{
Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputePipelineState, Degradation,
Device, LoadAction, PipelineOptions, RenderPassDescriptor, ResourceOptions, Size, StoreAction,
Texture, TextureDescriptor, WorkCounts,
};
use std::sync::{Barrier, Condvar, Mutex};
use std::time::{Duration, Instant};
/// Wait for `command_buffer`, which must complete without an error.
fn completed(command_buffer: &CommandBuffer) {
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(
(command_buffer.status(), command_buffer.error()),
(CommandBufferStatus::Completed, None)
);
}
/// Encode command buffers `0..encodes.len()` of `queue` (made on this thread in commit order),
/// each by its closure: serially, or with each encoded only once the one committed after it was
/// encoded whole (`reversed`), on a thread of its own; then commit them in order and wait.
fn committed_in_order(
queue: &CommandQueue,
encodes: &[&(dyn Fn(&CommandBuffer) + Sync)],
reversed: bool,
) {
let command_buffers: Vec<CommandBuffer> = (0..encodes.len())
.map(|_| queue.command_buffer().unwrap())
.collect();
if reversed {
// The baton: the next command buffer that may encode, from the last down.
let baton = Mutex::new(encodes.len() - 1);
let passed = Condvar::new();
std::thread::scope(|scope| {
for (index, encode) in encodes.iter().enumerate() {
let (baton, passed, command_buffer) = (&baton, &passed, &command_buffers[index]);
scope.spawn(move || {
let mut held = baton.lock().unwrap();
while *held != index {
held = passed.wait_timeout(held, WAIT).unwrap().0;
}
encode(command_buffer);
*held = index.saturating_sub(1);
drop(held);
passed.notify_all();
});
}
});
} else {
for (encode, command_buffer) in encodes.iter().zip(&command_buffers) {
encode(command_buffer);
}
}
for command_buffer in &command_buffers {
command_buffer.commit().unwrap();
}
for command_buffer in &command_buffers {
completed(command_buffer);
}
}
/// A new `Private` `Depth32Float` render target, 16 square, of `samples`.
fn fresh_depth(device: &Device, samples: u64) -> Texture {
let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::Depth32Float, 16, 16, false);
if samples > 1 {
descriptor.texture_type = TextureType::Type2DMultisample;
descriptor.sample_count = samples;
}
descriptor.usage = TextureUsage::RENDER_TARGET | TextureUsage::SHADER_READ;
descriptor.resource_options = ResourceOptions::private();
device.new_texture(&descriptor).unwrap()
}
/// A pass of `depth` alone that loads it by `load` (a clear to 0.25) and stores it, encoded
/// with no draw into `command_buffer`.
fn depth_pass(command_buffer: &CommandBuffer, depth: &Texture, load: LoadAction) {
let mut pass = RenderPassDescriptor::new();
pass.depth_attachment.texture = Some(depth.clone());
pass.depth_attachment.load_action = load;
pass.depth_attachment.clear_depth = 0.25;
pass.depth_attachment.store_action = StoreAction::Store;
let encoder = command_buffer.render_command_encoder(&pass).unwrap();
encoder.end_encoding().unwrap();
}
/// The notices of a new texture's pattern read (`FRESH_KINDS`) `messages` holds, taken with the
/// rest.
fn fresh_notices(messages: &Messages) -> usize {
(messages.take_notices().iter())
.filter_map(|message| message.degradation.as_ref())
.filter(|notice| FRESH_KINDS.contains(&notice.degradation))
.count()
}
/// What a pass's load of a new texture's unwritten depth pattern announces: `fresh-pattern-zeroed`
/// where the texture reads zero, `signed-depth-test` where it holds Metal's signed NaN and the
/// device's depth test is not Metal's (`runtime::fresh_unwritten`).
const FRESH_KINDS: [Degradation; 2] = [
Degradation::FreshPatternZeroed,
Degradation::SignedDepthTest,
];
/// The notice of a new texture's pattern follows the commit order (the module docs): a load
/// after a committed-earlier clear announces nothing, and a load before a committed-later clear
/// announces the pattern it reads, whichever pass was encoded first. A 4-sample `Depth32Float`
/// reads zero on every device (`fresh-pattern-zeroed`, Metal reading the pattern once where its
/// load comes first); a single-sample one reads zero, or holds Metal's signed NaN, announced as
/// `signed-depth-test` where the device's depth test is not Metal's: its serial run, in commit
/// order, is its answer.
#[test]
fn a_fresh_texture_s_pattern_notice_follows_the_commit_order() {
let messages = Messages::default();
let cache = ScratchCache::new().unwrap();
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |options| {
options.announce_each.extend(FRESH_KINDS);
})
.unwrap();
let name = device.name().to_owned();
let queue = device.new_command_queue().unwrap();
messages.take_notices();
// (samples, the first pass's load, the second's, Metal's reads of the pattern where every
// device announces them)
let cases = [
(4, LoadAction::Clear, LoadAction::Load, Some(0)),
(4, LoadAction::Load, LoadAction::Clear, Some(1)),
(1, LoadAction::Clear, LoadAction::Load, Some(0)),
(1, LoadAction::Load, LoadAction::Clear, None),
];
let mut wrong = Vec::new();
for (samples, first, second, metal) in cases {
let mut announced = [0; 2];
for (reversed, count) in announced.iter_mut().enumerate() {
let depth = fresh_depth(&device, samples);
let one = |cb: &CommandBuffer| depth_pass(cb, &depth, first);
let two = |cb: &CommandBuffer| depth_pass(cb, &depth, second);
committed_in_order(&queue, &[&one, &two], reversed == 1);
*count = fresh_notices(&messages);
}
println!(
"PARALLEL-FRESH on {name}: {samples}x, {first:?} then {second:?}: {} notice(s) serially, {} with the later encoded first; Metal reads the pattern {metal:?} time(s)",
announced[0], announced[1]
);
let expected = metal.unwrap_or(announced[0]);
if announced != [expected; 2] {
wrong.push((samples, first, second, announced, expected));
}
}
assert!(
wrong.is_empty(),
"on {name}, notices of a new texture's pattern read that differ from the reads in commit order ((samples, loads, notices serially and with the later encoded first, the answer)): {wrong:?}"
);
drop(queue);
drop(device);
layer_reported_nothing_at_all(&messages);
}
/// The texels of the shadowed texture: `SIDE`² `RGBA8Unorm`, rows [`ROW`] bytes apart.
const SIDE: u64 = 8;
const ROW: u64 = 48;
const TEXEL_ROW: u64 = 4 * SIDE;
const BYTES: u64 = ROW * SIDE;
const WORDS: u64 = SIDE * SIDE;
/// The command buffers of the shadow test, its threads, and its runs each way.
const SHADOW_COMMAND_BUFFERS: usize = 8;
const SHADOW_THREADS: usize = 4;
const SHADOW_RUNS: u64 = 16;
/// SplitMix64, for the test's bytes and pauses.
struct Rng(u64);
impl Rng {
fn next(&mut self) -> u64 {
self.0 = self.0.wrapping_add(0x9E37_79B9_7F4A_7C15);
let mut z = self.0;
z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9);
z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB);
z ^ (z >> 31)
}
fn bytes(&mut self, len: u64) -> Vec<u8> {
(0..len).map(|_| self.next() as u8).collect()
}
}
/// The fixture's texel kernels (`seq_programs`): words into texels, and texels into words.
struct TexelKernels {
write: ComputePipelineState,
read: ComputePipelineState,
}
fn texel_kernels(device: &Device) -> TexelKernels {
let bitcode = llvm_assemble(&engine_dir().join("seq_programs.ll")).unwrap();
let library = device.new_library_with_air(&bitcode).unwrap();
let kernel = |name| {
let function = library.new_function_with_name(name).unwrap();
device
.new_compute_pipeline_state_with_function(&function, &PipelineOptions::default())
.unwrap()
};
TexelKernels {
write: kernel("seq_texel_write"),
read: kernel("seq_texel_read"),
}
}
/// One dispatch of `kernel` over the texture's texels, with `words`.
fn texel_dispatch(
cb: &CommandBuffer,
kernel: &ComputePipelineState,
texture: &Texture,
words: &Buffer,
) {
let mut compute = cb.compute_command_encoder().unwrap();
compute.set_compute_pipeline_state(kernel).unwrap();
compute.set_texture(Some(texture), 0).unwrap();
compute.set_buffer(Some(words), 0, 0).unwrap();
compute
.dispatch_threads(Size::new(SIDE, SIDE, 1), Size::new(SIDE, 1, 1))
.unwrap();
compute.end_encoding().unwrap();
}
/// One run of the shadow test's command buffers: each one's words, and the buffers its copy and
/// its read fill.
struct ShadowRun {
words: Vec<Buffer>,
copies: Vec<Buffer>,
reads: Vec<Buffer>,
}
/// The shadow test's work counts: shadow copies, texels copied in, texels a carry spared.
fn shadow_counts(counts: &WorkCounts) -> [u64; 3] {
[
counts.shadow_copies,
counts.shadow_texels_copied_in,
counts.shadow_texels_first_copy_in_carried,
]
}
/// A run of the shadow test on `device` (the module docs), its command buffers encoded on this
/// thread in turn, or on [`SHADOW_THREADS`] threads from a barrier, with seeded pauses, where
/// `seed` is some; each command buffer's copy and read compared with its words. Its counts.
fn shadow_run(
device: &Device,
queue: &CommandQueue,
(truth, texture, initial): (&Buffer, &Texture, &[u8]),
kernels: &TexelKernels,
seed: Option<u64>,
) -> [u64; 3] {
let mut rng = Rng(seed.unwrap_or(0x5AD0));
let run = ShadowRun {
words: (0..SHADOW_COMMAND_BUFFERS)
.map(|_| buffer_with(device, &rng.bytes(4 * WORDS)).unwrap())
.collect(),
copies: (0..SHADOW_COMMAND_BUFFERS)
.map(|_| buffer_with(device, &vec![0xee; BYTES as usize]).unwrap())
.collect(),
reads: (0..SHADOW_COMMAND_BUFFERS)
.map(|_| buffer_with(device, &vec![0xee; (4 * WORDS) as usize]).unwrap())
.collect(),
};
let encode = |index: usize, cb: &CommandBuffer, pause: &mut dyn FnMut()| {
texel_dispatch(cb, &kernels.write, texture, &run.words[index]);
pause();
let mut blit = cb.blit_command_encoder().unwrap();
blit.copy_from_buffer_to_buffer(truth, 0, &run.copies[index], 0, BYTES)
.unwrap();
blit.end_encoding().unwrap();
pause();
texel_dispatch(cb, &kernels.read, texture, &run.reads[index]);
};
let before = shadow_counts(&device.work_counts());
let command_buffers: Vec<CommandBuffer> = (0..SHADOW_COMMAND_BUFFERS)
.map(|_| queue.command_buffer().unwrap())
.collect();
match seed {
None => {
for (index, cb) in command_buffers.iter().enumerate() {
encode(index, cb, &mut || {});
}
}
Some(_) => {
let start = Barrier::new(SHADOW_THREADS);
let seeds: Vec<u64> = (0..SHADOW_THREADS).map(|_| rng.next()).collect();
std::thread::scope(|scope| {
for (me, &seed) in seeds.iter().enumerate() {
let (start, encode, command_buffers) = (&start, &encode, &command_buffers);
scope.spawn(move || {
let mut rng = Rng(seed);
let mut pause = || match rng.next() % 4 {
0 => {}
1 => std::thread::yield_now(),
2 => {
let until = Instant::now() + Duration::from_micros(rng.next() % 30);
while Instant::now() < until {
std::hint::spin_loop();
}
}
_ => std::thread::sleep(Duration::from_micros(rng.next() % 60)),
};
start.wait();
// Each thread takes every fourth command buffer, the latest first.
let mine = (0..SHADOW_COMMAND_BUFFERS)
.rev()
.filter(|i| i % SHADOW_THREADS == me);
for index in mine {
pause();
encode(index, &command_buffers[index], &mut pause);
}
});
}
});
}
}
for cb in &command_buffers {
cb.commit().unwrap();
}
for cb in &command_buffers {
completed(cb);
}
let after = shadow_counts(&device.work_counts());
for index in 0..SHADOW_COMMAND_BUFFERS {
let words = read_buffer(&run.words[index], 0, 4 * WORDS).unwrap();
let mut expected = initial.to_vec();
for row in 0..SIDE {
let (at, from) = ((row * ROW) as usize, (row * TEXEL_ROW) as usize);
expected[at..at + TEXEL_ROW as usize]
.copy_from_slice(&words[from..from + TEXEL_ROW as usize]);
}
assert_eq!(
read_buffer(&run.copies[index], 0, BYTES).unwrap(),
expected,
"cb{index}'s copy of the buffer under seed {seed:?}"
);
assert_eq!(
read_buffer(&run.reads[index], 0, 4 * WORDS).unwrap(),
words,
"cb{index}'s read of the texture under seed {seed:?}"
);
}
[0, 1, 2].map(|i| after[i] - before[i])
}
/// A shadowed texture's every use holds its own command buffer's bytes however its command
/// buffers' encoders interleave; the copies in a carry spares serially are printed beside those
/// the parallel runs made (the module docs).
#[test]
fn a_shadowed_texture_keeps_each_command_buffer_s_bytes() {
let messages = Messages::default();
let cache = ScratchCache::new().unwrap();
let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), |_| {}).unwrap();
let name = device.name().to_owned();
let queue = device.new_command_queue().unwrap();
let kernels = texel_kernels(&device);
let initial = Rng(0x1A1A).bytes(BYTES);
let staging = buffer_with(&device, &initial).unwrap();
let truth = device
.new_buffer(BYTES, ResourceOptions::private())
.unwrap();
let setup = queue.command_buffer().unwrap();
let mut blit = setup.blit_command_encoder().unwrap();
blit.copy_from_buffer_to_buffer(&staging, 0, &truth, 0, BYTES)
.unwrap();
blit.end_encoding().unwrap();
setup.commit().unwrap();
completed(&setup);
let shadows = device.work_counts().shadowed_textures;
let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false);
descriptor.usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE;
descriptor.resource_options = ResourceOptions::private();
let texture = truth.new_texture(&descriptor, 0, ROW).unwrap();
let shadowed = device.work_counts().shadowed_textures > shadows;
let shadow = (&truth, &texture, &initial[..]);
let serial: Vec<[u64; 3]> = (0..SHADOW_RUNS)
.map(|_| shadow_run(&device, &queue, shadow, &kernels, None))
.collect();
let parallel: Vec<[u64; 3]> = (0..SHADOW_RUNS)
.map(|run| {
let seed = 0x5EED_0000 + run;
shadow_run(&device, &queue, shadow, &kernels, Some(seed))
})
.collect();
let sum = |runs: &[[u64; 3]]| {
runs.iter()
.fold([0; 3], |sum, run| [0, 1, 2].map(|i| sum[i] + run[i]))
};
println!(
"PARALLEL-SHADOW on {name}: shadowed {shadowed}; over {SHADOW_RUNS} runs of \
{SHADOW_COMMAND_BUFFERS} command buffers, (shadow copies, texels copied in, texels a \
carry spared) serially {:?}, on {SHADOW_THREADS} threads {:?}",
sum(&serial),
sum(&parallel)
);
let notices: Vec<String> = (messages.take_notices().iter())
.filter_map(|message| message.degradation.as_ref())
.map(|notice| notice.degradation.code().to_owned())
.collect();
println!("PARALLEL-SHADOW on {name}: notices {notices:?}");
drop((texture, truth, queue, kernels));
drop(device);
layer_reported_nothing_at_all(&messages);
}
+7 -4
View File
@@ -1859,8 +1859,10 @@ bound.
texture Metal keeps losslessly compressed reads a fixed pattern in Metal, which the device cannot
write exactly into its image: a NaN depth where a copy into a depth image may store it clamped or
the image is multisampled, a NaN texel of a multisampled image (whose bits a clear leaves to the
device), or an image holding other bytes than Metal's texel. Cost: the new texture reads zero
where Metal reads its fixed pattern until a write.
device), or an image holding other bytes than Metal's texel. Announced at the commit of the
command buffer whose command first reads a texel of that content no clear, resolve or blit
covered, in commit order, whatever order or thread the command buffers were encoded in. Cost:
the new texture reads zero where Metal reads its fixed pattern until a write.
- `metal2vulkan-degrade-zeroed-index-fetch` (precision). `ZeroedIndexFetch`: An indexed draw from an
index offset at or past its index buffer's length draws index 0 plus the base vertex at each
position, a direct draw from a zero-padded copy and an indirect one through the index bounds pass,
@@ -2743,8 +2745,9 @@ bound.
a pass with depth writes that may store such a value with its sign, where Metal's test compares
the stored value's magnitude (a NaN above +inf) and its pass with depth writes stores every texel
no fragment wrote without its sign. Announced at a write that may give a render target's depth
such a value, or at the pass that loads a new texture's pattern (a NaN with the sign set) before a
write covered it, on a device that keeps such a value in a depth image:
such a value, or at the commit of a pass that loads a new texture's pattern (a NaN with the sign
set) before a write covered it in commit order, on a device that keeps such a value in a depth
image:
`VK_EXT_depth_range_unrestricted` enabled, or `DriverFact::DepthImageKeepsValuesOutsideUnitRange`
(elsewhere `restricted-depth-upload` is announced). MoltenVK's test is Metal's own
(`DriverFact::DepthTestComparesMagnitudes`): there it is announced at a pass that loads and stores