zink: use dynamic rasterizer_discard state when possible
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 7 Mar 2022 20:17:55 +0000 (15:17 -0500)
committerMarge Bot <emma+marge@anholt.net>
Mon, 14 Mar 2022 04:08:29 +0000 (04:08 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15328>

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

index 97b1130..68e24e4 100644 (file)
@@ -364,6 +364,7 @@ struct zink_context {
    bool rast_state_changed : 1;
    bool dsa_state_changed : 1;
    bool stencil_ref_changed : 1;
+   bool rasterizer_discard_changed : 1;
 };
 
 static inline struct zink_context *
index 0a002fc..b5e66fd 100644 (file)
@@ -786,6 +786,11 @@ zink_draw(struct pipe_context *pctx,
       ctx->primitive_restart = dinfo->primitive_restart;
    }
 
+   if (DYNAMIC_STATE >= ZINK_DYNAMIC_STATE2 && (BATCH_CHANGED || ctx->rasterizer_discard_changed)) {
+      VKCTX(CmdSetRasterizerDiscardEnableEXT)(batch->state->cmdbuf, ctx->gfx_pipeline_state.dyn_state2.rasterizer_discard);
+      ctx->rasterizer_discard_changed = false;
+   }
+
    if (zink_program_has_descriptors(&ctx->curr_program->base))
       screen->descriptors_update(ctx, false);
 
index 791a39e..fc6ed10 100644 (file)
@@ -162,7 +162,7 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
    rast_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
 
    rast_state.depthClampEnable = hw_rast_state->depth_clamp;
-   rast_state.rasterizerDiscardEnable = hw_rast_state->rasterizer_discard;
+   rast_state.rasterizerDiscardEnable = state->dyn_state2.rasterizer_discard;
    rast_state.polygonMode = hw_rast_state->polygon_mode;
    rast_state.cullMode = hw_rast_state->cull_mode;
    rast_state.frontFace = state->dyn_state1.front_face;
@@ -228,8 +228,10 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
       else if (screen->info.have_EXT_extended_dynamic_state)
          dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT;
    }
-   if (screen->info.have_EXT_extended_dynamic_state2)
+   if (screen->info.have_EXT_extended_dynamic_state2) {
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT;
+      dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE_EXT;
+   }
 
    VkPipelineRasterizationLineStateCreateInfoEXT rast_line_state;
    if (screen->info.have_EXT_line_rasterization) {
index 76bfcf6..ea220f1 100644 (file)
@@ -42,7 +42,7 @@ struct zink_vertex_elements_state;
 struct zink_gfx_pipeline_state {
    uint32_t rast_state : ZINK_RAST_HW_STATE_SIZE; //zink_rasterizer_hw_state
    uint32_t vertices_per_patch:5;
-   uint32_t rast_samples:7;
+   uint32_t rast_samples:8; //2 extra bits
    uint32_t void_alpha_attachments:PIPE_MAX_COLOR_BUFS;
    VkSampleMask sample_mask;
 
@@ -62,6 +62,7 @@ struct zink_gfx_pipeline_state {
 
    struct {
       bool primitive_restart;
+      bool rasterizer_discard;
    } dyn_state2;
 
    VkShaderModule modules[PIPE_SHADER_TYPES - 1];
index 3991eba..29801bb 100644 (file)
@@ -589,7 +589,6 @@ zink_create_rasterizer_state(struct pipe_context *pctx,
 
    assert(rs_state->depth_clip_far == rs_state->depth_clip_near);
    state->hw_state.depth_clamp = rs_state->depth_clip_near == 0;
-   state->hw_state.rasterizer_discard = rs_state->rasterizer_discard;
    state->hw_state.force_persample_interp = rs_state->force_persample_interp;
    state->hw_state.pv_last = !rs_state->flatshade_first;
    state->hw_state.clip_halfz = rs_state->clip_halfz;
@@ -709,6 +708,12 @@ zink_bind_rasterizer_state(struct pipe_context *pctx, void *cso)
          ctx->gfx_pipeline_state.dyn_state1.front_face = ctx->rast_state->front_face;
          ctx->gfx_pipeline_state.dirty |= !zink_screen(pctx->screen)->info.have_EXT_extended_dynamic_state;
       }
+      if (ctx->gfx_pipeline_state.dyn_state2.rasterizer_discard != ctx->rast_state->base.rasterizer_discard) {
+         ctx->gfx_pipeline_state.dyn_state2.rasterizer_discard = ctx->rast_state->base.rasterizer_discard;
+         ctx->gfx_pipeline_state.dirty |= !zink_screen(pctx->screen)->info.have_EXT_extended_dynamic_state2;
+         if (zink_screen(pctx->screen)->info.have_EXT_extended_dynamic_state2)
+            ctx->rasterizer_discard_changed = true;
+      }
       if (ctx->rast_state->base.point_quad_rasterization != point_quad_rasterization)
          zink_set_fs_point_coord_key(ctx);
       if (ctx->rast_state->base.scissor != scissor)
index 2f3850e..502982d 100644 (file)
@@ -71,13 +71,12 @@ struct zink_rasterizer_hw_state {
    unsigned cull_mode : 2; //VkCullModeFlags
    unsigned line_mode : 2; //VkLineRasterizationModeEXT
    unsigned depth_clamp:1;
-   unsigned rasterizer_discard:1;
    unsigned pv_last:1;
    unsigned line_stipple_enable:1;
    unsigned force_persample_interp:1;
    unsigned clip_halfz:1;
 };
-#define ZINK_RAST_HW_STATE_SIZE 12
+#define ZINK_RAST_HW_STATE_SIZE 11
 
 
 struct zink_rasterizer_state {