| 1 |
/* |
| 2 |
* Copyright © 2024 Collabora Ltd. |
| 3 |
* |
| 4 |
* Derived from tu_cmd_buffer.c which is: |
| 5 |
* Copyright © 2016 Red Hat. |
| 6 |
* Copyright © 2016 Bas Nieuwenhuizen |
| 7 |
* Copyright © 2015 Intel Corporation |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: MIT |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "panvk_cmd_buffer.h" |
| 13 |
#include "panvk_entrypoints.h" |
| 14 |
#include "panvk_event.h" |
| 15 |
#include "panvk_meta.h" |
| 16 |
|
| 17 |
#include "util/u_dynarray.h" |
| 18 |
|
| 19 |
static void |
| 20 |
panvk_add_set_event_operation(struct panvk_cmd_buffer *cmdbuf, |
| 21 |
struct panvk_event *event, |
| 22 |
enum panvk_cmd_event_op_type type) |
| 23 |
{ |
| 24 |
struct panvk_cmd_event_op op = { |
| 25 |
.type = type, |
| 26 |
.event = event, |
| 27 |
}; |
| 28 |
|
| 29 |
if (cmdbuf->cur_batch == NULL) { |
| 30 |
/* No open batch, let's create a new one so this operation happens in |
| 31 |
* the right order. |
| 32 |
*/ |
| 33 |
panvk_per_arch(cmd_open_batch)(cmdbuf); |
| 34 |
util_dynarray_append(&cmdbuf->cur_batch->event_ops, op); |
| 35 |
panvk_per_arch(cmd_close_batch)(cmdbuf); |
| 36 |
} else { |
| 37 |
/* Let's close the current batch so the operation executes before any |
| 38 |
* future commands. |
| 39 |
*/ |
| 40 |
util_dynarray_append(&cmdbuf->cur_batch->event_ops, op); |
| 41 |
panvk_per_arch(cmd_close_batch)(cmdbuf); |
| 42 |
panvk_per_arch(cmd_open_batch)(cmdbuf); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
panvk_add_wait_event_operation(struct panvk_cmd_buffer *cmdbuf, |
| 48 |
struct panvk_event *event) |
| 49 |
{ |
| 50 |
struct panvk_cmd_event_op op = { |
| 51 |
.type = PANVK_EVENT_OP_WAIT, |
| 52 |
.event = event, |
| 53 |
}; |
| 54 |
|
| 55 |
if (cmdbuf->cur_batch == NULL) { |
| 56 |
/* No open batch, let's create a new one and have it wait for this event. */ |
| 57 |
panvk_per_arch(cmd_open_batch)(cmdbuf); |
| 58 |
util_dynarray_append(&cmdbuf->cur_batch->event_ops, op); |
| 59 |
} else { |
| 60 |
/* Let's close the current batch so any future commands wait on the |
| 61 |
* event signal operation. |
| 62 |
*/ |
| 63 |
if (cmdbuf->cur_batch->frag_jc.first_job || |
| 64 |
cmdbuf->cur_batch->vtc_jc.first_job) { |
| 65 |
panvk_per_arch(cmd_close_batch)(cmdbuf); |
| 66 |
panvk_per_arch(cmd_open_batch)(cmdbuf); |
| 67 |
} |
| 68 |
util_dynarray_append(&cmdbuf->cur_batch->event_ops, op); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
VKAPI_ATTR void VKAPI_CALL |
| 73 |
panvk_per_arch(CmdSetEvent2)(VkCommandBuffer commandBuffer, VkEvent _event, |
| 74 |
const VkDependencyInfo *pDependencyInfo) |
| 75 |
{ |
| 76 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 77 |
VK_FROM_HANDLE(panvk_event, event, _event); |
| 78 |
|
| 79 |
/* vkCmdSetEvent cannot be called inside a render pass */ |
| 80 |
assert(cmdbuf->vk.render_pass == NULL); |
| 81 |
|
| 82 |
panvk_add_set_event_operation(cmdbuf, event, PANVK_EVENT_OP_SET); |
| 83 |
} |
| 84 |
|
| 85 |
VKAPI_ATTR void VKAPI_CALL |
| 86 |
panvk_per_arch(CmdResetEvent2)(VkCommandBuffer commandBuffer, VkEvent _event, |
| 87 |
VkPipelineStageFlags2 stageMask) |
| 88 |
{ |
| 89 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 90 |
VK_FROM_HANDLE(panvk_event, event, _event); |
| 91 |
|
| 92 |
/* vkCmdResetEvent cannot be called inside a render pass */ |
| 93 |
assert(cmdbuf->vk.render_pass == NULL); |
| 94 |
|
| 95 |
panvk_add_set_event_operation(cmdbuf, event, PANVK_EVENT_OP_RESET); |
| 96 |
} |
| 97 |
|
| 98 |
VKAPI_ATTR void VKAPI_CALL |
| 99 |
panvk_per_arch(CmdWaitEvents2)(VkCommandBuffer commandBuffer, |
| 100 |
uint32_t eventCount, const VkEvent *pEvents, |
| 101 |
const VkDependencyInfo *pDependencyInfos) |
| 102 |
{ |
| 103 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 104 |
|
| 105 |
assert(eventCount > 0); |
| 106 |
|
| 107 |
for (uint32_t i = 0; i < eventCount; i++) { |
| 108 |
VK_FROM_HANDLE(panvk_event, event, pEvents[i]); |
| 109 |
const VkDependencyInfo *info = &pDependencyInfos[i]; |
| 110 |
|
| 111 |
panvk_add_wait_event_operation(cmdbuf, event); |
| 112 |
|
| 113 |
for (uint32_t i = 0; i < info->imageMemoryBarrierCount; i++) { |
| 114 |
const VkImageMemoryBarrier2 *barrier = &info->pImageMemoryBarriers[i]; |
| 115 |
|
| 116 |
panvk_per_arch(cmd_transition_image_layout)(commandBuffer, barrier); |
| 117 |
} |
| 118 |
|
| 119 |
/* We don't need to do anything here to establish the sync between layout |
| 120 |
* transition dispatches and the commands following the barrier. See the |
| 121 |
* comment in ./panvk_vX_cmd_buffer.c:CmdPipelineBarrier2 for details. |
| 122 |
*/ |
| 123 |
} |
| 124 |
} |