zink: set primitive restart with extended dynamic state2
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 11 Jun 2021 15:20:30 +0000 (11:20 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 27 Aug 2021 03:31:25 +0000 (03:31 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12585>

src/gallium/drivers/zink/zink_context.c
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_program.c

index 7f0c60cd738809e0b98cd6483c15f224b941e350..eea5d72eaa3df3362fa114bf66f1d4ea1f17ed66 100644 (file)
@@ -3508,6 +3508,7 @@ zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    _mesa_hash_table_init(&ctx->batch_states, ctx, NULL, _mesa_key_pointer_equal);
 
    ctx->gfx_pipeline_state.have_EXT_extended_dynamic_state = screen->info.have_EXT_extended_dynamic_state;
+   ctx->gfx_pipeline_state.have_EXT_extended_dynamic_state2 = screen->info.have_EXT_extended_dynamic_state2;
 
    slab_create_child(&ctx->transfer_pool, &screen->transfer_pool);
    slab_create_child(&ctx->transfer_pool_unsync, &screen->transfer_pool);
index 1abf833faf3da36fb095ce1744001e3fde4ba2ca..4a58dadd945c6fafdac2200d6d439dccbb84ebcd 100644 (file)
@@ -317,6 +317,7 @@ struct zink_context {
    bool gfx_dirty;
 
    bool is_device_lost;
+   bool primitive_restart;
    bool vertex_state_changed : 1;
    bool blend_state_changed : 1;
    bool rast_state_changed : 1;
index 93f94e11a840a2b7a445c5adb70ac147e8e5ee09..9a1ecb1cd266171ab379d92dbf073f98652a0842 100644 (file)
@@ -455,9 +455,11 @@ zink_draw_vbo(struct pipe_context *pctx,
    }
    ctx->gfx_prim_mode = mode;
 
-   if (ctx->gfx_pipeline_state.primitive_restart != dinfo->primitive_restart)
-      ctx->gfx_pipeline_state.dirty = true;
-   ctx->gfx_pipeline_state.primitive_restart = dinfo->primitive_restart;
+   if (!HAS_DYNAMIC_STATE2) {
+      if (ctx->gfx_pipeline_state.primitive_restart != dinfo->primitive_restart)
+         ctx->gfx_pipeline_state.dirty = true;
+      ctx->gfx_pipeline_state.primitive_restart = dinfo->primitive_restart;
+   }
 
    unsigned index_offset = 0;
    unsigned index_size = dinfo->index_size;
@@ -684,6 +686,11 @@ zink_draw_vbo(struct pipe_context *pctx,
          screen->vk.CmdSetPrimitiveTopologyEXT(batch->state->cmdbuf, zink_primitive_topology(mode));
    }
 
+   if (HAS_DYNAMIC_STATE2 && (BATCH_CHANGED || ctx->primitive_restart != dinfo->primitive_restart)) {
+      screen->vk.CmdSetPrimitiveRestartEnableEXT(batch->state->cmdbuf, dinfo->primitive_restart);
+      ctx->primitive_restart = dinfo->primitive_restart;
+   }
+
    if (zink_program_has_descriptors(&ctx->curr_program->base))
       screen->descriptors_update(ctx, false);
 
index e7e4523497f2b312bcd9e43431e5313f661481a5..e0dd175a55fee8c30484da40382f90df411705ec 100644 (file)
@@ -73,19 +73,21 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
    VkPipelineInputAssemblyStateCreateInfo primitive_state = {0};
    primitive_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
    primitive_state.topology = primitive_topology;
-   switch (primitive_topology) {
-   case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
-   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
-   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
-   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
-   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
-   case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
-      if (state->primitive_restart)
-         debug_printf("restart_index set with unsupported primitive topology %u\n", primitive_topology);
-      primitive_state.primitiveRestartEnable = VK_FALSE;
-      break;
-   default:
-      primitive_state.primitiveRestartEnable = state->primitive_restart ? VK_TRUE : VK_FALSE;
+   if (!screen->info.have_EXT_extended_dynamic_state2) {
+      switch (primitive_topology) {
+      case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+      case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+      case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+      case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
+      case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
+      case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
+         if (state->primitive_restart)
+            debug_printf("restart_index set with unsupported primitive topology %u\n", primitive_topology);
+         primitive_state.primitiveRestartEnable = VK_FALSE;
+         break;
+      default:
+         primitive_state.primitiveRestartEnable = state->primitive_restart ? VK_TRUE : VK_FALSE;
+      }
    }
 
    VkPipelineColorBlendAttachmentState blend_att[PIPE_MAX_COLOR_BUFS];
@@ -195,6 +197,8 @@ zink_create_gfx_pipeline(struct zink_screen *screen,
    if (screen->info.have_EXT_vertex_input_dynamic_state) {
       dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_EXT;
    }
+   if (screen->info.have_EXT_extended_dynamic_state2)
+      dynamicStateEnables[state_count++] = VK_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE_EXT;
 
    VkPipelineRasterizationLineStateCreateInfoEXT rast_line_state;
    if (screen->info.have_EXT_line_rasterization) {
index 18784e9e9dc4325caec443f12c337e98b0c99c2d..1f619a179f2bd9fad51600c62d4fea748405781f 100644 (file)
@@ -51,8 +51,6 @@ struct zink_gfx_pipeline_state {
 
    unsigned num_viewports;
 
-   bool primitive_restart;
-
    /* Pre-hashed value for table lookup, invalid when zero.
     * Members after this point are not included in pipeline state hash key */
    uint32_t hash;
@@ -60,6 +58,8 @@ struct zink_gfx_pipeline_state {
 
    struct zink_depth_stencil_alpha_hw_state *depth_stencil_alpha_state; //non-dynamic state
    VkFrontFace front_face;
+   
+   bool primitive_restart; //dynamic state2
 
    VkShaderModule modules[PIPE_SHADER_TYPES - 1];
    uint32_t module_hash;
@@ -75,7 +75,7 @@ struct zink_gfx_pipeline_state {
    uint32_t vertex_strides[PIPE_MAX_ATTRIBS];
    bool sample_locations_enabled;
    bool have_EXT_extended_dynamic_state;
-
+   bool have_EXT_extended_dynamic_state2;
    VkPipeline pipeline;
    uint8_t patch_vertices;
    unsigned idx : 8;
index 748a6b419d3f2bb010bb6fffb9cb4798449985cd..597e325711a3f0635a56bc5e3015497b6854e542 100644 (file)
@@ -309,6 +309,8 @@ hash_gfx_pipeline_state(const void *key)
 {
    const struct zink_gfx_pipeline_state *state = key;
    uint32_t hash = _mesa_hash_data(key, offsetof(struct zink_gfx_pipeline_state, hash));
+   if (!state->have_EXT_extended_dynamic_state2)
+      hash = XXH32(&state->primitive_restart, 1, hash);
    if (state->have_EXT_extended_dynamic_state)
       return hash;
    return XXH32(&state->depth_stencil_alpha_state, sizeof(void*), hash);
@@ -337,6 +339,10 @@ equals_gfx_pipeline_state(const void *a, const void *b)
           memcmp(sa->depth_stencil_alpha_state, sb->depth_stencil_alpha_state, sizeof(struct zink_depth_stencil_alpha_hw_state)))
          return false;
    }
+   if (!sa->have_EXT_extended_dynamic_state2) {
+      if (sa->primitive_restart != sb->primitive_restart)
+         return false;
+   }
    return !memcmp(sa->modules, sb->modules, sizeof(sa->modules)) &&
           !memcmp(a, b, offsetof(struct zink_gfx_pipeline_state, hash));
 }