RUNTIME 2332: A pass's first instance records inline over a bound linear color, and snapshot readers inline after a split

A pass's first instance records inline over a bound linear color

On a device that renders a linear image only by VK_NV_linear_color_attachment's rule
(NVIDIA's), the guest surface is a bound linear color rendered in place, and
inline_first refused it (NotInline::Attachments): every such pass recorded its first
instance into a secondary, and its splits too. The 3090 walk's counts put about 52 of
its 88 secondaries a frame there.

The refusal guarded linear_attachment::settle, which may render the bound colors apart
as the pass ends where a later instance renders a color through a stand-in of another
format. That case already has its route for an inline first instance: the stand-in
arrives later, takes the attachment's texels right after the last inline instance and
is merged back (render.rs's stand_ins_after_first and kept_after_first, as for a
fetched attachment's scratch). Every color of an instance that opens inline is linear
and the pass has no depth or stencil attachment, since apart() renders the bound
colors apart from the open otherwise, through a stand-in inline_first refuses; and no
inline instance after a split takes a view of another format. So the first instance
renders the image in place under the extension's rule, and the refusal goes.

Tests:
- tests::bound_inline (new): with the rule forced, an R32Float target over a Shared
  buffer, a first draw inline in place, an RGBA8Unorm draw through a stand-in of that
  format, a third draw; counts one inline pass, no refusal for its attachments, one
  pass through copies, and the bytes equal a private texture's.
- runtime_lane::linear_attachments: the sampling and detach tests expect the pass
  inline by the rule too; the sampling test's instance after the split is inline but
  where the reader's snapshots lead it.

Verification: the jobs that compile and run it are reported with this sha.

Instances that read through snapshots record inline after a split too

A draw that reads its pass's texture through a snapshot inside its instance, or in place,
holds those colors in the feedback loop layout for the instance's render pass instance.
Inline splits refused such an instance (inline_splits.rs, `instance.feedback ==
Feedback::NONE`), so after an inline first instance every reader split the pass into a
secondary: its begin, end, execute and whole dynamic state recorded again, which the
inline route exists to remove.

An instance recorded inline after a split now takes them as the pass's end takes a
secondary's: a render pass of the instance's shape with those colors in that layout
(render_target::final_pass with its Feedback) and a framebuffer whose views of them carry
feedback loop usage, one Later per shape, feedback colors and arrivals; the moves from
GENERAL into the layout right before its begin and back right after its end
(render_target::moved_barriers), recorded by record_kept around it, and after the pass's
last inline instance as the pass ends it. The snapshot pairs' B1/B2 and the in-place
reader's barriers record with the kept draws as before (Pair, in the recordings). A later
reader of the same colors, or of some of them, records into such an instance rather than
splitting again (snapshot_apart), as it does into a secondary's. Leading snapshots stay
out: their instance records in a secondary. The commands, their order and the barriers
between instances are the end's; only SUBPASS_CONTENTS_INLINE in the pass's command
buffer replaces a secondary and its execute.

The guard of the previous commit, tests::bound_inline, expects on a device whose draws
read colors as input attachments (lavapipe) the end's existing refusal of a bound color
put apart while every color is taken, as before.

Verification: the jobs that compile and run it are reported with this sha.

Verified: job 31111 at 5a4df749ec: clippy -D warnings plain, under --cfg
m2v_gpu and --cfg m2v_cpu_icd; rustdoc -D warnings; the runtime suite on
lavapipe 2744/2744 (tests::bound_inline among them, its refusal branch
there); the render lanes on lavapipe 133/133. Lavapipe takes neither the
bound-linear apart case nor snapshots: the pixel proof and the A/B of
begins and secondaries a frame are the 5080 and Iris runs, pending.
This commit is contained in:
Anees Iqbal committed 2026-11-14 20:31:16 -08:00
1 parent 8e052df070
commit 51b19a5bb4
10 files changed
+433 -90

No files matched your search

@@ -26,8 +26,10 @@
//! begins, from its descriptor ([`apart`]), so every use a draw makes of the attachment (a
//! framebuffer fetch's view, a view in another format) finds the image the pass renders; and
//! again as it ends ([`settle`]), where a draw made an attachment of the runtime's (a fetched
//! texture's scratch, a stand-in of another format): a bound attachment a draw took a view of is
//! refused there (`NotImplemented(Render)`), as the pass cannot render it apart any more.
//! texture's scratch, a stand-in of another format), from the first instance after those
//! recorded inline, which rendered it in place (`render/inline_first.rs`): a bound attachment a
//! draw took a view of is refused there (`NotImplemented(Render)`), as the pass cannot render it
//! apart any more.
//! - **A multisampled pass resolving into a bound texture** resolves into a scratch image copied
//! there (`resolve.rs`).
//!
@@ -256,8 +258,10 @@ pub(super) fn apart(
/// Render the bound attachments among `layout`'s colors, a pass's as it ends, apart where a
/// render pass instance of it holds a color attachment that is not linear: `other`, the first
/// color index an instance renders through an image of the runtime's (a stand-in of another
/// format), of the first instance with one. Refused (`NotImplemented(Render)`) where a draw took a view of a bound one
/// (`taken`): the pass renders it in place.
/// format), of the first instance with one. Its instances recorded inline before that one
/// rendered them in place, and the image each renders through takes their texels right after
/// them (`render/inline_first.rs`). Refused (`NotImplemented(Render)`) where a draw took a view
/// of a bound one (`taken`): the pass renders it in place.
pub(super) fn settle(
maker: &CommandBuffer,
colors: &mut [Option<ColorTarget>],
+25
View File
@@ -4702,6 +4702,12 @@ impl RenderLowering {
.iter()
.take_while(|instance| instance.inline)
.count();
// The last of them's colors in the feedback loop layout, where it recorded inline after a
// split, moved back to `GENERAL` right after its render pass instance ends, as the pass's
// end ends it (`render/inline_splits.rs`).
let inline_moved = (inlined.checked_sub(1))
.and_then(|last| instances[last].kept.as_ref())
.map_or_else(Vec::new, |kept| kept.moved().to_vec());
if inline && instances.len() > 1 {
core.device().shared().counts.inline_pass_split();
}
@@ -6371,6 +6377,25 @@ impl RenderLowering {
});
}
core.release_pass()?;
if !inline_moved.is_empty() {
let family = core.queue_flags();
core.command(vk::PipelineStageFlags2::NONE, &[], |raw, command_buffer| {
// SAFETY: the pass's command buffer is recording right after the last inline
// instance's render pass instance ended, and only this encoder records it;
// its colors in the feedback loop layout are there since its begin, their
// images live until the command buffer completes (the layout's textures,
// which the encoder retains).
unsafe {
render_target::moved_barriers(
raw,
command_buffer,
&inline_moved,
false,
family,
)
}
});
}
}
// The passes of the runs an execution may split an instance into (`render/executions.rs`).
let mut run_objects = Vec::new();
@@ -25,14 +25,27 @@
//! from the whole pass may change them. So: an attachment, one layer of one sample, no
//! rasterization-rate map, custom sample positions or visibility buffer, and
//! every color attachment the texture's own image or its image over a buffer's bytes
//! (`Texture::image_over_buffer`; not a texture buffer, a shadow, a stand-in while the bytes
//! are detached, or a bound linear image), of no extended-range, padded or bfloat format,
//! (`Texture::image_over_buffer`; a bound linear image among them, below; not a texture
//! buffer, a shadow, or a stand-in while the bytes are detached), of no extended-range, padded
//! or bfloat format,
//! with no resolve or stand-in, loaded `Load` or `Clear` (of no NaN the device must clear
//! apart) and stored `Store`; or a memoryless texture's own transient image loaded and stored
//! `DontCare` (below). Then the end changes none of the first instance's load and store
//! operations (`render_target::final_pass` stores every attachment of an instance that is not
//! the last; so does the last here, and `kept_bytes.rs` keeps a stored attachment in place),
//! its attachments or its clear values.
//! - **A bound linear image** (`linear_attachment.rs`: a linear image the device renders only
//! where every color attachment of the render pass instance is linear,
//! `VK_NV_linear_color_attachment`'s rule) renders in place in the first instance. A pass
//! beside a color that is not linear, or with a depth or stencil attachment, renders it apart
//! from its open (`linear_attachment::apart`), through a stand-in, which rules the instance
//! out; so every color of an instance that opens is linear, and the pass has no depth or
//! stencil attachment. A later instance whose draw renders a color through an image of the
//! runtime's (a stand-in of another format) records in a secondary, as no inline instance
//! after a split takes a view of another format (`render/inline_splits.rs`), and the pass's end
//! renders the bound colors apart from the first instance after the inline ones
//! (`linear_attachment::settle`): a stand-in that arrives later (below). Such a pass joins no
//! run of passes (`pass_runs.rs`), as no pass recorded inline does.
//! - **A depth/stencil attachment** ([`depth_stencil_opens`]) the texture's own image (not the
//! scratch image of separate depth and stencil textures, `depth_stencil_scratch.rs`, a
//! stand-in, `attachment_stand_in.rs`, or a texture over a buffer), held in `GENERAL` (`render_target::depth_layout`: a
@@ -123,7 +136,8 @@
//! before the later instances (`EncoderCore::cut_before`): the first instance runs after them,
//! as where the segment records it.
//! - **A stand-in that arrives later** (a fetched attachment whose image lacks the usage the
//! fetch needs) stands in from the next instance on: the end copies each attachment into its
//! fetch needs, or a bound linear image the end renders apart) stands in from the next
//! instance on: the end copies each attachment into its
//! stand-in right after the inline instance, which rendered the attachment itself, not before
//! the pass, and back after the last as before; after the last instance a draw pinned to the
//! attachments' own images, where one did (`render/snapshot.rs`). The stand-in of a texture
@@ -155,7 +169,6 @@ use super::{Instance, Next, RenderLowering, ViewSetup};
use crate::clear_reach;
use crate::device::Device;
use crate::error::Error;
use crate::linear_attachment;
use crate::render_pass::{ColorTarget, DepthStencilTarget, PassLayout};
use crate::render_target::{
self, Feedback, FramebufferObject, PassShape, Position, RenderPassObject,
@@ -288,8 +301,7 @@ pub(super) fn opens_inline(
let own = color.stand_in.is_none()
&& color.planes.is_none()
&& color.straight_clear.is_none()
&& ExtendedRange::of(texture.pixel_format()).is_none()
&& linear_attachment::bound(device, target).is_ok_and(|bound| !bound);
&& ExtendedRange::of(texture.pixel_format()).is_none();
if !own {
return Err(NotInline::Attachments);
}
@@ -56,11 +56,21 @@
//! made, no view of another format, multiview, shader-side test, depth stand-in, tile
//! dispatch, execution of render commands, pending pipeline, imageblock or visibility query in
//! the pass so far, no stand-in arriving with it but memoryless colors' backings (below), and
//! no color its draw reads through a snapshot (`render/snapshot.rs`), whose feedback loop
//! layout the later render pass would lack. Elsewhere the instance records as before, in a
//! secondary, and so does every later one.
//! - **Render passes and framebuffers** ([`Later`]): one of each per shape and set of
//! attachments, made at the first instance that needs it. Two attachment references "are
//! no snapshots of its draw that lead it (`render/snapshot.rs`), which run in a render pass
//! instance of their own before it. Elsewhere the instance records as before, in a secondary,
//! and so does every later one.
//! - **Colors in the feedback loop layout** (`render_target::Feedback`): an instance whose draw
//! reads colors through snapshots inside it, or in place (`render/snapshot.rs`), holds them
//! there for its render pass instance, as the pass's end holds a secondary's: its render pass
//! and framebuffer are of those colors in that layout (`render_target::final_pass`,
//! `render_target::framebuffer`, whose views of them have the usage it needs), and they move
//! there from `GENERAL` right before its begin and back right after its end
//! (`render_target::moved_barriers`), between the instance before and the barrier after it.
//! A later draw of such a reader's colors, or of some of them, records into it, as into a
//! secondary's instance; one of another color records into a new instance
//! (`RenderCommandEncoder::snapshot_apart`).
//! - **Render passes and framebuffers** ([`Later`]): one of each per shape, colors in the
//! feedback loop layout and set of attachments, made at the first instance that needs it. Two attachment references "are
//! compatible if they have matching format and sample count, or are both
//! `VK_ATTACHMENT_UNUSED`", so a render pass that leaves a color out for the interlock is not
//! compatible with the first instance's, whose framebuffer it cannot begin in: it takes a
@@ -87,7 +97,7 @@ use crate::encoder::EncoderCore;
use crate::error::Error;
use crate::render_pass::PassLayout;
use crate::render_target::{
self, Feedback, FramebufferObject, PassShape, Position, RenderPassObject,
self, Feedback, FramebufferObject, MovedImage, PassShape, Position, RenderPassObject,
};
use crate::render_values::LoadAction;
use crate::shadow::ShadowCopy;
@@ -107,6 +117,10 @@ pub(super) struct Kept {
objects: (vk::RenderPass, vk::Framebuffer),
/// The clears of the memoryless colors' backings that arrived with it, before it.
clears: Option<Clears>,
/// Its colors in the feedback loop layout, moved there right before its render pass instance
/// begins and back right after it ends (`render_target::moved_images`); none for an instance
/// of no such color.
moved: Vec<MovedImage>,
}
/// Where a [`Kept`] keeps its draws and commands, which the device keeps once its pass ended
@@ -182,6 +196,12 @@ enum KeptCommand {
}
impl Kept {
/// Its colors in the feedback loop layout, which move back to `GENERAL` right after its render
/// pass instance ends.
pub(super) fn moved(&self) -> &[MovedImage] {
&self.moved
}
/// Keep a draw's `recording`, of its made `pipeline`: over the room an earlier instance's
/// recording left where there is one.
pub(super) fn draw(&mut self, recording: &Recording, pipeline: vk::Pipeline) {
@@ -242,12 +262,14 @@ impl Kept {
}
/// A render pass and framebuffer inline instances after a split begin in: a render pass of
/// their shape that loads and stores every attachment, and a framebuffer of the pass's
/// attachments as they stand, made at the first such instance; the first instance's framebuffer
/// serves those of its shape and attachments.
/// their shape and colors in the feedback loop layout that loads and stores every attachment,
/// and a framebuffer of the pass's attachments as they stand, made at the first such instance;
/// the first instance's framebuffer serves those of its shape and attachments with no such color.
pub(super) struct Later {
/// The shape of the instances it serves.
shape: PassShape,
/// Their colors in the feedback loop layout.
feedback: Feedback,
/// The backings' arrivals before them (`inline_first::Begun::stood`).
stood: u32,
pass: RenderPassObject,
@@ -263,6 +285,7 @@ pub(super) struct SplitBegin {
copies: Vec<ShadowCopy>,
objects: (vk::RenderPass, vk::Framebuffer),
clears: Option<Clears>,
moved: Vec<MovedImage>,
}
impl RenderLowering {
@@ -314,16 +337,21 @@ impl RenderLowering {
&& instance.reformats.is_empty()
&& instance.views == ViewSetup::default()
&& !instance.shadow
&& !instance.shader_tests
&& instance.feedback == Feedback::NONE;
&& !instance.shader_tests;
if !admitted {
return None;
}
// Its render pass and framebuffer: the instances' of its shape since the last backings
// arrived, else made now, of the pass's attachments as they stand from it on.
// Its render pass and framebuffer: the instances' of its shape and colors in the feedback
// loop layout since the last backings arrived, else made now, of the pass's attachments
// as they stand from it on.
let stood_now = begun.stood + u32::from(stood.is_some());
let feedback = instance.feedback;
let found = (begun.later.iter())
.find(|later| later.shape == *instance.shape && later.stood == stood_now)
.find(|later| {
later.shape == *instance.shape
&& later.feedback == feedback
&& later.stood == stood_now
})
.map(|later| {
let framebuffer = later.framebuffer.as_ref().unwrap_or(&begun.framebuffer);
(later.pass.raw, framebuffer.raw)
@@ -336,22 +364,25 @@ impl RenderLowering {
first: false,
last: false,
};
let (none, general) = (Feedback::NONE, vk::ImageLayout::GENERAL);
let general = vk::ImageLayout::GENERAL;
let device = self.core.device().clone();
let (shape, views) = (&instance.shape, instance.views);
let pass =
render_target::final_pass(&device, layout, shape, at, none, general).ok()?;
let pass = render_target::final_pass(&device, layout, shape, at, feedback, general)
.ok()?;
// The first instance's framebuffer is compatible with a render pass of its
// shape, of the same attachments.
let framebuffer = match **shape == begun.shape && stood_now == 0 {
// shape, of the same attachments, whose views of colors in the feedback loop
// layout lack the usage it needs.
let first = **shape == begun.shape && stood_now == 0 && feedback == Feedback::NONE;
let framebuffer = match first {
true => None,
false => Some(
render_target::framebuffer(&device, &pass, layout, shape, views, none)
render_target::framebuffer(&device, &pass, layout, shape, views, feedback)
.ok()?,
),
};
Some(Later {
shape: PassShape::clone(shape),
feedback,
stood: stood_now,
pass,
framebuffer,
@@ -363,6 +394,8 @@ impl RenderLowering {
Some((&color.target, color.clear))
});
let clears = Clears::plan(backings).ok()?;
let general = vk::ImageLayout::GENERAL;
let moved = render_target::moved_images(layout, instance.views, feedback, general).ok()?;
let copies = self.plan_one(None).ok()?;
let inline_first::Inline::Begun(begun) = &mut self.inline else {
return None;
@@ -382,6 +415,7 @@ impl RenderLowering {
copies,
objects,
clears,
moved,
})
}
@@ -398,6 +432,7 @@ impl RenderLowering {
copies,
objects,
clears,
moved,
} = begin;
self.record_flushed(before, &copies);
let device = self.core.device().clone();
@@ -407,6 +442,7 @@ impl RenderLowering {
draws: 0,
objects,
clears,
moved,
});
self.current.rerecord = None;
device.shared().counts.inline_split_instance();
@@ -420,7 +456,9 @@ impl RenderLowering {
if waiting(&self.current) {
let copies = self.plan_one(None)?;
let bound = &mut self.held_bound;
record_kept(&mut self.core, bound, &self.current, &copies, &self.layout);
let ended = ended_moves(self.earlier.last());
let kept = (&self.current, &copies[..], ended);
record_kept(&mut self.core, bound, kept, &self.layout);
self.current.planned = true;
return Ok(());
}
@@ -490,7 +528,13 @@ impl RenderLowering {
self.core.shadow_copies(copies);
} else {
let (bound, instance) = (&mut self.held_bound, &self.earlier[at]);
record_kept(&mut self.core, bound, instance, copies, &self.layout);
let ended = ended_moves(at.checked_sub(1).map(|before| &self.earlier[before]));
record_kept(
&mut self.core,
bound,
(instance, copies, ended),
&self.layout,
);
}
self.earlier[at].planned = true;
}
@@ -542,18 +586,24 @@ fn arriving_backings(layout: &PassLayout, stood: &PassLayout) -> Option<ColorLis
Some(arriving)
}
/// The colors in the feedback loop layout of `instance`, whose render pass instance the next
/// kept one's recording ends ([`record_kept`]): none for the pass's first instance, or one of no
/// such color.
fn ended_moves(instance: Option<&Instance>) -> &[MovedImage] {
(instance.and_then(|instance| instance.kept.as_ref())).map_or(&[][..], |kept| kept.moved())
}
/// Record `instance`, kept (the module docs), into the pass's command buffer after the render
/// pass instance before it: that one's end, a barrier from everything before, `copies` (one run
/// of them, `EncoderCore::held_shadow_copies`, followed by a barrier), the steps its draws take
/// before it, its render pass instance's begin
/// in `objects` (a render pass compatible with its draws' pipelines, and the pass's
/// framebuffer), and its commands, recorded through `bound`, the record of what the command
/// buffer bound.
/// pass instance before it: that one's end, the moves of its colors in the feedback loop layout
/// back to `GENERAL` (`ended`), a barrier from everything before, `copies` (one run of them,
/// `EncoderCore::held_shadow_copies`, followed by a barrier), the steps its draws take before it,
/// the moves of its own such colors there, its render pass instance's begin in `objects` (a
/// render pass compatible with its draws' pipelines, and the pass's framebuffer), and its
/// commands, recorded through `bound`, the record of what the command buffer bound.
fn record_kept(
core: &mut EncoderCore,
bound: &mut Bound,
instance: &Instance,
copies: &[ShadowCopy],
(instance, copies, ended): (&Instance, &[ShadowCopy], &[MovedImage]),
layout: &PassLayout,
) {
let (Some(held), Some(kept)) = (core.held_pass(), instance.kept.as_ref()) else {
@@ -563,10 +613,14 @@ fn record_kept(
let device = core.device().clone();
let shared = device.shared();
let raw = shared.vk();
let family = core.queue_flags();
// SAFETY: the held command buffer is recording inside the render pass instance before this
// one, and only this encoder records it.
// one, and only this encoder records it; that instance's colors in the feedback loop layout
// (`ended`) are there from its begin, their images live until the command buffer completes
// (the layout's textures, which the encoder retains).
unsafe {
raw.cmd_end_render_pass(held);
render_target::moved_barriers(raw, held, ended, false, family);
Barrier::everything().record(raw, held);
}
core.held_shadow_copies(copies);
@@ -593,15 +647,17 @@ fn record_kept(
// encoder records it; the steps' objects are live until it completes (retained at their
// draws); the pass and framebuffer are live until it completes (the encoder holds them to its
// end, which retains them), the pass compatible with every kept draw's pipeline (made for
// the instance's shape, `render_target::final_pass`) and the framebuffer made for the pass's
// first instance, of the same attachments; every image rests in `GENERAL`; every kept
// draw's objects are live until the command buffer completes (retained at the draw), and
// `bound` is the record of what the draws recorded into it bound, which the copies and
// barriers recorded since (transfer commands) leave bound.
// the instance's shape, `render_target::final_pass`) and its framebuffer of the same
// attachments; every image rests in `GENERAL` but its colors in the feedback loop layout,
// moved there right before its begin; every kept draw's objects are live until the command
// buffer completes (retained at the draw), and `bound` is the record of what the draws
// recorded into it bound, which the copies and barriers recorded since (transfer commands)
// leave bound.
unsafe {
for step in &instance.before {
step.record_in(raw, held);
}
render_target::moved_barriers(raw, held, &kept.moved, true, family);
raw.cmd_begin_render_pass(held, &info, vk::SubpassContents::INLINE);
let begun = crate::work_counts::PassBegun::InlineSplit;
shared.counts.render_pass_begun(begun);
@@ -127,14 +127,16 @@
//! attachment, on a device that also enabled
//! `fragmentStoresAndAtomics`) and the variant is made; no slot takes the snapshot slot as
//! storage. The draw's instance holds those colors in the feedback loop layout from its render
//! pass instance's begin, which records in a secondary: where the current instance
//! cannot (`RenderCommandEncoder::snapshot_apart`: it records inline, `render/inline_first.rs`
//! and `render/inline_splits.rs`, its render pass instance begun already; it ran an execution
//! of render commands; a draw of it bound such a color's image as a storage image; or it
//! leaves the color out), the draw records into a new instance, with no copy
//! (`WorkCounts::snapshot_inline_splits` counts the first cause). After it, an execution of
//! render commands, and a draw that binds such a color's image as a storage image, record into
//! another instance: the feedback loop layout serves neither.
//! pass instance's begin, which records in a secondary, or inline after a split where the pass
//! allows it (`render/inline_splits.rs`, its render pass and framebuffer made of those colors
//! in that layout): where the current instance cannot (`RenderCommandEncoder::snapshot_apart`:
//! it records inline, `render/inline_first.rs` and `render/inline_splits.rs`, its render pass
//! instance begun already, but for one recorded inline after a split that holds every such
//! color in that layout already; it ran an execution of render commands; a draw of it bound
//! such a color's image as a storage image; or it leaves the color out), the draw records into
//! a new instance, with no copy (`WorkCounts::snapshot_inline_splits` counts the first cause).
//! After it, an execution of render commands, and a draw that binds such a color's image as a
//! storage image, record into another instance: the feedback loop layout serves neither.
//! - **Leading snapshots.** A texture whose image the device makes without feedback loop usage (a
//! linear image on NVIDIA's drivers, `texture::feedback_candidate`) has no layout in which a
//! barrier inside a subpass orders its color's writes before a sampled read of it. A reader of
@@ -1223,16 +1225,20 @@ impl RenderLowering {
/// Whether a draw that reads through `wanted` records into a new instance, as the current
/// one cannot hold its colors in the feedback loop layout: it records inline, its render
/// pass instance begun already (`render/inline_first.rs`, `render/inline_splits.rs`); it
/// runs an execution of render commands, whose runs begin render pass instances of their
/// own (`render/executions.rs`); a draw recorded into it needs such a color in `GENERAL`
/// (`general_colors`: it binds its image as a storage image, or reads levels past the
/// attached ones through a view that holds them, or its snapshots lead the instance, whose
/// draws read every color in `GENERAL`); or it leaves such a color out of its subpass (the
/// storage form).
/// pass instance begun already (`render/inline_first.rs`, `render/inline_splits.rs`), but
/// for one recorded inline after a split whose render pass holds every such color in that
/// layout already; it runs an execution of render commands, whose runs begin render pass
/// instances of their own (`render/executions.rs`); a draw recorded into it needs such a
/// color in `GENERAL` (`general_colors`: it binds its image as a storage image, or reads
/// levels past the attached ones through a view that holds them, or its snapshots lead the
/// instance, whose draws read every color in `GENERAL`); or it leaves such a color out of its
/// subpass (the storage form).
pub(super) fn snapshot_apart(&self, wanted: &Wanted) -> bool {
let current = &self.current;
current.inline
let held = current.kept.is_some()
&& current.feedback != Feedback::NONE
&& wanted.feedback.0 & !current.feedback.0 == 0;
(current.inline && !held)
|| current.leading.is_some()
|| current
.pieces
@@ -0,0 +1,231 @@
//! A pass over a bound linear attachment (`linear_attachment.rs`) whose first instance records
//! inline, in place (`render/inline_first.rs`), and whose later instance renders the color in
//! another format through a stand-in: with the device's rule forced
//! (`DeviceShared::linear_rule_forced`), one pass of one color, an `R32Float` render target over a
//! `Shared` buffer's bytes that is its own linear image, loaded and stored, of three draws: an
//! `R32Float` state over most of it, recorded inline into the target itself; an `RGBA8Unorm` state
//! blended over its left half, which the image takes no view of (no `PixelFormatView`), through a
//! stand-in of that format (`attachment_stand_in::stand_in_as`) in an instance of its own, in a
//! secondary; and the `R32Float` state over its right half, after it. The pass's end renders the
//! bound color apart from that instance on (`linear_attachment::settle`): the image its texture
//! keeps takes the target's texels right after the inline instance, and the words the later
//! instances changed are merged back (`linear_merge.rs`). The bytes equal those the same draws
//! leave in a private texture of the same first texels, made with `PixelFormatView`, whose second
//! draw renders through a view. On a device whose draws read the colors as input attachments
//! (`framebuffer_fetch::through_inputs`: lavapipe's rasterization-order access), every color is
//! taken as the pass ends, and the bound color put apart there is refused
//! (`NotImplemented(Render)`), as it was before the first instance recorded inline: the first
//! instance still records inline.
//!
//! Waits for the device's in-place check to end before it makes anything
//! (`merge_scratch::settled`), and reads the counts of its own pass only then
//! (`merge_scratch::counts_alone`). Every draw waits for its pipeline
//! (`blit_holds::exact_waits_device`), so the first one records inline wherever the layout allows.
//!
//! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The functions are the owned fixture
//! `validation/fixtures/public/engine/tob_renders.ll` (`llvm-as`).
use super::blit_holds::{exact_waits_device, Scratch, WAIT};
use super::encoder_holds::{bytes_of, library};
use super::merge_scratch::{blit, counts_alone, first_bytes, read, settled, staged, H, TEXEL};
use crate::{
BlitOption, CommandQueue, Device, Error, LoadAction, Origin, PipelineOptions,
RenderPassDescriptor, RenderPipelineState, ResourceOptions, RuntimeGap, Size, StoreAction,
Texture, TextureDescriptor, WorkCounts,
};
use metal2vulkan::metal::{BlendFactor, PixelFormat, PrimitiveType, TextureUsage};
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
use std::sync::atomic::Ordering;
/// The target's width: rows of 256 bytes.
const WIDTH: u64 = 64;
/// The pass's draws: by the `R32Float` state (`false`) or the blended `RGBA8Unorm` one (`true`),
/// over the rectangle (normalized device coordinates, `[x0, y0, x1, y1]`), of the color.
const DRAWS: [(bool, [f32; 4], [f32; 4]); 3] = [
(false, [-1.0, -1.0, 0.5, 0.5], [0.25, 0.0, 0.0, 1.0]),
(true, [-1.0, -1.0, 0.0, 1.0], [0.2, 0.4, 0.6, 0.8]),
(false, [0.0, -1.0, 1.0, 0.0], [0.75, 0.0, 0.0, 1.0]),
];
/// The rectangle state (`tob_rect`, corners from vertex buffer 0) of the color in fragment buffer
/// 0 (`tob_solid`) into a color of `format`, blending it over the color by its alpha where
/// `blends`.
fn state(device: &Device, format: PixelFormat, blends: bool) -> RenderPipelineState {
let library = library(device, "engine/tob_renders.ll");
let function = |name: &str| {
let function = library.new_function_with_name(name).unwrap();
StageSource::Function(function.function_descriptor())
};
let mut descriptor = RenderPipelineDescriptor::new(function("tob_rect"));
descriptor.fragment = Some(function("tob_solid"));
let mut color = ColorAttachmentDescriptor::new(format);
if blends {
color.blending_enabled = true;
color.source_rgb_blend_factor = BlendFactor::SourceAlpha;
color.destination_rgb_blend_factor = BlendFactor::OneMinusSourceAlpha;
color.source_alpha_blend_factor = BlendFactor::One;
color.destination_alpha_blend_factor = BlendFactor::Zero;
}
descriptor.color_attachments[0] = Some(color);
device
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
.unwrap()
}
/// One pass over `texture`, loading and storing it, of [`DRAWS`] by `states` (`R32Float`,
/// `RGBA8Unorm`), committed and completed. The device's work counts as it completed; or the
/// refusal of its end, uncommitted.
fn pass(
queue: &CommandQueue,
texture: &Texture,
states: (&RenderPipelineState, &RenderPipelineState),
) -> Result<WorkCounts, Error> {
let mut descriptor = RenderPassDescriptor::new();
let color = &mut descriptor.color_attachments[0];
color.texture = Some(texture.clone());
color.load_action = LoadAction::Load;
color.store_action = StoreAction::Store;
let command_buffer = queue.command_buffer().unwrap();
let mut encoder = command_buffer.render_command_encoder(&descriptor).unwrap();
for (bytes, corners, rgba) in DRAWS {
let state = match bytes {
false => states.0,
true => states.1,
};
encoder.set_render_pipeline_state(state).unwrap();
(encoder.set_vertex_bytes(&bytes_of(&corners, f32::to_le_bytes), 0)).unwrap();
(encoder.set_fragment_bytes(&bytes_of(&rgba, f32::to_le_bytes), 0)).unwrap();
(encoder.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)).unwrap();
}
encoder.end_encoding()?;
command_buffer.commit().unwrap();
command_buffer.wait_until_completed_for(WAIT).unwrap();
assert_eq!(command_buffer.error(), None);
Ok(queue.device().work_counts())
}
/// The texels of `texture`, [`WIDTH`] x [`H`], packed: read through a blit.
fn texels_of(queue: &CommandQueue, texture: &Texture) -> Vec<u8> {
let packed = WIDTH * TEXEL;
let out = (queue.device())
.new_buffer(packed * H, ResourceOptions::shared())
.unwrap();
blit(queue, |b| {
(b.copy_from_texture_to_buffer(
texture,
0,
0,
Origin::new(0, 0, 0),
Size::new(WIDTH, H, 1),
&out,
0,
packed,
packed * H,
BlitOption::None,
))
.unwrap()
});
read(&out, packed * H)
}
/// The module docs' pass, over a private texture and then over the target with the rule forced:
/// the target's first instance recorded inline, and the pass rendered apart from its later
/// instances on, the target's bytes the private texture's texels; or, where the draws read the
/// colors as input attachments, refused as it ends.
#[test]
fn a_bound_color_recorded_inline_goes_apart_after_its_first_instance() {
let cache = Scratch::new("bound-inline");
let device = settled(exact_waits_device(&cache.0));
let queue = device.new_command_queue().unwrap();
let states = (
state(&device, PixelFormat::R32Float, false),
state(&device, PixelFormat::RGBA8Unorm, true),
);
let states = (&states.0, &states.1);
let packed = WIDTH * TEXEL;
let first = first_bytes(WIDTH, packed);
// The private texture of the target's first texels, which takes views of other formats.
let mut d = TextureDescriptor::texture_2d(PixelFormat::R32Float, WIDTH, H, false);
d.usage = TextureUsage::RENDER_TARGET | TextureUsage::PIXEL_FORMAT_VIEW;
d.resource_options = ResourceOptions::private();
let reference = device.new_texture(&d).unwrap();
let source = staged(&device, &first);
blit(&queue, |b| {
(b.copy_from_buffer_to_texture(
&source,
0,
packed,
packed * H,
Size::new(WIDTH, H, 1),
&reference,
0,
0,
Origin::new(0, 0, 0),
BlitOption::None,
))
.unwrap()
});
pass(&queue, &reference, states).unwrap();
let expected = texels_of(&queue, &reference);
// The target: its own linear image over a `Shared` buffer of the same first texels, which
// takes no view of another format.
let buffer = staged(&device, &first);
let mut d = TextureDescriptor::texture_2d(PixelFormat::R32Float, WIDTH, H, false);
d.usage = TextureUsage::RENDER_TARGET;
d.resource_options = buffer.resource_options();
let texture = buffer.new_texture(&d, 0, packed).unwrap();
if !texture.linear_image().unwrap() {
println!(
"BOUND-INLINE on {}: the target is no linear image",
device.name()
);
return;
}
let inputs = crate::framebuffer_fetch::through_inputs(device.compile_device().profile());
let forced = &device.shared().linear_rule_forced;
let before = counts_alone(&device);
forced.store(true, Ordering::Relaxed);
let ended = pass(&queue, &texture, states);
forced.store(false, Ordering::Relaxed);
let after = device.work_counts();
let delta = |of: fn(&WorkCounts) -> u64| of(&after) - of(&before);
let inline = delta(|c| c.inline_passes);
let refused = delta(|c| c.passes_not_inline_attachments);
assert_eq!(
(inline, refused),
(1, 0),
"the pass's first instance recorded inline"
);
if inputs {
println!(
"BOUND-INLINE on {}: colors read as input attachments; passes inline {inline}, the \
end {ended:?}",
device.name()
);
assert_eq!(
ended.err(),
Some(Error::NotImplemented(RuntimeGap::Render)),
"the bound color put apart as the pass ends, every color taken"
);
return;
}
ended.unwrap();
let through = delta(|c| c.linear_passes_through_copies);
let got = read(&buffer, packed * H);
let differ = (0..got.len() / 4)
.filter(|&t| got[t * 4..t * 4 + 4] != expected[t * 4..t * 4 + 4])
.count();
println!(
"BOUND-INLINE on {}: passes inline {inline}, refused for their attachments {refused}, \
through copies {through}; {differ} texels differ",
device.name()
);
assert_eq!(
through, 1,
"the pass rendered the bound color apart from its later instances"
);
assert_eq!(differ, 0, "the texels differ from the private texture's");
drop((texture, buffer));
}
@@ -47,6 +47,8 @@ mod blit_plan;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod blocks_ahead;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod bound_inline;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod buffer_carved_reads;
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod buffer_tail_device;
@@ -2235,9 +2235,9 @@ pub(crate) enum NotInline {
/// A color attachment that is a texture over a buffer the pass does not render through an
/// image over the buffer's bytes.
BufferTextures,
/// Another color attachment kind: a stand-in, planes, a clear made apart, an extended-range
/// format, or a bound linear image; or another depth/stencil attachment kind: separate depth
/// and stencil textures' scratch, a stand-in, a texture over a buffer, or a NaN depth clear
/// Another color attachment kind: a stand-in, planes, a clear made apart, or an
/// extended-range format; or another depth/stencil attachment kind: separate depth and
/// stencil textures' scratch, a stand-in, a texture over a buffer, or a NaN depth clear
/// written apart.
Attachments,
/// The pass's layout allowed it, and its first draw that records reads or writes a color
@@ -8332,10 +8332,11 @@ pub struct WorkCounts {
/// Of them, those with a color attachment that is a texture over a buffer they do not render
/// through an image over the buffer's bytes.
pub passes_not_inline_buffer_textures: u64,
/// Of them, those with a color attachment of another kind: a stand-in, planes, a clear made
/// apart, an extended-range format, or a bound linear image (`linear_attachment.rs`); or a
/// depth/stencil attachment of another kind: separate depth and stencil textures' scratch, a
/// stand-in, a texture over a buffer, or a NaN depth clear written apart.
/// Of them, those with a color attachment of another kind: a stand-in (a bound linear image
/// rendered apart from the pass's open among them, `linear_attachment.rs`), planes, a clear
/// made apart, or an extended-range format; or a depth/stencil attachment of another kind:
/// separate depth and stencil textures' scratch, a stand-in, a texture over a buffer, or a NaN
/// depth clear written apart.
pub passes_not_inline_attachments: u64,
/// Of them, those whose layout allowed it and whose first draw that records reads or writes a
/// color attachment as storage: a fetch in the pixel interlock, which leaves it out of the
@@ -67,14 +67,14 @@
//! a panel, a render-target barrier, then a draw sampling the surface's own texture at its
//! pixel: the buffer holds the private texture's pass. A cleared one renders in place (a command
//! of it may read the bytes); one apart is split at the barrier, merged and copied in again.
//! Where the device renders the texture's own image as any other, the pass alone records its
//! instances inline (`render/inline_first.rs`, `render/inline_splits.rs`), counted.
//! The pass alone records its first instance inline, by the rule or not, and the instance after
//! the split too but where the reader's snapshots lead it (`render/inline_first.rs`,
//! `render/inline_splits.rs`, `render/snapshot.rs`), counted.
//! - [`a_detach_while_a_pass_over_host_pages_is_open_fails_its_command_buffer`] and
//! [`a_detach_while_a_pass_in_a_no_copy_heap_is_open_fails_its_command_buffer`]: the bytes
//! detached after the pass's first draw: the command buffer fails `DetachedBacking`, the pages
//! keep their bytes, and the validation layer reports nothing, where the pass records inline
//! too (`render/inline_first.rs`; a heap's texture of its own image does, unless the rule binds
//! it).
//! too (`render/inline_first.rs`; a heap's texture of its own image does).
//! - [`a_rebind_while_a_pass_over_host_pages_is_open_is_refused`]: refused `EncodedUses`, before
//! any draw.
//!
@@ -1172,15 +1172,17 @@ fn sampling_pass(
/// the draw after the barrier read the panel the pass drew. Where the texture is aliased by the
/// rule the pass renders in place, loaded or cleared, announcing nothing; beside a stencil
/// attachment apart, split at the barrier, announcing `linear-attachment-copies`: the stand-in
/// merged back (or, cleared, copied back) and copied in again before the reading draw. Where the device renders the texture's own image as any
/// other, the pass alone records both its instances inline, the reading draw's after the split
/// (`WorkCounts::inline_split_instances`).
/// merged back (or, cleared, copied back) and copied in again before the reading draw. The pass
/// alone, by the rule or not, records its first instance inline, and the reading draw's after the
/// split too (`WorkCounts::inline_split_instances`) but where the draw's snapshots lead it
/// (`WorkCounts::reading_draws_snapshotted_leading`: their instance records in a secondary,
/// `render/snapshot.rs`).
fn sampling(start: usize, load: LoadAction, stencil: bool) {
on_device(|device, messages| {
messages.take_notices();
let (contents, buffer, texture) = surface_of(device, start, WIDE[0], WIDE[1]);
let rule = by_the_rule(device) && aliased(&texture);
let inline = aliased(&texture) && !by_the_rule(device) && !stencil;
let inline = aliased(&texture) && !stencil;
println!(
"LINEAR-ATTACHMENT sampled after a barrier on {}: {load:?}, stencil {stencil}, by the \
rule {rule}, inline {inline}",
@@ -1206,11 +1208,16 @@ fn sampling(start: usize, load: LoadAction, stencil: bool) {
let before = device.work_counts();
sampling_pass(&queue, &states, &texture, load, stencil);
let inlined = inlined(device, &before);
println!("LINEAR-ATTACHMENT sampled after a barrier: inline counts {inlined:?}");
let leading = device.work_counts().reading_draws_snapshotted_leading
- before.reading_draws_snapshotted_leading;
println!(
"LINEAR-ATTACHMENT sampled after a barrier: inline counts {inlined:?}, readers \
through leading snapshots {leading}"
);
assert_eq!(
inlined,
match inline {
true => [1, 1, 1],
true => [1, 1, u64::from(leading == 0)],
false => [0, 0, 0],
},
"passes inline, of them split, and instances after a split inline"
@@ -1350,8 +1357,8 @@ fn detached_in_an_open_pass(
/// [`detached_in_an_open_pass`] over a [`WIDE`] render target over a no-copy buffer's host pages
/// (counting from 59): the pages keep their bytes, and the validation layer reports nothing. The
/// pass holds the pages from its open (`render.rs`), so the images over them the detach replaces
/// stay until the command buffer goes (`detach.rs`). Where the texture is its own image outside
/// `VK_NV_linear_color_attachment`'s rule ([`by_the_rule`]), the pass records inline.
/// stay until the command buffer goes (`detach.rs`). Where the texture is its own image, by
/// `VK_NV_linear_color_attachment`'s rule ([`by_the_rule`]) or not, the pass records inline.
#[test]
fn a_detach_while_a_pass_over_host_pages_is_open_fails_its_command_buffer() {
on_device(|device, messages| {
@@ -1361,7 +1368,7 @@ fn a_detach_while_a_pass_over_host_pages_is_open_fails_its_command_buffer() {
};
let n = (WIDE[0] * WIDE[1] * TEXEL) as usize;
let inline = detached_in_an_open_pass(device, &texture, WIDE, || buffer.detach_backing());
let own = aliased(&texture) && !by_the_rule(device);
let own = aliased(&texture);
println!(
"LINEAR-ATTACHMENT detached in an open pass on {}: aliased {}, by the rule {}, inline \
{inline}",
@@ -1382,12 +1389,11 @@ fn a_detach_while_a_pass_over_host_pages_is_open_fails_its_command_buffer() {
}
/// [`detached_in_an_open_pass`] over a render target in a no-copy heap, detached while the pass is
/// open: where the texture is an image of its own (no `shadowed-texture` announced) that the device
/// renders without `VK_NV_linear_color_attachment`'s rule ([`by_the_rule`]; a pass of an image the
/// rule binds records into a secondary), the pass's first instance records inline into a command
/// buffer it holds, naming the image's view from its first draw; the detach leaves that image and
/// view until the command buffer goes, so the command buffer stays valid to its end, and the
/// validation layer reports nothing.
/// open: where the texture is an image of its own (no `shadowed-texture` announced), whether the
/// device renders it by `VK_NV_linear_color_attachment`'s rule ([`by_the_rule`]) or not, the
/// pass's first instance records inline into a command buffer it holds, naming the image's view
/// from its first draw; the detach leaves that image and view until the command buffer goes, so
/// the command buffer stays valid to its end, and the validation layer reports nothing.
#[test]
fn a_detach_while_a_pass_in_a_no_copy_heap_is_open_fails_its_command_buffer() {
on_device(|device, messages| {
@@ -1411,7 +1417,7 @@ fn a_detach_while_a_pass_in_a_no_copy_heap_is_open_fails_its_command_buffer() {
{shadowed}, by the rule {rule}, inline {inline}",
device.name()
);
if !shadowed && !rule {
if !shadowed {
assert_eq!(inline, 1, "passes inline");
}
drop((texture, heap));
+1 -1
View File
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 523;
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
/// keeps no history.
pub const RUNTIME_VERSION: u32 = 2331;
pub const RUNTIME_VERSION: u32 = 2332;
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles