Runtime: the queue cut comes off development until its gates pass; the runtime is f979769faf's with stage input
What: the runtime crate goes back to f979769faf's, plus stage input. Its sources, its tests and api_signatures.tsv now equal those off979769fafwitha916e61185,f21db0934c,59e0a3f7caand58e9267b6capplied, file for file. This one new commit takes out the queue cut and everything built on it:56cdcb7075,929718d58f,9adc440ec6,f997dfa7d3,544f21b48f,c9c53b85cf,75773059e7,855eb86147,62183f55af,2ec8680181,eaba828dcd,600b38fda7,f268d3ca07,59481e60bd,e74f1480ed,5686863157andf0b6fff640. That covers piece.rs, tests/pieces.rs, the rate inputs of the barrier, heap and event tests, and the README's sections on pieces and the device's room. It also removes the parts of41b5038342that state the cut's cross-queue rule. Those are the README's "goes after it only once that one is submitted" sentence and its known-gap line on commit order between queues. Without the cut, a command buffer never goes ahead of an earlier-committed one it shares a tracked resource or a fence with, and the README says so again. Kept: - stage input, froma916e61185and f21db0934c; - its NaN rows for the XTX, the Iris Xe and the RTX 3090, from59e0a3f7caand 58e9267b6c; - the replay player's host wait for its own surface fill, from41b5038342: the player, its test and docs/REPLAY-STREAM.md; - the README's import-cost paragraph, fromf53ddc5917. Why: - development carries a confirmed stall. A cut command buffer waiting for room, with an empty or present-only command buffer behind it on its queue, spins the submit thread with the work lock held. Lavapipe, m3-max-68758. - It carries a candidate benchmark regression: the compute benchmark on the RX 7900 XTX scored 5.09% lower in the consumer's first pair (m3-max-68746 against m3-max-68738). Its second pair is still being read. - Stage input is a refusal a guest met. The consumer pins only exact commits on development, so stage input reaches it only through a development commit without the cut. The cut and its fixes go to steelbrain/cut, as this commit's revert plus the fixes. They come back to development as one series when the spin fix is green in all four forms, the XTX benchmark is within 3% in an alternated pair or the owner rules on the trade, and the wait-split sharer fix is in, if that turns out to be the cut's regression. Verified: - The runtime crate's tree and api_signatures.tsv equal steelbrain/pin-stagein (ce10a0d627). - The diff to it is the README's import-cost paragraph, the replay player's two files and docs/REPLAY-STREAM.md. - fmt, the refusal surface, the signatures table, the conformance coverage and the Metal coverage all check as current. - The quick check and the suites at this commit are named where it lands.
This commit is contained in:
1 parent
f0b6fff640
commit
e3d30c5101
22 files changed
+148
-1603
No files matched your search
@@ -1676,11 +1676,7 @@ made, with no lock, and never rewritten for layouts.
|
||||
image's memory alignment, takes them: NVIDIA lays a linear image's rows at the row
|
||||
rounded to 128 bytes, AMD to 256, so a pitch rounded to 256 is copied on NVIDIA; the Iris Xe
|
||||
lays them at the row itself (the answer is the texel's bytes), so a pitch rounded past the row
|
||||
is copied there. In a recorded play of a compute workload on the RTX 5080 Laptop, 80 textures of
|
||||
2448x3264 RGBA8 at 9,984 bytes a row, against the device's linear row of 9,856, took 206 copies
|
||||
of 3,835,938,720 bytes in three frames, 95.2% of the play's pitch-copy bytes; their cost on those
|
||||
frames was not resolved: the means read 0.9% more GPU busy time and 2.2% more wall time, with
|
||||
the two pairs of opposite sign (job m3-max-68398). A render
|
||||
is copied there. A render
|
||||
target over a buffer is copied on NVIDIA, whose linear tiling does not take it in place. A
|
||||
render target whose advertised subresource ends past its own rows or its buffer is copied too:
|
||||
llvmpipe (lavapipe) advertises a linear image's height rounded up to 4 rows and stores whole
|
||||
@@ -1837,28 +1833,14 @@ 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
|
||||
@@ -1868,61 +1850,26 @@ made, with no lock, and never rewritten for layouts.
|
||||
`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. 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, while one its queue holds, in a group or for room, may
|
||||
a command buffer of a queue with nothing running is submitted at once, ahead of every command
|
||||
buffer committed after it on any queue, 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
|
||||
@@ -2002,8 +1949,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.
|
||||
@@ -2071,8 +2018,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
|
||||
@@ -2125,11 +2072,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
|
||||
@@ -2165,25 +2107,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.
|
||||
- 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`
|
||||
@@ -2333,12 +2264,6 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
|
||||
arguments, reads zero in every threadgroup until the program writes it, as an Apple GPU reads it
|
||||
(the translator's null initializers, docs/API.md, "Threadgroup memory before the program writes
|
||||
it").
|
||||
- On the Intel UHD 630 under Windows (driver 101.2145), a kernel whose thread memory is in the
|
||||
private arena can return 1 or 2 wrong results in 512 from one long dispatch of its whole grid,
|
||||
intermittently: 2 failing runs of 31 alone at one build and 0 of 31 at the next (m3-max-68291,
|
||||
m3-max-68314), and 1 failing suite run of 11 (m3-max-68142). No other device the suites run on
|
||||
shows it, no split dispatch has shown it, and a kernel that checks each of its reads met no wrong
|
||||
one in 5 runs (m3-max-68367). The cause is not found.
|
||||
|
||||
## Compute encoders
|
||||
|
||||
@@ -3034,13 +2959,6 @@ subgroup mode is planned again keeping that mode pinned: the re-plan takes the p
|
||||
it weighs less than the emulated one by the stage weight; otherwise the emulated one goes on. The
|
||||
one taken compiles in the process where it is under the bound, and in the helper where it is not.
|
||||
|
||||
A fill's memory follows the threadgroup size its pipeline is made at, as the workgroup size is part
|
||||
of what the driver compiles. On the Iris Xe of RPL-P (ANV, Mesa 26.2.6) one emulated module of
|
||||
weight 46,491 took 794 MiB in 18.5 s at 1 thread a threadgroup and 2,630 MiB in 57.7 s at 32, the
|
||||
state's execution width; at 1,024, its `max_total_threads_per_threadgroup`, the helper passed the
|
||||
consumer's 3,072 MiB cap after 46 s and the pipeline was refused (job m3-max-68473, twice of two).
|
||||
So a kernel whose fill fits at its execution width can be refused at a larger threadgroup.
|
||||
|
||||
Render stages have a bound of their own, 99,109, as no helper compiles a render stage: a render
|
||||
pipeline with a stage past it is refused (Known gaps of render pipeline states), and one at or
|
||||
under it compiles in the process that runs the program with no cap, past the kernels' bound too.
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -44,7 +44,6 @@ mod memory;
|
||||
mod over;
|
||||
mod own;
|
||||
mod pass;
|
||||
mod piece;
|
||||
mod pipeline;
|
||||
mod pixel_format_info;
|
||||
mod places;
|
||||
|
||||
@@ -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()) };
|
||||
|
||||
@@ -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,
|
||||
@@ -583,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,
|
||||
@@ -601,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(),
|
||||
@@ -1163,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)))]
|
||||
@@ -1535,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,
|
||||
@@ -1547,16 +1512,11 @@ impl WorkState {
|
||||
&mut self.fifos[index]
|
||||
}
|
||||
|
||||
/// Takes `cb`'s place at its queue's end. A queue with nothing queued or in flight takes turn
|
||||
/// 0, as one that never submitted.
|
||||
/// 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);
|
||||
if fifo.entries.is_empty() && fifo.group.is_none() && fifo.in_flight.is_empty() {
|
||||
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,
|
||||
@@ -1623,10 +1583,7 @@ impl WorkState {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
@@ -1659,140 +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;
|
||||
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.
|
||||
fn has_room(&self, index: usize, run: u64) -> bool {
|
||||
let fifo = &self.fifos[index];
|
||||
let me = Self::rank(fifo, self.wants(fifo).map_or(u64::MAX, |(_, seq)| seq));
|
||||
room(&self.in_flight, run)
|
||||
&& !(self.fifos.iter().enumerate()).any(|(other, fifo)| {
|
||||
other != index
|
||||
&& (self.wants(fifo)).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 `fifo` 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.
|
||||
fn wants(&self, fifo: &Fifo) -> Option<(u64, u64)> {
|
||||
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];
|
||||
fifo.group.as_ref().is_some_and(|group| {
|
||||
self.stop || fifo.send_through >= group.first || 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
|
||||
@@ -1833,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())
|
||||
@@ -1858,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())
|
||||
@@ -1882,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;
|
||||
};
|
||||
@@ -1890,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;
|
||||
@@ -1935,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
|
||||
@@ -1957,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))
|
||||
{
|
||||
@@ -1988,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 {
|
||||
@@ -2034,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
|
||||
@@ -2080,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,
|
||||
}
|
||||
@@ -2095,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();
|
||||
}
|
||||
@@ -2157,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),
|
||||
@@ -2184,16 +2000,9 @@ 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(fifo).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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2225,6 +2034,16 @@ impl Fifo {
|
||||
(self.entries.front()).and_then(|entry| entry.pending.as_ref())
|
||||
}
|
||||
|
||||
/// 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)
|
||||
})
|
||||
}
|
||||
|
||||
/// Ends `entry` with `error` (its own, where it has one): behind the group held, which it
|
||||
/// joins to retire with; else once the queue's submissions in flight and the command buffers
|
||||
/// it ended before complete, at once where none is. One not committed ends at its commit.
|
||||
@@ -2268,7 +2087,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;
|
||||
@@ -2462,9 +2281,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);
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
@@ -1063,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");
|
||||
@@ -1133,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
|
||||
@@ -1146,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();
|
||||
@@ -1816,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| {
|
||||
@@ -1833,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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,630 +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, 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");
|
||||
});
|
||||
}
|
||||
|
||||
/// 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
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 =
|
||||
|
||||
@@ -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.
|
Reference in new issue
Block a user