From 9c39185e208f0c57dfc54b809f72745271ab3d54 Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Thu, 13 Jun 2024 09:04:09 +0200 Subject: [PATCH] panvk: Upload render state in panvk_shader Signed-off-by: Mary Guillemard Part-of: --- src/panfrost/vulkan/bifrost/panvk_pipeline.h | 1 - .../vulkan/bifrost/panvk_vX_pipeline.c | 11 --------- .../vulkan/jm/panvk_vX_cmd_dispatch.c | 11 ++++++--- src/panfrost/vulkan/jm/panvk_vX_cmd_draw.c | 6 ++++- src/panfrost/vulkan/panvk_shader.h | 1 + src/panfrost/vulkan/panvk_vX_shader.c | 23 +++++++++++++++---- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/panfrost/vulkan/bifrost/panvk_pipeline.h b/src/panfrost/vulkan/bifrost/panvk_pipeline.h index 9722b5b0901..0eebb0b0dc0 100644 --- a/src/panfrost/vulkan/bifrost/panvk_pipeline.h +++ b/src/panfrost/vulkan/bifrost/panvk_pipeline.h @@ -28,7 +28,6 @@ struct panvk_pipeline_shader { struct panvk_shader *base; - struct panvk_priv_mem rsd; struct { struct panvk_priv_mem attribs; diff --git a/src/panfrost/vulkan/bifrost/panvk_vX_pipeline.c b/src/panfrost/vulkan/bifrost/panvk_vX_pipeline.c index 0f4286f24ae..81b5c78d2ad 100644 --- a/src/panfrost/vulkan/bifrost/panvk_vX_pipeline.c +++ b/src/panfrost/vulkan/bifrost/panvk_vX_pipeline.c @@ -75,15 +75,6 @@ init_pipeline_shader(struct panvk_pipeline *pipeline, compute_pipeline->local_size = shader->local_size; } - if (stage_info->stage != VK_SHADER_STAGE_FRAGMENT_BIT) { - pshader->rsd = panvk_pool_alloc_desc(&dev->mempools.rw, RENDERER_STATE); - - pan_pack(panvk_priv_mem_host_addr(pshader->rsd), RENDERER_STATE, cfg) { - pan_shader_prepare_rsd(&pshader->info, - panvk_shader_get_dev_addr(pshader->base), &cfg); - } - } - return VK_SUCCESS; } @@ -94,8 +85,6 @@ cleanup_pipeline_shader(struct panvk_pipeline *pipeline, { struct panvk_device *dev = to_panvk_device(pipeline->base.device); - panvk_pool_free_mem(&dev->mempools.rw, pshader->rsd); - if (pshader->base != NULL) panvk_per_arch(shader_destroy)(dev, pshader->base, alloc); } diff --git a/src/panfrost/vulkan/jm/panvk_vX_cmd_dispatch.c b/src/panfrost/vulkan/jm/panvk_vX_cmd_dispatch.c index cb42cf410a1..36ad0898fae 100644 --- a/src/panfrost/vulkan/jm/panvk_vX_cmd_dispatch.c +++ b/src/panfrost/vulkan/jm/panvk_vX_cmd_dispatch.c @@ -36,6 +36,13 @@ panvk_per_arch(CmdDispatch)(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) { VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); + const struct panvk_compute_pipeline *pipeline = + cmdbuf->state.compute.pipeline; + + /* If there's no compute shader, we can skip the dispatch. */ + if (!panvk_priv_mem_dev_addr(pipeline->cs.base->rsd)) + return; + struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); struct panvk_physical_device *phys_dev = to_panvk_physical_device(dev->vk.physical); @@ -50,8 +57,6 @@ panvk_per_arch(CmdDispatch)(VkCommandBuffer commandBuffer, uint32_t x, &cmdbuf->state.compute.desc_state; struct panvk_shader_desc_state *cs_desc_state = &cmdbuf->state.compute.cs.desc; - const struct panvk_compute_pipeline *pipeline = - cmdbuf->state.compute.pipeline; panvk_per_arch(cmd_alloc_tls_desc)(cmdbuf, false); dispatch.tsd = batch->tls.gpu; @@ -111,7 +116,7 @@ panvk_per_arch(CmdDispatch)(VkCommandBuffer commandBuffer, uint32_t x, } pan_section_pack(job.cpu, COMPUTE_JOB, DRAW, cfg) { - cfg.state = panvk_priv_mem_dev_addr(pipeline->cs.rsd); + cfg.state = panvk_priv_mem_dev_addr(pipeline->cs.base->rsd); cfg.attributes = cs_desc_state->img_attrib_table; cfg.attribute_buffers = cs_desc_state->tables[PANVK_BIFROST_DESC_TABLE_IMG]; diff --git a/src/panfrost/vulkan/jm/panvk_vX_cmd_draw.c b/src/panfrost/vulkan/jm/panvk_vX_cmd_draw.c index cdbf9f51d17..0c4702aed41 100644 --- a/src/panfrost/vulkan/jm/panvk_vX_cmd_draw.c +++ b/src/panfrost/vulkan/jm/panvk_vX_cmd_draw.c @@ -806,7 +806,7 @@ panvk_draw_prepare_vertex_job(struct panvk_cmd_buffer *cmdbuf, } pan_section_pack(ptr.cpu, COMPUTE_JOB, DRAW, cfg) { - cfg.state = panvk_priv_mem_dev_addr(pipeline->vs.rsd); + cfg.state = panvk_priv_mem_dev_addr(pipeline->vs.base->rsd); cfg.attributes = draw->vs.attributes; cfg.attribute_buffers = draw->vs.attribute_bufs; cfg.varyings = draw->vs.varyings; @@ -1043,6 +1043,10 @@ panvk_cmd_draw(struct panvk_cmd_buffer *cmdbuf, struct panvk_draw_info *draw) const struct vk_rasterization_state *rs = &cmdbuf->vk.dynamic_graphics_state.rs; + /* If there's no vertex shader, we can skip the draw. */ + if (!panvk_priv_mem_dev_addr(pipeline->vs.base->rsd)) + return; + /* There are only 16 bits in the descriptor for the job ID. Each job has a * pilot shader dealing with descriptor copies, and we need one * pair per draw. diff --git a/src/panfrost/vulkan/panvk_shader.h b/src/panfrost/vulkan/panvk_shader.h index 16ee3a8a8e0..67f53c082c0 100644 --- a/src/panfrost/vulkan/panvk_shader.h +++ b/src/panfrost/vulkan/panvk_shader.h @@ -123,6 +123,7 @@ struct panvk_shader { uint32_t bin_size; struct panvk_priv_mem code_mem; + struct panvk_priv_mem rsd; }; static inline mali_ptr diff --git a/src/panfrost/vulkan/panvk_vX_shader.c b/src/panfrost/vulkan/panvk_vX_shader.c index cc632581eb0..93b25095682 100644 --- a/src/panfrost/vulkan/panvk_vX_shader.c +++ b/src/panfrost/vulkan/panvk_vX_shader.c @@ -140,11 +140,23 @@ static VkResult panvk_shader_upload(struct panvk_device *dev, struct panvk_shader *shader, const VkAllocationCallbacks *pAllocator) { - if (shader->bin_size > 0) { - shader->code_mem = panvk_pool_upload_aligned( - &dev->mempools.exec, shader->bin_ptr, shader->bin_size, 128); - } else { - shader->code_mem = (struct panvk_priv_mem){0}; + shader->code_mem = (struct panvk_priv_mem){0}; + shader->rsd = (struct panvk_priv_mem){0}; + + if (!shader->bin_size) + return VK_SUCCESS; + + shader->code_mem = panvk_pool_upload_aligned( + &dev->mempools.exec, shader->bin_ptr, shader->bin_size, 128); + + if (shader->info.stage == MESA_SHADER_FRAGMENT) + return VK_SUCCESS; + + shader->rsd = panvk_pool_alloc_desc(&dev->mempools.rw, RENDERER_STATE); + + pan_pack(panvk_priv_mem_host_addr(shader->rsd), RENDERER_STATE, cfg) { + pan_shader_prepare_rsd(&shader->info, panvk_shader_get_dev_addr(shader), + &cfg); } return VK_SUCCESS; @@ -394,6 +406,7 @@ panvk_per_arch(shader_destroy)(struct panvk_device *dev, struct panvk_shader *shader, const VkAllocationCallbacks *alloc) { + panvk_pool_free_mem(&dev->mempools.rw, shader->rsd); panvk_pool_free_mem(&dev->mempools.rw, shader->desc_info.others.map); panvk_pool_free_mem(&dev->mempools.exec, shader->code_mem);