Mesa (main): zink: use dynamic line stipple

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 27 23:34:18 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Tue May 25 16:57:50 2021 -0400

zink: use dynamic line stipple

save those pipeline bits!

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12011>

---

 src/gallium/drivers/zink/zink_draw.cpp   |  3 +++
 src/gallium/drivers/zink/zink_pipeline.c | 32 ++++++++++++++------------------
 src/gallium/drivers/zink/zink_state.c    | 13 ++++++-------
 src/gallium/drivers/zink/zink_state.h    |  3 +--
 4 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index d6aae521616..7ba687d5ed3 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -606,6 +606,9 @@ zink_draw_vbo(struct pipe_context *pctx,
    bool rast_state_changed = ctx->rast_state_changed;
    if (HAS_DYNAMIC_STATE && (BATCH_CHANGED || rast_state_changed))
       screen->vk.CmdSetFrontFaceEXT(batch->state->cmdbuf, ctx->gfx_pipeline_state.front_face);
+   if ((BATCH_CHANGED || rast_state_changed) &&
+       screen->info.have_EXT_line_rasterization && rast_state->base.line_stipple_enable)
+      screen->vk.CmdSetLineStippleEXT(batch->state->cmdbuf, rast_state->base.line_stipple_factor, rast_state->base.line_stipple_pattern);
 
    if (BATCH_CHANGED || ctx->rast_state_changed || mode_changed) {
       enum pipe_prim_type reduced_prim = u_reduced_prim(mode);
diff --git a/src/gallium/drivers/zink/zink_pipeline.c b/src/gallium/drivers/zink/zink_pipeline.c
index 26167b0f06d..d60bcc20418 100644
--- a/src/gallium/drivers/zink/zink_pipeline.c
+++ b/src/gallium/drivers/zink/zink_pipeline.c
@@ -149,24 +149,6 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
       rast_state.pNext = &pv_state;
    }
 
-   VkPipelineRasterizationLineStateCreateInfoEXT rast_line_state;
-   if (screen->info.have_EXT_line_rasterization) {
-      rast_line_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
-      rast_line_state.pNext = rast_state.pNext;
-      rast_line_state.lineRasterizationMode = state->rast_state->line_mode;
-
-      if (state->rast_state->line_stipple_pattern != UINT16_MAX) {
-         rast_line_state.stippledLineEnable = VK_TRUE;
-         rast_line_state.lineStippleFactor = state->rast_state->line_stipple_factor + 1;
-         rast_line_state.lineStipplePattern = state->rast_state->line_stipple_pattern;
-      } else {
-         rast_line_state.stippledLineEnable = VK_FALSE;
-         rast_line_state.lineStippleFactor = 0;
-         rast_line_state.lineStipplePattern = 0;
-      }
-      rast_state.pNext = &rast_line_state;
-   }
-
    VkPipelineDepthStencilStateCreateInfo depth_stencil_state = {0};
    depth_stencil_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
    depth_stencil_state.depthTestEnable = state->depth_stencil_alpha_state->depth_test;
@@ -210,6 +192,20 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_EXT;
    }
 
+   VkPipelineRasterizationLineStateCreateInfoEXT rast_line_state;
+   if (screen->info.have_EXT_line_rasterization) {
+      rast_line_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
+      rast_line_state.pNext = rast_state.pNext;
+      rast_line_state.stippledLineEnable = VK_FALSE;
+      rast_line_state.lineRasterizationMode = state->rast_state->line_mode;
+
+      if (state->rast_state->line_stipple_enable) {
+         dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_LINE_STIPPLE_EXT;
+         rast_line_state.stippledLineEnable = VK_TRUE;
+      }
+      rast_state.pNext = &rast_line_state;
+   }
+
    VkPipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo = {0};
    pipelineDynamicStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
    pipelineDynamicStateCreateInfo.pDynamicStates = dynamicStateEnables;
diff --git a/src/gallium/drivers/zink/zink_state.c b/src/gallium/drivers/zink/zink_state.c
index cf8a1ce7643..4e66eb53191 100644
--- a/src/gallium/drivers/zink/zink_state.c
+++ b/src/gallium/drivers/zink/zink_state.c
@@ -465,6 +465,8 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
       return NULL;
 
    state->base = *rs_state;
+   state->base.line_stipple_factor++;
+   state->hw_state.line_stipple_enable = rs_state->line_stipple_enable;
 
    assert(rs_state->depth_clip_far == rs_state->depth_clip_near);
    state->hw_state.depth_clamp = rs_state->depth_clip_near == 0;
@@ -488,9 +490,6 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
       VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
 
    if (rs_state->line_stipple_enable) {
-      state->hw_state.line_stipple_factor = rs_state->line_stipple_factor;
-      state->hw_state.line_stipple_pattern = rs_state->line_stipple_pattern;
-
       if (screen->info.have_EXT_line_rasterization) {
          if (rs_state->line_rectangular) {
             if (rs_state->line_smooth) {
@@ -505,8 +504,8 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
                VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
          else {
             /* no suitable mode that supports line stippling */
-            state->hw_state.line_stipple_factor = 0;
-            state->hw_state.line_stipple_pattern = UINT16_MAX;
+            state->base.line_stipple_factor = 0;
+            state->base.line_stipple_pattern = UINT16_MAX;
          }
       }
    } else {
@@ -523,8 +522,8 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
             state->hw_state.line_mode =
                VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
       }
-      state->hw_state.line_stipple_factor = 0;
-      state->hw_state.line_stipple_pattern = UINT16_MAX;
+      state->base.line_stipple_factor = 0;
+      state->base.line_stipple_pattern = UINT16_MAX;
    }
 
    state->offset_point = rs_state->offset_point;
diff --git a/src/gallium/drivers/zink/zink_state.h b/src/gallium/drivers/zink/zink_state.h
index e314a9bed23..599514ad3fa 100644
--- a/src/gallium/drivers/zink/zink_state.h
+++ b/src/gallium/drivers/zink/zink_state.h
@@ -62,8 +62,7 @@ struct zink_rasterizer_hw_state {
    unsigned depth_clamp : 1;
    unsigned rasterizer_discard : 1;
    unsigned force_persample_interp : 1;
-   unsigned line_stipple_factor : 8;
-   unsigned line_stipple_pattern : 16;
+   bool line_stipple_enable;
 };
 
 struct zink_rasterizer_state {



More information about the mesa-commit mailing list