Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions drivers/gpu/drm/asahi/g17/queue/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ pub(crate) struct RenderDependencies {
/// Fragment kicks of other pairs' overlapping same-VM renders.
pub(crate) hazards: [KickDependency; crate::g17::hazard::PUBLICATION_BARRIERS],
pub(crate) hazard_count: usize,
/// Another pair of the owner may hold a render that has not retired, which a compute wait
/// or an attachment overlap can stand for (`render_barriers`). Publication clears it when
/// the owner's other pairs are idle.
pub(crate) sibling_in_flight: bool,
}

impl RenderDependencies {
Expand All @@ -76,6 +80,7 @@ impl RenderDependencies {
fragment_compute_count: 0,
hazards: [KickDependency::ZERO; crate::g17::hazard::PUBLICATION_BARRIERS],
hazard_count: 0,
sibling_in_flight: true,
};
pub(crate) fn render(&self) -> &[KickDependency] {
&self.render[..self.render_count]
Expand Down Expand Up @@ -797,9 +802,10 @@ fn render_barriers(
let fragment_stage = fragment_stage || stage_prefixes;
// Ordered partial rendering covers this pair's earlier fragment work, which `fragment_busy`
// drains, and the renders the fragment barriers name. Only a queue of several pairs can reach
// such a render on another pair through a compute wait; with one pair per queue the tiling
// kick keeps overlapping compute waits and other queues' attachments.
let ordered_indirect = ordered_partial && render_pairs > 1;
// such a render on another pair through a compute wait, and only while one of its other pairs
// holds a render that has not retired; with one pair per queue, or with the other pairs idle,
// the tiling kick keeps overlapping compute waits and other queues' attachments.
let ordered_indirect = ordered_partial && render_pairs > 1 && dependencies.sibling_in_flight;
let mut tiling_barriers = [KickDependency::ZERO;
7 + 2 * crate::g17::pairs::COMPUTE_CHANNELS_MAX + crate::g17::hazard::PUBLICATION_BARRIERS];
let mut tiling_count = 0;
Expand Down Expand Up @@ -859,16 +865,17 @@ fn render_barriers(
fragment_count += 1;
// A fragment-only compute wait may transitively order an earlier render on another
// pair (or write attachments read by a partial render), so promote it to tiling when
// ordered partial rendering is advertised on a queue of several pairs.
// ordered partial rendering is advertised and another pair of the queue is busy.
if ordered_indirect {
tiling_barriers[tiling_count] = *compute;
tiling_types[tiling_count] = compute_class;
tiling_count += 1;
}
}
// Only tile stores overlap: the tiling kick stays concurrent unless ordered partial
// rendering is advertised on a queue of several pairs, where a tiler-heap overflow partial
// render can touch the overlapping attachment before another pair's fragment pass completes.
// rendering is advertised and another pair of the queue is busy, where a tiler-heap overflow
// partial render can touch the overlapping attachment before that pair's fragment pass
// completes.
for hazard in &dependencies.hazards[..dependencies.hazard_count] {
fragment_barriers[fragment_count] = *hazard;
fragment_count += 1;
Expand Down Expand Up @@ -3982,6 +3989,37 @@ mod ordered_partial_tests {
assert_eq!(one.tiling_types[0], 2);
}

#[test]
fn a_two_pair_queue_with_idle_siblings_tiles_beside_its_compute_waits_and_hazards() {
let own_tiling = dep(4);
let own_fragment_qid = 5;
let mut deps = RenderDependencies::EMPTY;
deps.render[0] = dep(5);
deps.render_count = 1;
deps.fragment_compute[0] = dep(12);
deps.fragment_compute_count = 1;
deps.hazards[0] = dep(9);
deps.hazard_count = 1;
deps.sibling_in_flight = false;
let idle = render_barriers(false, true, true, 2, &deps, own_tiling, own_fragment_qid, 3);
assert_eq!(idle.tiling_count, 0);
assert_eq!(idle.tiling_types[0], 1);
assert_eq!(idle.fragment_count, 4);
// A render in flight on another pair of the queue holds tiling behind both.
deps.sibling_in_flight = true;
let busy = render_barriers(false, true, true, 2, &deps, own_tiling, own_fragment_qid, 3);
assert_eq!(busy.tiling_count, 2);
assert_eq!(busy.tiling[0].word(), dep(12).word());
assert_eq!(busy.tiling[1].word(), dep(9).word());
// A named render on another pair is ordered either way.
deps.sibling_in_flight = false;
deps.render[0] = dep(7);
let named = render_barriers(false, true, true, 2, &deps, own_tiling, own_fragment_qid, 3);
assert_eq!(named.tiling_count, 1);
assert_eq!(named.tiling[0].word(), dep(7).word());
assert_eq!(named.tiling_types[0], 2);
}

#[test]
fn max_sized_barriers_fit_kick_entry_with_and_without_ancestor() {
let own_tiling = dep(4);
Expand Down
20 changes: 20 additions & 0 deletions drivers/gpu/drm/asahi/g17/runtime/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,26 @@ impl Registry {
)
})
}
/// A pair of `owner` other than `slot` holds a render that has not retired, or one parked
/// for replay, resident or lent out: a render published on `slot` can then wait for it
/// through a compute command or an attachment overlap.
pub(in crate::g17) fn sibling_render_in_flight(&self, slot: u8, owner: u64) -> bool {
self.render
.entries
.iter()
.enumerate()
.any(|(index, entry)| {
entry.as_ref().is_some_and(|entry| {
index != usize::from(slot)
&& entry.reservation.owner == owner
&& entry.pair.as_ref().map_or(
(entry.preparing.is_some() || entry.growing)
&& (entry.borrowed_active || entry.borrowed_replay.is_some()),
|pair| pair.in_flight(),
)
})
})
}
pub(in crate::g17) fn retain_render_completions(&mut self, masks: [u64; 2]) -> [u64; 2] {
let mut matched = [0u64; 2];
for entry in self.render.entries.iter_mut().flatten() {
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/asahi/g17/runtime/render/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub(in crate::g17::runtime) struct Loan {
fragment_compute:
[crate::g17::fw::kick::KickDependency; crate::g17::pairs::COMPUTE_CHANNELS_MAX],
fragment_compute_count: usize,
/// `Registry::sibling_render_in_flight` when the pair was lent.
sibling_in_flight: bool,
}

enum DirectTarget {
Expand Down Expand Up @@ -374,6 +376,7 @@ impl crate::g17::Firmware {
compute_count,
fragment_compute,
fragment_compute_count,
sibling_in_flight: self.queues.sibling_render_in_flight(slot, owner),
}))
}

Expand Down Expand Up @@ -511,6 +514,7 @@ impl Backend {
dependencies.fragment_compute[..loan.fragment_compute_count]
.copy_from_slice(&loan.fragment_compute[..loan.fragment_compute_count]);
dependencies.fragment_compute_count = loan.fragment_compute_count;
dependencies.sibling_in_flight = loan.sibling_in_flight;
if let Some(footprint) = packet.footprint.as_ref() {
dependencies.hazard_count = self.admission.publication_barriers(
self.owner,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g17/runtime/render/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ impl crate::g17::Firmware {
return Err(EBUSY);
}
let mut dependencies = self.queues.render_dependencies(owner, packet, state)?;
dependencies.sibling_in_flight = self.queues.sibling_render_in_flight(slot, owner);
packet.check_firmware_producers()?;
// Every render publication, with or without the device mutex, holds the
// port's render lock: the render work rings have one host producer at a
Expand Down
31 changes: 23 additions & 8 deletions tools/asahi/g17-render-partial-order-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

`fragment_busy` drains only the fragment work of the pair a partial render runs on. A fragment
wait for a render of another pair therefore also holds the tiling kick. With several pairs per
queue a compute wait or a same-VM attachment overlap can stand for such a render, and they hold it
as well. With one pair per queue (A18 Pro, one- and two-cluster M5) they stay on the fragment kick,
so that tiling overlaps them, and without `fragment_busy` nothing is promoted.
queue a compute wait or a same-VM attachment overlap can stand for such a render while one of the
queue's other pairs holds a render that has not retired, and they hold it as well. With one pair
per queue (A18 Pro, one- and two-cluster M5), or while the other pairs are idle, they stay on the
fragment kick, so that tiling overlaps them, and without `fragment_busy` nothing is promoted.

Each `--mutation` widens or drops one of these promotions and must fail.
"""
Expand Down Expand Up @@ -157,6 +158,12 @@ def fixture():
if several { expected.push((OTHER_OWNER, 2)); }
assert_eq!(tiling, expected, "attachment overlap, {clusters:?} clusters");
assert_eq!(waits(&undrained, pass, &dependencies).0, [(COMPUTE, class)]);
// The queue's other pairs are idle: neither wait can stand for a render there.
dependencies.sibling_in_flight = false;
let (tiling, fragment) = waits(&pair, pass, &dependencies);
assert_eq!(fragment, [TILING, FRAGMENT, FRAGMENT_COMPUTE, OTHER_OWNER]);
assert_eq!(tiling, [(COMPUTE, class)], "idle other pairs, {clusters:?} clusters");
dependencies.sibling_in_flight = true;
// A fragment wait that names a render of another pair: every count promotes it.
dependencies.render[1] = kick(OTHER_FRAGMENT);
dependencies.render_count = 2;
Expand All @@ -165,24 +172,32 @@ def fixture():
expected.insert(0, (OTHER_FRAGMENT, 2));
assert_eq!(tiling, expected, "another pair's render, {clusters:?} clusters");
assert_eq!(waits(&undrained, pass, &dependencies).0, [(COMPUTE, class)]);
// And whatever the other pairs hold.
dependencies.sibling_in_flight = false;
assert_eq!(waits(&pair, pass, &dependencies).0, [(OTHER_FRAGMENT, 2), (COMPUTE, class)],
"another pair's render beside idle other pairs, {clusters:?} clusters");
}
}
println!("PASS g17-render-partial-order: one pair per queue tiles beside compute waits and attachment overlaps");
println!("PASS g17-render-partial-order: one pair per queue, or idle other pairs, tile beside compute waits and attachment overlaps");
}
'''


# name -> [(old, new)], each applied exactly once.
MUTATIONS = {
# One-pair queues are promoted as well, for both kinds of wait or for one.
'every-count': [('ordered_partial && render_pairs > 1;', 'ordered_partial;')],
'compute-every-count': [('several pairs.\n if ordered_indirect {', 'several pairs.\n if ordered_partial {')],
'every-count': [('ordered_partial && render_pairs > 1 && dependencies.sibling_in_flight;', 'ordered_partial;')],
'sibling-only': [('ordered_partial && render_pairs > 1 && dependencies.sibling_in_flight;',
'ordered_partial && dependencies.sibling_in_flight;')],
'compute-every-count': [('queue is busy.\n if ordered_indirect {', 'queue is busy.\n if ordered_partial {')],
'hazard-every-count': [(' fragment_count += 1;\n if ordered_indirect {',
' fragment_count += 1;\n if ordered_partial {')],
'count-ignored': [('crate::g17::pairs::per_owner(),', '2,')],
# Two-pair queues are promoted while their other pairs are idle.
'idle-siblings-promoted': [('render_pairs > 1 && dependencies.sibling_in_flight;', 'render_pairs > 1;')],
# A promotion two-pair queues need is gone.
'no-count': [('ordered_partial && render_pairs > 1;', 'false;')],
'compute-dropped': [('several pairs.\n if ordered_indirect {', 'several pairs.\n if false {')],
'no-count': [('ordered_partial && render_pairs > 1 && dependencies.sibling_in_flight;', 'false;')],
'compute-dropped': [('queue is busy.\n if ordered_indirect {', 'queue is busy.\n if false {')],
'hazard-dropped': [(' fragment_count += 1;\n if ordered_indirect {',
' fragment_count += 1;\n if false {')],
'render-dropped': [('if ordered_partial && dependency.qid() != own_fragment_qid {', 'if false {')],
Expand Down
5 changes: 3 additions & 2 deletions tools/asahi/run-host-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,9 @@ def mutations(flag, names, base, expect=KILL):
'parked-unseen', 'failed-unseen', 'batch-kept',
'batch-unchecked'), []),
'g17-render-partial-order-tests.py': [([], PASS)]
+ mutations('--mutation', ('every-count', 'compute-every-count', 'hazard-every-count',
'count-ignored', 'no-count', 'compute-dropped', 'hazard-dropped',
+ mutations('--mutation', ('every-count', 'sibling-only', 'compute-every-count',
'hazard-every-count', 'count-ignored', 'idle-siblings-promoted',
'no-count', 'compute-dropped', 'hazard-dropped',
'render-dropped', 'render-several-only', 'own-pair-promoted',
'undrained-promoted'), []),
'g17-render-return-observe-tests.py': [([], PASS)]
Expand Down
Loading