Runtime: a restoring make waits for its restore's batch, not for a group's command buffers
A texture made in place over host memory's import on a unified device restores the bytes under its image inside the make, and waits for the progress value Work::flush gives: the submit thread's next submission's. Where a group goes at that turn, the flushed uploads went ahead of the group's command buffers in the same batch, with one signal at the batch's end, so the make waited for the guest's command buffers too. The consumer's walk on the Iris Xe saw restoring makes take up to 63.9 ms (9 spans of one photo-decode step, 67.4 ms in all) where the runtime's own makes take about 3.5 ms. Now a flush the host waits for (Work::flush, the staging waits, the surface and block ready waits) marks its uploads awaited. Where a group's submission takes them, WorkState::close gives them the progress value below the group's first, the value the flush returned, and submit has the last of them signal it: their batch ends there, ahead of the group's, in the same vkQueueSubmit2. The make waits for that batch alone. The pre-wait for the work already submitted is unchanged, so a group submitted between that wait and the flush still lands ahead of the restore on the queue, and the make still waits for it. Two cases keep the group's signal: - uploads that use memory another API shares (a surface plane or an exported block, held or read by the uploads' copies) signal no value of their own: that memory is the other API's again only at the first part's release, after the part's command buffers, so the wait is for the part's value, as before; - a batch signals a timeline semaphore once (Vulkan 1.4, section 7.2), so where nothing follows the uploads in their part, parts gives the part's value in place of theirs. A flush nobody waits for (the half-region staging flush, the release of held bytes) adds no batch: its uploads go with the group's command buffers as before. Docs: submit.rs's module doc and the flush docs; texture.rs's restore comment, RestoreFence and Buffer::new_texture; Block::wait_until_ready and Surface::wait_until_ready; the runtime README's restore paragraph, the fence's span, the known gap's span sentence and the two ready waits. RUNTIME_VERSION moves to the next number above development's: a restoring make, a getBytes read and the ready waits now end at the uploads' own batch. Tests: - restore_batch.rs each_device_returns_from_a_restoring_make_ahead_of_a_groups_command_buffers (the commit before this one) passes; - plane_parts.rs uploads_with_a_value_of_their_own_end_a_batch_that_signals_it_once: uploads that signal their own value end a batch of their own ahead of the group's segment, and alone in their part they signal the part's value once. runtime-sources.sha256 is unchanged (a92fe0a8): it covers none of the files this edits. Verified: - red, submit.rs at the commit before this one: restore_batch hangs and fails after 10 s, and plane_parts' new test fails (the uploads' value and the part's in one batch), on lavapipe (llvmpipe, LLVM 23.1.1, job m3-max-83370) and on the Iris Xe (RPL-P, ANV, job m3-max-83373); - green: restore_batch passes, the make returning with the fill's command buffer Scheduled, and plane_parts 4 of 4, on both; the runtime's suite on lavapipe 985 passed (4 skipped), job m3-max-83370, and on the Iris Xe 987 passed (4 skipped), job m3-max-83383; - job m3-max-83370: fmt, the signatures, clippy plain, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, rustdoc, the private rustdoc and the API reference check passed; the suites 3738 of 3739 passed (24 skipped), the one failure the golden table, a bless due on development; validation 1337 passed (3 skipped); conformance 1052 passed; the doctests passed.
This commit is contained in:
1 parent
b975709ed0
commit
126ee4fdf5
7 files changed
+210
-78
No files matched your search
@@ -870,10 +870,13 @@ match ("Importing memory from a host pointer shares ownership of the memory betw
|
||||
Vulkan implementation", section 11.2.6). So the image's one move home goes between a copy of the
|
||||
bytes bound under it into a Private block of the runtime's and a copy of them back, inside the
|
||||
make: the make has the upload that holds them go at once, in the submit thread's next submission,
|
||||
and returns once that submission completed. That submission is the runtime's own where no queue's
|
||||
group goes at that turn; otherwise it is a group's, the upload ahead of the group's command buffers
|
||||
(of its first part, where the group goes member by member), so the make waits for those command
|
||||
buffers too. The upload records a barrier from every earlier
|
||||
and returns once that upload completed. That submission is the runtime's own where no queue's group
|
||||
goes at that turn; otherwise it is a group's, the upload in a batch of its own ahead of the group's
|
||||
command buffers (of its first part, where the group goes member by member), in the same
|
||||
`vkQueueSubmit2`, which signals a progress value of its own, so the make waits for none of those
|
||||
command buffers. Where an upload that goes with it uses memory another API shares (an exported
|
||||
block or a surface), the make waits for the group's first part, whose release ends it. The upload
|
||||
records a barrier from every earlier
|
||||
command's writes (earlier submissions on the runtime's one queue among them) to the save, the save,
|
||||
the move in a barrier that waits for the save's reads, the write-back, and a barrier from it to
|
||||
every later command and the host. Nothing of the consumer's runs between the save and the
|
||||
@@ -901,12 +904,13 @@ The caller's fence. `Buffer::new_texture_fenced` and `Buffer::new_texture_in_pla
|
||||
texture as `new_texture` and `new_texture_in_place` do, and take a `RestoreFence`, two calls of the
|
||||
caller's that the runtime makes on this make alone, the one that restores, on the make's thread. In
|
||||
order: the make waits for the GPU work already submitted, calls `before`, adds the image's move home
|
||||
to the upload, flushes it, waits for the submission that carries it, and calls `after`. Between
|
||||
`before` and `after` the runtime saves, moves and writes back the block's bytes, so a host write to
|
||||
them in that span is lost, and a host read of them then may see them undefined. The span holds that
|
||||
whole submission, a group's command buffers too where one carries the upload. A caller that can have
|
||||
such a writer fences it there; a caller without one passes nothing, through the calls without a
|
||||
fence. Vulkan documents no form that keeps the bytes without the write-back: an acquire keeps a
|
||||
to the upload, flushes it, waits for the batch that carries it, and calls `after`. Between `before`
|
||||
and `after` the runtime saves, moves and writes back the block's bytes, so a host write to them in
|
||||
that span is lost, and a host read of them then may see them undefined. The span holds the upload's
|
||||
batch and the GPU work submitted ahead of it since the make's first wait. It holds no command buffer
|
||||
of a group that goes in the same submission, except where an upload in that batch uses memory
|
||||
another API shares. A caller that can have such a writer fences it there; a caller without one
|
||||
passes nothing, through the calls without a fence. Vulkan documents no form that keeps the bytes without the write-back: an acquire keeps a
|
||||
resource's bytes only after a release by their other owner (section 12.10.1, "Release exclusive
|
||||
ownership from the source instance or API", and section 7.7.6, the release and acquire of an
|
||||
ownership transfer), and the other owner of host memory is the host itself, whose accesses Vulkan
|
||||
@@ -977,9 +981,12 @@ opaque handle, `VK_QUEUE_FAMILY_FOREIGN_EXT` for a dma-buf), one buffer barrier
|
||||
`Metrics::external_releases`, in a command buffer of the runtime's own at the head of the
|
||||
runtime's submission that carries the next commit, ahead of every command buffer committed after
|
||||
the make. The make submits nothing and waits for nothing. Before the other API's first access,
|
||||
the consumer calls `Block::wait_until_ready()` on its own thread: it returns once that submission
|
||||
has completed, and has it go at once where it is not yet made, so it returns with no command
|
||||
buffer committed. It counts in `Metrics::surface_waits` as a surface's wait does (Exported
|
||||
the consumer calls `Block::wait_until_ready()` on its own thread: it has that submission go at once
|
||||
where it is not yet made, so it returns with no command buffer committed, and returns once the
|
||||
making has completed. Where the submission went before the call, that is once the submission has;
|
||||
where the call sends it, once the batch at its head that carries the making and the uploads has,
|
||||
ahead of the command buffers of a group that goes in it, which the call waits for only where an
|
||||
upload in that batch uses memory another API shares. It counts in `Metrics::surface_waits` as a surface's wait does (Exported
|
||||
surfaces). A block that is not exported is `Refusal::NotExported`.
|
||||
|
||||
**Each submission hands it over.** From its making the other API owns the block between the
|
||||
@@ -1117,9 +1124,9 @@ command buffer of the runtime's own at the head of the runtime's submission that
|
||||
commit, ahead of every command buffer committed after the make and of any acquire. That move may
|
||||
discard what the memory holds, so the other API accesses the surface's memory only once the
|
||||
making has completed: before the other API's first access, the consumer calls
|
||||
`Surface::wait_until_ready()` on its own thread, which returns once the making's submission has
|
||||
completed and has that submission go at once where it is not yet made. The runtime's own commands
|
||||
need no wait. Each call that waits, in either form, is counted in `Metrics::surface_waits`, with
|
||||
`Surface::wait_until_ready()` on its own thread, which has the making's submission go at once where
|
||||
it is not yet made and returns once the making has completed, as `Block::wait_until_ready()` does
|
||||
(above). The runtime's own commands need no wait. Each call that waits, in either form, is counted in `Metrics::surface_waits`, with
|
||||
its time in `surface_wait_nanos`, the longest in `surface_wait_max_nanos`, and in
|
||||
`surface_wait_submissions` the runtime's submissions it waited for: those not yet complete as it
|
||||
began, the one that carries the making among them unless it completed first (a submission made
|
||||
@@ -1501,8 +1508,9 @@ exported block, an exported surface in either form, and a Direct3D 11 import.
|
||||
nothing: the save and the write-back of the bytes bound under its image around its move out of
|
||||
the undefined layout, the layout Vulkan makes such an image start in
|
||||
(`VUID-vkBindImageMemory-memory-02989`, `VUID-VkImageCreateInfo-pNext-01443`) and lets that move
|
||||
discard the bytes. The make runs the pair in the submit thread's next submission, its own or a
|
||||
group's, and returns once it completed (Imported blocks), so a host write before the make, or after it returns, holds. A
|
||||
discard the bytes. The make runs the pair in the submit thread's next submission, its own or, in a
|
||||
batch of its own ahead of the group's command buffers, a group's, and returns once that batch
|
||||
completed (Imported blocks), so a host write before the make, or after it returns, holds. A
|
||||
host write to those bytes from another thread while the make runs may be lost, and a host read
|
||||
of them then may see them undefined, where Metal's make touches no bytes; the make waits for the
|
||||
GPU work already submitted, as well as for its own. A caller that can have such a writer gives
|
||||
@@ -1519,10 +1527,12 @@ exported block, an exported surface in either form, and a Direct3D 11 import.
|
||||
M3 Max (KosmicKrisp 26.3.1, job m3-max-82721), 603 and 877 on the Radeon 780M (RADV PHOENIX,
|
||||
Mesa 26.2.6, job m3-max-82720) and 3267 and 3504 on the Iris Xe (ANV, Mesa 26.2.6, job
|
||||
m3-max-82734); for 16 by 4 RGBA8Unorm texels 328 and 396, 120 and 169, and 507 and 934. The
|
||||
span holds the whole submission that carries the restore, so another thread's command buffers
|
||||
in it lengthen it. In place, every read of the texture is a read of a linear image, as of
|
||||
any texture over a Shared buffer in place, where the copy's image is optimal. The device type
|
||||
chooses because of what a frame costs each way. Measured with a 1920 by 1080 RGBA8Unorm texture
|
||||
span holds the batch that carries the restore and the GPU work submitted ahead of it since the
|
||||
make's first wait, so another thread's command buffers submitted in that time lengthen it. A
|
||||
group's command buffers that go in the same submission, behind the restore's batch, do not,
|
||||
except where an upload in that batch uses memory another API shares. In place, every read of the
|
||||
texture is a read of a linear image, as of any texture over a Shared buffer in place, where the
|
||||
copy's image is optimal. The device type chooses because of what a frame costs each way. Measured with a 1920 by 1080 RGBA8Unorm texture
|
||||
over host memory that the CPU writes whole each frame and a 1080p pass of 1 or 4 draws that read
|
||||
its every texel, the per-use copy against in place, in microseconds a frame (median of six
|
||||
alternating runs of 300 frames each):
|
||||
|
||||
@@ -309,9 +309,12 @@ impl Block {
|
||||
/// The block is the runtime's until its making: the release of its buffer to the other API's
|
||||
/// queue family, which [`Device::new_exported_block`] records for the runtime's first
|
||||
/// submission after the make and does not wait for. The other API's first access of the
|
||||
/// block comes after that submission. The call returns once it has completed, and has it go
|
||||
/// at once where it is not yet made, so it returns with no command buffer committed. The
|
||||
/// runtime's own commands need no such wait: the making goes ahead of every command buffer
|
||||
/// block comes after the making. The call has that submission go at once where it is not yet
|
||||
/// made, so it returns with no command buffer committed, and returns once the making has
|
||||
/// completed: once that submission has, where it went before the call; else once the batch
|
||||
/// at its head that carries the making and the uploads has, ahead of the command buffers of
|
||||
/// a group that goes in it, which the call waits for only where an upload in that batch uses
|
||||
/// memory another API shares. The runtime's own commands need no such wait: the making goes ahead of every command buffer
|
||||
/// committed after the make. Each call counts in
|
||||
/// [`Metrics::surface_waits`](crate::Metrics::surface_waits), with its time and the
|
||||
/// submissions it waited for.
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
//! one its waiters take as submitted. One that waits on a semaphore leads a new
|
||||
//! group, the one held going first. A group is one submission with one signal of the progress
|
||||
//! semaphore, or member by member one a member, which the completion thread follows in commit
|
||||
//! order; its queue counts it one submission in flight. A command buffer that takes no
|
||||
//! order; its queue counts it one submission in flight. Uploads the host waits for that go with a
|
||||
//! group ([`Work::flush`]) end a batch of their own ahead of the group's, in the same
|
||||
//! `vkQueueSubmit2`, with a signal of their own, the value below the group's, so that wait waits
|
||||
//! for none of the group's command buffers; where they use memory another API shares, the first
|
||||
//! part's release, after its command buffers, ends their wait. A command buffer that takes no
|
||||
//! submission of its own (one with nothing for the GPU that no copy-in waits for, or one ended
|
||||
//! with an error) and finds a
|
||||
//! group held joins it, and the group goes at once: what it retires behind is then submitted, so
|
||||
@@ -244,7 +248,9 @@ pub(crate) struct WorkState {
|
||||
/// and that submission's progress value ([`Work::settled`]). At most the command buffers
|
||||
/// the queues hold at once.
|
||||
carried: VecDeque<(u64, u64)>,
|
||||
/// The progress value of the last submission that took an upload, 0 before the first.
|
||||
/// The progress value at which the uploads the last submission to take any took complete:
|
||||
/// that submission's, or the one their own batch signals where the host waits for them
|
||||
/// ([`WorkState::close`]); 0 before the first.
|
||||
uploaded: u64,
|
||||
/// The upload recording: zero fills, copies and new textures' moves to a home layout, the
|
||||
/// calls made since the last commit, or before it where none has been made since
|
||||
@@ -253,8 +259,12 @@ pub(crate) struct WorkState {
|
||||
/// Uploads a later call or a flush ended the recording of, oldest first, not yet submitted.
|
||||
sealed: VecDeque<Upload>,
|
||||
/// How many of `sealed`, from the oldest, the next submission takes whatever its command
|
||||
/// buffers, alone where no group goes ([`Work::flush`]); 0 for none.
|
||||
/// buffers, alone where no group goes ([`flush`](WorkState::flush)); 0 for none.
|
||||
flush: usize,
|
||||
/// Whether the host waits for the uploads `flush` sends ([`Work::flush`]): where a group goes,
|
||||
/// they then end a batch of their own ahead of the group's, which signals a progress value of
|
||||
/// its own ([`close`](WorkState::close)).
|
||||
awaited: bool,
|
||||
/// The staging region, from the first copy on.
|
||||
region: Option<Region>,
|
||||
/// The Managed buffers' ranges named since the last commit.
|
||||
@@ -802,6 +812,7 @@ impl Work {
|
||||
upload: None,
|
||||
sealed: VecDeque::new(),
|
||||
flush: 0,
|
||||
awaited: false,
|
||||
region: None,
|
||||
changes: Changes::default(),
|
||||
dirty: false,
|
||||
@@ -1075,7 +1086,7 @@ impl Work {
|
||||
if !state.full(staging, released) {
|
||||
return Ok(state);
|
||||
}
|
||||
let value = state.flush();
|
||||
let value = state.flush_awaited();
|
||||
drop(state);
|
||||
self.wake();
|
||||
core.counters.count(Metric::UploadWaits);
|
||||
@@ -1285,7 +1296,7 @@ impl Work {
|
||||
};
|
||||
let value = match oldest {
|
||||
Oldest::Submitted(value) => value,
|
||||
Oldest::Pending => state.flush(),
|
||||
Oldest::Pending => state.flush_awaited(),
|
||||
// Another call finishes writing or reading its span: its release wakes this one.
|
||||
Oldest::Busy => {
|
||||
if state.lost() {
|
||||
@@ -1550,11 +1561,15 @@ impl Work {
|
||||
})
|
||||
}
|
||||
|
||||
/// Has every upload not yet submitted go at once, alone where no group goes: the progress
|
||||
/// value at which everything recorded into uploads so far has completed and is visible to the
|
||||
/// host, for [`Done::wait`](crate::complete::Done::wait).
|
||||
/// Has every upload not yet submitted go at once, in the submit thread's next submission:
|
||||
/// alone where no group goes, else in a batch of their own ahead of the group's, which
|
||||
/// signals a progress value of its own ([`WorkState::close`]). The progress value at which
|
||||
/// everything recorded into uploads so far has completed and is visible to the host, for
|
||||
/// [`Done::wait`](crate::complete::Done::wait): a wait for it waits for no command buffer of
|
||||
/// a group that goes in that submission, except where those uploads use memory another API
|
||||
/// shares, which is that API's again only at the release that ends the group's first part.
|
||||
pub(crate) fn flush(&self) -> u64 {
|
||||
let value = self.lock().flush();
|
||||
let value = self.lock().flush_awaited();
|
||||
self.wake();
|
||||
value
|
||||
}
|
||||
@@ -1632,7 +1647,7 @@ impl Work {
|
||||
// A submission takes the upload under this lock, setting the point as it does.
|
||||
match point.load(Ordering::Relaxed) {
|
||||
0 => {
|
||||
let value = state.flush();
|
||||
let value = state.flush_awaited();
|
||||
drop(state);
|
||||
self.wake();
|
||||
value
|
||||
@@ -1737,9 +1752,9 @@ impl WorkState {
|
||||
self.next_seq
|
||||
}
|
||||
|
||||
/// Has every upload not yet submitted go at once, alone where no group goes: the progress
|
||||
/// value at which everything recorded into uploads so far has completed. The upload
|
||||
/// recording ends here; a later call begins the next. The caller wakes the thread.
|
||||
/// Has every upload not yet submitted go at once, alone where no group goes, else with the
|
||||
/// group's command buffers, which no host waits for. The upload recording ends here; a later
|
||||
/// call begins the next. The caller wakes the thread.
|
||||
fn flush(&mut self) -> u64 {
|
||||
self.sealed.extend(self.upload.take());
|
||||
if self.sealed.is_empty() {
|
||||
@@ -1752,6 +1767,17 @@ impl WorkState {
|
||||
self.progress + 1
|
||||
}
|
||||
|
||||
/// [`flush`](Self::flush), for a caller that waits for the uploads on the host: where a group
|
||||
/// goes, they end a batch of their own ahead of the group's ([`Work::flush`]). The progress
|
||||
/// value at which everything recorded into uploads so far has completed. The caller wakes
|
||||
/// the thread.
|
||||
fn flush_awaited(&mut self) -> u64 {
|
||||
let value = self.flush();
|
||||
// Nothing to send is nothing to wait for.
|
||||
self.awaited |= self.flush > 0;
|
||||
value
|
||||
}
|
||||
|
||||
/// The upload a call made now records into: the one of the next commit, numbered as that
|
||||
/// commit will be. Where the upload recording holds calls made before the last commit, the
|
||||
/// call ends its recording ([`sealed`](WorkState::sealed)): it goes in the first submission
|
||||
@@ -1817,6 +1843,7 @@ impl WorkState {
|
||||
.count();
|
||||
let count = within.max(self.flush).min(self.sealed.len());
|
||||
self.flush = 0;
|
||||
self.awaited = false;
|
||||
let mut taken: Vec<Upload> = self.sealed.drain(..count).collect();
|
||||
if self.sealed.is_empty() {
|
||||
taken.extend(self.upload.take_if(|upload| upload.number <= through));
|
||||
@@ -1861,6 +1888,7 @@ impl WorkState {
|
||||
let mut dropped: Vec<Upload> = self.sealed.drain(..).collect();
|
||||
dropped.extend(self.upload.take());
|
||||
self.flush = 0;
|
||||
self.awaited = false;
|
||||
if let Some(region) = &mut self.region {
|
||||
for upload in &dropped {
|
||||
for &number in &upload.spans {
|
||||
@@ -2330,13 +2358,14 @@ impl WorkState {
|
||||
|
||||
/// The FIFO at `index`'s group, given the next progress value and the uploads of the commits
|
||||
/// up to its last command buffer's ([`take_uploads`](Self::take_uploads)): the submission it
|
||||
/// makes.
|
||||
/// makes, with the progress value its uploads signal ahead of the group where the host waits
|
||||
/// for a flush of them ([`Work::flush`]).
|
||||
fn close(
|
||||
&mut self,
|
||||
index: usize,
|
||||
core: &Core,
|
||||
released: &AtomicU64,
|
||||
) -> Option<(u64, Vec<Upload>, Batch)> {
|
||||
) -> Option<(u64, Option<u64>, Vec<Upload>, Batch)> {
|
||||
let fifo = &mut self.fifos[index];
|
||||
let mut batch = fifo.group.take()?;
|
||||
// The bound again, with the expected run as it now stands: a completion since a join may
|
||||
@@ -2398,14 +2427,23 @@ impl WorkState {
|
||||
// One progress value, or, where it goes member by member, one for each part, the last
|
||||
// part's the highest (`submit`): each command buffer retires at its own part's, so one
|
||||
// ahead of a long one is seen complete at its own end. The queue counts it one submission
|
||||
// in flight, at its last value.
|
||||
// in flight, at its last value. Where the host waits for a flush of the uploads not yet
|
||||
// submitted, they take the value below the group's first, which the flush gave: they
|
||||
// signal it at their own end, in a batch ahead of the group's in the same
|
||||
// `vkQueueSubmit2` (`submit`), so that wait waits for none of the group's command
|
||||
// buffers.
|
||||
let parts = match batch.apart {
|
||||
true => batch.starts.len() as u64 + 1,
|
||||
false => 1,
|
||||
};
|
||||
self.progress += parts;
|
||||
let alone = self.awaited;
|
||||
self.progress += parts + u64::from(alone);
|
||||
let value = self.progress;
|
||||
let first = value + 1 - parts;
|
||||
let uploaded = match alone {
|
||||
true => first - 1,
|
||||
false => value,
|
||||
};
|
||||
fifo.in_flight.push_back((value, batch.run));
|
||||
if batch.partial {
|
||||
if let Some(Entry {
|
||||
@@ -2428,8 +2466,8 @@ impl WorkState {
|
||||
.extend((batch.finished.iter()).map(|(_, pending, _)| (pending.seq, pending.value)));
|
||||
(self.carried)
|
||||
.extend((batch.finished.iter()).map(|(_, pending, _)| (pending.seq, pending.value)));
|
||||
let uploads = self.take_uploads(core, released, value, through);
|
||||
Some((value, uploads, batch))
|
||||
let uploads = self.take_uploads(core, released, uploaded, through);
|
||||
Some((value, alone.then_some(uploaded), uploads, batch))
|
||||
}
|
||||
|
||||
/// The first FIFO whose group goes at the end of a pass ([`Fifo::goes`]).
|
||||
@@ -2753,14 +2791,14 @@ fn pass<'a>(core: &'a Core, mut state: MutexGuard<'a, WorkState>) -> MutexGuard<
|
||||
}
|
||||
None => index,
|
||||
};
|
||||
let Some((value, uploads, batch)) = state.close(index, core, &work.released) else {
|
||||
let Some((value, alone, uploads, batch)) = state.close(index, core, &work.released) else {
|
||||
continue;
|
||||
};
|
||||
drop(state);
|
||||
// Scheduled handlers run here, with no lock held, before the submission they are in.
|
||||
scheduled(&mut joined);
|
||||
core.done.end_all(core, std::mem::take(&mut ended));
|
||||
submit(core, value, uploads, batch);
|
||||
submit(core, value, alone, uploads, batch);
|
||||
sent = true;
|
||||
state = work.lock();
|
||||
}
|
||||
@@ -2770,7 +2808,7 @@ fn pass<'a>(core: &'a Core, mut state: MutexGuard<'a, WorkState>) -> MutexGuard<
|
||||
if !uploads.is_empty() {
|
||||
state.progress = value;
|
||||
drop(state);
|
||||
submit(core, value, uploads, Batch::empty());
|
||||
submit(core, value, None, uploads, Batch::empty());
|
||||
state = work.lock();
|
||||
}
|
||||
}
|
||||
@@ -2936,8 +2974,14 @@ pub(crate) fn parts<P>(
|
||||
.semaphore(progress)
|
||||
.value(*at)
|
||||
.stage_mask(vk::PipelineStageFlags2::ALL_COMMANDS);
|
||||
// A batch signals a timeline semaphore once (Vulkan 1.4, section 7.2): where the
|
||||
// uploads' own value ends the part, nothing follows them, and the part's value takes its
|
||||
// place, above it.
|
||||
if let Some(last) = part.last_mut() {
|
||||
last.signals.push(signal);
|
||||
match (last.signals.iter_mut()).find(|own| own.semaphore == progress) {
|
||||
Some(own) => *own = signal,
|
||||
None => last.signals.push(signal),
|
||||
}
|
||||
}
|
||||
}
|
||||
parts
|
||||
@@ -2979,9 +3023,12 @@ fn scheduled(joined: &mut Vec<Joined>) {
|
||||
|
||||
/// Submits a group: its uploads first, oldest first, then each segment in order, the last
|
||||
/// signalling the progress `value`, and where it goes member by member each part before it its
|
||||
/// own lower value. Whatever was passed to `vkQueueSubmit2` goes to the completion thread as in
|
||||
/// flight; a failed submission is taken as a loss.
|
||||
fn submit(core: &Core, value: u64, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
/// own lower value. Where the host waits for a flush of the uploads, they end their own batch
|
||||
/// signalling `alone`, the value the flush gave, ahead of the group's batch in the same
|
||||
/// `vkQueueSubmit2` (`WorkState::close`), unless they use memory another API shares. Whatever was
|
||||
/// passed to `vkQueueSubmit2` goes to the completion thread as in flight; a failed submission is
|
||||
/// taken as a loss.
|
||||
fn submit(core: &Core, value: u64, alone: Option<u64>, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
let Batch {
|
||||
mut segments,
|
||||
mut finished,
|
||||
@@ -3100,6 +3147,9 @@ fn submit(core: &Core, value: u64, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
// Whether the uploads use memory another API shares, which is that API's again only at the
|
||||
// first part's release, after the part's command buffers.
|
||||
let mut shares = !read.is_empty();
|
||||
for item in read {
|
||||
item.keep(&mut handed[0]);
|
||||
}
|
||||
@@ -3112,6 +3162,7 @@ fn submit(core: &Core, value: u64, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
shares = true;
|
||||
if handed.is_empty() {
|
||||
handed.push(Vec::new());
|
||||
}
|
||||
@@ -3137,6 +3188,32 @@ fn submit(core: &Core, value: u64, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
..Staged::default()
|
||||
}),
|
||||
);
|
||||
// Uploads the host waits for signal their own value at their end, which ends their batch
|
||||
// (`infos`): a part of no command where none recorded anything. Uploads that use memory
|
||||
// another API shares signal none: the wait is for the first part's value, above theirs, past
|
||||
// its release, so the memory is the other API's again once it returns, as at a submission of
|
||||
// theirs alone.
|
||||
let mut ahead = uploads.len();
|
||||
if let Some(at) = alone.filter(|_| !shares) {
|
||||
let signal = vk::SemaphoreSubmitInfo::default()
|
||||
.semaphore(core.done.progress)
|
||||
.value(at)
|
||||
.stage_mask(vk::PipelineStageFlags2::ALL_COMMANDS);
|
||||
match ahead.checked_sub(1).and_then(|last| segments.get_mut(last)) {
|
||||
Some(last) => last.signals.push(signal),
|
||||
None => {
|
||||
let signals = vec![signal];
|
||||
segments.insert(
|
||||
0,
|
||||
Staged {
|
||||
signals,
|
||||
..Staged::default()
|
||||
},
|
||||
);
|
||||
ahead = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
let leads = match apart {
|
||||
true => &starts[..],
|
||||
false => &[][..],
|
||||
@@ -3144,7 +3221,7 @@ fn submit(core: &Core, value: u64, mut uploads: Vec<Upload>, batch: Batch) {
|
||||
let mut hands = Vec::new();
|
||||
let mut parts = self::parts(
|
||||
segments,
|
||||
uploads.len(),
|
||||
ahead,
|
||||
leads,
|
||||
(core.done.progress, value),
|
||||
&handed,
|
||||
|
||||
@@ -1670,9 +1670,12 @@ impl Surface {
|
||||
/// image moves out of the undefined layout into the general one, a move that may discard
|
||||
/// what the memory holds, and is released to the other API's queue family; in the copy form,
|
||||
/// the block's buffer is released ([`Block::wait_until_ready`]). So the other API's first
|
||||
/// access of the memory comes after that submission. The call returns once it has completed,
|
||||
/// and has it go at once where it is not yet made. The runtime's own commands need no such
|
||||
/// wait: the making goes ahead of every command buffer committed after the make. For a
|
||||
/// access of the memory comes after the making. The call has that submission go at once where
|
||||
/// it is not yet made, and returns once the making has completed: once that submission has,
|
||||
/// where it went before the call; else once the batch at its head that carries the making and
|
||||
/// the uploads has, ahead of the command buffers of a group that goes in it, which the call
|
||||
/// waits for only where an upload in that batch uses memory another API shares. The runtime's
|
||||
/// own commands need no such wait: the making goes ahead of every command buffer committed after the make. For a
|
||||
/// Direct3D 11 import (`Device::import_d3d11_surface`, on Windows), which Direct3D 11 made,
|
||||
/// the call returns at once. Each call that waits counts in
|
||||
/// [`Metrics::surface_waits`](crate::Metrics::surface_waits), with its time and the
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
//! at its head and releases them at its end, the release taking that part's last signals, its
|
||||
//! progress value among them, so it adds no submit info; a part that uses none takes neither,
|
||||
//! and a group sent as one part acquires once ahead of everything and releases once after
|
||||
//! everything.
|
||||
//! everything. Uploads that signal a progress value of their own end a batch of their own, and
|
||||
//! where nothing follows them in their part, the part's value takes the place of theirs, since a
|
||||
//! batch signals the progress semaphore once.
|
||||
|
||||
use crate::submit::{infos, parts, Staged};
|
||||
use ash::vk::{self, Handle};
|
||||
@@ -174,3 +176,35 @@ fn a_group_sent_as_one_part_hands_its_planes_over_once() {
|
||||
);
|
||||
assert!(asked.is_empty());
|
||||
}
|
||||
|
||||
/// Uploads the host waits for signal the progress value below the group's at their end
|
||||
/// (`WorkState::close`): a batch of their own ahead of the group's segments, or, where nothing
|
||||
/// follows them in their part, one signal of the part's value in place of theirs.
|
||||
#[test]
|
||||
fn uploads_with_a_value_of_their_own_end_a_batch_that_signals_it_once() {
|
||||
let uploads = |follow: bool| {
|
||||
let mut segments = vec![staged(90, &[PROGRESS])];
|
||||
if follow {
|
||||
segments.push(staged(1, &[]));
|
||||
}
|
||||
segments
|
||||
};
|
||||
let (parts, _) = shape(uploads(true), 1, &[], &[]);
|
||||
assert_eq!(
|
||||
parts,
|
||||
[(
|
||||
10,
|
||||
vec![
|
||||
(vec![90], vec![(PROGRESS, 1)]),
|
||||
(vec![1], vec![(PROGRESS, 10)])
|
||||
]
|
||||
)],
|
||||
"the uploads end a batch that signals their own value, ahead of the group's"
|
||||
);
|
||||
let (parts, _) = shape(uploads(false), 1, &[], &[]);
|
||||
assert_eq!(
|
||||
parts,
|
||||
[(10, vec![(vec![90], vec![(PROGRESS, 10)])])],
|
||||
"a batch signals the progress semaphore once: the part's value in place of the uploads'"
|
||||
);
|
||||
}
|
||||
@@ -2278,9 +2278,10 @@ impl Device {
|
||||
inner: Arc::new(inner),
|
||||
device: self.clone(),
|
||||
};
|
||||
// In place over host memory's import, its move home, between the save of the bytes under
|
||||
// it and their write-back, runs in the submit thread's next submission, the runtime's own
|
||||
// or a group's, which the make waits for: Metal's make touches no bytes, and a CPU write to
|
||||
// In place over host memory's import, its move home, between the save of the bytes under it
|
||||
// and their write-back, runs in the submit thread's next submission, the runtime's own or,
|
||||
// in a batch of its own ahead of the group's command buffers, a group's, and the make waits
|
||||
// for that batch alone (`crate::submit`): Metal's make touches no bytes, and a CPU write to
|
||||
// them once the make returns is the program's, which no later submission, from any queue,
|
||||
// may revert. The submit thread makes that submission, so the make is refused in a
|
||||
// scheduled handler, which runs there.
|
||||
@@ -6845,16 +6846,20 @@ impl TextureObject for Arc<TextureInner> {
|
||||
///
|
||||
/// [`Buffer::new_texture_fenced`] and [`Buffer::new_texture_in_place_fenced`] take one. On a make
|
||||
/// that restores, on the make's thread and in this order, the make waits for the GPU work already
|
||||
/// submitted, calls [`before`](Self::before), adds the image's move home, between the save and
|
||||
/// the write-back, to the upload of the next commit, has that upload go at once in the submit
|
||||
/// thread's next submission (its own, or a group's, ahead of the group's command buffers), waits
|
||||
/// for that submission, and calls [`after`](Self::after). Every save, move and write-back of the
|
||||
/// make lies between the two calls, so a caller that fences its host writers there loses no
|
||||
/// write to those bytes; a caller with no such writer gives no fence. A make that restores
|
||||
/// nothing (any other buffer, a discrete or virtual device, the counted copy, a texture buffer)
|
||||
/// calls neither, and so does a refusal ahead of the restore
|
||||
/// ([`Refusal::InScheduledHandler`], the descriptor's, [`Refusal::TextureNotInPlace`]). The make
|
||||
/// is the same with a fence or without one.
|
||||
/// submitted, calls [`before`](Self::before), adds the image's move home, between the save and the
|
||||
/// write-back, to the upload of the next commit, has that upload go at once in the submit thread's
|
||||
/// next submission (its own, or a group's, in a batch of its own ahead of the group's command
|
||||
/// buffers, with a signal of its own), waits for that upload's batch, and calls
|
||||
/// [`after`](Self::after). The span between the two calls holds the save, the move and the
|
||||
/// write-back, the uploads of other threads that go with them, and the GPU work submitted ahead of
|
||||
/// them since the make's first wait, but none of a group's command buffers that go in the same
|
||||
/// submission behind them, unless an upload in that batch uses memory another API shares. Every
|
||||
/// save, move and write-back of the make lies between the two calls, so a caller that fences its
|
||||
/// host writers there loses no write to those bytes; a caller with no such writer gives no fence. A
|
||||
/// make that restores nothing (any other buffer, a discrete or virtual device, the counted copy, a
|
||||
/// texture buffer) calls neither, and so does a refusal ahead of the restore
|
||||
/// ([`Refusal::InScheduledHandler`], the descriptor's, [`Refusal::TextureNotInPlace`]). The make is
|
||||
/// the same with a fence or without one.
|
||||
pub trait RestoreFence {
|
||||
/// Opens the span: the runtime records the save only after this returns `Ok`. `Err(reason)`
|
||||
/// refuses the make ([`Refusal::RestoreFenceRefused`] with `reason`): nothing is saved, moved
|
||||
@@ -6910,20 +6915,20 @@ impl Buffer {
|
||||
/// Over a buffer in host memory's import ([`Device::import_host_memory`]), the image is so on
|
||||
/// an integrated or CPU device ([`Device::has_unified_memory`]) where the device's external
|
||||
/// image query takes a linear image made for host memory's handle (importable, compatible and
|
||||
/// not dedicated-only): made undefined, as Vulkan requires of an image for imported memory,
|
||||
/// and moved home once, inside the make, between a copy of the bytes under it into a block of
|
||||
/// the runtime's and a copy of them back, since Vulkan lets a move out of the undefined layout
|
||||
/// not dedicated-only): made undefined, as Vulkan requires of an image for imported memory, and
|
||||
/// moved home once, inside the make, between a copy of the bytes under it into a block of the
|
||||
/// runtime's and a copy of them back, since Vulkan lets a move out of the undefined layout
|
||||
/// discard them. The make has them go at once, in the submit thread's next submission (the
|
||||
/// runtime's own, or a group's, ahead of its command buffers), after the GPU work already
|
||||
/// submitted, and returns once it completed: one pair of copies in the texture's life,
|
||||
/// counted in
|
||||
/// runtime's own, or a group's, in a batch of their own ahead of its command buffers), after
|
||||
/// the GPU work already submitted, and returns once that batch completed: one pair of copies in
|
||||
/// the texture's life, counted in
|
||||
/// [`Metrics::over_copies_host_memory_restore`](crate::Metrics::over_copies_host_memory_restore)
|
||||
/// ([`OverCause::HostMemoryRestore`]), and none at its uses. A host write to those bytes from
|
||||
/// another thread while the make runs may be lost, and a host read of them then may see them
|
||||
/// undefined; one before the make or after it returns holds. A caller that can have such a
|
||||
/// writer makes the texture with [`Buffer::new_texture_fenced`], and the runtime calls the
|
||||
/// caller's [`RestoreFence`] around that span. Metal copies nothing here. A
|
||||
/// texture in place over either import counts in
|
||||
/// caller's [`RestoreFence`] around that span. Metal copies nothing here. A texture in place
|
||||
/// over either import counts in
|
||||
/// [`Metrics::textures_in_place_over_imports`](crate::Metrics::textures_in_place_over_imports).
|
||||
///
|
||||
/// Where the device's linear image does not take the texture (another pitch, an offset off
|
||||
|
||||
Vendored
+1
-1
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 606;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 2558;
|
||||
pub const RUNTIME_VERSION: u32 = 2559;
|
||||
|
||||
/// Writes a digest as lowercase hex.
|
||||
pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result {
|
||||
|
||||
Reference in new issue
Block a user