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
13 changes: 13 additions & 0 deletions drivers/gpu/drm/asahi/g16/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ pub(crate) struct RenderCommand {
/// Explicit hardware attachments in effect for each render engine.
pub(crate) vertex_attachments: KVec<uapi::drm_asahi_attachment>,
pub(crate) fragment_attachments: KVec<uapi::drm_asahi_attachment>,
/// Whether this pass exceeds the light-TA wave threshold (multi-layer or large tilemap).
pub(crate) heavy_ta: bool,
}

impl RenderCommand {
/// Whether this render pass requires the conservative `TA_WAVE_PASSES` wave window.
pub(crate) fn is_heavy_ta(&self) -> bool {
self.heavy_ta
}
}

/// A validated compute command.
Expand Down Expand Up @@ -1517,6 +1526,9 @@ pub(crate) fn parse_stream(bytes: &[u8], early_tiling: bool) -> Result<ParsedStr
};
let vertex_attachments = take_render(&mut vertex, false)?;
let fragment_attachments = take_render(&mut fragment, true)?;
let heavy_ta = packet.layers > 1
|| super::encode::Geometry::new(&packet, 0).tilemap_bytes
> hw::sizes::TA_LIGHT_TILEMAP_BYTES;
commands.push(Command::Render(KBox::new(
RenderCommand {
cmd: packet,
Expand All @@ -1525,6 +1537,7 @@ pub(crate) fn parse_stream(bytes: &[u8], early_tiling: bool) -> Result<ParsedStr
timestamp_outputs: crate::timestamp::Destinations::empty(),
vertex_attachments,
fragment_attachments,
heavy_ta,
},
GFP_KERNEL,
)?))?;
Expand Down
497 changes: 439 additions & 58 deletions drivers/gpu/drm/asahi/g16/engine.rs

Large diffs are not rendered by default.

148 changes: 129 additions & 19 deletions drivers/gpu/drm/asahi/g16/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use kernel::{
use super::channel::Channel;
use super::fw::graph::{self, job_list, notifier_page, qinfo, qstate, sched_ctx};
use super::hw::{pte, sizes, tuning, FwAbi};
use super::object::{Class, FwObject, Objects, Placement, Request};
use super::object::{Class, Factory, FwObject, Objects, Placement, Request};
use super::Firmware;
use crate::driver::AsahiDrmDevice;

Expand Down Expand Up @@ -126,23 +126,55 @@ pub(crate) struct ComputeGraph {
pub(crate) fw_stamp: Arc<FwObject>,
}

struct QueueObjects {
struct QueueSession {
qinfo: Arc<FwObject>,
qstate: Arc<FwObject>,
ring: Arc<FwObject>,
user_stamp: Arc<FwObject>,
fw_stamp: Arc<FwObject>,
}
impl QueueObjects {
impl QueueSession {
fn new(o: &mut Objects) -> Result<Self> {
Ok(Self {
qinfo: alloc(o, qinfo::SIZE, graph_fw(), None, 0, false)?,
qstate: alloc(o, qstate::SIZE, Class::Fw, None, 0, false)?,
ring: alloc(o, sizes::QUEUE_CAP as usize * 8, cmd_fw(), None, 0, false)?,
user_stamp: alloc(o, 8, Class::Shared, None, 0, false)?,
fw_stamp: alloc(o, 8, Class::Shared, None, 0, false)?,
})
}
/// Completes the queue with its firmware-cached work ring from a device-lifetime
/// [`Factory::persistent_objects`] allocator. The host only writes 64-bit work/barrier VAs
/// into the ring before advancing the uncached `qstate::WRITE` producer and never reads
/// back firmware writes, matching macOS 26B123's `0x443` command-ring mapping.
fn finish(self, rings: &mut Objects) -> Result<QueueObjects> {
Ok(QueueObjects {
qinfo: self.qinfo,
qstate: self.qstate,
ring: alloc(
rings,
sizes::QUEUE_CAP as usize * 8,
Class::FwCoherent,
None,
0,
false,
)?,
user_stamp: self.user_stamp,
fw_stamp: self.fw_stamp,
})
}
}

struct QueueObjects {
qinfo: Arc<FwObject>,
qstate: Arc<FwObject>,
ring: Arc<FwObject>,
user_stamp: Arc<FwObject>,
fw_stamp: Arc<FwObject>,
}
impl QueueObjects {
#[allow(dead_code)]
fn new(o: &mut Objects, rings: &mut Objects) -> Result<Self> {
QueueSession::new(o)?.finish(rings)
}
}

fn init_queue(
Expand Down Expand Up @@ -173,14 +205,30 @@ fn init_notifier(page: &FwObject, threshold: &FwObject) -> Result {
Ok(())
}

impl ComputeGraph {
struct ComputeGraphSession {
sched_ctx: Arc<FwObject>,
notifier: Arc<FwObject>,
threshold: Arc<FwObject>,
job_list: Arc<FwObject>,
q: QueueSession,
}
impl ComputeGraphSession {
fn new(o: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<Self> {
let q = QueueObjects::new(o)?;
Ok(Self {
sched_ctx,
notifier: alloc(o, 0x1000, Class::Fw, None, 0, false)?,
threshold: alloc(o, 24, Class::Fw, None, 0, false)?,
job_list: alloc(o, job_list::SIZE, graph_fw(), None, 0, false)?,
q: QueueSession::new(o)?,
})
}
fn finish(self, rings: &mut Objects) -> Result<ComputeGraph> {
let q = self.q.finish(rings)?;
Ok(ComputeGraph {
sched_ctx: self.sched_ctx,
notifier: self.notifier,
threshold: self.threshold,
job_list: self.job_list,
qscratch: q.qinfo.clone(),
qinfo: q.qinfo,
qstate: q.qstate,
Expand All @@ -189,6 +237,13 @@ impl ComputeGraph {
fw_stamp: q.fw_stamp,
})
}
}

impl ComputeGraph {
#[allow(dead_code)]
fn new(o: &mut Objects, rings: &mut Objects, sched_ctx: Arc<FwObject>) -> Result<Self> {
ComputeGraphSession::new(o, sched_ctx)?.finish(rings)
}
fn init(&self, abi: FwAbi, init_ctx: bool) -> Result {
if init_ctx {
self.sched_ctx.write(0, &graph::context_image())?;
Expand Down Expand Up @@ -226,16 +281,21 @@ pub(crate) struct RenderGraph {
pub(crate) legacy_empty: Arc<FwObject>,
pub(crate) registration_barrier: Arc<FwObject>,
}
impl RenderGraph {
struct RenderGraphSession {
ta: QueueSession,
fs: QueueSession,
sched_ctx: Arc<FwObject>,
notifier: Arc<FwObject>,
threshold: Arc<FwObject>,
job_list: [Arc<FwObject>; 2],
legacy_empty: Arc<FwObject>,
registration_barrier: Arc<FwObject>,
}
impl RenderGraphSession {
fn new(o: &mut Objects, context: Arc<FwObject>) -> Result<Self> {
let [ta, fs] = [QueueObjects::new(o)?, QueueObjects::new(o)?];
Ok(Self {
qscratch: [ta.qinfo.clone(), fs.qinfo.clone()],
qinfo: [ta.qinfo, fs.qinfo],
qstate: [ta.qstate, fs.qstate],
ring: [ta.ring, fs.ring],
user_stamp: [ta.user_stamp, fs.user_stamp],
fw_stamp: [ta.fw_stamp, fs.fw_stamp],
ta: QueueSession::new(o)?,
fs: QueueSession::new(o)?,
sched_ctx: context,
notifier: alloc(o, 0x1000, Class::Fw, None, 0, false)?,
threshold: alloc(o, 24, Class::Fw, None, 0, false)?,
Expand All @@ -254,6 +314,30 @@ impl RenderGraph {
)?,
})
}
fn finish(self, rings: &mut Objects) -> Result<RenderGraph> {
let [ta, fs] = [self.ta.finish(rings)?, self.fs.finish(rings)?];
Ok(RenderGraph {
qscratch: [ta.qinfo.clone(), fs.qinfo.clone()],
qinfo: [ta.qinfo, fs.qinfo],
qstate: [ta.qstate, fs.qstate],
ring: [ta.ring, fs.ring],
user_stamp: [ta.user_stamp, fs.user_stamp],
fw_stamp: [ta.fw_stamp, fs.fw_stamp],
sched_ctx: self.sched_ctx,
notifier: self.notifier,
threshold: self.threshold,
job_list: self.job_list,
legacy_empty: self.legacy_empty,
registration_barrier: self.registration_barrier,
})
}
}

impl RenderGraph {
#[allow(dead_code)]
fn new(o: &mut Objects, rings: &mut Objects, context: Arc<FwObject>) -> Result<Self> {
RenderGraphSession::new(o, context)?.finish(rings)
}
fn init(&self, abi: FwAbi) -> Result {
init_notifier(&self.notifier, &self.threshold)?;
for e in 0..2 {
Expand All @@ -272,26 +356,52 @@ impl RenderGraph {
}
}

/// Session-side queue graph allocations before sealing the session allocator and attaching
/// the firmware-cached work rings from a probe-time device-lifetime
/// [`Factory::persistent_objects_probe`] pool.
pub(crate) struct GraphSession {
compute: [ComputeGraphSession; sizes::COMPUTE_PIPES],
render: RenderGraphSession,
}

pub(crate) struct Graphs {
pub(crate) dev: ARef<device::Device>,
pub(crate) compute: [ComputeGraph; sizes::COMPUTE_PIPES],
pub(crate) render: RenderGraph,
/// Owns the firmware-cached work rings for the device lifetime (never dropped).
_ring_objects: core::mem::ManuallyDrop<Objects>,
}
impl Graphs {
#[inline(never)]
pub(crate) fn new(dev: &AsahiDrmDevice, o: &mut Objects) -> Result<Self> {
pub(crate) fn prepare(o: &mut Objects) -> Result<GraphSession> {
// Host polls sched_ctx from WC during register_context(); keep uncached and share one
// scheduling context across all compute pipes and the render graph.
let sched_ctx = alloc(o, sched_ctx::SIZE, Class::Fw, None, 0, false)?;
let compute = [
ComputeGraph::new(o, sched_ctx.clone())?,
ComputeGraph::new(o, sched_ctx.clone())?,
ComputeGraphSession::new(o, sched_ctx.clone())?,
ComputeGraphSession::new(o, sched_ctx.clone())?,
];
let render = RenderGraph::new(o, sched_ctx)?;
let render = RenderGraphSession::new(o, sched_ctx)?;
Ok(GraphSession { compute, render })
}

#[inline(never)]
pub(crate) fn finish(
dev: &AsahiDrmDevice,
session: GraphSession,
factory: &Factory,
) -> Result<Self> {
// Never dropped even on partial failure: ASC-cached mappings have no qualified teardown.
let mut ring_objects = core::mem::ManuallyDrop::new(factory.persistent_objects_probe());
let [c0, c1] = session.compute;
let compute = [c0.finish(&mut ring_objects)?, c1.finish(&mut ring_objects)?];
let render = session.render.finish(&mut ring_objects)?;
ring_objects.finish_private()?;
Ok(Self {
dev: dev.as_ref().as_ref().into(),
compute,
render,
_ring_objects: ring_objects,
})
}
}
Expand Down
34 changes: 26 additions & 8 deletions drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,19 @@ pub(crate) mod sizes {
/// Worst-case firmware work-ring entries per compute command (`fs2c` barrier + cross-pipe
/// `c2c` barrier + `work`).
pub(crate) const MAX_COMPUTE_RING_ENTRIES: usize = 3;
/// Maximum unfinished TA passes kept in flight at once so multi-pass render bursts stay
/// inside M4 firmware's `<= 4`-pass TA/scene pipeline without throttling single-pass
/// pipelining (where TA finishes well ahead of FS).
/// Maximum unfinished TA passes kept in flight at once for heavy multi-layer or large-tilemap
/// renders so heavy bursts stay inside M4 firmware's `<= 4`-pass TA/scene pipeline.
pub(crate) const TA_WAVE_PASSES: usize = 4;
/// Unfinished TA pass count at or below which a TA-wave-paused render queue wakes to
/// Maximum unfinished TA passes kept in flight at once for light single-layer renders
/// (`tilemap_bytes <= TA_LIGHT_TILEMAP_BYTES`), doubling the wave window for light render
/// bursts and deeper micro-coalesced batches.
pub(crate) const TA_WAVE_PASSES_LIGHT: usize = 8;
/// Tilemap byte threshold at or below which a single-layer render qualifies for
/// `TA_WAVE_PASSES_LIGHT`.
pub(crate) const TA_LIGHT_TILEMAP_BYTES: u64 = 64 * 1024;
/// Headroom below the active TA wave cap at which a TA-wave-paused render queue wakes to
/// launch the next wave, avoiding 1-pass stub drips.
pub(crate) const TA_WAVE_REFILL: usize = TA_WAVE_PASSES / 2;
pub(crate) const TA_WAVE_REFILL_HEADROOM: usize = 2;
/// Base render pass slots allocated on first render (full TPC/tilemap capacity).
pub(crate) const BASE_RENDER_SLOTS: usize = 2;
/// Retained render pass slots per VM at most. A slot is reused only after a later render
Expand Down Expand Up @@ -896,10 +902,22 @@ pub(crate) mod sizes {
);
/// Maximum jobs folded into one barrier-free compute horizon prefix.
pub(crate) const HORIZON_JOBS: u32 = COMPUTE_UNITS as u32;
/// Jobs admitted to the engine per logical queue: enough to keep a queue's commands
/// in flight back to back without scheduler backpressure stalls; exact prior-command
/// Maximum commands accumulated in a busy-state horizon micro-coalescing batch before
/// immediate publication, and maximum hold window (18 us) while a queue already has >= 2
/// active commands in flight.
pub(crate) const COALESCE_MAX_CMDS: usize = 6;
pub(crate) const COALESCE_WINDOW_US: u32 = 18;
pub(crate) const COALESCE_WINDOW_NS: u64 = (COALESCE_WINDOW_US as u64) * 1000;
/// Per-queue retired CDM execution EWMA threshold (microseconds) at or above which
/// barrier-free compute fans out across both CDM pipes instead of staying 1-pipe affine.
pub(crate) const COMPUTE_HEAVY_EMA_US: u32 = 200;
/// Elapsed wall-clock time (nanoseconds) on a sole active single-command compute flight
/// that immediately classifies the queue as heavy before its first retirement updates EWMA.
pub(crate) const COMPUTE_HEAVY_INFLIGHT_NS: u64 = 180_000;
/// Jobs admitted to the engine per logical queue: enough to keep deep queues (`d=64`)
/// queued back to back without scheduler backpressure stalls; exact prior-command
/// dependencies still gate each one.
pub(crate) const SCHEDULER_CREDITS: u32 = 32;
pub(crate) const SCHEDULER_CREDITS: u32 = 64;
/// Unconsumed records per 256-entry channel ring a prefix may be posted behind.
pub(crate) const AHEAD_RECORDS: u32 = 128;
/// Policy bound on logical queues reported in QUEUE_LIMITS (not a firmware limit).
Expand Down
12 changes: 7 additions & 5 deletions drivers/gpu/drm/asahi/g16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,19 @@ impl Firmware {
);
power.set_table(booted.init.rows);
let backend = (|| -> Result<_> {
let graph = graph::Graphs::new(dev, &mut booted.objects)?;
let graph_session = graph::Graphs::prepare(&mut booted.objects)?;
let slots = slots::Slots::new()?;
let pools = pools::Pools::new_boxed(dev)?;
let vms = vm::Registry::new()?;
let engine = engine::Engine::new()?;
let render_cmds = resources::RenderCmds::new()?;
let compute_cmds = resources::ComputeCmds::new()?;
let private_factory = booted.objects.private_factory(render_cmds, compute_cmds);
let graph = graph::Graphs::finish(dev, graph_session, &private_factory)?;
let slot = KBox::<Firmware>::new_uninit(GFP_KERNEL)?;
Ok((graph, slots, pools, vms, engine, render_cmds, slot))
Ok((graph, private_factory, slots, pools, vms, engine, slot))
})();
let (graph, slots, pools, vms, engine, render_cmds, slot) = match backend {
let (graph, private_factory, slots, pools, vms, engine, slot) = match backend {
Ok(backend) => backend,
Err(error) => {
dev_err!(
Expand All @@ -773,12 +776,11 @@ impl Firmware {
let boot::Booted {
session,
init,
mut objects,
objects,
channels,
events,
..
} = KBox::into_inner(booted);
let private_factory = objects.private_factory(render_cmds);
let mut firmware = slot
.write_init(init!(Firmware {
session,
Expand Down
Loading