geom.c — Geometry (TA) kicks
Geometry (TA) kick and its completion.
Sources: docsClean kick-geometry-ta.md (phases A-G, the answers to
Q16b-Q16m), command-structs.md and data-structures.md (public
layouts), and the experiments E027-E040 (docs/logRefs/36.29.52.182/). The parameter
manager side lives in pm.c.
-
static inline uint64_t rd64(const uint8_t *p, uint32_t off)
Read a 64-bit field of a host structure.
- Parameters:
p – The structure.
off – Byte offset of the field.
- Returns:
The field.
-
static inline uint32_t rd32(const uint8_t *p, uint32_t off)
Read a 32-bit field of a host structure.
- Parameters:
p – The structure.
off – Byte offset of the field.
- Returns:
The field.
-
RTC_ZERO_LEN
Bytes of the render-target cache that are zeroed after an HWR.
-
static void geom_zero_caches(fwaddr_t ctxaddr, fwaddr_t memctx, const uint8_t *hwrt, const uint8_t *common)
Zero the TPC and the RTC with the CPU (after an HWR).
Follows
kick-geometry-ta.mdE andhardware-recovery.md: on a first kick withgeom_caches_need_zeroingset, the firmware maps the client memory and zeroes the tail pointer cache (tail_ptrs_dev_addr,hwrtdata_common.tpc_sizebytes) and, when there is one, the RTC (rtc_dev_addr,0x300bytes, traced asZero RTC for FWCtx). The SLC is flushed before (no dirty line may land over the zeroes) and after (the GPU must not read a stale line). When part of a range is not mapped, the SLC flush is all that is done for it.- Parameters:
ctxaddr – Firmware address of the render context.
memctx – Firmware address of its memory context.
hwrt – The HWRTData.
common – Its common data.
-
static void geom_pm_load(fwaddr_t ctxaddr, fwaddr_t memctx, fwaddr_t hwrt_fw, uint8_t *hwrt, const uint8_t *common, bool first)
Phase B: load an HWRTData into PM context 0.
Follows
kick-geometry-ta.mdB (answers to Q16h-Q16j and Q29b): the free lists andCONTEXT_PB_BASE, synchronised with a 3D of another context (Q38); the PM-MMU invalidation; the MLIST base and the catalogues; the VHeap table. A first kick then runs the TA cache command0x0258and the PM reset pulses0x0290/0x0198(render 2 on the second HWRTData stalls without them). A later kick of an HWRTData that another one evicted reloads its saved catalogues and stack pointers instead.- Parameters:
ctxaddr – Firmware address of the render context.
memctx – Firmware address of its memory context.
hwrt_fw – Firmware address of the HWRTData.
hwrt – The HWRTData.
common – Its common data.
first – This is the first kick of the render.
-
static void geom_rta_pr_reset(uint8_t *hwrt)
Start the partial-render bookkeeping of a new frame.
At a first kick after a partial render (
HWRT_FLAGS_PRIOR_PRset), the per-layer partial-render counters are zeroed and the flag is cleared: the renders of the previous frame’s partial renders are done (kick-compute-and-3d.md“Render-target arrays”, answer to Q31).- Parameters:
hwrt – The HWRTData.
-
RTC_BITMAP_OFF
Offset of the touched-layer bitmap in the render-target cache.
-
RTC_BITMAP_LEN
Size of the bitmap in bytes (2048 layers).
-
static void geom_rta_fill(uint8_t *hwrt, fwaddr_t memctx, uint64_t rtc)
List the layers of a render-target array render (answer to Q35).
Called at the last kick, before the TA starts.
valid_render_targets[]receives the firstactive_render_targetsset bits of the RTC bitmap atrtc_dev_addr + 0x200(bit k: layer k was touched by an earlier kick), read through the GPU MMU. When the bitmap cannot be read, every layer is listed in order. When fewer bits than the count are set, the count is lowered.current_render_targetbecomes the first listed layer.- Parameters:
hwrt – The HWRTData.
memctx – Firmware address of the render context’s memory context.
rtc – GPU address of the render-target cache.
-
void geom_rta_oom(uint8_t *hwrt, fwaddr_t memctx)
List the layers touched so far, when the TA runs out of memory before a
FRAG_PR(answer to Q31, step 3; layered partial renders, Q39).The partial render then runs the layer loop over them. Reads the layer count from
CR[0x0D20], flushes the RTC so that the bitmap is in memory (our addition), zeroesrtc_dev_addr + 0x000..0x1FFand scans the bitmap withgeom_rta_fill(). Does nothing without an RTC or with fewer than two layers.- Parameters:
hwrt – The HWRTData.
memctx – Firmware address of the render context’s memory context.
-
struct [anonymous]
The geometry context switch in progress (as
cswin frag.c).
-
bool kick_geom(fwaddr_t ctxaddr, struct fwcommoncontext *ctx, const struct ccb_cmd_header *hdr, const void *payload, uint32_t cmd_off)
Kick a geometry (TA) command.
The phases of
kick-geometry-ta.md:A. Bind the memory context to a BIF slot.
B. Load the HWRTData into PM context 0 when it is not there (or on a first kick); later kicks run the mid-TA cache command. Arm the SPM.
C. The geometry registers: PPP, TE, PSG region headers, tail pointers, screen and macrotile layout, anti-aliasing, the multisample control (flipped when asked), the VDM call stack and control stream.
D. The VDM context-state base, the RTC and the render-target array state, the TE core selection.
E. On a first kick, enable the geometry context and wait until the region headers are initialised.
F. HWRTData state, trace, data-master state.
G. Start the VDM (the last write).
- Parameters:
ctxaddr – Firmware address of the render context.
ctx – The render context.
hdr – The command header.
payload – The
rogue_fwif_cmd_geomcommand.cmd_off – Offset of the command in the client CCB.
- Returns:
truewhen the TA runs;falsewhen the command has no HWRTData, common data or local free list (it is retired without running).
Finish a geometry task (EV_TA_FINISHED).
Follows kick-geometry-ta.md “TPC flush, VHEAP store, and completion
sequence” (answers to Q19b and Q29) and runs before the geometry cache
flush. A non-last kick stores the VHeap. The TPC is flushed (without it
the tail pointers stay in the TE and every later render on the device
stalls, E041), and the RTC when there is one. The HWRTData then receives
the touched-layer count of a non-last kick, the PM stack pointers and
last catalogue bases (for a reload after eviction) and the
GEOM_FINISHED state. The free lists themselves are stored at the
fragment kick (Q19 answer).
- param s:
The geometry data master’s state.
-
static void geom_flush_tail(bool vheap, bool rtc)
The flushes of TA finished: the VHeap store (when asked), the TPC and, when there is one, the RTC.
- Parameters:
vheap – Store the VHeap (a non-last kick, or a stored TA).
rtc – An RTC is programmed.
-
static void geom_save_pm(uint8_t *hwrt)
Save the PM stack pointers and last catalogue bases into the HWRTData, for a reload after another HWRTData evicted it.
- Parameters:
hwrt – The HWRTData.
-
static bool geom_csw_enabled(void)
Whether the geometry may be preempted (
OS_CTXSWITCH_GEOM_EN, orEXP_CSW_FORCE).
-
void geom_csw_request(fwaddr_t new_ctx)
Ask the running TA to store its context, for a higher-priority geometry.
Programs the VDM and TA state bases and the store/resume task words of the current A/B buffer, ORs the command’s
vdm_context_resume_task0_sizeinto0x0450, then starts the store (CR[0x0468] = 1,CSW_17). Not during out-of-memory handling (assumption: the SPM owns the TA then).- Parameters:
new_ctx – Firmware address of the waiting context.
-
bool geom_csw_end(struct dm_state *s)
Finish a TA whose store was requested, at
TA_FINISHED.Waits for
CR[0x0430]bit 0. Without bit 1 the store came too late: thehwrtdata.flagsresume bit is cleared and the normal completion follows. With it, the VDM resume pointer (CR[0x0418]) is saved in the geometry context state,hwrtdata.flags |= 0x400, and the VHeap, TPC and RTC are flushed (CSW_13).CSW_16is logged in both cases. The PM stack pointers and catalogues are saved for a reload after eviction (as at TA finished). The caller flushes the geometry caches and releases the data master; theGEOMcommand is not retired.- Parameters:
s – The geometry data master’s state.
- Returns:
truewhen the TA was stored.
-
fwaddr_t geom_csw_yield_to(fwaddr_t ctxaddr)
The context a stored geometry context must let run first.
- Parameters:
ctxaddr – Firmware address of a context about to kick a geometry.
- Returns:
The higher-priority context it yields to, or 0.
-
void geom_csw_yield_done(void)
Stop yielding the geometry data master.
-
void geom_hwr_reset(void)
Forget a geometry context switch (after a hardware recovery).