| 1 |
/* |
| 2 |
* Copyright 2025 Arm Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "panvk_cmd_buffer.h" |
| 7 |
#include "panvk_queue.h" |
| 8 |
|
| 9 |
enum panvk_instr_work_type { |
| 10 |
PANVK_INSTR_WORK_TYPE_CMDBUF, |
| 11 |
PANVK_INSTR_WORK_TYPE_META, |
| 12 |
PANVK_INSTR_WORK_TYPE_RENDER, |
| 13 |
PANVK_INSTR_WORK_TYPE_DISPATCH, |
| 14 |
PANVK_INSTR_WORK_TYPE_DISPATCH_INDIRECT, |
| 15 |
PANVK_INSTR_WORK_TYPE_BARRIER, |
| 16 |
PANVK_INSTR_WORK_TYPE_FLUSH_CACHE, |
| 17 |
PANVK_INSTR_WORK_TYPE_SYNC32_ADD, |
| 18 |
PANVK_INSTR_WORK_TYPE_SYNC64_ADD, |
| 19 |
PANVK_INSTR_WORK_TYPE_SYNC32_WAIT, |
| 20 |
PANVK_INSTR_WORK_TYPE_SYNC64_WAIT, |
| 21 |
}; |
| 22 |
|
| 23 |
struct panvk_instr_end_args { |
| 24 |
/* Depending on which work type is ended, one of the options below is valid. */ |
| 25 |
union { |
| 26 |
struct { |
| 27 |
uint8_t wait_sb_mask; |
| 28 |
uint8_t wait_subqueue_mask; |
| 29 |
} barrier; |
| 30 |
|
| 31 |
struct { |
| 32 |
VkCommandBufferUsageFlags flags; |
| 33 |
} cmdbuf; |
| 34 |
|
| 35 |
struct { |
| 36 |
VkRenderingFlags flags; |
| 37 |
const struct pan_fb_layout *fb; |
| 38 |
} render; |
| 39 |
|
| 40 |
struct { |
| 41 |
uint16_t base_group_x; |
| 42 |
uint16_t base_group_y; |
| 43 |
uint16_t base_group_z; |
| 44 |
uint16_t group_count_x; |
| 45 |
uint16_t group_count_y; |
| 46 |
uint16_t group_count_z; |
| 47 |
uint16_t group_size_x; |
| 48 |
uint16_t group_size_y; |
| 49 |
uint16_t group_size_z; |
| 50 |
} dispatch; |
| 51 |
|
| 52 |
struct { |
| 53 |
uint64_t buffer_gpu; |
| 54 |
} dispatch_indirect; |
| 55 |
|
| 56 |
struct { |
| 57 |
uint8_t l2; |
| 58 |
uint8_t lsc; |
| 59 |
uint8_t other; |
| 60 |
} flush_cache; |
| 61 |
|
| 62 |
struct { |
| 63 |
struct cs_index addr_regs; |
| 64 |
struct cs_index val_regs; |
| 65 |
enum mali_cs_condition cond; |
| 66 |
} sync; |
| 67 |
}; |
| 68 |
}; |
| 69 |
|
| 70 |
void |
| 71 |
panvk_per_arch(panvk_instr_begin_work)(enum panvk_subqueue_id id, |
| 72 |
struct panvk_cmd_buffer *cmdbuf, |
| 73 |
enum panvk_instr_work_type work_type); |
| 74 |
|
| 75 |
/** |
| 76 |
* Mark the end of synchronous work. |
| 77 |
*/ |
| 78 |
void panvk_per_arch(panvk_instr_end_work)( |
| 79 |
enum panvk_subqueue_id id, struct panvk_cmd_buffer *cmdbuf, |
| 80 |
enum panvk_instr_work_type work_type, |
| 81 |
const struct panvk_instr_end_args *const args); |
| 82 |
|
| 83 |
/** |
| 84 |
* Mark the end of async work with an async_op. Note that the signal_slot will |
| 85 |
* be overwritten and should therefore be left as 0. |
| 86 |
*/ |
| 87 |
void panvk_per_arch(panvk_instr_end_work_async)( |
| 88 |
enum panvk_subqueue_id id, struct panvk_cmd_buffer *cmdbuf, |
| 89 |
enum panvk_instr_work_type work_type, |
| 90 |
const struct panvk_instr_end_args *const args, |
| 91 |
struct cs_async_op ts_async_op); |
| 92 |
|
| 93 |
#define PANVK_INSTR_SYNC_OPS(__cnt_width) \ |
| 94 |
static inline void panvk_instr_sync##__cnt_width##_add( \ |
| 95 |
struct panvk_cmd_buffer *cmdbuf, enum panvk_subqueue_id id, \ |
| 96 |
bool propagate_error, enum mali_cs_sync_scope scope, \ |
| 97 |
struct cs_index val, struct cs_index addr, struct cs_async_op async) \ |
| 98 |
{ \ |
| 99 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, id); \ |
| 100 |
panvk_per_arch(panvk_instr_begin_work)( \ |
| 101 |
id, cmdbuf, PANVK_INSTR_WORK_TYPE_SYNC##__cnt_width##_ADD); \ |
| 102 |
cs_sync##__cnt_width##_add(b, propagate_error, scope, val, addr, async); \ |
| 103 |
struct panvk_instr_end_args instr_info = { \ |
| 104 |
.sync = {.addr_regs = addr, .val_regs = val}, \ |
| 105 |
}; \ |
| 106 |
async.signal_slot = 0; \ |
| 107 |
panvk_per_arch(panvk_instr_end_work_async)( \ |
| 108 |
id, cmdbuf, PANVK_INSTR_WORK_TYPE_SYNC##__cnt_width##_ADD, \ |
| 109 |
&instr_info, async); \ |
| 110 |
} \ |
| 111 |
\ |
| 112 |
static inline void panvk_instr_sync##__cnt_width##_wait( \ |
| 113 |
struct panvk_cmd_buffer *cmdbuf, enum panvk_subqueue_id id, \ |
| 114 |
bool reject_error, enum mali_cs_condition cond, struct cs_index ref, \ |
| 115 |
struct cs_index addr) \ |
| 116 |
{ \ |
| 117 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, id); \ |
| 118 |
panvk_per_arch(panvk_instr_begin_work)( \ |
| 119 |
id, cmdbuf, PANVK_INSTR_WORK_TYPE_SYNC##__cnt_width##_WAIT); \ |
| 120 |
cs_sync##__cnt_width##_wait(b, reject_error, cond, ref, addr); \ |
| 121 |
struct panvk_instr_end_args instr_info = { \ |
| 122 |
.sync = {.addr_regs = addr, .val_regs = ref, .cond = cond}, \ |
| 123 |
}; \ |
| 124 |
panvk_per_arch(panvk_instr_end_work)( \ |
| 125 |
id, cmdbuf, PANVK_INSTR_WORK_TYPE_SYNC##__cnt_width##_WAIT, \ |
| 126 |
&instr_info); \ |
| 127 |
} |
| 128 |
|
| 129 |
PANVK_INSTR_SYNC_OPS(32) |
| 130 |
PANVK_INSTR_SYNC_OPS(64) |