| 1 |
/* |
| 2 |
* Copyright © 2021 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 "genxml/gen_macros.h" |
| 13 |
|
| 14 |
#include "panvk_buffer.h" |
| 15 |
#include "panvk_cmd_alloc.h" |
| 16 |
#include "panvk_cmd_buffer.h" |
| 17 |
#include "panvk_cmd_desc_state.h" |
| 18 |
#include "panvk_cmd_draw.h" |
| 19 |
#include "panvk_cmd_frame_shaders.h" |
| 20 |
#include "panvk_cmd_pool.h" |
| 21 |
#include "panvk_cmd_push_constant.h" |
| 22 |
#include "panvk_device.h" |
| 23 |
#include "panvk_entrypoints.h" |
| 24 |
#include "panvk_instance.h" |
| 25 |
#include "panvk_meta.h" |
| 26 |
#include "panvk_physical_device.h" |
| 27 |
#include "panvk_priv_bo.h" |
| 28 |
|
| 29 |
#include "pan_desc.h" |
| 30 |
#include "pan_encoder.h" |
| 31 |
#include "pan_props.h" |
| 32 |
#include "pan_samples.h" |
| 33 |
|
| 34 |
#include "vk_descriptor_update_template.h" |
| 35 |
#include "vk_format.h" |
| 36 |
|
| 37 |
static VkResult |
| 38 |
panvk_cmd_prepare_fragment_job(struct panvk_cmd_buffer *cmdbuf, uint64_t fbd) |
| 39 |
{ |
| 40 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 41 |
struct panvk_batch *batch = cmdbuf->cur_batch; |
| 42 |
struct pan_ptr job_ptr = panvk_cmd_alloc_desc(cmdbuf, FRAGMENT_JOB); |
| 43 |
|
| 44 |
if (!job_ptr.gpu) |
| 45 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 46 |
|
| 47 |
pan_section_pack(job_ptr.cpu, FRAGMENT_JOB, PAYLOAD, payload) { |
| 48 |
assert(pan_fb_bbox_is_valid(fb->tiling_area_px)); |
| 49 |
payload.bound_min_x = fb->tiling_area_px.min_x >> MALI_TILE_SHIFT; |
| 50 |
payload.bound_min_y = fb->tiling_area_px.min_y >> MALI_TILE_SHIFT; |
| 51 |
payload.bound_max_x = fb->tiling_area_px.max_x >> MALI_TILE_SHIFT; |
| 52 |
payload.bound_max_y = fb->tiling_area_px.max_y >> MALI_TILE_SHIFT; |
| 53 |
|
| 54 |
payload.framebuffer = fbd; |
| 55 |
} |
| 56 |
|
| 57 |
pan_section_pack(job_ptr.cpu, FRAGMENT_JOB, HEADER, header) { |
| 58 |
header.type = MALI_JOB_TYPE_FRAGMENT; |
| 59 |
header.index = 1; |
| 60 |
} |
| 61 |
|
| 62 |
pan_jc_add_job(&batch->frag_jc, MALI_JOB_TYPE_FRAGMENT, false, false, 0, 0, |
| 63 |
&job_ptr, false); |
| 64 |
util_dynarray_append(&batch->jobs, job_ptr.cpu); |
| 65 |
return VK_SUCCESS; |
| 66 |
} |
| 67 |
|
| 68 |
void |
| 69 |
panvk_per_arch(cmd_close_batch)(struct panvk_cmd_buffer *cmdbuf) |
| 70 |
{ |
| 71 |
struct panvk_batch *batch = cmdbuf->cur_batch; |
| 72 |
|
| 73 |
if (!batch) |
| 74 |
return; |
| 75 |
|
| 76 |
assert(batch); |
| 77 |
|
| 78 |
if (!batch->fb.desc.gpu && !batch->vtc_jc.first_job) { |
| 79 |
if (util_dynarray_num_elements(&batch->event_ops, |
| 80 |
struct panvk_cmd_event_op) == 0) { |
| 81 |
/* Content-less batch, let's drop it */ |
| 82 |
vk_free(&cmdbuf->vk.pool->alloc, batch); |
| 83 |
} else { |
| 84 |
/* Batch has no jobs but is needed for synchronization, let's add a |
| 85 |
* NULL job so the SUBMIT ioctl doesn't choke on it. |
| 86 |
*/ |
| 87 |
struct pan_ptr ptr = panvk_cmd_alloc_desc(cmdbuf, JOB_HEADER); |
| 88 |
|
| 89 |
if (ptr.gpu) { |
| 90 |
util_dynarray_append(&batch->jobs, ptr.cpu); |
| 91 |
pan_jc_add_job(&batch->vtc_jc, MALI_JOB_TYPE_NULL, false, false, 0, |
| 92 |
0, &ptr, false); |
| 93 |
} |
| 94 |
|
| 95 |
list_addtail(&batch->node, &cmdbuf->batches); |
| 96 |
} |
| 97 |
cmdbuf->cur_batch = NULL; |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 102 |
struct panvk_physical_device *phys_dev = |
| 103 |
to_panvk_physical_device(dev->vk.physical); |
| 104 |
|
| 105 |
list_addtail(&batch->node, &cmdbuf->batches); |
| 106 |
|
| 107 |
if (batch->tlsinfo.tls.size) { |
| 108 |
unsigned thread_tls_alloc = |
| 109 |
pan_query_thread_tls_alloc(&phys_dev->kmod.dev->props); |
| 110 |
unsigned core_id_range; |
| 111 |
|
| 112 |
pan_query_core_count(&phys_dev->kmod.dev->props, &core_id_range); |
| 113 |
|
| 114 |
unsigned size = pan_get_total_stack_size(batch->tlsinfo.tls.size, |
| 115 |
thread_tls_alloc, core_id_range); |
| 116 |
batch->tlsinfo.tls.ptr = |
| 117 |
panvk_cmd_alloc_dev_mem(cmdbuf, tls, size, 4096).gpu; |
| 118 |
} |
| 119 |
|
| 120 |
if (batch->tlsinfo.wls.size) { |
| 121 |
assert(batch->wls_total_size); |
| 122 |
batch->tlsinfo.wls.ptr = |
| 123 |
panvk_cmd_alloc_dev_mem(cmdbuf, tls, batch->wls_total_size, 4096).gpu; |
| 124 |
} |
| 125 |
|
| 126 |
if (batch->tls.cpu) |
| 127 |
GENX(pan_emit_tls)(&batch->tlsinfo, batch->tls.cpu); |
| 128 |
|
| 129 |
if (batch->fb.desc.cpu && |
| 130 |
(cmdbuf->cur_batch->vtc_jc.first_tiler || |
| 131 |
cmdbuf->state.gfx.render.fb.needs_store)) { |
| 132 |
panvk_per_arch(cmd_select_tile_size)(cmdbuf); |
| 133 |
|
| 134 |
/* At this point, we should know sample count and the tile size should |
| 135 |
* have been calculated |
| 136 |
*/ |
| 137 |
const struct panvk_rendering_state *render = &cmdbuf->state.gfx.render; |
| 138 |
assert(render->fb.layout.sample_count > 0); |
| 139 |
assert(render->fb.layout.tile_size_px > 0); |
| 140 |
|
| 141 |
const uint8_t sample_count = render->fb.layout.sample_count; |
| 142 |
struct pan_fb_desc_info fbd_info = { |
| 143 |
.fb = &render->fb.layout, |
| 144 |
.load = render->fb.needs_load ? &render->fb.load : |
| 145 |
&render->fb.spill.load, |
| 146 |
.store = render->fb.needs_store ? &render->fb.store : |
| 147 |
&render->fb.spill.store, |
| 148 |
.sample_pos_array_pointer = dev->sample_positions->addr.dev + |
| 149 |
pan_sample_positions_offset(pan_sample_pattern(sample_count)), |
| 150 |
.provoking_vertex_first = |
| 151 |
cmdbuf->state.gfx.render.first_provoking_vertex != U_TRISTATE_NO, |
| 152 |
.tls = &batch->tlsinfo, |
| 153 |
.tiler_ctx = &batch->tiler.ctx, |
| 154 |
}; |
| 155 |
|
| 156 |
struct pan_fb_frame_shaders fs; |
| 157 |
VkResult result = panvk_per_arch(cmd_get_frame_shaders)( |
| 158 |
cmdbuf, &render->fb.layout, fbd_info.load, |
| 159 |
render->fb.needs_store ? &render->fb.resolve : NULL, &fs); |
| 160 |
if (result != VK_SUCCESS) |
| 161 |
return; |
| 162 |
|
| 163 |
uint32_t view_mask = cmdbuf->state.gfx.render.view_mask; |
| 164 |
assert(view_mask == 0 || util_bitcount(view_mask) <= batch->fb.layer_count); |
| 165 |
uint32_t enabled_layer_count = view_mask ? |
| 166 |
util_bitcount(view_mask) : |
| 167 |
batch->fb.layer_count; |
| 168 |
|
| 169 |
for (uint32_t i = 0; i < enabled_layer_count; i++) { |
| 170 |
uint32_t layer_id = (view_mask != 0) ? u_bit_scan(&view_mask) : i; |
| 171 |
VkResult result; |
| 172 |
|
| 173 |
result = panvk_per_arch(cmd_prepare_tiler_context)(cmdbuf, layer_id); |
| 174 |
if (result != VK_SUCCESS) |
| 175 |
break; |
| 176 |
|
| 177 |
const struct pan_ptr fbd = |
| 178 |
pan_ptr_offset(batch->fb.desc, batch->fb.desc_stride * layer_id); |
| 179 |
uint64_t tagged_fbd_ptr = fbd.gpu; |
| 180 |
|
| 181 |
fbd_info.layer = layer_id; |
| 182 |
fbd_info.frame_shaders = fs; |
| 183 |
fbd_info.frame_shaders.dcd_pointer += layer_id * 3 * pan_size(DRAW); |
| 184 |
tagged_fbd_ptr |= GENX(pan_emit_fb_desc)(&fbd_info, fbd.cpu); |
| 185 |
|
| 186 |
result = panvk_cmd_prepare_fragment_job(cmdbuf, tagged_fbd_ptr); |
| 187 |
if (result != VK_SUCCESS) |
| 188 |
break; |
| 189 |
} |
| 190 |
|
| 191 |
/* We've now done the load. Everything from now on should spill */ |
| 192 |
cmdbuf->state.gfx.render.fb.needs_load = false; |
| 193 |
} |
| 194 |
|
| 195 |
cmdbuf->cur_batch = NULL; |
| 196 |
} |
| 197 |
|
| 198 |
VkResult |
| 199 |
panvk_per_arch(cmd_alloc_fb_desc)(struct panvk_cmd_buffer *cmdbuf) |
| 200 |
{ |
| 201 |
struct panvk_batch *batch = cmdbuf->cur_batch; |
| 202 |
|
| 203 |
if (batch->fb.desc.gpu) |
| 204 |
return VK_SUCCESS; |
| 205 |
|
| 206 |
struct panvk_rendering_state *render = &cmdbuf->state.gfx.render; |
| 207 |
const struct pan_fb_layout *fb = &render->fb.layout; |
| 208 |
bool has_zs_ext = pan_fb_has_zs(fb); |
| 209 |
batch->fb.layer_count = render->layer_count; |
| 210 |
unsigned fbd_size = pan_size(FRAMEBUFFER); |
| 211 |
|
| 212 |
if (has_zs_ext) |
| 213 |
fbd_size = ALIGN_POT(fbd_size, pan_alignment(ZS_CRC_EXTENSION)) + |
| 214 |
pan_size(ZS_CRC_EXTENSION); |
| 215 |
|
| 216 |
fbd_size = ALIGN_POT(fbd_size, pan_alignment(RENDER_TARGET)) + |
| 217 |
(fb->rt_count * pan_size(RENDER_TARGET)); |
| 218 |
|
| 219 |
batch->fb.bo_count = cmdbuf->state.gfx.render.fb.bo_count; |
| 220 |
memcpy(batch->fb.bos, cmdbuf->state.gfx.render.fb.bos, |
| 221 |
batch->fb.bo_count * sizeof(batch->fb.bos[0])); |
| 222 |
|
| 223 |
batch->fb.desc = |
| 224 |
panvk_cmd_alloc_dev_mem(cmdbuf, desc, fbd_size * batch->fb.layer_count, |
| 225 |
pan_alignment(FRAMEBUFFER)); |
| 226 |
batch->fb.desc_stride = fbd_size; |
| 227 |
|
| 228 |
return batch->fb.desc.gpu ? VK_SUCCESS : VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 229 |
} |
| 230 |
|
| 231 |
VkResult |
| 232 |
panvk_per_arch(cmd_alloc_tls_desc)(struct panvk_cmd_buffer *cmdbuf, bool gfx) |
| 233 |
{ |
| 234 |
struct panvk_batch *batch = cmdbuf->cur_batch; |
| 235 |
|
| 236 |
assert(batch); |
| 237 |
if (!batch->tls.gpu) { |
| 238 |
batch->tls = panvk_cmd_alloc_desc(cmdbuf, LOCAL_STORAGE); |
| 239 |
if (!batch->tls.gpu) |
| 240 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 241 |
} |
| 242 |
|
| 243 |
return VK_SUCCESS; |
| 244 |
} |
| 245 |
|
| 246 |
VkResult |
| 247 |
panvk_per_arch(cmd_prepare_tiler_context)(struct panvk_cmd_buffer *cmdbuf, |
| 248 |
uint32_t layer_idx) |
| 249 |
{ |
| 250 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 251 |
struct panvk_physical_device *phys_dev = |
| 252 |
to_panvk_physical_device(cmdbuf->vk.base.device->physical); |
| 253 |
struct panvk_batch *batch = cmdbuf->cur_batch; |
| 254 |
uint64_t tiler_desc; |
| 255 |
|
| 256 |
if (batch->tiler.ctx_descs.gpu) { |
| 257 |
tiler_desc = |
| 258 |
batch->tiler.ctx_descs.gpu + (pan_size(TILER_CONTEXT) * layer_idx); |
| 259 |
goto out_set_layer_ctx; |
| 260 |
} |
| 261 |
|
| 262 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 263 |
uint32_t layer_count = cmdbuf->state.gfx.render.layer_count; |
| 264 |
batch->tiler.heap_desc = panvk_cmd_alloc_desc(cmdbuf, TILER_HEAP); |
| 265 |
batch->tiler.ctx_descs = |
| 266 |
panvk_cmd_alloc_desc_array(cmdbuf, layer_count, TILER_CONTEXT); |
| 267 |
if (!batch->tiler.heap_desc.gpu || !batch->tiler.ctx_descs.gpu) |
| 268 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 269 |
|
| 270 |
tiler_desc = |
| 271 |
batch->tiler.ctx_descs.gpu + (pan_size(TILER_CONTEXT) * layer_idx); |
| 272 |
|
| 273 |
pan_pack(&batch->tiler.heap_templ, TILER_HEAP, cfg) { |
| 274 |
cfg.size = pan_kmod_bo_size(dev->tiler_heap->bo); |
| 275 |
cfg.base = dev->tiler_heap->addr.dev; |
| 276 |
cfg.bottom = dev->tiler_heap->addr.dev; |
| 277 |
cfg.top = cfg.base + cfg.size; |
| 278 |
} |
| 279 |
|
| 280 |
pan_pack(&batch->tiler.ctx_templ, TILER_CONTEXT, cfg) { |
| 281 |
cfg.hierarchy_mask = panvk_select_tiler_hierarchy_mask( |
| 282 |
phys_dev, &cmdbuf->state.gfx, pan_kmod_bo_size(dev->tiler_heap->bo)); |
| 283 |
cfg.fb_width = fb->width_px; |
| 284 |
cfg.fb_height = fb->height_px; |
| 285 |
cfg.heap = batch->tiler.heap_desc.gpu; |
| 286 |
cfg.sample_pattern = pan_sample_pattern(fb->sample_count); |
| 287 |
} |
| 288 |
|
| 289 |
memcpy(batch->tiler.heap_desc.cpu, &batch->tiler.heap_templ, |
| 290 |
sizeof(batch->tiler.heap_templ)); |
| 291 |
|
| 292 |
struct mali_tiler_context_packed *ctxs = batch->tiler.ctx_descs.cpu; |
| 293 |
|
| 294 |
assert(layer_count > 0); |
| 295 |
for (uint32_t i = 0; i < layer_count; i++) { |
| 296 |
STATIC_ASSERT( |
| 297 |
!(pan_size(TILER_CONTEXT) & (pan_alignment(TILER_CONTEXT) - 1))); |
| 298 |
|
| 299 |
memcpy(&ctxs[i], &batch->tiler.ctx_templ, sizeof(*ctxs)); |
| 300 |
} |
| 301 |
|
| 302 |
out_set_layer_ctx: |
| 303 |
if (PAN_ARCH >= 9) |
| 304 |
batch->tiler.ctx.valhall.desc = tiler_desc; |
| 305 |
else |
| 306 |
batch->tiler.ctx.bifrost.desc = tiler_desc; |
| 307 |
|
| 308 |
return VK_SUCCESS; |
| 309 |
} |
| 310 |
|
| 311 |
struct panvk_batch * |
| 312 |
panvk_per_arch(cmd_open_batch)(struct panvk_cmd_buffer *cmdbuf) |
| 313 |
{ |
| 314 |
assert(!cmdbuf->cur_batch); |
| 315 |
cmdbuf->cur_batch = |
| 316 |
vk_zalloc(&cmdbuf->vk.pool->alloc, sizeof(*cmdbuf->cur_batch), 8, |
| 317 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 318 |
cmdbuf->cur_batch->jobs = UTIL_DYNARRAY_INIT; |
| 319 |
cmdbuf->cur_batch->event_ops = UTIL_DYNARRAY_INIT; |
| 320 |
assert(cmdbuf->cur_batch); |
| 321 |
return cmdbuf->cur_batch; |
| 322 |
} |
| 323 |
|
| 324 |
VKAPI_ATTR VkResult VKAPI_CALL |
| 325 |
panvk_per_arch(EndCommandBuffer)(VkCommandBuffer commandBuffer) |
| 326 |
{ |
| 327 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 328 |
|
| 329 |
panvk_per_arch(cmd_close_batch)(cmdbuf); |
| 330 |
|
| 331 |
panvk_pool_flush_maps(&cmdbuf->desc_pool); |
| 332 |
|
| 333 |
return vk_command_buffer_end(&cmdbuf->vk); |
| 334 |
} |
| 335 |
|
| 336 |
VKAPI_ATTR void VKAPI_CALL |
| 337 |
panvk_per_arch(CmdPipelineBarrier2)(VkCommandBuffer commandBuffer, |
| 338 |
const VkDependencyInfo *pDependencyInfo) |
| 339 |
{ |
| 340 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 341 |
|
| 342 |
/* Caches are flushed/invalidated at batch boundaries for now, nothing to do |
| 343 |
* for memory barriers assuming we implement barriers with the creation of a |
| 344 |
* new batch. |
| 345 |
* FIXME: We can probably do better with a CacheFlush job that has the |
| 346 |
* barrier flag set to true. |
| 347 |
*/ |
| 348 |
if (cmdbuf->cur_batch) { |
| 349 |
panvk_per_arch(cmd_close_batch)(cmdbuf); |
| 350 |
panvk_per_arch(cmd_open_batch)(cmdbuf); |
| 351 |
} |
| 352 |
|
| 353 |
for (uint32_t i = 0; i < pDependencyInfo->imageMemoryBarrierCount; i++) { |
| 354 |
const VkImageMemoryBarrier2 *barrier = &pDependencyInfo->pImageMemoryBarriers[i]; |
| 355 |
|
| 356 |
panvk_per_arch(cmd_transition_image_layout)(commandBuffer, barrier); |
| 357 |
} |
| 358 |
|
| 359 |
/* If we had any layout transition dispatches, the batch will be closed at |
| 360 |
* this point, therefore establishing the sync between itself and the |
| 361 |
* commands that follow. |
| 362 |
*/ |
| 363 |
} |
| 364 |
|
| 365 |
static void |
| 366 |
panvk_reset_cmdbuf(struct vk_command_buffer *vk_cmdbuf, |
| 367 |
VkCommandBufferResetFlags flags) |
| 368 |
{ |
| 369 |
struct panvk_cmd_buffer *cmdbuf = |
| 370 |
container_of(vk_cmdbuf, struct panvk_cmd_buffer, vk); |
| 371 |
|
| 372 |
vk_command_buffer_reset(&cmdbuf->vk); |
| 373 |
|
| 374 |
list_for_each_entry_safe(struct panvk_batch, batch, &cmdbuf->batches, node) { |
| 375 |
list_del(&batch->node); |
| 376 |
util_dynarray_fini(&batch->jobs); |
| 377 |
util_dynarray_fini(&batch->event_ops); |
| 378 |
|
| 379 |
vk_free(&cmdbuf->vk.pool->alloc, batch); |
| 380 |
} |
| 381 |
|
| 382 |
panvk_pool_reset(&cmdbuf->desc_pool); |
| 383 |
panvk_pool_reset(&cmdbuf->tls_pool); |
| 384 |
panvk_pool_reset(&cmdbuf->varying_pool); |
| 385 |
panvk_cmd_buffer_obj_list_reset(cmdbuf, push_sets); |
| 386 |
|
| 387 |
memset(&cmdbuf->state, 0, sizeof(cmdbuf->state)); |
| 388 |
} |
| 389 |
|
| 390 |
static void |
| 391 |
panvk_destroy_cmdbuf(struct vk_command_buffer *vk_cmdbuf) |
| 392 |
{ |
| 393 |
struct panvk_cmd_buffer *cmdbuf = |
| 394 |
container_of(vk_cmdbuf, struct panvk_cmd_buffer, vk); |
| 395 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 396 |
|
| 397 |
list_for_each_entry_safe(struct panvk_batch, batch, &cmdbuf->batches, node) { |
| 398 |
list_del(&batch->node); |
| 399 |
util_dynarray_fini(&batch->jobs); |
| 400 |
util_dynarray_fini(&batch->event_ops); |
| 401 |
|
| 402 |
vk_free(&cmdbuf->vk.pool->alloc, batch); |
| 403 |
} |
| 404 |
|
| 405 |
#if PAN_ARCH < 9 |
| 406 |
panvk_shader_link_cleanup(&cmdbuf->state.gfx.link); |
| 407 |
#endif |
| 408 |
|
| 409 |
panvk_pool_cleanup(&cmdbuf->desc_pool); |
| 410 |
panvk_pool_cleanup(&cmdbuf->tls_pool); |
| 411 |
panvk_pool_cleanup(&cmdbuf->varying_pool); |
| 412 |
panvk_cmd_buffer_obj_list_cleanup(cmdbuf, push_sets); |
| 413 |
vk_command_buffer_finish(&cmdbuf->vk); |
| 414 |
vk_free(&dev->vk.alloc, cmdbuf); |
| 415 |
} |
| 416 |
|
| 417 |
static VkResult |
| 418 |
panvk_create_cmdbuf(struct vk_command_pool *vk_pool, VkCommandBufferLevel level, |
| 419 |
struct vk_command_buffer **cmdbuf_out) |
| 420 |
{ |
| 421 |
struct panvk_device *device = |
| 422 |
container_of(vk_pool->base.device, struct panvk_device, vk); |
| 423 |
struct panvk_cmd_pool *pool = |
| 424 |
container_of(vk_pool, struct panvk_cmd_pool, vk); |
| 425 |
struct panvk_cmd_buffer *cmdbuf; |
| 426 |
|
| 427 |
cmdbuf = vk_zalloc(&device->vk.alloc, sizeof(*cmdbuf), 8, |
| 428 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 429 |
if (!cmdbuf) |
| 430 |
return panvk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 431 |
|
| 432 |
VkResult result = vk_command_buffer_init( |
| 433 |
&pool->vk, &cmdbuf->vk, &panvk_per_arch(cmd_buffer_ops), level); |
| 434 |
if (result != VK_SUCCESS) { |
| 435 |
vk_free(&device->vk.alloc, cmdbuf); |
| 436 |
return result; |
| 437 |
} |
| 438 |
|
| 439 |
panvk_cmd_buffer_obj_list_init(cmdbuf, push_sets); |
| 440 |
cmdbuf->vk.dynamic_graphics_state.vi = &cmdbuf->state.gfx.dynamic.vi; |
| 441 |
cmdbuf->vk.dynamic_graphics_state.ms.sample_locations = |
| 442 |
&cmdbuf->state.gfx.dynamic.sl; |
| 443 |
|
| 444 |
struct panvk_pool_properties desc_pool_props = { |
| 445 |
.create_flags = |
| 446 |
panvk_device_adjust_bo_flags(device, PAN_KMOD_BO_FLAG_WB_MMAP), |
| 447 |
.slab_size = 64 * 1024, |
| 448 |
.label = "Command buffer descriptor pool", |
| 449 |
.prealloc = true, |
| 450 |
.owns_bos = true, |
| 451 |
.needs_locking = false, |
| 452 |
}; |
| 453 |
panvk_pool_init(&cmdbuf->desc_pool, device, &pool->desc_bo_pool, NULL, |
| 454 |
&desc_pool_props); |
| 455 |
|
| 456 |
struct panvk_pool_properties tls_pool_props = { |
| 457 |
.create_flags = |
| 458 |
panvk_device_adjust_bo_flags(device, PAN_KMOD_BO_FLAG_NO_MMAP), |
| 459 |
.slab_size = 64 * 1024, |
| 460 |
.label = "TLS pool", |
| 461 |
.prealloc = false, |
| 462 |
.owns_bos = true, |
| 463 |
.needs_locking = false, |
| 464 |
}; |
| 465 |
panvk_pool_init(&cmdbuf->tls_pool, device, &pool->tls_bo_pool, &pool->tls_big_bo_pool, |
| 466 |
&tls_pool_props); |
| 467 |
|
| 468 |
struct panvk_pool_properties var_pool_props = { |
| 469 |
.create_flags = |
| 470 |
panvk_device_adjust_bo_flags(device, PAN_KMOD_BO_FLAG_NO_MMAP), |
| 471 |
.slab_size = 64 * 1024, |
| 472 |
.label = "Varying pool", |
| 473 |
.prealloc = false, |
| 474 |
.owns_bos = true, |
| 475 |
.needs_locking = false, |
| 476 |
}; |
| 477 |
panvk_pool_init(&cmdbuf->varying_pool, device, &pool->varying_bo_pool, NULL, |
| 478 |
&var_pool_props); |
| 479 |
|
| 480 |
list_inithead(&cmdbuf->batches); |
| 481 |
*cmdbuf_out = &cmdbuf->vk; |
| 482 |
return VK_SUCCESS; |
| 483 |
} |
| 484 |
|
| 485 |
const struct vk_command_buffer_ops panvk_per_arch(cmd_buffer_ops) = { |
| 486 |
.create = panvk_create_cmdbuf, |
| 487 |
.reset = panvk_reset_cmdbuf, |
| 488 |
.destroy = panvk_destroy_cmdbuf, |
| 489 |
}; |
| 490 |
|
| 491 |
VKAPI_ATTR VkResult VKAPI_CALL |
| 492 |
panvk_per_arch(BeginCommandBuffer)(VkCommandBuffer commandBuffer, |
| 493 |
const VkCommandBufferBeginInfo *pBeginInfo) |
| 494 |
{ |
| 495 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 496 |
|
| 497 |
vk_command_buffer_begin(&cmdbuf->vk, pBeginInfo); |
| 498 |
|
| 499 |
return VK_SUCCESS; |
| 500 |
} |