From: Jonathan Marek Date: Mon, 24 Feb 2020 14:40:56 +0000 (-0500) Subject: turnip: make cond_exec helper easier to use X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a410e64b6812b23e1db8b969516ae7f4ebb8b811;p=mesa.git turnip: make cond_exec helper easier to use Signed-off-by: Jonathan Marek Reviewed-by: Eric Anholt Part-of: --- diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index 4f9f19bfd77..581edfa34a7 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -922,24 +922,14 @@ tu6_emit_predicated_blit(struct tu_cmd_buffer *cmd, uint32_t gmem_a, bool resolve) { - const uint32_t space = 14 + 6; - struct tu_cond_exec_state state; - - VkResult result = tu_cond_exec_start(cmd->device, cs, &state, - CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | - CP_COND_REG_EXEC_0_GMEM, - space); - if (result != VK_SUCCESS) { - cmd->record_result = result; - return; - } + tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_GMEM); tu6_emit_blit_info(cmd, cs, cmd->state.framebuffer->attachments[a].attachment, cmd->state.pass->attachments[gmem_a].gmem_offset, resolve); tu6_emit_blit(cmd, cs); - tu_cond_exec_end(cs, &state); + tu_cond_exec_end(cs); } static void @@ -973,21 +963,9 @@ static void tu6_emit_resolve(struct tu_cmd_buffer *cmd, tu6_emit_predicated_blit(cmd, cs, a, gmem_a, true); - const struct tu_framebuffer *fb = cmd->state.framebuffer; - const uint32_t space = 25 + 66 * fb->layers + 17; - struct tu_cond_exec_state state; - - VkResult result = tu_cond_exec_start(cmd->device, cs, &state, - CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | - CP_COND_REG_EXEC_0_SYSMEM, - space); - if (result != VK_SUCCESS) { - cmd->record_result = result; - return; - } - + tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM); tu6_emit_sysmem_resolve(cmd, cs, a, gmem_a); - tu_cond_exec_end(cs, &state); + tu_cond_exec_end(cs); } static void diff --git a/src/freedreno/vulkan/tu_cs.c b/src/freedreno/vulkan/tu_cs.c index 072a52cbd3c..16d49838ba8 100644 --- a/src/freedreno/vulkan/tu_cs.c +++ b/src/freedreno/vulkan/tu_cs.c @@ -364,12 +364,33 @@ tu_cs_reserve_space(struct tu_cs *cs, uint32_t reserved_size) tu_cs_add_entry(cs); } + if (cs->cond_flags) { + /* Subtract one here to account for the DWORD field itself. */ + *cs->cond_dwords = cs->cur - cs->cond_dwords - 1; + + /* space for CP_COND_REG_EXEC in next bo */ + reserved_size += 3; + } + /* switch to a new BO */ uint32_t new_size = MAX2(cs->next_bo_size, reserved_size); VkResult result = tu_cs_add_bo(cs, new_size); if (result != VK_SUCCESS) return result; + /* if inside a condition, emit a new CP_COND_REG_EXEC */ + if (cs->cond_flags) { + cs->reserved_end = cs->cur + reserved_size; + + tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2); + tu_cs_emit(cs, cs->cond_flags); + + cs->cond_dwords = cs->cur; + + /* Emit dummy DWORD field here */ + tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0)); + } + /* double the size for the next bo */ new_size <<= 1; if (cs->next_bo_size < new_size) diff --git a/src/freedreno/vulkan/tu_cs.h b/src/freedreno/vulkan/tu_cs.h index f5c331cdd30..29baca74faf 100644 --- a/src/freedreno/vulkan/tu_cs.h +++ b/src/freedreno/vulkan/tu_cs.h @@ -238,41 +238,34 @@ tu_cs_emit_call(struct tu_cs *cs, const struct tu_cs *target) /* Helpers for bracketing a large sequence of commands of unknown size inside * a CP_COND_REG_EXEC packet. */ - -struct tu_cond_exec_state { - uint32_t *dword_ptr; - uint32_t max_dwords; -}; - -static inline VkResult -tu_cond_exec_start(struct tu_device *dev, struct tu_cs *cs, - struct tu_cond_exec_state *state, - uint32_t condition, uint32_t max_dwords) +static inline void +tu_cond_exec_start(struct tu_cs *cs, uint32_t cond_flags) { - /* Reserve enough space so that both the condition packet and the actual - * condition will fit in the same IB. - */ - VkResult result = tu_cs_reserve_space(cs, max_dwords + 3); - if (result != VK_SUCCESS) - return result; + assert(cs->mode == TU_CS_MODE_GROW); + assert(!cs->cond_flags && cond_flags); - state->max_dwords = max_dwords; tu_cs_emit_pkt7(cs, CP_COND_REG_EXEC, 2); - tu_cs_emit(cs, condition); - state->dword_ptr = cs->cur; + tu_cs_emit(cs, cond_flags); + + cs->cond_flags = cond_flags; + cs->cond_dwords = cs->cur; + /* Emit dummy DWORD field here */ tu_cs_emit(cs, CP_COND_REG_EXEC_1_DWORDS(0)); - - return VK_SUCCESS; } +#define CP_COND_EXEC_0_RENDER_MODE_GMEM \ + (CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | CP_COND_REG_EXEC_0_GMEM) +#define CP_COND_EXEC_0_RENDER_MODE_SYSMEM \ + (CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | CP_COND_REG_EXEC_0_SYSMEM) static inline void -tu_cond_exec_end(struct tu_cs *cs, struct tu_cond_exec_state *state) +tu_cond_exec_end(struct tu_cs *cs) { + assert(cs->cond_flags); + + cs->cond_flags = 0; /* Subtract one here to account for the DWORD field itself. */ - uint32_t actual_dwords = cs->cur - state->dword_ptr - 1; - assert(actual_dwords <= state->max_dwords); - *state->dword_ptr = actual_dwords; + *cs->cond_dwords = cs->cur - cs->cond_dwords - 1; } #define fd_reg_pair tu_reg_value diff --git a/src/freedreno/vulkan/tu_meta_clear.c b/src/freedreno/vulkan/tu_meta_clear.c index 7d24c737cc7..1454afe68f2 100644 --- a/src/freedreno/vulkan/tu_meta_clear.c +++ b/src/freedreno/vulkan/tu_meta_clear.c @@ -171,19 +171,7 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer, const struct tu_subpass *subpass = cmd->state.subpass; struct tu_cs *cs = &cmd->draw_cs; - /* Note: reserving space here should never fail because we allocated - * enough above. - */ - struct tu_cond_exec_state state; - VkResult result = - tu_cond_exec_start(cmd->device, cs, &state, - CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | - CP_COND_REG_EXEC_0_GMEM, - rectCount * (3 + attachmentCount * 15)); - if (result != VK_SUCCESS) { - cmd->record_result = result; - return; - } + tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_GMEM); for (unsigned i = 0; i < rectCount; i++) { unsigned x1 = pRects[i].rect.offset.x; @@ -218,22 +206,9 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer, } } - tu_cond_exec_end(cs, &state); - - uint32_t clear_count = 3; - for (unsigned j = 0; j < rectCount; j++) - clear_count += 18 + 66 * pRects[j].layerCount + 17; + tu_cond_exec_end(cs); - result = - tu_cond_exec_start(cmd->device, cs, &state, - CP_COND_REG_EXEC_0_MODE(RENDER_MODE) | - CP_COND_REG_EXEC_0_SYSMEM, - attachmentCount * clear_count); - - if (result != VK_SUCCESS) { - cmd->record_result = result; - return; - } + tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM); for (unsigned i = 0; i < rectCount; i++) { for (unsigned j = 0; j < attachmentCount; j++) { @@ -261,5 +236,5 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer, } } - tu_cond_exec_end(cs, &state); + tu_cond_exec_end(cs); } diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index 5268586349e..a7b1f76da37 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -580,6 +580,10 @@ struct tu_cs struct tu_bo **bos; uint32_t bo_count; uint32_t bo_capacity; + + /* state for cond_exec_start/cond_exec_end */ + uint32_t cond_flags; + uint32_t *cond_dwords; }; struct tu_device_memory