Runtime: the queue cut comes off again

Reverts, in one commit, the nineteen commits of c38852d665..c2088436aa
that carry the queue cut and its order fixes (newest first): 333adf36cf
8828e8ad6c daaccb7bb0 4f683ad891 7cd99ae0b1 5f93a64342 6523e2b65c
76f369dbbf 2bcac43a53 c5e98be51d 635da9d820 1f7f77e4cc 4b1cdaf505
9e8baebc48 b1b375b8e1 40a9982a94 02923fb2ae ec24ba8439 69754cb203.
piece.rs and its tests go, and the README rows on the pieces' cost.

Kept: 6adfe028d8 (a half vector joined from read lanes keeps its bits),
7d8aabed34 and c2088436aa (the 780M import-cost rows). Against
c38852d665 the tree differs only by those three commits' paths and
changes. The cut bumped no version, so none moves here.

Why: the fallback for the Iris Xe regression under the planner's 18:00
PST box. The guest's image step reads take-to-show p90 17.16 ms cold and
24.66 ms warm (Iris Xe, the consumer's walks, job 67930) against 4.34 and
4.42 ms before. The cut, with no green fix tip by the box, comes off with
the one-module move that caused it; the cut continues on its own branch.
This commit is contained in:
Anees Iqbal committed 2026-11-22 16:25:58 -08:00
1 parent c2088436aa
commit e3a3f5c7dc
23 files changed
+170 -2145

No files matched your search

+28 -170
View File
@@ -1880,110 +1880,48 @@ made, with no lock, and never rewritten for layouts.
each upload that holds a released object. `Metrics::held_releases` and `held_release_bytes`
count every release they held, and `held_release_starts` those that were the first since they
came to hold the object, each a submission it started. While
the device has room on its `VkQueue`, a command buffer goes at once, alone. It has room while
fewer than two of its submissions, of every queue, are not yet seen complete, and while fewer
than three are whose expected GPU runs (below) behind the oldest, with the next's, sum to 4 ms
or less; a run not yet known counts as past 4 ms. So while a queue's run is not yet known (none
of its command buffers has retired with its GPU times), its command buffer goes only where fewer
than two submissions are on the device. The device keeps on the `VkQueue` no more than about
4 ms of work behind what runs, and one behind it always, whatever the queues, and a command
buffer committed later waits behind no more of it: behind a running piece of at most 4 ms
(below), such a wait stays within 16 ms. The room goes first to the queue that waited longest: by
its turn, its last submission, or none where its command buffer was committed with nothing of
its queue queued or in flight, then in commit order. So a command buffer of an idle queue goes
at the device's next room, behind what runs and the one behind it, ahead of every queue's
backlog, and a backlog whose last piece just completed passes no queue idle longer. A queue's
backlog waits for as long as other queues that commit only when idle keep the device's room
taken: Metal promises no order between queues, and the runtime keeps no aging rule for it.
Where one queue keeps 20 ms command buffers in flight, each signalling a waiter committed to
another queue, that waiter takes a place in the room, so the long queue's next starts one
completion round trip after the one before it ends: its GPU idle before each grew to about
0.45 ms on the RX 7900 XTX (job m3-max-68440) and the Iris Xe (job m3-max-68441) and 0.6 ms on
an RTX 3090 (job m3-max-68465), its GPU time a command buffer by 1.0%, 1.4% and 2.5% (by 0.3%,
0.9% and 1.1% where the other queue's command buffers wait for nothing).
Without room, the ones committed meanwhile are held
a queue has room on the device's `VkQueue`, each of its command buffers goes at once, alone. It
has room while fewer than two of its submissions are not yet seen complete, and while fewer than
three are whose expected GPU runs (below) behind the oldest, with the next's, sum to 16 ms or
less; a run not yet known counts as past 16 ms. So a queue whose run is not yet known (none of
its command buffers has retired with its GPU times) has room for two submissions, and its third
command buffer waits for one seen complete. A queue keeps on the `VkQueue` no more than about 16
ms of work behind what runs, and one behind it always, and a command buffer of another queue
committed later waits behind no more of it. Without room, the ones committed meanwhile are held
in one group of at most sixteen, each scheduled as it joins; one the group does not take is held
too, not yet in a group, scheduled as it would be in one (its waits met, in its queue's order,
its scheduled handlers run: `Metrics::held_for_room`), and so are its queue's later command
buffers. The held work goes when a completion leaves room (the completion thread wakes the
submit thread as it retires; no commit or
wait is needed), when the host is to wait for one of them (`wait_until_completed`, or
`CommandQueue::send_now`, the hint for a wait the runtime does not see), or at teardown. No
command buffer goes past one of another queue committed before it, to a queue with nothing
queued or running, not yet submitted, with a part ready, that holds a buffer or texture it holds
(or where either reaches memory outside its resources), whether the device's room or a host
wait would send it: until that one is submitted it is not staged, and its queue neither wants
nor takes the room, whose order then sends that one first, as Metal submitted that one at its
commit and orders it after (job m3-max-68673). So where that one waits behind a cut command
buffer it shares with (below), a later sharer of a third queue waits behind both; without the
rule it went between the cut one's pieces and read the buffer before that one wrote it (on
lavapipe, job m3-max-68970). A group is asked by its first command buffer, and those that joined
it go with it. Two readers of one resource share it here too: an over-hold. Waiting
`CommandQueue::send_now`, the hint for a wait the runtime does not see), or at teardown. Waiting
for a place in the queue sends nothing. A segment that signals an event ends its group, which goes
at once as it is staged, and so does a presenting command buffer's last (see "Presenting"); so a
command buffer that signals an event, in any segment, is staged only once the device has room
for it, as one held for room behind it is, and a wait for its signal waits with it, while a
presenting one has its queue go at once, through to it, and so does one with nothing for the
GPU or one ended before it went, except behind a cut command buffer, whose pieces go at the
room's pace: such a one goes after its last piece, as the room comes, and a cut one that
presents waits for room at each piece as any cut one does. So of a chain of command buffers, each
waiting for the signal of the one before it, the links past the device's room go as earlier
ones complete. The
command buffer that signals an event, in any segment, is staged only once its queue has room for
it, as one held for room behind it is, and a wait for its signal waits with it, while a
presenting one has its queue go at once, through to it. The
driver runs a submission's command buffers as one kernel job, which a job timeout ends as a whole
(Linux's amdgpu ends a job past its timeout and resets the ring), so a group is bounded by its
expected GPU run: a queue's expected run follows its command buffers'
own GPU times as each retires (a longer one raises it at once, a shorter one halves the way toward
it), and a command buffer joins a group only while the group's expected runs, summed, stay within
4 ms. One whose queue has no run yet, or that would take the sum past the bound, goes alone, the
16 ms. One whose queue has no run yet, or that would take the sum past the bound, goes alone, the
group held going first. The bound is tested again as the group goes, with the expected run as it
then stands: a group past it goes member by member, one `vkQueueSubmit2` each, only the last
signalling. At most four command buffers join a group while none of the queue's retires, since
they join on an expected run no completion has updated: in
a replay stream on an RTX 3090, the most GPU time over four consecutive command buffers of a queue
was 385.1 ms, within a quarter of amdgpu's default job timeout of 2,000 ms, and over sixteen
1,536.6 ms. A command buffer's compute work goes to the `VkQueue` in pieces, each one
submission that waits for the device's room as a command buffer does: the runtime cuts it
before a compute dispatch that would take the piece's expected GPU run past 4 ms, between the
dispatches of a kernel with no measured rate yet, which share a piece of their own, and any
other, and where a compute or blit encoder opens after a full piece, never before or inside a
render pass (`Metrics::cuts`). A dispatch's expected run is its kernel's rate, the GPU run of
one threadgroup as the pieces that ran the kernel measured it, times its threadgroups; an
indirect dispatch, whose threadgroups only the GPU reads, counts as one. A command buffer of
one segment (not cut, and not split at an event) is one piece, timed by its own two timestamps,
which hold no other submission's run, and writes no other; the first piece of several runs from
the command buffer's start to a timestamp at the piece's end; each other piece, and a first
whose dispatches follow a blit or render encoder's commands, is timed by two timestamps of its
own. So a
command buffer of another queue committed while one runs goes between two of its pieces
(`Metrics::pieces_passed`), unless it holds a buffer or texture the cut one holds (by the ids
the hazards track them by, a heap's resources by the heap's), waits on a fence the cut one
updates, or either reaches memory outside its resources: then it goes after the last piece
(`Metrics::shared_holds`), held only while the cut one's next piece is ready; where that piece
waits for an event not yet met, it goes, as Metal's wait stops only its own queue, and the
signal may come from the queue it holds. Across queues, a command buffer that shares a tracked
resource with an earlier-committed one of another queue goes after it only once that one is
submitted, as Metal's hazard tracking orders such a pair against work already submitted, and no
more (the M3 Max rows below, jobs m3-max-52432 and m3-max-52415); a cut command buffer that has
begun counts as submitted until its next piece waits for an event. An event wait holds only its
own queue. A command buffer that waits on a fence goes after each command buffer of another
queue that updates it and is held in a group or for room, and after every ready piece of a cut
one; Metal's side of that is measured only by the probe under `Fence` below (jobs m3-max-52186
and m3-max-52188). Two readers of one
resource share it here, so a read waits behind a cut command buffer that only reads what it
reads, though no write orders them: an over-hold. The cut command buffer is scheduled as its first piece is submitted,
where none of its later pieces waits for an event, and its GPU times run from its first piece's
start to its last piece's end, the runs of what went between its pieces included, as on the UHD
630 under macOS 26.7.1 a running command buffer's end moved by the run of one that started
beside it (job m3-max-68129). The thread holds a segment whose event waits are not met, and its queue's later
1,536.6 ms. The thread holds a segment whose event waits are not met, and its queue's later
command buffers behind it, while the segments before it run, so the host can see a signal the
command buffer makes before its wait. Other queues go on. Each queue groups on its own count:
a command buffer of a queue with nothing queued or running is submitted at the device's next
room, ahead of every command buffer committed after it on any queue, its part before an event
wait included (of the groups that go at once, the one committed first goes first: on an M3
Max, a copy on another queue, committed after a command buffer that fills, waits for the event
the copy then signals, and fills again, read the first fill and not the second, job
m3-max-68673), while one its queue holds, in a group or for room, may
be passed by another queue's command buffer committed after it, which only a fence or an event
a command buffer of a queue with nothing running is submitted at once, ahead of every command
buffer committed after it on any queue, its part before an event wait included (of the groups
that go at once, the one committed first goes first: on an M3 Max, a copy on another queue,
committed after a command buffer that fills, waits for the event the copy then signals, and
fills again, read the first fill and not the second, job m3-max-68673), while one its queue
holds, in a group or for room, may be passed by another queue's command buffer committed after
it, which only a fence or an event
then orders after it. Metal's hazard tracking orders such a pair against work already submitted, and no
more. Recorded on an M3 Max with macOS 27.0.1, with tracked buffers and no fence, a blit fill on
one queue and a copy of what it filled on another, committed after it, five runs each: where the
@@ -2062,8 +2000,8 @@ made, with no lock, and never rewritten for layouts.
`CommandQueue::command_buffer` on a queue whose maximum count are made and not yet completed,
which a scheduled handler answers the same way. No wait of the runtime's hangs by construction.
A command buffer of a group is seen complete with the group's last: up to the GPU time of the
fifteen after it late. Only a queue that finds the device without room holds a group; one that
finds room sends its next command buffer alone. Without a wait or a hint, the lateness is bounded only while the queue has no room,
fifteen after it late. Only a queue without room holds a group; one whose
submissions have completed sends its next command buffer alone. Without a wait or a hint, the lateness is bounded only while the queue has no room,
and the completion that leaves room sends the group (the measured lateness is under
"Known gaps"). A command buffer ended while its queue holds a group joins it, and retires in its
place; the group goes at once.
@@ -2131,8 +2069,8 @@ made, with no lock, and never rewritten for layouts.
buffers). A waiter with nothing for the GPU (an encoder that only waits) completes no sooner
than the last submission that updates its fence, as Metal's does (job m3-max-52194); its GPU
times are one time, as for any command buffer with nothing for the GPU, where Metal reports a
span over the update's run. Work with no fence or event between it is ordered only as the
queue rule above says.
span over the update's run. Work with no fence between it is ordered as well, where Metal may
run it at once.
- `CommandQueue::abandon` ends every command buffer of the queue held at an event wait or not yet
scheduled with `NotRun` and runs its handlers, as a Mac drops a dead process's held work, each
retiring in the queue's order. Segments already submitted still complete, and so does a group
@@ -2185,11 +2123,6 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
### Known gaps
- A program that relies on commit order between queues for a shared resource, with no event or
fence, can read the earlier contents on the runtime, where a Mac's timing usually hides it: work
held behind its own queue's can go to the device after another queue's later command buffer.
That is Metal's rule (the M3 Max rows in the queue rule above, jobs m3-max-52432 and
m3-max-52415).
- A lost device is not recovered. After a loss, the device and everything made on it stay dead:
its buffers, textures, heaps, pipeline states, queues and events, and every device address and
resource ID it handed out. Every later commit ends `DeviceLost`. The consumer may make a new device
@@ -2225,89 +2158,14 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
The call's time grows with the new block it is the first to use: 2.1 and 2.5 ms with a 1 MiB
block, 9.1 ms with 64 MiB and 28.4 ms with 256 MiB (job m3-max-52745); the probe's later
submissions spent at most 0.18 ms each.
- A command buffer of another queue waits for the whole of what the pieces do not cut: a
dispatch whose own expected run passes 4 ms, a render pass and the encoders after it, the
dispatches of a kernel whose rate is not yet measured, and the commands of a piece that writes
a Managed buffer or while copies over a texture are owed. It waits behind every piece of a cut
command buffer that holds one of its buffers or textures, a read of a read included, except
while that command buffer's next piece waits for an event. Metal
starts it beside the running command buffer: on a Radeon Pro 5300M another queue's command
buffer started 0.21 to 0.40 ms after its commit beside a running one (job m3-max-68137), and on
an Intel UHD 630 under macOS 26.7.1 one of a queue at a lower priority number started about
0.4 ms after its commit, mid-way through a running 60 ms command buffer, whose own run did not
change (job m3-max-68129). The runtime starts it at the next piece's boundary.
- The pieces cost host instructions on every command buffer, cut or not. Measured with the
compute harness on an RTX 3090 against the runtime with no pieces (f979769faf; the build with
them, fa77a9035b, also fetches a kernel's stage input, a change to pipeline creation and to no
encoder's path), four runs of each build in random order (job m3-max-68794), the thread that
encodes and commits ran 1,239 more instructions a command buffer in `burst_2000` (2.5%; all
threads together ran 513 fewer), 1,609 in `burst_160` (3.5%), 1,633 in `burst_160_shared`
(2.7%), 1,843 in `frame_5cb` (2.8%) and 4,566 in `burst_2000x5` (4.4%), whose command buffers
open five compute encoders of one dispatch each: about 830 more for each encoder past the
first. The rows of one command buffer a run (`waves`, `constant_private` and the two
`sampling_distinct` rows) ran 952 to 1,166 more.
On an RX 7900 XTX (job m3-max-68607) the rise was 964 in `burst_2000` and 883 in `burst_160`;
with parts of the path put back to their form with no pieces (the step's scan for shared
resources, the room's ranking of what is ready, the scan as a group closes, the cut test where
an encoder opens, the rate kept for each segment as it retires), one or a few at a time, it was
848 to 1,014 and 550 to 745, and with all of them 710 and 465: the cost is spread over the
path, in no one part of it. On the 3090 no row's time moved by 3% or more beyond its runs'
spread: `burst_160`, `burst_160_shared`, `burst_2000`, `burst_2000x5` and
`frame_5cb_from_idle` moved 0.2% or less, `bind_2000` 2.6% and `waves` 2.9%; the runs of
`frame_5cb`, `waves`, `constant_private` and the two `sampling_distinct` rows spread past 3%
within one build, so those rows decide nothing.
- Each piece is a submission of its own, and the host pays a `vkQueueSubmit2` call's price on
the driver for every piece. A guest's compute benchmark over its 371 s timed pass on an Iris Xe
(ANV, Mesa 26.2.6), with the pieces (f21db0934c) against the runtime with no pieces
(f979769faf), one timed pass each (jobs m3-max-68858 and m3-max-68837): 63,704 submissions
against 18,764 (3.4 times), 47.1 s against 15.3 s inside the calls
(`Metrics::submit_call_nanos`; about 0.74 ms a call with the pieces), and 49.1 s against
15.8 s of the submit thread's CPU time. The GPU's busy time was the same (235.7 s against
234.3 s), and so was the score (8,069 against 8,098, 0.36% lower). On an RTX 3090 (NVIDIA
620.70.06), two runs of each build alternated, the same guest made 14% to 15% more submissions
with the pieces (23,670 and 23,489 against 20,750 and 20,406) and spent 912 and 923 ms against
606 and 666 ms inside the calls; the score did not move beyond the base runs' own spread
(80,706 and 80,730 with the pieces, 75,949 and 80,946 without; jobs m3-max-68865,
m3-max-68889, m3-max-68789 and m3-max-68954).
- On an RX 7900 XTX (RADV, Mesa 26.2.6) the same guest's compute benchmark scores 3.7% lower
on the mean with the pieces (118,115 against 122,618 over eight runs), and the cause is not
found. Two pairs were alternated in each of two builds:
- with the pieces at f21db0934c, against the runtime with no pieces at f979769faf: 115,608
and 121,011 against 121,802 and 124,665 (jobs m3-max-68746, m3-max-68756, m3-max-68738 and
m3-max-68783);
- with the pieces at fa77a9035b plus counters, against 2953064a1c: 118,494 and 117,345 against
124,568 and 119,436 (jobs m3-max-68959, m3-max-68974, m3-max-68955 and m3-max-68969). Every
run with the pieces scored under every run without, and the means are 3.35% apart, where the
runs without spread 4.1% and those with 1.0%.
What was read over the last pair:
- The submissions, the held starts, the GPU's busy time and the pass's wall time are level. The
time inside the calls is 84 ms more over a 118 s pass.
- One of the guest's workloads takes more GPU time in every run with the pieces than in every
run without: 7.0% more in the last pair, and 10.5% over all eight runs. That workload is cut 1
to 6 times a run, with 0 to 2 command buffers held for room.
- The other workloads' GPU times are mixed.
The pieces are kept. On the Iris Xe, the slowest card tested, they bring the image step's
frames over 16.7 ms from 6 and 17 to 0 warm, and from 7 to 2 cold. Its benchmark score and the
RTX 3090's are level.
- On the Iris Xe (Mesa's ANV), in the harness row `two_queues`, a command buffer of a second
queue whose event wait the end of a command buffer of the first queue signals, committed right
after it, starts on the GPU 30.4 µs after the signaller's GPU end at the median, against 9.0 µs
with no pieces (jobs m3-max-68441, m3-max-68517, m3-max-68545 and m3-max-68608). Where the
waiter waits is not placed. In the same row, a command buffer of the second queue committed
every 16.667 ms beside the first queue's backlog of eight (three fills each, 22.5 ms on the GPU
at the median) completes 23.7 ms after its commit at the median, against 34.8 ms with no pieces
(jobs m3-max-68545 and m3-max-68608), and no other form that keeps Metal's order was found to
bring those late frames in.
- On NVIDIA each submission pays the driver's latency per submission. The runtime submits each
command buffer as soon as it can, so short command buffers committed back to back reach the GPU
in several submissions: on an RTX 2080 (harness row `frame_5cb`: five short command buffers a
run, two runs in flight) a run takes about 2.5 submissions, and each submission boundary leaves
the GPU idle for about 20-25 µs.
- One dispatch, render pass or blit encoder whose own GPU run passes the driver's job timeout
still ends there: the runtime cuts a command buffer's compute work only between dispatches and
where an encoder opens (the pieces above), and joins none to it (the grouping bound above). Linux's amdgpu ends a job past its timeout, 2 s by default (Linux 7.3.3),
- One command buffer whose own GPU run passes the driver's job timeout still ends there: the
runtime does not cut a command buffer's work into shorter jobs, and joins none to it (the
grouping bound above). Linux's amdgpu ends a job past its timeout, 2 s by default (Linux 7.3.3),
and resets the ring, where Metal runs the command buffer within its own watchdog's longer bound.
- A command buffer whose timestamps are not available when its submission signals reports no GPU
times: its `gpu_start_time` and `gpu_end_time` are 0, and `Metrics::stamps_not_available`
+1 -1
View File
@@ -137,7 +137,7 @@ impl CommandBuffer {
/// Err: [`Refusal::Committed`]; [`Refusal::EncoderOpen`] while another encoder of the command
/// buffer is open.
pub fn blit_command_encoder(&self) -> Result<BlitCommandEncoder, Error> {
let mut building = self.open_encoder(true, false)?;
let mut building = self.open_encoder()?;
building.count(Metric::Passes);
Ok(BlitCommandEncoder {
command_buffer: self.clone(),
+15 -207
View File
@@ -13,8 +13,7 @@ use crate::hazard::{Access, Hazards};
use crate::kept::{Lent, Objects};
use crate::memory::Block;
use crate::over::{self, Overs, Reached};
use crate::piece::{Kernels, Work};
use crate::pipeline::{Compiled, ComputePipelineState};
use crate::pipeline::ComputePipelineState;
use crate::queue::QueueInner;
use crate::record::{self, Reach, Recorder};
use crate::render::RenderPipelineState;
@@ -35,14 +34,7 @@ use std::sync::{Arc, Condvar, Mutex, MutexGuard, PoisonError};
/// operations between them. The submit thread holds a segment whose waits are not yet met, and its
/// queue's later command buffers behind it, while the segments before it run: an event the held
/// part waits for can be signalled by the part before it. Each segment's commands end with one
/// barrier that makes their writes visible to every later command and to the host. Its compute
/// work is cut into pieces too, before a dispatch that would take a piece's expected GPU run past
/// 4 ms, between the dispatches of a kernel with no measured rate yet and any other, and where a
/// compute or blit encoder opens after a full piece, never before or inside a render pass
/// (`crate::piece`): each piece is a submission of its own, and a command buffer of another queue
/// committed meanwhile goes between two pieces unless it shares a buffer, a texture or a fence
/// with the cut one. It is scheduled as its first piece is submitted where its later pieces wait
/// for no event.
/// barrier that makes their writes visible to every later command and to the host.
///
/// Its GPU times come from two timestamps, written where its first commands begin and as the last
/// command of its last segment, after the copies back of the images its commands wrote and its end
@@ -297,14 +289,6 @@ pub(crate) struct Gpu {
/// The occlusion queries of its render encoders' visibility results, from pools of its own,
/// each given back to the device as it retires (`crate::visibility`).
pub(crate) queries: Queries,
/// Its recording was cut into pieces (`crate::piece`), each a submission of its own.
pub(crate) cut: bool,
/// A dispatch reached memory through an address outside its resources: it shares every
/// resource with another queue's command buffer (`crate::submit`).
pub(crate) unbound: bool,
/// Of a cut command buffer, from its commit: the ids its buffers and textures are tracked by
/// (`crate::kept::ByKind::tracked`), sorted.
pub(crate) ids: Vec<u32>,
}
impl Gpu {
@@ -326,17 +310,6 @@ impl Gpu {
pub(crate) fn presents(&self) -> bool {
(self.segments.last()).is_some_and(|segment| !segment.binary.is_empty())
}
/// Whether `self`, committed after `cut`, a cut command buffer of another queue, holds a
/// resource `cut` holds, by the ids the hazards track them by (a view's is its texture's, a
/// heap's resources' the heap's), waits on a fence `cut` updates, or either reaches memory
/// outside its resources: then `cut`'s pieces go first (`crate::submit`).
pub(crate) fn shares(&self, cut: &Gpu) -> bool {
self.unbound
|| cut.unbound
|| self.kept.meets(&cut.ids)
|| cut.fences.updates_for(&self.fences)
}
}
/// One submission's part of a command buffer: its waits, its commands and its signals.
@@ -363,15 +336,6 @@ pub(crate) struct Segment {
/// upload that leads its submission takes the copies back owed to them by writes submitted
/// before it (`crate::over::ManagedOvers`).
pub(crate) managed_reached: Vec<Arc<BufferInner>>,
/// Its dispatches, which bound it as a piece (`crate::piece`).
pub(crate) work: Work,
/// Its own pair of timestamp queries, whose span feeds its kernels' rates: from its first
/// dispatch to its end; of the first segment, taken only as it splits, its end alone, its run
/// starting at the command buffer's own start. None where it dispatches nothing or found no
/// pair, and for the only segment, which the command buffer's own pair spans (`retire`).
pub(crate) stamps: Option<Pair>,
/// A submission carried it, so its pair was written.
pub(crate) sent: bool,
}
pub(crate) struct Handlers {
@@ -441,9 +405,6 @@ impl CommandBuffer {
fences: Fences::default(),
executed: Vec::new(),
queries: Queries::default(),
cut: false,
unbound: false,
ids: Vec::new(),
},
handlers: Handlers {
scheduled: Vec::new(),
@@ -483,21 +444,11 @@ impl CommandBuffer {
f(state.open()?)
}
/// Takes what is being recorded for an encoder, until [`close_encoder`](Self::close_encoder):
/// for a compute or blit encoder (`cut`), past the end of a full piece
/// ([`Building::cut`]); the commands of any other than a compute encoder follow the
/// segment's dispatches ([`Building::other_commands`]).
/// Err: [`Refusal::Committed`]; [`Refusal::EncoderOpen`]; [`Error::Vulkan`] where ending the
/// piece's commands fails.
pub(crate) fn open_encoder(&self, cut: bool, compute: bool) -> Result<Building, Error> {
/// Takes what is being recorded for an encoder, until [`close_encoder`](Self::close_encoder).
/// Err: [`Refusal::Committed`]; [`Refusal::EncoderOpen`].
pub(crate) fn open_encoder(&self) -> Result<Building, Error> {
let mut state = self.state();
let building = state.open()?;
if cut {
building.cut(None, Some(0))?;
}
if !compute {
building.other_commands();
}
state.open()?;
state.encoding = true;
Ok(state
.building
@@ -667,7 +618,7 @@ impl CommandBuffer {
let mut state = self.state();
state.open()?;
if state.status == CommandBufferStatus::NotEnqueued {
work.enqueue(&self.inner, core.done.completed());
work.enqueue(&self.inner);
state.status = CommandBufferStatus::Enqueued;
self.inner.changed.notify_all();
}
@@ -717,15 +668,12 @@ impl CommandBuffer {
(building.device.core().counters).add(&mut building.tally);
let Building {
device,
mut gpu,
gpu,
handlers,
stamps,
presents,
..
} = building;
if gpu.cut {
gpu.ids = gpu.kept.tracked();
}
state.times.kernel_start = times::host_time();
state.stamps = stamps;
// Its drawables are presented: the presentation engine's once it has run.
@@ -756,7 +704,7 @@ impl CommandBuffer {
.end_all(&core, vec![(Arc::clone(&self.inner), pending, Some(error))]);
} else {
// One ended while enqueued retires behind its queue's work held or in flight.
work.commit(&self.inner, pending, ended, core.done.completed());
work.commit(&self.inner, pending, ended);
drop(work);
core.work.wake();
}
@@ -896,11 +844,7 @@ impl CommandBuffer {
/// observed. 0 until it completes, and for one that ended with an error. One whose segments
/// hold no commands, no event wait and no event signal writes no timestamp: its start and end
/// are one time, the latest GPU end of its queue's command buffers before it, or its kernel
/// end where that is later, as Metal reports for a command buffer that does no work. Of a
/// command buffer cut into pieces ([`Metrics::cuts`](crate::Metrics::cuts)), the span to
/// [`gpu_end_time`](Self::gpu_end_time) holds the runs of other queues' command buffers that
/// went between its pieces, as on the UHD 630 under macOS 26.7.1 the running command
/// buffer's end moved by the run of one that started beside it (job m3-max-68129).
/// end where that is later, as Metal reports for a command buffer that does no work.
pub fn gpu_start_time(&self) -> u64 {
self.state().times.gpu_start
}
@@ -915,9 +859,7 @@ impl CommandBuffer {
/// uploads and copy-ins the runtime submits ahead of it are not in it
/// ([`Metrics::runtime_command_buffer_gpu_nanos`](crate::Metrics::runtime_command_buffer_gpu_nanos)).
/// 0 until it completes, and for one that ended with an error; its start time for one that
/// writes no timestamp. Of a command buffer cut into pieces, it is later by the runs of other
/// queues' command buffers that went between its pieces
/// ([`gpu_start_time`](Self::gpu_start_time)).
/// writes no timestamp.
pub fn gpu_end_time(&self) -> u64 {
self.state().times.gpu_end
}
@@ -1061,10 +1003,6 @@ impl Building {
};
self.host_written |= back.iter().any(|copy| copy.shared);
}
// The end of its own pair once its commands completed, before its end barrier.
if let Some(pair) = self.last().stamps {
times::write_end(&core.device, command, pair.pool, pair.first);
}
// Its end barrier pays what is owed and starts the hazard sets again.
self.owed = false;
self.owed_all = false;
@@ -1084,94 +1022,11 @@ impl Building {
/// Starts a new segment after the last one.
fn split(&mut self) -> Result<(), Error> {
// The first segment's run starts at the command buffer's own start, where no other
// encoder's commands lead its dispatches: its pair, taken as it ends, gives the end, its
// first query written only so the pair reads whole.
let first = self.gpu.segments.len() == 1;
let last = self.last();
let timed = last.stamps.is_some() || last.work.is_empty() || last.work.led();
if let (true, false, Some(command)) = (first, timed, last.command) {
let core = self.device.core();
let pair = core.stamps.take(&core.device, &core.counters);
if let Some(pair) = pair {
times::write_start(&core.device, command, pair.pool, pair.first);
}
self.last().stamps = pair;
}
self.close(&[], None)?;
self.gpu.segments.push(Segment::default());
Ok(())
}
/// Before a dispatch of `kernel` expected to run `run` (None: its rate unknown), and with no
/// kernel and `Some(0)` where a compute or blit encoder opens: where the segment's dispatches are a full
/// piece ([`Work::full`]), the commands after begin a new segment, the command buffer's next
/// piece, counted (`Metrics::cuts`). Not where a texture over a buffer in an image of its own,
/// or over a Managed buffer's device copy, was used in the segment: a cut there would add a
/// copy (`crate::over`).
pub(crate) fn cut(
&mut self,
kernel: Option<&Arc<Compiled>>,
run: Option<u64>,
) -> Result<(), Error> {
let (last, kernels) = self.piece();
// Commands after a signal go in a new segment anyway (`current`).
if !last.signals.is_empty() {
return self.split();
}
let overs = last.overs.ahead() || last.overs.leaning().next().is_some();
if !last.work.full(kernels, kernel, run) || overs || !last.managed_wrote.is_empty() {
return Ok(());
}
self.split()?;
self.gpu.cut = true;
self.tally.count(Metric::Cuts);
Ok(())
}
/// A dispatch of `kernel`, of `groups` threadgroups (None for an indirect one), goes in the
/// current segment, after [`cut`](Self::cut); a dispatch reaching memory outside its resources
/// is `unbound`.
pub(crate) fn dispatched(
&mut self,
kernel: &Arc<Compiled>,
groups: Option<u64>,
unbound: bool,
) {
self.gpu.unbound |= unbound;
let (last, kernels) = self.piece();
last.work.add(kernels, kernel, groups);
}
/// The last segment, and the list its piece's kernels are in (`crate::piece::Kernels`).
fn piece(&mut self) -> (&mut Segment, &mut Kernels) {
let Gpu { segments, kept, .. } = &mut self.gpu;
let last = segments.len() - 1;
(&mut segments[last], &mut kept.kernels)
}
/// Commands of a blit or render encoder follow: the segment's run tells no rate.
pub(crate) fn other_commands(&mut self) {
self.last().work.blind();
}
/// Writes the start of the current segment's own pair into `command`, its command buffer,
/// before its first dispatch, where the device gives a pair: not in the command buffer's
/// first segment where no other encoder's commands lead it, whose run starts at the command
/// buffer's own start ([`split`](Self::split)).
pub(crate) fn stamp_piece(&mut self, command: vk::CommandBuffer) {
let last = self.gpu.segments.len() - 1;
if (last == 0 && !self.last().work.led()) || self.last().stamps.is_some() {
return;
}
let core = self.device.core();
let pair = core.stamps.take(&core.device, &core.counters);
if let Some(pair) = pair {
times::write_start(&core.device, command, pair.pool, pair.first);
}
self.last().stamps = pair;
}
fn wait(&mut self, event: &Arc<EventInner>, value: u64) -> Result<(), Error> {
let last = self.last();
if last.command.is_some() || !last.signals.is_empty() {
@@ -1769,55 +1624,15 @@ pub(crate) fn retire(
) {
let Completion {
gpu_times,
ticks,
round,
spans,
} = completion;
// Where its retirement begins, the step before its handlers (`Round::steps`): one clock read.
let retiring = times::host_time();
// Each piece's own run sets its kernels' rates (`crate::piece`): the first segment's from the
// command buffer's own start, unless another encoder's commands lead its dispatches, to its
// own pair's end or, the only one, the command buffer's own end; each other by its own pair.
// Each pair goes back, reset where a submission wrote it.
let mut pieces = 0;
if let ([segment], Some((start, end)), None) = (&gpu.segments[..], ticks, error) {
if segment.stamps.is_none() && !segment.work.led() {
segment
.work
.ran(&gpu.kept.kernels, core.ticks.span(start, end));
}
}
for (index, segment) in gpu.segments.iter().enumerate() {
let Some(pair) = segment.stamps else {
continue;
};
if let (true, None) = (segment.sent, error) {
// SAFETY: the pair's pool is the device's, and only this retirement resets its two
// queries, after this read.
let read = unsafe { pair.times(&core.device, &core.counters) };
let start = |own| match index == 0 && !segment.work.led() {
true => ticks.map(|(start, _)| start),
false => Some(own),
};
if let Some((start, end)) = read.and_then(|(own, end)| Some((start(own)?, end))) {
let run = core.ticks.span(start, end);
segment.work.ran(&gpu.kept.kernels, run);
pieces += run;
}
}
if segment.sent {
times::reset(&core.device, pair.pool, pair.first, 2);
}
core.stamps.give_back(pair);
}
// Its own GPU run sets what its queue expects of the next (`QueueInner::expected_run`, which
// bounds the groups `submit.rs` joins): by its timestamps, or where it was cut, its pieces'
// runs summed, without what other queues ran between them.
// Its own GPU run, by its timestamps, sets what its queue expects of the next
// (`QueueInner::expected_run`, which bounds the groups `submit.rs` joins).
if let Some((start, end)) = gpu_times {
inner.queue.ran(match gpu.cut {
true => pieces,
false => end.saturating_sub(start),
});
inner.queue.ran(end.saturating_sub(start));
}
// What was released while it was in flight may go (`crate::memory::Wait`).
core.pool.ended();
@@ -1857,15 +1672,12 @@ pub(crate) fn retire(
fences,
executed,
queries,
cut: _,
unbound: _,
ids,
} = gpu;
if let Some(recorder) = recorder {
core.recorders.give_back(core, recorder);
}
ring.give_back(core);
drop((segments, blocks, images, fences, executed, ids));
drop((segments, blocks, images, fences, executed));
queries.give_back(core);
kept.clear();
if let Some(pair) = stamps {
@@ -1929,7 +1741,6 @@ impl Drop for CbInner {
let core = device.core();
let Gpu {
recorder,
segments,
mut kept,
ring,
queries,
@@ -1938,9 +1749,6 @@ impl Drop for CbInner {
if let Some(recorder) = recorder {
core.recorders.give_back(core, recorder);
}
for pair in segments.iter().filter_map(|segment| segment.stamps) {
core.stamps.give_back(pair);
}
ring.give_back(core);
if let Some(pair) = stamps {
core.stamps.give_back(pair);
+1 -18
View File
@@ -99,9 +99,6 @@ enum Item {
Upload(Upload),
/// A Managed buffer's copy-in the submission took (`crate::capture`).
CopyIn(CopyIn),
/// A submission that carries nothing to retire, a piece before its command buffer's last
/// (`crate::piece`): its completion leaves the device room for the next (`crate::submit`).
Piece,
}
impl Done {
@@ -246,7 +243,6 @@ impl Done {
Item::Command { .. } => "a command buffer",
Item::Upload(_) => "an upload",
Item::CopyIn(_) => "a copy-in",
Item::Piece => "a piece",
};
let reached = match reached_by_wait(device, self.progress, oldest.value) {
Ok(reached) => reached.to_string(),
@@ -357,14 +353,6 @@ impl Done {
},
});
}
if state.flight.back().is_none_or(|last| last.value != value) {
state.flight.push_back(Retiree {
value,
held,
lost: false,
item: Item::Piece,
});
}
state.watched.extend(watch);
self.wake(&mut state, &core.device, flight_only);
}
@@ -448,7 +436,6 @@ impl Retiree {
Item::Command { .. } => "a command buffer",
Item::Upload(_) => "an upload",
Item::CopyIn(_) => "a copy-in",
Item::Piece => "a piece",
},
self.value,
if self.lost { ", lost" } else { "" }
@@ -470,7 +457,6 @@ impl Retiree {
}
Item::Upload(upload) => upload.retire(core, end),
Item::CopyIn(copy_in) => copy_in.retire(core, end),
Item::Piece => None,
}
}
@@ -539,11 +525,9 @@ impl Round {
}
/// What the completion thread knows of a command buffer's completion as it retires it: its GPU
/// times where they were read, placed on the host clock and as the GPU wrote them, its round,
/// and the GPU spans retired before it.
/// times where they were read, its round, and the GPU spans retired before it.
pub(crate) struct Completion<'a> {
pub(crate) gpu_times: Option<(u64, u64)>,
pub(crate) ticks: Option<(u64, u64)>,
pub(crate) round: &'a Round,
pub(crate) spans: &'a Spans,
}
@@ -758,7 +742,6 @@ pub(crate) fn run(core: Arc<Core>) {
.map(|(stamps, calibration)| calibration.place(&core.ticks, stamps, seen));
let completion = Completion {
gpu_times: times,
ticks: stamps,
round: &round,
spans: &spans,
};
@@ -268,12 +268,6 @@ pub(crate) enum Metric {
SubmissionsDuringFrees,
/// [`Metrics::untimed_command_buffers`].
UntimedCommandBuffers,
/// [`Metrics::cuts`].
Cuts,
/// [`Metrics::pieces_passed`].
PiecesPassed,
/// [`Metrics::shared_holds`].
SharedHolds,
/// [`Metrics::sampler_element_writes`].
SamplerElementWrites,
/// [`Metrics::stamps_not_available`].
@@ -346,9 +340,6 @@ const METRIC_ORDER: [Metric; METRICS] = [
Metric::AllocationsFreed,
Metric::SubmissionsDuringFrees,
Metric::UntimedCommandBuffers,
Metric::Cuts,
Metric::PiecesPassed,
Metric::SharedHolds,
Metric::SamplerElementWrites,
Metric::StampsNotAvailable,
Metric::WaitsBehindCounter,
@@ -732,9 +723,6 @@ struct Atomics {
held_release_bytes: AtomicU64,
held_release_starts: AtomicU64,
untimed_command_buffers: AtomicU64,
cuts: AtomicU64,
pieces_passed: AtomicU64,
shared_holds: AtomicU64,
sampler_element_writes: AtomicU64,
stamps_not_available: AtomicU64,
runtime_command_buffers: AtomicU64,
@@ -902,9 +890,6 @@ impl Counters {
Metric::AllocationsFreed => &a.allocations_freed,
Metric::SubmissionsDuringFrees => &a.submissions_during_frees,
Metric::UntimedCommandBuffers => &a.untimed_command_buffers,
Metric::Cuts => &a.cuts,
Metric::PiecesPassed => &a.pieces_passed,
Metric::SharedHolds => &a.shared_holds,
Metric::SamplerElementWrites => &a.sampler_element_writes,
Metric::StampsNotAvailable => &a.stamps_not_available,
Metric::WaitsBehindCounter => &a.waits_behind_counter,
@@ -1807,9 +1792,6 @@ impl Counters {
held_release_bytes: a.held_release_bytes.load(Relaxed),
held_release_starts: a.held_release_starts.load(Relaxed),
untimed_command_buffers: a.untimed_command_buffers.load(Relaxed),
cuts: a.cuts.load(Relaxed),
pieces_passed: a.pieces_passed.load(Relaxed),
shared_holds: a.shared_holds.load(Relaxed),
sampler_element_writes: a.sampler_element_writes.load(Relaxed),
stamps_not_available: a.stamps_not_available.load(Relaxed),
runtime_command_buffers: a.runtime_command_buffers.load(Relaxed),
@@ -2633,21 +2615,6 @@ pub struct Metrics {
/// as they began count here too, and their time in
/// [`runtime_command_buffer_gpu_nanos`](Self::runtime_command_buffer_gpu_nanos) is lost.
pub untimed_command_buffers: u64,
/// No Metal counterpart: the cuts that ended a piece of a command buffer: before a compute
/// dispatch that would take the piece's expected GPU run past 4 ms; between the dispatches of
/// a kernel with no measured rate yet, which share a piece of their own, and any other; and
/// where a compute or blit encoder opens after a full piece. Each piece is a submission of
/// its own, so a command buffer of another queue committed meanwhile goes between two pieces
/// ([`CommandBuffer`](crate::CommandBuffer)).
pub cuts: u64,
/// Submissions of a queue's command buffers that went to the `VkQueue` while a cut command
/// buffer of another queue had pieces not yet submitted: they run before those pieces.
pub pieces_passed: u64,
/// Command buffers held behind every piece of a cut command buffer of another queue,
/// committed before them, as they hold a buffer or texture it holds (by the ids the hazards
/// track them by), wait on a fence it updates, or either reaches memory outside its
/// resources: held while its next piece is ready, not while that piece waits for an event.
pub shared_holds: u64,
/// Elements of set 1's sampler arrays written (`vkUpdateDescriptorSets`): a sampler state's or
/// a constexpr sampler's placement and its going write only the elements whose sampler
/// differs from what the index's element holds, so an equal state made at the index of one
+1 -10
View File
@@ -13,7 +13,6 @@ use crate::indirect::IndirectCommandBuffer;
use crate::kept::{Handle, Lent, Uncounted};
use crate::memory::BlockId;
use crate::over::{self, Reached, Span};
use crate::piece::Work;
use crate::pipeline::{
address_word, Compiled, ComputePipelineState, FieldValue, Form, Interface, Kernel, Place,
Which, PUSH_STAGES, SQUARE,
@@ -449,7 +448,7 @@ impl CommandBuffer {
&self,
dispatch_type: DispatchType,
) -> Result<ComputeCommandEncoder, Error> {
let mut building = self.open_encoder(true, true)?;
let mut building = self.open_encoder()?;
// SAFETY: the encoder holds `building`, whose device handle keeps the core, until it ends;
// nothing uses the borrow after that.
let core = unsafe { Uncounted::of(building.device.core()) };
@@ -1095,13 +1094,6 @@ impl ComputeCommandEncoder {
pipeline: vk_pipeline,
});
let interface = &kernel.interface;
// A dispatch that would take its piece past the bound begins the command buffer's next
// piece (`crate::piece`).
let groups = direct.map(|(_, groups, _)| groups.iter().map(|&n| u64::from(n)).product());
let building = recording(&mut self.building);
building.cut(Some(inner), Work::expected(inner, groups))?;
let unbound = interface.reads_unbound || interface.writes_unbound;
building.dispatched(inner, groups, unbound);
if self.facts.module != Some(module) {
self.facts.managed = self.reaches_managed(interface);
self.facts.host = self.writes_host(interface);
@@ -1787,7 +1779,6 @@ impl Building {
let command = self.command(Reach::Dispatches {
indirect: matches!(launch, Launch::Indirect(..)),
})?;
self.stamp_piece(command);
// SAFETY: the command buffer is the current segment's, recording outside any render pass;
// the pipeline is the device's, of its layout, and the window lies in the layout's one
// push range, of `PUSH_STAGES`.
+2 -30
View File
@@ -10,12 +10,11 @@
//! than the bound. They live in one allocation that moves whole between the queue and its command
//! buffers ([`Objects`]), so a command buffer allocates and frees none of it.
use crate::buffer::{Buffer, BufferObject};
use crate::piece::Kernels;
use crate::buffer::Buffer;
use crate::pipeline::ComputePipelineState;
use crate::render::RenderPipelineState;
use crate::sampler::SamplerState;
use crate::texture::{Texture, TextureObject};
use crate::texture::Texture;
use std::collections::HashSet;
use std::hash::{BuildHasherDefault, Hasher};
use std::mem::ManuallyDrop;
@@ -230,10 +229,6 @@ impl DerefMut for Objects {
/// The lists of each kind a recording keeps.
#[derive(Default)]
pub(crate) struct ByKind {
/// Its pieces' kernels (`crate::piece::Kernels`), each the content of a state `pipelines`
/// keeps, held with no count: emptied before `pipelines` is, as it is dropped first, so no
/// copy outlives its state.
pub(crate) kernels: Kernels,
pub(crate) buffers: Kept<Buffer>,
pub(crate) textures: Kept<Texture>,
pub(crate) samplers: Kept<SamplerState>,
@@ -242,32 +237,9 @@ pub(crate) struct ByKind {
}
impl ByKind {
/// The ids the hazards track its buffers and textures by, a view's being its texture's and a
/// heap's resources' the heap's, each once, sorted.
pub(crate) fn tracked(&self) -> Vec<u32> {
let mut ids: Vec<u32> = self.ids().collect();
ids.sort_unstable();
ids.dedup();
ids
}
/// Whether one of its buffers or textures is tracked by one of `ids`, sorted.
pub(crate) fn meets(&self, ids: &[u32]) -> bool {
!ids.is_empty() && self.ids().any(|id| ids.binary_search(&id).is_ok())
}
fn ids(&self) -> impl Iterator<Item = u32> + '_ {
let buffers = self.buffers.iter().map(BufferObject::tracked_id);
buffers.chain(self.textures.iter().map(TextureObject::tracked_id))
}
/// Releases every object, keeping each list's capacity, within [`KEPT_BOUND`], for the next
/// recording.
pub(crate) fn clear(&mut self) {
match self.kernels.capacity() > KEPT_BOUND {
true => self.kernels = Kernels::new(),
false => self.kernels.clear(),
}
self.buffers.clear();
self.textures.clear();
self.samplers.clear();
-1
View File
@@ -44,7 +44,6 @@ mod memory;
mod over;
mod own;
mod pass;
mod piece;
mod pipeline;
mod pixel_format_info;
mod places;
-199
View File
@@ -1,199 +0,0 @@
//! Pieces: a command buffer's compute work goes to the device's `VkQueue` in pieces, each one
//! segment, whose dispatches are expected to run on the GPU for at most
//! [`GROUP_RUN`](crate::submit::GROUP_RUN) together, so a command buffer of another queue committed
//! while one runs waits for that piece rather than for the whole command buffer
//! (`crate::submit`). A dispatch's expected run is its kernel's rate, the run of one of its
//! threadgroups, times its threadgroups. Each rate comes from the runs of the pieces that ran the
//! kernel: a command buffer of one piece timed by its own two timestamps, which nothing of another
//! submission passes inside; the first piece of several from the command buffer's start to a
//! timestamp at the piece's end; each later piece by a pair of its own. So the work of another
//! queue's command buffer that went between two pieces is in no rate, and a command buffer that
//! is not cut writes no timestamp past its own two. The rate is scheduling data, as a queue's
//! expected run is (`QueueInner::expected_run`): it bounds where a piece ends, and never chooses
//! between two forms of the work.
use crate::kept::Uncount;
use crate::pipeline::Compiled;
use crate::queue::next_run;
use crate::submit::GROUP_RUN;
use std::mem::ManuallyDrop;
use std::ops::Range;
use std::sync::atomic::{AtomicU64, Ordering::Relaxed};
use std::sync::Arc;
/// A kernel's rate: the GPU run of one threadgroup of its dispatches, in picoseconds, as the
/// pieces that ran it measured, rising at once to a longer one and halving the way toward a
/// shorter one ([`next_run`]); unknown until the first such piece completed.
pub(crate) struct Rate(AtomicU64);
impl Default for Rate {
fn default() -> Rate {
Rate(AtomicU64::new(u64::MAX))
}
}
impl Rate {
/// The expected run, in nanoseconds, of `groups` threadgroups; None while the rate is
/// unknown.
pub(crate) fn expected(&self, groups: u64) -> Option<u64> {
let rate = self.0.load(Relaxed);
let nanos = u128::from(groups) * u128::from(rate) / 1000;
(rate != u64::MAX).then(|| u64::try_from(nanos).unwrap_or(u64::MAX))
}
/// For the device tests: the rate is `picos` exactly, the test's own input in place of what
/// the pieces measured, until a piece that ran the kernel completes.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) fn set_for_test(&self, picos: u64) {
self.0.store(picos, Relaxed);
}
/// A piece measured `picos` for each threadgroup of this kernel.
fn ran(&self, picos: u64) {
let _ = self.0.try_update(Relaxed, Relaxed, |rate| {
Some(next_run((rate != u64::MAX).then_some(rate), picos))
});
}
}
/// A kernel of a piece, with its threadgroups summed: its content as its state holds it, taking
/// no count ([`Uncount`]), since the command buffer keeps the state it bound until it retires,
/// after its pieces' runs set their rates (`crate::command::retire`).
pub(crate) struct Kernel {
compiled: ManuallyDrop<Arc<Compiled>>,
groups: u64,
}
/// A command buffer's pieces' kernels, piece by piece: a list its kept objects hold
/// (`crate::kept::ByKind`), whose capacity goes on to the queue's next recording, so a recording
/// allocates for them only past what an earlier one left, and frees none.
pub(crate) type Kernels = Vec<Kernel>;
/// The dispatches of one piece: each kernel once, with its threadgroups summed, in its command
/// buffer's list ([`Kernels`]), and their expected run.
#[derive(Default)]
pub(crate) struct Work {
/// Its kernels' places in the list: the last piece's run to the list's end.
kernels: Range<usize>,
/// The expected GPU run of its dispatches, in nanoseconds, summed.
pub(crate) run: u64,
/// It holds dispatches of a kernel whose rate was unknown, and of no other kernel, so its run
/// sets that kernel's rate.
alone: bool,
/// Its run tells no rate: it holds an indirect dispatch, whose threadgroups the GPU reads and
/// which counts as one, a dispatch of a kernel of unknown rate beside others, or commands of
/// a blit or render encoder after its first dispatch.
blind: bool,
/// Commands of a blit or render encoder come before its first dispatch, so a span from the
/// command buffer's start would hold them: its own pair starts at its first dispatch.
led: bool,
}
impl Work {
/// Whether it holds a dispatch.
pub(crate) fn is_empty(&self) -> bool {
self.kernels.is_empty()
}
/// Whether a dispatch of `kernel` expected to run `run` (None: its kernel's rate unknown;
/// where an encoder opens, no kernel and `Some(0)`) begins a new piece: this one holds a
/// dispatch, and holds a kernel of unknown rate (unless the dispatch is that kernel's too, of
/// a rate still unknown), or the dispatch's rate is unknown, or the two would pass the bound.
pub(crate) fn full(
&self,
list: &[Kernel],
kernel: Option<&Arc<Compiled>>,
run: Option<u64>,
) -> bool {
let own = |kernel: &Arc<Compiled>| self.of(list).iter().all(|kept| kept.is(kernel));
!self.is_empty()
&& match (self.alone, run) {
(true, None) => !kernel.is_some_and(own),
(true, Some(_)) | (false, None) => true,
(false, Some(run)) => self.run.saturating_add(run) > GROUP_RUN,
}
}
/// The expected run of a dispatch of `kernel` of `groups` threadgroups; None where its rate
/// is unknown. An indirect dispatch (`groups` None) counts as one threadgroup, and as none of
/// a kernel of unknown rate: its run, of threadgroups only the GPU reads, sets no rate.
pub(crate) fn expected(kernel: &Compiled, groups: Option<u64>) -> Option<u64> {
match groups {
Some(groups) => kernel.rate.expected(groups),
None => Some(kernel.rate.expected(1).unwrap_or(0)),
}
}
/// Adds a dispatch of `kernel`, of the state its command buffer keeps, to the piece, the last
/// of `list`'s: `groups` threadgroups, None for an indirect dispatch.
pub(crate) fn add(&mut self, list: &mut Kernels, kernel: &Arc<Compiled>, groups: Option<u64>) {
let expected = Work::expected(kernel, groups);
let own = self.of(list).iter().all(|kept| kept.is(kernel));
self.blind |= groups.is_none() || ((expected.is_none() || self.alone) && !own);
self.alone |= expected.is_none();
self.run = self.run.saturating_add(expected.unwrap_or(0));
let groups = groups.unwrap_or(1);
let range = self.kernels.clone();
match (list.get_mut(range)).and_then(|mine| mine.iter_mut().find(|kept| kept.is(kernel))) {
Some(kept) => kept.groups = kept.groups.saturating_add(groups),
None => {
if self.kernels.is_empty() {
self.kernels = list.len()..list.len();
}
// SAFETY: `kernel` is the content of the state the encoder bound, which the
// command buffer's kept objects hold, counted (`Building::lend_pipeline`), in
// `pipelines`; `list` is the same objects' `kernels`, emptied before `pipelines`
// releases anything, and dropped first (`ByKind`). The copy is read only through
// `list` (`Work::ran`), so never after its state is released.
let compiled = unsafe { kernel.uncounted() };
list.push(Kernel { compiled, groups });
self.kernels.end = list.len();
}
}
}
/// Its kernels in `list`, its command buffer's.
fn of<'a>(&self, list: &'a [Kernel]) -> &'a [Kernel] {
list.get(self.kernels.clone()).unwrap_or_default()
}
/// Commands of another encoder go in the piece: after its dispatches, or ahead of them.
pub(crate) fn blind(&mut self) {
self.blind |= !self.is_empty();
self.led |= self.is_empty();
}
/// Whether commands of another encoder came before its first dispatch.
pub(crate) fn led(&self) -> bool {
self.led
}
/// The piece ran `nanos` on the GPU: a kernel alone in it takes its rate from that run, and
/// several each scale theirs by the run against what they expected.
pub(crate) fn ran(&self, list: &[Kernel], nanos: u64) {
if self.blind {
return;
}
let kernels = self.of(list);
let picos = u128::from(nanos) * 1000;
let rate = |kernel: &Compiled| u128::from(kernel.rate.0.load(Relaxed));
let expected: u128 = (kernels.iter())
.map(|kept| rate(&kept.compiled) * u128::from(kept.groups))
.sum();
for kept in kernels {
let picos = match kernels.len() {
1 => picos / u128::from(kept.groups.max(1)),
_ if expected == 0 => continue,
_ => rate(&kept.compiled).saturating_mul(picos) / expected,
};
(kept.compiled.rate).ran(u64::try_from(picos).unwrap_or(u64::MAX - 1));
}
}
}
impl Kernel {
/// Whether it is `kernel`.
fn is(&self, kernel: &Arc<Compiled>) -> bool {
Arc::ptr_eq(&self.compiled, kernel)
}
}
@@ -66,7 +66,6 @@ use crate::encoder::{
use crate::error::{Error, Gap, IndirectCommandsKind, KernelInputKind, Refusal, StageInKind};
use crate::hazard::Access;
use crate::kernel_map::KernelKey;
use crate::piece::Rate;
use crate::reaper::{Free, Job};
use crate::ring::CHUNK;
use crate::sampler::{canonical, constexpr_notes, hold_constexpr, release_constexpr};
@@ -186,9 +185,6 @@ pub(crate) struct Compiled {
/// [`ComputePipelineState::finish_pipeline`] makes, or its creation for a kernel past the
/// stage bound; none where its descriptor holds no key of a `VkPipeline`.
main: Option<DispatchVariant>,
/// The GPU run of one threadgroup of its dispatches, which bounds the pieces their command
/// buffers go in (`crate::piece`), shared by every state of the content.
pub(crate) rate: Rate,
}
/// What Metal's compute state answers of a content beside its threads, from its whole module's
@@ -1193,7 +1189,6 @@ impl Compiled {
notes,
answers,
main: None,
rate: Rate::default(),
}
}
}
@@ -717,7 +717,7 @@ impl CommandBuffer {
&self,
descriptor: &RenderPassDescriptor,
) -> Result<RenderCommandEncoder, Error> {
let mut building = self.open_encoder(false, false)?;
let mut building = self.open_encoder()?;
// SAFETY: the encoder holds `building`, whose device handle keeps the core, until it ends;
// nothing uses the borrow after that, and a refused descriptor drops it with no use.
let core = unsafe { Uncounted::of(building.device.core()) };
+75 -372
View File
@@ -85,15 +85,13 @@ use std::sync::{Arc, Condvar, Mutex, MutexGuard, PoisonError, Weak};
/// command buffers in half the time no bound did (probe 06860a3848, job m3-max-44105).
pub(crate) const GROUP: usize = 16;
/// The most expected GPU run, in nanoseconds, of the command buffers one group holds, summed, of
/// the dispatches of one piece of a command buffer (`crate::piece`), and of the device's
/// submissions behind its oldest not seen complete ([`room`]): 4 ms. So a command buffer
/// committed while others run waits behind the running submission and about 4 ms more, inside
/// the 16 ms that is the owner's line for an intolerable wait. Each command buffer's expected run
/// is its queue's (`QueueInner::expected_run`), from the GPU times of the queue's command buffers
/// as they retire; a piece's is its dispatches' kernels' rates. Command buffers each within the
/// driver's job timeout may pass it summed in one job.
pub(crate) const GROUP_RUN: u64 = 4_000_000;
/// The most expected GPU run, in nanoseconds, of the command buffers one group holds, summed, and
/// of a queue's submissions behind its oldest not seen complete ([`room`]): 16 ms, the owner's
/// line for an intolerable wait. Each command buffer's
/// expected run is its queue's (`QueueInner::expected_run`), from the GPU times of the queue's
/// command buffers as they retire. Command buffers each within the driver's job timeout may pass
/// it summed in one job.
pub(crate) const GROUP_RUN: u64 = 16_000_000;
/// The most command buffers that join one group while none of their queue's retires with its GPU
/// times: they join on an expected run no completion has updated, so a program whose command
@@ -128,8 +126,8 @@ pub(crate) fn apart(members: u64, run: Option<u64>) -> bool {
members > 1 && run.is_none_or(|run| run.saturating_mul(members) > GROUP_RUN)
}
/// The submissions of the device not yet seen complete at which its command buffers are held in
/// a group or for room ([`room`]). Three, not two: with two, the GPU idles between a group's end and the next
/// The submissions of a queue not yet seen complete at which its command buffers are held in a
/// group ([`room`]). Three, not two: with two, the GPU idles between a group's end and the next
/// submission's start whenever the completion that sends the held group comes late. Behind three,
/// the frame of five command buffers on the UHD 630 completed in 420-429 us against 895-1137 us,
/// and the second of four long command buffers was seen complete 74.7 ms after its commit against
@@ -142,14 +140,13 @@ pub(crate) fn apart(members: u64, run: Option<u64>) -> bool {
/// 78.1-78.2 ms against 42.8-43.2 ms (jobs m3-max-44442 and m3-max-44443).
pub(crate) const IN_FLIGHT: usize = 3;
/// Whether a device whose submissions not seen complete have the expected runs `in_flight`, oldest
/// first (`u64::MAX` for one not known), has room for a group or a piece whose expected run is
/// `run`: with fewer than two of them always, so one waits on the GPU behind the one running and
/// long command buffers run back to back; with fewer than [`IN_FLIGHT`] while the runs behind the
/// oldest, the group's with them, stay within [`GROUP_RUN`]. So the device's one `VkQueue` holds
/// no more than about that bound behind what runs, whatever the queues, and a command buffer
/// committed later waits behind no more of it. Which queue takes the room is
/// [`WorkState::has_room`]'s.
/// Whether a queue whose submissions not seen complete have the expected runs `in_flight`, oldest
/// first (`u64::MAX` for one not known), has room for a group whose expected run is `run`: with
/// fewer than two of them always, so one waits on the GPU behind the one running and long command
/// buffers run back to back; with fewer than [`IN_FLIGHT`] while the runs behind the oldest, the
/// group's with them, stay within [`GROUP_RUN`]. So a queue keeps on the device's one `VkQueue`
/// no more than about that bound behind what runs, and another queue's command buffer committed
/// later waits behind no more of it.
pub(crate) fn room(in_flight: &VecDeque<(u64, u64)>, run: u64) -> bool {
let behind = (in_flight.iter().skip(1)).fold(run, |sum, &(_, run)| sum.saturating_add(run));
in_flight.len() < 2 || (in_flight.len() < IN_FLIGHT && behind <= GROUP_RUN)
@@ -220,11 +217,6 @@ pub(crate) struct WorkState {
next_place: u64,
/// The progress value of the last submission.
progress: u64,
/// The progress values of the queues' submissions not yet seen complete, in order, each with
/// its expected run ([`room`]).
in_flight: VecDeque<(u64, u64)>,
/// The submissions of the queues' work so far: each FIFO's turn is the count at its last.
turns: u64,
/// The command buffers whose last segment a submission not seen complete when the submit
/// thread last looked carried, in the order submitted: each one's place in the commit order
/// and that submission's progress value ([`Work::settled`]). At most the command buffers
@@ -265,9 +257,6 @@ pub(crate) struct WorkState {
/// ([`Work::stall`]).
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
lost_at: u64,
/// For the device tests: the queue of each submission of the queues' work, in order.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
order: Vec<usize>,
}
struct Fifo {
@@ -275,17 +264,9 @@ struct Fifo {
entries: VecDeque<Entry>,
/// The group staged and not yet submitted.
group: Option<Batch>,
/// The progress values of the queue's submissions not yet seen complete, in order: what its
/// command buffers with no submission of their own retire behind, and whether a commit finds
/// it idle ([`WorkState::push`]).
in_flight: VecDeque<u64>,
/// When it last submitted ([`WorkState::turns`]), 0 before and from a commit that found it
/// with nothing queued or in flight: the device's room goes first to the queue that waited
/// longest ([`WorkState::rank`]).
turn: u64,
/// Its head is held behind every piece of a cut command buffer of another queue committed
/// before it, with which it shares a resource ([`WorkState::block_shared`]).
blocked: bool,
/// The progress values of the queue's submissions not yet seen complete, in order, each with
/// its expected run ([`room`]).
in_flight: VecDeque<(u64, u64)>,
/// A host wait is to come for the command buffer at this place: a group from it or before
/// goes at once.
send_through: u64,
@@ -312,20 +293,6 @@ struct Entry {
held: Option<u64>,
}
impl Entry {
/// Whether, met behind a head that waits for room, it has its queue sent through to it
/// rather than held ([`WorkState::hold`]): committed and ended before it went, holding
/// nothing for the GPU that no copy-in waits for, or presenting a drawable, which is
/// scheduled once submitted.
fn sent_through(&self, captured: &capture::Captured) -> bool {
self.pending.as_ref().is_some_and(|pending| {
self.error.is_some()
|| (pending.gpu.is_empty() && !captured.waits_for(pending.seq))
|| pending.gpu.presents()
})
}
}
/// Commands recorded into one command buffer apart from any command buffer of the guest's (zero
/// fills, texture copies, and new textures' moves to their home layouts), the calls made before
/// one commit and after the one before it: submitted ahead of everything in the first submission
@@ -597,8 +564,6 @@ impl Work {
next_seq: 0,
next_place: 0,
progress: 0,
in_flight: VecDeque::new(),
turns: 0,
carried: VecDeque::new(),
uploaded: 0,
upload: None,
@@ -615,8 +580,6 @@ impl Work {
exported: ExportedOvers::default(),
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
lost_at: 0,
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
order: Vec::new(),
}),
changed: Condvar::new(),
spans: Condvar::new(),
@@ -1177,16 +1140,6 @@ impl Work {
(state.region.as_ref()).map_or_else(Vec::new, |region| region.ring.live())
}
/// For the device tests: of the submissions of the queues' work so far, in order, which were
/// `queue`'s.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) fn submitted_by(&self, queue: &QueueInner) -> Vec<bool> {
let at = std::ptr::from_ref(queue) as usize;
(self.lock().order.iter())
.map(|&queue| queue == at)
.collect()
}
/// For the device tests: `queue`'s submissions not seen complete when the submit thread last
/// looked, and whether it holds a group not yet submitted.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
@@ -1549,8 +1502,6 @@ impl WorkState {
entries: VecDeque::new(),
group: None,
in_flight: VecDeque::new(),
turn: 0,
blocked: false,
send_through: 0,
behind: 0,
held_since: None,
@@ -1561,21 +1512,11 @@ impl WorkState {
&mut self.fifos[index]
}
/// Takes `cb`'s place at its queue's end. A queue with nothing queued, and nothing in flight
/// past `completed`, the progress value the completion thread has seen complete, takes turn
/// 0, as one that never submitted: the submit thread forgets a queue's completed submissions
/// only as it next looks ([`settle`](Self::settle)), which a completion with nothing held does
/// not wake it to do, so its list alone would keep a queue whose work all completed out of
/// turn 0, and a later commit of another queue would rank before it ([`rank`](Self::rank)).
fn push(&mut self, cb: &Arc<CbInner>, completed: u64) -> &mut Entry {
/// Takes `cb`'s place at its queue's end.
fn push(&mut self, cb: &Arc<CbInner>) -> &mut Entry {
self.next_place += 1;
let place = self.next_place;
let fifo = self.fifo(&cb.queue);
let done = (fifo.in_flight.back()).is_none_or(|&value| value <= completed);
if fifo.entries.is_empty() && fifo.group.is_none() && done {
fifo.turn = 0;
}
let entries = &mut fifo.entries;
let entries = &mut self.fifo(&cb.queue).entries;
entries.push_back(Entry {
cb: Arc::clone(cb),
place,
@@ -1586,29 +1527,26 @@ impl WorkState {
entries.back_mut().expect("an entry just pushed")
}
/// Takes `cb`'s place in its queue's FIFO, `completed` being the progress value seen
/// complete ([`push`](Self::push)).
pub(crate) fn enqueue(&mut self, cb: &Arc<CbInner>, completed: u64) {
self.push(cb, completed);
/// Takes `cb`'s place in its queue's FIFO.
pub(crate) fn enqueue(&mut self, cb: &Arc<CbInner>) {
self.push(cb);
}
/// Hands `cb` to the submit thread: at its place where it was enqueued, else at its queue's
/// end. With `error` (it ended while enqueued, and its place went), at its queue's end, to
/// retire with that error behind the work held or in flight before it. `completed` is the
/// progress value seen complete ([`push`](Self::push)).
/// retire with that error behind the work held or in flight before it.
pub(crate) fn commit(
&mut self,
cb: &Arc<CbInner>,
pending: Pending,
error: Option<CommandBufferError>,
completed: u64,
) {
self.dirty = true;
let enqueued = (self.fifo(&cb.queue).entries.iter_mut())
.find(|entry| Arc::ptr_eq(&entry.cb, cb) && entry.pending.is_none());
let entry = match enqueued {
Some(entry) => entry,
None => self.push(cb, completed),
None => self.push(cb),
};
entry.pending = Some(pending);
entry.error = error;
@@ -1640,29 +1578,12 @@ impl WorkState {
/// no longer waits, the earliest held: it was scheduled before anything that comes next.
/// Else, of the committed heads that are ended or whose next segment is ready, and of the
/// first command buffers not yet scheduled behind heads that wait, ended or with every
/// segment's waits met, the earliest committed; where the head that waits is cut, none
/// [`hold`](Self::hold) would send its queue through to ([`Entry::sent_through`]).
/// segment's waits met, the earliest committed.
fn next_ready(&self) -> Option<(usize, bool)> {
let mut held: Option<(u64, usize)> = None;
let mut best: Option<(usize, bool, u64)> = None;
for (index, fifo) in self.fifos.iter().enumerate() {
let waits = self.waits_for_room(index);
if fifo.blocked && !waits {
continue;
}
// A head that would go before an earlier commit of another queue Metal submitted
// ([`sends_past`](Self::sends_past)) does not join a group held that would not: it
// waits for that group to go, and then leads one of its own, held until that commit
// is submitted, as a group whose first would go before it is.
let past = |pending: &Pending| self.sends_past(index, pending);
let joins = (fifo.group.as_ref()).is_some_and(|group| !group.partial)
&& !fifo.sends().is_some_and(past)
&& (fifo.entries.front()).is_some_and(|head| {
head.error.is_none() && head.pending.as_ref().is_some_and(past)
});
if joins && !waits {
continue;
}
let waits = self.waits_for_room(fifo);
if let (false, Some(at)) = (waits, fifo.entries.front().and_then(|head| head.held)) {
held = held.filter(|&(first, _)| first < at).or(Some((at, index)));
continue;
@@ -1671,19 +1592,6 @@ impl WorkState {
true => fifo.entries.iter().find(|entry| entry.held.is_none()),
false => fifo.entries.front(),
};
// A cut head's every piece waits for room, never sent through (`waits_for_room`), so
// an entry `hold` would send the queue through to, the head or one behind it, is not
// picked while it waits: `hold` would leave it as it was, picked again at once, the
// work lock held, for as long as the room stays full. It goes in the queue's order as
// the room comes.
let head = fifo.entries.front().and_then(|head| head.pending.as_ref());
let captured = &self.changes.captured;
if waits
&& head.is_some_and(|head| head.gpu.cut)
&& entry.is_some_and(|entry| entry.sent_through(captured))
{
continue;
}
let Some(Entry {
pending: Some(pending),
error,
@@ -1708,153 +1616,39 @@ impl WorkState {
(held.map(|(_, index)| (index, false))).or(best.map(|(index, waits, _)| (index, waits)))
}
/// Whether the head of the FIFO at `index` waits in its list, not staged, for room: committed,
/// with commands or a copy-in for the GPU, its first segment not yet staged, behind a group
/// held that does not go ([`goes`](Self::goes)) nor conflict with it, and that does not take
/// it ([`Batch::takes`]) or would go at its signal. With no group held, one that signals an
/// event in any segment, which would send its group at once, waits where its queue has no room
/// for it. A cut command buffer's every piece waits for room, as no group takes it. The command
/// buffers behind it wait with it.
fn waits_for_room(&self, index: usize) -> bool {
let fifo = &self.fifos[index];
/// Whether the head of `fifo` waits in its list, not staged, for room: committed, with
/// commands or a copy-in for the GPU, its first segment not yet staged, behind a group held
/// that does not go ([`Fifo::goes`]) nor conflict with it, and that does not take it
/// ([`Batch::takes`]) or would go at its signal. With no group held, one that signals an event
/// in any segment, which would send its group at once, waits where its queue has no room for
/// it. The command buffers behind it wait with it.
fn waits_for_room(&self, fifo: &Fifo) -> bool {
let Some(head) = fifo.entries.front() else {
return false;
};
let (Some(pending), None) = (&head.pending, head.error) else {
return false;
};
let cut = pending.gpu.cut;
let empty = pending.gpu.is_empty() && !self.changes.captured.waits_for(pending.seq);
if (pending.next != 0 && !cut) || empty {
if pending.next != 0 || empty {
return false;
}
let segments = &pending.gpu.segments;
let signals = cut || (segments.iter()).any(|segment| !segment.signals.is_empty());
let (segment, run) = (&segments[pending.next], fifo.queue.expected_run());
let signals = (segments.iter()).any(|segment| !segment.signals.is_empty());
let (segment, run) = (&segments[0], fifo.queue.expected_run());
match &fifo.group {
Some(group) => {
!group.leans.conflicts(&segment.overs)
&& (signals || !group.takes(run, fifo.queue.retired()))
&& !self.goes(index)
&& !fifo.goes(self.stop)
}
None => {
let run = match cut {
true => segment.work.run,
false => run.unwrap_or(u64::MAX),
};
let through =
fifo.send_through >= head.place && !cut && !self.sends_past(index, pending);
signals && !(self.stop || through || self.has_room(index, run))
let room = room(&fifo.in_flight, run.unwrap_or(u64::MAX));
signals && !(self.stop || fifo.send_through >= head.place || room)
}
}
}
/// Whether the FIFO at `index` has room on the device for a submission expected to run `run`
/// ([`room`]), no FIFO ranked before it ([`rank`](Self::rank)) wanting room that fits
/// ([`wants`](Self::wants)): so the queue that waited longest goes first, and a command
/// buffer passed by another queue's goes before that queue's next. A queue the
/// shared-resource rule holds wants nothing, so it holds no other queue back, and one whose
/// next submission would go before an earlier commit of another queue Metal submitted has no
/// room ([`sends_past`](Self::sends_past)).
fn has_room(&self, index: usize, run: u64) -> bool {
let fifo = &self.fifos[index];
let me = Self::rank(fifo, self.wants(index).map_or(u64::MAX, |(_, seq)| seq));
!(fifo.sends()).is_some_and(|first| self.sends_past(index, first))
&& room(&self.in_flight, run)
&& !(self.fifos.iter().enumerate()).any(|(other, fifo)| {
other != index
&& (self.wants(other)).is_some_and(|(run, seq)| {
Self::rank(fifo, seq) < me && room(&self.in_flight, run)
})
})
}
/// Where `fifo` stands for the device's room, for work of its committed at `seq`: by its turn
/// (its last submission, or 0 where it was idle at its head's commit), the earliest first,
/// then by commit order. So a command buffer committed to an idle queue goes before every
/// queue's backlog, as it would have gone at its commit with room for itself, behind only
/// other idle queues' earlier commits, in their commit order; and a backlog whose last piece
/// just completed outranks no queue that submitted before it.
fn rank(fifo: &Fifo, seq: u64) -> (u64, u64) {
(fifo.turn, seq)
}
/// The expected run of what the FIFO at `index` would submit with room, and the commit number
/// of its first command buffer: its group held, else its head's next piece or the command
/// buffer, where it is committed, with something for the GPU, its next segment's waits met,
/// and not held behind a cut command buffer it shares with. Nothing where that would go before
/// an earlier commit of another queue Metal submitted ([`sends_past`](Self::sends_past)), so
/// it holds no queue back.
fn wants(&self, index: usize) -> Option<(u64, u64)> {
let fifo = &self.fifos[index];
if (fifo.sends()).is_some_and(|first| self.sends_past(index, first)) {
return None;
}
let head = fifo.head();
if let Some(group) = &fifo.group {
let first = (group.leads.first().copied()).or(head.map(|head| head.seq));
return Some((group.run, first.unwrap_or(u64::MAX)));
}
let entry = fifo.entries.front().filter(|_| !fifo.blocked)?;
let pending = entry.pending.as_ref().filter(|_| entry.error.is_none())?;
let empty = pending.gpu.is_empty() && !self.changes.captured.waits_for(pending.seq);
let segment = &pending.gpu.segments[pending.next];
if empty || !ready(segment) {
return None;
}
let run = match pending.gpu.cut {
true => segment.work.run,
false => fifo.queue.expected_run().unwrap_or(u64::MAX),
};
Some((run, pending.seq))
}
/// Whether the FIFO at `index` holds a group that goes now: at teardown, where a host wait is
/// to come for one of its command buffers or one behind it, or with room
/// ([`has_room`](Self::has_room)). A round of the completion thread sends none: it holds what
/// it saw complete when it began, so held work waits for the round to end.
fn goes(&self, index: usize) -> bool {
let fifo = &self.fifos[index];
let past = || (fifo.sends()).is_some_and(|first| self.sends_past(index, first));
fifo.group.as_ref().is_some_and(|group| {
self.stop
|| (fifo.send_through >= group.first && !past())
|| self.has_room(index, group.run)
})
}
/// Marks each FIFO whose head, committed after a cut command buffer of another queue, the head
/// of its own with pieces not yet staged, shares a resource with it (`Gpu::shares`): held while
/// that command buffer's next piece is ready, until its every piece is staged, counted once a
/// head (`Metrics::shared_holds`). One whose next piece waits for an event not yet met holds
/// no other queue, as Metal's wait stops only its own queue: the signal it waits for may come
/// from the queue it would hold.
fn block_shared(&mut self, counters: &Counters) {
let cuts: Vec<(usize, u64)> = (self.fifos.iter().enumerate())
.filter_map(|(index, fifo)| {
let pending = fifo.head()?;
let next = pending.gpu.segments.get(pending.next);
(pending.gpu.cut && next.is_some_and(ready)).then_some((index, pending.seq))
})
.collect();
for index in 0..self.fifos.len() {
let shares = (self.fifos[index].head()).is_some_and(|pending| {
pending.next == 0
&& cuts.iter().any(|&(other, seq)| {
let cut = self.fifos[other].head().map(|cut| &cut.gpu);
other != index
&& seq < pending.seq
&& cut.is_some_and(|cut| pending.gpu.shares(cut))
})
});
let fifo = &mut self.fifos[index];
if shares && !fifo.blocked {
counters.count(Metric::SharedHolds);
}
fifo.blocked = shares;
}
}
/// The first command buffer not yet scheduled of the FIFO at `index`, whose head waits for
/// room, every wait of its met: scheduled now, as it would be in a group held, its scheduled
/// handlers going to `joined`, and counted. One that presents a drawable (scheduled once
@@ -1866,13 +1660,14 @@ impl WorkState {
let Some(entry) = fifo.entries.iter_mut().find(|entry| entry.held.is_none()) else {
return;
};
if entry.sent_through(captured) {
fifo.send_through = fifo.send_through.max(entry.place);
return;
}
let Some(pending) = entry.pending.as_mut() else {
return;
};
let empty = pending.gpu.is_empty() && !captured.waits_for(pending.seq);
if entry.error.is_some() || empty || pending.gpu.presents() {
fifo.send_through = fifo.send_through.max(entry.place);
return;
}
let scheduled = std::mem::take(&mut pending.handlers.scheduled);
entry.cb.scheduled(now, !scheduled.is_empty());
if !scheduled.is_empty() {
@@ -1894,10 +1689,7 @@ impl WorkState {
return None;
}
let before = head.held.unwrap_or(u64::MAX);
// A cut command buffer's pieces go at the room's pace, never sent through: a waiter
// committed after it is held behind them as one that shares with it (`block_shared`).
let updates =
|pending: &Pending| !pending.gpu.cut && pending.gpu.fences.updates_for(waiter);
let updates = |pending: &Pending| pending.gpu.fences.updates_for(waiter);
let mut others = (self.fifos.iter().enumerate()).filter(|&(other, _)| other != index);
others.find_map(|(other, fifo)| {
let held = (fifo.entries.iter())
@@ -1919,11 +1711,8 @@ impl WorkState {
while (self.carried.front()).is_some_and(|&(_, value)| value <= completed) {
self.carried.pop_front();
}
while (self.in_flight.front()).is_some_and(|&(value, _)| value <= completed) {
self.in_flight.pop_front();
}
self.fifos.retain_mut(|fifo| {
while (fifo.in_flight.front()).is_some_and(|&value| value <= completed) {
while (fifo.in_flight.front()).is_some_and(|&(value, _)| value <= completed) {
fifo.in_flight.pop_front();
}
!(fifo.entries.is_empty() && fifo.group.is_none() && fifo.in_flight.is_empty())
@@ -1943,7 +1732,6 @@ impl WorkState {
joined: &mut Vec<Joined>,
ended: &mut Vec<Ended>,
) -> Step {
self.block_shared(counters);
let Some((index, waits)) = self.next_ready() else {
return Step::Idle;
};
@@ -1951,6 +1739,7 @@ impl WorkState {
self.hold(index, now, counters, joined);
return Step::Staged;
}
let stop = self.stop;
let fifo = &mut self.fifos[index];
let Some(entry) = fifo.entries.front_mut() else {
return Step::Idle;
@@ -1996,7 +1785,6 @@ impl WorkState {
}
return Step::Staged;
}
let cut = pending.gpu.cut;
let segment = &pending.gpu.segments[pending.next];
// A segment that leans on the leading copy for a buffer an earlier segment of the group
// wrote leads its group, so its copy follows the write (`crate::over`); so does one that
@@ -2018,8 +1806,7 @@ impl WorkState {
let leads = pending.next == 0;
if let (true, Some(group)) = (leads, &fifo.group) {
let after = group.leads.last().copied().unwrap_or(0);
if cut
|| !group.takes(run, retired)
if !group.takes(run, retired)
|| (!group.wrote.is_empty()
&& (self.changes.captured).names_written(after, pending.seq, &group.wrote))
{
@@ -2049,14 +1836,8 @@ impl WorkState {
wrote: Vec::new(),
reached: Vec::new(),
});
// A cut command buffer's piece goes alone, its run its dispatches' (`crate::piece`).
let piece = match (cut, leads) {
(true, _) => segment.work.run,
(false, true) => run.unwrap_or(u64::MAX),
(false, false) => 0,
};
group.run = group.run.saturating_add(piece);
if leads {
group.run = group.run.saturating_add(run.unwrap_or(u64::MAX));
group.starts.push(group.segments.len());
group.leads.push(pending.seq);
if group.seen != retired {
@@ -2095,25 +1876,10 @@ impl WorkState {
// once the command buffer is scheduled.
let signals = !staged.signals.is_empty();
group.segments.push(staged);
pending.gpu.segments[pending.next].sent = true;
pending.next += 1;
// A cut command buffer whose later pieces wait only for room is scheduled with its first,
// as one held for room is ([`hold`](Self::hold)).
if cut && leads && entry.held.is_none() && !pending.gpu.presents() {
let later = &pending.gpu.segments[pending.next..];
if later.iter().all(|segment| segment.waits.is_empty()) {
let scheduled = std::mem::take(&mut pending.handlers.scheduled);
entry.cb.scheduled(now, !scheduled.is_empty());
if !scheduled.is_empty() {
joined.push((Arc::clone(&entry.cb), scheduled));
}
self.holds += 1;
entry.held = Some(self.holds);
}
}
if pending.next < pending.gpu.segments.len() {
group.partial = true;
return if signals || cut {
return if signals {
Step::Goes(index)
} else {
Step::Staged
@@ -2141,7 +1907,7 @@ impl WorkState {
// A command buffer held for room behind it joins it or, not taken, sends it first: with
// room the two would have been staged together.
let held_behind = (fifo.entries.front()).is_some_and(|entry| entry.held.is_some());
match signals || (self.goes(index) && !held_behind) {
match signals || (fifo.goes(stop) && !held_behind) {
true => Step::Goes(index),
false => Step::Staged,
}
@@ -2156,20 +1922,14 @@ impl WorkState {
core: &Core,
released: &AtomicU64,
) -> Option<(u64, Vec<Upload>, Batch)> {
// It goes before the pieces not yet submitted of another queue's cut command buffer.
let passes = (self.fifos.iter().enumerate())
.any(|(other, fifo)| other != index && fifo.head().is_some_and(|head| head.gpu.cut));
let fifo = &mut self.fifos[index];
let mut batch = fifo.group.take()?;
if passes {
core.counters.count(Metric::PiecesPassed);
}
// The bound again, with the expected run as it now stands: a completion since a join may
// have raised it.
batch.apart = apart(batch.starts.len() as u64, fifo.queue.expected_run());
// A group held that goes with room goes as a completion left it, whatever else would have
// sent it now.
batch.held &= room(&self.in_flight, batch.run);
batch.held &= room(&fifo.in_flight, batch.run);
if batch.held {
core.counters.held_start();
}
@@ -2218,12 +1978,7 @@ impl WorkState {
batch.take(taken);
self.progress += 1;
let value = self.progress;
fifo.in_flight.push_back(value);
self.in_flight.push_back((value, batch.run));
self.turns += 1;
fifo.turn = self.turns;
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
self.order.push(Arc::as_ptr(&fifo.queue) as usize);
fifo.in_flight.push_back((value, batch.run));
if batch.partial {
if let Some(Entry {
pending: Some(pending),
@@ -2245,46 +2000,15 @@ impl WorkState {
Some((value, uploads, batch))
}
/// The FIFO whose group goes at the end of a pass ([`goes`](Self::goes)): of those that go,
/// the one ranked first ([`rank`](Self::rank)).
/// The first FIFO whose group goes at the end of a pass ([`Fifo::goes`]).
fn unheld(&self) -> Option<usize> {
let rank = |index: usize| {
let fifo = &self.fifos[index];
Self::rank(fifo, self.wants(index).map_or(u64::MAX, |(_, seq)| seq))
};
(0..self.fifos.len())
.filter(|&index| self.goes(index))
.min_by_key(|&index| rank(index))
(self.fifos.iter()).position(|fifo| fifo.goes(self.stop))
}
/// Whether `pending`, a command buffer of the FIFO at `index`, would go before an earlier
/// commit of another queue that Metal had submitted at its commit, the first command buffer
/// not yet submitted of a queue committed to it idle ([`Fifo::idle_first`]), that holds a
/// buffer or texture `pending` holds, by the ids the hazards track them by, or where either
/// reaches memory outside its resources. Metal's hazard tracking orders `pending` after that
/// one, so `pending` waits for its submission: it is not staged
/// ([`next_ready`](Self::next_ready)), its queue wants no room and has none
/// ([`wants`](Self::wants), [`has_room`](Self::has_room)), and no host wait sends it through
/// ([`goes`](Self::goes), [`waits_for_room`](Self::waits_for_room)). The room's order
/// ([`rank`](Self::rank)) then sends that one first. A group is asked by its first command
/// buffer ([`Fifo::sends`]): what joined it after that goes with it.
fn sends_past(&self, index: usize, pending: &Pending) -> bool {
(self.fifos.iter().enumerate()).any(|(other, holder)| {
let Some(first) =
(holder.idle_first()).filter(|first| other != index && first.seq < pending.seq)
else {
return false;
};
first.gpu.unbound
|| pending.gpu.unbound
|| pending.gpu.kept.meets(&first.gpu.kept.tracked())
})
}
/// The FIFO, other than the one at `index`, whose group goes now ([`goes`](Self::goes)) and
/// whose first command buffer was committed first, before every command buffer the group at
/// `index` holds ([`Fifo::first_committed`]): it goes before that group. So a group that goes
/// at a signal, as a host wait sends it, or at the end of a pass goes no sooner than another
/// The FIFO, other than the one at `index`, whose group goes now ([`Fifo::goes`]) and whose
/// first command buffer was committed first, before every command buffer the group at `index`
/// holds ([`Fifo::first_committed`]): it goes before that group. So a group that goes at a
/// signal, as a host wait sends it, or at the end of a pass goes no sooner than another
/// queue's group that goes now and was committed before it, the part of a command buffer
/// before its event wait included: Metal submits a command buffer committed to a queue with
/// nothing ahead of it at its commit, and its hazard tracking orders after that part a command
@@ -2294,7 +2018,7 @@ impl WorkState {
fn goes_before(&self, index: usize) -> Option<usize> {
let before = self.fifos[index].first_committed();
(0..self.fifos.len())
.filter(|&other| other != index && self.goes(other))
.filter(|&other| other != index && self.fifos[other].goes(self.stop))
.map(|other| (other, self.fifos[other].first_committed()))
.filter(|&(_, first)| first < before)
.min_by_key(|&(_, first)| first)
@@ -2330,35 +2054,14 @@ impl Fifo {
(self.entries.front()).and_then(|entry| entry.pending.as_ref())
}
/// The first command buffer of its next submission: its group's first, else its head.
fn sends(&self) -> Option<&Pending> {
match &self.group {
Some(group) => (group.finished.first().map(|(_, pending, _)| pending))
.or_else(|| self.head().filter(|_| group.partial)),
None => self.head(),
}
}
/// Its first command buffer not yet submitted with a part ready for the device, where the
/// queue has submitted nothing since a commit found it idle (its turn 0): staged in its group,
/// or its next segment's waits met. Metal submits a command buffer committed to a queue with
/// nothing ahead of it at its commit (the runtime README's M3 Max rows). One that has ended,
/// holds nothing for the GPU, or waits for an event not yet met has no part ready: Metal's wait
/// stops only its own queue.
fn idle_first(&self) -> Option<&Pending> {
if self.turn != 0 {
return None;
}
match &self.group {
Some(group) => (group.finished.first().map(|(_, pending, _)| pending))
.or_else(|| self.head().filter(|_| group.partial)),
None => {
let entry = self.entries.front().filter(|entry| entry.error.is_none())?;
let head = entry.pending.as_ref()?;
let next = head.gpu.segments.get(head.next);
(!head.gpu.is_empty() && next.is_some_and(ready)).then_some(head)
}
}
/// Whether it holds a group that goes now: at teardown (`stop`), where a host wait is to come
/// for one of its command buffers or one behind it, or with room ([`room`]). A round of the
/// completion thread sends none: it holds what it saw complete when it began, so held work
/// waits for the round to end.
fn goes(&self, stop: bool) -> bool {
self.group.as_ref().is_some_and(|group| {
stop || self.send_through >= group.first || room(&self.in_flight, group.run)
})
}
/// The place in the commit order of the first command buffer its group holds: the first that
@@ -2415,7 +2118,7 @@ impl Fifo {
// Behind its queue's work, and, where it waits on a fence, behind the last
// submission that updates it, as Metal's fence wait holds a command buffer with no
// work too (`crate::fence`).
let in_flight = self.in_flight.back().copied().unwrap_or(0);
let in_flight = self.in_flight.back().map_or(0, |&(value, _)| value);
let waited = pending.gpu.fences.waited_through();
pending.value = pending.value.max(in_flight).max(self.behind).max(waited);
self.behind = pending.value;
@@ -2624,9 +2327,9 @@ fn pass<'a>(core: &'a Core, mut state: MutexGuard<'a, WorkState>) -> MutexGuard<
}
}
let holds = |fifo: &Fifo| {
fifo.entries.front().is_some_and(|entry| {
entry.held.is_some() || entry.pending.as_ref().is_some_and(|head| head.gpu.cut)
})
fifo.entries
.front()
.is_some_and(|entry| entry.held.is_some())
};
if (state.fifos.iter()).all(|fifo| fifo.group.is_none() && !holds(fifo)) {
work.keeping.store(false, Ordering::SeqCst);
@@ -250,24 +250,17 @@ mod on_device {
/// (`use_heap`), reaching them through the resource IDs its argument buffer holds. Their last
/// handles drop after the commit, in three forms: while the command buffer waits on an event
/// (committed, not submitted), while long work committed ahead of it on its queue runs, and
/// 20 ms into a pass of about `PASS_RUN` of dispatches, while it samples them: as many as the
/// shorter GPU span of the first two forms' one dispatch gives (the first holds the kernel's
/// first use: on lavapipe about 25 times a dispatch of the pass), at most `SAMPLINGS`, the
/// drop asserted before the pass's GPU end. The heap's range and each form's GPU span beside
/// the drop's host time are printed, so a fault's address and time can be placed. A
/// texture's going waits for the command buffers committed before its release
/// (`crate::memory::Wait`): each completes with no error, and its pass reads the textures as
/// they were.
/// 20 ms into a pass of `SAMPLINGS` dispatches, while it samples them. The heap's range and
/// each form's GPU span beside the drop's host time are printed, so a fault's address and
/// time can be placed. A texture's going waits for the command buffers committed before its
/// release (`crate::memory::Wait`): each completes with no error, and its pass reads the
/// textures as they were.
#[cfg(any(m2v_cpu_icd, all(m2v_gpu, m2v_gpu_hazards)))]
#[test]
fn every_device_keeps_heap_textures_read_through_their_indices_past_their_release() {
/// The most dispatches of the pass that samples while its textures drop: about 200 ms on
/// an RTX 3090.
/// The dispatches of the pass that samples while its textures drop: about 200 ms on an
/// RTX 3090.
const SAMPLINGS: u32 = 40_000;
/// The GPU run, in nanoseconds, that pass is sized to, from the GPU spans of the first
/// two forms' one dispatch: on a CPU device under load the fixed `SAMPLINGS` ran past the
/// tests' patience.
const PASS_RUN: u64 = 200_000_000;
use crate::tests::command::on_device::shared_event;
use crate::tests::compute::on_device::step;
use crate::tests::gpu_span::on_device::{dispatches_for, long, words, WORDS};
@@ -354,7 +347,6 @@ mod on_device {
let count = dispatches_for(name, &queue, &ahead_state, &busy, 200_000_000);
let event = shared_event(&device);
let mut unlike = Vec::new();
let (mut samplings, mut one) = (SAMPLINGS, u64::MAX);
for (round, form) in ["at an event wait", "behind long work", "while it runs"]
.into_iter()
.enumerate()
@@ -381,7 +373,7 @@ mod on_device {
encoder.set_buffer(Some(&out), 0, 1).expect("out");
(encoder.set_sampler_state(Some(&sampler), 0)).expect("the sampler");
(encoder.use_heap(heap.block)).expect("the heap");
for _ in 0..if round == 2 { samplings } else { 1 } {
for _ in 0..if round == 2 { SAMPLINGS } else { 1 } {
(encoder.dispatch_threadgroups([1, 1, 1], [SIDE, SIDE, 1]))
.unwrap_or_else(|error| panic!("{name}: {error}"));
}
@@ -416,23 +408,6 @@ mod on_device {
"{name}: {form}: dropped at {dropped}, the pass's GPU span {start}..{end}; \
loss {loss:?}, error {error:?}, read {read:?}"
);
if round < 2 && end > start {
one = one.min(end - start);
samplings = u32::try_from(PASS_RUN / one)
.map_or(SAMPLINGS, |count| count.clamp(1, SAMPLINGS));
println!(
"{name}: {form}: one sampling dispatch's GPU span {} ns: the pass while it \
runs takes {samplings} dispatches",
end - start
);
}
if round == 2 && loss.is_none() && error.is_none() {
assert!(
dropped < end,
"{name}: {form}: the textures dropped at {dropped}, after the pass's GPU \
end {end}"
);
}
if loss.is_some() || error.is_some() || read != want {
unlike.push(form);
}
+21 -114
View File
@@ -87,9 +87,12 @@ fn a_stage_span_lands_in_its_power_of_two_bucket() {
#[test]
fn a_command_buffer_joins_a_group_only_within_the_bound_tested_again_at_the_send() {
let ms = 1_000_000;
assert!(joins(ms, 1, Some(ms)), "within the bound");
assert!(joins(ms, 1, Some(GROUP_RUN - ms)), "at the bound");
assert!(!joins(ms, 1, Some(GROUP_RUN - ms + 1)), "past it: alone");
assert!(joins(10 * ms, 1, Some(ms)), "within the bound");
assert!(joins(10 * ms, 1, Some(GROUP_RUN - 10 * ms)), "at the bound");
assert!(
!joins(10 * ms, 1, Some(GROUP_RUN - 10 * ms + 1)),
"past it: alone"
);
assert!(!joins(0, 0, None), "an unknown run: alone");
assert!(
!joins(u64::MAX, 1, Some(1)),
@@ -139,7 +142,6 @@ pub(crate) mod on_device {
use crate::buffer::BufferObject;
use crate::device::lock;
use crate::submit::{GROUP_RUN, IN_FLIGHT, UNSEEN_JOINS};
use crate::tests::compute::on_device::step;
use crate::tests::devices_of_the_cfgs_kind;
use crate::{
host_time, AllocationId, AllocationInfo, Block, BlockMappings, Buffer, CommandBuffer,
@@ -1064,20 +1066,6 @@ pub(crate) mod on_device {
("plain", &plain, (&a, &b), 1),
("shared", shared.as_event(), (&c, &d), 3),
] {
// Each queue's expected run 1 ms, the test's own input, set as each round begins,
// so the device has room for the round's three submissions at once
// (`submit::room`) while Busy's gate holds every completion. The runs the round
// before measured would stand in its place (`QueueInner::ran`, rising at once to a
// longer run): past 2 ms, on a loaded device, `next` would have no room, and no
// completion would come to make it. Printed, the runs it replaces.
for queue in [&queue, &signaller_queue] {
let probe = queue.command_buffer().expect("a command buffer");
println!(
"{name}: {label}: a queue's run before the round's input {:?} ns",
probe.queue().expected_run()
);
probe.queue().set_run_for_test(BODY_RUN);
}
let busy = Busy::new(&device);
let signaller = signaller_queue.command_buffer().expect("a command buffer");
(signaller.encode_signal_event(event, 1)).expect("a signal");
@@ -1134,7 +1122,7 @@ pub(crate) mod on_device {
/// Links of a chain on two queues, each but the first waiting for the shared event's value the
/// link before it signals, then copying the words of every link before it from that link's
/// buffer, writing its own after them, and signalling the next, all behind busy work: each
/// queue's expected run 1 ms, so the device has room for the three links (`submit::room`), every link goes
/// queue's expected run 1 ms, so each has room for its links (`submit::room`), every link goes
/// to the driver and reads `Scheduled`, its scheduled handler run, before the first has run,
/// and the submit thread holds none of them for a value. No semaphore wait is
/// submitted for a link: once the busy work ends, the links complete in order, and each holds
@@ -1147,7 +1135,7 @@ pub(crate) mod on_device {
/// held.
#[test]
fn every_device_submits_a_shared_event_chain_across_two_queues_before_its_first_link_runs() {
const LINKS: u32 = IN_FLIGHT as u32;
const LINKS: u32 = 5;
each_device("event_chain", |name, _, device| {
let mut arena = Arena::new(&device);
let buffers: Vec<Buffer> = (0..=LINKS).map(|_| arena.buffer()).collect();
@@ -1817,15 +1805,15 @@ pub(crate) mod on_device {
}
}
/// A write on a queue with nothing running is submitted when the device has room, before a
/// command buffer of another idle queue committed after it, so that one reads the write, with
/// no fence or event between them: every queue's submissions go to the device's one
/// `VkQueue`, each segment ending in a barrier that reaches the commands after it, and of
/// idle queues the device's room goes in commit order (`WorkState::rank`). A third queue's
/// busy work holds the GPU and fills the device's room, so both wait, scheduled, and neither
/// runs before both are submitted. Metal's hazard tracking orders the same pair of tracked
/// buffers where the writer's queue has nothing ahead of it, and not where its queue's own
/// work is ahead of it (the README's "Queues, command buffers and events").
/// A write on a queue with nothing running is submitted at once, so a command buffer of
/// another queue committed after it reads the write, with no fence or event between them:
/// every queue's submissions go to the device's one `VkQueue`, each segment ending in a barrier
/// that reaches the commands after it. A third queue's busy work holds the GPU, so neither
/// runs before both are submitted, and puts as many submissions in flight across the device
/// as a queue keeps before it groups: the writer's queue groups on its own count alone.
/// Metal's hazard tracking orders the same pair of tracked buffers where the writer's queue
/// has nothing ahead of it, and not where its queue's own work is ahead of it (the README's
/// "Queues, command buffers and events").
#[test]
fn every_device_submits_a_write_on_an_idle_queue_before_another_queues_later_read() {
each_device("command_cross_queue_order", |name, _, device| {
@@ -1834,23 +1822,16 @@ pub(crate) mod on_device {
let (busy_queue, writer_queue, reader_queue) =
(queue(&device), queue(&device), queue(&device));
behind_busy(name, &device, &busy_queue, |busy, _, _| {
let sent = || device.counters().metrics().submissions;
let before = sent();
let writer = queue_fill(&writer_queue, &written, 0x5a5a_5a5a);
within(name, || writer.status() != CommandBufferStatus::Committed);
within(name, || sent() > before);
let reader = reader_queue.command_buffer().expect("a command buffer");
let mut blit = reader.blit_command_encoder().expect("an encoder");
(blit.copy_from_buffer_to_buffer(&written, 0, &read, 0, 256)).expect("a copy");
blit.end_encoding();
reader.commit().expect("a commit");
within(name, || reader.status() != CommandBufferStatus::Committed);
let work = &device.core().work;
assert_eq!(
(
work.in_flight(writer.queue()),
work.in_flight(reader.queue())
),
((0, true), (0, true)),
"{name}: each held in a group for the device's room, nothing in flight"
);
within(name, || sent() > before + 1);
busy.open();
finished(name, &reader);
finished(name, &writer);
@@ -2035,80 +2016,6 @@ pub(crate) mod on_device {
});
}
/// Behind the busy gate ([`Busy::new`]), a long writer runs on one queue: six dispatches of
/// `x = x * 2 + 1`, two kernels of unknown rate in turn, so a runtime that cuts a command
/// buffer into pieces of a kernel's rate makes six, more than the device's room takes, and
/// the rest wait. A copy of what it writes is then committed to an idle queue, and a copy of
/// that copy to a third idle queue, with no host wait for either. The third queue ran one
/// command buffer before the gate, and its expected run is [`BODY_RUN`], the test's own input,
/// so the second copy fits the device's room behind the writer's pieces: a queue whose run is
/// unknown has room only with one submission in flight. Once the submit thread has
/// looked past the second copy (an empty command buffer committed after it is scheduled) the
/// gate opens. Metal submits the first copy at its commit, its queue having nothing ahead of
/// it, so its hazard tracking orders that copy after the writer and the second copy after it:
/// both read every step. The device's counts are printed once the copies were seen and once
/// all completed, so a run shows the shape it held, where its tree counts it: the cuts, the
/// copies held behind the writer, and the submissions that went before a cut command buffer's
/// pieces not yet submitted.
#[test]
fn every_device_copies_an_idle_queues_copy_of_a_long_write_into_a_later_sharer() {
each_device("command_sharer_behind_held", |name, _, device| {
let mut arena = Arena::new(&device);
let (written, copied, read) = (arena.buffer(), arena.buffer(), arena.buffer());
let kernels = [step(&device), step(&device)];
let (writing, copying, reading, probing) = (
queue(&device),
queue(&device),
queue(&device),
queue(&device),
);
let earlier = reading.command_buffer().expect("a command buffer");
(earlier.record_for_test(&[], |_, _| {})).expect("a command buffer's commands");
earlier.commit().expect("a commit");
finished(name, &earlier);
earlier.queue().set_run_for_test(BODY_RUN);
let busy = Busy::new(&device);
let writer = writing.command_buffer().expect("a command buffer");
let mut encoder =
(writer.compute_command_encoder(DispatchType::Serial)).expect("an encoder");
encoder.set_buffer(Some(&written), 0, 0).expect("a buffer");
for kernel in kernels.iter().cycle().take(6) {
encoder.set_compute_pipeline_state(kernel).expect("a state");
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
}
encoder.end_encoding();
writer.commit().expect("a commit");
within(name, || writer.status() != CommandBufferStatus::Committed);
let copy = |queue: &CommandQueue, from: &Buffer, to: &Buffer| {
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut blit = command_buffer.blit_command_encoder().expect("an encoder");
(blit.copy_from_buffer_to_buffer(from, 0, to, 0, 256)).expect("a copy");
blit.end_encoding();
command_buffer.commit().expect("a commit");
command_buffer
};
let first = copy(&copying, &written, &copied);
let second = copy(&reading, &copied, &read);
let probe = probing.command_buffer().expect("a command buffer");
probe.commit().expect("a commit");
within(name, || probe.status() != CommandBufferStatus::Committed);
let counts = device.counters().metrics();
println!("{name}: the device's counts once the copies were seen: {counts:?}");
busy.open();
for command_buffer in [&writer, &first, &second, &probe] {
finished(name, command_buffer);
assert_eq!(command_buffer.error(), None, "{name}");
}
let counts = device.counters().metrics();
println!("{name}: the device's counts once all completed: {counts:?}");
assert_eq!(
(word(&written), word(&copied), word(&read)),
(63, 63, 63),
"{name}: the write's six steps, the first copy and the second"
);
});
}
/// The expected run of queue A of [`two_queues`]: past `GROUP_RUN` with one more behind its
/// oldest submission, so it has room for two.
const LONG_RUN: u64 = 20_000_000;
@@ -191,11 +191,8 @@ pub(crate) mod on_device {
size: [4, 5, 6],
};
let mut per_dispatch = Vec::new();
// No region, a region set before each dispatch, and the setter with no dispatch. The
// kernel's rate 1 ps a threadgroup, the test's own input, so each arm's dispatches
// share one piece (`crate::piece`): no arm pays for a cut the others do not.
// No region, a region set before each dispatch, and the setter with no dispatch.
for (set, dispatched) in [(false, true), (true, true), (true, false)] {
state.inner.compiled.rate.set_for_test(1);
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = command_buffer
.compute_command_encoder(DispatchType::Serial)
@@ -364,14 +361,11 @@ pub(crate) mod on_device {
let expected: Vec<u32> = (0..WORDS as u32).map(chained).collect();
assert_eq!(words(&x), expected, "{name}: dependent");
// Independent: each dispatch has a buffer of its own. The kernel's rate 1 ps a
// threadgroup, the test's own input, so the dispatches share one piece
// (`crate::piece`) and the barriers counted are the hazards' alone; so too below.
// Independent: each dispatch has a buffer of its own.
let buffers: Vec<Buffer> = (0..count).map(|_| arena.buffer()).collect();
for buffer in &buffers {
write_words(buffer, |index| index);
}
state.inner.compiled.rate.set_for_test(1);
let before = device.counters().metrics();
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = command_buffer
@@ -395,7 +389,6 @@ pub(crate) mod on_device {
// Concurrent: barriers where asked for, and none at the hazards.
write_words(&x, |index| index);
state.inner.compiled.rate.set_for_test(1);
let before = device.counters().metrics();
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = command_buffer
@@ -445,11 +438,8 @@ pub(crate) mod on_device {
.unwrap_or_else(|error| panic!("{name}: {error}"))
};
// Two dispatches of `step`, each over one buffer: the barriers they take, the
// segment's end among them. The kernel's rate 1 ps a threadgroup, the test's own
// input, so the two dispatches share one piece (`crate::piece`) and the barriers
// counted are the hazards' and the one segment end's alone.
// segment's end among them.
let barriers = |buffers: [&Buffer; 2]| -> u64 {
state.inner.compiled.rate.set_for_test(1);
let before = device.counters().metrics();
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = command_buffer
+14 -17
View File
@@ -339,15 +339,14 @@ mod on_device {
});
}
/// A wait on a fence no encoder updated waits for nothing but the device's room, while queue A
/// holds in a group an update of another fence: on queue B, a command buffer with work after
/// the wait joins a group of its own, held while A's busy work fills the device's room, A's
/// group staying held too, and both go when the device has room; on a third queue an encoder
/// that only waits on it completes at once. The submissions are counted first, with no round
/// of the completion thread run since the wait's commit: a command buffer with nothing for the
/// GPU retires in one.
/// A wait on a fence no encoder updated waits for nothing, while queue A holds in a group an
/// update of another fence: on queue B, a command buffer with work after the wait goes in one
/// submission of its own, A's group staying held, and on a third queue an encoder that only
/// waits on it completes at once. The submissions are counted first, with no round of the
/// completion thread run since the wait's commit: a command buffer with nothing for the GPU
/// retires in one.
#[test]
fn every_device_runs_a_wait_on_a_fence_never_updated_when_the_device_has_room() {
fn every_device_runs_a_wait_on_a_fence_never_updated_at_once() {
each_device("fence_never_updated", |name, _, device| {
let (written, copy) = written_and_copy(&device);
let updated = device.new_fence();
@@ -379,19 +378,17 @@ mod on_device {
let all = after.submissions - before.submissions;
let (a_sent, a_held) = work.in_flight(updater.queue());
let a_sent = a_sent.saturating_sub(IN_FLIGHT) as u64;
let (b_sent, b_held) = work.in_flight(waiter.queue());
let b_sent = b_sent as u64;
let b_sent = work.in_flight(waiter.queue()).0 as u64;
let alone = all.saturating_sub(a_sent + b_sent);
let own = after.runtime_command_buffers - before.runtime_command_buffers;
let rounds = device.core().pool.rounds() - rounds;
assert_eq!(
(all, b_sent, b_held, a_sent, a_held, alone, own, rounds),
(0, 0, true, 0, true, 0, 0, 0),
"{name}: after the wait's commit, the submissions: all of them; B's, and \
whether B holds the wait's group for the device's room; A's group's, and \
whether A still holds it; the runtime's own uploads sent alone; the \
runtime's own command buffers in them (uploads, copy-ins); and the \
completion thread's rounds"
(all, b_sent, a_sent, a_held, alone, own, rounds),
(1, 1, 0, true, 0, 0, 0),
"{name}: after the wait's commit, the submissions: all of them; B's, the \
wait's; A's group's, and whether A still holds it; the runtime's own uploads \
sent alone; the runtime's own command buffers in them (uploads, copy-ins); \
and the completion thread's rounds"
);
let empty = c.command_buffer().expect("a command buffer");
let mut compute =
@@ -74,7 +74,6 @@ mod over_aliases;
mod over_causes;
mod pass;
mod patch;
mod pieces;
mod pixel_format_info;
mod pixel_interlock;
mod places;
@@ -1,736 +0,0 @@
//! Pieces, under a device cfg on every device of the cfg's kind: a command buffer's compute work
//! goes to the device's `VkQueue` in pieces, each expected to run for at most `GROUP_RUN`
//! (`crate::piece`), each a submission that waits for the device's room. A kernel's rate here is
//! the test's own input (`Rate::set_for_test`), set before each recording, so where a piece ends
//! does not depend on how fast the device runs. Behind the busy gate (`Busy::new`) nothing
//! submitted completes until the test opens it, so the device holds the two pieces its room
//! takes and the rest wait: a command buffer of another queue goes between two pieces, one that
//! shares a resource or a fence with a cut command buffer goes after its last (unless it signals
//! the event a later piece waits for, when it runs beside it, as Metal's does), the queue's own
//! next waits for every piece, a cut command buffer is scheduled at its first piece and kept by an
//! abandon, an empty or ended command buffer behind pieces waiting for room retires after them,
//! and an idle queue's commit waits for no more than the two pieces on the device
//! behind five queues' backlogs. Without the gate: the cuts counted, a kernel of unknown rate in
//! a piece of its own whose run sets its rate, a dispatch past the bound uncut, a blit encoder
//! after a full piece cut, and a command buffer of one piece, committed behind another queue's
//! long one, taking a rate that holds none of the long one's run.
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
mod on_device {
use crate::tests::command::on_device::{
each_device, fill, finished, shared_event, within, word, Arena, Busy, BODY_RUN,
};
use crate::tests::compute::on_device::{add, step};
use crate::tests::gpu_span::on_device::{dispatches_for, long, words, WORDS};
use crate::{
Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputeCommandEncoder,
ComputePipelineState, Device, DispatchType,
};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
/// A kernel's rate of 3 ms a threadgroup, in picoseconds: one dispatch of one threadgroup
/// fits a piece of 4 ms (`GROUP_RUN`), two do not, and the device's room takes two such
/// pieces, not three (`submit::room`).
const RATE: u64 = 3_000_000_000;
fn queue(device: &Device) -> CommandQueue {
device.new_command_queue(64).expect("a queue")
}
/// A compute encoder of `count` dispatches of `state` (`x = x * 2 + 1`), each of one
/// threadgroup, over `buffer`, left open.
fn steps(
command_buffer: &CommandBuffer,
state: &ComputePipelineState,
buffer: &Buffer,
count: u32,
) -> ComputeCommandEncoder {
let mut encoder =
(command_buffer.compute_command_encoder(DispatchType::Serial)).expect("an encoder");
encoder.set_compute_pipeline_state(state).expect("a state");
encoder.set_buffer(Some(buffer), 0, 0).expect("a buffer");
for _ in 0..count {
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
}
encoder
}
/// A command buffer of `queue` with `count` steps over `buffer`, `state`'s rate set to
/// `rate` first, committed.
fn cut(
queue: &CommandQueue,
state: &ComputePipelineState,
rate: u64,
buffer: &Buffer,
count: u32,
) -> CommandBuffer {
state.inner.compiled.rate.set_for_test(rate);
let command_buffer = queue.command_buffer().expect("a command buffer");
steps(&command_buffer, state, buffer, count).end_encoding();
command_buffer.commit().expect("a commit");
command_buffer
}
/// The word `count` steps leave in a word that held 0.
fn stepped(count: u32) -> u32 {
(1 << count) - 1
}
/// Of the queues' submissions so far, in order, which were `of`'s queue's.
fn order(device: &Device, of: &CommandBuffer) -> Vec<bool> {
device.core().work.submitted_by(of.queue())
}
/// The queues' submissions so far.
fn sent(device: &Device, queue: &CommandQueue) -> usize {
order(device, &queue.command_buffer().expect("a command buffer")).len()
}
/// Waits for `command_buffer` to complete, as Metal's would, with no error.
fn completed(name: &str, command_buffer: &CommandBuffer) {
finished(name, command_buffer);
assert_eq!(command_buffer.error(), None, "{name}");
}
/// The cuts: at 3 ms a threadgroup six dispatches go in six pieces, five cuts, each its own
/// submission; at 1.5 ms, two to a piece, three pieces and two cuts. Every step lands.
#[test]
fn every_device_cuts_a_command_buffer_into_pieces_of_the_bound() {
each_device("pieces_cuts", |name, _, device| {
let mut arena = Arena::new(&device);
let state = step(&device);
let queue = queue(&device);
for (rate, pieces) in [(RATE, 6), (RATE / 2, 3)] {
let buffer = arena.buffer();
let (from, cuts) = (sent(&device, &queue), device.counters().metrics().cuts);
let command_buffer = cut(&queue, &state, rate, &buffer, 6);
completed(name, &command_buffer);
assert_eq!(
(
device.counters().metrics().cuts - cuts,
order(&device, &command_buffer).len() - from,
word(&buffer),
),
(pieces - 1, pieces as usize, stepped(6)),
"{name}: at {rate} ps a threadgroup, the cuts, the submissions and the word"
);
}
});
}
/// A command buffer of another queue goes between two pieces: A's command buffer of four
/// pieces has two on the device, the room's two, and B's fill, committed to an idle queue,
/// goes before A's third, counted once (`Metrics::pieces_passed`). Every step and the fill
/// land.
#[test]
fn every_device_runs_another_queues_command_buffer_between_two_pieces() {
each_device("pieces_passed", |name, _, device| {
let mut arena = Arena::new(&device);
let (stepped_buffer, filled) = (arena.buffer(), arena.buffer());
let state = step(&device);
let (a, b) = (queue(&device), queue(&device));
let busy = Busy::new(&device);
let from = sent(&device, &a);
let pieces = cut(&a, &state, RATE, &stepped_buffer, 4);
within(name, || order(&device, &pieces).len() == from + 2);
let passed = device.counters().metrics().pieces_passed;
let passer = b.command_buffer().expect("a command buffer");
fill(&passer, &filled, 7);
passer.commit().expect("a commit");
within(name, || passer.status() != CommandBufferStatus::Committed);
busy.open();
completed(name, &pieces);
completed(name, &passer);
assert_eq!(
order(&device, &passer)[from..],
[false, false, true, false, false],
"{name}: A's two pieces, B's fill, A's last two"
);
assert_eq!(
(
device.counters().metrics().pieces_passed - passed,
word(&stepped_buffer),
word(&filled),
),
(1, stepped(4), 7),
"{name}: the passes, the steps and the fill"
);
});
}
/// A command buffer of another queue that reads what a cut command buffer committed before
/// it writes goes after its last piece, held once (`Metrics::shared_holds`), though its queue
/// is idle, and reads every step.
#[test]
fn every_device_runs_a_read_of_a_cut_command_buffers_write_after_its_last_piece() {
each_device("pieces_shared", |name, _, device| {
let mut arena = Arena::new(&device);
let (written, read) = (arena.buffer(), arena.buffer());
let state = step(&device);
let (a, b) = (queue(&device), queue(&device));
let busy = Busy::new(&device);
let from = sent(&device, &a);
let pieces = cut(&a, &state, RATE, &written, 4);
within(name, || order(&device, &pieces).len() == from + 2);
let holds = device.counters().metrics().shared_holds;
let reader = b.command_buffer().expect("a command buffer");
let mut blit = reader.blit_command_encoder().expect("an encoder");
(blit.copy_from_buffer_to_buffer(&written, 0, &read, 0, 256)).expect("a copy");
blit.end_encoding();
reader.commit().expect("a commit");
within(name, || {
device.counters().metrics().shared_holds == holds + 1
});
busy.open();
completed(name, &pieces);
completed(name, &reader);
assert_eq!(
order(&device, &reader)[from..],
[false, false, false, false, true],
"{name}: A's four pieces, then B's read"
);
assert_eq!(word(&read), stepped(4), "{name}: the read sees every step");
});
}
/// A queue's next command buffer waits for every piece of its cut one: its copy reads every
/// step.
#[test]
fn every_device_runs_a_queues_next_command_buffer_after_every_piece() {
each_device("pieces_own_order", |name, _, device| {
let mut arena = Arena::new(&device);
let (written, read) = (arena.buffer(), arena.buffer());
let state = step(&device);
let a = queue(&device);
let busy = Busy::new(&device);
let from = sent(&device, &a);
let pieces = cut(&a, &state, RATE, &written, 4);
within(name, || order(&device, &pieces).len() == from + 2);
let next = a.command_buffer().expect("a command buffer");
let mut blit = next.blit_command_encoder().expect("an encoder");
(blit.copy_from_buffer_to_buffer(&written, 0, &read, 0, 256)).expect("a copy");
blit.end_encoding();
next.commit().expect("a commit");
busy.open();
completed(name, &pieces);
completed(name, &next);
assert_eq!(
(order(&device, &next).len() - from, word(&read)),
(5, stepped(4)),
"{name}: four pieces and the copy, which sees every step"
);
});
}
/// A wait on another queue for a fence a cut command buffer updates after its last
/// dispatch goes after that last piece, held once (`Metrics::shared_holds`), though it
/// shares no buffer with it.
#[test]
fn every_device_runs_a_fence_wait_after_the_last_piece_of_its_update() {
each_device("pieces_fence", |name, _, device| {
let mut arena = Arena::new(&device);
let (written, filled) = (arena.buffer(), arena.buffer());
let state = step(&device);
let fence = device.new_fence();
let (a, b) = (queue(&device), queue(&device));
let busy = Busy::new(&device);
state.inner.compiled.rate.set_for_test(RATE);
let updater = a.command_buffer().expect("a command buffer");
let mut encoder = steps(&updater, &state, &written, 4);
encoder.update_fence(&fence).expect("an update");
encoder.end_encoding();
let from = order(&device, &updater).len();
updater.commit().expect("a commit");
within(name, || order(&device, &updater).len() == from + 2);
let holds = device.counters().metrics().shared_holds;
let waiter = b.command_buffer().expect("a command buffer");
let mut blit = waiter.blit_command_encoder().expect("an encoder");
blit.wait_for_fence(&fence).expect("a wait");
(blit.fill_buffer(&filled, 0..4, 9)).expect("a fill");
blit.end_encoding();
waiter.commit().expect("a commit");
within(name, || {
device.counters().metrics().shared_holds == holds + 1
});
busy.open();
completed(name, &updater);
completed(name, &waiter);
assert_eq!(
(order(&device, &waiter)[from..].to_vec(), word(&filled)),
(vec![false, false, false, false, true], 0x0909_0909),
"{name}: A's four pieces, then B's wait and fill"
);
});
}
/// A command buffer of another queue that shares a buffer with a cut command buffer
/// committed before it, and signals the event a later piece of that command buffer waits
/// for, runs: Metal runs it beside the cut one, whose wait its signal then meets. Where it
/// has not completed within ten seconds, the host signals the event, so both finish and the
/// case fails instead of stalling.
#[test]
fn every_device_runs_the_signaller_of_a_cut_command_buffers_wait_though_it_shares() {
each_device("pieces_shared_signaller", |name, _, device| {
let mut arena = Arena::new(&device);
let (written, read, filled) = (arena.buffer(), arena.buffer(), arena.buffer());
let state = step(&device);
let event = shared_event(&device);
let (a, b) = (queue(&device), queue(&device));
state.inner.compiled.rate.set_for_test(RATE);
let waiter = a.command_buffer().expect("a command buffer");
steps(&waiter, &state, &written, 2).end_encoding();
(waiter.encode_wait_for_event(event.as_event(), 1)).expect("a wait");
fill(&waiter, &filled, 5);
waiter.commit().expect("a commit");
let signaller = b.command_buffer().expect("a command buffer");
let mut blit = signaller.blit_command_encoder().expect("an encoder");
(blit.copy_from_buffer_to_buffer(&written, 0, &read, 0, 256)).expect("a copy");
blit.end_encoding();
(signaller.encode_signal_event(event.as_event(), 1)).expect("a signal");
signaller.commit().expect("a commit");
let deadline = Instant::now() + Duration::from_secs(10);
while signaller.status() != CommandBufferStatus::Completed && Instant::now() < deadline
{
thread::sleep(Duration::from_millis(1));
}
let ran = signaller.status() == CommandBufferStatus::Completed;
if !ran {
event.set_signaled_value(1);
}
completed(name, &waiter);
completed(name, &signaller);
assert!(
ran,
"{name}: the signaller completes while the cut command buffer waits for its signal"
);
assert_eq!(
(word(&written), word(&filled)),
(stepped(2), 5),
"{name}: the steps and the fill land"
);
});
}
/// The dispatches of a kernel of unknown rate share a piece of their own: three of one such
/// kernel and then one of another make two pieces, one cut, and each piece's run sets its
/// kernel's rate. A dispatch past the bound is not cut, and a second after it is.
#[test]
fn every_device_puts_a_kernel_of_unknown_rate_in_a_piece_of_its_own() {
each_device("pieces_unknown_rate", |name, _, device| {
let mut arena = Arena::new(&device);
let (x, a, b, o) = (
arena.buffer(),
arena.buffer(),
arena.buffer(),
arena.buffer(),
);
let (stepping, adding) = (step(&device), add(&device));
let rate = |state: &ComputePipelineState| state.inner.compiled.rate.expected(1);
assert_eq!((rate(&stepping), rate(&adding)), (None, None), "{name}");
let queue = queue(&device);
let cuts = || device.counters().metrics().cuts;
let before = cuts();
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = steps(&command_buffer, &stepping, &x, 3);
encoder
.set_compute_pipeline_state(&adding)
.expect("a state");
for (slot, buffer) in [&a, &b, &o].into_iter().enumerate() {
(encoder.set_buffer(Some(buffer), 0, slot as u32)).expect("a buffer");
}
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
encoder.end_encoding();
command_buffer.commit().expect("a commit");
completed(name, &command_buffer);
assert_eq!(
cuts() - before,
1,
"{name}: the steps' piece, then the add's"
);
assert!(
rate(&stepping).is_some() && rate(&adding).is_some(),
"{name}: each kernel's rate set by its piece's run"
);
for (count, cut_before) in [(1, 0), (2, 1)] {
let before = cuts();
completed(name, &cut(&queue, &stepping, 5 * RATE, &x, count));
assert_eq!(cuts() - before, cut_before, "{name}: {count} of 15 ms");
}
assert_eq!(word(&x), stepped(6), "{name}");
});
}
/// A blit encoder that opens after a piece past the bound begins the next piece, and one
/// after a piece within it does not.
#[test]
fn every_device_cuts_before_a_blit_encoder_after_a_full_piece() {
each_device("pieces_blit", |name, _, device| {
let mut arena = Arena::new(&device);
let (x, filled) = (arena.buffer(), arena.buffer());
let state = step(&device);
let queue = queue(&device);
for (rate, cuts) in [(5 * RATE / 3, 1), (RATE / 3, 0)] {
state.inner.compiled.rate.set_for_test(rate);
let before = device.counters().metrics().cuts;
let command_buffer = queue.command_buffer().expect("a command buffer");
steps(&command_buffer, &state, &x, 1).end_encoding();
let mut blit = command_buffer.blit_command_encoder().expect("an encoder");
(blit.fill_buffer(&filled, 0..4, 5)).expect("a fill");
blit.end_encoding();
command_buffer.commit().expect("a commit");
completed(name, &command_buffer);
assert_eq!(
device.counters().metrics().cuts - before,
cuts,
"{name}: after a piece of {rate} ps"
);
}
assert_eq!(
(word(&x), word(&filled)),
(stepped(2), 0x0505_0505),
"{name}"
);
});
}
/// A cut command buffer is scheduled as its first piece is staged, its scheduled handler
/// run, while two of its four pieces wait for the device's room.
#[test]
fn every_device_schedules_a_cut_command_buffer_at_its_first_piece() {
each_device("pieces_scheduled", |name, _, device| {
let mut arena = Arena::new(&device);
let x = arena.buffer();
let state = step(&device);
let queue = queue(&device);
let busy = Busy::new(&device);
state.inner.compiled.rate.set_for_test(RATE);
let command_buffer = queue.command_buffer().expect("a command buffer");
steps(&command_buffer, &state, &x, 4).end_encoding();
let scheduled = Arc::new(AtomicUsize::new(0));
let counted = Arc::clone(&scheduled);
(command_buffer.add_scheduled_handler(move |_| {
counted.fetch_add(1, Ordering::SeqCst);
}))
.expect("a handler");
let from = order(&device, &command_buffer).len();
command_buffer.commit().expect("a commit");
within(name, || order(&device, &command_buffer).len() == from + 2);
within(name, || scheduled.load(Ordering::SeqCst) == 1);
assert_eq!(
(
command_buffer.status(),
order(&device, &command_buffer).len() - from
),
(CommandBufferStatus::Scheduled, 2),
"{name}: scheduled, with two pieces submitted and two waiting for room"
);
busy.open();
completed(name, &command_buffer);
assert_eq!(word(&x), stepped(4), "{name}");
});
}
/// An abandon of a queue whose cut command buffer is scheduled with pieces still waiting for
/// room ends nothing: every piece runs, and the command buffer completes.
#[test]
fn every_device_keeps_a_scheduled_cut_command_buffer_through_an_abandon() {
each_device("pieces_abandon", |name, _, device| {
let mut arena = Arena::new(&device);
let x = arena.buffer();
let state = step(&device);
let queue = queue(&device);
let busy = Busy::new(&device);
let command_buffer = cut(&queue, &state, RATE, &x, 4);
within(name, || {
command_buffer.status() == CommandBufferStatus::Scheduled
});
queue.abandon();
busy.open();
completed(name, &command_buffer);
assert_eq!(word(&x), stepped(4), "{name}: every piece ran");
});
}
/// Behind a cut command buffer whose later pieces wait for room, a command buffer of its
/// queue that holds nothing for the GPU is not held for room (`WorkState::hold`): it retires
/// behind the pieces, after them, as the room comes (`behind_pieces`).
#[test]
fn every_device_retires_an_empty_command_buffer_behind_pieces_waiting_for_room() {
behind_pieces("empty");
}
/// Behind a cut command buffer whose later pieces wait for room, a command buffer of its
/// queue ended before it went (a fill, enqueued, its queue abandoned, then committed) is not
/// held for room (`WorkState::hold`): it retires behind the pieces, after them, with its
/// error, as the room comes (`behind_pieces`).
#[test]
fn every_device_retires_an_ended_command_buffer_behind_pieces_waiting_for_room() {
behind_pieces("ended");
}
/// The two tests above, by `form`, "empty" or "ended", each in its own process. The window is
/// shown open first: the head scheduled with its first piece, two of its four pieces
/// submitted 50 ms on. The command buffer's commit and both completions are waited for on
/// another thread, within `BOUND` each; past it the test ends its process, as a submit
/// thread that spins holding the work lock lets no handle drop.
fn behind_pieces(form: &'static str) {
use std::sync::{mpsc, Mutex};
const BOUND: Duration = Duration::from_secs(10);
each_device(&format!("pieces_hold_{form}"), |name, _, device| {
let mut arena = Arena::new(&device);
let state = step(&device);
let (x, y) = (arena.buffer(), arena.buffer());
let queue = queue(&device);
let busy = Busy::new(&device);
let retired: Arc<Mutex<Vec<&'static str>>> = Arc::default();
let log = |command_buffer: &CommandBuffer, label: &'static str| {
let retired = Arc::clone(&retired);
(command_buffer.add_completed_handler(move |_| {
retired.lock().expect("the log").push(label);
}))
.expect("a completed handler");
};
let from = sent(&device, &queue);
state.inner.compiled.rate.set_for_test(RATE);
let pieces = queue.command_buffer().expect("a command buffer");
steps(&pieces, &state, &x, 4).end_encoding();
log(&pieces, "pieces");
pieces.commit().expect("a commit");
within(name, || order(&device, &pieces).len() == from + 2);
let behind = queue.command_buffer().expect("a command buffer");
log(&behind, form);
if form == "ended" {
fill(&behind, &y, 9);
behind.enqueue().expect("an enqueue");
queue.abandon();
}
// The window: the head scheduled with its first piece (held, `WorkState::step`),
// two of its four pieces on the device and, nothing completing behind the gate,
// the third waiting for room a while on.
thread::sleep(Duration::from_millis(50));
let window = (pieces.status(), order(&device, &pieces).len() - from);
println!("{name}: {form}: committed behind the head at {window:?} of 4 pieces");
assert_eq!(
window,
(CommandBufferStatus::Scheduled, 2),
"{name}: {form}: the head scheduled, its third piece waiting for room"
);
let (tell, told) = mpsc::channel();
let watcher = {
let (pieces, behind) = (pieces.clone(), behind.clone());
thread::spawn(move || {
let committed = behind.commit();
let _ = tell.send(format!("committed {committed:?}"));
let done = [&pieces, &behind].map(|cb| cb.wait_until_completed());
let _ = tell.send(format!("completed {done:?}"));
})
};
for wait in ["its commit", "both completions"] {
match told.recv_timeout(BOUND) {
Ok(line) => println!("{name}: {form}: {line}"),
Err(_) => {
eprintln!(
"{name}: {form}: {wait} not within {BOUND:?}: the submit thread \
holds the work lock behind a head waiting for room"
);
std::process::exit(101);
}
}
if wait == "its commit" {
busy.open();
}
}
watcher.join().expect("the watcher");
assert_eq!(
(pieces.error(), word(&x)),
(None, stepped(4)),
"{name}: {form}: every piece ran"
);
within(name, || retired.lock().expect("the log").len() == 2);
assert_eq!(
*retired.lock().expect("the log"),
["pieces", form],
"{name}: {form}: it retires behind the pieces"
);
drop(busy);
});
}
/// The shape of five queues with backlogs and a sixth, idle, committing one command buffer.
/// Each of the five submits a fill, the first piece of a cut command buffer whose next waits
/// for an event's value, and holds behind it a second of four pieces. The value set, the
/// device takes two pieces, its room, and the sixth queue, which last submitted before all of
/// them and expects a run of 2 ms, too long to go behind two pieces of 3 ms, commits a fill.
/// It goes at the device's next room, before any backlog's next piece, though the three queues
/// with nothing in flight hold command buffers committed before it: the pieces submitted
/// ahead of it are the two on the device when it committed. Every step lands.
#[test]
fn every_device_runs_an_idle_queues_commit_behind_two_pieces_of_five_backlogs() {
each_device("pieces_backlogs", |name, _, device| {
let mut arena = Arena::new(&device);
let state = step(&device);
let event = shared_event(&device);
let queues: Vec<CommandQueue> = (0..5).map(|_| queue(&device)).collect();
let buffers: Vec<Buffer> = (0..5).map(|_| arena.buffer()).collect();
let (idle, filled) = (queue(&device), arena.buffer());
let warm = idle.command_buffer().expect("a command buffer");
fill(&warm, &filled, 0);
warm.commit().expect("a commit");
completed(name, &warm);
warm.queue().set_run_for_test(2 * BODY_RUN);
state.inner.compiled.rate.set_for_test(RATE);
let base = order(&device, &warm).len();
let mut backlogs = Vec::new();
for (queue, buffer) in queues.iter().zip(&buffers) {
let head = queue.command_buffer().expect("a command buffer");
fill(&head, buffer, 0);
(head.encode_wait_for_event(event.as_event(), 1)).expect("a wait");
steps(&head, &state, buffer, 4).end_encoding();
head.commit().expect("a commit");
let next = queue.command_buffer().expect("a command buffer");
steps(&next, &state, buffer, 4).end_encoding();
next.commit().expect("a commit");
backlogs.extend([head, next]);
}
let work = &device.core().work;
within(name, || {
order(&device, &warm).len() == base + 5
&& (backlogs.iter()).all(|backlog| work.in_flight(backlog.queue()).0 == 0)
});
let busy = Busy::new(&device);
let from = base + 5;
event.set_signaled_value(1);
within(name, || order(&device, &warm).len() == from + 2);
let late = idle.command_buffer().expect("a command buffer");
fill(&late, &filled, 7);
late.commit().expect("a commit");
within(name, || late.status() != CommandBufferStatus::Committed);
busy.open();
completed(name, &late);
for command_buffer in &backlogs {
completed(name, command_buffer);
}
let submitted = order(&device, &late);
let ahead = submitted[from..].iter().position(|&late| late);
println!("{name}: {ahead:?} pieces submitted ahead of the idle queue's fill");
assert_eq!(
ahead,
Some(2),
"{name}: the pieces submitted ahead of the fill"
);
assert_eq!(
submitted.len() - from,
41,
"{name}: forty pieces and the fill"
);
for buffer in &buffers {
assert_eq!(word(buffer), stepped(8), "{name}");
}
assert_eq!(word(&filled), 7, "{name}");
});
}
/// A command buffer of one piece takes no pair of timestamps past its own, and its kernel's
/// rate from its own two, which hold no other submission's run: one dispatch of `add`
/// committed to a queue right behind another queue's command buffer of about 20 ms of
/// dispatches, uncut (its kernel's rate the test's own), submitted while the long one is on
/// the device (its submission seen before the long one's GPU end, and its own end after it),
/// takes a rate whose run is shorter than the long one's run left as it was submitted: a pair
/// begun at its submission, or anywhere earlier in the long one's run, would hold at least that
/// much. The rate it takes alone and the ratio are printed: on a CPU device the run itself
/// moves with the host's load.
#[test]
fn every_device_rates_a_one_piece_command_buffer_without_the_run_ahead_of_it() {
each_device("pieces_rate_behind", |name, _, device| {
let (long_state, add) = (step(&device), add(&device));
let words = words(&device);
let mut arena = Arena::new(&device);
let slots = [arena.buffer(), arena.buffer(), arena.buffer()];
let (first, second) = (queue(&device), queue(&device));
let count = dispatches_for(name, &first, &long_state, &words, 20_000_000);
// One dispatch of `add` on the second queue, its rate unknown, so its run sets it.
let one = || {
add.inner.compiled.rate.set_for_test(u64::MAX);
let command_buffer = second.command_buffer().expect("a command buffer");
let mut encoder = (command_buffer.compute_command_encoder(DispatchType::Serial))
.expect("an encoder");
encoder.set_compute_pipeline_state(&add).expect("a state");
for (index, buffer) in (0..).zip(&slots) {
encoder
.set_buffer(Some(buffer), 0, index)
.expect("a buffer");
}
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
encoder.end_encoding();
command_buffer
};
let rate = || (add.inner.compiled.rate.expected(1000)).expect("a rate");
// The first meets every first use; the second is the rate alone.
for _ in 0..2 {
let alone = one();
alone.commit().expect("a commit");
completed(name, &alone);
}
let alone = rate();
// Recorded, it holds its own pair of timestamps alone (`Building::stamp_piece`).
let stamps = &device.core().stamps;
let out = stamps.out_for_test();
let recorded = one();
assert_eq!(
stamps.out_for_test() - out,
1,
"{name}: the pairs a command buffer of one piece takes"
);
recorded.commit().expect("a commit");
completed(name, &recorded);
long_state.inner.compiled.rate.set_for_test(1);
let ahead = long(&first, &long_state, &words, count, WORDS);
let behind = one();
let second_sent = || {
order(&device, &behind)
.into_iter()
.filter(|&own| own)
.count()
};
let before = second_sent();
ahead.commit().expect("a commit");
behind.commit().expect("a commit");
assert_ne!(
ahead.status(),
CommandBufferStatus::Completed,
"{name}: the long command buffer still runs as the short one is committed"
);
// The short one's submission, seen on the host clock no earlier than it went.
within(name, || second_sent() > before);
let sent_at = crate::host_time();
completed(name, &ahead);
completed(name, &behind);
let (start, end) = (ahead.gpu_start_time(), ahead.gpu_end_time());
assert!(
sent_at < end && behind.gpu_end_time() >= end,
"{name}: the short one, submitted at {sent_at}, behind the long one's \
{start}..{end}: it ends at {}",
behind.gpu_end_time()
);
let behind_rate = rate();
let ratio = behind_rate as f64 / alone.max(1) as f64;
println!(
"pieces_rate_behind: {name}: alone {alone} ps a threadgroup, behind a {} us \
command buffer, submitted {} us before its GPU end, {behind_rate} ps: ratio \
{ratio:.2}",
(end - start.min(end)) / 1000,
(end - sent_at) / 1000
);
// One threadgroup: its run is its rate, in picoseconds.
assert!(
behind_rate / 1000 < end - sent_at,
"{name}: the rate behind the long command buffer, {behind_rate} ps a threadgroup, \
holds the {} us of the long one's run left as the short one was submitted",
(end - sent_at) / 1000
);
});
}
}
@@ -35,9 +35,6 @@
//! swapchain destroyed as the guide says, and a second made on the surface.
//! - One command buffer presents two drawables, each signalling a semaphore of its own; the same
//! semaphore for both, and the same drawable twice, are refused.
//! - Behind the busy gate, a command buffer that only presents retires after the pieces of its
//! queue's cut command buffer waiting for room, and a cut command buffer that presents goes as
//! the room another queue's pieces hold comes.
//! - What a drawable's texture is not is refused: another descriptor, format or usage than the
//! swapchain's images, an acquire or a present of a texture that is not a drawable's, a present
//! of a drawable not acquired, a second acquire, and a second present; a command buffer dropped
@@ -975,166 +972,6 @@ mod on_device {
});
}
/// Behind a cut command buffer of its queue whose later pieces wait for room, a command
/// buffer that only presents the drawable is never held for room (`WorkState::hold`): it
/// retires after the pieces, as the room comes (`presenting_by_room`).
#[test]
fn every_device_retires_a_presenting_command_buffer_behind_pieces_waiting_for_room() {
presenting_by_room("behind");
}
/// A cut command buffer that presents, its first piece waiting for the room another queue's
/// pieces hold, is never held for room (`WorkState::hold`): it goes as the room comes
/// (`presenting_by_room`).
#[test]
fn every_device_sends_a_cut_presenting_command_buffer_as_the_room_comes() {
presenting_by_room("cut");
}
/// The two tests above, by `form`, "behind" or "cut", each in its own process. Behind the
/// busy gate the window is shown open first: the head of the pieces holding the room
/// scheduled with its first, two of its four submitted 50 ms on. The presenting command
/// buffer's commit and both completions are waited for on another thread within `BOUND`
/// each; past it the test ends its process, as a submit thread that spins holding the work
/// lock lets no handle drop. The present signals a binary semaphore of the test's, which the
/// stand-in present waits on once both have completed.
fn presenting_by_room(form: &'static str) {
use crate::tests::command::on_device::{word, Busy};
use crate::tests::compute::on_device::step;
use crate::{CommandQueue, DispatchType};
use std::sync::mpsc;
const BOUND: Duration = Duration::from_secs(10);
/// A kernel's rate of 3 ms a threadgroup, in picoseconds, the test's own input: each
/// dispatch is a piece, and the device's room holds two (`tests::pieces`).
const RATE: u64 = 3_000_000_000;
each_device(&format!("present_hold_{form}"), |name, _, device| {
(device.grant_indices(IndexClass::Texture, 4096, 2)).expect("a grant");
let state = step(&device);
let mut arena = Arena::new(&device);
let info = swapchain(USAGE);
let stand_in = StandIn::new(&device, &info);
let render = descriptor(TextureUsage::RENDER_TARGET);
// SAFETY: the stand-in is made with `info` on the device, in the undefined layout,
// and is destroyed once every command buffer that used it has completed.
let drawable =
unsafe { device.new_drawable_texture(&render, Some(4097), stand_in.image, &info) }
.unwrap_or_else(|error| panic!("{name}: a drawable's texture: {error}"));
// A command buffer of `queue` of four steps (`x = x * 2 + 1`) over `x`, four pieces.
let pieces = |queue: &CommandQueue, x: &Buffer| {
state.inner.compiled.rate.set_for_test(RATE);
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = (command_buffer.compute_command_encoder(DispatchType::Serial))
.expect("an encoder");
encoder.set_compute_pipeline_state(&state).expect("a state");
encoder.set_buffer(Some(x), 0, 0).expect("a buffer");
for _ in 0..4 {
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
}
encoder.end_encoding();
command_buffer
};
// The submissions so far of `of`'s queue.
let own = |of: &CommandBuffer| {
let sent = device.core().work.submitted_by(of.queue());
sent.into_iter().filter(|&own| own).count()
};
// SAFETY: the stand-in is the test's, in the undefined layout, and nothing reads
// it.
unsafe { drawable.drawable_acquired() }
.unwrap_or_else(|error| panic!("{name}: an acquire: {error}"));
let queue = device.new_command_queue(4).expect("a queue");
let other = device.new_command_queue(4).expect("a queue");
let (x, y, out) = (arena.buffer(), arena.buffer(), arena.buffer());
let ready = semaphore(&device);
let busy = Busy::new(&device);
let retired: Arc<Mutex<Vec<&'static str>>> = Arc::default();
let log = |command_buffer: &CommandBuffer, label: &'static str| {
let retired = Arc::clone(&retired);
(command_buffer.add_completed_handler(move |_| {
retired.lock().expect("the log").push(label);
}))
.expect("a completed handler");
};
let room = pieces(if form == "behind" { &queue } else { &other }, &x);
log(&room, "pieces");
room.commit().expect("a commit");
within(name, || own(&room) == 2);
let presenting = match form {
"behind" => queue.command_buffer().expect("a command buffer"),
_ => pieces(&queue, &y),
};
log(&presenting, form);
// SAFETY: `ready` is a binary semaphore of the device, unsignalled with no signal or
// wait pending, which lives past the command buffer and only the stand-in present
// waits on; the drawable is acquired.
unsafe { presenting.present_drawable(&drawable, ready) }
.unwrap_or_else(|error| panic!("{name}: {form}: a present: {error}"));
// The window: the room's head scheduled with its first piece (held,
// `WorkState::step`), two of its four pieces on the device and, nothing
// completing behind the gate, the third waiting for room a while on.
thread::sleep(Duration::from_millis(50));
let window = (room.status(), own(&room));
println!("{name}: {form}: committed with the room's head at {window:?} of 4 pieces");
assert_eq!(
window,
(CommandBufferStatus::Scheduled, 2),
"{name}: {form}: the room's head scheduled, its third piece waiting for room"
);
let (tell, told) = mpsc::channel();
let watcher = {
let (room, presenting) = (room.clone(), presenting.clone());
thread::spawn(move || {
let committed = presenting.commit();
let _ = tell.send(format!("committed {committed:?}"));
let done = [&room, &presenting].map(|cb| cb.wait_until_completed());
let _ = tell.send(format!("completed {done:?}"));
})
};
for wait in ["its commit", "both completions"] {
match told.recv_timeout(BOUND) {
Ok(line) => println!("{name}: {form}: {line}"),
Err(_) => {
eprintln!(
"{name}: {form}: {wait} not within {BOUND:?}: the submit thread \
holds the work lock behind a head waiting for room"
);
std::process::exit(101);
}
}
if wait == "its commit" {
busy.open();
}
}
watcher.join().expect("the watcher");
let errors = (room.error(), presenting.error());
assert_eq!(errors, (None, None), "{name}: {form}: both completed");
within(name, || retired.lock().expect("the log").len() == 2);
let steps = (word(&x), (form == "cut").then(|| word(&y)));
assert_eq!(
steps,
(15, (form == "cut").then_some(15)),
"{name}: {form}: every step ran"
);
if form == "behind" {
assert_eq!(
*retired.lock().expect("the log"),
["pieces", form],
"{name}: {form}: it retires behind the pieces of its queue"
);
}
let shown = show(&device, stand_in.image, ready, &out);
assert_eq!(shown, Ok(()), "{name}: {form}: the stand-in present");
drop(busy);
drop(drawable);
// SAFETY: every submission that used the image, and that signalled or waited on the
// semaphore, has completed, and nothing uses either again.
unsafe {
stand_in.destroy(&device);
device.raw().device.destroy_semaphore(ready, None);
}
});
}
/// A refusal of `made`, which is to be refused.
fn refusal(name: &str, made: Result<impl Sized, Error>) -> Refusal {
match made {
@@ -134,11 +134,6 @@ entry:
kernels: &[&ComputePipelineState],
outs: &[Buffer],
) -> (u64, crate::Metrics) {
// Each kernel's rate 1 ps a threadgroup, the test's own input, so the dispatches share one
// piece (`crate::piece`) and the barriers counted are the dispatches' own.
for kernel in kernels {
kernel.inner.compiled.rate.set_for_test(1);
}
let counters = device.counters();
let before = counters.metrics();
let queue = device.new_command_queue(1).expect("a queue");
@@ -1106,11 +1106,6 @@ mod on_device {
let out = (device.new_texture(&d, Some(first + 1)))
.unwrap_or_else(|error| panic!("{label}: the output: {error}"));
let pair = |target: &crate::Buffer| -> u64 {
// Each kernel's rate 1 ps a threadgroup, the test's own input, so the two dispatches
// share one piece (`crate::piece`) and the barriers counted are the pair's own.
for state in [add, invert] {
state.inner.compiled.rate.set_for_test(1);
}
let before = counters.metrics().barriers;
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder =
-8
View File
@@ -379,14 +379,6 @@ impl StampPools {
Some(Pair { pool, first: 0 })
}
/// For the device tests: the pairs taken and not given back.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) fn out_for_test(&self) -> usize {
let state = lock(&self.state);
let made = state.pools.len().saturating_sub(1) * (POOL_QUERIES / 2) as usize;
made + state.next as usize - state.free.len()
}
/// Gives back `pair`, both its queries reset.
pub(crate) fn give_back(&self, pair: Pair) {
lock(&self.state).free.push(pair);
@@ -1399,7 +1399,6 @@ field metal2vulkan-runtime::Metrics.consumer_allocation_max_nanos pub consumer_a
field metal2vulkan-runtime::Metrics.consumer_allocation_nanos pub consumer_allocation_nanos: u64
field metal2vulkan-runtime::Metrics.consumer_allocations pub consumer_allocations: u64
field metal2vulkan-runtime::Metrics.creations_before_seed pub creations_before_seed: u64
field metal2vulkan-runtime::Metrics.cuts pub cuts: u64
field metal2vulkan-runtime::Metrics.dispatches_without_effects pub dispatches_without_effects: u64
field metal2vulkan-runtime::Metrics.emulated_simdgroup_dispatches pub emulated_simdgroup_dispatches: u64
field metal2vulkan-runtime::Metrics.event_holds pub event_holds: [u64; STAGE_BUCKETS]
@@ -1493,7 +1492,6 @@ field metal2vulkan-runtime::Metrics.over_copy_bytes_surface pub over_copy_bytes_
field metal2vulkan-runtime::Metrics.overlapping_copies_refused pub overlapping_copies_refused: u64
field metal2vulkan-runtime::Metrics.partial_variant_whole_grids pub partial_variant_whole_grids: u64
field metal2vulkan-runtime::Metrics.passes pub passes: u64
field metal2vulkan-runtime::Metrics.pieces_passed pub pieces_passed: u64
field metal2vulkan-runtime::Metrics.pipeline_cache_lock_wait_max_nanos pub pipeline_cache_lock_wait_max_nanos: u64
field metal2vulkan-runtime::Metrics.pipeline_cache_lock_wait_nanos pub pipeline_cache_lock_wait_nanos: u64
field metal2vulkan-runtime::Metrics.pipeline_cache_lock_waits pub pipeline_cache_lock_waits: u64
@@ -1530,7 +1528,6 @@ field metal2vulkan-runtime::Metrics.sampler_element_writes pub sampler_element_w
field metal2vulkan-runtime::Metrics.scheduled_to_gpu_start pub scheduled_to_gpu_start: [u64; STAGE_BUCKETS]
field metal2vulkan-runtime::Metrics.scheduled_to_gpu_start_behind_nanos pub scheduled_to_gpu_start_behind_nanos: u64
field metal2vulkan-runtime::Metrics.scheduled_to_gpu_start_nanos pub scheduled_to_gpu_start_nanos: u64
field metal2vulkan-runtime::Metrics.shared_holds pub shared_holds: u64
field metal2vulkan-runtime::Metrics.shared_long_reuses pub shared_long_reuses: u64
field metal2vulkan-runtime::Metrics.shared_remade_after_frees pub shared_remade_after_frees: u64
field metal2vulkan-runtime::Metrics.shared_take_allocations pub shared_take_allocations: SiteAllocations
Can't render this file because it is too large.