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
7 changes: 0 additions & 7 deletions drivers/gpu/drm/asahi/g16/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ pub(crate) struct RenderCommand {
pub(crate) fragment_attachments: KVec<uapi::drm_asahi_attachment>,
}

impl RenderCommand {
/// Whether this render pass is multisampled.
pub(crate) fn is_multisampled(&self) -> bool {
self.cmd.samples > 1
}
}

/// A validated compute command.
pub(crate) struct ComputeCommand {
pub(crate) cmd: uapi::drm_asahi_cmd_compute,
Expand Down
161 changes: 53 additions & 108 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,19 @@ fn compute_uma_conflict(f: &Flight, vm: &Arc<super::vm::VmState>, uma_mask: u32)
f.computes != 0 && !Arc::ptr_eq(&f.job.vm, vm) && (f.compute_uma_mask & uma_mask) != 0
}

/// Whether a render of `vm`, multisampled when `msaa`, must wait for render flight `f` to
/// retire before it is published.
/// Whether a render of `vm` must wait for flight `f` to retire before it is published.
///
/// Every VM's render passes share the one firmware TA/FS queue pair. While passes of two VMs
/// are both published there and one of the VMs renders multisampled
/// (`VmStateInner::renders_msaa`), that VM's passes can lose coverage (uncovered or zero
/// pixels and samples, also in single-sampled passes that read its multisampled images) and
/// its fragment shaders can read VA 0. Ordering the two passes' TA and FS with ring barriers
/// does not prevent it; publishing one only after the other retired does. Passes of one VM,
/// and passes of VMs that never render multisampled, still share the queues.
fn msaa_render_conflict(f: &Flight, vm: &Arc<super::vm::VmState>, msaa: bool) -> bool {
f.renders != 0
&& !Arc::ptr_eq(&f.job.vm, vm)
&& (msaa || vm.renders_msaa() || f.job.vm.renders_msaa())
/// are both published there, the GPU faults in the VM whose pass runs (linux#3201): its VDM
/// reads the pass slot's kernel prefix and its control stream, and its shader cores read
/// from a null base, at addresses that are not mapped in its context. Multisampled passes
/// also lose coverage and their fragment shaders read VA 0. Ordering the two passes' TA and
/// FS with ring barriers does not prevent it; publishing one only after the other retired
/// does. A render of another VM also never runs beside compute, so a long compute dispatch
/// cannot starve its fragment shading into a firmware DM1 timeout. Renders of one VM still
/// share the queues.
fn cross_vm_render_conflict(f: &Flight, vm: &Arc<super::vm::VmState>) -> bool {
!Arc::ptr_eq(&f.job.vm, vm)
}

/// Resolved ring-barrier placement for one render pass (legacy, `FRAGMENT_BARRIERS`, or
Expand All @@ -211,17 +210,14 @@ struct RenderBarrierPlan {
}

/// Computes TA/FS hardware ring barriers for a render command from its flags, prior render
/// FS stamp, resolved render waits (`fs_wait_render`, `ta_wait_fs`), resolved `[ta, fs]`
/// per-pipe compute wait stamps, and whether the immediately preceding in-flight render belongs
/// to a different VM (`cross_vm_prev`).
/// FS stamp, resolved render waits (`fs_wait_render`, `ta_wait_fs`), and resolved `[ta, fs]`
/// per-pipe compute wait stamps.
///
/// Same-VM pipelined renders share one parameter-buffer / UMA slot, and cross-VM pipelined
/// renders use distinct UMA slots (`RENDER_UMA_SLOT + slot`) on the shared TA/FS pipes: TA(N)
/// always waits on TA(N-1) (`ta_prev_wait`, matching G15's `prev_barrier`) whenever
/// `ta_fs_wait` does not already wait on `prev_fs` (which dominates `prev_ta` via
/// `own_barrier`). Same-VM independent FS passes omit `fs_dep`, while `cross_vm_prev` forces
/// `fs_render_wait = Some(prev_fs)` (whenever `ta_fs_wait != Some(prev_fs)`) so cross-VM TA
/// overlaps the previous VM's FS without ever overlapping two VMs' FS/PB teardowns.
/// Pipelined renders all belong to one VM ([`cross_vm_render_conflict`]) and reuse that VM's
/// warm parameter-buffer / UMA slots on the shared TA/FS pipes: TA(N) always waits on TA(N-1)
/// (`ta_prev_wait`, matching G15's `prev_barrier`) whenever `ta_fs_wait` does not already wait
/// on `prev_fs` (which dominates `prev_ta` via `own_barrier`). Independent FS passes omit
/// `fs_dep`.
#[expect(
clippy::too_many_arguments,
reason = "Pure barrier-plan helper mirrors the exact render barrier inputs."
Expand All @@ -234,7 +230,6 @@ fn plan_render_barriers(
fs_wait_render: Option<u32>,
ta_wait_fs: Option<u32>,
compute_waits: [[Option<u32>; sizes::COMPUTE_PIPES]; 2],
cross_vm_prev: bool,
) -> RenderBarrierPlan {
let staged =
flags & kernel::uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_STAGE_PREFIXES != 0;
Expand Down Expand Up @@ -264,16 +259,8 @@ fn plan_render_barriers(
None
};
let ta_prev_wait = class_behind && ta_fs_wait != Some(prev_fs);
let effective_fs_wait = if cross_vm_prev && class_behind {
Some(prev_fs)
} else {
let fs_render_wait = if class_behind && early && fs_wait_render != ta_fs_wait {
fs_wait_render
};
let fs_render_wait = if class_behind
&& (early || (cross_vm_prev && ta_fs_wait != Some(prev_fs)))
&& effective_fs_wait != ta_fs_wait
{
effective_fs_wait
} else {
None
};
Expand All @@ -299,24 +286,24 @@ fn plan_render_barriers(
///
/// Every render's TA work goes on the one firmware TA queue, whose works the firmware runs in
/// ring order: on Metal's TA ring, which carries no barriers, each pass's tiling starts after
/// the previous pass's tiling has ended. A same-VM predecessor shares this render's parameter
/// buffer and UMA slot only through that order. A predecessor of another VM
/// (`cross_vm_prev`, its own UMA slot and the conflict of [`msaa_render_conflict`]) and any
/// InitBM producer or consumer (`producer_initbm`) keep the barrier.
fn ta_ring_orders_prev(cross_vm_prev: bool, producer_initbm: bool) -> bool {
!cross_vm_prev && !producer_initbm
/// the previous pass's tiling has ended. A predecessor shares this render's parameter buffer
/// and UMA slot only through that order; it is always of the same VM, because a render of
/// another VM drains the engine first ([`cross_vm_render_conflict`]). Any InitBM producer or
/// consumer (`producer_initbm`) keeps the barrier.
fn ta_ring_orders_prev(producer_initbm: bool) -> bool {
!producer_initbm
}

/// Whether the FS ring's own order already holds FS(N) behind FS(N-1), so that the FS->FS
/// `fs_dep` barrier of [`plan_render_barriers`] would only re-check a stamp the ring implies.
///
/// Every render's FS work goes on the one firmware FS queue, whose works the firmware runs in
/// ring order: on Metal's FS ring, which carries only each pass's own TA barrier ahead of its
/// FS work, consecutive passes serialize in ring order without self-event FS->FS barriers. A
/// predecessor of another VM (`cross_vm_prev`) and any InitBM producer or consumer
/// (`producer_initbm || init_buffer`) keep the barrier.
fn fs_ring_orders_prev(cross_vm_prev: bool, producer_initbm: bool, init_buffer: bool) -> bool {
!cross_vm_prev && !producer_initbm && !init_buffer
/// FS work, consecutive passes serialize in ring order without self-event FS->FS barriers.
/// The predecessor is of the same VM ([`cross_vm_render_conflict`]). Any InitBM producer or
/// consumer (`producer_initbm || init_buffer`) keeps the barrier.
fn fs_ring_orders_prev(producer_initbm: bool, init_buffer: bool) -> bool {
!producer_initbm && !init_buffer
}

/// Engine of the previous member.
Expand Down Expand Up @@ -397,9 +384,6 @@ pub(crate) struct Flight {
pub(crate) rt_compute: bool,
/// Bitmask of hardware compute UMA slots (`0..COMPUTE_UMA_SLOTS`) active in this flight.
pub(crate) compute_uma_mask: u32,
/// Whether this flight includes a multisampled render pass; its VM is marked
/// (`VmStateInner::note_msaa_render`) once the flight becomes visible.
pub(crate) msaa: bool,
}

impl Flight {
Expand Down Expand Up @@ -444,7 +428,6 @@ impl Flight {
has_timestamps: false,
rt_compute: false,
compute_uma_mask: 0,
msaa: false,
}
}
}
Expand Down Expand Up @@ -498,9 +481,8 @@ pub(crate) enum HoldCause {
DrainFailed,
/// A cold `InitBM` render is in flight.
DrainInitbm,
/// Compute behind render of another VM, render behind compute of another VM, an SCS
/// compute conflict, or a render beside another VM's render while one of the two VMs
/// renders multisampled.
/// Compute behind render of another VM, render behind any flight of another VM, or an SCS
/// compute conflict.
DrainCross,
/// No warm PB/UMA allocator slot of the VM can take the render behind active flights.
DrainPb,
Expand Down Expand Up @@ -1411,16 +1393,6 @@ impl Firmware {
Ok(())
}

/// Whether render `r` of `vm` may be published beside the flights in flight
/// ([`msaa_render_conflict`]). Every member of a prefix is checked, not only its first.
fn msaa_member_allowed(&self, vm: &Arc<super::vm::VmState>, r: &RenderCommand) -> bool {
!self
.engine
.flights
.iter()
.any(|f| msaa_render_conflict(f, vm, r.is_multisampled()))
}

/// Whether `job` requires `self.engine.flights` to drain to empty before it can
/// publish (so `alt`-class bypass must not keep refilling the engine ahead of it).
fn needs_engine_drain(&self, job: &Arc<Job>) -> bool {
Expand All @@ -1435,17 +1407,15 @@ impl Firmware {
} else {
0
};
let is_msaa_render = matches!(cmd, Some(Command::Render(r)) if r.is_multisampled());
job.vm.status.get() != 0
|| self.engine.flights.iter().any(|f| {
f.doomed
|| f.recovery_suspect
|| f.initbm
|| (is_compute && scs_compute_conflict(f, &job.vm, is_rt_compute))
|| (is_compute && compute_uma_conflict(f, &job.vm, uma_mask))
|| (is_render && msaa_render_conflict(f, &job.vm, is_msaa_render))
|| (((is_compute && f.renders != 0) || (is_render && f.computes != 0))
&& !Arc::ptr_eq(&f.job.vm, &job.vm))
|| (is_render && cross_vm_render_conflict(f, &job.vm))
|| (is_compute && f.renders != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm))
})
|| (is_render && !self.render_can_pipeline(job))
}
Expand Down Expand Up @@ -1568,14 +1538,13 @@ impl Firmware {
/// is set and a same-queue predecessor in its compute or render barrier prefix has
/// CPU-published timestamp outputs that have not retired yet
/// (`DRM_ASAHI_COMPUTE_NO_QUERY_ACCESS` clears `query_access`).
/// - Render queues behind healthy non-InitBM render flights of any VM or same-VM compute
/// flights (up to [`params::render_flights`] active renders), rotating `PassSlot`
/// (`0..RENDER_SLOTS`) while reusing that VM's warm PB/UMA allocator slot
/// (`Pools::can_pipeline_within`, each owning its own hardware UMA slot
/// `RENDER_UMA_SLOT + slot`). Hardware barriers on the CDM/TA/FS rings preserve exact
/// same-engine, cross-engine, and cross-VM FS ordering while allowing cross-VM TA to
/// overlap the preceding VM's FS.
/// - Cross-VM compute/render overlap is disallowed in both directions so a long compute
/// - Render queues behind healthy non-InitBM render and compute flights of its own VM (up
/// to [`params::render_flights`] active renders), rotating `PassSlot` (`0..RENDER_SLOTS`)
/// while reusing that VM's warm PB/UMA allocator slot (`Pools::can_pipeline_within`,
/// each owning its own hardware UMA slot `RENDER_UMA_SLOT + slot`). Hardware barriers on
/// the CDM/TA/FS rings preserve exact same-engine and cross-engine ordering. A render
/// never queues behind a flight of another VM ([`cross_vm_render_conflict`]).
/// - Compute never queues behind a render of another VM either, so a long compute
/// dispatch from one client cannot starve another client's fragment shading into a
/// firmware DM1 timeout. Cold InitBM priming renders and every failure or recovery path
/// still drain the engine first.
Expand Down Expand Up @@ -1669,15 +1638,13 @@ impl Firmware {
.compute_slot_mask()
.is_ok_and(|mask| self.has_compute_pipe_for_vm(&job.vm, mask, scs))
}
Some(Command::Render(r)) => {
let cross_vm_compute = e
Some(Command::Render(_)) => {
let cross_vm = e
.flights
.iter()
.any(|f| f.computes != 0 && !Arc::ptr_eq(&f.job.vm, &job.vm));
let msaa_conflict = !self.msaa_member_allowed(&job.vm, r);
.any(|f| cross_vm_render_conflict(f, &job.vm));
let render_count: usize = e.flights.iter().map(|f| f.renders as usize).sum();
!cross_vm_compute
&& !msaa_conflict
!cross_vm
&& render_count < params::render_flights()
&& !self.slots.render_exhausted()
&& !self.pools.exhausted()
Expand Down Expand Up @@ -3059,9 +3026,6 @@ impl Firmware {
let Some(Command::Render(r2)) = command(job, end) else {
break;
};
if !self.msaa_member_allowed(&job.vm, r2) {
break;
}
let Some(o2) = job.command_order(end) else {
break;
};
Expand Down Expand Up @@ -3203,10 +3167,6 @@ impl Firmware {
precheck_ok = false;
break;
};
if !self.msaa_member_allowed(&job.vm, r2) {
precheck_ok = false;
break;
}
let Some(o2) = j2.command_order(k) else {
precheck_ok = false;
break;
Expand Down Expand Up @@ -3347,9 +3307,6 @@ impl Firmware {
// Even a failed first store may have become visible. From this boundary preserve
// every owner and return explicit uncertainty rather than guessing from errno.
*visible = true;
if f.msaa {
job.vm.note_msaa_render();
}
let publication = (|| -> Result {
if render {
let a = f.pb_slot as usize;
Expand Down Expand Up @@ -3865,15 +3822,6 @@ impl Firmware {
} else {
None
};
let cross_vm_prev = member == 0
&& class_behind
&& self
.engine
.flights
.iter()
.rev()
.find(|fl| fl.renders != 0)
.is_some_and(|fl| !Arc::ptr_eq(&fl.job.vm, &job.vm));
let plan_flags = if !staged
&& job.fw_waits.iter().any(|w| {
w.last_ordinal[super::command::RENDER].is_some_and(|last| {
Expand All @@ -3897,7 +3845,6 @@ impl Firmware {
ta_wait_compute.map(|w| w.map(|t| t.stamp)),
fs_wait_compute.map(|w| w.map(|t| t.stamp)),
],
cross_vm_prev,
);
// Claim performs only a qualified per-use scrub, never allocator/list reset.
self.slots
Expand Down Expand Up @@ -3940,7 +3887,6 @@ impl Firmware {
(refs, false)
};
f.has_timestamps |= !cmd.timestamp_outputs.is_empty();
f.msaa |= cmd.is_multisampled();
let p = resources.render_pass(k)?;
let pass = p.refs();
let heap_bytes = if cmd.cmd.layers > 1 { 0x1000 } else { 0x200 };
Expand Down Expand Up @@ -4053,14 +3999,13 @@ impl Firmware {
|| fs_wait_render.is_some_and(|w| w.initbm)
|| ta_wait_fs.is_some_and(|w| w.initbm);
let render_bar = cross_engine_barrier_type(producer_initbm, init_buffer);
// Pipelined renders share TA/FS pipes across same-VM and cross-VM flights. The plan
// asks for the TA(N-1)->TA(N) `prev_barrier` (matching G15) whenever `plan.ta_fs_wait`
// does not already serialize behind `prev_fs`; it is posted unless the TA ring's own
// order already holds TA(N) behind TA(N-1) (`ta_ring_orders_prev`). Emit
// `ta_fs_barrier` only when `plan.ta_fs_wait` names an in-flight FS stamp, and `fs_dep`
// when `plan.fs_render_wait` names an in-flight FS dependency (or cross-VM `prev_fs`)
// not already dominated by TA.
let ta_ordered = ta_ring_orders_prev(cross_vm_prev, producer_initbm);
// Pipelined renders of one VM share the TA/FS pipes. The plan asks for the
// TA(N-1)->TA(N) `prev_barrier` (matching G15) whenever `plan.ta_fs_wait` does not
// already serialize behind `prev_fs`; it is posted unless the TA ring's own order
// already holds TA(N) behind TA(N-1) (`ta_ring_orders_prev`). Emit `ta_fs_barrier` only
// when `plan.ta_fs_wait` names an in-flight FS stamp, and `fs_dep` only when
// `plan.fs_render_wait` names an in-flight FS dependency not already dominated by TA.
let ta_ordered = ta_ring_orders_prev(producer_initbm);
if plan.ta_prev_wait && ta_ordered {
pf.ta_order += 1;
}
Expand Down Expand Up @@ -4091,7 +4036,7 @@ impl Firmware {
r.ring[0].w64(8 * pf.ta_head as usize, p.ta_fs_barrier.va)?;
pf.ta_head = (pf.ta_head + 1) % cap;
}
let fs_ordered = fs_ring_orders_prev(cross_vm_prev, producer_initbm, init_buffer);
let fs_ordered = fs_ring_orders_prev(producer_initbm, init_buffer);
if let Some(wait_fs) = plan.fs_render_wait {
if fs_ordered {
pf.fs_order += 1;
Expand Down
17 changes: 1 addition & 16 deletions drivers/gpu/drm/asahi/g16/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//! alike.

use core::ops::Range;
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
use core::sync::atomic::{AtomicU32, Ordering};
use kernel::{
drm::gem::BaseObject,
new_mutex,
Expand Down Expand Up @@ -135,8 +135,6 @@ pub(crate) struct VmStateInner {
/// Private mappings are kept outside generic close's user GPUVA teardown.
context_mappings: KVec<mmu::KernelMapping>,
pub(crate) resources: Option<Arc<super::resources::Cache>>,
/// Set once a multisampled render pass of this VM becomes visible ([`Self::renders_msaa`]).
renders_msaa: AtomicBool,
#[allow(dead_code)]
pub(crate) live: Arc<LiveToken>,
}
Expand All @@ -148,18 +146,6 @@ impl VmStateInner {
.as_ref()
.is_some_and(|cache| cache.renders_unpublished())
}

/// Whether this VM has published a multisampled render pass. Its later passes can still
/// read multisampled images (an attachmentless pass reading them as input attachments is
/// single-sampled), so the property is the VM's from then on.
pub(crate) fn renders_msaa(&self) -> bool {
self.renders_msaa.load(Ordering::Relaxed)
}

/// Records that a multisampled render pass of this VM became visible to the firmware.
pub(crate) fn note_msaa_render(&self) {
self.renders_msaa.store(true, Ordering::Relaxed);
}
}

impl Drop for VmStateInner {
Expand Down Expand Up @@ -484,7 +470,6 @@ pub(crate) fn new_vm(
vm: vm.clone(),
context_mappings: mappings,
resources: Some(resources),
renders_msaa: AtomicBool::new(false),
live,
};
let state = Arc::new(VmState(crate::cleanup::Deferred::new(inner)?), GFP_KERNEL)?;
Expand Down
Loading
Loading