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

Author: Lionel Landwerlin <[email protected]>
Date:   Tue Jun  6 07:55:05 2023 +0300

vulkan/runtime: add support for EXT_depth_bias_control

Signed-off-by: Lionel Landwerlin <[email protected]>
Reviewed-by: Georg Lehmann <[email protected]>
Reviewed-by: Samuel Pitoiset <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23716>

---

 src/vulkan/runtime/vk_graphics_state.c | 65 ++++++++++++++++++++++++++++++++++
 src/vulkan/runtime/vk_graphics_state.h | 12 +++++++
 2 files changed, 77 insertions(+)

diff --git a/src/vulkan/runtime/vk_graphics_state.c 
b/src/vulkan/runtime/vk_graphics_state.c
index 3d493fd74f5..80626eb3082 100644
--- a/src/vulkan/runtime/vk_graphics_state.c
+++ b/src/vulkan/runtime/vk_graphics_state.c
@@ -513,6 +513,8 @@ vk_rasterization_state_init(struct vk_rasterization_state 
*rs,
       .provoking_vertex = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT,
       .line.mode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT,
       .depth_clip_enable = IS_DYNAMIC(RS_DEPTH_CLAMP_ENABLE) ? 
VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP : VK_MESA_DEPTH_CLIP_ENABLE_FALSE,
+      .depth_bias.representation = 
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT,
+      .depth_bias.exact = false,
    };
    if (!rs_info)
       return;
@@ -604,6 +606,16 @@ vk_rasterization_state_init(struct vk_rasterization_state 
*rs,
          break;
       }
 
+      case VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT: {
+         const VkDepthBiasRepresentationInfoEXT *dbr_info =
+            (const VkDepthBiasRepresentationInfoEXT *)ext;
+         if (!IS_DYNAMIC(RS_DEPTH_BIAS_FACTORS)) {
+            rs->depth_bias.representation = dbr_info->depthBiasRepresentation;
+            rs->depth_bias.exact = dbr_info->depthBiasExact;
+         }
+         break;
+      }
+
       default:
          break;
       }
@@ -1770,6 +1782,8 @@ vk_dynamic_graphics_state_copy(struct 
vk_dynamic_graphics_state *dst,
    COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.constant);
    COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.clamp);
    COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.slope);
+   COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.representation);
+   COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.exact);
    COPY_IF_SET(RS_LINE_WIDTH, rs.line.width);
    COPY_IF_SET(RS_LINE_MODE, rs.line.mode);
    COPY_IF_SET(RS_LINE_STIPPLE_ENABLE, rs.line.stipple.enable);
@@ -2204,6 +2218,18 @@ vk_common_CmdSetDepthBias(VkCommandBuffer commandBuffer,
                  rs.depth_bias.clamp, depthBiasClamp);
    SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
                  rs.depth_bias.slope, depthBiasSlopeFactor);
+
+   /** From the Vulkan 1.3.254 spec:
+    *
+    *   "Calling this function is equivalent to calling vkCmdSetDepthBias2EXT
+    *    without a VkDepthBiasRepresentationInfoEXT in the pNext chain of
+    *    VkDepthBiasInfoEXT."
+    */
+   SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                 rs.depth_bias.representation,
+                 
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT);
+   SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                 rs.depth_bias.exact, false);
 }
 
 VKAPI_ATTR void VKAPI_CALL
@@ -2668,3 +2694,42 @@ vk_common_CmdSetDiscardRectangleModeEXT(VkCommandBuffer 
commandBuffer,
 
    SET_DYN_VALUE(dyn, DR_MODE, dr.mode, discardRectangleMode);
 }
+
+VKAPI_ATTR void VKAPI_CALL
+vk_common_CmdSetDepthBias2EXT(
+    VkCommandBuffer                             commandBuffer,
+    const VkDepthBiasInfoEXT*                   pDepthBiasInfo)
+{
+   VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
+   struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
+
+   SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                 rs.depth_bias.constant, 
pDepthBiasInfo->depthBiasConstantFactor);
+   SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                 rs.depth_bias.clamp, pDepthBiasInfo->depthBiasClamp);
+   SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                 rs.depth_bias.slope, pDepthBiasInfo->depthBiasSlopeFactor);
+
+   /** From the Vulkan 1.3.254 spec:
+    *
+    *    "If pNext does not contain a VkDepthBiasRepresentationInfoEXT
+    *     structure, then this command is equivalent to including a
+    *     VkDepthBiasRepresentationInfoEXT with depthBiasExact set to VK_FALSE
+    *     and depthBiasRepresentation set to
+    *     VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT."
+    */
+   const VkDepthBiasRepresentationInfoEXT *dbr_info =
+      vk_find_struct_const(pDepthBiasInfo->pNext, 
DEPTH_BIAS_REPRESENTATION_INFO_EXT);
+   if (dbr_info) {
+      SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                    rs.depth_bias.representation, 
dbr_info->depthBiasRepresentation);
+      SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                    rs.depth_bias.exact, dbr_info->depthBiasExact);
+   } else {
+      SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                    rs.depth_bias.representation,
+                    
VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT);
+      SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
+                    rs.depth_bias.exact, false);
+   }
+}
diff --git a/src/vulkan/runtime/vk_graphics_state.h 
b/src/vulkan/runtime/vk_graphics_state.h
index 11826a85b0e..56fb0213b28 100644
--- a/src/vulkan/runtime/vk_graphics_state.h
+++ b/src/vulkan/runtime/vk_graphics_state.h
@@ -320,6 +320,18 @@ struct vk_rasterization_state {
        * MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
        */
       float slope;
+
+      /** VkDepthBiasRepresentationInfoEXT::depthBiasRepresentation
+       *
+       * MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
+       */
+      VkDepthBiasRepresentationEXT representation;
+
+      /** VkDepthBiasRepresentationInfoEXT::depthBiasExact
+       *
+       * MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
+       */
+      bool exact;
    } depth_bias;
 
    struct {

Reply via email to