RUNTIME 2302: render encoders record into the VkCommandBuffer of the encoders before them
A render encoder took a VkCommandBuffer of its own at every open, so a compute, render and blit step began 2.71 and submitted 4 VkCommandBuffers per step (dispatch_chain renders, lavapipe). A render encoder with a log of its calls now takes part in the encoder fold: - One whose pass records at its end (draws in a secondary) joins the group before it; one whose first instance records inline joins none and may lead a group. - No barrier records inside a pass: a joined render encoder records one barrier from everything of the group's earlier encoders (FoldOrder::everything) at its open, counted in command_barriers. - Color groups, rasterization-rate maps and a depth attachment out of GENERAL take no group; segments, fence updates and Overwrites end the group after the encoder. Logless devices keep one VkCommandBuffer per render encoder. - A folded member's layout moves go before its group's first part (GroupPlaces). - A check splits a group with a render member at its pass's submission (as RUNTIME 2297 does for blits). - A group's order is built as its second encoder joins, not as its first ends. A/B (lavapipe, dispatch_chain, per step, base vs tip): renders 2.71 -> 1.35 VkCommandBuffers begun, 4 -> 2 submitted, GPU 119.5 -> 97.7 us; renders-apart 3.71 -> 1.00, 4 -> about 0, 143.6 -> 94.6 us; passes unchanged in buffers, the encoder's open about 250-480 ns more on the host (the group an inline pass begins), the whole pass within the host's noise. Tests: tests::render_fold (device), tests::held_depth, shadow_runs' rebind expectation (a rebind encodes a group whole). Docs: encoder_fold.rs, API.md, FAST-PATHS known gap and ANV row. Verified (msi, lavapipe): the full runtime suite 2683/2684 at c502efba29, the one failure the race test fixed in ca5042567b; clippy plain and --cfg m2v_cpu_icd, rustdoc, fast_paths 0. Negative control (the explicit order removed, renderfold-negctl): the hazard tests fail on their barrier counts; lavapipe shows no wrong texel because it completes each command as it runs, so the texel proof is a GPU that overlaps work.
This commit is contained in:
1 parent
a91629c1a6
commit
d8666d430f
22 files changed
+1496
-150
No files matched your search
@@ -22,6 +22,18 @@
|
||||
//! - **`copies`**: `N` blit encoders of that copy alone, no dispatch: what a program of blit
|
||||
//! encoders alone costs (each line's "dispatch" is a copy). The copies' buffer must hold the
|
||||
//! words' zeros;
|
||||
//! - **`renders`**: `blits` with a render encoder between each compute encoder and its blit
|
||||
//! encoder, which draws two triangles over the whole of a `Private` `RGBA8Unorm` target of
|
||||
//! `TARGET_SIDE` texels a side, loaded and stored (a pass whose first instance records inline,
|
||||
//! `render/inline_first.rs`), with `colored_vertex` and `colored_fragment` of the repository's
|
||||
//! owned fixture (`validation/fixtures/public/examples/runtime_examples.ll`): `3N` encoders, as
|
||||
//! an image workload that also draws between its dispatches and copies. Every texel of the
|
||||
//! target must hold the triangles' color;
|
||||
//! - **`renders-apart`**: `renders` with the target not loaded (`DontCare`), a pass recorded in a
|
||||
//! secondary command buffer that the encoder's end executes;
|
||||
//! - **`passes`**: `N` render encoders of that loaded pass alone, no dispatch and no copy: what a
|
||||
//! program of render encoders alone costs (each line's "dispatch" is a pass). The words must
|
||||
//! hold their zeros;
|
||||
//! - **`serial`**: one serial compute encoder of the `N` dispatches;
|
||||
//! - **`concurrent`**: one concurrent encoder of them, with no memory barrier: nothing orders the
|
||||
//! dispatches, so this is the kernels' own time with no barrier between them (their words race,
|
||||
@@ -102,7 +114,11 @@
|
||||
//!
|
||||
//! `make` is `command_buffer`, `open` the encoders' opening, `pipeline` and `bind` the state's
|
||||
//! calls, `end` `end_encoding` (with `blits`, a dispatch's blit encoder's opening, copy and end
|
||||
//! count in its `open`, `dispatch` and `end`; with `copies`, each blit encoder's alone); `encode` is their sum and `commit` the `commit_and_submit` call;
|
||||
//! count in its `open`, `dispatch` and `end`; with `copies`, each blit encoder's alone; with
|
||||
//! `renders` and `renders-apart`, a dispatch's render encoder's opening, pipeline state, vertex
|
||||
//! buffers, draw and end count in its `open`, `pipeline`, `bind`, `dispatch` and `end` too; with
|
||||
//! `passes`, each render encoder's alone); `encode` is their sum and `commit` the
|
||||
//! `commit_and_submit` call;
|
||||
//! `thread_cpu` the calling thread's CPU time over both (`CLOCK_THREAD_CPUTIME_ID`), and
|
||||
//! `least_encode_commit` the least run's. `HOST-COMMIT` splits the commit call by the device's
|
||||
//! commit phases (`WorkCounts::commit_lowering_nanos` and kin). `HOST-THREADS` is each group of the
|
||||
@@ -129,15 +145,17 @@
|
||||
//! scheduler's among them.
|
||||
//!
|
||||
//! The kernels are text here: LLVM IR assembled by `llvm-as`, SPIR-V by `spirv-as`, both from
|
||||
//! `PATH`.
|
||||
//! `PATH`; the render shapes' functions are the owned fixture's LLVM IR, assembled by `llvm-as`.
|
||||
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::SamplerDescriptor;
|
||||
use metal2vulkan::metal::{BarrierScope, DispatchType, PixelFormat, TextureUsage};
|
||||
use metal2vulkan::metal::{BarrierScope, DispatchType, PixelFormat, PrimitiveType, TextureUsage};
|
||||
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
|
||||
use metal2vulkan_runtime::{
|
||||
Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputeCommandEncoder,
|
||||
BlitOption, Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputeCommandEncoder,
|
||||
ComputePipelineState, Device, DeviceOptions, Heap, HeapDescriptor, HeapType, HostMemory,
|
||||
PipelineOptions, ResourceOptions, SamplerState, Size, Texture, TextureDescriptor, WorkCounts,
|
||||
LoadAction, Origin, PipelineOptions, RenderPassDescriptor, RenderPipelineState,
|
||||
ResourceOptions, SamplerState, Size, StoreAction, Texture, TextureDescriptor, WorkCounts,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Write;
|
||||
@@ -472,6 +490,104 @@ fn state(device: &Device, binds: Binds) -> Result<ComputePipelineState> {
|
||||
Ok(device.new_compute_pipeline_state_with_function(&function, &PipelineOptions::default())?)
|
||||
}
|
||||
|
||||
/// The render shapes' target's side, in texels.
|
||||
const TARGET_SIDE: u64 = 64;
|
||||
|
||||
/// The color the render shapes' triangles draw, and the bytes an `RGBA8Unorm` texel stores of it.
|
||||
const DRAWN: [f32; 4] = [1.0, 0.2, 0.0, 1.0];
|
||||
const DRAWN_TEXEL: [u8; 4] = [255, 51, 0, 255];
|
||||
|
||||
/// The render shapes' names, each with whether its passes load the target (`renders`, `passes`),
|
||||
/// whose first instance records inline, or not (`renders-apart`), recorded in a secondary.
|
||||
const RENDER_SHAPES: [(&str, bool); 3] = [
|
||||
("renders", true),
|
||||
("renders-apart", false),
|
||||
("passes", true),
|
||||
];
|
||||
|
||||
/// Whether the shape `name` loads its passes' target, where it is a render shape.
|
||||
fn loads(name: &str) -> Option<bool> {
|
||||
(RENDER_SHAPES.iter())
|
||||
.find(|(shape, _)| *shape == name)
|
||||
.map(|(_, loads)| *loads)
|
||||
}
|
||||
|
||||
/// The render shapes' pipeline state, target, vertices and passes.
|
||||
struct Render {
|
||||
state: RenderPipelineState,
|
||||
target: Texture,
|
||||
positions: Buffer,
|
||||
colors: Buffer,
|
||||
/// The target loaded and stored.
|
||||
loaded: RenderPassDescriptor,
|
||||
/// The target not loaded (`DontCare`), and stored.
|
||||
apart: RenderPassDescriptor,
|
||||
/// What the target's texels are copied into to be checked.
|
||||
readback: Buffer,
|
||||
}
|
||||
|
||||
impl Render {
|
||||
/// The owned fixture's `colored_vertex` and `colored_fragment`, assembled by `llvm-as`, over
|
||||
/// a `Private` target, and two triangles over the whole of it.
|
||||
fn new(device: &Device) -> Result<Render> {
|
||||
let path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../metal2vulkan-validation/fixtures/public/examples/runtime_examples.ll"
|
||||
);
|
||||
let text =
|
||||
std::fs::read_to_string(path).map_err(|error| format!("read {path}: {error}"))?;
|
||||
let bitcode = tool("llvm-as", &["-o", "-", "-"], &text)?;
|
||||
let library = device
|
||||
.new_library_with_compile_library(metal2vulkan::library::Library::from_air(&bitcode)?);
|
||||
let vertex = library.new_function_with_name("colored_vertex")?;
|
||||
let fragment = library.new_function_with_name("colored_fragment")?;
|
||||
let mut descriptor =
|
||||
RenderPipelineDescriptor::new(StageSource::Function(vertex.function_descriptor()));
|
||||
descriptor.fragment = Some(StageSource::Function(fragment.function_descriptor()));
|
||||
descriptor.color_attachments[0] =
|
||||
Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
let state = device.new_render_pipeline_state(&descriptor, &PipelineOptions::default())?;
|
||||
let mut texture =
|
||||
TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, TARGET_SIDE, TARGET_SIDE, false);
|
||||
texture.usage = TextureUsage::RENDER_TARGET;
|
||||
texture.resource_options = ResourceOptions::private();
|
||||
let target = device.new_texture(&texture)?;
|
||||
let corners: [[f32; 2]; 6] = [
|
||||
[-1.0, 1.0],
|
||||
[1.0, 1.0],
|
||||
[-1.0, -1.0],
|
||||
[1.0, 1.0],
|
||||
[1.0, -1.0],
|
||||
[-1.0, -1.0],
|
||||
];
|
||||
let positions: Vec<u8> = (corners.iter().flatten())
|
||||
.flat_map(|value| value.to_le_bytes())
|
||||
.collect();
|
||||
let colors: Vec<u8> = (0..corners.len())
|
||||
.flat_map(|_| DRAWN)
|
||||
.flat_map(|value| value.to_le_bytes())
|
||||
.collect();
|
||||
let pass = |load_action: LoadAction| {
|
||||
let mut pass = RenderPassDescriptor::new();
|
||||
let color = &mut pass.color_attachments[0];
|
||||
color.texture = Some(target.clone());
|
||||
color.load_action = load_action;
|
||||
color.store_action = StoreAction::Store;
|
||||
pass
|
||||
};
|
||||
Ok(Render {
|
||||
state,
|
||||
positions: device.new_buffer_with_bytes(&positions, ResourceOptions::shared())?,
|
||||
colors: device.new_buffer_with_bytes(&colors, ResourceOptions::shared())?,
|
||||
loaded: pass(LoadAction::Load),
|
||||
apart: pass(LoadAction::DontCare),
|
||||
readback: device
|
||||
.new_buffer(TARGET_SIDE * TARGET_SIDE * 4, ResourceOptions::shared())?,
|
||||
target,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The counts of `counts` by name, read from their `Debug` form.
|
||||
fn counts(counts: &WorkCounts) -> BTreeMap<String, u64> {
|
||||
let text = format!("{counts:?}");
|
||||
@@ -774,6 +890,8 @@ struct Ours<'a> {
|
||||
readback: Buffer,
|
||||
/// What the `blits` shape's copies write.
|
||||
copies: Buffer,
|
||||
/// The render shapes' pipeline state, target and passes, where one runs.
|
||||
render: Option<Render>,
|
||||
/// The heap each command buffer of the host's time makes its buffers in (`--heap-churn`).
|
||||
churn: Option<Heap>,
|
||||
}
|
||||
@@ -788,6 +906,7 @@ impl Ours<'_> {
|
||||
let threads = Size::new(u64::from(shape.threads), 1, 1);
|
||||
let encoders = match name {
|
||||
"encoders" | "blits" | "copies" => shape.dispatches,
|
||||
_ if loads(name).is_some() => shape.dispatches,
|
||||
_ => 1,
|
||||
};
|
||||
for _ in 0..encoders {
|
||||
@@ -795,6 +914,10 @@ impl Ours<'_> {
|
||||
self.copy(&command_buffer)?;
|
||||
continue;
|
||||
}
|
||||
if name == "passes" {
|
||||
self.draw(&command_buffer, true, None)?;
|
||||
continue;
|
||||
}
|
||||
let mut encoder = match name {
|
||||
"concurrent" | "barriers" => command_buffer
|
||||
.compute_command_encoder_with_dispatch_type(DispatchType::Concurrent)?,
|
||||
@@ -809,7 +932,10 @@ impl Ours<'_> {
|
||||
encoder.dispatch_threadgroups(groups, threads)?;
|
||||
}
|
||||
encoder.end_encoding()?;
|
||||
if name == "blits" {
|
||||
if let Some(loaded) = loads(name) {
|
||||
self.draw(&command_buffer, loaded, None)?;
|
||||
}
|
||||
if name == "blits" || loads(name).is_some() {
|
||||
self.copy(&command_buffer)?;
|
||||
}
|
||||
}
|
||||
@@ -880,6 +1006,7 @@ impl Ours<'_> {
|
||||
let threads = Size::new(u64::from(shape.threads), 1, 1);
|
||||
let encoders = match name {
|
||||
"encoders" | "blits" | "copies" => shape.dispatches,
|
||||
_ if loads(name).is_some() => shape.dispatches,
|
||||
_ => 1,
|
||||
};
|
||||
let mut lap = Lap::default();
|
||||
@@ -895,6 +1022,10 @@ impl Ours<'_> {
|
||||
self.copy_lapped(&command_buffer, &mut lap, &mut at)?;
|
||||
continue;
|
||||
}
|
||||
if name == "passes" {
|
||||
self.draw(&command_buffer, true, Some((&mut lap, &mut at)))?;
|
||||
continue;
|
||||
}
|
||||
let mut encoder = match name {
|
||||
"concurrent" | "barriers" => command_buffer
|
||||
.compute_command_encoder_with_dispatch_type(DispatchType::Concurrent)?,
|
||||
@@ -914,7 +1045,10 @@ impl Ours<'_> {
|
||||
}
|
||||
encoder.end_encoding()?;
|
||||
lap.lap(&mut at, Call::End);
|
||||
if name == "blits" {
|
||||
if let Some(loaded) = loads(name) {
|
||||
self.draw(&command_buffer, loaded, Some((&mut lap, &mut at)))?;
|
||||
}
|
||||
if name == "blits" || loads(name).is_some() {
|
||||
self.copy_lapped(&command_buffer, &mut lap, &mut at)?;
|
||||
}
|
||||
}
|
||||
@@ -1065,6 +1199,75 @@ impl Ours<'_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A render encoder of `command_buffer` that draws the triangles over the render shapes'
|
||||
/// target, loaded or not, ended; with `laps`, its opening, pipeline state, vertex buffers,
|
||||
/// draw and end timed as an encoder's opening, pipeline, bind, dispatch and end.
|
||||
fn draw(
|
||||
&self,
|
||||
command_buffer: &CommandBuffer,
|
||||
loaded: bool,
|
||||
mut laps: Option<(&mut Lap, &mut Instant)>,
|
||||
) -> Result<()> {
|
||||
let render = self.render.as_ref().ok_or("no render state")?;
|
||||
let mut lap = |call: Call| {
|
||||
if let Some((sum, at)) = laps.as_mut() {
|
||||
sum.lap(at, call);
|
||||
}
|
||||
};
|
||||
let pass = match loaded {
|
||||
true => &render.loaded,
|
||||
false => &render.apart,
|
||||
};
|
||||
let mut encoder = command_buffer.render_command_encoder(pass)?;
|
||||
lap(Call::Open);
|
||||
encoder.set_render_pipeline_state(&render.state)?;
|
||||
lap(Call::Pipeline);
|
||||
encoder.set_vertex_buffer(Some(&render.positions), 0, 0)?;
|
||||
encoder.set_vertex_buffer(Some(&render.colors), 0, 1)?;
|
||||
lap(Call::Bind);
|
||||
encoder.draw_primitives(PrimitiveType::Triangle, 0, 6, 1, 0)?;
|
||||
lap(Call::Dispatch);
|
||||
encoder.end_encoding()?;
|
||||
lap(Call::End);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Copy the render shapes' target back and check each texel holds the triangles' color.
|
||||
fn check_target(&self, name: &str) -> Result<()> {
|
||||
let render = self.render.as_ref().ok_or("no render state")?;
|
||||
let row = TARGET_SIDE * 4;
|
||||
let queue = self.device.new_command_queue()?;
|
||||
let command_buffer = queue.command_buffer()?;
|
||||
let mut blit = command_buffer.blit_command_encoder()?;
|
||||
blit.copy_from_texture_to_buffer(
|
||||
&render.target,
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
Size::new(TARGET_SIDE, TARGET_SIDE, 1),
|
||||
&render.readback,
|
||||
0,
|
||||
row,
|
||||
row * TARGET_SIDE,
|
||||
BlitOption::None,
|
||||
)?;
|
||||
blit.end_encoding()?;
|
||||
command_buffer.commit()?;
|
||||
command_buffer
|
||||
.wait_until_completed_for(WAIT)
|
||||
.map_err(|_| "the target's read back did not complete")?;
|
||||
let contents = render.readback.contents().ok_or("no contents")?;
|
||||
for at in 0..(TARGET_SIDE * TARGET_SIDE) as usize {
|
||||
// SAFETY: the target's `readback` is `Shared`, as long as its texels, and no command
|
||||
// buffer writes it while the CPU reads it.
|
||||
let texel = unsafe { contents.as_ptr().cast::<[u8; 4]>().add(at).read_volatile() };
|
||||
if texel != DRAWN_TEXEL {
|
||||
return Err(format!("{name}: texel {at} is {texel:?}, not {DRAWN_TEXEL:?}").into());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fill(&self, value: u8) -> Result<()> {
|
||||
let queue = self.device.new_command_queue()?;
|
||||
let command_buffer = queue.command_buffer()?;
|
||||
@@ -1082,7 +1285,9 @@ impl Ours<'_> {
|
||||
}
|
||||
|
||||
/// Copy the words back and check each is `want`; with `blits`, the last copy's too; with
|
||||
/// `copies`, which dispatches nothing, the copies' alone, the words' zeros.
|
||||
/// `copies`, which dispatches nothing, the copies' alone, the words' zeros; with `renders` and
|
||||
/// `renders-apart`, the last copy's and the target's too; with `passes`, which dispatches
|
||||
/// nothing, the words' zeros and the target.
|
||||
fn check(&self, want: u32, name: &str) -> Result<()> {
|
||||
match name {
|
||||
"copies" => self.check_words(&self.copies, 0, name),
|
||||
@@ -1090,6 +1295,15 @@ impl Ours<'_> {
|
||||
self.check_words(&self.words, want, name)?;
|
||||
self.check_words(&self.copies, want, "blits' copies")
|
||||
}
|
||||
"passes" => {
|
||||
self.check_words(&self.words, 0, name)?;
|
||||
self.check_target(name)
|
||||
}
|
||||
"renders" | "renders-apart" => {
|
||||
self.check_words(&self.words, want, name)?;
|
||||
self.check_words(&self.copies, want, "renders' copies")?;
|
||||
self.check_target(name)
|
||||
}
|
||||
_ => self.check_words(&self.words, want, name),
|
||||
}
|
||||
}
|
||||
@@ -1664,11 +1878,18 @@ fn main() -> Result<()> {
|
||||
readback: device.new_buffer(bytes, ResourceOptions::shared())?,
|
||||
copies: device.new_buffer(bytes, ResourceOptions::private())?,
|
||||
churn,
|
||||
render: match RENDER_SHAPES.iter().any(|(name, _)| shape.runs(name)) {
|
||||
true => Some(Render::new(&device)?),
|
||||
false => None,
|
||||
},
|
||||
};
|
||||
for shape_name in [
|
||||
"encoders",
|
||||
"blits",
|
||||
"copies",
|
||||
"renders",
|
||||
"renders-apart",
|
||||
"passes",
|
||||
"serial",
|
||||
"concurrent",
|
||||
"barriers",
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
//! `CommandBufferError::Injected` of the first failure's code (a `commit_failed`'s before any
|
||||
//! check's). A check that panics fails its submission with code 1 (`Internal`). The commit of
|
||||
//! a command buffer with a check encodes again apart the encoders whose commands a shared
|
||||
//! `VkCommandBuffer` of a group of compute and blit encoders holds where they lie in more than
|
||||
//! `VkCommandBuffer` of a group of encoders holds where they lie in more than
|
||||
//! one submission (`encoder_fold.rs`'s **Failed**), so a failed submission's encoders run
|
||||
//! nothing alone; where it cannot encode them again so, a failed submission whose commands
|
||||
//! such a `VkCommandBuffer` holds fails every submission whose commands it holds.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! A command buffer's groups of compute and blit encoders recorded into one `VkCommandBuffer`
|
||||
//! A command buffer's groups of encoders recorded into one `VkCommandBuffer`
|
||||
//! (`encoder_fold.rs`): the group its tail holds, which encoder joins it, its logs, and the
|
||||
//! failures and left out work that split a group.
|
||||
|
||||
use super::{FailedEncoders, FailedSignals, Failure, State};
|
||||
use crate::encoder::Overwrite;
|
||||
use crate::encoder_fold::{Fold, FoldEnd, Joining, Stashed};
|
||||
use crate::encoder_fold::{Fold, FoldEnd, FoldOrder, Joining, Stashed};
|
||||
use crate::replay::Replay;
|
||||
use crate::resource::ResourceKey;
|
||||
use crate::tracker::Summary;
|
||||
@@ -14,10 +14,12 @@ use std::collections::BTreeSet;
|
||||
use std::ops::Range;
|
||||
|
||||
impl State {
|
||||
/// The group the compute or blit encoder opening now joins, asking `joining`, where its
|
||||
/// The group the encoder opening now joins, asking `joining`, where its
|
||||
/// command buffer's tail holds one it may join (`encoder_fold.rs`'s **Where**): taken, with
|
||||
/// the tail, which the encoder records into. `None` where it joins none, the group left in
|
||||
/// place: the encoder's open closes it once it opened ([`close_fold`](Self::close_fold)).
|
||||
/// the tail, which the encoder records into, and, where it is the group's second encoder, the
|
||||
/// group's order built from its first part's summary (`Fold::order`). `None` where it joins
|
||||
/// none, the group left in place: the encoder's open closes it once it opened
|
||||
/// ([`close_fold`](Self::close_fold)).
|
||||
pub(crate) fn join_fold(&mut self, joining: Joining, trail: bool) -> Option<Box<Fold>> {
|
||||
let fold = self.fold.as_ref()?;
|
||||
let joins = fold.admits(joining)
|
||||
@@ -30,11 +32,20 @@ impl State {
|
||||
if !joins {
|
||||
return None;
|
||||
}
|
||||
// Its second encoder orders after its first part, as that part's end left it.
|
||||
let order = match fold.members.len() {
|
||||
1 => Some(FoldOrder::after(&self.recorded.get(fold.leader)?.summary)),
|
||||
_ => None,
|
||||
};
|
||||
self.tail = None;
|
||||
self.fold.take()
|
||||
let mut fold = self.fold.take()?;
|
||||
if let Some(order) = order {
|
||||
fold.order = order;
|
||||
}
|
||||
Some(fold)
|
||||
}
|
||||
|
||||
/// A compute or blit encoder ended (`end`), its last `VkCommandBuffer` the tail: it goes on in the
|
||||
/// An encoder that asked a group ended (`end`), its last `VkCommandBuffer` the tail: it goes on in the
|
||||
/// group it joined where the tail is still that group's and it leaves nothing that needs a
|
||||
/// boundary, else the group closes and it begins one of its own where it may lead one (its
|
||||
/// one part leaves nothing that needs a boundary, the command buffer used no command
|
||||
@@ -47,11 +58,12 @@ impl State {
|
||||
fold,
|
||||
in_tail,
|
||||
encoder,
|
||||
plain,
|
||||
summary,
|
||||
log,
|
||||
} = end;
|
||||
let may_lead = !self.predicated && self.protection.options() == 0;
|
||||
let leads = joining.zip(summary).filter(|_| may_lead);
|
||||
let may_lead = plain && !self.predicated && self.protection.options() == 0;
|
||||
let leads = joining.filter(|_| may_lead);
|
||||
let mut log = log.map(|(log, executions)| Stashed {
|
||||
encoder,
|
||||
log,
|
||||
@@ -65,8 +77,8 @@ impl State {
|
||||
}
|
||||
fold.stashed.extend(log.take());
|
||||
let goes_on = self.tail == Some(fold.tail);
|
||||
if let (Some((joining, summary)), true) = (&leads, goes_on) {
|
||||
fold.went_on(*joining, summary);
|
||||
if let (Some(joining), Some(summary), true) = (leads, &summary, goes_on) {
|
||||
fold.went_on(joining, summary);
|
||||
fold.batches = self.batches.all().len();
|
||||
self.fold = Some(fold);
|
||||
return unkept;
|
||||
@@ -75,7 +87,7 @@ impl State {
|
||||
unkept = self.close_fold(counts);
|
||||
}
|
||||
match (leads, self.tail) {
|
||||
(Some((joining, summary)), Some(tail)) => {
|
||||
(Some(joining), Some(tail)) => {
|
||||
// The tail is its last `VkCommandBuffer`.
|
||||
if let Some(record) = self.ended.get_mut(encoder) {
|
||||
record.in_tail = true;
|
||||
@@ -86,7 +98,7 @@ impl State {
|
||||
tail,
|
||||
(leader, encoder),
|
||||
(batches, joining),
|
||||
(&summary, stashed),
|
||||
stashed,
|
||||
)));
|
||||
}
|
||||
_ => unkept.extend(log.map(|stashed| stashed.log)),
|
||||
|
||||
@@ -827,7 +827,7 @@ pub(super) struct State {
|
||||
/// into it as the batch ends ([`CommandBufferShared::close_tail`]), or it ends as it is where
|
||||
/// a later encoder joins its batch.
|
||||
pub(super) tail: Option<vk::CommandBuffer>,
|
||||
/// The group of compute and blit encoders whose last one's `VkCommandBuffer` is `tail`, which
|
||||
/// The group of encoders whose last one's `VkCommandBuffer` is `tail`, which
|
||||
/// the next such encoder may join, recording on into it (`encoder_fold.rs`); held by that
|
||||
/// encoder while it is open.
|
||||
pub(super) fold: Option<Box<crate::encoder_fold::Fold>>,
|
||||
@@ -3879,7 +3879,7 @@ impl CommandBuffer {
|
||||
// a refusal that left the count behind would be a correctness question.
|
||||
device.shared().program_gave_gpu_work();
|
||||
self.mark_gpu_written();
|
||||
// No compute encoder joins the group its tail holds from here (`encoder_fold.rs`): its
|
||||
// No encoder joins the group its tail holds from here (`encoder_fold.rs`): its
|
||||
// encoders take a failure and a rebind together, and the logs it keeps for that are kept.
|
||||
let unkept = self.state().close_fold(&device.shared().counts);
|
||||
for log in unkept {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
//! and it keeps the run's scratch after its own merge where a later pass went on over it, a
|
||||
//! linear attachment's run's box copied in again first (`State::replaying_keeps`, recorded by
|
||||
//! `EncoderCore::finish_replay`). Its run's other passes are not encoded again.
|
||||
//! - **Groups whole.** The compute and blit encoders of a group recorded into one
|
||||
//! - **Groups whole.** The encoders of a group recorded into one
|
||||
//! `VkCommandBuffer` (`encoder_fold.rs`) are encoded again together: a rebind that moves one
|
||||
//! encodes each again, into `VkCommandBuffer`s of its own, and puts them in their places
|
||||
//! together, or puts none where one of them kept no log, is refused or does not fit its place.
|
||||
@@ -490,7 +490,7 @@ impl CommandBufferShared {
|
||||
/// work than its encoding again's.
|
||||
const UNFIT: &str = "its place holds other parts or work than its encoding again's";
|
||||
|
||||
/// Why an encoder of a group of compute and blit encoders recorded into one `VkCommandBuffer`
|
||||
/// Why an encoder of a group of encoders recorded into one `VkCommandBuffer`
|
||||
/// keeps its first recording where the group cannot be encoded again whole (`encoder_fold.rs`).
|
||||
const TOGETHER: &str = "it records into one VkCommandBuffer with encoders around it, \
|
||||
which are not all encoded again";
|
||||
@@ -530,8 +530,8 @@ impl State {
|
||||
|
||||
/// The units the rebind's turn encodes again of `moved`, the ended encoders it moved, with
|
||||
/// their logs, in order, each with whether it splits a group: each encoder alone, but an
|
||||
/// encoder of a group of compute and blit encoders recorded into one `VkCommandBuffer` with
|
||||
/// every encoder of its group (`encoder_fold.rs`), whose shared recording none may leave
|
||||
/// encoder of a group of encoders recorded into one `VkCommandBuffer` with every encoder of
|
||||
/// its group (`encoder_fold.rs`), whose shared recording none may leave
|
||||
/// alone. A group one of whose encoders kept no log, or cannot be encoded again apart in its
|
||||
/// command buffer's command predication (`State::encodes_again_apart`), is split where each
|
||||
/// such encoder lies in one of Metal's submissions that runs nothing anyway
|
||||
@@ -579,7 +579,7 @@ impl State {
|
||||
units
|
||||
}
|
||||
|
||||
/// `group`, a group of compute and blit encoders recorded into one `VkCommandBuffer` some of
|
||||
/// `group`, a group of encoders recorded into one `VkCommandBuffer` some of
|
||||
/// whose encoders cannot be encoded again ([`State::encodes_again`]), split by a rebind: where
|
||||
/// each of those lies in one of Metal's submissions (`checks::metal_submissions`) that holds
|
||||
/// one of them that named a buffer the rebinds moved (`rebound`), which the first submission
|
||||
|
||||
@@ -217,6 +217,7 @@ use super::kept_barriers::{KeptBarriers, SlotStamps};
|
||||
use super::{lock, recording_error, submission_error, CommandBufferShared, State};
|
||||
use crate::deferred::Deferred;
|
||||
use crate::encoder::{count_shadow_copies, OverwriteBy, Recorded, RecordedSegment};
|
||||
use crate::encoder_fold::GroupPlaces;
|
||||
use crate::error::CommandBufferError;
|
||||
use crate::error::{internal, Error};
|
||||
use crate::event::EventShared;
|
||||
@@ -763,14 +764,22 @@ impl CommandBufferShared {
|
||||
let exit = (!exits.is_empty()).then(|| Summary::outside_encoders(exit_uses));
|
||||
// The held depths' moves before each encoder that names one, into the layout it needs
|
||||
// (`texture/held_depth.rs`): writes the tracker plans with the encoder's uses, before
|
||||
// them, so each waits for what came before it and orders what follows.
|
||||
// them, so each waits for what came before it and orders what follows. Those of an
|
||||
// encoder whose commands a group's shared `VkCommandBuffer` holds go before the group
|
||||
// (`encoder_fold::GroupPlaces`).
|
||||
let unnamed = BTreeSet::new();
|
||||
let held_moves = shared.textures.held.moves(encoders.iter().map(|recorded| {
|
||||
match state.ended.get(recorded.encoder) {
|
||||
Some(record) => (&record.keys, record.held.as_slice()),
|
||||
None => (&unnamed, &[][..]),
|
||||
}
|
||||
}));
|
||||
let mut places = GroupPlaces::default();
|
||||
let held_moves =
|
||||
(shared.textures.held).moves(encoders.iter().enumerate().map(|(at, recorded)| {
|
||||
match state.ended.get(recorded.encoder) {
|
||||
Some(record) => (
|
||||
places.place(at, recorded.encoder, record.group.as_ref()),
|
||||
&record.keys,
|
||||
record.held.as_slice(),
|
||||
),
|
||||
None => (at, &unnamed, &[][..]),
|
||||
}
|
||||
}));
|
||||
// Each encoder's summary with its moves' uses joined, where it has moves; the first's
|
||||
// with what the command buffer's work may write through its residency, which any of its
|
||||
// encoders may write (`State::resident_writes`).
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
//!
|
||||
//! - **Recording.** `open` allocates a primary `VkCommandBuffer` from the command buffer's pool
|
||||
//! and begins it; `end` ends it and appends it to the command buffer's recordings, which
|
||||
//! `commit` submits in that order. A compute or blit encoder records on instead in the one of
|
||||
//! the compute and blit encoders before it where nothing between them needs a boundary, a
|
||||
//! barrier from their commands before each of its own that needs one (`encoder_fold.rs`).
|
||||
//! `commit` submits in that order. A compute or blit encoder, or a render encoder with a log
|
||||
//! whose pass records at its end, records on instead in the one of the encoders before it where
|
||||
//! nothing between them needs a boundary, a barrier from their commands before each of its own
|
||||
//! that needs one (a render encoder's one barrier from everything of theirs, at its open:
|
||||
//! `encoder_fold.rs`).
|
||||
//! - **Segments**. An indirect command buffer's commands may change until the command buffer is
|
||||
//! committed, so an encoder that executes them [`defer`](EncoderCore::defer)s them: it ends its
|
||||
//! `VkCommandBuffer` there and goes on in a new one, and the segment's own is recorded later
|
||||
@@ -411,8 +413,9 @@ pub(super) struct EncoderCore {
|
||||
/// command buffer. Not `recorded`: a pass may hold it, and what records before that pass
|
||||
/// goes in another before it, which leads the encoder's then.
|
||||
barriered: Option<vk::CommandBuffer>,
|
||||
/// What a compute or blit encoder asked, as it opened, of the group of encoders its command
|
||||
/// buffer's tail held (`encoder_fold.rs`); `None` for any other encoder.
|
||||
/// What a compute, blit or render encoder asked, as it opened, of the group of encoders its
|
||||
/// command buffer's tail held (`encoder_fold.rs`); `None` for any other encoder, and for a
|
||||
/// render encoder that takes no group.
|
||||
joining: Option<Joining>,
|
||||
/// The group it joined, recording on into its tail, which its group's first part holds
|
||||
/// (`encoder_fold.rs`); `None` where it began a `VkCommandBuffer` of its own.
|
||||
@@ -674,8 +677,9 @@ impl EncoderCore {
|
||||
/// Open an encoder on `command_buffer` for Metal's `call`, `ordered` when Metal runs its
|
||||
/// commands in encoded order (a blit or serial compute encoder); a compute or blit encoder
|
||||
/// asks `joining` of the group of encoders the command buffer's tail holds, which it joins
|
||||
/// where it may, recording on into the tail (`encoder_fold.rs`). Refused when the command
|
||||
/// buffer is committed, has an open encoder, or has an abandoned one.
|
||||
/// where it may, recording on into the tail (`encoder_fold.rs`), as may a render encoder with
|
||||
/// a log. Refused when the command buffer is committed, has an open encoder, or has an
|
||||
/// abandoned one.
|
||||
pub(super) fn open(
|
||||
command_buffer: &CommandBuffer,
|
||||
call: &'static str,
|
||||
@@ -729,7 +733,7 @@ impl EncoderCore {
|
||||
// the group it joined), under the state lock, and only this encoder records it now; the
|
||||
// device made by the runtime enables `hostQueryReset` (`gpu_time.rs`).
|
||||
let times = unsafe { shared.timing.encoders().open(shared.vk(), raw) };
|
||||
// A group of compute and blit encoders it did not join takes no encoder from here.
|
||||
// A group of encoders it did not join takes no encoder from here.
|
||||
let unkept = state.close_fold(&shared.counts);
|
||||
state.encoder_open = true;
|
||||
// Made under the protection options set now (`command_buffer/protection.rs`).
|
||||
@@ -746,7 +750,7 @@ impl EncoderCore {
|
||||
shared.scheduler.spare_logs().give(log);
|
||||
}
|
||||
shared.identifiers.encoder_opened(kind);
|
||||
Ok(EncoderCore {
|
||||
let mut core = EncoderCore {
|
||||
open: OpenGuard {
|
||||
command_buffer: command_buffer.clone(),
|
||||
ended: false,
|
||||
@@ -800,7 +804,15 @@ impl EncoderCore {
|
||||
resident_noted: None,
|
||||
tally: Tally::take(),
|
||||
_not_sync: PhantomData,
|
||||
})
|
||||
};
|
||||
// A render encoder records its pass, and the steps before and after it, through commands
|
||||
// that name none of the pass's uses (`render.rs`'s end), and no barrier may record inside
|
||||
// the pass: one that joined a group orders after everything of the group's earlier
|
||||
// encoders first, here, before any command of its own (`encoder_fold.rs`).
|
||||
if kind == EncoderKind::Render {
|
||||
core.order_after_fold(raw);
|
||||
}
|
||||
Ok(core)
|
||||
}
|
||||
|
||||
/// The core a segment of `command_buffer` records into at its commit, `ordered` as the
|
||||
@@ -1341,7 +1353,7 @@ impl EncoderCore {
|
||||
/// ([`gather`](Self::gather)). `None` where none can be made, which abandons the command
|
||||
/// buffer (as a failure to end one does, [`defer`](Self::defer)).
|
||||
///
|
||||
/// In an encoder that joined a group of compute and blit encoders (`encoder_fold.rs`), whose
|
||||
/// In an encoder that joined a group of encoders (`encoder_fold.rs`), whose
|
||||
/// commands
|
||||
/// record here without the order each command takes after the group's earlier encoders
|
||||
/// ([`track`](Self::track)), a barrier from everything of theirs not yet ordered to
|
||||
@@ -1369,8 +1381,10 @@ impl EncoderCore {
|
||||
let Some(barrier) = fold.order.everything() else {
|
||||
return;
|
||||
};
|
||||
let shared = self.open.command_buffer.device().shared();
|
||||
// SAFETY: as in `barrier`.
|
||||
unsafe { barrier.record(self.open.command_buffer.device().shared().vk(), raw) };
|
||||
unsafe { barrier.record(shared.vk(), raw) };
|
||||
shared.counts.command_barrier();
|
||||
fold.order.ordered(barrier);
|
||||
}
|
||||
|
||||
@@ -3207,9 +3221,9 @@ impl EncoderCore {
|
||||
}
|
||||
Some(_) => None,
|
||||
};
|
||||
// A log not kept goes back to the device's spares (`replay.rs`); a compute or blit
|
||||
// encoder's waits for its end, which keeps it where the encoder is in a group of encoders
|
||||
// that may be encoded again (`encoder_fold.rs`).
|
||||
// A log not kept goes back to the device's spares (`replay.rs`); that of an encoder that
|
||||
// asked a group as it opened waits for its end, which keeps it where the encoder is in a
|
||||
// group of encoders that may be encoded again (`encoder_fold.rs`).
|
||||
let mut held_log = None;
|
||||
let replay = replay.and_then(|log| {
|
||||
let keeps = self.segments.iter().all(Segment::records_again)
|
||||
@@ -3321,7 +3335,7 @@ impl EncoderCore {
|
||||
let command_buffer_id = open.command_buffer.object_id().get();
|
||||
let trail = trail.map(|notes| notes.described(kind, command_buffer_id, encoder));
|
||||
state.encoder_holds(encoder, uses.held().to_vec());
|
||||
// Whether it may begin or go on in a group of compute and blit encoders
|
||||
// Whether it may begin or go on in a group of encoders
|
||||
// (`encoder_fold.rs`).
|
||||
let fails = fails_command_buffer.is_some() || faults.is_some();
|
||||
match fails_command_buffer {
|
||||
@@ -3386,7 +3400,7 @@ impl EncoderCore {
|
||||
// Its whole writes go with its first part, which records its pass's clears before its
|
||||
// draws; none where a command-predication record left parts out before it.
|
||||
let mut overwrites = (left_out == 0).then_some(overwrites);
|
||||
// What a compute or blit encoder of one part used, which the next encoder of a group it
|
||||
// What an encoder of one part that asked a group used, which the next encoder of a group it
|
||||
// begins or goes on in orders after (`encoder_fold.rs`); and whether that part leaves
|
||||
// nothing that needs a `VkCommandBuffer` of its own after it.
|
||||
let mut fold_summary = None;
|
||||
@@ -3400,7 +3414,7 @@ impl EncoderCore {
|
||||
}
|
||||
if plain {
|
||||
plain = segments.is_empty() && !summary.has_updates();
|
||||
fold_summary = plain.then(|| summary.clone());
|
||||
fold_summary = (plain && fold.is_some()).then(|| summary.clone());
|
||||
}
|
||||
// Its uses and fence waits join its group's first part's summary, whose
|
||||
// `VkCommandBuffer` its first commands went into; its own part keeps its fence
|
||||
@@ -3449,7 +3463,7 @@ impl EncoderCore {
|
||||
);
|
||||
}
|
||||
state.tail = Some(raw);
|
||||
// It begins a group of compute and blit encoders, goes on in the one it joined, or closes
|
||||
// It begins a group of encoders, goes on in the one it joined, or closes
|
||||
// it (`encoder_fold.rs`).
|
||||
if joining.is_some() {
|
||||
let shared = open.command_buffer.device().shared();
|
||||
@@ -3458,6 +3472,7 @@ impl EncoderCore {
|
||||
fold,
|
||||
in_tail,
|
||||
encoder,
|
||||
plain,
|
||||
summary: fold_summary,
|
||||
log: held_log.map(|log| (log, executed)),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Consecutive compute and blit encoders of one command buffer recorded into one
|
||||
//! Consecutive compute, blit and render encoders of one command buffer recorded into one
|
||||
//! `VkCommandBuffer`.
|
||||
//!
|
||||
//! Every encoder records into a primary `VkCommandBuffer` of its own (`encoder.rs`), and each
|
||||
@@ -9,10 +9,12 @@
|
||||
//! (`examples/dispatch_chain.rs`), and each `vkBeginCommandBuffer` host time (ANV clears its
|
||||
//! command buffer state there). A compute or blit encoder that opens where the encoder before it
|
||||
//! leaves nothing that needs a boundary records on in that encoder's `VkCommandBuffer`, the
|
||||
//! command buffer's tail, and its batch's submission submits no command buffer for it.
|
||||
//! command buffer's tail, and its batch's submission submits no command buffer for it; so does a
|
||||
//! render encoder whose pass records at its end (**Render encoders**, below).
|
||||
//!
|
||||
//! - **Where.** A compute or blit encoder takes the tail where the encoder before it was a compute
|
||||
//! or blit encoder ([`Fold`], kept by the command buffer as that one ended) whose recording is
|
||||
//! - **Where.** A compute or blit encoder takes the tail where the encoder before it was a
|
||||
//! compute, blit or render encoder ([`Fold`], kept by the command buffer as that one ended,
|
||||
//! **Render encoders** below) whose recording is
|
||||
//! one part, with no work left for later (no segment), no fence update and nothing that fails
|
||||
//! or faults its command buffer, nor work its batch's submission records after it or judges
|
||||
//! by its part (a write into an ASTC carrier, whose second twin's decode the submission records
|
||||
@@ -26,8 +28,33 @@
|
||||
//! of command predication (`predication.rs`), so a group that holds one may hold compute
|
||||
//! encoders of two units: a record that leaves its unit's work out (an unbalanced one) from an
|
||||
//! encoder past the group's first splits the group at the commit (**Failed**, below). Every
|
||||
//! compute and blit encoder logs its calls (`replay.rs`), so each of a group's encoders can be
|
||||
//! encoded again apart. Counted: `WorkCounts::encoders_folded`.
|
||||
//! compute and blit encoder logs its calls (`replay.rs`), and a render encoder takes a group
|
||||
//! only with a log, so each of a group's encoders can be encoded again apart. Counted:
|
||||
//! `WorkCounts::encoders_folded`.
|
||||
//! - **Render encoders.** A render encoder takes a group only where it logs its calls (`replay.rs`:
|
||||
//! the device has a buffer over host pages; a device with none keeps one `VkCommandBuffer` for
|
||||
//! each render encoder), its pass is of one color group and over no rasterization-rate map
|
||||
//! (its later groups, and a reset of its map, encode it again alone), and its depth attachment
|
||||
//! is no image the device holds out of `GENERAL` between passes (`texture/held_depth.rs`: a
|
||||
//! holding encoder's moves go before its own `VkCommandBuffer`; and a group's other encoders'
|
||||
//! moves go before the group, `GroupPlaces`, each into `GENERAL`, which no member then leaves).
|
||||
//! One whose pass records at its end, its draws in a secondary command buffer the pass executes
|
||||
//! there, joins a group as a blit encoder does (`Joining::Render`); one whose first instance
|
||||
//! records inline (`render/inline_first.rs`) begins its pass at its first draw and records the
|
||||
//! commands its end finds before the pass in a `VkCommandBuffer` that goes before the pass's, so
|
||||
//! it joins none, and begins its own. Either may begin a group, as its end leaves the tail
|
||||
//! outside any render pass instance; one that begins a group no encoder joins pays for it as
|
||||
//! the next encoder opens (the group closed, nothing built for it: [`Fold::order`] waits for a
|
||||
//! second encoder). No barrier may record inside a pass instance, and the
|
||||
//! encoder records its pass, and the steps before and after it, through commands that name none
|
||||
//! of the pass's uses: one that joined a group records one barrier from everything of the
|
||||
//! group's earlier encoders not yet ordered to everything after ([`FoldOrder::everything`]) at
|
||||
//! its open, before any command of its own, as an encoder past the scheduler's planned
|
||||
//! barriers takes one from everything before at its open (`encoder.rs`). What its pass leaves
|
||||
//! for later (a draw or tile dispatch whose pipeline is being made, an execution of render
|
||||
//! commands: `deferred.rs` segments), a fence update, or a write it judges by its part
|
||||
//! (`Overwrite`) ends the group after it, as for any encoder; a late resolve target
|
||||
//! (`render/late_resolve.rs`) is the pass's own, recorded at its end in its `VkCommandBuffer`.
|
||||
//! - **The barrier between them** is recorded as the encoder records, by the rule the tracker
|
||||
//! applies between two encoders of one batch: from each earlier write of a tracked resource's
|
||||
//! overlapping range to a later read or write, its accesses made visible, and from each earlier
|
||||
@@ -64,15 +91,16 @@
|
||||
//! ones run nothing: exactly the encoders the failure names, or the record leaves out, run
|
||||
//! nothing, as on Metal. Where the encoders that run cannot all be encoded again (a compute
|
||||
//! encoder whose unit of command predication laid a loop or left work out, so a command of its
|
||||
//! encoded again would run outside its block: `Predication::alone`; a blit encoder belongs to no
|
||||
//! unit; or a call answers otherwise when encoded again), the failure fails the whole group
|
||||
//! (docs/API.md, "A command buffer committed as failed"). A command buffer with a submission
|
||||
//! check (`command_buffer/checks.rs`), which fails one of Metal's submissions as it is
|
||||
//! submitted, splits so at the commit each group whose shared `VkCommandBuffer` holds commands
|
||||
//! of more than one of them, those commands' encoders encoded again apart, so a check fails its
|
||||
//! own submission's encoders alone (an encoder that went on in `VkCommandBuffer`s of its own
|
||||
//! before any command of its recorded there is failed by its own parts); one that cannot be
|
||||
//! split so stays whole, and a check that fails one of those submissions fails each of them.
|
||||
//! encoded again would run outside its block: `Predication::alone`; a blit or render encoder
|
||||
//! belongs to no unit; or a call answers otherwise when encoded again), the failure fails the
|
||||
//! whole group (docs/API.md, "A command buffer committed as failed"). A command buffer with a
|
||||
//! submission check (`command_buffer/checks.rs`), which fails one of Metal's submissions as it
|
||||
//! is submitted, splits so at the commit each group whose shared `VkCommandBuffer` holds
|
||||
//! commands of more than one of them (a render pass is a submission of its own), those
|
||||
//! commands' encoders encoded again apart, so a check fails its own submission's encoders alone
|
||||
//! (an encoder that went on in `VkCommandBuffer`s of its own before any command of its recorded
|
||||
//! there is failed by its own parts); one that cannot be split so stays whole, and a check that
|
||||
//! fails one of those submissions fails each of them.
|
||||
//! - **Logs.** A group's members' logs are held from the group's close for the commit, which
|
||||
//! keeps them for every member where one member keeps its own for a rebind, and keeps those of
|
||||
//! a group its failure splits; the rest stay held until the command buffer's release, which
|
||||
@@ -130,11 +158,16 @@ pub(crate) struct FoldOrder<K> {
|
||||
}
|
||||
|
||||
impl<K: Copy + Eq + Hash> FoldOrder<K> {
|
||||
/// The order after nothing.
|
||||
pub(crate) fn none() -> FoldOrder<K> {
|
||||
FoldOrder {
|
||||
priors: KeyMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The order after the encoder whose summary is `summary`.
|
||||
pub(crate) fn after(summary: &Summary<K>) -> FoldOrder<K> {
|
||||
let mut order = FoldOrder {
|
||||
priors: KeyMap::default(),
|
||||
};
|
||||
let mut order = FoldOrder::none();
|
||||
order.join(summary);
|
||||
order
|
||||
}
|
||||
@@ -292,25 +325,27 @@ pub(crate) struct Stashed {
|
||||
/// What an encoder asks of the group its command buffer's tail may hold, as it opens: a compute
|
||||
/// encoder joins one whose compute encoders are of its dispatch type (or that holds none), as a
|
||||
/// unit of command predication holds compute encoders of one dispatch type (`predication.rs`); a
|
||||
/// blit encoder joins any.
|
||||
/// blit encoder joins any; a render encoder joins any where `joins`, else none, and may begin one
|
||||
/// either way (the module docs, **Render encoders**).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Joining {
|
||||
Compute(DispatchType),
|
||||
Blit,
|
||||
Render { joins: bool },
|
||||
}
|
||||
|
||||
impl Joining {
|
||||
/// The dispatch type of the compute encoders of a group it joins: its own, a compute
|
||||
/// encoder's; `group`'s, a blit encoder's.
|
||||
/// encoder's; `group`'s, a blit or render encoder's.
|
||||
fn dispatch_type(self, group: Option<DispatchType>) -> Option<DispatchType> {
|
||||
match self {
|
||||
Joining::Compute(dispatch_type) => Some(dispatch_type),
|
||||
Joining::Blit => group,
|
||||
Joining::Blit | Joining::Render { .. } => group,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The group of compute and blit encoders whose last ended one's `VkCommandBuffer` is its
|
||||
/// The group of encoders whose last ended one's `VkCommandBuffer` is its
|
||||
/// command buffer's tail and may take the next such encoder (the module docs): kept by the
|
||||
/// command buffer between encoders, held by the encoder that joined it while it is open.
|
||||
pub(crate) struct Fold {
|
||||
@@ -329,7 +364,9 @@ pub(crate) struct Fold {
|
||||
/// Whether every encoder it holds is a blit encoder: a later one's write of a texture whole
|
||||
/// joins its first part's (`Fold::overwrites_join`).
|
||||
pub(crate) blits_alone: bool,
|
||||
/// What its encoders did, which the next one's commands order after.
|
||||
/// What its encoders did, which the next one's commands order after: empty until a second
|
||||
/// encoder joins, which builds it from its first part's summary (`State::join_fold`), so a
|
||||
/// group no encoder joins costs no copy of what its first encoder used.
|
||||
pub(crate) order: FoldOrder<ResourceKey>,
|
||||
/// Its members' logs not kept by themselves.
|
||||
pub(crate) stashed: Vec<Stashed>,
|
||||
@@ -343,16 +380,17 @@ impl Fold {
|
||||
.dispatch_type
|
||||
.is_none_or(|group| group == dispatch_type),
|
||||
Joining::Blit => true,
|
||||
Joining::Render { joins } => joins,
|
||||
}
|
||||
}
|
||||
|
||||
/// The group `joining`'s encoder begins, its first part `leader`, its first `VkCommandBuffer`
|
||||
/// the tail.
|
||||
/// the tail; its order is built as a second encoder joins.
|
||||
pub(crate) fn begun(
|
||||
tail: vk::CommandBuffer,
|
||||
(leader, encoder): (usize, usize),
|
||||
(batches, joining): (usize, Joining),
|
||||
(summary, stashed): (&Summary<ResourceKey>, Vec<Stashed>),
|
||||
stashed: Vec<Stashed>,
|
||||
) -> Fold {
|
||||
Fold {
|
||||
tail,
|
||||
@@ -361,7 +399,7 @@ impl Fold {
|
||||
batches,
|
||||
dispatch_type: joining.dispatch_type(None),
|
||||
blits_alone: joining == Joining::Blit,
|
||||
order: FoldOrder::after(summary),
|
||||
order: FoldOrder::none(),
|
||||
stashed,
|
||||
}
|
||||
}
|
||||
@@ -384,7 +422,42 @@ impl Fold {
|
||||
}
|
||||
}
|
||||
|
||||
/// A compute or blit encoder's end as the group it begins or goes on in takes it
|
||||
/// The place, among a batch's parts, of the part whose `VkCommandBuffer` begins each encoder's
|
||||
/// commands, for what goes before them (the held depths' moves, `texture/held_depth.rs`): a
|
||||
/// part's own, or, for an encoder of a group past its first, the group's first part's, whose
|
||||
/// `VkCommandBuffer` holds the group's commands. A group lies inside one batch, its first
|
||||
/// encoder's one part before its other encoders' parts.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct GroupPlaces {
|
||||
/// The first encoder of the last group met, and the place of its part.
|
||||
leader: Option<(usize, usize)>,
|
||||
}
|
||||
|
||||
impl GroupPlaces {
|
||||
/// The place for the part at `at` of `encoder`, of the group of encoders `group` where it is
|
||||
/// one of a group's (`EncoderRecord::group`).
|
||||
pub(crate) fn place(
|
||||
&mut self,
|
||||
at: usize,
|
||||
encoder: usize,
|
||||
group: Option<&Range<usize>>,
|
||||
) -> usize {
|
||||
let Some(group) = group else {
|
||||
return at;
|
||||
};
|
||||
match self.leader {
|
||||
Some((first, place)) if first == group.start && encoder != first => place,
|
||||
_ => {
|
||||
if encoder == group.start {
|
||||
self.leader = Some((encoder, at));
|
||||
}
|
||||
at
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A compute, blit or render encoder's end as the group it begins or goes on in takes it
|
||||
/// (`State::fold_ended`).
|
||||
pub(crate) struct FoldEnd {
|
||||
/// What it asked as it opened; `None` where no group may take it (the encoder trail is on).
|
||||
@@ -395,10 +468,13 @@ pub(crate) struct FoldEnd {
|
||||
pub(crate) in_tail: bool,
|
||||
/// Its place among its command buffer's ended encoders.
|
||||
pub(crate) encoder: usize,
|
||||
/// What its one part used, where that part leaves nothing that needs a `VkCommandBuffer`
|
||||
/// boundary after it: no work for later, no fence update, nothing that fails or faults its
|
||||
/// command buffer, no write into an ASTC carrier and no `Overwrite`. `None` where it is not
|
||||
/// so.
|
||||
/// Whether its one part leaves nothing that needs a `VkCommandBuffer` boundary after it: no
|
||||
/// work for later, no fence update, nothing that fails or faults its command buffer, no write
|
||||
/// into an ASTC carrier and no `Overwrite`.
|
||||
pub(crate) plain: bool,
|
||||
/// What that part used, where it is plain and joined a group, whose next encoders order
|
||||
/// after it; `None` else (the first part of a group it begins holds its summary, which the
|
||||
/// group's second encoder orders after: `State::join_fold`).
|
||||
pub(crate) summary: Option<Summary<ResourceKey>>,
|
||||
/// Its log, which it did not keep, with its executions' place.
|
||||
pub(crate) log: Option<(Replay, Range<usize>)>,
|
||||
|
||||
@@ -2300,9 +2300,22 @@ impl CommandBuffer {
|
||||
true => vk::CommandBuffer::null(),
|
||||
false => self.begin_draws(&compatible)?,
|
||||
};
|
||||
// A pass with a log may take a group of encoders recorded into one `VkCommandBuffer`
|
||||
// (`encoder_fold.rs`, **Render encoders**): it joins one where it records its pass at
|
||||
// its end, and may begin one either way. One over a rasterization-rate map or of several
|
||||
// color groups takes none (a reset of its map, or its later groups, encode it again
|
||||
// alone), nor one whose depth attachment the device holds out of `GENERAL` between passes
|
||||
// (`texture/held_depth.rs`), whose moves go before its own `VkCommandBuffer`.
|
||||
let held_attachment = (layout.depth_stencil.as_ref()).is_some_and(|ds| {
|
||||
let none = crate::tracker::Access::NONE;
|
||||
let key = ds.target.texture.bound_use(none, none).key;
|
||||
device.shared().textures.held.holds(key)
|
||||
});
|
||||
let joining = (log.is_some() && rate_map.is_none() && groups == 1 && !held_attachment)
|
||||
.then_some(super::encoder_fold::Joining::Render { joins: !inline });
|
||||
// A refusal past here leaves the secondary command buffer unused, freed with the pool.
|
||||
let mut core = match again {
|
||||
None => EncoderCore::open(self, CALL, EncoderKind::Render, (false, None))?,
|
||||
None => EncoderCore::open(self, CALL, EncoderKind::Render, (false, joining))?,
|
||||
Some(_) => EncoderCore::replaying(self, false)?,
|
||||
}
|
||||
.boxed();
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
//! ([`Replay::run`] fails, and the encoder is not encoded again). A render encoder's log
|
||||
//! starts at its open where the device has a buffer over host pages (`Rebinds::any`), else it
|
||||
//! logs nothing; a compute or blit encoder always logs, as a commit whose failure splits the
|
||||
//! group of encoders it recorded with encodes it again (`encoder_fold.rs`). It costs one push
|
||||
//! group of encoders it recorded with encodes it again (`encoder_fold.rs`), which a render
|
||||
//! encoder takes only with a log. It costs one push
|
||||
//! per call; a slice of buffers, offsets, textures or bytes goes into one of the log's arenas,
|
||||
//! so the common calls allocate nothing of their own.
|
||||
//! - **What is kept.** The command buffer keeps an ended encoder's log only where a command of
|
||||
@@ -48,7 +49,7 @@
|
||||
//! 27.0.1, probe `dealloc-probe`). And no other thread may hold such a handle past the
|
||||
//! completion: a no-copy buffer's deallocator would run where it went, on the scheduler's thread
|
||||
//! for one, whose own hold of the command buffer keeps the deallocator's wait for it from
|
||||
//! returning (`scheduler::Spent`). A log let go of in the release (a group of compute and blit
|
||||
//! returning (`scheduler::Spent`). A log let go of in the release (a group of
|
||||
//! encoders' held for the commit among them, `encoder_fold.rs`), or at its encoder's end where
|
||||
//! it is not kept, is cleared (its calls and handles go then) and its room kept for the
|
||||
//! device's next encoders ([`SpareLogs`]), so the encoding thread's logs reuse their memory
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! The held depths' moves between encoders (`texture/held_depth.rs`): each batch moves a held
|
||||
//! image into the layout each encoder that names it needs, from the layout the batches submitted
|
||||
//! before left it in, and a move is a write of the whole image the tracker orders.
|
||||
//! before left it in, and a move is a write of the whole image the tracker orders; an encoder of
|
||||
//! a group recorded into one `VkCommandBuffer` (`encoder_fold.rs`) has its moves go before the
|
||||
//! group.
|
||||
|
||||
use crate::encoder_fold::GroupPlaces;
|
||||
use crate::resource::ResourceKey;
|
||||
use crate::texture::held_depth::{need, BatchMoves, HeldImage, HeldImages, HELD};
|
||||
use crate::tracker::{Access, ImagePlace, Use, UseRange};
|
||||
@@ -33,15 +36,13 @@ fn record(key: ResourceKey, named: bool, held: bool) -> (BTreeSet<ResourceKey>,
|
||||
(names, holds)
|
||||
}
|
||||
|
||||
/// The moves of a batch of `encoders`.
|
||||
/// The moves of a batch of `encoders`, each its own place.
|
||||
fn moves(
|
||||
images: &HeldImages,
|
||||
encoders: &[(BTreeSet<ResourceKey>, Vec<ResourceKey>)],
|
||||
) -> BatchMoves {
|
||||
images.moves(
|
||||
encoders
|
||||
.iter()
|
||||
.map(|(named, held)| (named, held.as_slice())),
|
||||
(encoders.iter().enumerate()).map(|(at, (named, held))| (at, named, held.as_slice())),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -158,3 +159,54 @@ fn an_image_gone_is_not_moved() {
|
||||
assert_eq!(layouts(&planned, 2), vec![Vec::new(), Vec::new()]);
|
||||
assert!(planned.is_empty());
|
||||
}
|
||||
|
||||
/// A group of three encoders recorded into the first's `VkCommandBuffer` (`encoder_fold.rs`),
|
||||
/// then one of its own: the second, which samples the image the batch before left held, has its
|
||||
/// move go before the group's first, where the shared `VkCommandBuffer` begins, not before its
|
||||
/// own part, which holds no `VkCommandBuffer` and comes after the commands it moves for.
|
||||
#[test]
|
||||
fn a_grouped_encoder_s_move_goes_before_its_group() {
|
||||
let (images, key) = one();
|
||||
moves(&images, &[record(key, true, true)]).submitted();
|
||||
let group = 0..3;
|
||||
let mut places = GroupPlaces::default();
|
||||
let at: Vec<usize> = [Some(&group), Some(&group), Some(&group), None]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(at, group)| places.place(at, at, group))
|
||||
.collect();
|
||||
assert_eq!(at, [0, 0, 0, 3]);
|
||||
let batch = [
|
||||
record(key, false, false),
|
||||
record(key, true, false),
|
||||
record(key, false, false),
|
||||
record(key, true, false),
|
||||
];
|
||||
let planned = images.moves(
|
||||
(batch.iter().zip(&at)).map(|((named, held), &place)| (place, named, held.as_slice())),
|
||||
);
|
||||
assert_eq!(
|
||||
layouts(&planned, 4),
|
||||
vec![vec![(HELD, GENERAL)], Vec::new(), Vec::new(), Vec::new()]
|
||||
);
|
||||
assert_eq!(planned.released, 1);
|
||||
}
|
||||
|
||||
/// Two groups of one batch each take their own first part's place, and an encoder of no group
|
||||
/// its own.
|
||||
#[test]
|
||||
fn each_group_s_encoders_take_their_own_group_s_first_place() {
|
||||
let (first, second) = (0..2, 3..5);
|
||||
let mut places = GroupPlaces::default();
|
||||
let groups = [
|
||||
Some(&first),
|
||||
Some(&first),
|
||||
None,
|
||||
Some(&second),
|
||||
Some(&second),
|
||||
];
|
||||
let at: Vec<usize> = (groups.into_iter().enumerate())
|
||||
.map(|(at, group)| places.place(at, at, group))
|
||||
.collect();
|
||||
assert_eq!(at, [0, 0, 2, 3, 3]);
|
||||
}
|
||||
@@ -614,6 +614,8 @@ mod render_creation_cost;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod render_directory_trips;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod render_fold;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod render_sibling_work;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod render_stage_digests;
|
||||
|
||||
@@ -74,6 +74,13 @@ impl Page {
|
||||
unsafe { std::slice::from_raw_parts(self.0.as_ptr().cast::<u32>(), BYTES / 4) }
|
||||
}
|
||||
|
||||
/// Write `bytes` at its start, while no command uses it.
|
||||
pub(super) fn write(&self, bytes: &[u8]) {
|
||||
assert!(bytes.len() <= BYTES, "the page holds {BYTES} bytes");
|
||||
// SAFETY: `BYTES` bytes, allocated in `new`, which no command uses now.
|
||||
unsafe { std::ptr::copy_nonoverlapping(bytes.as_ptr(), self.0.as_ptr(), bytes.len()) };
|
||||
}
|
||||
|
||||
/// Its pages, for a no-copy buffer or a rebind.
|
||||
///
|
||||
/// # Safety
|
||||
|
||||
@@ -0,0 +1,904 @@
|
||||
//! Render encoders in groups of encoders recorded into one `VkCommandBuffer` (`encoder_fold.rs`,
|
||||
//! **Render encoders**): one whose pass records at its end joins the group before it, one whose
|
||||
//! first instance records inline only begins one, each after one barrier from everything of the
|
||||
//! group's earlier encoders, and what a pass leaves for later ends the group after it. A render
|
||||
//! encoder takes a group only with a log of its calls, which the device keeps where it has a
|
||||
//! buffer over host pages: each lane but [`a_render_encoder_without_a_log_takes_no_group`] makes
|
||||
//! one first.
|
||||
//!
|
||||
//! The hazards a missing barrier leaves are checked by what each encoder reads, a draw's colors
|
||||
//! that the compute encoder before it wrote and a copy of the target the draw wrote; a CPU device
|
||||
//! may run them in order without the barrier, so each lane also counts the barrier at each render
|
||||
//! encoder's open (`WorkCounts::command_barriers`).
|
||||
//!
|
||||
//! 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 `scale_and_offset`
|
||||
//! (`output[i] = input[i] * scale + i`), `colored_vertex` and `colored_fragment` of the owned
|
||||
//! fixture `validation/fixtures/public/examples/runtime_examples.ll`.
|
||||
|
||||
use super::blit_holds::{options, Scratch, WAIT};
|
||||
use super::dispatch_pending::state;
|
||||
use super::encoder_holds::{render_state, words_of};
|
||||
use super::rebind_behind_a_wait::{Page, BYTES};
|
||||
use crate::pipeline::pool::held;
|
||||
use crate::{
|
||||
BlitOption, Buffer, ClearColor, CommandBuffer, CommandBufferError, CommandBufferStatus,
|
||||
CommitFailure, ComputePipelineState, Device, EncoderKind, Error, EventRef, FailedEncoders,
|
||||
LoadAction, Origin, PipelineOptions, RenderPassDescriptor, RenderPipelineState, ResolveTarget,
|
||||
ResourceOptions, Size, StoreAction, Submission, SubmissionCheck, Texture, TextureDescriptor,
|
||||
WorkCounts,
|
||||
};
|
||||
use metal2vulkan::device::RenderLoweringPolicy;
|
||||
use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureType, TextureUsage};
|
||||
use metal2vulkan::pipeline::{ColorAttachmentDescriptor, RenderPipelineDescriptor, StageSource};
|
||||
use std::collections::BTreeSet;
|
||||
use std::num::NonZeroU64;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
/// The target's side, in texels.
|
||||
const SIDE: u64 = 16;
|
||||
|
||||
/// The color the draws take, and the bytes an `RGBA8Unorm` texel stores of it.
|
||||
const DRAWN: [f32; 4] = [1.0, 0.2, 0.0, 1.0];
|
||||
const DRAWN_TEXEL: [u8; 4] = [255, 51, 0, 255];
|
||||
|
||||
/// The quad's vertices, and the floats of their colors.
|
||||
const VERTICES: u32 = 6;
|
||||
const COLOR_WORDS: u64 = VERTICES as u64 * 4;
|
||||
|
||||
/// The steps of a chain.
|
||||
const STEPS: u64 = 6;
|
||||
|
||||
/// The fixture's functions and the buffers every lane draws and dispatches with, on a device with
|
||||
/// a buffer over host pages, so it logs its render encoders' calls.
|
||||
struct Lane {
|
||||
device: Device,
|
||||
compute: ComputePipelineState,
|
||||
render: RenderPipelineState,
|
||||
scale: Buffer,
|
||||
/// Two triangles over the whole target.
|
||||
positions: Buffer,
|
||||
/// The input from which `scale_and_offset` writes [`DRAWN`] for every vertex.
|
||||
from: Buffer,
|
||||
/// [`DRAWN`] for every vertex, as the CPU wrote it.
|
||||
colors: Buffer,
|
||||
/// The buffer over host pages; `None` on a lane that makes none.
|
||||
_host: Option<Buffer>,
|
||||
/// The host pages, dropped after the buffer over them and the device.
|
||||
_page: Page,
|
||||
}
|
||||
|
||||
impl Lane {
|
||||
/// A lane on a device of `options`, with a buffer over host pages where `host`; `None`,
|
||||
/// printed, where the device imports no host memory.
|
||||
fn new(scratch: &Scratch, lowering: RenderLoweringPolicy, host: bool) -> Option<Lane> {
|
||||
let mut options = options(&scratch.0);
|
||||
options.policy.render_lowering = lowering;
|
||||
let device = Device::system_default_with(&options).unwrap();
|
||||
let page = Page::new();
|
||||
let host = match host {
|
||||
false => None,
|
||||
// SAFETY: the page outlives the buffer (dropped after it and the device), and no
|
||||
// command uses it.
|
||||
true => match unsafe {
|
||||
device.new_buffer_with_bytes_no_copy(
|
||||
page.memory(),
|
||||
BYTES as u64,
|
||||
ResourceOptions::shared(),
|
||||
None,
|
||||
)
|
||||
} {
|
||||
Ok(buffer) => Some(buffer),
|
||||
Err(Error::Unsupported(gap)) => {
|
||||
eprintln!("RENDER-FOLD: the device imports no host memory: {gap:?}");
|
||||
return None;
|
||||
}
|
||||
Err(error) => panic!("new_buffer_with_bytes_no_copy: {error:?}"),
|
||||
},
|
||||
};
|
||||
let corners: [[f32; 2]; 6] = [
|
||||
[-1.0, 1.0],
|
||||
[1.0, 1.0],
|
||||
[-1.0, -1.0],
|
||||
[1.0, 1.0],
|
||||
[1.0, -1.0],
|
||||
[-1.0, -1.0],
|
||||
];
|
||||
let lane = Lane {
|
||||
compute: state(&device),
|
||||
render: render_state(
|
||||
&device,
|
||||
"examples/runtime_examples.ll",
|
||||
"colored_vertex",
|
||||
"colored_fragment",
|
||||
),
|
||||
scale: floats(&device, [1.0]),
|
||||
positions: floats(&device, corners.into_iter().flatten()),
|
||||
from: floats(
|
||||
&device,
|
||||
(0..COLOR_WORDS).map(|i| DRAWN[(i % 4) as usize] - i as f32),
|
||||
),
|
||||
colors: floats(&device, (0..VERTICES).flat_map(|_| DRAWN)),
|
||||
_host: host,
|
||||
_page: page,
|
||||
device,
|
||||
};
|
||||
Some(lane)
|
||||
}
|
||||
|
||||
/// A lane on the default device, which lowers render calls at the call.
|
||||
fn at_call(scratch: &Scratch) -> Option<Lane> {
|
||||
Lane::new(scratch, RenderLoweringPolicy::AtCall, true)
|
||||
}
|
||||
|
||||
/// A `Private` target, cleared to zero and warm: each pass shape the lanes draw, and a
|
||||
/// dispatch and a copy, ran once, so the chains below record each at once (no draw waits
|
||||
/// for its pipeline, which would leave work for later).
|
||||
fn target(&self) -> Texture {
|
||||
let mut descriptor =
|
||||
TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false);
|
||||
descriptor.usage = TextureUsage::RENDER_TARGET;
|
||||
descriptor.resource_options = ResourceOptions::private();
|
||||
let target = self.device.new_texture(&descriptor).unwrap();
|
||||
let queue = self.device.new_command_queue().unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let colors = self.zeros(COLOR_WORDS);
|
||||
self.dispatch(&command_buffer, &colors);
|
||||
self.draw(&command_buffer, &target, LoadAction::DontCare, &colors);
|
||||
self.draw(&command_buffer, &target, LoadAction::Load, &colors);
|
||||
let back = self.back();
|
||||
self.copy_back(&command_buffer, &target, &back);
|
||||
run(&command_buffer);
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let mut cleared = pass(&target, LoadAction::Clear);
|
||||
cleared.color_attachments[0].clear_color = ClearColor::new(0.0, 0.0, 0.0, 0.0);
|
||||
let encoder = command_buffer.render_command_encoder(&cleared).unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
run(&command_buffer);
|
||||
target
|
||||
}
|
||||
|
||||
/// A `Shared` buffer of `words` zero floats.
|
||||
fn zeros(&self, words: u64) -> Buffer {
|
||||
floats(&self.device, (0..words).map(|_| 0.0))
|
||||
}
|
||||
|
||||
/// A `Shared` buffer the target's texels are copied into.
|
||||
fn back(&self) -> Buffer {
|
||||
self.zeros(SIDE * SIDE)
|
||||
}
|
||||
|
||||
/// A compute encoder that writes [`DRAWN`] for every vertex into `colors`, ended.
|
||||
fn dispatch(&self, command_buffer: &CommandBuffer, colors: &Buffer) {
|
||||
let mut encoder = command_buffer.compute_command_encoder().unwrap();
|
||||
encoder.set_compute_pipeline_state(&self.compute).unwrap();
|
||||
encoder.set_buffer(Some(&self.from), 0, 0).unwrap();
|
||||
encoder.set_buffer(Some(colors), 0, 1).unwrap();
|
||||
encoder.set_buffer(Some(&self.scale), 0, 2).unwrap();
|
||||
encoder
|
||||
.dispatch_threads(Size::new(COLOR_WORDS, 1, 1), Size::new(COLOR_WORDS, 1, 1))
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
}
|
||||
|
||||
/// A render encoder that draws the quad over `target`, loaded as `load`, with the vertices'
|
||||
/// colors from `colors`, ended: `DontCare` records its pass at its end, `Load` its first
|
||||
/// instance inline.
|
||||
fn draw(
|
||||
&self,
|
||||
command_buffer: &CommandBuffer,
|
||||
target: &Texture,
|
||||
load: LoadAction,
|
||||
colors: &Buffer,
|
||||
) {
|
||||
let mut encoder = (command_buffer)
|
||||
.render_command_encoder(&pass(target, load))
|
||||
.unwrap();
|
||||
encoder.set_render_pipeline_state(&self.render).unwrap();
|
||||
encoder
|
||||
.set_vertex_buffer(Some(&self.positions), 0, 0)
|
||||
.unwrap();
|
||||
encoder.set_vertex_buffer(Some(colors), 0, 1).unwrap();
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, VERTICES, 1, 0)
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
}
|
||||
|
||||
/// A blit encoder that copies `target`'s texels into `back`, ended.
|
||||
fn copy_back(&self, command_buffer: &CommandBuffer, target: &Texture, back: &Buffer) {
|
||||
let row = SIDE * 4;
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.copy_from_texture_to_buffer(
|
||||
target,
|
||||
0,
|
||||
0,
|
||||
Origin::new(0, 0, 0),
|
||||
Size::new(SIDE, SIDE, 1),
|
||||
back,
|
||||
0,
|
||||
row,
|
||||
row * SIDE,
|
||||
BlitOption::None,
|
||||
)
|
||||
.unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A pass over `target`, loaded as `load` and stored.
|
||||
fn pass(target: &Texture, load: LoadAction) -> RenderPassDescriptor {
|
||||
let mut pass = RenderPassDescriptor::new();
|
||||
let color = &mut pass.color_attachments[0];
|
||||
color.texture = Some(target.clone());
|
||||
color.load_action = load;
|
||||
color.store_action = StoreAction::Store;
|
||||
pass
|
||||
}
|
||||
|
||||
/// A `Shared` buffer of `values`' bytes.
|
||||
fn floats(device: &Device, values: impl IntoIterator<Item = f32>) -> Buffer {
|
||||
let bytes: Vec<u8> = values.into_iter().flat_map(f32::to_le_bytes).collect();
|
||||
device
|
||||
.new_buffer_with_bytes(&bytes, ResourceOptions::shared())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Commit `command_buffer` and wait for it: it completes with no error.
|
||||
fn run(command_buffer: &CommandBuffer) {
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(
|
||||
command_buffer.status(),
|
||||
CommandBufferStatus::Completed,
|
||||
"{:?}",
|
||||
command_buffer.error()
|
||||
);
|
||||
}
|
||||
|
||||
/// How many of the texels copied into `back` are not [`DRAWN_TEXEL`].
|
||||
fn wrong_texels(back: &Buffer) -> usize {
|
||||
(words_of(back).into_iter())
|
||||
.filter(|word| word.to_le_bytes() != DRAWN_TEXEL)
|
||||
.count()
|
||||
}
|
||||
|
||||
/// What moved of the counts the groups name.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Moved {
|
||||
/// `encoders_folded`.
|
||||
folded: u64,
|
||||
/// `command_buffers_begun_encoders`.
|
||||
begun: u64,
|
||||
/// `command_buffers_begun_secondaries`.
|
||||
secondaries: u64,
|
||||
/// `command_barriers`.
|
||||
barriers: u64,
|
||||
}
|
||||
|
||||
impl Moved {
|
||||
fn of(before: &WorkCounts, after: &WorkCounts) -> Moved {
|
||||
Moved {
|
||||
folded: after.encoders_folded - before.encoders_folded,
|
||||
begun: after.command_buffers_begun_encoders - before.command_buffers_begun_encoders,
|
||||
secondaries: after.command_buffers_begun_secondaries
|
||||
- before.command_buffers_begun_secondaries,
|
||||
barriers: after.command_barriers - before.command_barriers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A chain of [`STEPS`] steps on `lane`, each a compute encoder that writes a draw's colors, a
|
||||
/// render encoder that draws with them over a target of its own, its pass recorded at its end,
|
||||
/// and a blit encoder that copies the target's texels back: what moved, and how many texels of
|
||||
/// each step came back wrong.
|
||||
fn chain(lane: &Lane) -> (Moved, Vec<usize>) {
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let targets: Vec<Texture> = (0..STEPS).map(|_| lane.target()).collect();
|
||||
let colors: Vec<Buffer> = (0..STEPS).map(|_| lane.zeros(COLOR_WORDS)).collect();
|
||||
let backs: Vec<Buffer> = (0..STEPS).map(|_| lane.back()).collect();
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
for ((target, colors), back) in targets.iter().zip(&colors).zip(&backs) {
|
||||
lane.dispatch(&command_buffer, colors);
|
||||
lane.draw(&command_buffer, target, LoadAction::DontCare, colors);
|
||||
lane.copy_back(&command_buffer, target, back);
|
||||
}
|
||||
run(&command_buffer);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
(moved, backs.iter().map(wrong_texels).collect())
|
||||
}
|
||||
|
||||
/// Render encoders whose passes record at their ends join the group of the compute and blit
|
||||
/// encoders around them: one `VkCommandBuffer` for the chain, and each draw's secondary. Each
|
||||
/// draw reads the colors the compute encoder before it wrote, and each copy the texels the draw
|
||||
/// before it wrote: each render encoder's open recorded one barrier, and each copy's one.
|
||||
#[test]
|
||||
fn render_encoders_whose_pass_records_at_its_end_join_their_group() {
|
||||
let scratch = Scratch::new("render-fold-chain");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let (moved, wrong) = chain(&lane);
|
||||
println!("RENDER-FOLD-CHAIN {moved:?} wrong texels by step {wrong:?}");
|
||||
assert_eq!(wrong, vec![0; STEPS as usize], "every texel is the draw's");
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun, moved.secondaries),
|
||||
(3 * STEPS - 1, 1, STEPS),
|
||||
"every encoder after the first joined the first's group: {moved:?}"
|
||||
);
|
||||
assert!(
|
||||
moved.barriers >= 2 * STEPS,
|
||||
"each render encoder ordered after the group at its open, each copy after its draw: \
|
||||
{moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The same chain where the device lowers render calls after they return
|
||||
/// (`RenderLoweringPolicy::Worker`): each render encoder's end, lowered on the device's lowering
|
||||
/// thread or settled by the next encoder's open, takes the group as one lowered at its call does.
|
||||
#[test]
|
||||
fn render_encoders_lowered_after_their_calls_join_their_group() {
|
||||
let scratch = Scratch::new("render-fold-worker");
|
||||
let Some(lane) = Lane::new(&scratch, RenderLoweringPolicy::Worker, true) else {
|
||||
return;
|
||||
};
|
||||
let (moved, wrong) = chain(&lane);
|
||||
println!("RENDER-FOLD-WORKER {moved:?} wrong texels by step {wrong:?}");
|
||||
assert_eq!(wrong, vec![0; STEPS as usize], "every texel is the draw's");
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun, moved.secondaries),
|
||||
(3 * STEPS - 1, 1, STEPS),
|
||||
"{moved:?}"
|
||||
);
|
||||
assert!(moved.barriers >= 2 * STEPS, "{moved:?}");
|
||||
}
|
||||
|
||||
/// A render encoder whose first instance records inline joins no group but begins one: the
|
||||
/// copy and the compute encoder after it record into its `VkCommandBuffer`, and the next such
|
||||
/// render encoder begins its own, which the copy after it joins.
|
||||
#[test]
|
||||
fn a_render_encoder_that_records_inline_begins_a_group_and_joins_none() {
|
||||
let scratch = Scratch::new("render-fold-inline");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let targets = [lane.target(), lane.target()];
|
||||
let backs = [lane.back(), lane.back()];
|
||||
let colors = lane.zeros(COLOR_WORDS);
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.draw(&command_buffer, &targets[0], LoadAction::Load, &lane.colors);
|
||||
lane.copy_back(&command_buffer, &targets[0], &backs[0]);
|
||||
lane.dispatch(&command_buffer, &colors);
|
||||
lane.draw(&command_buffer, &targets[1], LoadAction::Load, &colors);
|
||||
lane.copy_back(&command_buffer, &targets[1], &backs[1]);
|
||||
run(&command_buffer);
|
||||
let after = lane.device.work_counts();
|
||||
let moved = Moved::of(&before, &after);
|
||||
let inline = after.render_passes_begun_inline - before.render_passes_begun_inline;
|
||||
let wrong: Vec<usize> = backs.iter().map(wrong_texels).collect();
|
||||
println!("RENDER-FOLD-INLINE {moved:?} inline {inline} wrong texels {wrong:?}");
|
||||
assert_eq!(wrong, [0, 0], "every texel is the draw's");
|
||||
assert_eq!(
|
||||
inline, 2,
|
||||
"both passes recorded their first instance inline"
|
||||
);
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun),
|
||||
(3, 2),
|
||||
"each inline render encoder began a group, which the encoders after it joined: {moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// On a device with no buffer over host pages a render encoder logs no call, so it takes no
|
||||
/// group: the compute encoder's, its own and the copy's `VkCommandBuffer`s, as before.
|
||||
#[test]
|
||||
fn a_render_encoder_without_a_log_takes_no_group() {
|
||||
let scratch = Scratch::new("render-fold-logless");
|
||||
let Some(lane) = Lane::new(&scratch, RenderLoweringPolicy::AtCall, false) else {
|
||||
return;
|
||||
};
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let target = lane.target();
|
||||
let (colors, back) = (lane.zeros(COLOR_WORDS), lane.back());
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.dispatch(&command_buffer, &colors);
|
||||
lane.draw(&command_buffer, &target, LoadAction::DontCare, &colors);
|
||||
lane.copy_back(&command_buffer, &target, &back);
|
||||
run(&command_buffer);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
println!("RENDER-FOLD-LOGLESS {moved:?}");
|
||||
assert_eq!(wrong_texels(&back), 0, "every texel is the draw's");
|
||||
assert_eq!((moved.folded, moved.begun), (0, 3), "{moved:?}");
|
||||
}
|
||||
|
||||
/// A compute encoder, a render encoder that joins its group and whose pass `encode` leaves work
|
||||
/// for later, and a copy of the texture the pass rendered: the render encoder joins, and the
|
||||
/// group ends after it, so the copy begins a `VkCommandBuffer` of its own. What moved.
|
||||
fn ends_its_group(
|
||||
lane: &Lane,
|
||||
encode: impl FnOnce(&CommandBuffer) -> Texture,
|
||||
after_encoding: impl FnOnce(),
|
||||
back: &Buffer,
|
||||
) -> Moved {
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let colors = lane.zeros(COLOR_WORDS);
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.dispatch(&command_buffer, &colors);
|
||||
let target = encode(&command_buffer);
|
||||
lane.copy_back(&command_buffer, &target, back);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
command_buffer.commit().unwrap();
|
||||
after_encoding();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(
|
||||
command_buffer.status(),
|
||||
CommandBufferStatus::Completed,
|
||||
"{:?}",
|
||||
command_buffer.error()
|
||||
);
|
||||
moved
|
||||
}
|
||||
|
||||
/// A draw whose pipeline is still being made (the pool held) records its pass later, as a
|
||||
/// segment: the render encoder joined the compute encoder's group, which ends after it.
|
||||
#[test]
|
||||
fn a_draw_whose_pipeline_is_being_made_ends_its_group() {
|
||||
let scratch = Scratch::new("render-fold-pending");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let target = lane.target();
|
||||
let back = lane.back();
|
||||
let row_center = 1.0 - 1.0 / SIDE as f32;
|
||||
let line = floats(&lane.device, [-2.0, row_center, 2.0, row_center]);
|
||||
let hold = held::hold();
|
||||
let pooled = lane.device.work_counts().pipelines_pooled;
|
||||
let moved = ends_its_group(
|
||||
&lane,
|
||||
|command_buffer| {
|
||||
let mut encoder = (command_buffer)
|
||||
.render_command_encoder(&pass(&target, LoadAction::DontCare))
|
||||
.unwrap();
|
||||
encoder.set_render_pipeline_state(&lane.render).unwrap();
|
||||
encoder.set_vertex_buffer(Some(&line), 0, 0).unwrap();
|
||||
encoder.set_vertex_buffer(Some(&lane.colors), 0, 1).unwrap();
|
||||
// A line, of another class than the triangles the state's creation made the
|
||||
// pipeline of: only its draw makes its pipeline.
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Line, 0, 2, 1, 0)
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
target.clone()
|
||||
},
|
||||
|| drop(hold),
|
||||
&back,
|
||||
);
|
||||
let pooled = lane.device.work_counts().pipelines_pooled - pooled;
|
||||
let top = words_of(&back)[..SIDE as usize].to_vec();
|
||||
println!("RENDER-FOLD-PENDING {moved:?} pooled {pooled}");
|
||||
assert_eq!(pooled, 1, "the line's making waited in the pool");
|
||||
assert!(
|
||||
top.iter().all(|word| word.to_le_bytes() == DRAWN_TEXEL),
|
||||
"the line drew the top row: {top:x?}"
|
||||
);
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun),
|
||||
(1, 2),
|
||||
"the render encoder joined, the copy began its own: {moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A pass that executes an indirect command buffer's draw records later, as a segment: the
|
||||
/// render encoder joined the compute encoder's group, which ends after it.
|
||||
#[test]
|
||||
fn an_execution_of_render_commands_ends_its_group() {
|
||||
use super::indirect_command_buffer_device::render_state as icb_state;
|
||||
use crate::IndirectCommandBufferDescriptor;
|
||||
use metal2vulkan::metal::{IndirectCommandType, RenderStages, ResourceUsage};
|
||||
let scratch = Scratch::new("render-fold-execution");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let target = lane.target();
|
||||
let back = lane.back();
|
||||
let state = icb_state(&lane.device, true);
|
||||
let mut descriptor = IndirectCommandBufferDescriptor::new();
|
||||
descriptor.command_types = IndirectCommandType::DRAW;
|
||||
descriptor.max_vertex_buffer_bind_count = 2;
|
||||
let icb = (lane.device)
|
||||
.new_indirect_command_buffer(&descriptor, 1, ResourceOptions::shared())
|
||||
.unwrap();
|
||||
let command = icb.indirect_render_command_at(0).unwrap();
|
||||
command.set_render_pipeline_state(&state).unwrap();
|
||||
command
|
||||
.set_vertex_buffer(Some(&lane.positions), 0, 0)
|
||||
.unwrap();
|
||||
command.set_vertex_buffer(Some(&lane.colors), 0, 1).unwrap();
|
||||
command
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, VERTICES.into(), 1, 0)
|
||||
.unwrap();
|
||||
let moved = ends_its_group(
|
||||
&lane,
|
||||
|command_buffer| {
|
||||
let mut encoder = (command_buffer)
|
||||
.render_command_encoder(&pass(&target, LoadAction::DontCare))
|
||||
.unwrap();
|
||||
for buffer in [&lane.positions, &lane.colors] {
|
||||
encoder
|
||||
.use_resource(
|
||||
buffer.as_resource(),
|
||||
ResourceUsage::READ,
|
||||
RenderStages::VERTEX,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
encoder.execute_commands_in_buffer(&icb, 0..1).unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
target.clone()
|
||||
},
|
||||
|| (),
|
||||
&back,
|
||||
);
|
||||
println!("RENDER-FOLD-EXECUTION {moved:?}");
|
||||
assert_eq!(
|
||||
wrong_texels(&back),
|
||||
0,
|
||||
"every texel is the execution's draw's"
|
||||
);
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun),
|
||||
(1, 2),
|
||||
"the render encoder joined, the copy began its own: {moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A tile dispatch whose pipeline is still being made (the pool held) records its pass later, as
|
||||
/// a segment: the render encoder joined the compute encoder's group, which ends after it. Its
|
||||
/// pass's last attachment, every pixel of which the dispatch writes, is loaded `DontCare`, so the
|
||||
/// pass records at its end: one whose first instance records inline joins no group
|
||||
/// (`a_render_encoder_that_records_inline_begins_a_group_and_joins_none`).
|
||||
#[test]
|
||||
fn a_tile_dispatch_whose_pipeline_is_being_made_ends_its_group() {
|
||||
use super::tile_pending::{tile_state, Targets};
|
||||
let scratch = Scratch::new("render-fold-tile");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let state = tile_state(&lane.device);
|
||||
let targets = Targets::new(&lane.device);
|
||||
// Made, and the lane's pipelines with it, before the pool is held.
|
||||
let copied = lane.target();
|
||||
let back = lane.back();
|
||||
let hold = held::hold();
|
||||
let before = lane.device.work_counts();
|
||||
let moved = ends_its_group(
|
||||
&lane,
|
||||
|command_buffer| {
|
||||
let mut pass = RenderPassDescriptor::new();
|
||||
for (attachment, target) in pass.color_attachments.iter_mut().zip(&targets.colors) {
|
||||
attachment.texture = Some(target.clone());
|
||||
attachment.load_action = LoadAction::Load;
|
||||
attachment.store_action = StoreAction::Store;
|
||||
}
|
||||
pass.color_attachments[2].load_action = LoadAction::DontCare;
|
||||
pass.tile_width = 16;
|
||||
pass.tile_height = 16;
|
||||
let mut encoder = command_buffer.render_command_encoder(&pass).unwrap();
|
||||
encoder.set_render_pipeline_state(&state).unwrap();
|
||||
encoder.set_tile_buffer(Some(&targets.out), 0, 0).unwrap();
|
||||
encoder
|
||||
.dispatch_threads_per_tile(Size::new(8, 8, 1))
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
copied.clone()
|
||||
},
|
||||
|| drop(hold),
|
||||
&back,
|
||||
);
|
||||
let after = lane.device.work_counts();
|
||||
let pooled = after.tile_pipelines_pooled - before.tile_pipelines_pooled;
|
||||
let inline = after.render_passes_begun_inline - before.render_passes_begun_inline;
|
||||
println!("RENDER-FOLD-TILE {moved:?} pooled {pooled} inline {inline}");
|
||||
assert_eq!(pooled, 1, "the dispatch's making waited in the pool");
|
||||
assert_eq!(inline, 0, "the pass recorded at its end");
|
||||
assert!(targets.stored(), "the dispatch stored what Metal's stores");
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun),
|
||||
(1, 2),
|
||||
"the render encoder joined, the copy began its own: {moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A four-sample pass whose color is resolved into a target set late
|
||||
/// (`set_color_resolve_target`, `render/late_resolve.rs`) records its pass, the resolve with it,
|
||||
/// at its end in the group's `VkCommandBuffer`: it joins, and so does the copy of the resolved
|
||||
/// target after it, which reads every texel the resolve wrote.
|
||||
#[test]
|
||||
fn a_late_resolve_records_in_its_group() {
|
||||
let scratch = Scratch::new("render-fold-resolve");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let library = super::encoder_holds::library(&lane.device, "examples/runtime_examples.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("colored_vertex"));
|
||||
descriptor.fragment = Some(function("colored_fragment"));
|
||||
descriptor.raster_sample_count = 4;
|
||||
descriptor.color_attachments[0] = Some(ColorAttachmentDescriptor::new(PixelFormat::RGBA8Unorm));
|
||||
let multisampled = (lane.device)
|
||||
.new_render_pipeline_state(&descriptor, &PipelineOptions::default())
|
||||
.unwrap();
|
||||
let mut msaa = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false);
|
||||
msaa.texture_type = TextureType::Type2DMultisample;
|
||||
msaa.sample_count = 4;
|
||||
msaa.usage = TextureUsage::RENDER_TARGET;
|
||||
msaa.resource_options = ResourceOptions::private();
|
||||
let samples = lane.device.new_texture(&msaa).unwrap();
|
||||
let resolved = lane.target();
|
||||
let encode = |command_buffer: &CommandBuffer, colors: &Buffer| {
|
||||
let mut pass = pass(&samples, LoadAction::DontCare);
|
||||
pass.color_attachments[0].store_action = StoreAction::Unknown;
|
||||
let mut encoder = command_buffer.render_command_encoder(&pass).unwrap();
|
||||
encoder.set_render_pipeline_state(&multisampled).unwrap();
|
||||
encoder
|
||||
.set_vertex_buffer(Some(&lane.positions), 0, 0)
|
||||
.unwrap();
|
||||
encoder.set_vertex_buffer(Some(colors), 0, 1).unwrap();
|
||||
encoder
|
||||
.draw_primitives(PrimitiveType::Triangle, 0, VERTICES, 1, 0)
|
||||
.unwrap();
|
||||
(encoder.set_color_resolve_target(Some(ResolveTarget::new(resolved.clone())), 0)).unwrap();
|
||||
(encoder.set_color_store_action(StoreAction::MultisampleResolve, 0)).unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
};
|
||||
// Warm: the four-sample pass's pipeline made, so the pass below records at its end.
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
encode(&command_buffer, &lane.colors);
|
||||
run(&command_buffer);
|
||||
|
||||
let (colors, back) = (lane.zeros(COLOR_WORDS), lane.back());
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.dispatch(&command_buffer, &colors);
|
||||
encode(&command_buffer, &colors);
|
||||
lane.copy_back(&command_buffer, &resolved, &back);
|
||||
run(&command_buffer);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
println!("RENDER-FOLD-RESOLVE {moved:?}");
|
||||
assert_eq!(wrong_texels(&back), 0, "every resolved texel is the draw's");
|
||||
assert_eq!(
|
||||
(moved.folded, moved.begun),
|
||||
(2, 1),
|
||||
"the render encoder and the copy joined the compute encoder's group: {moved:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A compute encoder, a render encoder, a compute encoder and a blit encoder's fill of one group,
|
||||
/// the fill updating a fence, which ends the group, and a compute encoder after it, committed as
|
||||
/// failed with `encoders`: which of the five ran (each compute encoder writes the colors of a
|
||||
/// buffer of its own, the render encoder draws over a target the copy after the commit reads),
|
||||
/// and how many encoders the commit encoded again (`WorkCounts::encoders_reencoded`).
|
||||
fn failed_with(encoders: FailedEncoders) -> ([bool; 5], u64) {
|
||||
let scratch = Scratch::new("render-fold-failed");
|
||||
let lane = Lane::at_call(&scratch).expect("the device imports host memory");
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let target = lane.target();
|
||||
let outputs: Vec<Buffer> = (0..5).map(|_| lane.zeros(COLOR_WORDS)).collect();
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.dispatch(&command_buffer, &outputs[0]);
|
||||
lane.draw(&command_buffer, &target, LoadAction::DontCare, &lane.colors);
|
||||
lane.dispatch(&command_buffer, &outputs[2]);
|
||||
let fence = lane.device.new_fence();
|
||||
let mut blit = command_buffer.blit_command_encoder().unwrap();
|
||||
blit.fill_buffer(&outputs[3], 0..COLOR_WORDS * 4, 0x5a)
|
||||
.unwrap();
|
||||
blit.update_fence(&fence).unwrap();
|
||||
blit.end_encoding().unwrap();
|
||||
lane.dispatch(&command_buffer, &outputs[4]);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
assert_eq!((moved.folded, moved.begun), (3, 2), "{moved:?}");
|
||||
let failure = CommitFailure {
|
||||
code: 2,
|
||||
encoders,
|
||||
signals: true,
|
||||
};
|
||||
command_buffer.commit_failed(failure).unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.status(), CommandBufferStatus::Error);
|
||||
assert_eq!(
|
||||
command_buffer.error(),
|
||||
Some(CommandBufferError::Injected(2))
|
||||
);
|
||||
let after = lane.device.work_counts();
|
||||
let back = lane.back();
|
||||
let copy = queue.command_buffer().unwrap();
|
||||
lane.copy_back(©, &target, &back);
|
||||
run(©);
|
||||
let ran = |at: usize| match at {
|
||||
1 => wrong_texels(&back) == 0,
|
||||
_ => words_of(&outputs[at]).iter().any(|&word| word != 0),
|
||||
};
|
||||
let reencoded = after.encoders_reencoded - before.encoders_reencoded;
|
||||
([ran(0), ran(1), ran(2), ran(3), ran(4)], reencoded)
|
||||
}
|
||||
|
||||
/// A failed set that names a group's render encoder fails it alone: the group's other three are
|
||||
/// encoded again apart at the commit, and the encoder after it runs.
|
||||
#[test]
|
||||
fn a_failed_render_encoder_inside_a_group_fails_alone() {
|
||||
let set = FailedEncoders::Set(BTreeSet::from([1]));
|
||||
assert_eq!(failed_with(set), ([true, false, true, true, true], 3));
|
||||
}
|
||||
|
||||
/// A failed set that names the compute encoder before a group's render encoder fails it alone:
|
||||
/// the render encoder is encoded again from its log, apart, with the other two.
|
||||
#[test]
|
||||
fn a_failed_encoder_before_a_render_encoder_of_its_group_fails_alone() {
|
||||
let set = FailedEncoders::Set(BTreeSet::from([0]));
|
||||
assert_eq!(failed_with(set), ([false, true, true, true, true], 3));
|
||||
}
|
||||
|
||||
/// A first failed encoder past a group's render encoder fails from there on: the compute and
|
||||
/// render encoders before it are encoded again apart at the commit, and run.
|
||||
#[test]
|
||||
fn a_first_failed_encoder_after_a_render_encoder_runs_it() {
|
||||
let from = FailedEncoders::From(2);
|
||||
assert_eq!(failed_with(from), ([true, true, false, false, false], 2));
|
||||
}
|
||||
|
||||
/// A compute encoder, a render encoder whose pass records at its end and a compute encoder, of
|
||||
/// one group, are three of Metal's submissions (a render pass is one of its own). With a
|
||||
/// submission check that fails the render encoder's, the commit encodes them again apart
|
||||
/// (`State::split_failure`; the pass not where the check failed it first), as the group's
|
||||
/// `VkCommandBuffer` holds commands of each: the pass runs nothing and the dispatches around it
|
||||
/// run, as on Metal; the check sees each submission once.
|
||||
#[test]
|
||||
fn a_check_failing_a_group_s_render_pass_fails_it_alone() {
|
||||
let scratch = Scratch::new("render-fold-checked");
|
||||
let lane = Lane::at_call(&scratch).expect("the device imports host memory");
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let target = lane.target();
|
||||
let outputs: Vec<Buffer> = (0..3).map(|_| lane.zeros(COLOR_WORDS)).collect();
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
lane.dispatch(&command_buffer, &outputs[0]);
|
||||
lane.draw(&command_buffer, &target, LoadAction::DontCare, &lane.colors);
|
||||
lane.dispatch(&command_buffer, &outputs[2]);
|
||||
let moved = Moved::of(&before, &lane.device.work_counts());
|
||||
assert_eq!((moved.folded, moved.begun), (2, 1), "{moved:?}");
|
||||
let seen = Arc::new(Mutex::new(Vec::new()));
|
||||
let noted = Arc::clone(&seen);
|
||||
let check: SubmissionCheck = Arc::new(move |submission: &Submission<'_>| {
|
||||
let kind = submission.kind();
|
||||
noted.lock().unwrap().push((kind, submission.encoders()));
|
||||
(kind == EncoderKind::Render).then(|| NonZeroU64::new(8).unwrap())
|
||||
});
|
||||
command_buffer.set_submission_check(check).unwrap();
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.status(), CommandBufferStatus::Error);
|
||||
assert_eq!(
|
||||
command_buffer.error(),
|
||||
Some(CommandBufferError::Injected(8))
|
||||
);
|
||||
let after = lane.device.work_counts();
|
||||
// The pass's encoding again takes its place too, unless the check, on the scheduler's
|
||||
// thread, failed its submission first (`command_buffer/reencode.rs`, **Split at the commit**).
|
||||
let reencoded = after.encoders_reencoded - before.encoders_reencoded;
|
||||
assert!(matches!(reencoded, 2 | 3), "{reencoded}");
|
||||
assert_eq!(
|
||||
*seen.lock().unwrap(),
|
||||
[
|
||||
(EncoderKind::Compute, 0..1),
|
||||
(EncoderKind::Render, 1..2),
|
||||
(EncoderKind::Compute, 2..3)
|
||||
]
|
||||
);
|
||||
let back = lane.back();
|
||||
let copy = queue.command_buffer().unwrap();
|
||||
lane.copy_back(©, &target, &back);
|
||||
run(©);
|
||||
assert_eq!(
|
||||
wrong_texels(&back),
|
||||
words_of(&back).len(),
|
||||
"the pass drew nothing"
|
||||
);
|
||||
for at in [0, 2] {
|
||||
assert!(
|
||||
words_of(&outputs[at]).iter().any(|&word| word != 0),
|
||||
"the dispatch of encoder {at} ran"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A group of a compute encoder and a render encoder that draws with colors from a buffer over
|
||||
/// host pages, committed behind an event wait only the host signals, the buffer rebound to other
|
||||
/// pages before the signal: the rebind encodes both again (`command_buffer/reencode.rs`, groups
|
||||
/// whole), refusing none, and the draw takes its colors from the new pages.
|
||||
#[test]
|
||||
fn a_rebind_encodes_a_group_with_a_render_encoder_again() {
|
||||
// Declared before the lane, so dropped after it.
|
||||
let pages = [Page::new(), Page::new()];
|
||||
let scratch = Scratch::new("render-fold-rebind");
|
||||
let Some(lane) = Lane::at_call(&scratch) else {
|
||||
return;
|
||||
};
|
||||
let queue = lane.device.new_command_queue().unwrap();
|
||||
let target = lane.target();
|
||||
let words: Vec<u8> = (0..VERTICES)
|
||||
.flat_map(|_| DRAWN)
|
||||
.flat_map(f32::to_le_bytes)
|
||||
.collect();
|
||||
pages[1].write(&words);
|
||||
// SAFETY: each page outlives every buffer over it (dropped after the lane), and only the
|
||||
// buffer's commands use it while it lives.
|
||||
let colors = unsafe {
|
||||
lane.device.new_buffer_with_bytes_no_copy(
|
||||
pages[0].memory(),
|
||||
BYTES as u64,
|
||||
ResourceOptions::shared(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
.unwrap();
|
||||
let written = lane.zeros(COLOR_WORDS);
|
||||
let gate = lane.device.new_shared_event().unwrap();
|
||||
let before = lane.device.work_counts();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
command_buffer
|
||||
.encode_wait_for_event(EventRef::Shared(&gate), 1)
|
||||
.unwrap();
|
||||
lane.dispatch(&command_buffer, &written);
|
||||
lane.draw(&command_buffer, &target, LoadAction::DontCare, &colors);
|
||||
command_buffer.commit().unwrap();
|
||||
assert_eq!(colors.detach_backing(), Ok(true));
|
||||
// SAFETY: as above.
|
||||
unsafe { colors.rebind_bytes_no_copy(pages[1].memory(), None, None) }.unwrap();
|
||||
// Read before the signal: the rebind encodes again in its own call.
|
||||
let after = lane.device.work_counts();
|
||||
gate.set_signaled_value(1);
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(
|
||||
command_buffer.status(),
|
||||
CommandBufferStatus::Completed,
|
||||
"{:?}",
|
||||
command_buffer.error()
|
||||
);
|
||||
let back = lane.back();
|
||||
let copy = queue.command_buffer().unwrap();
|
||||
lane.copy_back(©, &target, &back);
|
||||
run(©);
|
||||
let moved = Moved::of(&before, &after);
|
||||
println!(
|
||||
"RENDER-FOLD-REBIND {moved:?} reencoded {} refused {}",
|
||||
after.encoders_reencoded - before.encoders_reencoded,
|
||||
after.reencodes_refused - before.reencodes_refused
|
||||
);
|
||||
assert_eq!(
|
||||
moved.folded, 1,
|
||||
"the render encoder joined the compute encoder's group"
|
||||
);
|
||||
assert_eq!(
|
||||
(
|
||||
after.encoders_reencoded - before.encoders_reencoded,
|
||||
after.reencodes_refused - before.reencodes_refused
|
||||
),
|
||||
(2, 0),
|
||||
"the rebind encoded both encoders of the group again"
|
||||
);
|
||||
assert_eq!(
|
||||
wrong_texels(&back),
|
||||
0,
|
||||
"the draw took its colors from the new pages"
|
||||
);
|
||||
}
|
||||
@@ -757,6 +757,14 @@ fn corners(i: usize, from: &Buffer) -> (usize, Corners<'_>) {
|
||||
/// the passes before and after them form runs of their own. The texels left are those of a
|
||||
/// private texture whose four passes drew the new rectangle, and the bytes between the rows keep
|
||||
/// theirs.
|
||||
///
|
||||
/// The first pass, which merges in place as its encoder ends, leaves nothing for later, so its
|
||||
/// `VkCommandBuffer` may take the next encoder (`encoder_fold.rs`, **Render encoders**): the
|
||||
/// second pass, which opens the run, joins it where the device records its first instance at its
|
||||
/// end (counted in `encoders_folded`), and its run's merge, left for later, ends the group. A
|
||||
/// rebind encodes a group's encoders again together (`reencode.rs`, **Groups whole**), so it then
|
||||
/// encodes the second pass again too, which leaves its run as the others do. No other pass
|
||||
/// merges in place, so no other group forms.
|
||||
#[test]
|
||||
fn rebound_passes_leave_their_runs() {
|
||||
let (host, moved, moved_to) = (Host::new(ROW * H), Host::new(1 << 16), Host::new(1 << 16));
|
||||
@@ -822,14 +830,24 @@ fn rebound_passes_leave_their_runs() {
|
||||
count.planned,
|
||||
);
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
let grouped = encoded.encoders_folded - before.encoders_folded;
|
||||
assert!(
|
||||
grouped <= 1,
|
||||
"only the second pass joined a group: {grouped}"
|
||||
);
|
||||
assert_eq!(
|
||||
encoded.encoders_reencoded - before.encoders_reencoded,
|
||||
NAMING.len() as u64,
|
||||
"the rebind encodes the passes that bound the buffer again"
|
||||
NAMING.len() as u64 + grouped,
|
||||
"the rebind encodes the passes that bound the buffer again, and the second with the first"
|
||||
);
|
||||
// The first pass's keep and the run's, then each pass encoded again: its own keep, and,
|
||||
// where a later pass went on from it, one after itself.
|
||||
let again: u64 = NAMING.iter().map(|&i| if i == 0 { 1 } else { 2 }).sum();
|
||||
// where a later pass went on from it, one after itself (the second's too, where it joined the
|
||||
// first's group).
|
||||
let again: u64 = NAMING
|
||||
.iter()
|
||||
.map(|&i| if i == 0 { 1 } else { 2 })
|
||||
.sum::<u64>()
|
||||
+ 2 * grouped;
|
||||
assert_eq!(
|
||||
count.kept,
|
||||
(2 + again) * W * H,
|
||||
|
||||
@@ -58,9 +58,9 @@ pub(super) fn tile_state(device: &Device) -> RenderPipelineState {
|
||||
}
|
||||
|
||||
/// The pass's attachments and the fixture's records.
|
||||
struct Targets {
|
||||
colors: [Texture; 3],
|
||||
out: Buffer,
|
||||
pub(super) struct Targets {
|
||||
pub(super) colors: [Texture; 3],
|
||||
pub(super) out: Buffer,
|
||||
}
|
||||
|
||||
/// The value of attachment 0 and attachment 1 at pixel (`x`, `y`) before the pass.
|
||||
@@ -73,7 +73,7 @@ fn v(x: u64, y: u64) -> u32 {
|
||||
}
|
||||
|
||||
impl Targets {
|
||||
fn new(device: &Device) -> Targets {
|
||||
pub(super) fn new(device: &Device) -> Targets {
|
||||
let attachment = |format, texel: &dyn Fn(u64, u64) -> u32| {
|
||||
let [width, height] = AREA;
|
||||
let mut descriptor = TextureDescriptor::texture_2d(format, width, height, false);
|
||||
@@ -103,7 +103,7 @@ impl Targets {
|
||||
|
||||
/// Whether every pixel holds what the fixture's dispatch over every tile stores, as Metal's
|
||||
/// does: `f * 2 + 1`, `v * 3 + k` and its tile's and cell's tag.
|
||||
fn stored(&self) -> bool {
|
||||
pub(super) fn stored(&self) -> bool {
|
||||
let words = |texture: &Texture| {
|
||||
let [width, height] = AREA;
|
||||
let mut bytes = vec![0u8; (width * height * 4) as usize];
|
||||
|
||||
@@ -176,12 +176,17 @@ impl HeldImages {
|
||||
}
|
||||
|
||||
/// The moves of a batch whose encoders, in order, named `encoders`' keys and held the keys
|
||||
/// beside them (`EncoderRecord`): for each encoder, the moves before it, and their uses.
|
||||
/// Nothing is allocated where the batch moves nothing, and nothing is looked at where the
|
||||
/// device holds no image.
|
||||
/// beside them (`EncoderRecord`), each with the place of the encoder its moves go before, its
|
||||
/// own or an earlier one's: for each encoder, the moves before it, and their uses. An encoder
|
||||
/// whose commands a group of encoders' shared `VkCommandBuffer` holds (`encoder_fold.rs`) has
|
||||
/// its moves go before the group's first, where that `VkCommandBuffer` begins: no member of a
|
||||
/// group holds an image (a render encoder whose depth attachment the device holds takes no
|
||||
/// group), so each needs every image it names in `GENERAL`, which a move before the group
|
||||
/// leaves it in for all of them. Nothing is allocated where the batch moves nothing, and
|
||||
/// nothing is looked at where the device holds no image.
|
||||
pub(crate) fn moves<'a>(
|
||||
&self,
|
||||
encoders: impl ExactSizeIterator<Item = (&'a BTreeSet<ResourceKey>, &'a [ResourceKey])>,
|
||||
encoders: impl ExactSizeIterator<Item = (usize, &'a BTreeSet<ResourceKey>, &'a [ResourceKey])>,
|
||||
) -> BatchMoves {
|
||||
let count = encoders.len();
|
||||
let mut moves = BatchMoves::none();
|
||||
@@ -190,7 +195,7 @@ impl HeldImages {
|
||||
}
|
||||
let images: Vec<Arc<HeldImage>> = self.lock().values().cloned().collect();
|
||||
let mut layouts: Vec<ImageLayout> = images.iter().map(|image| image.current()).collect();
|
||||
for (at, (named, held)) in encoders.enumerate() {
|
||||
for (at, named, held) in encoders {
|
||||
for (index, image) in images.iter().enumerate() {
|
||||
if !named.contains(&image.key) && !held.contains(&image.key) {
|
||||
continue;
|
||||
|
||||
@@ -135,9 +135,10 @@ pub(super) struct EncoderRecord {
|
||||
pub(super) unlogged: Option<crate::command_buffer::rebound_use::Unlogged>,
|
||||
/// Why a rebind's encoding of it again was refused (`command_buffer/reencode.rs`).
|
||||
pub(super) refused: Option<String>,
|
||||
/// The places of the compute encoders whose commands one `VkCommandBuffer` holds with its
|
||||
/// own, where it is one of more (`encoder_fold.rs`): a failure fails them together, and a
|
||||
/// rebind encodes them again together.
|
||||
/// The places of the encoders whose commands one `VkCommandBuffer` holds with its own, where
|
||||
/// it is one of more (`encoder_fold.rs`): a failure fails them together, a rebind encodes
|
||||
/// them again together, and the held depths' moves go before the first
|
||||
/// (`encoder_fold::GroupPlaces`).
|
||||
pub(super) group: Option<std::ops::Range<usize>>,
|
||||
/// Whether its commands lie in that `VkCommandBuffer`, some or all: the group's first
|
||||
/// encoder's do, and a later one's where a command of its recorded there before it went on
|
||||
|
||||
@@ -3680,7 +3680,8 @@ impl Counters {
|
||||
|
||||
/// A command of an encoder Metal orders (a blit encoder, a serial compute encoder) was
|
||||
/// recorded after a barrier for the encoder's earlier commands (`tracker::EncoderUses`), or a
|
||||
/// compute encoder's after one for the earlier encoders of its group (`encoder_fold.rs`).
|
||||
/// compute, blit or render encoder's after one for the earlier encoders of its group
|
||||
/// (`encoder_fold.rs`).
|
||||
pub(crate) fn command_barrier(&self) {
|
||||
self.command_barriers.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
@@ -3692,8 +3693,8 @@ impl Counters {
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// A compute or blit encoder joined the group of compute and blit encoders before it,
|
||||
/// recording into their `VkCommandBuffer` (`encoder_fold.rs`).
|
||||
/// A compute, blit or render encoder joined the group of encoders before it, recording into
|
||||
/// their `VkCommandBuffer` (`encoder_fold.rs`).
|
||||
pub(crate) fn encoder_folded(&self) {
|
||||
self.encoders_folded.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
@@ -7106,13 +7107,14 @@ pub struct WorkCounts {
|
||||
/// their barriers. Such a barrier orders every command of the encoder after every command
|
||||
/// before it, where Metal orders only those whose resources meet.
|
||||
pub encoders_barriered_at_open: u64,
|
||||
/// Compute and blit encoders that began no `VkCommandBuffer` of their own: each recorded into
|
||||
/// the one of the compute and blit encoders before it in its command buffer, where nothing
|
||||
/// Compute, blit and render encoders that began no `VkCommandBuffer` of their own: each
|
||||
/// recorded into the one of the encoders before it in its command buffer, where nothing
|
||||
/// between them needs a boundary (the same batch, a compute encoder's dispatch type that of
|
||||
/// the group's compute encoders, no work left for later, no fence update, nothing failing),
|
||||
/// after the barrier the tracker plans between two encoders of a batch, and its batch's
|
||||
/// submission submits no command buffer for it, of barriers or of its own. Of
|
||||
/// `encoder_command_buffers_begun`'s encoders, those it does not count.
|
||||
/// the group's compute encoders, no work left for later, no fence update, nothing failing; a
|
||||
/// render encoder's pass recorded at its end, with a log of its calls), after the barrier the
|
||||
/// tracker plans between two encoders of a batch, and its batch's submission submits no
|
||||
/// command buffer for it, of barriers or of its own. Of `encoder_command_buffers_begun`'s
|
||||
/// encoders, those it does not count.
|
||||
pub encoders_folded: u64,
|
||||
/// Of `command_buffers_begun`, the device's own submissions' and staging submissions'.
|
||||
pub command_buffers_begun_internal: u64,
|
||||
@@ -7616,7 +7618,8 @@ pub struct WorkCounts {
|
||||
pub prefixed_starts: u64,
|
||||
/// Barriers recorded before a command of an encoder Metal orders (a blit encoder, a serial
|
||||
/// compute encoder) for the encoder's earlier commands (`tracker::EncoderUses`), or of a
|
||||
/// compute encoder for the earlier encoders of the group it joined (`encoder_fold.rs`): on
|
||||
/// compute, blit or render encoder for the earlier encoders of the group it joined (a render
|
||||
/// encoder's one, from everything of theirs, before its first command; `encoder_fold.rs`): on
|
||||
/// MoltenVK each ends the Metal encoder, and the next waits for the one before (`tracker.rs`,
|
||||
/// **Inside an encoder**, orders a blit's untracked uses by key and range).
|
||||
pub command_barriers: u64,
|
||||
@@ -10604,8 +10607,9 @@ pub struct WorkCounts {
|
||||
pub attached_read_unswapped_texels_pass: u64,
|
||||
/// The texels the copies of `attached_read_unswapped_split` moved.
|
||||
pub attached_read_unswapped_texels_split: u64,
|
||||
/// Ended compute and blit encoders whose logs their command buffers kept, as a rebind before
|
||||
/// the first submission may encode them again (`replay.rs`), and the bytes of those logs.
|
||||
/// Ended compute, blit and render encoders whose logs their command buffers kept, as a rebind
|
||||
/// before the first submission may encode them again (`replay.rs`), and the bytes of those
|
||||
/// logs.
|
||||
pub replay_logs_kept: u64,
|
||||
/// The bytes of the logs counted in `replay_logs_kept`.
|
||||
pub replay_log_bytes: u64,
|
||||
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 522;
|
||||
/// 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 = 2301;
|
||||
pub const RUNTIME_VERSION: u32 = 2302;
|
||||
|
||||
/// 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
|
||||
|
||||
+14
-9
@@ -2104,7 +2104,7 @@ program called, its total and share, and its time per encoder at the median and
|
||||
logs one line per command buffer whose GPU time is `N` ms or more, 1024 at most: each encoder's
|
||||
place, kind, states, dispatches and draws, offset from the command buffer's GPU start and time. An
|
||||
encoder whose recording ran nothing reads no time and counts as not timed: one encoded again (a
|
||||
rebind, a failure that splits a group of compute and blit encoders), one left out by command predication or
|
||||
rebind, a failure that splits a group of encoders recorded together), one left out by command predication or
|
||||
failed, and one that ended inside a predicated loop. An encoder whose parts went in submissions
|
||||
apart, with a host step between them, counts the time between them. It does nothing on a device
|
||||
whose queue family writes no timestamps, one the runtime adopted (it resets query pools on the
|
||||
@@ -5442,14 +5442,19 @@ each item named states the rule in full.
|
||||
|
||||
**A command buffer committed as failed** (`CommandBuffer::commit_failed`)
|
||||
|
||||
- **A failure inside a group of compute and blit encoders whose unit of command predication laid
|
||||
a loop or left work out fails the whole group.** The runtime records a compute or blit encoder
|
||||
into the `VkCommandBuffer` of the compute or blit encoder before it where nothing needs a
|
||||
boundary between them: a compute encoder's dispatch type that of the group's compute encoders,
|
||||
the same batch (no event wait or signal between them), no fence update or work left for later in
|
||||
the earlier one, nor a write into an ASTC texture or a write of a new texture whole before any
|
||||
read, no command predication yet, the encoder trail off (`DeviceOptions::encoder_trail`) and
|
||||
protection options 0 (`WorkCounts::encoders_folded` counts each). A failure that fails some of
|
||||
- **A failure inside a group of encoders recorded together whose unit of command predication
|
||||
laid a loop or left work out fails the whole group.** The runtime records a compute or blit
|
||||
encoder into the `VkCommandBuffer` of the compute, blit or render encoder before it where
|
||||
nothing needs a boundary between them: a compute encoder's dispatch type that of the group's
|
||||
compute encoders, the same batch (no event wait or signal between them), no fence update or work
|
||||
left for later in the earlier one, nor a write into an ASTC texture or a write of a new texture
|
||||
whole before any read, no command predication yet, the encoder trail off
|
||||
(`DeviceOptions::encoder_trail`) and protection options 0 (`WorkCounts::encoders_folded` counts
|
||||
each). It records a render encoder there too where it logs its calls (the device has a buffer
|
||||
over host pages), its pass is of one color group, over no rasterization-rate map, with no depth
|
||||
attachment the device holds between passes, and records at the encoder's end (its draws in a
|
||||
secondary command buffer); one whose first instance records inline begins such a group but
|
||||
joins none. A failure that fails some of
|
||||
such a group's encoders and not the others (a `FailedEncoders::From(n)` whose `n` lies inside
|
||||
it, a `FailedEncoders::Set` that names some of them, a fault or a recording failure at one)
|
||||
splits it at the commit: the encoders that run are recorded again from their logs, each into
|
||||
|
||||
+18
-17
@@ -1235,8 +1235,8 @@ driver's. Each is open work.
|
||||
compute encoder its unit of command predication reaches past, which is one whose unit laid a
|
||||
step before it opened or one of its own that the unit's later encoders read, and one whose unit
|
||||
laid a loop or left work out; work on the GPU alone) fail `EncodedUseRebound` (announced).
|
||||
- **A failure inside a group of compute and blit encoders recorded together, whose unit of
|
||||
command predication laid a loop or left work out, fails the whole group** (`encoder_fold.rs`,
|
||||
- **A failure inside a group of encoders recorded together, whose unit of command predication
|
||||
laid a loop or left work out, fails the whole group** (`encoder_fold.rs`,
|
||||
`command_buffer/fold.rs`'s `State::split_failure`). A `CommandBuffer::commit_failed` whose
|
||||
`FailedEncoders::From(n)` lies inside such a group, or whose `FailedEncoders::Set` names some of
|
||||
its encoders, splits the group at the commit and records its running encoders again from their
|
||||
@@ -1246,17 +1246,17 @@ driver's. Each is open work.
|
||||
encoders of one dispatch type it lies in, `predication.rs`) called `encode_start_while` or
|
||||
`encode_start_do_while`, or left a record unbalanced, that encoder cannot be recorded again
|
||||
outside the unit's blocks, so the group runs nothing, where Metal runs its encoders the failure
|
||||
does not name. A blit encoder belongs to no unit and is always recorded again. So does a
|
||||
submission check (`CommandBuffer::set_submission_check`) that fails one of Metal's submissions
|
||||
of such a group (a blit encoder's and a compute encoder's are two): the commit of a command
|
||||
buffer with a check records the encoders whose commands the group's shared `VkCommandBuffer`
|
||||
holds again apart where they lie in more than one submission, and where it cannot (one keeps no
|
||||
log, or its work runs in a segment), a check that fails one of those submissions fails each of
|
||||
them, where Metal runs the others. A rebind that moves a buffer such a group named,
|
||||
where its encoder that cannot be recorded again lies in a submission that still runs, records
|
||||
none of the group again, and its moved encoders fail `EncodedUseRebound` where Metal runs them
|
||||
over the new pages; where every such encoder's submission fails rebound anyway, the group's
|
||||
other encoders are recorded again apart and run.
|
||||
does not name. A blit or render encoder belongs to no unit and is always recorded again. So does
|
||||
a submission check (`CommandBuffer::set_submission_check`) that fails one of Metal's submissions
|
||||
of such a group (a blit encoder's and a compute encoder's are two, and a render pass is one of
|
||||
its own): the commit of a command buffer with a check records the encoders whose commands the
|
||||
group's shared `VkCommandBuffer` holds again apart where they lie in more than one submission,
|
||||
and where it cannot (one keeps no log, or its work runs in a segment), a check that fails one of
|
||||
those submissions fails each of them, where Metal runs the others. A rebind that moves a buffer
|
||||
such a group named, where its encoder that cannot be recorded again lies in a submission that
|
||||
still runs, records none of the group again, and its moved encoders fail `EncodedUseRebound`
|
||||
where Metal runs them over the new pages; where every such encoder's submission fails rebound
|
||||
anyway, the group's other encoders are recorded again apart and run.
|
||||
- **A copied rebind under a texture in place, where the device's check did not pass fresh pages
|
||||
and its own linear image lies at another pitch, is refused** (`NotImplemented(RebindTextures)`).
|
||||
A rebind whose pages the gate refuses, or whose bytes moved in their page, copies them, and the
|
||||
@@ -2365,10 +2365,11 @@ compares with Metal's.
|
||||
`DontCare`, a multisampled, layered or resolved pass, and the other kinds
|
||||
`WorkCounts::passes_not_inline_*` count). A batch begins one more before each of the first
|
||||
2,048 encoders of its command buffer that needs a barrier, and none past them (`encoder.rs`,
|
||||
`WorkCounts::encoders_barriered_at_open`); a compute or blit encoder recorded into the
|
||||
`VkCommandBuffer` of the compute and blit encoders before it takes none (`encoder_fold.rs`,
|
||||
`WorkCounts::encoders_folded`). On ms01's Iris Xe one command buffer of 10,000 render
|
||||
passes, each a draw beside a cleared depth target, runs in 12,049 command buffers
|
||||
`WorkCounts::encoders_barriered_at_open`); a compute, blit or render encoder recorded into
|
||||
the `VkCommandBuffer` of the encoders before it takes none, a render encoder's draws in a
|
||||
secondary still taking theirs (`encoder_fold.rs`, `WorkCounts::encoders_folded`). On ms01's
|
||||
Iris Xe one command buffer of 10,000 render passes, each a draw beside a cleared depth target,
|
||||
runs in 12,049 command buffers
|
||||
(`tests::many_passes`); one of such passes recorded inline encoded 16,173 and refused to open
|
||||
the next, and one of passes that take a secondary failed at the end of its 8,087th, the
|
||||
spares holding 424 command buffers. A command buffer of passes recorded inline, its targets'
|
||||
|
||||
Reference in new issue
Block a user