zink: start using dynamic front face state
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 2 Mar 2021 16:21:58 +0000 (11:21 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 7 May 2021 02:00:54 +0000 (02:00 +0000)
this doesn't actually do anything other than test the codepath since
the hashed pipeline state will still change on every frontface change,
but it's a start

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

src/gallium/drivers/zink/zink_draw.c
src/gallium/drivers/zink/zink_pipeline.c
src/gallium/drivers/zink/zink_pipeline.h
src/gallium/drivers/zink/zink_program.c
src/gallium/drivers/zink/zink_screen.c
src/gallium/drivers/zink/zink_screen.h
src/gallium/drivers/zink/zink_state.c
src/gallium/drivers/zink/zink_state.h

index 17dbe54..59682a9 100644 (file)
@@ -502,6 +502,7 @@ zink_draw_vbo(struct pipe_context *pctx,
             vkCmdSetStencilCompareMask(batch->state->cmdbuf, VK_STENCIL_FACE_FRONT_AND_BACK, dsa_state->hw_state.stencil_front.compareMask);
          }
       }
+      screen->vk_CmdSetFrontFaceEXT(batch->state->cmdbuf, ctx->gfx_pipeline_state.front_face);
    }
 
    if (depth_bias)
index 142bbba..6264ccb 100644 (file)
@@ -106,7 +106,7 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
    rast_state.rasterizerDiscardEnable = state->rast_state->rasterizer_discard;
    rast_state.polygonMode = state->rast_state->polygon_mode;
    rast_state.cullMode = state->rast_state->cull_mode;
-   rast_state.frontFace = state->rast_state->front_face;
+   rast_state.frontFace = state->front_face;
 
    rast_state.depthBiasEnable = VK_TRUE;
    rast_state.depthBiasConstantFactor = 0.0;
@@ -155,6 +155,7 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_STENCIL_OP_EXT;
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT;
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT;
+      dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_FRONT_FACE_EXT;
    } else {
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_VIEWPORT;
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_SCISSOR;
index 3032ca6..0c39acc 100644 (file)
@@ -59,6 +59,7 @@ struct zink_gfx_pipeline_state {
    bool dirty;
 
    struct zink_depth_stencil_alpha_hw_state *depth_stencil_alpha_state; //non-dynamic state
+   VkFrontFace front_face;
 
    VkShaderModule modules[PIPE_SHADER_TYPES - 1];
    uint32_t module_hash;
index ee042c5..88c2a51 100644 (file)
@@ -395,6 +395,8 @@ equals_gfx_pipeline_state(const void *a, const void *b)
          if (sa->vertex_strides[idx_a] != sb->vertex_strides[idx_b])
             return false;
       }
+      if (sa->front_face != sb->front_face)
+         return false;
       if (!!sa->depth_stencil_alpha_state != !!sb->depth_stencil_alpha_state ||
           (sa && sb && memcmp(sa->depth_stencil_alpha_state, sb->depth_stencil_alpha_state, sizeof(struct zink_depth_stencil_alpha_hw_state))))
          return false;
index 117be53..b4bda46 100644 (file)
@@ -1213,6 +1213,7 @@ load_device_extensions(struct zink_screen *screen)
       GET_PROC_ADDR(CmdSetStencilOpEXT);
       GET_PROC_ADDR(CmdSetStencilTestEnableEXT);
       GET_PROC_ADDR(CmdBindVertexBuffers2EXT);
+      GET_PROC_ADDR(CmdSetFrontFaceEXT);
    }
 
    if (screen->info.have_EXT_image_drm_format_modifier)
index a04df30..f062607 100644 (file)
@@ -141,6 +141,7 @@ struct zink_screen {
    PFN_vkCmdSetStencilTestEnableEXT vk_CmdSetStencilTestEnableEXT;
    PFN_vkCmdSetStencilOpEXT vk_CmdSetStencilOpEXT;
    PFN_vkCmdBindVertexBuffers2EXT vk_CmdBindVertexBuffers2EXT;
+   PFN_vkCmdSetFrontFaceEXT vk_CmdSetFrontFaceEXT;
 
    PFN_vkCreateDebugUtilsMessengerEXT vk_CreateDebugUtilsMessengerEXT;
    PFN_vkDestroyDebugUtilsMessengerEXT vk_DestroyDebugUtilsMessengerEXT;
index 1480b60..59d6b73 100644 (file)
@@ -445,9 +445,9 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
    state->hw_state.polygon_mode = (VkPolygonMode)rs_state->fill_front; // same values
    state->hw_state.cull_mode = (VkCullModeFlags)rs_state->cull_face; // same bits
 
-   state->hw_state.front_face = rs_state->front_ccw ?
-                                VK_FRONT_FACE_COUNTER_CLOCKWISE :
-                                VK_FRONT_FACE_CLOCKWISE;
+   state->front_face = rs_state->front_ccw ?
+                       VK_FRONT_FACE_COUNTER_CLOCKWISE :
+                       VK_FRONT_FACE_CLOCKWISE;
 
    state->offset_point = rs_state->offset_point;
    state->offset_line = rs_state->offset_line;
@@ -487,6 +487,10 @@ zink_bind_rasterizer_state(struct pipe_context *pctx, void *cso)
       if (clip_halfz != ctx->rast_state->base.clip_halfz)
          ctx->last_vertex_stage_dirty = true;
 
+      if (ctx->gfx_pipeline_state.front_face != ctx->rast_state->front_face) {
+         ctx->gfx_pipeline_state.front_face = ctx->rast_state->front_face;
+         ctx->gfx_pipeline_state.dirty |= !zink_screen(pctx->screen)->info.have_EXT_extended_dynamic_state;
+      }
       if (ctx->line_width != ctx->rast_state->line_width) {
          ctx->line_width = ctx->rast_state->line_width;
          ctx->gfx_pipeline_state.dirty = true;
index 309bb4d..7a200a5 100644 (file)
@@ -49,7 +49,6 @@ struct zink_vertex_elements_state {
 struct zink_rasterizer_hw_state {
    VkBool32 depth_clamp;
    VkBool32 rasterizer_discard;
-   VkFrontFace front_face;
    VkPolygonMode polygon_mode;
    VkCullModeFlags cull_mode;
    VkProvokingVertexModeEXT pv_mode;
@@ -61,6 +60,7 @@ struct zink_rasterizer_state {
    bool offset_point, offset_line, offset_tri;
    float offset_units, offset_clamp, offset_scale;
    float line_width;
+   VkFrontFace front_face;
    struct zink_rasterizer_hw_state hw_state;
 };