From f4ce783f0e9d352af3098019fa8aac46e9bed297 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 23 Apr 2024 10:33:54 +0200 Subject: [PATCH] panvk: Fully transition to vk_viewport_state Pre-emitting viewport descriptors at pipeline creation time makes things more complex for little savings. Be dumb and emit viewport at draw time based on the current command buffer dynamic state. Signed-off-by: Boris Brezillon Reviewed-by: Mary Guillemard Acked-by: Erik Faye-Lund Part-of: --- src/panfrost/vulkan/panvk_cmd_buffer.h | 4 -- src/panfrost/vulkan/panvk_pipeline.h | 6 -- src/panfrost/vulkan/panvk_vX_cmd_buffer.c | 77 ++++++----------------- src/panfrost/vulkan/panvk_vX_pipeline.c | 35 ----------- 4 files changed, 18 insertions(+), 104 deletions(-) diff --git a/src/panfrost/vulkan/panvk_cmd_buffer.h b/src/panfrost/vulkan/panvk_cmd_buffer.h index 9e8aea9abc6..7d2fd5c2dad 100644 --- a/src/panfrost/vulkan/panvk_cmd_buffer.h +++ b/src/panfrost/vulkan/panvk_cmd_buffer.h @@ -73,8 +73,6 @@ struct panvk_cmd_event_op { }; enum panvk_dynamic_state_bits { - PANVK_DYNAMIC_VIEWPORT = 1 << 0, - PANVK_DYNAMIC_SCISSOR = 1 << 1, PANVK_DYNAMIC_LINE_WIDTH = 1 << 2, PANVK_DYNAMIC_DEPTH_BIAS = 1 << 3, PANVK_DYNAMIC_BLEND_CONSTANTS = 1 << 4, @@ -167,8 +165,6 @@ struct panvk_cmd_graphics_state { } fb; mali_ptr vpd; - VkViewport viewport; - VkRect2D scissor; }; struct panvk_cmd_compute_state { diff --git a/src/panfrost/vulkan/panvk_pipeline.h b/src/panfrost/vulkan/panvk_pipeline.h index e39d126ae51..33bf4b293ae 100644 --- a/src/panfrost/vulkan/panvk_pipeline.h +++ b/src/panfrost/vulkan/panvk_pipeline.h @@ -147,12 +147,6 @@ struct panvk_graphics_pipeline { bool reads_dest; } blend; - struct { - uint64_t vpd; - VkViewport viewport; - VkRect2D scissor; - } vp; - struct vk_dynamic_graphics_state dynamic; struct vk_vertex_input_state vi; struct vk_sample_locations_state sl; diff --git a/src/panfrost/vulkan/panvk_vX_cmd_buffer.c b/src/panfrost/vulkan/panvk_vX_cmd_buffer.c index 456b3adddf2..ff48cc0074c 100644 --- a/src/panfrost/vulkan/panvk_vX_cmd_buffer.c +++ b/src/panfrost/vulkan/panvk_vX_cmd_buffer.c @@ -256,6 +256,14 @@ panvk_per_arch(cmd_alloc_tls_desc)(struct panvk_cmd_buffer *cmdbuf, bool gfx) } } +#define is_dirty(__cmdbuf, __name) \ + BITSET_TEST((__cmdbuf)->vk.dynamic_graphics_state.dirty, \ + MESA_VK_DYNAMIC_##__name) + +#define set_dirty(__cmdbuf, __nm) \ + BITSET_SET((__cmdbuf)->vk.dynamic_graphics_state.dirty, \ + MESA_VK_DYNAMIC_##__name) + static void panvk_cmd_prepare_draw_sysvals(struct panvk_cmd_buffer *cmdbuf, struct panvk_draw_info *draw) @@ -279,8 +287,8 @@ panvk_cmd_prepare_draw_sysvals(struct panvk_cmd_buffer *cmdbuf, desc_state->push_uniforms = 0; } - if (cmdbuf->state.gfx.dirty & PANVK_DYNAMIC_VIEWPORT) { - VkViewport *viewport = &cmdbuf->state.gfx.viewport; + if (is_dirty(cmdbuf, VP_VIEWPORTS)) { + VkViewport *viewport = &cmdbuf->vk.dynamic_graphics_state.vp.viewports[0]; /* Upload the viewport scale. Defined as (px/2, py/2, pz) at the start of * section 24.5 ("Controlling the Viewport") of the Vulkan spec. At the @@ -1024,28 +1032,19 @@ static void panvk_draw_prepare_viewport(struct panvk_cmd_buffer *cmdbuf, struct panvk_draw_info *draw) { - const struct panvk_graphics_pipeline *pipeline = cmdbuf->state.gfx.pipeline; - - if (pipeline->state.vp.vpd) { - draw->viewport = pipeline->state.vp.vpd; - } else if (cmdbuf->state.gfx.vpd) { - draw->viewport = cmdbuf->state.gfx.vpd; - } else { + if (is_dirty(cmdbuf, VP_VIEWPORTS) || is_dirty(cmdbuf, VP_SCISSORS)) { + const VkViewport *viewport = + &cmdbuf->vk.dynamic_graphics_state.vp.viewports[0]; + const VkRect2D *scissor = + &cmdbuf->vk.dynamic_graphics_state.vp.scissors[0]; struct panfrost_ptr vp = pan_pool_alloc_desc(&cmdbuf->desc_pool.base, VIEWPORT); - const VkViewport *viewport = - pipeline->state.dynamic_mask & PANVK_DYNAMIC_VIEWPORT - ? &cmdbuf->state.gfx.viewport - : &pipeline->state.vp.viewport; - const VkRect2D *scissor = - pipeline->state.dynamic_mask & PANVK_DYNAMIC_SCISSOR - ? &cmdbuf->state.gfx.scissor - : &pipeline->state.vp.scissor; - panvk_per_arch(emit_viewport)(viewport, scissor, vp.cpu); - draw->viewport = cmdbuf->state.gfx.vpd = vp.gpu; + cmdbuf->state.gfx.vpd = vp.gpu; } + + draw->viewport = cmdbuf->state.gfx.vpd; } static void @@ -2131,18 +2130,6 @@ panvk_per_arch(CmdBindPipeline)(VkCommandBuffer commandBuffer, cmdbuf->state.gfx.fs_rsd = 0; cmdbuf->state.gfx.varyings = gfx_pipeline->varyings; - - if (!(gfx_pipeline->state.dynamic_mask & - BITFIELD_BIT(VK_DYNAMIC_STATE_VIEWPORT))) { - cmdbuf->state.gfx.viewport = gfx_pipeline->state.vp.viewport; - cmdbuf->state.gfx.dirty |= PANVK_DYNAMIC_VIEWPORT; - } - if (!(gfx_pipeline->state.dynamic_mask & - BITFIELD_BIT(VK_DYNAMIC_STATE_SCISSOR))) { - cmdbuf->state.gfx.scissor = gfx_pipeline->state.vp.scissor; - cmdbuf->state.gfx.dirty |= PANVK_DYNAMIC_SCISSOR; - } - cmdbuf->state.gfx.pipeline = gfx_pipeline; break; } @@ -2158,34 +2145,6 @@ panvk_per_arch(CmdBindPipeline)(VkCommandBuffer commandBuffer, } } -VKAPI_ATTR void VKAPI_CALL -panvk_per_arch(CmdSetViewport)(VkCommandBuffer commandBuffer, - uint32_t firstViewport, uint32_t viewportCount, - const VkViewport *pViewports) -{ - VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); - assert(viewportCount == 1); - assert(!firstViewport); - - cmdbuf->state.gfx.viewport = pViewports[0]; - cmdbuf->state.gfx.vpd = 0; - cmdbuf->state.gfx.dirty |= PANVK_DYNAMIC_VIEWPORT; -} - -VKAPI_ATTR void VKAPI_CALL -panvk_per_arch(CmdSetScissor)(VkCommandBuffer commandBuffer, - uint32_t firstScissor, uint32_t scissorCount, - const VkRect2D *pScissors) -{ - VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); - assert(scissorCount == 1); - assert(!firstScissor); - - cmdbuf->state.gfx.scissor = pScissors[0]; - cmdbuf->state.gfx.vpd = 0; - cmdbuf->state.gfx.dirty |= PANVK_DYNAMIC_SCISSOR; -} - VKAPI_ATTR void VKAPI_CALL panvk_per_arch(CmdSetLineWidth)(VkCommandBuffer commandBuffer, float lineWidth) { diff --git a/src/panfrost/vulkan/panvk_vX_pipeline.c b/src/panfrost/vulkan/panvk_vX_pipeline.c index d18c016e673..7032e942230 100644 --- a/src/panfrost/vulkan/panvk_vX_pipeline.c +++ b/src/panfrost/vulkan/panvk_vX_pipeline.c @@ -398,36 +398,6 @@ init_shaders(struct panvk_pipeline *pipeline, } } -static void -parse_viewport(struct panvk_graphics_pipeline *pipeline, - const struct vk_graphics_pipeline_state *state) -{ - const struct vk_rasterization_state *rs = state->rs; - const struct vk_viewport_state *vp = state->vp; - - /* The spec says: - * - * pViewportState is a pointer to an instance of the - * VkPipelineViewportStateCreateInfo structure, and is ignored if the - * pipeline has rasterization disabled. - */ - if (!rs->rasterizer_discard_enable && - dyn_state_is_set(pipeline, MESA_VK_DYNAMIC_VP_VIEWPORTS) && - dyn_state_is_set(pipeline, MESA_VK_DYNAMIC_VP_SCISSORS)) { - struct panfrost_ptr vpd = - pan_pool_alloc_desc(&pipeline->base.desc_pool.base, VIEWPORT); - - panvk_per_arch(emit_viewport)(vp->viewports, vp->scissors, vpd.cpu); - pipeline->state.vp.vpd = vpd.gpu; - } - - if (dyn_state_is_set(pipeline, MESA_VK_DYNAMIC_VP_VIEWPORTS)) - pipeline->state.vp.viewport = vp->viewports[0]; - - if (dyn_state_is_set(pipeline, MESA_VK_DYNAMIC_VP_SCISSORS)) - pipeline->state.vp.scissor = vp->scissors[0]; -} - #define is_dyn(__state, __name) \ BITSET_TEST((__state)->dynamic, MESA_VK_DYNAMIC_##__name) @@ -435,10 +405,6 @@ static void parse_dynamic_state(struct panvk_graphics_pipeline *pipeline, const struct vk_graphics_pipeline_state *state) { - if (is_dyn(state, VP_VIEWPORTS)) - pipeline->state.dynamic_mask |= PANVK_DYNAMIC_VIEWPORT; - if (is_dyn(state, VP_SCISSORS)) - pipeline->state.dynamic_mask |= PANVK_DYNAMIC_SCISSOR; if (is_dyn(state, RS_LINE_WIDTH)) pipeline->state.dynamic_mask |= PANVK_DYNAMIC_LINE_WIDTH; if (is_dyn(state, RS_DEPTH_BIAS_FACTORS)) @@ -920,7 +886,6 @@ panvk_graphics_pipeline_create(struct panvk_device *dev, parse_vertex_input(gfx_pipeline, &state, shaders); init_fs_state(gfx_pipeline, &state, shaders[MESA_SHADER_FRAGMENT]); init_shaders(&gfx_pipeline->base, create_info, shaders); - parse_viewport(gfx_pipeline, &state); release_shaders(&gfx_pipeline->base, shaders, alloc); return VK_SUCCESS;