vk: format.lisp

Vulkan's formats as core texel formats, and every guest format lowered to them.

Other definitions

(defmacro vk-plan-case) source
(defmacro vk-plan-case (code use fn &optional (otherwise 0))
  "a CASE over the guest codes of USE: (funcall FN guest plan) for each that has a host plan"
  `(case ,code
     ,@(loop for g in (vk-guest-formats use)
             for p = (vk-plan g use)
             when p collect `(,(tf-code g) ,(funcall fn g p)))
     (otherwise ,otherwise)))
(defmacro vk-format-of) source
(defmacro vk-format-of (code use)
  "the VkFormat that guest format CODE becomes for USE, 0 when there is none"
  `(vk-plan-case ,code ,use ,(lambda (g p) (declare (ignore g)) (tf-code (getf p :host)))))
(defmacro vk-format-transform) source
(defmacro vk-format-transform (code use)
  "how guest bytes become host bytes: 0 copy, 1 repack, n swap every n bytes"
  `(vk-plan-case ,code ,use ,(lambda (g p) (declare (ignore g)) (vk-plan-transform p))))
(defmacro vk-format-host-bytes) source
(defmacro vk-format-host-bytes (code use)
  "the bytes of a host block of guest format CODE's plan for USE"
  `(vk-plan-case ,code ,use ,(lambda (g p) (declare (ignore g)) (texfmt-block-bytes (getf p :host)))))
(defmacro vk-texture-channel) source
(defmacro vk-texture-channel (code c)
  "the canonical component swizzle of the host view that reads channel C (0..3 = r g b a) of
   texture format CODE"
  `(vk-plan-case ,code :texture
                 ,(lambda (g p)
                    (let ((s (mapcar #'vk-swizzle-code (texfmt-swizzle g p))))
                      `(case ,c (0 ,(first s)) (1 ,(second s)) (2 ,(third s)) (otherwise ,(fourth s)))))))
(defmacro vk-repack) source
(defmacro vk-repack (code use reader writer)
  "one block of guest format CODE converted for USE into its host format (repack plans only)"
  `(vk-plan-case ,code ,use
                 ,(lambda (g p)
                    (if (eq (getf p :transform) :repack)
                        (texfmt-repack-form g p (lambda (n o) `(,reader ,n ,o))
                                            (lambda (n o v) `(,writer ,n ,o ,v)))
                        nil))
                 nil))
(defmacro vk-srgb-format) source
(defmacro vk-srgb-format (vkformat)
  "the sampled _SRGB sibling of VKFORMAT, 0 for none"
  `(case ,vkformat
     ,@(loop for f in *texfmts*
             for name = (and (tf-host f) (tf-name f))
             for s = (and name (search "_UNORM" name))
             for srgb = (and s (concatenate 'string (subseq name 0 s) "_SRGB" (subseq name (+ s 6))))
             for sf = (and srgb (texfmt-find srgb nil))
             when (and sf (member :sampled (getf (tf-props sf) :features)))
               collect `(,(tf-code f) ,(tf-code sf)))
     (otherwise 0)))
(defmacro vk-depth-format-p) source
(defmacro vk-depth-format-p (vkformat)
  "is VKFORMAT a depth (or depth/stencil) format?"
  `(case ,vkformat
     (,(mapcar (lambda (n) (vk-find-value n))
               '("VK_FORMAT_D16_UNORM" "VK_FORMAT_X8_D24_UNORM_PACK32" "VK_FORMAT_D32_SFLOAT"
                 "VK_FORMAT_D16_UNORM_S8_UINT" "VK_FORMAT_D24_UNORM_S8_UINT" "VK_FORMAT_D32_SFLOAT_S8_UINT"))
      t)
     (otherwise nil)))

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