A command buffer joins its ended encoders' resources where its work reads them, not as each ends
Each compute or render encoder's end joined everything it made resident into its command buffer's
residency (Residency::join_encoder: a clone and a hash insert per resource), and each later
encoder's open walked every texture of that union for the shadowed ones. Most command buffers'
work never reads the union: only the commit's and host steps' recordings against every encoder's
resources (CommandBuffer::residency), the resident set of a GPU-alone recording, a texture made in
a heap since, and an encoder encoded again do.
- command_buffer/mod.rs: an encoder's end joins its heaps at once (join_encoder_heaps) and leaves
its resources in its record; State::joined_residency joins the records not joined yet, in the
order they ended, at the first read (CommandBuffer::residency, make_resident, fresh_ranges, a
splice of an encoder encoded again, before the textures its heaps made since). The union holds
what the eager join made, in the same token order: State::sync_heaps joins the records first
where a heap made textures, as each encoder's join came before them. The commit's sync of its
heaps and an encoder's open (State::inherited) read no resource list unless one did.
- residency.rs: each residency lists its shadowed textures' tokens (shadowed), found where an
open first asks for them (find_shadowed) and each texture looked at once, so making a texture
resident reads nothing of it, and an open starts with the shadowed textures of the joined union
and of the records not joined yet, in the order they were made resident, with the joined usage
and stages, at the cost of their count. The join's resource and heap halves and sync_heaps's
finding and joining halves are split out.
- WorkCounts::resident_resources_joined counts the joins (api_signatures.tsv blessed: one field).
The records hold what their encoders made resident until the command buffer completes, as before,
and the union goes with them, so nothing lives longer or shorter. The same resources, usages,
stages, tokens, shadows and heaps at every read.
Release numbers, M3 Max (host_ab --only encode, runtime side, median of 3 rounds, µs; before is
this landing without this commit, after with it, two or three interleaved runs each):
before (3 runs) after (3 runs)
resident_0 end_call 14.1 11.6 14.9 11.3 14.4 15.1
resident_256 end_call 34.7 25.6 37.3 11.1 13.3 15.4
resident_4096 end_call 230.3 152.3 244.3 11.4 14.1 15.5
resident_moving_4096 end_call 170.5 154.3 248.6 10.7 11.8 15.2
resident_textures_256 end_call 41.5 29.5 43.1 11.2 13.0 15.3
resident_textures_4096 end_call 287.8 193.5 294.6 11.5 12.9 15.8
resident_4096 use_call 346.1 379.3 335.1 326.1 297.3 342.0
resident_textures_256 use_call 38.0 37.0 36.9 35.1 35.1 37.2
resident_textures_4096 use_call 450.3 481.0 430.3 409.5 419.6 438.3
resident_4096 encode/dispatch 1.73 1.32 1.62 1.74 1.65 1.65
resident_textures_4096 encode 2.20 1.78 1.93 1.93 1.99 1.97
static encode/dispatch 1.75 1.74 1.61 1.62 1.64 1.60
The end call no longer grows with what the encoder made resident, and the useResources call does
not take the cost instead. A first form of this change looked for a texture's shadow as it was
made resident; that put about 80 µs into resident_textures_4096's use_call (260 to 317 against
188 to 200 before, four interleaved runs each), which is why the shadowed textures are found
where an open first asks for them. Percall's counts are the same with and without this commit;
the calls workload's end_compute allocates 5 a call where it allocated 8.5.
Checks that fail without it, in tests/joined_residency.rs:
- ended_encoders_join_their_command_buffer_s_residency_where_it_is_read: with the second
encoder's open joining the records (the eager join's timing), its first assert fails (16 joined
where 0).
- shadowed_textures_made_resident_reach_the_next_encoders_in_order: with find_shadowed looking
at none, its first assert fails (no shadowed texture inherited).
Verified: the runtime GPU suite on the M3 (1527 passed, 3 skipped); cargo clippy -p metal2vulkan
-p metal2vulkan-runtime --all-targets --all-features -D warnings, with and without --cfg m2v_gpu;
scripts/api-signatures/signatures.py --check.
(cherry picked from commit 18553c295c98dabe4c74fc226be6b45955c0c13a)
(cherry picked from commit ae56cfdfdd2e4cb1e9b189c7ce303d680fbc2b7f)
This commit is contained in:
1 parent
c6ff058263
commit
2f9a3a3782
9 files changed
+329
-39
No files matched your search
@@ -175,6 +175,11 @@ impl CommandBufferShared {
|
||||
// What a refused splice held goes after the lock.
|
||||
let spliced_now = {
|
||||
let mut state = lock(&self.state);
|
||||
// Its residency joins what the first encoding made resident before the encoding
|
||||
// again takes that one's place (`State::joined_residency`).
|
||||
if residency.is_some() {
|
||||
state.joined_residency(counts);
|
||||
}
|
||||
let spliced = state.splice_replay(at, replayed, residency);
|
||||
if let (Ok(()), Some(predication)) = (&spliced, predication) {
|
||||
state.predication.take_checks(predication);
|
||||
|
||||
Reference in new issue
Block a user