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
12 changes: 11 additions & 1 deletion drivers/gpu/drm/asahi/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ pub(crate) trait Gpu: Send + Sync {
fn queue_limits(&self) -> Option<uapi::drm_asahi_queue_limits> {
None
}
/// GET_PARAMS feature bits that only this backend implements.
fn backend_feature_flags(&self) -> u64 {
0
}
/// Shared GET_PARAMS additions, using this backend's feature-number assignments.
fn feature_flags(&self) -> u64 {
let mut flags = 0;
let mut flags = self.backend_feature_flags();
if self.supports_vm_status() {
flags |= u64::from(uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_VM_STATUS)
| u64::from(uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_VM_STATUS_MIRROR);
Expand Down Expand Up @@ -1541,6 +1545,12 @@ extern "C" {

#[versions(AGX)]
impl Gpu for GpuManager::ver {
/// Render commands may order their dependencies on earlier renders after
/// their vertex half only (DRM_ASAHI_RENDER_FRAGMENT_BARRIERS).
fn backend_feature_flags(&self) -> u64 {
u64::from(uapi::drm_asahi_feature_DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS)
}

/// A light submission completes in tens of microseconds, so its submitter
/// sleeps briefly between submissions and the CPU scheduler places and
/// clocks it like idle work: on G13/G14 a single client then spends more
Expand Down
85 changes: 64 additions & 21 deletions drivers/gpu/drm/asahi/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,38 @@ fn wait_fence(fence: &Fence, interruptible: bool, timeout: kernel::ffi::c_long)

#[versions(AGX)]
impl Queue::ver {
/// Add a barrier to `queue_job` that waits for `event`.
fn add_explicit_barrier(
dev: &AsahiDevRef,
gpu: &gpu::GpuManager::ver,
queue_job: &mut workqueue::Job::ver,
event: &workqueue::QueueEventInfo::ver,
vm_slot: u32,
id: u64,
) -> Result {
let mut alloc = gpu.alloc();
mod_dev_dbg!(dev, "[Submission {}] Create Explicit Barrier\n", id);
let barrier = alloc.private.new_init(
pin_init::zeroed::<fw::workqueue::Barrier>(),
|_inner, _p| {
let queue_job = &*queue_job;
try_init!(fw::workqueue::raw::Barrier {
tag: fw::workqueue::CommandType::Barrier,
wait_stamp: event.fw_stamp_pointer,
wait_value: event.value,
wait_slot: event.slot,
stamp_self: queue_job.event_info().value.next(),
uuid: 0xffffbbbb,
external_barrier: 0,
internal_barrier_type: 1,
padding: Default::default(),
})
},
)?;
mod_dev_dbg!(dev, "[Submission {}] Add Explicit Barrier\n", id);
queue_job.add(barrier, vm_slot)
}

/// Waits, for at most [`QUEUE_CLOSE_WAIT_MS`], for the last submitted job to finish. The
/// jobs of one queue complete in order, so its finished fence covers all of them.
fn wait_submitted(&self) {
Expand Down Expand Up @@ -1237,6 +1269,15 @@ impl Queue for Queue::ver {
// Pre-increment command index to match last_compute/last_render
command_index += 1;

// A render's wait for earlier renders is added once its flags are
// known: without DRM_ASAHI_RENDER_FRAGMENT_BARRIERS it goes on the
// vertex queue; with it no barrier is added, since the wait names
// only earlier fragment work, which the fragment queue already runs
// first, so the vertex half can run beside it. Each fragment half
// still waits for its own vertex half.
let is_render =
u32::from(header.cmd_type) == uapi::drm_asahi_cmd_type_DRM_ASAHI_CMD_RENDER;
let mut render_wait = None;
for (queue_idx, index) in [header.vdm_barrier, header.cdm_barrier].iter().enumerate() {
if *index == uapi::DRM_ASAHI_BARRIER_NONE as u16 {
continue;
Expand All @@ -1245,32 +1286,16 @@ impl Queue for Queue::ver {
cls_pr_debug!(Errors, "Invalid barrier #{}: {}\n", queue_idx, index);
EINVAL
})? {
let mut alloc = gpu.alloc();
if is_render && queue_idx == SQ_RENDER {
render_wait = Some(*event);
continue;
}
let queue_job = match u32::from(header.cmd_type) {
uapi::drm_asahi_cmd_type_DRM_ASAHI_CMD_RENDER => job.get_vtx()?,
uapi::drm_asahi_cmd_type_DRM_ASAHI_CMD_COMPUTE => job.get_comp()?,
_ => return Err(EINVAL),
};
mod_dev_dbg!(self.dev, "[Submission {}] Create Explicit Barrier\n", id);
let barrier = alloc.private.new_init(
pin_init::zeroed::<fw::workqueue::Barrier>(),
|_inner, _p| {
let queue_job = &queue_job;
try_init!(fw::workqueue::raw::Barrier {
tag: fw::workqueue::CommandType::Barrier,
wait_stamp: event.fw_stamp_pointer,
wait_value: event.value,
wait_slot: event.slot,
stamp_self: queue_job.event_info().value.next(),
uuid: 0xffffbbbb,
external_barrier: 0,
internal_barrier_type: 1,
padding: Default::default(),
})
},
)?;
mod_dev_dbg!(self.dev, "[Submission {}] Add Explicit Barrier\n", id);
queue_job.add(barrier, vm_slot)?;
Self::add_explicit_barrier(&self.dev, &gpu, queue_job, event, vm_slot, id)?;
} else {
assert!(*index == 0);
}
Expand All @@ -1284,6 +1309,24 @@ impl Queue for Queue::ver {
cls_pr_debug!(Errors, "Unsupported render command fields\n")
})?;

// With FRAGMENT_BARRIERS the wait names only earlier fragment work of
// this queue (index 0 is its last fragment event, later indices are
// renders of this submission), which the fragment workqueue already
// runs first, so no barrier is needed at all.
let fragment_only = render.flags
& uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_FRAGMENT_BARRIERS
!= 0;
if let Some(event) = render_wait.take().filter(|_| !fragment_only) {
Self::add_explicit_barrier(
&self.dev,
&gpu,
job.get_vtx()?,
&event,
vm_slot,
id,
)?;
}

self.inner.submit_render(
&gpu,
&mut job,
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/asahi/queue/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl super::QueueInner::ver {
& !(uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_VERTEX_SCRATCH
| uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES
| uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING
| uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_DBIAS_IS_INT)
| uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_DBIAS_IS_INT
| uapi::drm_asahi_render_flags_DRM_ASAHI_RENDER_FRAGMENT_BARRIERS)
!= 0
{
cls_pr_debug!(Errors, "Invalid flags ({:#x})\n", cmdbuf.flags);
Expand Down
Loading