Mesa (main): vulkan: Add an enum for all dynamic graphics states

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 19 19:54:11 UTC 2022


Module: Mesa
Branch: main
Commit: fb3f9c0aac601959fd8636120a6191b2ccd3dd40
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fb3f9c0aac601959fd8636120a6191b2ccd3dd40

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Mon Jun 27 09:03:02 2022 -0500

vulkan: Add an enum for all dynamic graphics states

Also, add a helper function to turn VkPipelineDynamicStateCreateInfo
into a bitset.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17328>

---

 src/vulkan/runtime/meson.build         |  2 +
 src/vulkan/runtime/vk_graphics_state.c | 67 ++++++++++++++++++++++++
 src/vulkan/runtime/vk_graphics_state.h | 96 ++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)

diff --git a/src/vulkan/runtime/meson.build b/src/vulkan/runtime/meson.build
index 1f5a9633190..cd4d9ed4fd1 100644
--- a/src/vulkan/runtime/meson.build
+++ b/src/vulkan/runtime/meson.build
@@ -48,6 +48,8 @@ vulkan_runtime_files = files(
   'vk_fence.h',
   'vk_framebuffer.c',
   'vk_framebuffer.h',
+  'vk_graphics_state.c',
+  'vk_graphics_state.h',
   'vk_image.c',
   'vk_image.h',
   'vk_instance.c',
diff --git a/src/vulkan/runtime/vk_graphics_state.c b/src/vulkan/runtime/vk_graphics_state.c
new file mode 100644
index 00000000000..84dc41062fa
--- /dev/null
+++ b/src/vulkan/runtime/vk_graphics_state.c
@@ -0,0 +1,67 @@
+#include "vk_graphics_state.h"
+
+void
+vk_get_dynamic_graphics_states(BITSET_WORD *dynamic,
+                               const VkPipelineDynamicStateCreateInfo *info)
+{
+   /* From the Vulkan 1.3.218 spec:
+    *
+    *    "pDynamicState is a pointer to a VkPipelineDynamicStateCreateInfo
+    *    structure defining which properties of the pipeline state object are
+    *    dynamic and can be changed independently of the pipeline state. This
+    *    can be NULL, which means no state in the pipeline is considered
+    *    dynamic."
+    */
+   if (info == NULL)
+      return;
+
+#define CASE(VK, MESA) \
+   case VK_DYNAMIC_STATE_##VK: \
+      BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA); \
+      break;
+
+#define CASE2(VK, MESA1, MESA2) \
+   case VK_DYNAMIC_STATE_##VK: \
+      BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA1); \
+      BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA2); \
+      break;
+
+   for (uint32_t i = 0; i < info->dynamicStateCount; i++) {
+      switch (info->pDynamicStates[i]) {
+      CASE2(VERTEX_INPUT_EXT,             VI, VI_BINDING_STRIDES)
+      CASE( VERTEX_INPUT_BINDING_STRIDE,  VI_BINDING_STRIDES)
+      CASE( VIEWPORT,                     VP_VIEWPORTS)
+      CASE( SCISSOR,                      VP_SCISSORS)
+      CASE( LINE_WIDTH,                   RS_LINE_WIDTH)
+      CASE( DEPTH_BIAS,                   RS_DEPTH_BIAS_FACTORS)
+      CASE( BLEND_CONSTANTS,              CB_BLEND_CONSTANTS)
+      CASE( DEPTH_BOUNDS,                 DS_DEPTH_BOUNDS_TEST_BOUNDS)
+      CASE( STENCIL_COMPARE_MASK,         DS_STENCIL_COMPARE_MASK)
+      CASE( STENCIL_WRITE_MASK,           DS_STENCIL_WRITE_MASK)
+      CASE( STENCIL_REFERENCE,            DS_STENCIL_REFERENCE)
+      CASE( CULL_MODE,                    RS_CULL_MODE)
+      CASE( FRONT_FACE,                   RS_FRONT_FACE)
+      CASE( PRIMITIVE_TOPOLOGY,           IA_PRIMITIVE_TOPOLOGY)
+      CASE2(VIEWPORT_WITH_COUNT,          VP_VIEWPORT_COUNT, VP_VIEWPORTS)
+      CASE2(SCISSOR_WITH_COUNT,           VP_SCISSOR_COUNT, VP_SCISSORS)
+      CASE( DEPTH_TEST_ENABLE,            DS_DEPTH_TEST_ENABLE)
+      CASE( DEPTH_WRITE_ENABLE,           DS_DEPTH_WRITE_ENABLE)
+      CASE( DEPTH_COMPARE_OP,             DS_DEPTH_COMPARE_OP)
+      CASE( DEPTH_BOUNDS_TEST_ENABLE,     DS_DEPTH_BOUNDS_TEST_ENABLE)
+      CASE( STENCIL_TEST_ENABLE,          DS_STENCIL_TEST_ENABLE)
+      CASE( STENCIL_OP,                   DS_STENCIL_OP)
+      CASE( RASTERIZER_DISCARD_ENABLE,    RS_RASTERIZER_DISCARD_ENABLE)
+      CASE( DEPTH_BIAS_ENABLE,            RS_DEPTH_BIAS_ENABLE)
+      CASE( PRIMITIVE_RESTART_ENABLE,     IA_PRIMITIVE_RESTART_ENABLE)
+      CASE( DISCARD_RECTANGLE_EXT,        DR_RECTANGLES)
+      CASE( SAMPLE_LOCATIONS_EXT,         MS_SAMPLE_LOCATIONS)
+      CASE( FRAGMENT_SHADING_RATE_KHR,    FSR)
+      CASE( LINE_STIPPLE_EXT,             RS_LINE_STIPPLE)
+      CASE( PATCH_CONTROL_POINTS_EXT,     TS_PATCH_CONTROL_POINTS)
+      CASE( LOGIC_OP_EXT,                 CB_LOGIC_OP)
+      CASE( COLOR_WRITE_ENABLE_EXT,       CB_COLOR_WRITE_ENABLES)
+      default:
+         unreachable("Unsupported dynamic graphics state");
+      }
+   }
+}
diff --git a/src/vulkan/runtime/vk_graphics_state.h b/src/vulkan/runtime/vk_graphics_state.h
new file mode 100644
index 00000000000..a5bcc9f2d53
--- /dev/null
+++ b/src/vulkan/runtime/vk_graphics_state.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2022 Collabora, Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef VK_GRAPHICS_STATE_H
+#define VK_GRAPHICS_STATE_H
+
+#include "vulkan/vulkan_core.h"
+
+#include "util/bitset.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Enumeration of all Vulkan dynamic graphics states
+ *
+ * Enumerants are named with both the abreviation of the state group to which
+ * the state belongs as well as the name of the state itself.  These are
+ * intended to pretty closely match the VkDynamicState enum but may not match
+ * perfectly all the time.
+ */
+enum mesa_vk_dynamic_graphics_state {
+   MESA_VK_DYNAMIC_VI,
+   MESA_VK_DYNAMIC_VI_BINDING_STRIDES,
+   MESA_VK_DYNAMIC_IA_PRIMITIVE_TOPOLOGY,
+   MESA_VK_DYNAMIC_IA_PRIMITIVE_RESTART_ENABLE,
+   MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS,
+   MESA_VK_DYNAMIC_VP_VIEWPORT_COUNT,
+   MESA_VK_DYNAMIC_VP_VIEWPORTS,
+   MESA_VK_DYNAMIC_VP_SCISSOR_COUNT,
+   MESA_VK_DYNAMIC_VP_SCISSORS,
+   MESA_VK_DYNAMIC_DR_RECTANGLES,
+   MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE,
+   MESA_VK_DYNAMIC_RS_CULL_MODE,
+   MESA_VK_DYNAMIC_RS_FRONT_FACE,
+   MESA_VK_DYNAMIC_RS_DEPTH_BIAS_ENABLE,
+   MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS,
+   MESA_VK_DYNAMIC_RS_LINE_WIDTH,
+   MESA_VK_DYNAMIC_RS_LINE_STIPPLE,
+   MESA_VK_DYNAMIC_FSR,
+   MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS,
+   MESA_VK_DYNAMIC_DS_DEPTH_TEST_ENABLE,
+   MESA_VK_DYNAMIC_DS_DEPTH_WRITE_ENABLE,
+   MESA_VK_DYNAMIC_DS_DEPTH_COMPARE_OP,
+   MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_ENABLE,
+   MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_BOUNDS,
+   MESA_VK_DYNAMIC_DS_STENCIL_TEST_ENABLE,
+   MESA_VK_DYNAMIC_DS_STENCIL_OP,
+   MESA_VK_DYNAMIC_DS_STENCIL_COMPARE_MASK,
+   MESA_VK_DYNAMIC_DS_STENCIL_WRITE_MASK,
+   MESA_VK_DYNAMIC_DS_STENCIL_REFERENCE,
+   MESA_VK_DYNAMIC_CB_LOGIC_OP,
+   MESA_VK_DYNAMIC_CB_COLOR_WRITE_ENABLES,
+   MESA_VK_DYNAMIC_CB_BLEND_CONSTANTS,
+
+   /* Must be left at the end */
+   MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX,
+};
+
+/** Populate a bitset with dynamic states
+ *
+ * This function maps a VkPipelineDynamicStateCreateInfo to a bitset indexed
+ * by mesa_vk_dynamic_graphics_state enumerants.
+ *
+ * @param[out] dynamic  Bitset to populate
+ * @param[in]  info     VkPipelineDynamicStateCreateInfo or NULL
+ */
+void
+vk_get_dynamic_graphics_states(BITSET_WORD *dynamic,
+                               const VkPipelineDynamicStateCreateInfo *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* VK_GRAPHICS_STATE_H */



More information about the mesa-commit mailing list