Imagination_BXM-4-64

Data Master Scheduler and Preemption (CSW)

This document describes the per-Data Master (DM) context scheduling model, hardware overlap rules, and the cooperative preemption (CSW — Context Switch) protocol on the SpacemiT K3 (36.56.104.183).


1. Per-Data Master Queues ([P][D])

The scheduler manages an independent set of queues for each active DM on the K3:

DM Public Name Controlled Hardware Managed Queues
0 PVR_FWIF_DM_GP General control / KCCB KCCB + synchronization tasks
2 PVR_FWIF_DM_GEOM VDM + TE + PPP + PM (ctx 0) waiting_list, run_list, active_ctx
3 PVR_FWIF_DM_FRAG ISP (6 pipes) + PBE + ZLS + PM (ctx 1) waiting_list, run_list, active_ctx (shared among FRAG 3D, FRAG_PR, and TQ_3D)
4 PVR_FWIF_DM_CDM CDM + PDS + USC waiting_list, run_list, active_ctx

Absent DMs on K3: DM1 (TDM) and DM5 (RAY) do not exist on this silicon.


2. Scheduling Cycle ([D])

For each active DM (GEOM, FRAG, CDM), the scheduler maintains:

Advancement Rules (BG / HW0)

  1. Dependency evaluation (waiting_list → run_list):
    • For each context on waiting_list, advances past PADDING / PRIORITY and evaluates FENCE / FENCE_PR.
    • If blocked by a still-pending UFO/Sync Checkpoint (!= expected and != 0xEFF), it remains on waiting_list.
    • If unblocked:
      • If the next command is CCB_CMD_TYPE_NULL, retires it immediately, executes the following UPDATEs, and re-evaluates.
      • If it is a real TASK, moves the context to run_list (preserving priority order).
  2. Dispatch (run_list → hardware):
    • If the DM is idle (active_ctx == NULL) and not blocked by HWR/SPM/APM (FORCED_IDLE/POW_OFF):
      • Selects the highest-priority context in run_list.
      • Checks DM-specific preconditions (e.g., for FRAG, HWRTData not in conflict; if there is a pending SPM Partial Render, it has absolute priority over any normal 3D render on DM3!).
      • Activates MemCtx in the BIF (see data-masters.md).
      • Programs the DM registers and triggers the kick.
      • Arms HWR deadline monitoring for that DM.
    • If the DM is busy (active_ctx != NULL) and there is a context in run_list with strictly higher priority (or a switch requirement when CSW is enabled in fw_sys_config_flags):
      • Initiates the Cooperative Preemption (CSW) sequence (section 4).

3. Overlap Rules Between Data Masters ([P][D])

The BXM-4-64 silicon (36.56.104.183) has COMPUTE_OVERLAP = 1 and a decoupled tile-based pipeline. Overlap is not decided by the host: the firmware admits or serializes it at kick time based on configuration flags, the state of each DM, and context priorities (§5 and §6).

Simultaneous Combination Allowed on K3? Restrictions
GEOM (DM2) + FRAG (DM3) Yes Distinct hardware (VDM/TE/PPP vs ISP/PBE/ZLS) and distinct PM contexts (ctx 0 vs ctx 1). On the same HWRTData, normal FRAG is only dispatched after TA publishes TA_FINISHED (LASTKICK); serialization comes from the HWRTData state, not a bus lock. During Partial Render, TA is paused and FRAG_PR runs alone
GEOM (DM2) + CDM (DM4) Yes Default (COMPUTE_OVERLAP), subject to the Compute command’s exclusivity flags (§6)
FRAG (DM3) + CDM (DM4) Yes Default, overridable by FRAG: ROGUE_FRAG_FLAGS_PREVENT_CDM_OVERLAP (bit 26 of the command’s flags field, in cmd_frag.flags) causes the firmware to hold back CDM while FRAG is active
FRAG (DM3) + FRAG (DM3), including TQ_3D No TQ_3D is a kick type (ROGUE_FWIF_CCB_CMD_TYPE_TQ_3D), not a DM: it uses the same DM3 and the same queue, so it executes strictly serialized
GEOM (DM2) + GEOM2 (DM6) Irrelevant on K3 The scheduler has a path for PVR_FWIF_DM_GEOM2, but the K3 driver never submits to this DM

Correction (2026-11-28): earlier versions of this page listed TQ_3D as a “DM sharing the pipeline”. Verification against the binary shows the scheduler uses indices 2 = GEOM, 3 = FRAG, 4 = CDM, and 6 = GEOM2; TQ_3D arrives as a DM3 command.

3.1 Why GEOM and FRAG Can Coexist in the Same Frame

  1. The PM has three logical contexts and two hardware contexts; TA occupies context 0 and 3D occupies context 1 (see kick-geometry-ta.md §2).
  2. The page catalogs (vce_cat_base, te_cat_base, alist_cat_base) are per context, so two different HWRTData instances do not contend for the same catalog registers.
  3. The TA → 3D dependency is expressed by the HWRTData state (ROGUE_FWIF_RTDATA_STATE_*), evaluated by the scheduler before moving the context from waiting_list to run_list.

4. Cooperative Preemption — Context Switch (CSW) ([P][O][D])

Context preemption on Rogue GPUs is hardware-cooperative: the firmware requests the unit to save its state to memory at the next safe boundary (primitive/tile/workgroup boundary) and waits for the normal DM completion interrupt. It has been validated on K3 hardware under simultaneous contention between 2 processes (3D + Compute/3D).

Preconditions to Initiate a CSW Store ([D])

CSW Store Triggers per DM ([D])

DM Register Setup Before Trigger Hardware Trigger Verification on Completion (HW1)
DM2 (GEOM / TA) Programs context CSW state addresses: 0x0428 (VDM state base), 0x0CC0 (TA state base), 0x0438, 0x0440, 0x0448, 0x0450 (ORed with command task_size), 0x0458, 0x0460 CR[0x0468] = 1 Upon TA_FINISHED (0x20): polls ROGUE_CR_VDM_CONTEXT_STORE_STATUS (0x0430) bit 0 == 1 with a short timeout in CR_TIMER ticks (fallback on expiration: pulses CR[0x0100] = 0x804000 → 0, restoring 0x0420 and 0x0418). If bit 1 of 0x0430 == 1, TA was stored (preempted) before finishing: saves CR[0x0418] (call stack pointer) into the context CSW state, internally marks HWRTData as TA-preempted, and does not retire the cCCB command
DM3 (FRAG / 3D) No extra setup (resume/tile state managed by ISP/PM) BCAST[0x1000] = 1 Upon PIXELBE_END_RENDER (0x08): checks ROGUE_CR_ISP_STATUS (0x1038) bit 0 == 0 (render stopped before completion). If preempted: saves CR[0x1008] (ISP state) into context_state, polls CR[0x03F8] mask 0xC2 == 0xC2, saves CR[0x0360] and CR[0x0370] into context_state, marks context as preempted, and does not retire the cCCB command
DM4 (CDM) cdm_context_state_base_addr was already loaded into 0x0498/0x049C at kick time BCAST[0x0488] = 1 Upon COMPUTE_FINISHED (0x04): polls ROGUE_CR_CDM_CONTEXT_STORE_STATUS (0x04A0) bit 0 == 1. If bit 1 of 0x04A0 == 1, CDM was stored: records the stored-cores bitmask in the context and does not retire the cCCB command

Resuming a Preempted Context ([D])

When the preempted context is scheduled again later:


5. Kick Admission: the Overlap Test ([D])

Before programming the DM, the firmware runs an admission test that answers “can this kick run now, or must it wait?”. The test is per DM and evaluates, in this order:

5.1 Global Gate

A gate precedes all rules below: while hardware recovery (HWR or a restart request) is in progress and the SPM controller is idle, no new kick is admitted, preventing the GPU from receiving new work during recovery.

5.2 Serialized Mode: ROGUE_FWIF_INICFG_DISABLE_DM_OVERLAP

The host sets this bit (BIT(19) of sysdata.config_flags) when the SLC is smaller than 4 KiB (ROGUE_FWIF_SLC_MIN_SIZE_FOR_DM_OVERLAP_KB in pvr_fw.c). When set, the firmware serializes the DMs:

if any other DM has an active context:
    admit ONLY if that DM is "held" by OOM/SPM
        (DM's bit set in the pending-OOM DM mask)
    else: block

DMs held by OOM do not block the others — this is what allows SPM to make progress (a TA in OOM does not block the 3D that will free pages).

5.3 Overlapped Mode (Default on K3)

Without DISABLE_DM_OVERLAP, the test is:

  1. Core partitioning. The firmware maintains a mask of cores already committed to overlapped work. Each DM has an assigned core; CDM requests:
    • SINGLE_CORE (ROGUE_COMPUTE_FLAG_SINGLE_CORE, bit 5 of cmd_compute.flags) → mask 1;
    • otherwise → (1 << num_cores) - 1 (all cores), with num_cores = ROGUE_CR_MULTICORE_SYSTEM (0xF308). If the requested mask does not intersect the already-occupied cores, the kick passes.
  2. Priority. For DMs contending for the same core, the kick is blocked when candidate.i32Priority < active.i32Priority (strict comparison). Ties do not block. The field is i32Priority of struct rogue_fwif_fwcommoncontext.
  3. Command vetoes.
    • FRAG: ROGUE_FRAG_FLAGS_PREVENT_CDM_OVERLAP (bit 26) blocks CDM.
    • Compute: the two DDK 24.2 exclusivity flags (bits 1 and 4 of the flags word) cause the test to return blocked. The DDK 24.2 client header is not public; a new implementation should map its own API to these two bits.
  4. Global PB selection. For GEOM, the kick also requires coherence with the global parameter buffer number in hwrt_data_flags (bits 8–9), except when the HWRTData is in HWRTDATA_GEOM_NEEDS_RESUME (bit 10), in which case resumption is always admitted.

5.4 Practical Consequence


6. PM Synchronization Between DMs Sharing a Freelist

When two contexts use the same global freelist, the firmware does not block the kick because of it: the freelist is referenced by the HWRTData (apsFreeLists[]) and consumption is accounted in the PM itself. Contention surfaces as PM_OUT_OF_MEMORY (bit 7 of EVENT_STATUS), handled by SPM (partial-render-spm.md):

  1. The overflowing DM is marked in the pending-OOM DM mask and the event is cleared.
  2. Handling only runs when HWR state is idle (OOM during HWR is deferred).
  3. While TA is paused, the marked DM does not block the others in the admission test (§5.2), allowing in-flight 3D work to finish and return pages.
  4. If no pages are available and growth is not possible, SPM runs a Partial Render on DM3 with the same HWRTData — which necessarily waits for the previous 3D (§3).