rsx: nv4097.lisp

NV4097 (NV40 Curie, the RSX's 3D class): methods as effects on the abstract state.

NV4097_SET_DEPTH_TEST_ENABLE source

Method0x0A74
(defmethod-rsx NV4097_SET_DEPTH_TEST_ENABLE #x0A74 (value)
  (setf (gs depth test) (b2i (/= value 0))))

NV4097_SET_DEPTH_MASK source

Method0x0A70
(defmethod-rsx NV4097_SET_DEPTH_MASK #x0A70 (value)
  (setf (gs depth write) (b2i (/= value 0))))

NV4097_SET_DEPTH_FUNC source

Method0x0A6C
(defmethod-rsx NV4097_SET_DEPTH_FUNC #x0A6C (value)
  (setf (gs depth compare) (rsx->gfx compare-op value)))

NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE source

Method0x0380
(defmethod-rsx NV4097_SET_DEPTH_BOUNDS_TEST_ENABLE #x0380 (value)
  (setf (gs depth bounds-test) (b2i (/= value 0))))

NV4097_SET_DEPTH_BOUNDS_MIN source

Method0x0384
(defmethod-rsx NV4097_SET_DEPTH_BOUNDS_MIN #x0384 (value)
  (setf (gs depth bounds-min) (bits-f32 value)))

NV4097_SET_DEPTH_BOUNDS_MAX source

Method0x0388
(defmethod-rsx NV4097_SET_DEPTH_BOUNDS_MAX #x0388 (value)
  (setf (gs depth bounds-max) (bits-f32 value)))

NV4097_SET_POLY_OFFSET_FILL_ENABLE source

Method0x0A68
(defmethod-rsx NV4097_SET_POLY_OFFSET_FILL_ENABLE #x0A68 (value)
  (setf (gs depth-bias enable) (b2i (/= value 0))))

NV4097_SET_POLYGON_OFFSET_SCALE_FACTOR source

Method0x0A78
(defmethod-rsx NV4097_SET_POLYGON_OFFSET_SCALE_FACTOR #x0A78 (value)
  (setf (gs depth-bias slope) (bits-f32 value)))

NV4097_SET_POLYGON_OFFSET_BIAS source

Method0x0A7C
(defmethod-rsx NV4097_SET_POLYGON_OFFSET_BIAS #x0A7C (value)
  "TODO: GL's bias unit; Vulkan's depends on the depth format"
  (setf (gs depth-bias constant) (bits-f32 value)))

NV4097_SET_STENCIL_TEST_ENABLE source

Method0x0328
(defmethod-rsx NV4097_SET_STENCIL_TEST_ENABLE #x0328 (value)
  (setf (gs stencil test) (b2i (/= value 0))))

NV4097_SET_TWO_SIDED_STENCIL_TEST_ENABLE source

Method0x0348
(defmethod-rsx NV4097_SET_TWO_SIDED_STENCIL_TEST_ENABLE #x0348 (value)
  "the back face from its own registers, or from the front face's"
  (let ((two (/= value 0)))
    (setf (gs stencil-face 1 write-mask)
          (ldb (byte 8 0) (if two (reg NV4097_SET_BACK_STENCIL_MASK) (reg NV4097_SET_STENCIL_MASK)))
          (gs stencil-face 1 compare)
          (rsx->gfx compare-op (if two (reg NV4097_SET_BACK_STENCIL_FUNC) (reg NV4097_SET_STENCIL_FUNC)))
          (gs stencil-face 1 reference)
          (ldb (byte 8 0) (if two (reg NV4097_SET_BACK_STENCIL_FUNC_REF) (reg NV4097_SET_STENCIL_FUNC_REF)))
          (gs stencil-face 1 compare-mask)
          (ldb (byte 8 0) (if two (reg NV4097_SET_BACK_STENCIL_FUNC_MASK) (reg NV4097_SET_STENCIL_FUNC_MASK)))
          (gs stencil-face 1 fail-op)
          (rsx->gfx stencil-op (if two (reg NV4097_SET_BACK_STENCIL_OP_FAIL) (reg NV4097_SET_STENCIL_OP_FAIL)))
          (gs stencil-face 1 depth-fail-op)
          (rsx->gfx stencil-op (if two (reg NV4097_SET_BACK_STENCIL_OP_ZFAIL) (reg NV4097_SET_STENCIL_OP_ZFAIL)))
          (gs stencil-face 1 pass-op)
          (rsx->gfx stencil-op (if two (reg NV4097_SET_BACK_STENCIL_OP_ZPASS) (reg NV4097_SET_STENCIL_OP_ZPASS))))))

NV4097_SET_ALPHA_TEST_ENABLE source

Method0x0304
(defmethod-rsx NV4097_SET_ALPHA_TEST_ENABLE #x0304 (value)
  (setf (gs alpha-test enable) (b2i (/= value 0))))

NV4097_SET_ALPHA_FUNC source

Method0x0308
(defmethod-rsx NV4097_SET_ALPHA_FUNC #x0308 (value)
  (setf (gs alpha-test compare) (rsx->gfx compare-op value)))

NV4097_SET_ALPHA_REF source

Method0x030C
(defmethod-rsx NV4097_SET_ALPHA_REF #x030C (value)
  "TODO: FP16 surfaces take a half float, FP32 ones a float"
  (setf (gs alpha-test reference) (rsx-unorm8 value 0)))

NV4097_SET_BLEND_ENABLE source

Method0x0310
(defmethod-rsx NV4097_SET_BLEND_ENABLE #x0310 (value)
  (setf (gs blend 0 enable) (b2i (/= value 0))))

NV4097_SET_BLEND_ENABLE_MRT source

Method0x036C
(defmethod-rsx NV4097_SET_BLEND_ENABLE_MRT #x036C (value)
  "bits 1..3: surfaces B C D"
  (dotimes (i 3)
    (setf (gs blend (+ i 1) enable) (rsx-bit value (+ i 1)))))

NV4097_SET_BLEND_FUNC_SFACTOR source

one equation and one set of factors for every surface: RGB in bits 0..15, alpha in 16..31
Method0x0314
(defmethod-rsx NV4097_SET_BLEND_FUNC_SFACTOR #x0314 (value)
  (dotimes (i 4)
    (setf (gs blend i src-color) (rsx->gfx blend-factor (ldb (byte 16 0) value))
          (gs blend i src-alpha) (rsx->gfx blend-factor (ldb (byte 16 16) value)))))

NV4097_SET_BLEND_FUNC_DFACTOR source

Method0x0318
(defmethod-rsx NV4097_SET_BLEND_FUNC_DFACTOR #x0318 (value)
  (dotimes (i 4)
    (setf (gs blend i dst-color) (rsx->gfx blend-factor (ldb (byte 16 0) value))
          (gs blend i dst-alpha) (rsx->gfx blend-factor (ldb (byte 16 16) value)))))

NV4097_SET_BLEND_EQUATION source

Method0x0320
(defmethod-rsx NV4097_SET_BLEND_EQUATION #x0320 (value)
  (dotimes (i 4)
    (setf (gs blend i color-op) (rsx->gfx blend-op (ldb (byte 16 0) value))
          (gs blend i alpha-op) (rsx->gfx blend-op (ldb (byte 16 16) value)))))

NV4097_SET_BLEND_COLOR source

Method0x031C
(defmethod-rsx NV4097_SET_BLEND_COLOR #x031C (value)
  "A8R8G8B8 for 8-bit surfaces (TODO: R16G16 halves, with BLEND_COLOR2, for FP16 surfaces)"
  (setf (gs blend-constant r) (rsx-unorm8 value 16) (gs blend-constant g) (rsx-unorm8 value 8)
        (gs blend-constant b) (rsx-unorm8 value 0) (gs blend-constant a) (rsx-unorm8 value 24)))

NV4097_SET_COLOR_MASK source

Method0x0324
(defmethod-rsx NV4097_SET_COLOR_MASK #x0324 (value)
  "surface A: one byte per channel, B G R A from bit 0; the mask's bits are R G B A"
  (setf (gs blend 0 write-mask)
        (logior (b2i (/= (ldb (byte 8 16) value) 0)) (ash (b2i (/= (ldb (byte 8 8) value) 0)) 1)
                (ash (b2i (/= (ldb (byte 8 0) value) 0)) 2) (ash (b2i (/= (ldb (byte 8 24) value) 0)) 3))))

NV4097_SET_COLOR_MASK_MRT source

Method0x0370
(defmethod-rsx NV4097_SET_COLOR_MASK_MRT #x0370 (value)
  "surfaces B C D: a nibble each from bit 4, A R G B from its bit 0"
  (dotimes (i 3)
    (let ((n (ldb (byte 4 (* 4 (+ i 1))) value)))
      (setf (gs blend (+ i 1) write-mask)
            (logior (rsx-bit n 1) (ash (rsx-bit n 2) 1) (ash (rsx-bit n 3) 2) (ash (rsx-bit n 0) 3))))))

NV4097_SET_LOGIC_OP_ENABLE source

Method0x0374
(defmethod-rsx NV4097_SET_LOGIC_OP_ENABLE #x0374 (value)
  (setf (gs logic-op enable) (b2i (/= value 0))))

NV4097_SET_LOGIC_OP source

Method0x0378
(defmethod-rsx NV4097_SET_LOGIC_OP #x0378 (value)
  (setf (gs logic-op op) (rsx->gfx logic-op value)))

NV4097_SET_ANTI_ALIASING_CONTROL source

Method0x1D7C
(defmethod-rsx NV4097_SET_ANTI_ALIASING_CONTROL #x1D7C (value)
  "bit 0 multisampling (the surface format gives the count), 4 alpha to coverage, 8 alpha to one,
   16..31 the sample mask"
  (setf (gs multisample alpha-to-coverage) (rsx-bit value 4)
        (gs multisample alpha-to-one) (rsx-bit value 8)
        (gs multisample sample-mask) (ldb (byte 16 16) value)))

NV4097_SET_FRONT_FACE source

Method0x1834
(defmethod-rsx NV4097_SET_FRONT_FACE #x1834 (value)
  "TODO: winding as the guest's window origin sees it; a y-flipping viewport inverts it"
  (setf (gs raster front-face) (rsx->gfx front-face value)))

NV4097_SET_FRONT_POLYGON_MODE source

Method0x1828
(defmethod-rsx NV4097_SET_FRONT_POLYGON_MODE #x1828 (value)
  (setf (gs raster polygon-mode-front) (rsx->gfx polygon-mode value)))

NV4097_SET_BACK_POLYGON_MODE source

Method0x182C
(defmethod-rsx NV4097_SET_BACK_POLYGON_MODE #x182C (value)
  (setf (gs raster polygon-mode-back) (rsx->gfx polygon-mode value)))

NV4097_SET_LINE_WIDTH source

Method0x03B8
(defmethod-rsx NV4097_SET_LINE_WIDTH #x03B8 (value)
  "unsigned fixed point, 3 fraction bits"
  (setf (gs raster line-width) (/ (float (ldb (byte 29 0) value) 1.0) 8.0)))

NV4097_SET_LINE_STIPPLE source

Method0x1DB4
(defmethod-rsx NV4097_SET_LINE_STIPPLE #x1DB4 (value)
  (setf (gs raster line-stipple) (rsx-bit value 0)))

NV4097_SET_LINE_STIPPLE_PATTERN source

Method0x1DB8
(defmethod-rsx NV4097_SET_LINE_STIPPLE_PATTERN #x1DB8 (value)
  "factor in bits 0..15, pattern in 16..31"
  (setf (gs raster line-stipple-factor) (ldb (byte 16 0) value)
        (gs raster line-stipple-pattern) (ldb (byte 16 16) value)))

NV4097_SET_SHADE_MODE source

Method0x0368
(defmethod-rsx NV4097_SET_SHADE_MODE #x0368 (value)
  (setf (gs raster shade-model) (rsx->gfx shade-model value)))

NV4097_SET_POINT_SIZE source

Method0x1EE0
(defmethod-rsx NV4097_SET_POINT_SIZE #x1EE0 (value)
  (setf (gs raster point-size) (bits-f32 value)))

NV4097_SET_ZMIN_MAX_CONTROL source

Method0x1D78
(defmethod-rsx NV4097_SET_ZMIN_MAX_CONTROL #x1D78 (value)
  "bits 0..3 depth clip, 4..7 depth clamp (TODO: 8..11 clip ignoring w)"
  (setf (gs raster depth-clip) (b2i (/= (ldb (byte 4 0) value) 0))
        (gs raster depth-clamp) (b2i (/= (ldb (byte 4 4) value) 0))))

NV4097_SET_RESTART_INDEX_ENABLE source

Method0x1DAC
(defmethod-rsx NV4097_SET_RESTART_INDEX_ENABLE #x1DAC (value)
  (setf (gs primitive restart) (b2i (/= value 0))))

NV4097_SET_RESTART_INDEX source

Method0x1DB0
(defmethod-rsx NV4097_SET_RESTART_INDEX #x1DB0 (value)
  (setf (gs primitive restart-index) value))

NV4097_SET_VERTEX_DATA_ARRAY_FORMAT source

Method(5952 16 4)
(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 binding) i
          (gs vertex-attribute i format) (rsx-vertex-format-code type size)
          (gs vertex-attribute i offset) 0
          (gs vertex-binding i stride) (ldb (byte 8 8) value)
          (gs vertex-buffer i frequency) (ldb (byte 16 16) value)
          (gs vertex-binding i input-rate) (gfx-code input-rate vertex))
    (let ((n 0))
      (dotimes (a 16)
        (unless (= (ldb (byte 4 4) (reg NV4097_SET_VERTEX_DATA_ARRAY_FORMAT a)) 0)
          (setq n (+ a 1))))
      (setf (gs vertex-binding count) n))))

NV4097_SET_FREQUENCY_DIVIDER_OPERATION source

Method0x1FC0
(defmethod-rsx NV4097_SET_FREQUENCY_DIVIDER_OPERATION #x1FC0 (value)
  "bit i: array i reads element (vertex mod frequency), else (vertex / frequency)"
  (dotimes (i 16)
    (setf (gs vertex-buffer i modulo) (ldb (byte 1 i) value))))

NV4097_SET_VERTEX_DATA_ARRAY_OFFSET source

Method(5760 16 4)
(defmethod-rsx NV4097_SET_VERTEX_DATA_ARRAY_OFFSET (#x1680 16 4) (value i)
  (rsx-derive-array-address rsx i))

NV4097_SET_VERTEX_DATA_BASE_OFFSET source

Method0x1738
(defmethod-rsx NV4097_SET_VERTEX_DATA_BASE_OFFSET #x1738 (value)
  (dotimes (i 16)
    (rsx-derive-array-address rsx i)))

NV4097_SET_BEGIN_END source

Method0x1808
(defmethod-rsx NV4097_SET_BEGIN_END #x1808 (value)
  "a primitive (CELL_GCM_PRIMITIVE_) begins a batch; 0 ends it and draws"
  (if (= value 0)
      (rsx-flush-draw rsx)
      (setf (gs primitive topology) (rsx->gfx topology value))))

NV4097_DRAW_ARRAYS source

Method0x1814
(defmethod-rsx NV4097_DRAW_ARRAYS #x1814 (value)
  (rsx-add-range rsx (gfx-code draw-kind direct) value))

NV4097_DRAW_INDEX_ARRAY source

Method0x1824
(defmethod-rsx NV4097_DRAW_INDEX_ARRAY #x1824 (value)
  (rsx-add-range rsx (gfx-code draw-kind indexed) value))

NV4097_CLEAR_SURFACE source

Method0x1D94
(defmethod-rsx NV4097_CLEAR_SURFACE #x1D94 (value)
  "bit 0 depth, 1 stencil, 4..7 R G B A of every active colour surface; within the scissor (and
   the clear rectangle when one is set), to the clear values (colour A8R8G8B8, depth Z24 or Z16
   below stencil S8)"
  ;; the area: the scissor rectangle, as RPCS3's VKGSRender::clear does
  ;; (rpcs3/Emu/RSX/VK/VKGSRender.cpp, [RPCS3] in docs/refs.md); within the clear rectangle
  ;; when one is set (unverified: RPCS3 ignores the clear rectangle)
  (let* ((h (reg NV4097_SET_CLEAR_RECT_HORIZONTAL)) (v (reg NV4097_SET_CLEAR_RECT_VERTICAL))
         (sx (max 0 (gs scissor 0 x))) (sy (max 0 (gs scissor 0 y)))
         (x (if (= (ldb (byte 16 16) h) 0) sx (max sx (ldb (byte 16 0) h))))
         (y (if (= (ldb (byte 16 16) v) 0) sy (max sy (ldb (byte 16 0) v))))
         (x2 (if (= (ldb (byte 16 16) h) 0) (+ sx (gs scissor 0 width))
                 (min (+ sx (gs scissor 0 width)) (+ (ldb (byte 16 0) h) (ldb (byte 16 16) h)))))
         (y2 (if (= (ldb (byte 16 16) v) 0) (+ sy (gs scissor 0 height))
                 (min (+ sy (gs scissor 0 height)) (+ (ldb (byte 16 0) v) (ldb (byte 16 16) v)))))
         (w (max 0 (- x2 x))) (ht (max 0 (- y2 y)))
         (c (reg NV4097_SET_COLOR_CLEAR_VALUE)) (zs (reg NV4097_SET_ZSTENCIL_CLEAR_VALUE))
         (mask (ldb (byte 4 4) value))
         (targets (rsx-surface-targets (reg NV4097_SET_SURFACE_COLOR_TARGET)))
         (z24 (= (ldb (byte 3 5) (reg NV4097_SET_SURFACE_FORMAT)) 2))
         (depth (if z24
                    (/ (float (ldb (byte 24 8) zs) 1.0) 16777215.0)
                    (/ (float (ldb (byte 16 0) zs) 1.0) 65535.0)))
         (stencil (if z24 (ldb (byte 8 0) zs) 0)))
    (unless (= mask 0)
      (dotimes (i 4)
        (when (logbitp i targets)
          (gfx-clear-masked gfx 1 i mask (rsx-unorm8 c 16) (rsx-unorm8 c 8) (rsx-unorm8 c 0) (rsx-unorm8 c 24)
                            0.0 0 x y w ht)
          (rsx-event rsx +rsx-event-clear+))))
    (let ((aspects (logior (ash (rsx-bit value 0) 1) (ash (rsx-bit value 1) 2))))
      (unless (= aspects 0)
        (gfx-clear gfx aspects 0 0.0 0.0 0.0 0.0 depth stencil x y w ht)
        (rsx-event rsx +rsx-event-clear+)))))

NV4097_SET_SHADER_PROGRAM source

Method0x08E4
(defmethod-rsx NV4097_SET_SHADER_PROGRAM #x08E4 (value)
  "location + 1 in bits 0..1, the offset of the fragment program above"
  (setf (gs program fragment)
        (if (= (ldb (byte 2 0) value) 0) 0
            (rsx-address rsx (- (ldb (byte 2 0) value) 1) (logand value #xFFFFFFFC)))))

NV4097_SET_TRANSFORM_PROGRAM_START source

Method0x1EA0
(defmethod-rsx NV4097_SET_TRANSFORM_PROGRAM_START #x1EA0 (value)
  (rsx-derive-vertex-program rsx))

NV4097_SET_TRANSFORM_PROGRAM source

Method(2944 32 4)
(defmethod-rsx NV4097_SET_TRANSFORM_PROGRAM (#x0B80 32 4) (value i)
  "word I mod 4 of the instruction at the load slot; the slot advances after word 3"
  (let ((load (reg NV4097_SET_TRANSFORM_PROGRAM_LOAD)))
    (when (< load (floor (rsx-program-words) 4))
      (setf (aref (rsx-program rsx) (+ (* load 4) (logand i 3))) value)
      (when (= (logand i 3) 3)
        (setf (reg NV4097_SET_TRANSFORM_PROGRAM_LOAD) (+ load 1)))
      (setf (rsx-program-uploads rsx) (wrap 32 (+ (rsx-program-uploads rsx) 1)))
      (rsx-derive-vertex-program rsx))))

NV4097_SET_TRANSFORM_CONSTANT source

Method(7936 32 4)
(defmethod-rsx NV4097_SET_TRANSFORM_CONSTANT (#x1F00 32 4) (value i)
  "word I from the constant at the load index (the index does not advance)"
  (let ((word (+ (* (reg NV4097_SET_TRANSFORM_CONSTANT_LOAD) 4) i)))
    (when (< word (rsx-constant-words))
      (setf (aref (rsx-constants rsx) word) value))))

NV4097_TEXTURE_READ_SEMAPHORE_RELEASE source

Method0x1D74
(defmethod-rsx NV4097_TEXTURE_READ_SEMAPHORE_RELEASE #x1D74 (value)
  "once the textures read so far are fetched: the value at the semaphore"
  (mem-write 32 (rsx-semaphore-4097 rsx) value))

NV4097_BACK_END_WRITE_SEMAPHORE_RELEASE source

Method0x1D70
(defmethod-rsx NV4097_BACK_END_WRITE_SEMAPHORE_RELEASE #x1D70 (value)
  "once everything before is written: the value, bytes 0 and 2 swapped, at the semaphore"
  (mem-write 32 (rsx-semaphore-4097 rsx)
             (logior (logand value #xFF00FF00) (ash (ldb (byte 8 0) value) 16) (ldb (byte 8 16) value))))

Other definitions

(defun rsx-surface-reg) source
(defun rsx-surface-reg (rsx what i)
  "register WHAT (0 pitch, 1 offset, 2 DMA object) of colour surface I"
  (declare (type rsx rsx) (type u8 what i))
  (case what
    (0 (case i (0 (reg NV4097_SET_SURFACE_PITCH_A)) (1 (reg NV4097_SET_SURFACE_PITCH_B))
         (2 (reg NV4097_SET_SURFACE_PITCH_C)) (otherwise (reg NV4097_SET_SURFACE_PITCH_D))))
    (1 (case i (0 (reg NV4097_SET_SURFACE_COLOR_AOFFSET)) (1 (reg NV4097_SET_SURFACE_COLOR_BOFFSET))
         (2 (reg NV4097_SET_SURFACE_COLOR_COFFSET)) (otherwise (reg NV4097_SET_SURFACE_COLOR_DOFFSET))))
    (otherwise
     (case i (0 (reg NV4097_SET_CONTEXT_DMA_COLOR_A)) (1 (reg NV4097_SET_CONTEXT_DMA_COLOR_B))
       (2 (reg NV4097_SET_CONTEXT_DMA_COLOR_C)) (otherwise (reg NV4097_SET_CONTEXT_DMA_COLOR_D))))))
(defun rsx-surface-targets) source
(defun rsx-surface-targets (target)
  "the colour surfaces a CELL_GCM_SURFACE_TARGET_ value enables, as a mask (bit i surface i)"
  (declare (type u32 target))
  (case target (1 1) (2 2) (#x13 3) (#x17 7) (#x1F #xF) (otherwise 0)))
(defun rsx-span-start) source
(defun rsx-span-start (a b)
  "the start of the intersection of two spans packed as start:16 length:16"
  (declare (type u32 a b))
  (max (ldb (byte 16 0) a) (ldb (byte 16 0) b)))
(defun rsx-span-length) source
(defun rsx-span-length (a b)
  "the length of the intersection of two spans packed as start:16 length:16"
  (declare (type u32 a b))
  (let ((end (min (+ (ldb (byte 16 0) a) (ldb (byte 16 16) a)) (+ (ldb (byte 16 0) b) (ldb (byte 16 16) b))))
        (start (rsx-span-start a b)))
    (if (> end start) (- end start) 0)))
(defun rsx-two-sided) source
(defun rsx-two-sided (rsx)
  (declare (type rsx rsx))
  (/= (reg NV4097_SET_TWO_SIDED_STENCIL_TEST_ENABLE) 0))
(defmacro define-stencil-methods) source
(defmacro define-stencil-methods ((front front-address) (back back-address) field form)
  `(progn
     (defmethod-rsx ,front ,front-address (value)
       (setf (gs stencil-face 0 ,field) ,form)
       (unless (rsx-two-sided rsx)
         (setf (gs stencil-face 1 ,field) ,form)))
     (defmethod-rsx ,back ,back-address (value)
       (when (rsx-two-sided rsx)
         (setf (gs stencil-face 1 ,field) ,form)))))
(defun rsx-vertex-component-bytes) source
(defun rsx-vertex-component-bytes (rsx i)
  "the size of one component of array I (big-endian in memory), 0 when the array is off;
   a CMP array (one packed 32-bit word) counts as one component of 4 bytes"
  (declare (type rsx rsx) (type u8 i))
  (let ((format (reg NV4097_SET_VERTEX_DATA_ARRAY_FORMAT i)))
    (if (= (ldb (byte 4 4) format) 0)
        0
        (case (ldb (byte 4 0) format) ((1 3 5) 2) ((2 6) 4) ((4 7) 1) (otherwise 0)))))
(defun rsx-vertex-element-bytes) source
(defun rsx-vertex-element-bytes (rsx i)
  "the size of one element (vertex) of array I"
  (declare (type rsx rsx) (type u8 i))
  (let ((format (reg NV4097_SET_VERTEX_DATA_ARRAY_FORMAT i)))
    (if (= (ldb (byte 4 0) format) 6)
        4
        (* (rsx-vertex-component-bytes rsx i) (ldb (byte 4 4) format)))))
(defun rsx-flush-draw) source
(defun rsx-flush-draw (rsx)
  "the collected range, if any, as a draw"
  (declare (type rsx rsx))
  (when (= (rsx-draw-open rsx) 1)
    (let ((gfx (rsx-gfx rsx)))
      (gfx-draw gfx (rsx-draw-kind rsx) (rsx-draw-count rsx) 1 (rsx-draw-first rsx)
                (if (= (rsx-draw-kind rsx) (gfx-code draw-kind indexed))
                    (ldb (byte 20 0) (reg NV4097_SET_VERTEX_DATA_BASE_INDEX))
                    0)
                0))
    (setf (rsx-draw-open rsx) 0)
    (rsx-event rsx +rsx-event-draw+))
  nil)
(defun rsx-add-range) source
(defun rsx-add-range (rsx kind value)
  (declare (type rsx rsx) (type u8 kind) (type u32 value))
  (let ((first (ldb (byte 24 0) value)) (count (+ (ldb (byte 8 24) value) 1)))
    (if (and (= (rsx-draw-open rsx) 1) (= (rsx-draw-kind rsx) kind)
             (= (+ (rsx-draw-first rsx) (rsx-draw-count rsx)) first))
        (setf (rsx-draw-count rsx) (wrap 32 (+ (rsx-draw-count rsx) count)))
        (progn
          (rsx-flush-draw rsx)
          (setf (rsx-draw-open rsx) 1 (rsx-draw-kind rsx) kind
                (rsx-draw-first rsx) first (rsx-draw-count rsx) count))))
  nil)
(defun rsx-semaphore-4097) source
(defun rsx-semaphore-4097 (rsx)
  (declare (type rsx rsx))
  (rsx-address rsx (reg NV4097_SET_CONTEXT_DMA_SEMAPHORE) (reg NV4097_SET_SEMAPHORE_OFFSET)))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.