Imagination_BXM-4-64

PM Out-of-Memory Management and Partial Render (SPM)

When the geometry submitted by a scene exceeds the pages currently available in the Parameter Manager (PM) freelists, the GPU raises an Out-of-Memory (PM_OUT_OF_MEMORY, EVENT_STATUS bit 7 = 0x80) event and pauses the TA stage. The SPM (Smart Parameter Management) subsystem transparently recovers the scene without failing the frame, using three progressive tiers:

  1. Consumption of ready_pages (reserve pages already pre-allocated by the host).
  2. Dynamic freelist growth (FWCCB_CMD_FREELIST_GROW → KCCB_CMD_FREELIST_GROW_UPDATE).
  3. Partial Render (PR): flushes the already accumulated geometry by executing an intermediate 3D pass (PM_PARTIAL_RENDER_ENABLE, 0x0338 = 1) with on-demand Z/S and MSAA buffers, frees the PM pages, and resumes TA from exactly where it paused.

1. Conceptual SPM State Flow ([D])

The internal numeric encoding of SPM states is free for the clean-room implementation (it is not part of the shared ABI with the host); only the observable transitions below are normative:

[Idle]
   │  EVENT_STATUS bit 7 (PM_OOM = 0x80)
   ▼
[Waiting for Growth / Waiting for In-Flight 3D]
   ├── If ready_pages > 0 or host grows freelist ────────────────► [Resume TA without PR]
   │                                                                      │
   └── If freelist reached max_pages / could not grow                     │
          │  (wait for in-flight 3D if any; request Z/S backing if needed)│
          ▼                                                               │
       [Partial Render Running] ──► DM3 executes FRAG_PR (0x0338 = 1)     │
          │  PIXELBE_END_RENDER (0x08)                                    │
          ▼                                                               │
       [Resume TA post-PR]                                                │
          │                                                               │
          └─────────────────────► Resume TA hardware ─────────────────────┴──► [Idle]

2. Handling the PM_OUT_OF_MEMORY Event (EVENT_STATUS & 0x80) ([D])

Upon receiving EVENT_STATUS bit 7 in the IRQ (HW1) context:

  1. Clear the event: CR[0x0138] = 0x80.
  2. Identify the PM state:
    • Read the PM status registers to determine which freelist (local or global) was exhausted and how many pages are allocated.
    • Update struct rogue_fwif_freelist with the current current_stack_top read from hardware.
  3. Tier 1 — Immediate ready_pages:
    • If freelist.ready_pages > 0, the firmware immediately incorporates these pages into the active freelist (reloads the freelist in the PM via 0x0208 / 0x0200 + 0x20B0/0x20A8, see kick-geometry-ta.md), clears ready_pages, and schedules immediate TA resumption (without Partial Render), while optionally requesting FREELIST_GROW from the host to replenish the reserve.
  4. Tier 2 — Growth Request (FWCCB_CMD_FREELIST_GROW):
    • If freelist.current_pages + freelist.grow_pages <= freelist.max_pages:
      • Send FWCCB_CMD_FREELIST_GROW (0x2ABC0067) with freelist_id and grow_pages, waking the host (hwirq 75).
      • Wait for the KCCB_CMD_FREELIST_GROW_UPDATE (0x2ABC006E) response (while TA remains paused).
      • If the host succeeded in allocating the pages (new_size > current_pages), the firmware reloads the freelist in the PM and schedules TA resumption without PR.
  5. Tier 3 — Fallback to Partial Render (PR):
    • If the freelist reached max_pages or the host returned zero growth (allocation failure):
    • If a normal 3D render is already running on DM3, the firmware waits for its completion (freeing PM pages at the end of 3D may by itself return space to the global freelist and avoid PR).
    • If memory is still exhausted after the previous 3D completes (or if DM3 is idle):
      • Check the on-demand buffers of HWRTData (Z/S and MSAA scratch) that are not yet populated:
        • emit ROGUE_FWIF_FWCCB_CMD_ZSBUFFER_BACKING (0x2ABC0065) with the buffer identifier in the payload and wait for ROGUE_FWIF_KCCB_CMD_ZSBUFFER_BACKING_UPDATE (0x2ABC006C) from the host. In DDK 24.2 the same command appears as PRBUFFER_BACKING, since it also covers Partial Render buffers;
        • if the buffer is already BACKED or has a pending request, do not re-emit (see §5.1).
      • Schedule the ROGUE_FWIF_CCB_CMD_TYPE_FRAG_PR command for the same HWRTData at highest priority on DM3.

3. Partial Render Execution (DM3) ([P][D])

Partial Render executes nearly the same sequence as a normal 3D kick (kick-compute-and-3d.md). The firmware knows it is in a PR because the SPM controller state is 4; this state is passed to the kick as the is_pr parameter.

  1. Enable PR mode in the PM: write BCAST[0x0338] = 1 (ROGUE_CR_PM_PARTIAL_RENDER_ENABLE), clear CR[core*0x80000+0x0388] (3D mem-free disabled) and, unless the command requests otherwise, enable 0x0388 only when there is one core. Also publish CR[0x03D8] = rta_ctl.current_render_target and CR[0x03E0] = 1 when this is the last active RT. BCAST[0x06D0] (pixel merge) comes from the command (default value 0x1F).
  2. Disable CSW on DM3 while Partial Render is running (a Partial Render can never be preempted via CSW).
  3. Save partial state in Z/S + Color: use the addresses of the on-demand populated Z/S and MSAA buffers to preserve depth/stencil and color across partial passes.
  4. On completion (PIXELBE_END_RENDER, 0x08):
    • Execute all RTA slices if applicable.
    • Execute the DM3 completion flush (data-masters.md §4.1).
    • Set HWRTDATA_PARTIAL_RENDERED (BIT(3) in hwrtdata.hwrt_data_flags).
    • Update hwrtdata.state = ROGUE_FWIF_RTDATA_STATE_PARTIALRENDERFINISHED (8).
    • Do not retire the final 3D command from the cCCB (PR is an intermediate execution).
    • Schedule the post-PR TA resume sequence in the HW1 context.

3.1 What Changes Between 1st PR, 2nd+ PR, and Final Post-PR 3D ([D])

The kick is the same in all three cases (same 3D routine, same HWRTData); what changes is a small set of inputs:

Input 1st PR 2nd+ PR Final post-PR 3D
Command type FRAG_PR FRAG_PR FRAG
is_pr (SPM state == 4) 1 1 0
HWRTDATA_PARTIAL_RENDERED (bit 3) 0 1 (set at end of 1st) 1
BCAST[0x0338] 1 1 0
pds_bgnd[3] → 0x06A0..0x06AC/0x06B8/0x06BC pds_bgnd pds_bgnd pds_pr_bgnd (only with ROGUE_FRAG_FLAGS_SCRATCHBUFFER)
isp_ctl.PROCESS_EMPTY_TILES (bit 17) 0 0 1 (same condition)
CR[0x0388] (3D mem-free) 0 (or num_cores == 1) same programmed normally
isp_zlsctl (Z/S load) forced to “do not load” if buffer is not BACKED same loads from already populated buffer
Counter rta_ctl.sRTANumPartialRenders[RT] increments increments does not increment
HWRTData state on completion PARTIALRENDERFINISHED (8) PARTIALRENDERFINISHED (8) 3DFINISHED (5)

Practical takeaways:


4. Resuming TA After Growth or PR ([D])

In the interrupt handler (HW1), when the OOM-paused TA is ready to resume:

Case A — Resume Without PR (freelist grew or 3D freed pages)

  1. Set hwrtdata.state = ROGUE_FWIF_RTDATA_STATE_KICK_GEOM (1).
  2. Write CR[0x0328] = 1 (release/resume PM after OOM).
  3. Write CR[0x0CF8] = 1 (resume TE/VDM from the point where it paused).
  4. Re-enable DM2 HWR monitoring, return the SPM controller to the idle state, and signal CR[0x0B00] = 0.

Case B — Post-Partial Render Resume

  1. If the HWRTData was loaded in the 3D context (HW ctx 1) with state ROGUE_FWIF_RTDATA_STATE_PARTIALRENDERFINISHED (8), save the PM catalogue bases of context 1 and unbind it.
  2. Set hwrtdata.state = ROGUE_FWIF_RTDATA_STATE_KICK_GEOM (1).
  3. Update PM context selection in CR[0x03D0] and CR[0x03D4] (mask ~0x10000 / ~0x100 for primary context, or bits 0x20000 / 0x200 for secondary context).
  4. Write CR[0x0290] = 1 and CR[0x0198] = 1 (post-PR PM list state reinitialization).
  5. Invalidate the PM Page Catalogue MMU cache (mask = 1 for primary ctx, 4 for secondary ctx).
  6. If applicable for the PM mode, clear the context PM catalogue registers at CR[0x1248/1250/1260] (or 0x1268/1270/1280 for secondary).
  7. Trigger PM allocation cleanup/reset: CR[0x01B8] = 1 → Mandatory poll CR[0x01B8] bit 0 == 0.
  8. Resume PM and TA post-PR:
    • Write CR[0x0328] = 1
    • Write CR[0x0CA8] = 1 (resume TE after PR — distinct from 0x0CF8 used in the non-PR case)
  9. Reset the DM2 HWR timestamp/deadline, return the SPM controller to the idle state, and signal CR[0x0B00] = 0.

5. On-Demand Z/S and MSAA Backing ([P][D])

5.1 Observed Protocol ([D])

The firmware describes on-demand buffers using a stateful descriptor (RGXFWIF_PRBUFFER_STATE: UNBACKED=0, BACKED=1, BACKING_PENDING=2, UNBACKING_PENDING=3). The request routine walks a null-terminated list and, per buffer:

if the descriptor says the buffer is unused:       do not request (log it)
else if state == BACKED:                           do not request
else if state == BACKING_PENDING:                  do not request (request already in flight)
else (UNBACKED, or UNBACKING_PENDING):             emit FWCCB 0x2ABC0065 (ZS/PR buffer) with the ID
                                                   mark BACKING_PENDING

When the host finishes, it sends KCCB_CMD_ZSBUFFER_BACKING_UPDATE (0x2ABC006C) with the ID; the firmware marks the buffer as BACKED and the pending PR can be dispatched. The unbacking path emits ROGUE_FWIF_FWCCB_CMD_PRBUFFER_UNBACKING (0x2ABC0066) when the final 3D render of that HWRTData completes normally and no other render references the buffer.

5.2 Where the Address Enters ZLS Registers ([D])

The address returned by the host is not written directly by the KCCB handler: it takes effect on the next 3D kick, which already reads isp_zload_store_base and isp_stencil_load_store_base from the command and applies:

BCAST[0x0F48] = isp_zlsctl
BCAST[0x0F50]/[0x0F54] = isp_zload_store_base        (+ current_rt * zls_stride, via slice patch)
BCAST[0x0F58]/[0x0F5C] = isp_zload_store_base        (store — same value on normal kick)
BCAST[0x0F60]/[0x0F64] = isp_stencil_load_store_base
BCAST[0x0F68]/[0x0F6C] = isp_stencil_load_store_base

If the buffer descriptor indicates it is not BACKED at kick time, the firmware forces the “do not load” bits in isp_zlsctl (0x8002 for depth, 0x4002 for stencil) instead of reading unpopulated memory.

5.3 Deallocation

FWCCB_CMD_ZSBUFFER_UNBACKING (0x2ABC0066, PRBUFFER_UNBACKING in DDK 24.2) is emitted when HWRTData no longer needs the buffer (end of the final 3D render, or HWRTData teardown), so the driver can release the physical memory temporarily allocated during Partial Render.


6. Per-Register OOM Flow ([O])

The event is bit 7 (0x80) of ROGUE_CR_EVENT_STATUS, cleared with CR[0x0138] = 0x80. Decision path:

CR[0x0138] = 0x80;                       /* event W1C */
if (!ctx->oom_flag) handle_oom(...);
else { mark DM lockup; notify context reset; }   /* escalates to HWR */

6.1 Which Freelist Exhausted

There is no “which PB” register: the firmware derives it from HWRTData:

fl = (hwrtdata.flags & GLOBAL_PB_NUMBER_BIT0)
        ? hwrtdata.apsFreeLists[2]      /* global  */
        : hwrtdata.apsFreeLists[1];     /* local   */

6.2 Growth (grow) and Ack

if fl.ready_pages (+0x30) == 0:                 /* no reserved pages */
    CR[0x0320] = 1                              /* terminate/flush TA */
    poll(CR[0x0130] & 0x40 == 0x40)             /* TA_TERMINATE */
    if timeout: DM2 completion flush (data-masters.md §4.1)
    oom_bitmap |= 1 << dm ; mark "HWR pending"
else:
    grow(fl, fl.current_pages + fl.ready_pages)
    CR[0x0328] = 1                              /* ack: resume PM/TA */
    sample_progress(0x6020)
    CR[0x0B00] = 0                              /* MTS: reschedule BG */
    request new grow from host (freelist grow KCCB)

That is: 0x0328 is the ack that resumes the PM; 0x0320 only appears on the path where there are no reserved pages and TA must be terminated/flushed.

6.3 OOM During HWR

If an HWR is already in progress, OOM is not handled immediately: the DM is recorded in an internal bitmap and re-evaluated when HWR finishes (the IRQ handler only invokes OOM handling when the HWR state is idle).