rsx: format.lisp

the RSX's texture, vertex attribute and surface formats, as core texel formats.

Other definitions

(defmacro define-rsx-texture-formats) source
(defmacro define-rsx-texture-formats (&rest rows)
  "(code name (channels...) word...) or (code name :codec c :block b): texture format CODE"
  `(progn
     ,@(mapcar (lambda (r)
                 (destructuring-bind (code name &rest spec) r
                   (if (eq (car spec) :codec)
                       `(deftexfmt ,name (:code ,(+ #x10000 code) :usage (:texture) :codec ,(second spec)
                                          :block ,(fourth spec) :channels (r g b a)))
                       `(deftexfmt ,name (:code ,(+ #x10000 code) :channels ,(car spec)
                                          :usage ,(if (<= #x90 code #x93) '(:texture :shadow) '(:texture)))
                          ,@(cdr spec)))))
               rows)))
(defun rsx-texture-format-code) source
(defun rsx-texture-format-code (format)
  "the format code of TEXTURE_FORMAT bits 8..15 (LN and UN masked off), 0 for an unknown format"
  (declare (type u8 format))
  (let ((f (logand format #x9F)))
    (if (rsx-texture-format-known-p f) (+ #x10000 f) 0)))
(defmacro define-rsx-texture-format-known-p) source
(defmacro define-rsx-texture-format-known-p ()
  `(defun rsx-texture-format-known-p (f)
     (declare (type u8 f))
     (case f (,(loop for x in *texfmts* when (<= #x10000 (tf-code x) #x100FF) collect (- (tf-code x) #x10000)) t)
       (otherwise nil))))
(defmacro define-rsx-vertex-formats) source
(defmacro define-rsx-vertex-formats ()
  `(progn
     ,@(loop for (type kind bits) in *rsx-vertex-types*
             nconc (loop for n from 1 to 4
                         collect `(deftexfmt ,(intern (format nil "RSX-VTX-~D-~D" type n) :isa.rsx)
                                      (:code ,(+ #x11000 (* 16 type) n) :usage (:vertex)
                                       :channels ,(append (subseq '(x y z w) 0 n) (subseq '(0 0 0 1) n)))
                                    ,@(loop for c in (subseq '(x y z w) 0 n)
                                            collect `(,bits (,c ,bits ,kind))))))
     (deftexfmt rsx-vtx-cmp (:code ,(+ #x11000 (* 16 6) 1) :usage (:vertex) :channels (x y z 1))
       (32 (z 10 snorm) (y 11 snorm) (x 11 snorm)))))
(defun rsx-vertex-format-code) source
(defun rsx-vertex-format-code (type size)
  "the format code of a vertex array of TYPE with SIZE components, 0 when there is none"
  (declare (type u8 type size))
  (cond ((= size 0) 0)
        ((= type 6) (+ #x11000 (* 16 6) 1))
        ((and (<= size 4) (case type ((1 2 3 4 5 7) t) (otherwise nil))) (+ #x11000 (* 16 type) size))
        (t 0)))
(defmacro define-rsx-surface-formats) source
(defmacro define-rsx-surface-formats (&rest rows)
  `(progn
     ,@(mapcar (lambda (r)
                 (destructuring-bind (code name usage channels &rest words) r
                   `(deftexfmt ,name (:code ,code :usage ,usage :channels ,channels) ,@words)))
               rows)))
(defmacro define-rsx-surface-format-codes) source
(defmacro define-rsx-surface-format-codes ()
  (flet ((codes (lo hi)
           (loop for x in *texfmts* when (<= lo (tf-code x) hi) collect (tf-code x))))
    `(progn
       (defun rsx-color-format-code (format)
         "the format code of a CELL_GCM_SURFACE_ colour format, 0 for none"
         (declare (type u8 format))
         (case (+ #x12000 format) (,(codes #x12001 #x1201F) (+ #x12000 format)) (otherwise 0)))
       (defun rsx-depth-format-code (depth float)
         "the format code of depth format DEPTH (1 Z16, 2 Z24S8), FLOAT 1 for a float depth buffer"
         (declare (type u8 depth) (type u1 float))
         (let ((c (+ #x12100 depth (* 4 float))))
           (case c (,(codes #x12101 #x12107) c) (otherwise 0)))))))
(defmacro define-rsx-format-bytes) source
(defmacro define-rsx-format-bytes ()
  `(defun rsx-format-bytes (code)
     "the bytes of one block (a texel, a vertex element, a pixel) of format CODE, 0 for an unknown code"
     (declare (type u32 code))
     (case code
       ,@(loop for x in *texfmts* when (>= (tf-code x) #x10000)
               collect `(,(tf-code x) ,(texfmt-block-bytes x)))
       (otherwise 0))))

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