From d3ab5b68d5eb9a4980a8f3cf7a137bc036bfa6ee Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Tue, 9 May 2023 15:16:17 +0200 Subject: [PATCH] tu: Remove MSAA draw state We only need to emit MSAA state once per subpass at most, unless the pipeline switches primitive types or for framebuffer-less subpasses (which always use sysmem anyway). Therefore it seems like draw state skipping isn't going to bring much benefit here, and having it as a draw state in the first place is a remnant of how this used to be part of the pipeline state. Part-of: --- src/freedreno/vulkan/tu_cmd_buffer.cc | 24 +++++++++++++++--------- src/freedreno/vulkan/tu_cmd_buffer.h | 2 -- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/freedreno/vulkan/tu_cmd_buffer.cc b/src/freedreno/vulkan/tu_cmd_buffer.cc index e3cfaca..54c747c 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.cc +++ b/src/freedreno/vulkan/tu_cmd_buffer.cc @@ -718,15 +718,16 @@ tu6_emit_msaa(struct tu_cs *cs, VkSampleCountFlagBits vk_samples, static void tu6_update_msaa(struct tu_cmd_buffer *cmd) { - struct tu_cs cs; + VkSampleCountFlagBits samples = + cmd->vk.dynamic_graphics_state.ms.rasterization_samples;; - cmd->state.msaa = tu_cs_draw_state(&cmd->sub_cs, &cs, 9); - tu6_emit_msaa(&cs, cmd->vk.dynamic_graphics_state.ms.rasterization_samples, - cmd->state.msaa_disable); - if (!(cmd->state.dirty & TU_CMD_DIRTY_DRAW_STATE)) { - tu_cs_emit_pkt7(&cmd->draw_cs, CP_SET_DRAW_STATE, 3); - tu_cs_emit_draw_state(&cmd->draw_cs, TU_DRAW_STATE_MSAA, cmd->state.msaa); - } + /* The samples may not be set by the pipeline or dynamically if raster + * discard is enabled. We can set any valid value, but don't set the + * default invalid value of 0. + */ + if (samples == 0) + samples = VK_SAMPLE_COUNT_1_BIT; + tu6_emit_msaa(&cmd->draw_cs, samples, cmd->state.msaa_disable); } static void @@ -1585,6 +1586,12 @@ tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd) */ if (cmd->state.pass->has_fdm) cmd->state.dirty |= TU_CMD_DIRTY_FDM; + + /* We need to re-emit MSAA at the beginning of every renderpass because it + * isn't part of a draw state that gets automatically re-emitted. + */ + BITSET_SET(cmd->vk.dynamic_graphics_state.dirty, + MESA_VK_DYNAMIC_MS_RASTERIZATION_SAMPLES); } template @@ -4703,7 +4710,6 @@ tu6_draw_common(struct tu_cmd_buffer *cmd, tu_cs_emit_draw_state(cs, TU_DRAW_STATE_VS_PARAMS, cmd->state.vs_params); tu_cs_emit_draw_state(cs, TU_DRAW_STATE_FS_PARAMS, cmd->state.fs_params); tu_cs_emit_draw_state(cs, TU_DRAW_STATE_LRZ_AND_DEPTH_PLANE, cmd->state.lrz_and_depth_plane_state); - tu_cs_emit_draw_state(cs, TU_DRAW_STATE_MSAA, cmd->state.msaa); for (uint32_t i = 0; i < ARRAY_SIZE(cmd->state.dynamic_state); i++) { tu_cs_emit_draw_state(cs, TU_DRAW_STATE_DYNAMIC + i, diff --git a/src/freedreno/vulkan/tu_cmd_buffer.h b/src/freedreno/vulkan/tu_cmd_buffer.h index 52d8cc4..50a1dbb 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.h +++ b/src/freedreno/vulkan/tu_cmd_buffer.h @@ -35,7 +35,6 @@ enum tu_draw_state_group_id TU_DRAW_STATE_LRZ_AND_DEPTH_PLANE, TU_DRAW_STATE_PRIM_MODE_GMEM, TU_DRAW_STATE_PRIM_MODE_SYSMEM, - TU_DRAW_STATE_MSAA, /* dynamic state related draw states */ TU_DRAW_STATE_DYNAMIC, @@ -409,7 +408,6 @@ struct tu_cmd_state struct tu_draw_state vertex_buffers; struct tu_draw_state shader_const; struct tu_draw_state desc_sets; - struct tu_draw_state msaa; struct tu_draw_state vs_params; struct tu_draw_state fs_params; -- 2.7.4