Vulkan command semantics: effects on the abstract graphics state.
(defvk vkCmdSetViewport (first count viewports)
(dotimes (i count)
(let ((v (+ first i)))
(setf (gs viewport v x) (vk-in viewports i :x)
(gs viewport v y) (vk-in viewports i :y)
(gs viewport v width) (vk-in viewports i :width)
(gs viewport v height) (vk-in viewports i :height)
(gs viewport v min-depth) (vk-in viewports i :min-depth)
(gs viewport v max-depth) (vk-in viewports i :max-depth)))))
(defvk vkCmdSetScissor (first count scissors)
(dotimes (i count)
(let ((s (+ first i)))
(setf (gs scissor s x) (vk-in scissors i :offset.x)
(gs scissor s y) (vk-in scissors i :offset.y)
(gs scissor s width) (vk-in scissors i :extent.width)
(gs scissor s height) (vk-in scissors i :extent.height)))))
(defvk vkCmdSetLineWidth (width)
(setf (gs raster line-width) width))
(defvk vkCmdSetDepthBias (constant clamp slope)
(setf (gs depth-bias constant) constant
(gs depth-bias clamp) clamp
(gs depth-bias slope) slope))
(defvk vkCmdSetBlendConstants (constants)
(setf (gs blend-constant r) (vk-in constants 0)
(gs blend-constant g) (vk-in constants 1)
(gs blend-constant b) (vk-in constants 2)
(gs blend-constant a) (vk-in constants 3)))
(defvk vkCmdSetDepthBounds (min max)
(setf (gs depth bounds-min) min
(gs depth bounds-max) max))
face masks: VK_STENCIL_FACE_FRONT_BIT 1 is element 0, BACK_BIT 2 element 1
(defvk vkCmdSetStencilCompareMask (faces mask)
(dotimes (f 2)
(when (logbitp f faces) (setf (gs stencil-face f compare-mask) mask))))
(defvk vkCmdSetStencilWriteMask (faces mask)
(dotimes (f 2)
(when (logbitp f faces) (setf (gs stencil-face f write-mask) mask))))
(defvk vkCmdSetStencilReference (faces reference)
(dotimes (f 2)
(when (logbitp f faces) (setf (gs stencil-face f reference) reference))))
(defvk vkCmdSetCullMode (mode)
(setf (gs raster cull-mode) (vk->gfx cull-mode mode)))
(defvk vkCmdSetFrontFace (face)
(setf (gs raster front-face) (vk->gfx front-face face)))
(defvk vkCmdSetPrimitiveTopology (topology)
(setf (gs primitive topology) (vk->gfx topology topology)))
(defvk vkCmdSetViewportWithCount (count viewports)
(setf (gs viewport count) count)
(dotimes (v count)
(setf (gs viewport v x) (vk-in viewports v :x)
(gs viewport v y) (vk-in viewports v :y)
(gs viewport v width) (vk-in viewports v :width)
(gs viewport v height) (vk-in viewports v :height)
(gs viewport v min-depth) (vk-in viewports v :min-depth)
(gs viewport v max-depth) (vk-in viewports v :max-depth))))
(defvk vkCmdSetScissorWithCount (count scissors)
(setf (gs scissor count) count)
(dotimes (s count)
(setf (gs scissor s x) (vk-in scissors s :offset.x)
(gs scissor s y) (vk-in scissors s :offset.y)
(gs scissor s width) (vk-in scissors s :extent.width)
(gs scissor s height) (vk-in scissors s :extent.height))))
(defvk vkCmdSetDepthTestEnable (enable)
(setf (gs depth test) (vk-bool enable)))
(defvk vkCmdSetDepthWriteEnable (enable)
(setf (gs depth write) (vk-bool enable)))
(defvk vkCmdSetDepthCompareOp (op)
(setf (gs depth compare) (vk->gfx compare-op op)))
(defvk vkCmdSetDepthBoundsTestEnable (enable)
(setf (gs depth bounds-test) (vk-bool enable)))
(defvk vkCmdSetStencilTestEnable (enable)
(setf (gs stencil test) (vk-bool enable)))
(defvk vkCmdSetStencilOp (faces fail pass depth-fail compare)
(dotimes (f 2)
(when (logbitp f faces)
(setf (gs stencil-face f fail-op) (vk->gfx stencil-op fail)
(gs stencil-face f pass-op) (vk->gfx stencil-op pass)
(gs stencil-face f depth-fail-op) (vk->gfx stencil-op depth-fail)
(gs stencil-face f compare) (vk->gfx compare-op compare)))))
(defvk vkCmdSetRasterizerDiscardEnable (enable)
(setf (gs raster discard) (vk-bool enable)))
(defvk vkCmdSetDepthBiasEnable (enable)
(setf (gs depth-bias enable) (vk-bool enable)))
(defvk vkCmdSetPrimitiveRestartEnable (enable)
(setf (gs primitive restart) (vk-bool enable)))
(defvk vkCmdSetPatchControlPointsEXT (points)
(setf (gs primitive patch-points) points))
(defvk vkCmdSetLogicOpEXT (op)
(setf (gs logic-op op) (vk->gfx logic-op op)))
(defvk vkCmdSetPolygonModeEXT (mode)
"Vulkan has one polygon mode for both faces"
(setf (gs raster polygon-mode-front) (vk->gfx polygon-mode mode)
(gs raster polygon-mode-back) (vk->gfx polygon-mode mode)))
(defvk vkCmdSetRasterizationSamplesEXT (samples)
"a VkSampleCountFlagBits is the sample count itself"
(setf (gs multisample samples) samples))
(defvk vkCmdSetSampleMaskEXT (samples mask)
"the model keeps 32 samples' mask bits"
(setf (gs multisample sample-mask) (if (= mask 0) #xFFFFFFFF (vk-in mask 0))))
(defvk vkCmdSetAlphaToCoverageEnableEXT (enable)
(setf (gs multisample alpha-to-coverage) (vk-bool enable)))
(defvk vkCmdSetAlphaToOneEnableEXT (enable)
(setf (gs multisample alpha-to-one) (vk-bool enable)))
(defvk vkCmdSetLogicOpEnableEXT (enable)
(setf (gs logic-op enable) (vk-bool enable)))
(defvk vkCmdSetColorBlendEnableEXT (first count enables)
(dotimes (i count)
(setf (gs blend (+ first i) enable) (vk-bool (vk-in enables i)))))
(defvk vkCmdSetColorBlendEquationEXT (first count equations)
(dotimes (i count)
(let ((c (+ first i)))
(setf (gs blend c src-color) (vk->gfx blend-factor (vk-in equations i :src-color-blend-factor))
(gs blend c dst-color) (vk->gfx blend-factor (vk-in equations i :dst-color-blend-factor))
(gs blend c color-op) (vk->gfx blend-op (vk-in equations i :color-blend-op))
(gs blend c src-alpha) (vk->gfx blend-factor (vk-in equations i :src-alpha-blend-factor))
(gs blend c dst-alpha) (vk->gfx blend-factor (vk-in equations i :dst-alpha-blend-factor))
(gs blend c alpha-op) (vk->gfx blend-op (vk-in equations i :alpha-blend-op))))))
(defvk vkCmdSetColorWriteMaskEXT (first count masks)
"VK_COLOR_COMPONENT_R_BIT..A_BIT are bits 0..3, as the model's mask"
(dotimes (i count)
(setf (gs blend (+ first i) write-mask) (ldb (byte 4 0) (vk-in masks i)))))
(defvk vkCmdSetColorWriteEnableEXT (count enables)
(dotimes (i count)
(setf (gs blend i write-enable) (vk-bool (vk-in enables i)))))
(defvk vkCmdSetDepthClampEnableEXT (enable)
(setf (gs raster depth-clamp) (vk-bool enable)))
(defvk vkCmdSetDepthClipEnableEXT (enable)
(setf (gs raster depth-clip) (vk-bool enable)))
(defvk vkCmdSetProvokingVertexModeEXT (mode)
(setf (gs raster provoking-vertex) (vk->gfx provoking-vertex mode)))
(defvk vkCmdSetLineStippleEnableEXT (enable)
(setf (gs raster line-stipple) (vk-bool enable)))
(defvk vkCmdSetLineStipple (factor pattern)
(setf (gs raster line-stipple-factor) factor
(gs raster line-stipple-pattern) pattern))
(defvk vkCmdSetPrimitiveRestartIndexEXT (index)
(setf (gs primitive restart-index) index))
(defvk vkCmdSetVertexInputEXT (binding-count bindings attribute-count attributes)
"replaces the whole vertex input: unlisted attributes are disabled"
(let ((n 0))
(dotimes (i binding-count)
(let ((b (vk-in bindings i :binding)))
(setf (gs vertex-binding b stride) (vk-in bindings i :stride)
(gs vertex-binding b input-rate) (vk->gfx input-rate (vk-in bindings i :input-rate))
(gs vertex-binding b divisor) (vk-in bindings i :divisor))
(setq n (max n (+ b 1)))))
(setf (gs vertex-binding count) n))
(dotimes (l 16)
(setf (gs vertex-attribute l enable) 0))
(dotimes (i attribute-count)
(let ((l (vk-in attributes i :location)))
(setf (gs vertex-attribute l enable) 1
(gs vertex-attribute l binding) (vk-in attributes i :binding)
(gs vertex-attribute l format) (vk-in attributes i :format)
(gs vertex-attribute l offset) (vk-in attributes i :offset)))))
(defvk vkCmdBindVertexBuffers (first count buffers offsets)
(dotimes (i count)
(let ((b (+ first i)))
(setf (gs vertex-buffer b buffer) (vk-in buffers i)
(gs vertex-buffer b offset) (vk-in offsets i)
(gs vertex-buffer b size) (vk-value VK_WHOLE_SIZE)))))
(defvk vkCmdBindVertexBuffers2 (first count buffers offsets sizes strides)
"with STRIDES, also the binding strides (VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE)"
(dotimes (i count)
(let ((b (+ first i)))
(setf (gs vertex-buffer b buffer) (vk-in buffers i)
(gs vertex-buffer b offset) (vk-in offsets i)
(gs vertex-buffer b size) (if (= sizes 0) (vk-value VK_WHOLE_SIZE) (vk-in sizes i)))
(unless (= strides 0)
(setf (gs vertex-binding b stride) (ldb (byte 32 0) (vk-in strides i)))))))
(defvk vkCmdBindIndexBuffer (buffer offset type)
(setf (gs index buffer) buffer
(gs index offset) offset
(gs index size) (vk-value VK_WHOLE_SIZE)
(gs index type) (vk->gfx index-type type)))
(defvk vkCmdBindIndexBuffer2 (buffer offset size type)
(setf (gs index buffer) buffer
(gs index offset) offset
(gs index size) size
(gs index type) (vk->gfx index-type type)))
(defvk vkCmdBindDescriptorSets (bind-point layout first count sets dynamic-count dynamic-offsets)
"graphics bind point only; dynamic offsets are not modelled yet"
(when (= bind-point (vk-value VK_PIPELINE_BIND_POINT_GRAPHICS))
(dotimes (i count)
(setf (gs descriptor-set (+ first i) handle) (vk-in sets i)))))
(defvk vkCmdBeginRendering (info)
"the pass, its views, and the clears its load operations do"
(let ((x (vk-in info :render-area.offset.x)) (y (vk-in info :render-area.offset.y))
(w (vk-in info :render-area.extent.width)) (h (vk-in info :render-area.extent.height))
(colors (vk-in info :p-color-attachments))
(depth (vk-in info :p-depth-attachment))
(stencil (vk-in info :p-stencil-attachment)))
(setf (gs pass active) 1 (gs pass x) x (gs pass y) y (gs pass width) w (gs pass height) h
(gs pass layers) (vk-in info :layer-count))
(dotimes (i 8)
(setf (gs attachment i view) 0))
(dotimes (i (vk-in info :color-attachment-count))
(let ((c (vk-elt VkRenderingAttachmentInfo colors i)))
(setf (gs attachment i view) (vk-read vk-mem VkRenderingAttachmentInfo c :image-view))
(when (= (vk-read vk-mem VkRenderingAttachmentInfo c :load-op) (vk-value VK_ATTACHMENT_LOAD_OP_CLEAR))
(gfx-clear gfx 1 i
(vk-read vk-mem VkRenderingAttachmentInfo c :clear-value.color.float32.0)
(vk-read vk-mem VkRenderingAttachmentInfo c :clear-value.color.float32.1)
(vk-read vk-mem VkRenderingAttachmentInfo c :clear-value.color.float32.2)
(vk-read vk-mem VkRenderingAttachmentInfo c :clear-value.color.float32.3)
0.0 0 x y w h))))
(setf (gs depth-attachment view)
(if (= depth 0) 0 (vk-read vk-mem VkRenderingAttachmentInfo depth :image-view)))
(setf (gs depth-attachment stencil-view)
(if (= stencil 0) 0 (vk-read vk-mem VkRenderingAttachmentInfo stencil :image-view)))
(let ((aspects (logior (if (and (/= depth 0)
(= (vk-read vk-mem VkRenderingAttachmentInfo depth :load-op)
(vk-value VK_ATTACHMENT_LOAD_OP_CLEAR)))
2 0)
(if (and (/= stencil 0)
(= (vk-read vk-mem VkRenderingAttachmentInfo stencil :load-op)
(vk-value VK_ATTACHMENT_LOAD_OP_CLEAR)))
4 0))))
(unless (= aspects 0)
(gfx-clear gfx aspects 0 0.0 0.0 0.0 0.0
(if (= depth 0) 0.0
(vk-read vk-mem VkRenderingAttachmentInfo depth :clear-value.depth-stencil.depth))
(if (= stencil 0) 0
(vk-read vk-mem VkRenderingAttachmentInfo stencil :clear-value.depth-stencil.stencil))
x y w h)))))
(defvk vkCmdEndRendering ()
(setf (gs pass active) 0))
(defvk vkCmdBeginRenderPass (info contents)
"the pass and its area; attachments and clears live in the VkRenderPass and
VkFramebuffer objects, which the model does not track yet"
(setf (gs pass active) 1
(gs pass x) (vk-in info :render-area.offset.x)
(gs pass y) (vk-in info :render-area.offset.y)
(gs pass width) (vk-in info :render-area.extent.width)
(gs pass height) (vk-in info :render-area.extent.height)))
(defvk vkCmdEndRenderPass ()
(setf (gs pass active) 0))
(defvk vkCmdDraw (vertex-count instance-count first-vertex first-instance)
(gfx-draw gfx (gfx-code draw-kind direct) vertex-count instance-count first-vertex 0 first-instance))
(defvk vkCmdDrawIndexed (index-count instance-count first-index vertex-offset first-instance)
(gfx-draw gfx (gfx-code draw-kind indexed) index-count instance-count first-index vertex-offset
first-instance))
(defvk vkCmdDrawIndirect (buffer offset count stride)
(gfx-draw-indirect gfx (gfx-code draw-kind indirect) buffer offset count stride))
(defvk vkCmdDrawIndexedIndirect (buffer offset count stride)
(gfx-draw-indirect gfx (gfx-code draw-kind indexed-indirect) buffer offset count stride))
(defvk vkCmdClearAttachments (count attachments rect-count rects)
"one clear event per attachment and rectangle"
(dotimes (r rect-count)
(let ((x (vk-in rects r :rect.offset.x)) (y (vk-in rects r :rect.offset.y))
(w (vk-in rects r :rect.extent.width)) (h (vk-in rects r :rect.extent.height)))
(dotimes (i count)
(let ((aspects (vk-in attachments i :aspect-mask)))
;; VK_IMAGE_ASPECT_COLOR_BIT 1, DEPTH_BIT 2, STENCIL_BIT 4: the model's aspects
(gfx-clear gfx (ldb (byte 3 0) aspects) (vk-in attachments i :color-attachment)
(vk-in attachments i :clear-value.color.float32.0)
(vk-in attachments i :clear-value.color.float32.1)
(vk-in attachments i :clear-value.color.float32.2)
(vk-in attachments i :clear-value.color.float32.3)
(vk-in attachments i :clear-value.depth-stencil.depth)
(vk-in attachments i :clear-value.depth-stencil.stencil)
x y w h))))))
(defvk vkCreateShaderModule (device info allocator module)
"in the model a module is its size in bytes, tagged: the presenter's two differ"
(:cost :create)
(vk-out module 0 (logior #x5E00000000 (vk-in info :code-size)))
(vk-value VK_SUCCESS))
Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.