| 1 |
/* |
| 2 |
* Copyright © 2024 Collabora Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "drm-uapi/panthor_drm.h" |
| 7 |
|
| 8 |
#include "genxml/cs_builder.h" |
| 9 |
#include "genxml/decode.h" |
| 10 |
|
| 11 |
#include "panvk_buffer.h" |
| 12 |
#include "panvk_cmd_buffer.h" |
| 13 |
#include "panvk_device_memory.h" |
| 14 |
#include "panvk_macros.h" |
| 15 |
#include "panvk_queue.h" |
| 16 |
#include "panvk_utrace.h" |
| 17 |
|
| 18 |
#include "pan_trace.h" |
| 19 |
|
| 20 |
#include "util/bitscan.h" |
| 21 |
#include "vk_drm_syncobj.h" |
| 22 |
#include "vk_log.h" |
| 23 |
|
| 24 |
#define MIN_DESC_TRACEBUF_SIZE (128 * 1024) |
| 25 |
#define DEFAULT_DESC_TRACEBUF_SIZE (2 * 1024 * 1024) |
| 26 |
#define MIN_CS_TRACEBUF_SIZE (512 * 1024) |
| 27 |
#define DEFAULT_CS_TRACEBUF_SIZE (2 * 1024 * 1024) |
| 28 |
|
| 29 |
static void |
| 30 |
finish_render_desc_ringbuf(struct panvk_gpu_queue *queue) |
| 31 |
{ |
| 32 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 33 |
const bool tracing_enabled = PANVK_DEBUG(TRACE); |
| 34 |
struct panvk_desc_ringbuf *ringbuf = &queue->render_desc_ringbuf; |
| 35 |
|
| 36 |
panvk_pool_free_mem(&ringbuf->syncobj); |
| 37 |
|
| 38 |
if (dev->debug.decode_ctx && ringbuf->addr.dev) { |
| 39 |
pandecode_inject_free(dev->debug.decode_ctx, ringbuf->addr.dev, |
| 40 |
ringbuf->size); |
| 41 |
if (!tracing_enabled) |
| 42 |
pandecode_inject_free(dev->debug.decode_ctx, |
| 43 |
ringbuf->addr.dev + ringbuf->size, |
| 44 |
ringbuf->size); |
| 45 |
} |
| 46 |
|
| 47 |
if (ringbuf->addr.dev) { |
| 48 |
struct pan_kmod_vm_op op = { |
| 49 |
.type = PAN_KMOD_VM_OP_TYPE_UNMAP, |
| 50 |
.va = { |
| 51 |
.start = ringbuf->addr.dev, |
| 52 |
.size = ringbuf->size * (tracing_enabled ? 2 : 1), |
| 53 |
}, |
| 54 |
}; |
| 55 |
|
| 56 |
ASSERTED int ret = |
| 57 |
pan_kmod_vm_bind(dev->kmod.vm, PAN_KMOD_VM_OP_MODE_IMMEDIATE, &op, 1); |
| 58 |
assert(!ret); |
| 59 |
|
| 60 |
panvk_as_free(dev, dev->as.priv_heap, ringbuf->addr.dev, |
| 61 |
ringbuf->size * 2); |
| 62 |
} |
| 63 |
|
| 64 |
if (ringbuf->addr.host) { |
| 65 |
ASSERTED int ret = |
| 66 |
os_munmap(ringbuf->addr.host, ringbuf->size); |
| 67 |
assert(!ret); |
| 68 |
} |
| 69 |
|
| 70 |
pan_kmod_bo_put(ringbuf->bo); |
| 71 |
} |
| 72 |
|
| 73 |
static VkResult |
| 74 |
init_render_desc_ringbuf(struct panvk_gpu_queue *queue) |
| 75 |
{ |
| 76 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 77 |
const bool tracing_enabled = PANVK_DEBUG(TRACE); |
| 78 |
uint32_t flags = panvk_device_adjust_bo_flags(dev, PAN_KMOD_BO_FLAG_NO_MMAP); |
| 79 |
struct panvk_desc_ringbuf *ringbuf = &queue->render_desc_ringbuf; |
| 80 |
uint64_t dev_addr = 0; |
| 81 |
int ret; |
| 82 |
|
| 83 |
if (tracing_enabled) { |
| 84 |
ringbuf->size = debug_get_num_option("PANVK_DESC_TRACEBUF_SIZE", |
| 85 |
DEFAULT_DESC_TRACEBUF_SIZE); |
| 86 |
flags |= PAN_KMOD_BO_FLAG_GPU_UNCACHED; |
| 87 |
assert(ringbuf->size > MIN_DESC_TRACEBUF_SIZE && |
| 88 |
util_is_power_of_two_nonzero(ringbuf->size)); |
| 89 |
} else { |
| 90 |
ringbuf->size = RENDER_DESC_RINGBUF_SIZE; |
| 91 |
} |
| 92 |
|
| 93 |
ringbuf->bo = |
| 94 |
pan_kmod_bo_alloc(dev->kmod.dev, dev->kmod.vm, ringbuf->size, flags); |
| 95 |
if (!ringbuf->bo) |
| 96 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 97 |
"Failed to create a descriptor ring buffer context"); |
| 98 |
|
| 99 |
if (!(flags & PAN_KMOD_BO_FLAG_NO_MMAP)) { |
| 100 |
ringbuf->addr.host = pan_kmod_bo_mmap(ringbuf->bo, PROT_READ | PROT_WRITE, |
| 101 |
MAP_SHARED, NULL); |
| 102 |
if (ringbuf->addr.host == MAP_FAILED) |
| 103 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_HOST_MEMORY, |
| 104 |
"Failed to CPU map ringbuf BO"); |
| 105 |
} |
| 106 |
|
| 107 |
/* We choose the alignment to guarantee that we won't ever cross a 4G |
| 108 |
* boundary when accessing the mapping. This way we can encode the wraparound |
| 109 |
* using 32-bit operations. */ |
| 110 |
dev_addr = panvk_as_alloc(dev, dev->as.priv_heap, ringbuf->size * 2, |
| 111 |
ringbuf->size * 2); |
| 112 |
|
| 113 |
if (!dev_addr) |
| 114 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 115 |
"Failed to allocate virtual address for ringbuf BO"); |
| 116 |
|
| 117 |
struct pan_kmod_vm_op vm_ops[] = { |
| 118 |
{ |
| 119 |
.type = PAN_KMOD_VM_OP_TYPE_MAP, |
| 120 |
.va = { |
| 121 |
.start = dev_addr, |
| 122 |
.size = ringbuf->size, |
| 123 |
}, |
| 124 |
.map = { |
| 125 |
.bo = ringbuf->bo, |
| 126 |
.bo_offset = 0, |
| 127 |
}, |
| 128 |
}, |
| 129 |
{ |
| 130 |
.type = PAN_KMOD_VM_OP_TYPE_MAP, |
| 131 |
.va = { |
| 132 |
.start = dev_addr + ringbuf->size, |
| 133 |
.size = ringbuf->size, |
| 134 |
}, |
| 135 |
.map = { |
| 136 |
.bo = ringbuf->bo, |
| 137 |
.bo_offset = 0, |
| 138 |
}, |
| 139 |
}, |
| 140 |
}; |
| 141 |
|
| 142 |
/* If tracing is enabled, we keep the second part of the mapping unmapped |
| 143 |
* to serve as a guard region. */ |
| 144 |
ret = pan_kmod_vm_bind(dev->kmod.vm, PAN_KMOD_VM_OP_MODE_IMMEDIATE, vm_ops, |
| 145 |
tracing_enabled ? 1 : ARRAY_SIZE(vm_ops)); |
| 146 |
if (ret) { |
| 147 |
panvk_as_free(dev, dev->as.priv_heap, dev_addr, ringbuf->size * 2); |
| 148 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 149 |
"Failed to GPU map ringbuf BO"); |
| 150 |
} |
| 151 |
|
| 152 |
ringbuf->addr.dev = dev_addr; |
| 153 |
|
| 154 |
if (dev->debug.decode_ctx) { |
| 155 |
pandecode_inject_mmap(dev->debug.decode_ctx, ringbuf->addr.dev, |
| 156 |
ringbuf->addr.host, ringbuf->size, NULL); |
| 157 |
if (!tracing_enabled) |
| 158 |
pandecode_inject_mmap(dev->debug.decode_ctx, |
| 159 |
ringbuf->addr.dev + ringbuf->size, |
| 160 |
ringbuf->addr.host, ringbuf->size, NULL); |
| 161 |
} |
| 162 |
|
| 163 |
struct panvk_pool_alloc_info alloc_info = { |
| 164 |
.size = sizeof(struct panvk_cs_sync32), |
| 165 |
.alignment = 64, |
| 166 |
}; |
| 167 |
|
| 168 |
ringbuf->syncobj = panvk_pool_alloc_mem(&dev->mempools.rw, alloc_info); |
| 169 |
if (!panvk_priv_mem_check_alloc(ringbuf->syncobj)) |
| 170 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 171 |
"Failed to create the render desc ringbuf context"); |
| 172 |
|
| 173 |
panvk_priv_mem_write(ringbuf->syncobj, 0, struct panvk_cs_sync32, syncobj) { |
| 174 |
*syncobj = (struct panvk_cs_sync32){ |
| 175 |
.seqno = RENDER_DESC_RINGBUF_SIZE, |
| 176 |
}; |
| 177 |
} |
| 178 |
|
| 179 |
return VK_SUCCESS; |
| 180 |
} |
| 181 |
|
| 182 |
static void |
| 183 |
finish_subqueue_tracing(struct panvk_gpu_queue *queue, |
| 184 |
enum panvk_subqueue_id subqueue) |
| 185 |
{ |
| 186 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 187 |
struct panvk_subqueue *subq = &queue->subqueues[subqueue]; |
| 188 |
|
| 189 |
if (subq->tracebuf.addr.dev) { |
| 190 |
uint64_t pgsize = panvk_get_gpu_page_size(dev); |
| 191 |
|
| 192 |
pandecode_inject_free(dev->debug.decode_ctx, subq->tracebuf.addr.dev, |
| 193 |
subq->tracebuf.size); |
| 194 |
|
| 195 |
struct pan_kmod_vm_op op = { |
| 196 |
.type = PAN_KMOD_VM_OP_TYPE_UNMAP, |
| 197 |
.va = { |
| 198 |
.start = subq->tracebuf.addr.dev, |
| 199 |
.size = subq->tracebuf.size, |
| 200 |
}, |
| 201 |
}; |
| 202 |
|
| 203 |
ASSERTED int ret = |
| 204 |
pan_kmod_vm_bind(dev->kmod.vm, PAN_KMOD_VM_OP_MODE_IMMEDIATE, &op, 1); |
| 205 |
assert(!ret); |
| 206 |
|
| 207 |
panvk_as_free(dev, dev->as.priv_heap, subq->tracebuf.addr.dev, |
| 208 |
subq->tracebuf.size + pgsize); |
| 209 |
} |
| 210 |
|
| 211 |
if (subq->tracebuf.addr.host) { |
| 212 |
ASSERTED int ret = |
| 213 |
os_munmap(subq->tracebuf.addr.host, subq->tracebuf.size); |
| 214 |
assert(!ret); |
| 215 |
} |
| 216 |
|
| 217 |
pan_kmod_bo_put(subq->tracebuf.bo); |
| 218 |
|
| 219 |
vk_free(&dev->vk.alloc, subq->reg_file); |
| 220 |
} |
| 221 |
|
| 222 |
static VkResult |
| 223 |
init_subqueue_tracing(struct panvk_gpu_queue *queue, |
| 224 |
enum panvk_subqueue_id subqueue) |
| 225 |
{ |
| 226 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 227 |
struct panvk_subqueue *subq = &queue->subqueues[subqueue]; |
| 228 |
uint64_t dev_addr; |
| 229 |
|
| 230 |
if (!PANVK_DEBUG(TRACE)) |
| 231 |
return VK_SUCCESS; |
| 232 |
|
| 233 |
subq->reg_file = |
| 234 |
vk_zalloc(&dev->vk.alloc, sizeof(uint32_t) * 256, sizeof(uint64_t), |
| 235 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 236 |
if (!subq->reg_file) |
| 237 |
return panvk_errorf(dev->vk.physical, VK_ERROR_OUT_OF_HOST_MEMORY, |
| 238 |
"Failed to allocate reg file cache"); |
| 239 |
|
| 240 |
subq->tracebuf.size = debug_get_num_option("PANVK_CS_TRACEBUF_SIZE", |
| 241 |
DEFAULT_CS_TRACEBUF_SIZE); |
| 242 |
assert(subq->tracebuf.size > MIN_CS_TRACEBUF_SIZE && |
| 243 |
util_is_power_of_two_nonzero(subq->tracebuf.size)); |
| 244 |
|
| 245 |
subq->tracebuf.bo = |
| 246 |
pan_kmod_bo_alloc(dev->kmod.dev, dev->kmod.vm, subq->tracebuf.size, |
| 247 |
PAN_KMOD_BO_FLAG_GPU_UNCACHED); |
| 248 |
if (!subq->tracebuf.bo) |
| 249 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 250 |
"Failed to create a CS tracebuf"); |
| 251 |
|
| 252 |
subq->tracebuf.addr.host = pan_kmod_bo_mmap( |
| 253 |
subq->tracebuf.bo, PROT_READ | PROT_WRITE, MAP_SHARED, NULL); |
| 254 |
if (subq->tracebuf.addr.host == MAP_FAILED) { |
| 255 |
subq->tracebuf.addr.host = NULL; |
| 256 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_HOST_MEMORY, |
| 257 |
"Failed to CPU map tracebuf"); |
| 258 |
} |
| 259 |
|
| 260 |
/* Add a guard page. */ |
| 261 |
uint64_t pgsize = panvk_get_gpu_page_size(dev); |
| 262 |
dev_addr = panvk_as_alloc(dev, dev->as.priv_heap, |
| 263 |
subq->tracebuf.size + pgsize, pgsize); |
| 264 |
|
| 265 |
if (!dev_addr) |
| 266 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 267 |
"Failed to allocate virtual address for tracebuf"); |
| 268 |
|
| 269 |
struct pan_kmod_vm_op vm_op = { |
| 270 |
.type = PAN_KMOD_VM_OP_TYPE_MAP, |
| 271 |
.va = { |
| 272 |
.start = dev_addr, |
| 273 |
.size = subq->tracebuf.size, |
| 274 |
}, |
| 275 |
.map = { |
| 276 |
.bo = subq->tracebuf.bo, |
| 277 |
.bo_offset = 0, |
| 278 |
}, |
| 279 |
}; |
| 280 |
|
| 281 |
/* If tracing is enabled, we keep the second part of the mapping unmapped |
| 282 |
* to serve as a guard region. */ |
| 283 |
int ret = |
| 284 |
pan_kmod_vm_bind(dev->kmod.vm, PAN_KMOD_VM_OP_MODE_IMMEDIATE, &vm_op, 1); |
| 285 |
if (ret) { |
| 286 |
panvk_as_free(dev, dev->as.priv_heap, dev_addr, |
| 287 |
subq->tracebuf.size + pgsize); |
| 288 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 289 |
"Failed to GPU map ringbuf BO"); |
| 290 |
} |
| 291 |
|
| 292 |
subq->tracebuf.addr.dev = dev_addr; |
| 293 |
|
| 294 |
if (dev->debug.decode_ctx) { |
| 295 |
pandecode_inject_mmap(dev->debug.decode_ctx, subq->tracebuf.addr.dev, |
| 296 |
subq->tracebuf.addr.host, subq->tracebuf.size, |
| 297 |
NULL); |
| 298 |
} |
| 299 |
|
| 300 |
return VK_SUCCESS; |
| 301 |
} |
| 302 |
|
| 303 |
static void |
| 304 |
finish_subqueue(struct panvk_gpu_queue *queue, enum panvk_subqueue_id subqueue) |
| 305 |
{ |
| 306 |
panvk_pool_free_mem(&queue->subqueues[subqueue].context); |
| 307 |
panvk_pool_free_mem(&queue->subqueues[subqueue].req_resource.buf); |
| 308 |
panvk_pool_free_mem(&queue->subqueues[subqueue].regs_save); |
| 309 |
finish_subqueue_tracing(queue, subqueue); |
| 310 |
} |
| 311 |
|
| 312 |
static VkResult |
| 313 |
init_utrace(struct panvk_gpu_queue *queue) |
| 314 |
{ |
| 315 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 316 |
const struct panvk_physical_device *phys_dev = |
| 317 |
to_panvk_physical_device(dev->vk.physical); |
| 318 |
VkResult result; |
| 319 |
|
| 320 |
const struct vk_sync_type *sync_type = phys_dev->sync_types[0]; |
| 321 |
assert(sync_type && vk_sync_type_is_drm_syncobj(sync_type) && |
| 322 |
(sync_type->features & VK_SYNC_FEATURE_TIMELINE)); |
| 323 |
|
| 324 |
result = vk_sync_create(&dev->vk, sync_type, VK_SYNC_IS_TIMELINE, 0, |
| 325 |
&queue->utrace.sync); |
| 326 |
if (result != VK_SUCCESS) |
| 327 |
return result; |
| 328 |
|
| 329 |
queue->utrace.next_value = 1; |
| 330 |
|
| 331 |
return VK_SUCCESS; |
| 332 |
} |
| 333 |
|
| 334 |
static uint32_t |
| 335 |
get_resource_mask(enum panvk_subqueue_id subqueue) |
| 336 |
{ |
| 337 |
switch (subqueue) { |
| 338 |
case PANVK_SUBQUEUE_VERTEX_TILER: |
| 339 |
return CS_IDVS_RES | CS_TILER_RES; |
| 340 |
case PANVK_SUBQUEUE_FRAGMENT: |
| 341 |
return CS_FRAG_RES; |
| 342 |
case PANVK_SUBQUEUE_COMPUTE: |
| 343 |
return CS_COMPUTE_RES; |
| 344 |
default: |
| 345 |
UNREACHABLE("Unknown subqueue"); |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
static VkResult |
| 350 |
init_subqueue(struct panvk_gpu_queue *queue, enum panvk_subqueue_id subqueue) |
| 351 |
{ |
| 352 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 353 |
struct panvk_subqueue *subq = &queue->subqueues[subqueue]; |
| 354 |
const struct panvk_physical_device *phys_dev = |
| 355 |
to_panvk_physical_device(queue->vk.base.device->physical); |
| 356 |
|
| 357 |
VkResult result = init_subqueue_tracing(queue, subqueue); |
| 358 |
if (result != VK_SUCCESS) |
| 359 |
return result; |
| 360 |
|
| 361 |
struct panvk_pool_alloc_info alloc_info; |
| 362 |
|
| 363 |
if (dev->dump_region_size[subqueue]) { |
| 364 |
alloc_info.size = dev->dump_region_size[subqueue]; |
| 365 |
alloc_info.alignment = sizeof(uint32_t); |
| 366 |
subq->regs_save = panvk_pool_alloc_mem(&dev->mempools.rw, alloc_info); |
| 367 |
if (!panvk_priv_mem_check_alloc(subq->regs_save)) { |
| 368 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 369 |
"Failed to allocate register save area"); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
/* When tracing is enabled, we want to use a non-cached pool, so can get |
| 374 |
* up-to-date context even if the CS crashed in the middle. */ |
| 375 |
struct panvk_pool *mempool = |
| 376 |
PANVK_DEBUG(TRACE) ? &dev->mempools.rw_nc : &dev->mempools.rw; |
| 377 |
|
| 378 |
alloc_info.size = sizeof(uint64_t); |
| 379 |
alloc_info.alignment = 64; |
| 380 |
subq->req_resource.buf = panvk_pool_alloc_mem(mempool, alloc_info); |
| 381 |
if (!panvk_priv_mem_check_alloc(subq->req_resource.buf)) |
| 382 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 383 |
"Failed to create a req_resource buffer"); |
| 384 |
|
| 385 |
struct cs_builder b; |
| 386 |
const struct drm_panthor_csif_info *csif_info = |
| 387 |
panthor_kmod_get_csif_props(dev->kmod.dev); |
| 388 |
|
| 389 |
struct cs_buffer root_cs = { |
| 390 |
.cpu = panvk_priv_mem_host_addr(subq->req_resource.buf), |
| 391 |
.gpu = panvk_priv_mem_dev_addr(subq->req_resource.buf), |
| 392 |
.capacity = 1, |
| 393 |
}; |
| 394 |
struct cs_builder_conf conf = { |
| 395 |
.nr_registers = csif_info->cs_reg_count, |
| 396 |
.nr_kernel_registers = MAX2(csif_info->unpreserved_cs_reg_count, 4), |
| 397 |
.ls_sb_slot = SB_ID(LS), |
| 398 |
}; |
| 399 |
|
| 400 |
cs_builder_init(&b, &conf, root_cs); |
| 401 |
cs_req_res(&b, get_resource_mask(subqueue)); |
| 402 |
cs_end(&b); |
| 403 |
assert(cs_is_valid(&b)); |
| 404 |
subq->req_resource.cs_buffer_size = cs_root_chunk_size(&b); |
| 405 |
subq->req_resource.cs_buffer_addr = cs_root_chunk_gpu_addr(&b); |
| 406 |
cs_builder_fini(&b); |
| 407 |
panvk_priv_mem_flush(subq->req_resource.buf, 0, |
| 408 |
subq->req_resource.cs_buffer_size); |
| 409 |
|
| 410 |
alloc_info.size = sizeof(struct panvk_cs_subqueue_context); |
| 411 |
alloc_info.alignment = 64; |
| 412 |
|
| 413 |
subq->context = panvk_pool_alloc_mem(mempool, alloc_info); |
| 414 |
if (!panvk_priv_mem_check_alloc(subq->context)) |
| 415 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 416 |
"Failed to create a queue context"); |
| 417 |
|
| 418 |
panvk_priv_mem_write(subq->context, 0, struct panvk_cs_subqueue_context, |
| 419 |
cs_ctx) { |
| 420 |
*cs_ctx = (struct panvk_cs_subqueue_context){ |
| 421 |
.syncobjs = panvk_priv_mem_dev_addr(queue->syncobjs), |
| 422 |
.debug.tracebuf.cs = subq->tracebuf.addr.dev, |
| 423 |
#if PAN_ARCH == 10 |
| 424 |
/* On the VT/COMPUTE queue, the first iter_sb will skipped since |
| 425 |
* cs_next_iter_sb() is called before the first use, but that's okay, |
| 426 |
* because the next slot will be equally free, and the skipped one will |
| 427 |
* be re-used at some point. |
| 428 |
* On the fragment queue, we increment the iterator when the |
| 429 |
* FINISH_FRAGMENT job is issued, which is why we need this value |
| 430 |
* to point to a valid+free scoreboard from the start. |
| 431 |
*/ |
| 432 |
.iter_sb = SB_ITER(0), |
| 433 |
#endif |
| 434 |
.reg_dump_addr = panvk_priv_mem_dev_addr(subq->regs_save), |
| 435 |
}; |
| 436 |
|
| 437 |
if (subqueue != PANVK_SUBQUEUE_COMPUTE) { |
| 438 |
cs_ctx->render.tiler_heap = |
| 439 |
panvk_priv_mem_dev_addr(queue->tiler_heap.desc); |
| 440 |
/* Our geometry buffer comes 4k after the tiler heap, and we encode the |
| 441 |
* size in the lower 12 bits so the address can be copied directly |
| 442 |
* to the tiler descriptors. */ |
| 443 |
cs_ctx->render.geom_buf = |
| 444 |
(cs_ctx->render.tiler_heap + 4096) | ((64 * 1024) >> 12); |
| 445 |
|
| 446 |
/* Initialize the ringbuf */ |
| 447 |
cs_ctx->render.desc_ringbuf = (struct panvk_cs_desc_ringbuf){ |
| 448 |
.syncobj = |
| 449 |
panvk_priv_mem_dev_addr(queue->render_desc_ringbuf.syncobj), |
| 450 |
.ptr = queue->render_desc_ringbuf.addr.dev, |
| 451 |
.pos = 0, |
| 452 |
}; |
| 453 |
} |
| 454 |
|
| 455 |
if (subqueue == PANVK_SUBQUEUE_FRAGMENT) { |
| 456 |
/* The tiler OOM exception handler is registered to the fragment |
| 457 |
* queue, so the scratch FBD buffer is only needed there. We leave |
| 458 |
* it to NULL on other queues to make sure any attempt to access it |
| 459 |
* results in a NULL deref that can be caught. |
| 460 |
*/ |
| 461 |
cs_ctx->tiler_oom_ctx.ir_scratch_fbd_ptr = |
| 462 |
panvk_priv_mem_dev_addr(queue->tiler_heap.oom_fbd); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
/* We use the geometry buffer for our temporary CS buffer. */ |
| 467 |
root_cs = (struct cs_buffer){ |
| 468 |
.cpu = panvk_priv_mem_host_addr(queue->tiler_heap.desc) + 4096, |
| 469 |
.gpu = panvk_priv_mem_dev_addr(queue->tiler_heap.desc) + 4096, |
| 470 |
.capacity = 64 * 1024 / sizeof(uint64_t), |
| 471 |
}; |
| 472 |
conf = (struct cs_builder_conf){ |
| 473 |
.nr_registers = csif_info->cs_reg_count, |
| 474 |
.nr_kernel_registers = MAX2(csif_info->unpreserved_cs_reg_count, 4), |
| 475 |
.ls_sb_slot = SB_ID(LS), |
| 476 |
}; |
| 477 |
|
| 478 |
assert(panvk_priv_mem_dev_addr(queue->tiler_heap.desc) != 0); |
| 479 |
|
| 480 |
cs_builder_init(&b, &conf, root_cs); |
| 481 |
/* Pass the context. */ |
| 482 |
cs_move64_to(&b, cs_subqueue_ctx_reg(&b), |
| 483 |
panvk_priv_mem_dev_addr(subq->context)); |
| 484 |
|
| 485 |
/* Intialize scoreboard slots used for asynchronous operations. */ |
| 486 |
#if PAN_ARCH >= 11 |
| 487 |
cs_set_state_imm32(&b, MALI_CS_SET_STATE_TYPE_SB_SEL_ENDPOINT, SB_ITER(0)); |
| 488 |
cs_set_state_imm32(&b, MALI_CS_SET_STATE_TYPE_SB_MASK_WAIT, SB_WAIT_ITER(0)); |
| 489 |
cs_set_state_imm32(&b, MALI_CS_SET_STATE_TYPE_SB_SEL_OTHER, SB_ID(LS)); |
| 490 |
cs_set_state_imm32(&b, MALI_CS_SET_STATE_TYPE_SB_SEL_DEFERRED, |
| 491 |
SB_ID(DEFERRED_SYNC)); |
| 492 |
cs_set_state_imm32(&b, MALI_CS_SET_STATE_TYPE_SB_MASK_STREAM, |
| 493 |
dev->csf.sb.all_iters_mask & ~SB_WAIT_ITER(0)); |
| 494 |
#else |
| 495 |
cs_set_scoreboard_entry(&b, SB_ITER(0), SB_ID(LS)); |
| 496 |
#endif |
| 497 |
|
| 498 |
/* We do greater than test on sync objects, and given the reference seqno |
| 499 |
* registers are all zero at init time, we need to initialize all syncobjs |
| 500 |
* with a seqno of one. */ |
| 501 |
panvk_priv_mem_write(queue->syncobjs, |
| 502 |
subqueue * sizeof(struct panvk_cs_sync64), |
| 503 |
struct panvk_cs_sync64, syncobj) { |
| 504 |
syncobj->seqno = 1; |
| 505 |
} |
| 506 |
|
| 507 |
if (subqueue != PANVK_SUBQUEUE_COMPUTE) { |
| 508 |
struct cs_index heap_ctx_addr = cs_scratch_reg64(&b, 0); |
| 509 |
|
| 510 |
/* Pre-set the heap context on the vertex-tiler/fragment queues. */ |
| 511 |
cs_move64_to(&b, heap_ctx_addr, queue->tiler_heap.context.dev_addr); |
| 512 |
cs_heap_set(&b, heap_ctx_addr); |
| 513 |
} |
| 514 |
cs_end(&b); |
| 515 |
|
| 516 |
assert(cs_is_valid(&b)); |
| 517 |
|
| 518 |
panvk_priv_mem_flush(queue->tiler_heap.desc, 4096, cs_root_chunk_size(&b)); |
| 519 |
|
| 520 |
struct drm_panthor_sync_op syncop = { |
| 521 |
.flags = |
| 522 |
DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ | DRM_PANTHOR_SYNC_OP_SIGNAL, |
| 523 |
.handle = queue->syncobj_handle, |
| 524 |
.timeline_value = 0, |
| 525 |
}; |
| 526 |
struct drm_panthor_queue_submit qsubmit = { |
| 527 |
.queue_index = subqueue, |
| 528 |
.stream_size = cs_root_chunk_size(&b), |
| 529 |
.stream_addr = cs_root_chunk_gpu_addr(&b), |
| 530 |
.latest_flush = panthor_kmod_get_flush_id(dev->kmod.dev), |
| 531 |
.syncs = DRM_PANTHOR_OBJ_ARRAY(1, &syncop), |
| 532 |
}; |
| 533 |
struct drm_panthor_group_submit gsubmit = { |
| 534 |
.group_handle = queue->group_handle, |
| 535 |
.queue_submits = DRM_PANTHOR_OBJ_ARRAY(1, &qsubmit), |
| 536 |
}; |
| 537 |
|
| 538 |
cs_builder_fini(&b); |
| 539 |
|
| 540 |
pan_kmod_flush_bo_map_syncs(dev->kmod.dev); |
| 541 |
|
| 542 |
int ret = pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_GROUP_SUBMIT, |
| 543 |
&gsubmit); |
| 544 |
if (ret) |
| 545 |
return panvk_errorf(dev->vk.physical, VK_ERROR_INITIALIZATION_FAILED, |
| 546 |
"Failed to initialized subqueue: %m"); |
| 547 |
|
| 548 |
ret = drmSyncobjWait(dev->drm_fd, &queue->syncobj_handle, 1, INT64_MAX, 0, |
| 549 |
NULL); |
| 550 |
if (ret) |
| 551 |
return panvk_errorf(dev->vk.physical, VK_ERROR_INITIALIZATION_FAILED, |
| 552 |
"SyncobjWait failed: %m"); |
| 553 |
|
| 554 |
drmSyncobjReset(dev->drm_fd, &queue->syncobj_handle, 1); |
| 555 |
|
| 556 |
if (PANVK_DEBUG(TRACE)) { |
| 557 |
pandecode_user_msg(dev->debug.decode_ctx, "Init subqueue %d binary\n\n", |
| 558 |
subqueue); |
| 559 |
pandecode_cs_binary(dev->debug.decode_ctx, qsubmit.stream_addr, |
| 560 |
qsubmit.stream_size, |
| 561 |
phys_dev->kmod.dev->props.gpu_id); |
| 562 |
} |
| 563 |
|
| 564 |
return VK_SUCCESS; |
| 565 |
} |
| 566 |
|
| 567 |
static void |
| 568 |
cleanup_queue(struct panvk_gpu_queue *queue) |
| 569 |
{ |
| 570 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 571 |
|
| 572 |
for (uint32_t i = 0; i < PANVK_SUBQUEUE_COUNT; i++) |
| 573 |
finish_subqueue(queue, i); |
| 574 |
|
| 575 |
if (queue->utrace.sync) |
| 576 |
vk_sync_destroy(&dev->vk, queue->utrace.sync); |
| 577 |
|
| 578 |
finish_render_desc_ringbuf(queue); |
| 579 |
|
| 580 |
panvk_pool_free_mem(&queue->syncobjs); |
| 581 |
} |
| 582 |
|
| 583 |
static VkResult |
| 584 |
init_queue(struct panvk_gpu_queue *queue) |
| 585 |
{ |
| 586 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 587 |
VkResult result; |
| 588 |
|
| 589 |
struct panvk_pool_alloc_info alloc_info = { |
| 590 |
.size = |
| 591 |
ALIGN_POT(sizeof(struct panvk_cs_sync64), 64) * PANVK_SUBQUEUE_COUNT, |
| 592 |
.alignment = 64, |
| 593 |
}; |
| 594 |
|
| 595 |
queue->syncobjs = panvk_pool_alloc_mem(&dev->mempools.rw, alloc_info); |
| 596 |
if (!panvk_priv_mem_check_alloc(queue->syncobjs)) |
| 597 |
return panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 598 |
"Failed to allocate subqueue sync objects"); |
| 599 |
|
| 600 |
result = init_render_desc_ringbuf(queue); |
| 601 |
if (result != VK_SUCCESS) |
| 602 |
goto err_cleanup_queue; |
| 603 |
|
| 604 |
result = init_utrace(queue); |
| 605 |
if (result != VK_SUCCESS) |
| 606 |
goto err_cleanup_queue; |
| 607 |
|
| 608 |
for (uint32_t i = 0; i < PANVK_SUBQUEUE_COUNT; i++) { |
| 609 |
result = init_subqueue(queue, i); |
| 610 |
if (result != VK_SUCCESS) |
| 611 |
goto err_cleanup_queue; |
| 612 |
} |
| 613 |
|
| 614 |
if (PANVK_DEBUG(TRACE)) |
| 615 |
pandecode_next_frame(dev->debug.decode_ctx); |
| 616 |
|
| 617 |
return VK_SUCCESS; |
| 618 |
|
| 619 |
err_cleanup_queue: |
| 620 |
cleanup_queue(queue); |
| 621 |
return result; |
| 622 |
} |
| 623 |
|
| 624 |
static VkResult |
| 625 |
create_group(struct panvk_gpu_queue *queue, |
| 626 |
enum drm_panthor_group_priority group_priority, |
| 627 |
uint32_t shader_core_count) |
| 628 |
{ |
| 629 |
const struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 630 |
const struct panvk_physical_device *phys_dev = |
| 631 |
to_panvk_physical_device(queue->vk.base.device->physical); |
| 632 |
|
| 633 |
struct drm_panthor_queue_create qc[] = { |
| 634 |
[PANVK_SUBQUEUE_VERTEX_TILER] = |
| 635 |
{ |
| 636 |
.priority = 1, |
| 637 |
.ringbuf_size = 64 * 1024, |
| 638 |
}, |
| 639 |
[PANVK_SUBQUEUE_FRAGMENT] = |
| 640 |
{ |
| 641 |
.priority = 1, |
| 642 |
.ringbuf_size = 64 * 1024, |
| 643 |
}, |
| 644 |
[PANVK_SUBQUEUE_COMPUTE] = |
| 645 |
{ |
| 646 |
.priority = 1, |
| 647 |
.ringbuf_size = 64 * 1024, |
| 648 |
}, |
| 649 |
}; |
| 650 |
|
| 651 |
uint8_t max_compute_cores = util_bitcount64(phys_dev->compute_core_mask); |
| 652 |
uint8_t max_fragment_cores = util_bitcount64(phys_dev->fragment_core_mask); |
| 653 |
|
| 654 |
if (shader_core_count) { |
| 655 |
max_compute_cores = MIN2(shader_core_count, max_compute_cores); |
| 656 |
max_fragment_cores = MIN2(shader_core_count, max_fragment_cores); |
| 657 |
} |
| 658 |
|
| 659 |
struct drm_panthor_group_create gc = { |
| 660 |
.compute_core_mask = phys_dev->compute_core_mask, |
| 661 |
.fragment_core_mask = phys_dev->fragment_core_mask, |
| 662 |
.tiler_core_mask = 1, |
| 663 |
.max_compute_cores = max_compute_cores, |
| 664 |
.max_fragment_cores = max_fragment_cores, |
| 665 |
.max_tiler_cores = 1, |
| 666 |
.priority = group_priority, |
| 667 |
.queues = DRM_PANTHOR_OBJ_ARRAY(ARRAY_SIZE(qc), qc), |
| 668 |
.vm_id = pan_kmod_vm_handle(dev->kmod.vm), |
| 669 |
}; |
| 670 |
|
| 671 |
int ret = pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_GROUP_CREATE, &gc); |
| 672 |
if (ret) |
| 673 |
return panvk_errorf(dev, VK_ERROR_INITIALIZATION_FAILED, |
| 674 |
"Failed to create a scheduling group"); |
| 675 |
|
| 676 |
queue->group_handle = gc.group_handle; |
| 677 |
return VK_SUCCESS; |
| 678 |
} |
| 679 |
|
| 680 |
static void |
| 681 |
destroy_group(struct panvk_gpu_queue *queue) |
| 682 |
{ |
| 683 |
const struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 684 |
struct drm_panthor_group_destroy gd = { |
| 685 |
.group_handle = queue->group_handle, |
| 686 |
}; |
| 687 |
|
| 688 |
ASSERTED int ret = |
| 689 |
pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_GROUP_DESTROY, &gd); |
| 690 |
assert(!ret); |
| 691 |
} |
| 692 |
|
| 693 |
static VkResult |
| 694 |
init_tiler(struct panvk_gpu_queue *queue) |
| 695 |
{ |
| 696 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 697 |
const struct panvk_physical_device *phys_dev = |
| 698 |
to_panvk_physical_device(dev->vk.physical); |
| 699 |
struct panvk_tiler_heap *tiler_heap = &queue->tiler_heap; |
| 700 |
VkResult result; |
| 701 |
|
| 702 |
/* We allocate the tiler heap descriptor and geometry buffer in one go, |
| 703 |
* so we can pass it through a single 64-bit register to the VERTEX_TILER |
| 704 |
* command streams. */ |
| 705 |
struct panvk_pool_alloc_info alloc_info = { |
| 706 |
.size = (64 * 1024) + 4096, |
| 707 |
.alignment = 4096, |
| 708 |
}; |
| 709 |
|
| 710 |
tiler_heap->desc = panvk_pool_alloc_mem(&dev->mempools.rw, alloc_info); |
| 711 |
if (!panvk_priv_mem_check_alloc(tiler_heap->desc)) { |
| 712 |
result = panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 713 |
"Failed to create a tiler heap context"); |
| 714 |
goto err_free_desc; |
| 715 |
} |
| 716 |
|
| 717 |
tiler_heap->chunk_size = phys_dev->csf.tiler.chunk_size; |
| 718 |
|
| 719 |
alloc_info.size = get_fbd_size(true, MAX_RTS); |
| 720 |
alloc_info.alignment = pan_alignment(FRAMEBUFFER); |
| 721 |
tiler_heap->oom_fbd = panvk_pool_alloc_mem(&dev->mempools.rw, alloc_info); |
| 722 |
if (!panvk_priv_mem_check_alloc(tiler_heap->oom_fbd)) { |
| 723 |
result = panvk_errorf(dev, VK_ERROR_OUT_OF_DEVICE_MEMORY, |
| 724 |
"Failed to create a scratch FBD"); |
| 725 |
goto err_free_desc; |
| 726 |
} |
| 727 |
|
| 728 |
struct drm_panthor_tiler_heap_create thc = { |
| 729 |
.vm_id = pan_kmod_vm_handle(dev->kmod.vm), |
| 730 |
.chunk_size = tiler_heap->chunk_size, |
| 731 |
.initial_chunk_count = phys_dev->csf.tiler.initial_chunks, |
| 732 |
.max_chunks = phys_dev->csf.tiler.max_chunks, |
| 733 |
.target_in_flight = 65535, |
| 734 |
}; |
| 735 |
|
| 736 |
int ret = pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE, |
| 737 |
&thc); |
| 738 |
if (ret) { |
| 739 |
result = panvk_errorf(dev, VK_ERROR_INITIALIZATION_FAILED, |
| 740 |
"Failed to create a tiler heap context"); |
| 741 |
goto err_free_desc; |
| 742 |
} |
| 743 |
|
| 744 |
tiler_heap->context.handle = thc.handle; |
| 745 |
tiler_heap->context.dev_addr = thc.tiler_heap_ctx_gpu_va; |
| 746 |
|
| 747 |
panvk_priv_mem_write_desc(tiler_heap->desc, 0, TILER_HEAP, cfg) { |
| 748 |
cfg.size = tiler_heap->chunk_size; |
| 749 |
cfg.base = thc.first_heap_chunk_gpu_va; |
| 750 |
cfg.bottom = cfg.base + 64; |
| 751 |
cfg.top = cfg.base + cfg.size; |
| 752 |
} |
| 753 |
|
| 754 |
return VK_SUCCESS; |
| 755 |
|
| 756 |
err_free_desc: |
| 757 |
panvk_pool_free_mem(&tiler_heap->desc); |
| 758 |
panvk_pool_free_mem(&tiler_heap->oom_fbd); |
| 759 |
return result; |
| 760 |
} |
| 761 |
|
| 762 |
static void |
| 763 |
cleanup_tiler(struct panvk_gpu_queue *queue) |
| 764 |
{ |
| 765 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 766 |
struct panvk_tiler_heap *tiler_heap = &queue->tiler_heap; |
| 767 |
struct drm_panthor_tiler_heap_destroy thd = { |
| 768 |
.handle = tiler_heap->context.handle, |
| 769 |
}; |
| 770 |
ASSERTED int ret = |
| 771 |
pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY, &thd); |
| 772 |
assert(!ret); |
| 773 |
|
| 774 |
panvk_pool_free_mem(&tiler_heap->desc); |
| 775 |
panvk_pool_free_mem(&tiler_heap->oom_fbd); |
| 776 |
} |
| 777 |
|
| 778 |
struct panvk_queue_submit { |
| 779 |
const struct panvk_physical_device *phys_dev; |
| 780 |
struct panvk_device *dev; |
| 781 |
struct panvk_gpu_queue *queue; |
| 782 |
|
| 783 |
bool process_utrace; |
| 784 |
bool force_sync; |
| 785 |
|
| 786 |
uint32_t qsubmit_count; |
| 787 |
uint32_t wait_queue_mask; |
| 788 |
uint32_t signal_queue_mask; |
| 789 |
uint32_t req_resource_subqueue_mask; |
| 790 |
|
| 791 |
struct drm_panthor_queue_submit *qsubmits; |
| 792 |
struct drm_panthor_sync_op *wait_ops; |
| 793 |
struct drm_panthor_sync_op *signal_ops; |
| 794 |
|
| 795 |
struct { |
| 796 |
uint32_t queue_mask; |
| 797 |
enum panvk_subqueue_id first_subqueue; |
| 798 |
enum panvk_subqueue_id last_subqueue; |
| 799 |
bool needs_clone; |
| 800 |
const struct u_trace *last_ut; |
| 801 |
struct panvk_utrace_flush_data *data_storage; |
| 802 |
|
| 803 |
struct panvk_utrace_flush_data *data[PANVK_SUBQUEUE_COUNT]; |
| 804 |
} utrace; |
| 805 |
}; |
| 806 |
|
| 807 |
struct panvk_queue_submit_stack_storage { |
| 808 |
struct drm_panthor_queue_submit qsubmits[8]; |
| 809 |
struct drm_panthor_sync_op syncops[8]; |
| 810 |
}; |
| 811 |
|
| 812 |
static void |
| 813 |
panvk_queue_submit_init(struct panvk_queue_submit *submit, |
| 814 |
struct vk_queue *vk_queue) |
| 815 |
{ |
| 816 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 817 |
struct vk_device *vk_dev = vk_queue->base.device; |
| 818 |
|
| 819 |
*submit = (struct panvk_queue_submit){ |
| 820 |
.phys_dev = to_panvk_physical_device(vk_dev->physical), |
| 821 |
.dev = to_panvk_device(vk_dev), |
| 822 |
.queue = container_of(vk_queue, struct panvk_gpu_queue, vk), |
| 823 |
}; |
| 824 |
|
| 825 |
submit->process_utrace = |
| 826 |
u_trace_should_process(&submit->dev->utrace.utctx) && |
| 827 |
submit->phys_dev->kmod.dev->props.timestamp_frequency; |
| 828 |
|
| 829 |
submit->force_sync = PANVK_DEBUG(TRACE) || PANVK_DEBUG(SYNC); |
| 830 |
} |
| 831 |
|
| 832 |
static void |
| 833 |
panvk_queue_submit_init_storage( |
| 834 |
struct panvk_queue_submit *submit, const struct vk_queue_submit *vk_submit, |
| 835 |
struct panvk_queue_submit_stack_storage *stack_storage) |
| 836 |
{ |
| 837 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 838 |
submit->utrace.first_subqueue = PANVK_SUBQUEUE_COUNT; |
| 839 |
VkPipelineStageFlags2 cmd_stage_mask = VK_PIPELINE_STAGE_2_NONE; |
| 840 |
for (uint32_t i = 0; i < vk_submit->command_buffer_count; i++) { |
| 841 |
struct panvk_cmd_buffer *cmdbuf = container_of( |
| 842 |
vk_submit->command_buffers[i], struct panvk_cmd_buffer, vk); |
| 843 |
|
| 844 |
for (uint32_t j = 0; j < ARRAY_SIZE(cmdbuf->state.cs); j++) { |
| 845 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, j); |
| 846 |
assert(cs_is_valid(b)); |
| 847 |
if (cs_is_empty(b)) |
| 848 |
continue; |
| 849 |
|
| 850 |
cmd_stage_mask |= panvk_get_subqueue_stages(j); |
| 851 |
submit->qsubmit_count++; |
| 852 |
|
| 853 |
struct panvk_subqueue *subq = &submit->queue->subqueues[j]; |
| 854 |
/* If we need a resource the subqueue has not requested yet. */ |
| 855 |
if (b->req_resource_mask & (~subq->req_resource.mask)) { |
| 856 |
/* Ensure we do not need a resource not expected for this subqueue. */ |
| 857 |
assert(!(b->req_resource_mask & (~get_resource_mask(j)))); |
| 858 |
submit->qsubmit_count++; |
| 859 |
submit->req_resource_subqueue_mask |= BITFIELD_BIT(j); |
| 860 |
subq->req_resource.mask = get_resource_mask(j); |
| 861 |
} |
| 862 |
|
| 863 |
struct u_trace *ut = &cmdbuf->utrace.uts[j]; |
| 864 |
if (submit->process_utrace && u_trace_has_points(ut)) { |
| 865 |
submit->utrace.queue_mask |= BITFIELD_BIT(j); |
| 866 |
if (submit->utrace.first_subqueue == PANVK_SUBQUEUE_COUNT) |
| 867 |
submit->utrace.first_subqueue = j; |
| 868 |
submit->utrace.last_subqueue = j; |
| 869 |
submit->utrace.last_ut = ut; |
| 870 |
|
| 871 |
if (!(cmdbuf->flags & |
| 872 |
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) { |
| 873 |
/* we will follow the user cs with a timestamp copy cs */ |
| 874 |
submit->qsubmit_count++; |
| 875 |
submit->utrace.needs_clone = true; |
| 876 |
} |
| 877 |
} |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
/* wait_stages_mask is pipeline stages which limit |
| 882 |
* the second synchronization scope of a semaphore wait operation */ |
| 883 |
VkPipelineStageFlags2 wait_stages_mask = cmd_stage_mask; |
| 884 |
for (uint32_t i = 0; i < vk_submit->wait_count; i++) { |
| 885 |
wait_stages_mask |= vk_submit->waits[i].stage_mask; |
| 886 |
} |
| 887 |
|
| 888 |
/* signal_stages_mask is pipeline stages which limit |
| 889 |
* the first synchronization scope of a semaphore signal operation */ |
| 890 |
VkPipelineStageFlags2 signal_stages_mask = cmd_stage_mask; |
| 891 |
for (uint32_t i = 0; i < vk_submit->signal_count; i++) { |
| 892 |
signal_stages_mask |= vk_submit->signals[i].stage_mask; |
| 893 |
} |
| 894 |
|
| 895 |
/* if there is no cs in any subqueue */ |
| 896 |
if (cmd_stage_mask == VK_PIPELINE_STAGE_2_NONE) { |
| 897 |
/* signal stage mask is TOP_OF_PIPE/NONE, signal immediately */ |
| 898 |
if (signal_stages_mask == VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT || |
| 899 |
signal_stages_mask == VK_PIPELINE_STAGE_2_NONE) { |
| 900 |
signal_stages_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 901 |
} |
| 902 |
|
| 903 |
/* wait stage mask is BOTTOM_OF_PIPE/NONE, wait deferred */ |
| 904 |
if (wait_stages_mask == VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT || |
| 905 |
wait_stages_mask == VK_PIPELINE_STAGE_2_NONE) { |
| 906 |
wait_stages_mask = panvk_get_subqueue_stages(PANVK_SUBQUEUE_FRAGMENT) | |
| 907 |
panvk_get_subqueue_stages(PANVK_SUBQUEUE_COMPUTE); |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
submit->wait_queue_mask = |
| 912 |
vk_stages_to_subqueue_mask(wait_stages_mask, SYNC_SCOPE_SECOND); |
| 913 |
|
| 914 |
submit->signal_queue_mask = |
| 915 |
vk_stages_to_subqueue_mask(signal_stages_mask, SYNC_SCOPE_FIRST) | |
| 916 |
submit->utrace.queue_mask; |
| 917 |
|
| 918 |
/* Signal all subqueues if force_sync */ |
| 919 |
if (submit->force_sync) { |
| 920 |
submit->signal_queue_mask |= BITFIELD_MASK(PANVK_SUBQUEUE_COUNT); |
| 921 |
} |
| 922 |
|
| 923 |
uint32_t syncop_count = 0; |
| 924 |
|
| 925 |
/* We add sync-only queue submits to place our wait/signal operations. */ |
| 926 |
submit->qsubmit_count += util_bitcount(submit->wait_queue_mask); |
| 927 |
syncop_count += vk_submit->wait_count; |
| 928 |
|
| 929 |
submit->qsubmit_count += util_bitcount(submit->signal_queue_mask); |
| 930 |
syncop_count += util_bitcount(submit->signal_queue_mask); |
| 931 |
|
| 932 |
submit->qsubmits = |
| 933 |
submit->qsubmit_count <= ARRAY_SIZE(stack_storage->qsubmits) |
| 934 |
? stack_storage->qsubmits |
| 935 |
: malloc(sizeof(*submit->qsubmits) * submit->qsubmit_count); |
| 936 |
|
| 937 |
submit->wait_ops = syncop_count <= ARRAY_SIZE(stack_storage->syncops) |
| 938 |
? stack_storage->syncops |
| 939 |
: malloc(sizeof(*submit->wait_ops) * syncop_count); |
| 940 |
submit->signal_ops = submit->wait_ops + vk_submit->wait_count; |
| 941 |
|
| 942 |
/* reset so that we can initialize submit->qsubmits incrementally */ |
| 943 |
submit->qsubmit_count = 0; |
| 944 |
|
| 945 |
if (submit->utrace.queue_mask) { |
| 946 |
submit->utrace.data_storage = |
| 947 |
malloc(sizeof(*submit->utrace.data_storage) * |
| 948 |
util_bitcount(submit->utrace.queue_mask)); |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
static void |
| 953 |
panvk_queue_submit_cleanup_storage( |
| 954 |
struct panvk_queue_submit *submit, |
| 955 |
const struct panvk_queue_submit_stack_storage *stack_storage) |
| 956 |
{ |
| 957 |
if (submit->qsubmits != stack_storage->qsubmits) |
| 958 |
free(submit->qsubmits); |
| 959 |
if (submit->wait_ops != stack_storage->syncops) |
| 960 |
free(submit->wait_ops); |
| 961 |
|
| 962 |
/* either no utrace flush data or the data has been transferred to u_trace */ |
| 963 |
assert(!submit->utrace.data_storage); |
| 964 |
} |
| 965 |
|
| 966 |
static void |
| 967 |
panvk_queue_submit_init_utrace(struct panvk_queue_submit *submit, |
| 968 |
const struct vk_queue_submit *vk_submit) |
| 969 |
{ |
| 970 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 971 |
|
| 972 |
if (!submit->utrace.queue_mask) |
| 973 |
return; |
| 974 |
|
| 975 |
/* u_trace_context processes trace events in order. We want to make sure |
| 976 |
* it waits for the timestamp writes before processing the first event and |
| 977 |
* it can free the flush data after processing the last event. |
| 978 |
*/ |
| 979 |
struct panvk_utrace_flush_data *next = submit->utrace.data_storage; |
| 980 |
submit->utrace.data[submit->utrace.last_subqueue] = next++; |
| 981 |
submit->utrace.data[submit->utrace.last_subqueue]->free_self = true; |
| 982 |
|
| 983 |
u_foreach_bit(i, submit->utrace.queue_mask) { |
| 984 |
if (i != submit->utrace.last_subqueue) |
| 985 |
submit->utrace.data[i] = next++; |
| 986 |
|
| 987 |
const bool wait = i == submit->utrace.first_subqueue; |
| 988 |
*submit->utrace.data[i] = (struct panvk_utrace_flush_data){ |
| 989 |
.subqueue = i, |
| 990 |
.sync = wait ? submit->queue->utrace.sync : NULL, |
| 991 |
.wait_value = wait ? submit->queue->utrace.next_value : 0, |
| 992 |
.free_self = false, |
| 993 |
}; |
| 994 |
} |
| 995 |
} |
| 996 |
|
| 997 |
static void |
| 998 |
panvk_queue_submit_init_req_resource(struct panvk_queue_submit *submit) |
| 999 |
{ |
| 1000 |
if (!submit->req_resource_subqueue_mask) |
| 1001 |
return; |
| 1002 |
|
| 1003 |
struct panvk_device *dev = submit->dev; |
| 1004 |
uint32_t flush_id = panthor_kmod_get_flush_id(dev->kmod.dev); |
| 1005 |
|
| 1006 |
u_foreach_bit(i, submit->req_resource_subqueue_mask) { |
| 1007 |
struct panvk_subqueue *subq = &submit->queue->subqueues[i]; |
| 1008 |
submit->qsubmits[submit->qsubmit_count++] = |
| 1009 |
(struct drm_panthor_queue_submit){ |
| 1010 |
.queue_index = i, |
| 1011 |
.stream_size = subq->req_resource.cs_buffer_size, |
| 1012 |
.stream_addr = subq->req_resource.cs_buffer_addr, |
| 1013 |
.latest_flush = flush_id, |
| 1014 |
}; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
static void |
| 1019 |
panvk_queue_submit_init_waits(struct panvk_queue_submit *submit, |
| 1020 |
const struct vk_queue_submit *vk_submit) |
| 1021 |
{ |
| 1022 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 1023 |
if (!submit->wait_queue_mask) |
| 1024 |
return; |
| 1025 |
|
| 1026 |
for (uint32_t i = 0; i < vk_submit->wait_count; i++) { |
| 1027 |
const struct vk_sync_wait *wait = &vk_submit->waits[i]; |
| 1028 |
const struct vk_drm_syncobj *syncobj = vk_sync_as_drm_syncobj(wait->sync); |
| 1029 |
assert(syncobj); |
| 1030 |
|
| 1031 |
submit->wait_ops[i] = (struct drm_panthor_sync_op){ |
| 1032 |
.flags = (syncobj->base.flags & VK_SYNC_IS_TIMELINE |
| 1033 |
? DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ |
| 1034 |
: DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ) | |
| 1035 |
DRM_PANTHOR_SYNC_OP_WAIT, |
| 1036 |
.handle = syncobj->syncobj, |
| 1037 |
.timeline_value = wait->wait_value, |
| 1038 |
}; |
| 1039 |
} |
| 1040 |
|
| 1041 |
u_foreach_bit(i, submit->wait_queue_mask) { |
| 1042 |
submit->qsubmits[submit->qsubmit_count++] = |
| 1043 |
(struct drm_panthor_queue_submit){ |
| 1044 |
.queue_index = i, |
| 1045 |
.syncs = |
| 1046 |
DRM_PANTHOR_OBJ_ARRAY(vk_submit->wait_count, submit->wait_ops), |
| 1047 |
}; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
static void |
| 1052 |
panvk_queue_submit_init_cmdbufs(struct panvk_queue_submit *submit, |
| 1053 |
const struct vk_queue_submit *vk_submit) |
| 1054 |
{ |
| 1055 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 1056 |
struct panvk_device *dev = submit->dev; |
| 1057 |
|
| 1058 |
for (uint32_t i = 0; i < vk_submit->command_buffer_count; i++) { |
| 1059 |
struct panvk_cmd_buffer *cmdbuf = container_of( |
| 1060 |
vk_submit->command_buffers[i], struct panvk_cmd_buffer, vk); |
| 1061 |
|
| 1062 |
uint32_t flush_id = panthor_kmod_get_flush_id(dev->kmod.dev); |
| 1063 |
|
| 1064 |
for (uint32_t j = 0; j < ARRAY_SIZE(cmdbuf->state.cs); j++) { |
| 1065 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, j); |
| 1066 |
if (cs_is_empty(b)) |
| 1067 |
continue; |
| 1068 |
|
| 1069 |
submit->qsubmits[submit->qsubmit_count++] = |
| 1070 |
(struct drm_panthor_queue_submit){ |
| 1071 |
.queue_index = j, |
| 1072 |
.stream_size = cs_root_chunk_size(b), |
| 1073 |
.stream_addr = cs_root_chunk_gpu_addr(b), |
| 1074 |
.latest_flush = flush_id, |
| 1075 |
}; |
| 1076 |
} |
| 1077 |
|
| 1078 |
if (util_bitcount(submit->utrace.queue_mask) > 0) |
| 1079 |
flush_id = panthor_kmod_get_flush_id(dev->kmod.dev); |
| 1080 |
|
| 1081 |
u_foreach_bit(j, submit->utrace.queue_mask) { |
| 1082 |
struct u_trace *ut = &cmdbuf->utrace.uts[j]; |
| 1083 |
|
| 1084 |
if (!u_trace_has_points(ut)) |
| 1085 |
continue; |
| 1086 |
|
| 1087 |
/* The last subqueue frees the flush data itself. */ |
| 1088 |
bool free_data = ut == submit->utrace.last_ut; |
| 1089 |
|
| 1090 |
struct u_trace clone_ut; |
| 1091 |
if (!(cmdbuf->flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT)) { |
| 1092 |
u_trace_init(&clone_ut, &dev->utrace.utctx); |
| 1093 |
|
| 1094 |
const uint64_t root_buf_size = sizeof(uint64_t) * 1024; |
| 1095 |
struct panvk_utrace_buf *cs_root_buf = |
| 1096 |
panvk_utrace_create_buffer(&dev->utrace.utctx, root_buf_size); |
| 1097 |
assert(cs_root_buf); |
| 1098 |
/* For every sq, the cs buffer needs to be freed. */ |
| 1099 |
free_data = true; |
| 1100 |
|
| 1101 |
const struct cs_buffer cs_root = (struct cs_buffer){ |
| 1102 |
.cpu = cs_root_buf->host, |
| 1103 |
.gpu = cs_root_buf->dev, |
| 1104 |
.capacity = root_buf_size / sizeof(uint64_t), |
| 1105 |
}; |
| 1106 |
|
| 1107 |
submit->utrace.data[j]->clone_cs_root = cs_root_buf; |
| 1108 |
struct cs_builder clone_builder; |
| 1109 |
panvk_per_arch(utrace_clone_init_builder)(&clone_builder, dev, |
| 1110 |
&cs_root); |
| 1111 |
|
| 1112 |
u_trace_clone_append( |
| 1113 |
u_trace_begin_iterator(ut), u_trace_end_iterator(ut), &clone_ut, |
| 1114 |
&clone_builder, panvk_per_arch(utrace_copy_buffer)); |
| 1115 |
|
| 1116 |
panvk_per_arch(utrace_clone_finish_builder)(&clone_builder); |
| 1117 |
|
| 1118 |
submit->qsubmits[submit->qsubmit_count++] = |
| 1119 |
(struct drm_panthor_queue_submit){ |
| 1120 |
.queue_index = j, |
| 1121 |
.stream_size = cs_root_chunk_size(&clone_builder), |
| 1122 |
.stream_addr = cs_root_chunk_gpu_addr(&clone_builder), |
| 1123 |
.latest_flush = flush_id, |
| 1124 |
}; |
| 1125 |
|
| 1126 |
ut = &clone_ut; |
| 1127 |
} |
| 1128 |
|
| 1129 |
u_trace_flush(ut, submit->utrace.data[j], dev->vk.current_frame, |
| 1130 |
free_data); |
| 1131 |
} |
| 1132 |
} |
| 1133 |
|
| 1134 |
/* we've transferred the data ownership to utrace, if any */ |
| 1135 |
submit->utrace.data_storage = NULL; |
| 1136 |
} |
| 1137 |
|
| 1138 |
static void |
| 1139 |
panvk_queue_submit_init_signals(struct panvk_queue_submit *submit, |
| 1140 |
const struct vk_queue_submit *vk_submit) |
| 1141 |
{ |
| 1142 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 1143 |
struct panvk_gpu_queue *queue = submit->queue; |
| 1144 |
|
| 1145 |
uint32_t signal_op = 0; |
| 1146 |
u_foreach_bit(i, submit->signal_queue_mask) { |
| 1147 |
submit->signal_ops[signal_op] = (struct drm_panthor_sync_op){ |
| 1148 |
.flags = DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ | |
| 1149 |
DRM_PANTHOR_SYNC_OP_SIGNAL, |
| 1150 |
.handle = queue->syncobj_handle, |
| 1151 |
.timeline_value = signal_op + 1, |
| 1152 |
}; |
| 1153 |
|
| 1154 |
submit->qsubmits[submit->qsubmit_count++] = |
| 1155 |
(struct drm_panthor_queue_submit){ |
| 1156 |
.queue_index = i, |
| 1157 |
.syncs = DRM_PANTHOR_OBJ_ARRAY(1, &submit->signal_ops[signal_op++]), |
| 1158 |
}; |
| 1159 |
} |
| 1160 |
} |
| 1161 |
|
| 1162 |
static VkResult |
| 1163 |
panvk_queue_submit_ioctl(struct panvk_queue_submit *submit) |
| 1164 |
{ |
| 1165 |
const struct panvk_device *dev = submit->dev; |
| 1166 |
struct panvk_gpu_queue *queue = submit->queue; |
| 1167 |
int ret; |
| 1168 |
|
| 1169 |
if (PANVK_DEBUG(TRACE)) { |
| 1170 |
/* If we're tracing, we need to reset the desc ringbufs and the CS |
| 1171 |
* tracebuf. */ |
| 1172 |
for (uint32_t i = 0; i < ARRAY_SIZE(queue->subqueues); i++) { |
| 1173 |
panvk_priv_mem_rmw(queue->subqueues[i].context, 0, |
| 1174 |
struct panvk_cs_subqueue_context, ctx) { |
| 1175 |
if (ctx->render.desc_ringbuf.ptr) { |
| 1176 |
ctx->render.desc_ringbuf.ptr = |
| 1177 |
queue->render_desc_ringbuf.addr.dev; |
| 1178 |
ctx->render.desc_ringbuf.pos = 0; |
| 1179 |
} |
| 1180 |
|
| 1181 |
if (ctx->debug.tracebuf.cs) |
| 1182 |
ctx->debug.tracebuf.cs = queue->subqueues[i].tracebuf.addr.dev; |
| 1183 |
} |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
/* Flush pending synchronization requests before submitting the job, to |
| 1188 |
* make sure things are GPU-visible. */ |
| 1189 |
pan_kmod_flush_bo_map_syncs(dev->kmod.dev); |
| 1190 |
|
| 1191 |
struct drm_panthor_group_submit gsubmit = { |
| 1192 |
.group_handle = queue->group_handle, |
| 1193 |
.queue_submits = |
| 1194 |
DRM_PANTHOR_OBJ_ARRAY(submit->qsubmit_count, submit->qsubmits), |
| 1195 |
}; |
| 1196 |
|
| 1197 |
ret = pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_GROUP_SUBMIT, &gsubmit); |
| 1198 |
if (ret) |
| 1199 |
return vk_queue_set_lost(&queue->vk, "GROUP_SUBMIT: %m"); |
| 1200 |
|
| 1201 |
return VK_SUCCESS; |
| 1202 |
} |
| 1203 |
|
| 1204 |
static void |
| 1205 |
panvk_queue_submit_process_signals(struct panvk_queue_submit *submit, |
| 1206 |
const struct vk_queue_submit *vk_submit) |
| 1207 |
{ |
| 1208 |
struct panvk_device *dev = submit->dev; |
| 1209 |
struct panvk_gpu_queue *queue = submit->queue; |
| 1210 |
ASSERTED int ret; |
| 1211 |
|
| 1212 |
if (!submit->signal_queue_mask) |
| 1213 |
return; |
| 1214 |
|
| 1215 |
if (submit->force_sync) { |
| 1216 |
uint64_t point = util_bitcount(submit->signal_queue_mask); |
| 1217 |
ret = drmSyncobjTimelineWait(dev->drm_fd, &queue->syncobj_handle, |
| 1218 |
&point, 1, INT64_MAX, |
| 1219 |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, NULL); |
| 1220 |
assert(!ret); |
| 1221 |
} |
| 1222 |
|
| 1223 |
for (uint32_t i = 0; i < vk_submit->signal_count; i++) { |
| 1224 |
const struct vk_sync_signal *signal = &vk_submit->signals[i]; |
| 1225 |
const struct vk_drm_syncobj *syncobj = |
| 1226 |
vk_sync_as_drm_syncobj(signal->sync); |
| 1227 |
assert(syncobj); |
| 1228 |
|
| 1229 |
drmSyncobjTransfer(dev->drm_fd, syncobj->syncobj, signal->signal_value, |
| 1230 |
queue->syncobj_handle, 0, 0); |
| 1231 |
} |
| 1232 |
|
| 1233 |
if (submit->utrace.queue_mask) { |
| 1234 |
const struct vk_drm_syncobj *syncobj = |
| 1235 |
vk_sync_as_drm_syncobj(queue->utrace.sync); |
| 1236 |
|
| 1237 |
drmSyncobjTransfer(dev->drm_fd, syncobj->syncobj, |
| 1238 |
queue->utrace.next_value++, queue->syncobj_handle, 0, |
| 1239 |
0); |
| 1240 |
|
| 1241 |
/* process flushed events after the syncobj is set up */ |
| 1242 |
u_trace_context_process(&dev->utrace.utctx, false); |
| 1243 |
} |
| 1244 |
|
| 1245 |
drmSyncobjReset(dev->drm_fd, &queue->syncobj_handle, 1); |
| 1246 |
} |
| 1247 |
|
| 1248 |
static void |
| 1249 |
panvk_queue_submit_process_debug(const struct panvk_queue_submit *submit, |
| 1250 |
const struct vk_queue_submit *vk_submit) |
| 1251 |
{ |
| 1252 |
struct panvk_gpu_queue *queue = submit->queue; |
| 1253 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 1254 |
struct pandecode_context *decode_ctx = submit->dev->debug.decode_ctx; |
| 1255 |
|
| 1256 |
if (PANVK_DEBUG(TRACE)) { |
| 1257 |
const struct pan_kmod_dev_props *props = |
| 1258 |
&submit->phys_dev->kmod.dev->props; |
| 1259 |
|
| 1260 |
/* First we invalidate all desc buffers to make sure we see GPU updates |
| 1261 |
* on those. */ |
| 1262 |
for (uint32_t i = 0; i < vk_submit->command_buffer_count; i++) { |
| 1263 |
struct panvk_cmd_buffer *cmdbuf = container_of( |
| 1264 |
vk_submit->command_buffers[i], struct panvk_cmd_buffer, vk); |
| 1265 |
|
| 1266 |
panvk_pool_invalidate_maps(&cmdbuf->desc_pool); |
| 1267 |
} |
| 1268 |
|
| 1269 |
pan_kmod_flush_bo_map_syncs(dev->kmod.dev); |
| 1270 |
|
| 1271 |
for (uint32_t i = 0; i < submit->qsubmit_count; i++) { |
| 1272 |
const struct drm_panthor_queue_submit *qsubmit = &submit->qsubmits[i]; |
| 1273 |
if (!qsubmit->stream_size) |
| 1274 |
continue; |
| 1275 |
|
| 1276 |
pandecode_user_msg(decode_ctx, "CS %d on subqueue %d binaries\n\n", i, |
| 1277 |
qsubmit->queue_index); |
| 1278 |
pandecode_cs_binary(decode_ctx, qsubmit->stream_addr, |
| 1279 |
qsubmit->stream_size, props->gpu_id); |
| 1280 |
pandecode_user_msg(decode_ctx, "\n"); |
| 1281 |
} |
| 1282 |
|
| 1283 |
for (uint32_t i = 0; i < ARRAY_SIZE(queue->subqueues); i++) { |
| 1284 |
panvk_priv_mem_readback(queue->subqueues[i].context, 0, |
| 1285 |
struct panvk_cs_subqueue_context, ctx) { |
| 1286 |
size_t trace_size = |
| 1287 |
ctx->debug.tracebuf.cs - queue->subqueues[i].tracebuf.addr.dev; |
| 1288 |
|
| 1289 |
if (trace_size) { |
| 1290 |
assert( |
| 1291 |
trace_size <= queue->subqueues[i].tracebuf.size || |
| 1292 |
!"OOB access on the CS tracebuf, pass a bigger PANVK_CS_TRACEBUF_SIZE"); |
| 1293 |
|
| 1294 |
assert( |
| 1295 |
!ctx->render.desc_ringbuf.ptr || |
| 1296 |
ctx->render.desc_ringbuf.pos <= |
| 1297 |
queue->render_desc_ringbuf.size || |
| 1298 |
!"OOB access on the desc tracebuf, pass a bigger PANVK_DESC_TRACEBUF_SIZE"); |
| 1299 |
|
| 1300 |
uint64_t trace = queue->subqueues[i].tracebuf.addr.dev; |
| 1301 |
|
| 1302 |
pandecode_user_msg(decode_ctx, "\nCS traces on subqueue %d\n\n", |
| 1303 |
i); |
| 1304 |
pandecode_cs_trace(decode_ctx, trace, trace_size, props->gpu_id); |
| 1305 |
pandecode_user_msg(decode_ctx, "\n"); |
| 1306 |
} |
| 1307 |
} |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
if (PANVK_DEBUG(DUMP)) |
| 1312 |
pandecode_dump_mappings(decode_ctx); |
| 1313 |
|
| 1314 |
if (PANVK_DEBUG(TRACE)) |
| 1315 |
pandecode_next_frame(decode_ctx); |
| 1316 |
|
| 1317 |
/* validate last after the command streams are dumped */ |
| 1318 |
if (submit->force_sync) |
| 1319 |
panvk_per_arch(gpu_queue_check_status)(&queue->vk); |
| 1320 |
} |
| 1321 |
|
| 1322 |
VkResult |
| 1323 |
panvk_per_arch(gpu_queue_submit)(struct vk_queue *vk_queue, struct vk_queue_submit *vk_submit) |
| 1324 |
{ |
| 1325 |
PAN_TRACE_FUNC(PAN_TRACE_VK_CSF); |
| 1326 |
struct panvk_queue_submit_stack_storage stack_storage; |
| 1327 |
struct panvk_queue_submit submit; |
| 1328 |
VkResult result = VK_SUCCESS; |
| 1329 |
|
| 1330 |
if (vk_queue_is_lost(vk_queue)) |
| 1331 |
return VK_ERROR_DEVICE_LOST; |
| 1332 |
|
| 1333 |
panvk_queue_submit_init(&submit, vk_queue); |
| 1334 |
panvk_queue_submit_init_storage(&submit, vk_submit, &stack_storage); |
| 1335 |
panvk_queue_submit_init_utrace(&submit, vk_submit); |
| 1336 |
panvk_queue_submit_init_req_resource(&submit); |
| 1337 |
panvk_queue_submit_init_waits(&submit, vk_submit); |
| 1338 |
panvk_queue_submit_init_cmdbufs(&submit, vk_submit); |
| 1339 |
panvk_queue_submit_init_signals(&submit, vk_submit); |
| 1340 |
|
| 1341 |
result = panvk_queue_submit_ioctl(&submit); |
| 1342 |
if (result != VK_SUCCESS) |
| 1343 |
goto out; |
| 1344 |
|
| 1345 |
panvk_queue_submit_process_signals(&submit, vk_submit); |
| 1346 |
panvk_queue_submit_process_debug(&submit, vk_submit); |
| 1347 |
|
| 1348 |
out: |
| 1349 |
panvk_queue_submit_cleanup_storage(&submit, &stack_storage); |
| 1350 |
return result; |
| 1351 |
} |
| 1352 |
|
| 1353 |
static enum drm_panthor_group_priority |
| 1354 |
get_panthor_group_priority(const VkDeviceQueueCreateInfo *create_info) |
| 1355 |
{ |
| 1356 |
const VkDeviceQueueGlobalPriorityCreateInfoKHR *priority_info = |
| 1357 |
vk_find_struct_const(create_info->pNext, |
| 1358 |
DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_KHR); |
| 1359 |
const VkQueueGlobalPriorityKHR priority = |
| 1360 |
priority_info ? priority_info->globalPriority |
| 1361 |
: VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR; |
| 1362 |
|
| 1363 |
switch (priority) { |
| 1364 |
case VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR: |
| 1365 |
return PANTHOR_GROUP_PRIORITY_LOW; |
| 1366 |
case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR: |
| 1367 |
return PANTHOR_GROUP_PRIORITY_MEDIUM; |
| 1368 |
case VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR: |
| 1369 |
return PANTHOR_GROUP_PRIORITY_HIGH; |
| 1370 |
case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR: |
| 1371 |
return PANTHOR_GROUP_PRIORITY_REALTIME; |
| 1372 |
default: |
| 1373 |
UNREACHABLE("Invalid global priority"); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
VkResult |
| 1378 |
panvk_per_arch(create_gpu_queue)(struct panvk_device *dev, |
| 1379 |
const VkDeviceQueueCreateInfo *create_info, |
| 1380 |
uint32_t queue_idx, |
| 1381 |
struct vk_queue **out_queue) |
| 1382 |
{ |
| 1383 |
struct panvk_gpu_queue *queue = vk_zalloc(&dev->vk.alloc, sizeof(*queue), 8, |
| 1384 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1385 |
if (!queue) |
| 1386 |
return panvk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1387 |
|
| 1388 |
VkResult result = |
| 1389 |
vk_queue_init(&queue->vk, &dev->vk, create_info, queue_idx); |
| 1390 |
if (result != VK_SUCCESS) |
| 1391 |
goto err_free_queue; |
| 1392 |
|
| 1393 |
int ret = drmSyncobjCreate(dev->drm_fd, 0, &queue->syncobj_handle); |
| 1394 |
if (ret) { |
| 1395 |
result = panvk_errorf(dev, VK_ERROR_INITIALIZATION_FAILED, |
| 1396 |
"Failed to create our internal sync object"); |
| 1397 |
goto err_finish_queue; |
| 1398 |
} |
| 1399 |
|
| 1400 |
result = init_tiler(queue); |
| 1401 |
if (result != VK_SUCCESS) |
| 1402 |
goto err_destroy_syncobj; |
| 1403 |
|
| 1404 |
const VkDeviceQueueShaderCoreControlCreateInfoARM *core_ctrl = |
| 1405 |
vk_find_struct_const(create_info->pNext, |
| 1406 |
DEVICE_QUEUE_SHADER_CORE_CONTROL_CREATE_INFO_ARM); |
| 1407 |
|
| 1408 |
result = create_group(queue, get_panthor_group_priority(create_info), |
| 1409 |
core_ctrl ? core_ctrl->shaderCoreCount : 0); |
| 1410 |
if (result != VK_SUCCESS) |
| 1411 |
goto err_cleanup_tiler; |
| 1412 |
|
| 1413 |
result = init_queue(queue); |
| 1414 |
if (result != VK_SUCCESS) |
| 1415 |
goto err_destroy_group; |
| 1416 |
|
| 1417 |
queue->vk.driver_submit = panvk_per_arch(gpu_queue_submit); |
| 1418 |
*out_queue = &queue->vk; |
| 1419 |
return VK_SUCCESS; |
| 1420 |
|
| 1421 |
err_destroy_group: |
| 1422 |
destroy_group(queue); |
| 1423 |
|
| 1424 |
err_cleanup_tiler: |
| 1425 |
cleanup_tiler(queue); |
| 1426 |
|
| 1427 |
err_destroy_syncobj: |
| 1428 |
drmSyncobjDestroy(dev->drm_fd, queue->syncobj_handle); |
| 1429 |
|
| 1430 |
err_finish_queue: |
| 1431 |
vk_queue_finish(&queue->vk); |
| 1432 |
|
| 1433 |
err_free_queue: |
| 1434 |
vk_free(&dev->vk.alloc, queue); |
| 1435 |
return result; |
| 1436 |
} |
| 1437 |
|
| 1438 |
void |
| 1439 |
panvk_per_arch(destroy_gpu_queue)(struct vk_queue *vk_queue) |
| 1440 |
{ |
| 1441 |
struct panvk_gpu_queue *queue = container_of(vk_queue, struct panvk_gpu_queue, vk); |
| 1442 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 1443 |
|
| 1444 |
cleanup_queue(queue); |
| 1445 |
destroy_group(queue); |
| 1446 |
cleanup_tiler(queue); |
| 1447 |
drmSyncobjDestroy(dev->drm_fd, queue->syncobj_handle); |
| 1448 |
vk_queue_finish(&queue->vk); |
| 1449 |
vk_free(&dev->vk.alloc, queue); |
| 1450 |
} |
| 1451 |
|
| 1452 |
VkResult |
| 1453 |
panvk_per_arch(gpu_queue_check_status)(struct vk_queue *vk_queue) |
| 1454 |
{ |
| 1455 |
struct panvk_gpu_queue *queue = container_of(vk_queue, struct panvk_gpu_queue, vk); |
| 1456 |
struct panvk_device *dev = to_panvk_device(queue->vk.base.device); |
| 1457 |
struct drm_panthor_group_get_state state = { |
| 1458 |
.group_handle = queue->group_handle, |
| 1459 |
}; |
| 1460 |
|
| 1461 |
/* check for CS error and treat it as device lost */ |
| 1462 |
for (uint32_t i = 0; i < PANVK_SUBQUEUE_COUNT; i++) { |
| 1463 |
panvk_priv_mem_readback(queue->subqueues[i].context, 0, |
| 1464 |
struct panvk_cs_subqueue_context, subq_ctx) { |
| 1465 |
if (subq_ctx->last_error != 0) { |
| 1466 |
/* Check printf buffer one more time before exiting */ |
| 1467 |
u_printf_with_ctx(stdout, &dev->printf.ctx); |
| 1468 |
|
| 1469 |
return vk_queue_set_lost(&queue->vk, "CS_FAULT"); |
| 1470 |
} |
| 1471 |
} |
| 1472 |
} |
| 1473 |
|
| 1474 |
int ret = pan_kmod_ioctl(dev->drm_fd, DRM_IOCTL_PANTHOR_GROUP_GET_STATE, |
| 1475 |
&state); |
| 1476 |
if (!ret && !state.state) |
| 1477 |
return VK_SUCCESS; |
| 1478 |
|
| 1479 |
/* Check printf buffer one more time before exiting */ |
| 1480 |
u_printf_with_ctx(stdout, &dev->printf.ctx); |
| 1481 |
|
| 1482 |
vk_queue_set_lost(&queue->vk, |
| 1483 |
"group state: err=%d, state=0x%x, fatal_queues=0x%x", ret, |
| 1484 |
state.state, state.fatal_queues); |
| 1485 |
|
| 1486 |
return VK_ERROR_DEVICE_LOST; |
| 1487 |
} |