zink: use dynamic line stipple
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 25 May 2021 20:57:50 +0000 (16:57 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 27 Jul 2021 23:22:19 +0000 (23:22 +0000)
save those pipeline bits!

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

src/gallium/drivers/zink/zink_draw.cpp
src/gallium/drivers/zink/zink_pipeline.c
src/gallium/drivers/zink/zink_state.c
src/gallium/drivers/zink/zink_state.h

index d6aae52..7ba687d 100644 (file)
@@ -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);
index 26167b0..d60bcc2 100644 (file)
@@ -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;
index cf8a1ce..4e66eb5 100644 (file)
@@ -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;
index e314a9b..599514a 100644 (file)
@@ -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 {