radv: only initialize non-zero values for the default dynamic state
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 27 Jan 2023 17:34:48 +0000 (18:34 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 31 Jan 2023 09:01:48 +0000 (09:01 +0000)
This avoids a big memcpy and cut the function time by 2x.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20960>

src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_private.h

index 0b37121..53c828d 100644 (file)
@@ -65,98 +65,6 @@ static void radv_handle_image_transition(struct radv_cmd_buffer *cmd_buffer,
 
 static void radv_set_rt_stack_size(struct radv_cmd_buffer *cmd_buffer, uint32_t size);
 
-const struct radv_dynamic_state default_dynamic_state = {
-   .vk =
-      {
-         .ia =
-            {
-               .primitive_topology = 0u,
-               .primitive_restart_enable = 0u,
-            },
-         .vp =
-            {
-               .depth_clip_negative_one_to_one = 0u,
-               .viewport_count = 0,
-               .scissor_count = 0,
-            },
-         .ts =
-            {
-               .patch_control_points = 0,
-               .domain_origin = VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT,
-            },
-         .rs =
-            {
-               .rasterizer_discard_enable = 0u,
-               .depth_clamp_enable = 0u,
-               .depth_clip_enable = 0u,
-               .depth_bias =
-                  {
-                     .enable = 0,
-                     .constant = 0.0f,
-                     .clamp = 0.0f,
-                     .slope = 0.0f,
-                  },
-               .polygon_mode = 0,
-               .cull_mode = 0,
-               .front_face = 0u,
-               .conservative_mode = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT,
-               .provoking_vertex = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT,
-               .line =
-                  {
-                     .width = 1.0f,
-                     .mode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT,
-                     .stipple =
-                        {
-                           .enable = 0u,
-                           .factor = 0u,
-                           .pattern = 0u,
-                        },
-                  },
-            },
-         .fsr =
-            {
-               .fragment_size = {1u, 1u},
-               .combiner_ops = {VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR,
-                                VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR},
-            },
-         .ds =
-            {
-               .depth =
-                  {
-                     .bounds_test =
-                        {
-                           .min = 0.0f,
-                           .max = 1.0f,
-                        },
-                  },
-               .stencil =
-                  {
-                     .front =
-                        {
-                           .reference = 0u,
-                           .compare_mask = ~0,
-                           .write_mask = ~0,
-                        },
-                     .back =
-                        {
-                           .reference = 0u,
-                           .compare_mask = ~0,
-                           .write_mask = ~0,
-                        },
-                  },
-            },
-         .ms = {
-            .rasterization_samples = VK_SAMPLE_COUNT_1_BIT,
-            .alpha_to_coverage_enable = 0u,
-            .sample_mask = 0u,
-         },
-         .cb = {
-            .logic_op_enable = 0u,
-            .blend_constants = {0.0f, 0.0f, 0.0f, 0.0f},
-         },
-      },
-};
-
 static void
 radv_bind_dynamic_state(struct radv_cmd_buffer *cmd_buffer, const struct radv_dynamic_state *src)
 {
index b931cb0..8c6b400 100644 (file)
@@ -1040,15 +1040,24 @@ radv_pipeline_init_dynamic_state(struct radv_graphics_pipeline *pipeline,
                                  const struct vk_graphics_pipeline_state *state)
 {
    uint64_t needed_states = radv_pipeline_needed_dynamic_state(pipeline, state);
+   struct radv_dynamic_state *dynamic = &pipeline->dynamic_state;
    uint64_t states = needed_states;
 
-   pipeline->dynamic_state = default_dynamic_state;
+   /* Initialize non-zero values for default dynamic state. */
+   dynamic->vk.rs.line.width = 1.0f;
+   dynamic->vk.fsr.fragment_size.width = 1u;
+   dynamic->vk.fsr.fragment_size.height = 1u;
+   dynamic->vk.ds.depth.bounds_test.max = 1.0f;
+   dynamic->vk.ds.stencil.front.compare_mask = ~0;
+   dynamic->vk.ds.stencil.front.write_mask = ~0;
+   dynamic->vk.ds.stencil.back.compare_mask = ~0;
+   dynamic->vk.ds.stencil.back.write_mask = ~0;
+   dynamic->vk.ms.rasterization_samples = VK_SAMPLE_COUNT_1_BIT;
+
    pipeline->needed_dynamic_state = needed_states;
 
    states &= ~pipeline->dynamic_states;
 
-   struct radv_dynamic_state *dynamic = &pipeline->dynamic_state;
-
    /* Input assembly. */
    if (states & RADV_DYNAMIC_PRIMITIVE_TOPOLOGY) {
       dynamic->vk.ia.primitive_topology = si_translate_prim(state->ia->primitive_topology);
index c629709..1401853 100644 (file)
@@ -1362,8 +1362,6 @@ struct radv_dynamic_state {
    struct radv_sample_locations_state sample_location;
 };
 
-extern const struct radv_dynamic_state default_dynamic_state;
-
 const char *radv_get_debug_option_name(int id);
 
 const char *radv_get_perftest_option_name(int id);