171 definitions in 12 files, 0 with an encoding diagram. src/isa/rsx
| File | Definitions | Other | What |
|---|---|---|---|
| package.lisp | 0 | 0 | the ISA.RSX package: the RSX (the PS3's GPU), described as an ISA. |
| defrsx.lisp | 0 | 11 | the RSX as an ISA: DEFMETHOD-RSX, the method table, RSX enumerations. |
| format.lisp | 0 | 8 | the RSX's texture, vertex attribute and surface formats, as core texel formats. |
| state.lisp | 0 | 21 | the RSX machine: registers, abstract state, memory windows, the FIFO's own state. |
| vp.lisp | 45 | 29 | the RSX vertex program: encodings, decoders, semantics on the shading machine, the interpreter. |
| fp.lisp | 67 | 29 | the RSX fragment program: encodings, decoder, semantics on the shading machine, the interpreter. |
| nv406e.lisp | 6 | 4 | NV406E (the channel's DMA class): reference, semaphores; and the GCM driver methods. |
| nv4097.lisp | 50 | 11 | NV4097 (NV40 Curie, the RSX's 3D class): methods as effects on the abstract state. |
| texture.lisp | 0 | 19 | NV4097 textures: the 16 fragment and 4 vertex texture units, decoded into the abstract state. |
| xfer.lisp | 3 | 0 | the transfer classes: NV0039 (memory to memory), NV3062/NV309E (2D surfaces), |
| dispatch.lisp | 0 | 2 | RSX-METHOD: one method write, generated from the method table. |
| fifo.lisp | 0 | 3 | the command processor: GET chases PUT through the command buffer. |
The RSX (the PS3's GPU, an NV47) is translated the way the CPUs are: as a
match problem (docs/isel.md). Its instructions are
methods: the command processor (the FIFO) writes 32-bit values to
method addresses. Each method's semantics is written as effects on the
abstract graphics state of the core (src/core/gfx.lisp), in the same
spelling as the Vulkan commands of src/isa/vk. ctil can then match an
RSX state change against the cheapest Vulkan commands with the same effect
(vk-state-change-plan, src/isa/vk/cost.lisp).
Package ISA.RSX (uses CL and CORE).
| File | Role |
|---|---|
package.lisp | the package and its exports |
defrsx.lisp | defmethod-rsx and friends, the method table, RSX enumerants to canonical codes, RSX formats to VkFormat, guest-memory fields to host fields |
state.lisp | the machine: method registers, the abstract state, memory windows and the IO map, FIFO and draw state, transform program and constants, display buffers and flips, rsx-reset, the event sink rsx-event |
nv406e.lisp | NV406E (the channel): reference, semaphores; the GCM driver's flip methods |
nv4097.lisp | NV4097 (3D): surfaces, viewport, scissor, depth/stencil, alpha test, blending, raster, vertex and index arrays, draws, clears, programs, semaphores |
vp.lisp, fp.lisp | the vertex and fragment programs as ISAs: encodings, decoders, semantics on the shading machine (src/core/shade.lisp), interpreters, assemblers (docs/shade.md) |
xfer.lisp | NV0039 (memory to memory), NV3062/NV309E (2D surfaces), NV308A (image from CPU), NV3089 (scaled image): scaffold |
dispatch.lisp | rsx-method, generated from the table: store the register, run the body |
fifo.lisp | rsx-command, rsx-run (the command processor); rsx-assemble (command buffers at compile time) |
(defmethod-rsx NV4097_SET_DEPTH_FUNC #x0A6C (value)
(setf (gs depth compare) (rsx->gfx compare-op value)))
(defmethod-rsx NV4097_SET_VERTEX_DATA_ARRAY_FORMAT (#x1740 16 4) (value i)
(let ((type (ldb (byte 4 0) value)) (size (ldb (byte 4 4) value)))
(setf (gs vertex-attribute i enable) (b2i (/= size 0))
(gs vertex-attribute i format) (rsx-vertex-vk-format (+ (* 16 type) size))
(gs vertex-binding i stride) (ldb (byte 8 8) value) ...)))
(define-rsx-registers (NV4097_SET_SURFACE_PITCH_Z #x022C) ...) ; stored, read with REG
(defrsx-derive rsx-derive-cull () ; shared by several methods
(setf (gs raster cull-mode)
(if (= (reg NV4097_SET_CULL_FACE_ENABLE) 0)
(gfx-code cull-mode none)
(rsx->gfx cull-mode (reg NV4097_SET_CULL_FACE)))))
(defmethods-rsx ((NV4097_SET_CULL_FACE_ENABLE #x183C) (NV4097_SET_CULL_FACE #x1830)) (value)
(rsx-derive-cull rsx))
NV4097,
NV406E, NV0039, NV3062, NV309E, NV308A, NV3089, GCM).(base
count stride) for an arrayed method (blend per target, viewport scale
and offset, vertex arrays, textures, transform program and constants).
Overlaps are errors.(reg NAME [i]) reads any method's last value. Abstract fields that
several registers make up (a surface's DMA object, offset and pitch;
cull enable and face; two-sided stencil) are recomputed by a
defrsx-derive helper from all of them.rsx-sem-body returns the recorded body; rsx-writes the (group
field) pairs it assigns, including those of the helpers it calls.
rsx-method-at / rsx-method-name-at decode an address.define-rsx-enum lists the GL-style values of each
canonical name ((less #x201)), and rsx->gfx expands to a case.
Formats are core texel formats with guest codes (format.lisp); a host
derives its own from them (docs/texfmt.md), and
rsx_plan prints the Vulkan plan of each.state.lisp)(make-rsx) holds the registers (16384 words), gfx, the memory windows
the HLE sets, the command processor's status and call return, the draw
being collected, the transform program (544 instructions) and constants
(468), flip and transfer counters.
| Location | DMA object | Effective address |
|---|---|---|
local (CELL_GCM_LOCATION_LOCAL 0) | #xFEED0000 | local-base (#xC0000000) + offset |
main (CELL_GCM_LOCATION_MAIN 1) | #xFEED0001 | through the IO map (rsx-io) |
| semaphores | #x66606660, #x66616661 | label-base + offset |
| reports | #x66626660 | label-base + #x1400 + offset |
IO map: io-map holds the effective 1 MiB page of each of the 512 IO
pages (#xFFFF unmapped), filled by rsx-map-io / rsx-unmap-io. Until
the first page is mapped (io-mapped 0) IO offset 0 is at io-base and
the space is linear, which is what the hand-built tests use.
Display: display-offset/pitch/width/height (8 buffers, offsets in local
memory) and display-count are set by cellGcmSetDisplayBuffer. A flip
method (GCM_FLIP_COMMAND, GCM_FLIP_HEAD) calls rsx-flip: the buffer
becomes flip-buffer, flips counts it, flip-status becomes 0
(CELL_GCM_DISPLAY_FLIP_STATUS_DONE), label 1 (16 bytes at label-base +
#x10, what cellGcmSetWaitFlip waits on) is cleared, and flip-handlers
counts a flip handler call the HLE owes the PPU.
Events: after each gfx-clear (one per surface of a CLEAR_SURFACE),
each gfx-draw and each flip, the RSX calls (rsx-event rsx kind) with
+rsx-event-clear+, +rsx-event-draw+ or +rsx-event-flip+, while the
state is that of the event. The definition here does nothing. The
presenter (src/present) defines it again: the last definition loaded is
the one ECL calls and ctil lowers. Builds without the presenter (the HLE
and loader tests, the disc test) keep the empty one.
Guest-memory objects in the abstract state are addresses
(attachment address/pitch, depth-attachment, vertex-buffer
address, index address); a run-time cache turns them into host
objects. rsx-host-fields maps a changed memory field to the host fields
it resolves to (vertex-buffer address to buffer and offset), which
is what vk-state-change-plan takes.
fifo.lisp)(rsx-run rsx limit) runs commands from GET to PUT (IO offsets in the
CellGcmControl registers at control: PUT +0, GET +4, REF +8), writes
GET back after each, and leaves the reason it stopped in rsx-status:
| Status | When |
|---|---|
+rsx-idle+ | GET reached PUT, or a command's arguments are not all before PUT yet |
+rsx-spin+ | a jump to itself (libgcm's idle loop) |
+rsx-blocked+ | NV406E_SEMAPHORE_ACQUIRE does not hold; the command runs again next time |
+rsx-limit+ | LIMIT commands ran |
+rsx-error+ | an invalid header, a call within a call, a return without a call |
Headers: increment and non-increment (bit 30) method writes with an
11-bit count (count 0 is a NOP), the old (001 + 29 bits) and new (..01)
jumps, call (..10, one level, as the RSX) and return (0x00020000).
The method field includes the subchannel bits, and the classes sit one per
subchannel, so the address alone names the method.
Draws: SET_BEGIN_END(prim) sets the topology; each DRAW_ARRAYS /
DRAW_INDEX_ARRAY value is a range of up to 256; contiguous ranges are
merged (a long strip is sent in pieces) and become one gfx-draw at a gap
or at SET_BEGIN_END(0). Indexed draws take SET_VERTEX_DATA_BASE_INDEX
as the vertex offset. CLEAR_SURFACE makes one gfx-clear-masked per
active colour surface and one depth/stencil gfx-clear.
rsx-assemble builds command buffers at compile time:
(rsx-assemble #x1000
'((NV4097_SET_DEPTH_FUNC #x203 1 1) ; incrementing: FUNC, MASK, TEST
(:ni NV4097_DRAW_ARRAYS #xFF000000 #x2B000100) ; non-incrementing
(:call sub) done (:jump done)
sub (NV4097_SET_BEGIN_END 0) (:return)))
tests/isa/rsx/plan.lisp runs a frame through the FIFO, takes the fields that
change between draws, and plans them for a Vulkan 1.3 pipeline with every
core dynamic state, and for one with extended dynamic state 3 as well:
draw 2 changes ((raster cull-mode) (raster front-face) (depth compare))
1.3: (:COST 3 :COMMANDS ("vkCmdSetCullMode" "vkCmdSetFrontFace" "vkCmdSetDepthCompareOp") :PIPELINE NIL)
draw 3 changes ((blend enable) (blend src-color) (blend dst-color) (blend src-alpha) (blend dst-alpha) (blend write-mask))
1.3: (:COST 25 :COMMANDS NIL :PIPELINE :SWITCH)
eds3: (:COST 3 :COMMANDS ("vkCmdSetColorBlendEnableEXT" "vkCmdSetColorBlendEquationEXT" "vkCmdSetColorWriteMaskEXT") :PIPELINE NIL)
draw 5 changes ((primitive topology) (vertex-buffer address) (index address))
1.3: (:COST 5 :COMMANDS ("vkCmdSetPrimitiveTopology" "vkCmdBindVertexBuffers2" "vkCmdBindIndexBuffer2") :PIPELINE NIL)
draw 6 changes ((alpha-test enable) (alpha-test compare) (alpha-test reference))
1.3: (:COST 25 :COMMANDS NIL :PIPELINE :SWITCH)
The alpha test has no Vulkan state; it becomes part of the fragment shader, so a change is a pipeline switch.
src/core/gfx.lisp)topology line-loop; blend-op add-signed, reverse-add-signed,
reverse-subtract-signed; shade-model (smooth, flat).raster shade-model, point-size; group alpha-test (enable,
compare, reference).address (and pitch) of attachment, depth-attachment,
vertex-buffer, index: guest memory.clear write-mask (gfx-clear writes #xF, gfx-clear-masked
another mask); gfx-collect-writes for matchers.src/sys/ps3/lv2/gcmsys.lisp)The HLE owns one machine, *gcm-rsx* (SYS.PS3.LV2 uses ISA.RSX).
_cellGcmInitBody(context, cmdSize, ioSize, ioAddress) resets it, maps
the IO region at IO offset 0, allocates the control registers
(cellGcmGetControlRegister; PUT = GET = #x1000, REF = #xFFFFFFFF),
the label area (256 labels of 16 bytes; reports at +#x1400, 2048 of 16
bytes), the offset table, display/tile/z-cull info, and sets the
registers the real init leaves set (DMA objects of the semaphores,
reports, surfaces; default surface format and pitches). The default
context is the IO region in 32 KiB segments, the first 4 KiB reserved:
begin = ioAddress + #x1000, end = ioAddress + #x8000 - 4, and its
callback is the OPD of the HLE function cellGcmCallback.cellGcmCallback (the context is full): PUT to current, an old-style
jump to the next segment (the first after the last) written at current,
the context moved there, the FIFO run (gcm-service). Since the RSX runs
synchronously, it has left the next segment once it caught up with PUT.cellGcmMapMainMemory (first free run of pages), MapEaIoAddress
(WithFlags), UnmapIoAddress, UnmapEaIoAddress, AddressToOffset,
IoOffsetToAddress, GetOffsetTable (the guest's u16 tables mirror the
RSX's IO -> EA pages and the HLE's EA -> IO pages), Reserve/
UnreserveIoMapSize, GetMaxIoMapSize.GetLabelAddress(i) = label-base + 16 i;
GetReportDataAddressLocation (local: label-base + #x1400 + 16 i; main:
IO offset #x0E000000 + 16 i), GetReport*, GetTimeStamp*.SetDisplayBuffer, GetDisplayInfo; SetFlip (the
flip command, then PUT to current and the FIFO run), SetPrepareFlip,
_cellGcmSetFlipCommand (no flush), ...WithWaitLabel (a semaphore
acquire first), SetWaitFlip (acquire label 1 == 0), Get/Reset/
SetFlipStatus (GetFlipStatus runs the FIFO first), SetFlipMode,
the handlers, GetLastFlipTime, GetVBlankCount.SetTile (checked, packed into the guest's tile
info as the real library packs it; the RSX does not untile yet),
BindZcull/SetZcull, GetTiledPitchSize (the table of pitches).gcm-serviceThe game moves PUT with a plain store (cellGcmFlush is inline), so the
RSX runs when someone calls (gcm-service) (exported by SYS.PS3.LV2): it
runs the FIFO from GET towards PUT (up to #x100000 commands) and returns
rsx-status; it costs a few loads when GET = PUT. The GCM functions that
need the RSX call it (SetFlip, GetFlipStatus, the callback, the
report reads). The PPU scheduler must call it whenever a thread
yields, sleeps (sys_timer_usleep, sys_ppu_thread_yield, lwmutex and
event waits) and when every thread waits: games wait for the RSX by
polling REF or a label between sleeps (GTA does: see below).
(gcm-vblank) is a vertical blank: the platform's timer should call it
60 times a second (the scheduler, until there is a timer). It counts
cellGcmGetVBlankCount and owes the vblank handler a call.
(gcm-next-handler) returns the OPD of a handler the RSX owes the PPU (0
for none), flip handlers first, with its argument in *gcm-handler-arg*
(the head, 1); the scheduler runs it as the interrupt thread would:
handler(arg) on a stack of its own, to completion, before the threads
continue.
*gcm-trace* 1 prints each call that configures the RSX.
With XSPE_CONTINUE=2 and gcm-service after every 200000 instructions:
_cellGcmInitBody(ctx, cmdSize #x100000, ioSize #x400000, ioAddress
#x30200000), cellGcmMapMainMemory(#x30700000, 1 MiB) -> IO #x400000,
cellGcmBindZcull(0, #x300000, 1280, 768), display buffers 0 and 1 at
local #x6C0000 and #xA44000 (1280 x 720, pitch 5120), another 1 MiB at IO
#x500000, cellGcmSetFlipMode(1) (hsync), then cellGcmSetFlip(ctx, 0):
the RSX runs 59 commands (a call into the second mapped region and back,
then colour mask, blend, depth test less, smooth shading, back-face
culling, DMA objects, the surface: A8R8G8B8 + Z24S8 at local #x6C0000 /
#x300000, pitch 5120) and the first flip, to buffer 0. Then GTA sets its
vblank and flip handlers, calls a dozen functions of libraries the HLE
does not have yet, and loops on sys_timer_usleep (syscall 141, the
scheduler's, not in this branch) with PUT = GET: no clear or draw is sent
before that loop ends.
Methods with semantics: 93 of 210 named NV4097 methods (815 addresses), plus NV406E, GCM flips, NV0039, NV308A; the rest are named registers.
texture
and sampler groups (texture.lisp, docs/texfmt.md);
formats are core texel formats (format.lisp). CONTROL2 is not modelled.SET_SHADER_WINDOW), window offset, the
depth range clip (CLIP_MIN/MAX), FP16/FP32 blend colour and alpha
reference, per-mode polygon offset enables, frequency dividers,
float depth clear values, GET_REPORT, immediate vertex data,
INLINE_ARRAY, ARRAY_ELEMENT16/32, NV3089 scaled blits, swizzled
NV309E destinations, NV308A clipping.SET_TRANSFORM_PROGRAM); the fragment
program is 4-word instructions in guest memory at the shader address
(halfword-swapped, with inline constants). Both are ISAs of their own,
vp.lisp (RSX-VPV, RSX-VPS) and fp.lisp (RSX-FP), with
interpreters, translated to SPIR-V by src/isel/rsxspv*.lisp
(docs/shade.md); their identities are recorded in
the state (program vertex: upload count and start slot; program
fragment: the guest address).| Test | What |
|---|---|
rsx_fifo | a hand-built command buffer in steps of PUT: state, draws and clears, a call, labels, a blocking acquire, a flip, a copy, an error |
rsx_plan | the method table, format tables against the Vulkan registry, per-method and per-draw Vulkan plans |
lower_rsx | the FIFO and methods through ctil --emit and cc, against golden output |
hle_gcm | cellGcmSys: init, the IO map, labels, the command buffer and its wrap, flips, flip status, handlers, tiles |
present_trace, present_gpu | a frame through the presenter (src/present/README.md) |
Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.