| 1 |
/* |
| 2 |
* Copyright © 2024 Collabora Ltd. |
| 3 |
* Copyright © 2025 Arm Ltd. |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <assert.h> |
| 8 |
#include <fcntl.h> |
| 9 |
#include <stdbool.h> |
| 10 |
#include <string.h> |
| 11 |
#include <unistd.h> |
| 12 |
|
| 13 |
#include "util/mesa-blake3.h" |
| 14 |
#include "vk_alloc.h" |
| 15 |
#include "vk_descriptor_update_template.h" |
| 16 |
#include "vk_descriptors.h" |
| 17 |
#include "vk_format.h" |
| 18 |
#include "vk_log.h" |
| 19 |
#include "vk_util.h" |
| 20 |
|
| 21 |
#include "util/bitset.h" |
| 22 |
|
| 23 |
#include "genxml/gen_macros.h" |
| 24 |
|
| 25 |
#include "panvk_buffer.h" |
| 26 |
#include "panvk_buffer_view.h" |
| 27 |
#include "panvk_descriptor_set.h" |
| 28 |
#include "panvk_descriptor_set_layout.h" |
| 29 |
#include "panvk_device.h" |
| 30 |
#include "panvk_entrypoints.h" |
| 31 |
#include "panvk_image.h" |
| 32 |
#include "panvk_image_view.h" |
| 33 |
#include "panvk_macros.h" |
| 34 |
#include "panvk_priv_bo.h" |
| 35 |
#include "panvk_sampler.h" |
| 36 |
|
| 37 |
static const void * |
| 38 |
get_desc_slot_ptr(struct panvk_descriptor_set *set, uint32_t binding, |
| 39 |
uint32_t elem, struct panvk_subdesc_info subdesc) |
| 40 |
{ |
| 41 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 42 |
&set->layout->bindings[binding]; |
| 43 |
|
| 44 |
uint32_t offset = panvk_get_desc_index(binding_layout, elem, subdesc); |
| 45 |
|
| 46 |
assert(offset < set->layout->desc_count); |
| 47 |
|
| 48 |
return (char *)set->descs.host + offset * PANVK_DESCRIPTOR_SIZE; |
| 49 |
} |
| 50 |
|
| 51 |
static void |
| 52 |
write_desc_data(struct panvk_descriptor_set *set, uint32_t binding, |
| 53 |
uint32_t elem, struct panvk_subdesc_info subdesc, |
| 54 |
uint32_t desc_offset, const void *desc_data, size_t desc_size) |
| 55 |
{ |
| 56 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 57 |
&set->layout->bindings[binding]; |
| 58 |
|
| 59 |
uint32_t index = panvk_get_desc_index(binding_layout, elem, subdesc); |
| 60 |
|
| 61 |
assert(index < set->layout->desc_count); |
| 62 |
assert(index + DIV_ROUND_UP(desc_size, PANVK_DESCRIPTOR_SIZE) <= |
| 63 |
set->layout->desc_count); |
| 64 |
|
| 65 |
uint32_t offset_B = desc_offset + index * PANVK_DESCRIPTOR_SIZE; |
| 66 |
|
| 67 |
memcpy((char *)set->descs.host + offset_B, desc_data, desc_size); |
| 68 |
|
| 69 |
set->descs.dirty_min = MIN2(set->descs.dirty_min, offset_B); |
| 70 |
set->descs.dirty_max = MAX2(set->descs.dirty_max, offset_B + desc_size); |
| 71 |
} |
| 72 |
|
| 73 |
#define write_desc(set, binding, elem, desc, subdesc) \ |
| 74 |
do { \ |
| 75 |
static_assert(sizeof(*(desc)) == PANVK_DESCRIPTOR_SIZE, \ |
| 76 |
"wrong descriptor size"); \ |
| 77 |
write_desc_data(set, binding, elem, subdesc, 0, \ |
| 78 |
(desc), PANVK_DESCRIPTOR_SIZE); \ |
| 79 |
} while (0) |
| 80 |
|
| 81 |
#if PAN_ARCH >= 9 |
| 82 |
#define write_nulldesc(set, binding, elem, subdesc) \ |
| 83 |
do { \ |
| 84 |
struct mali_null_descriptor_packed null_desc; \ |
| 85 |
pan_pack(&null_desc, NULL_DESCRIPTOR, cfg) \ |
| 86 |
; \ |
| 87 |
write_desc(set, binding, elem, &null_desc, (subdesc)); \ |
| 88 |
} while (0) |
| 89 |
#else |
| 90 |
#define write_nulldesc(set, binding, elem, subdesc) \ |
| 91 |
do { \ |
| 92 |
} while (0) |
| 93 |
#endif |
| 94 |
|
| 95 |
static void |
| 96 |
write_sampler_desc(struct panvk_descriptor_set *set, |
| 97 |
const VkDescriptorImageInfo *const pImageInfo, |
| 98 |
uint32_t binding, uint32_t elem, bool write_immutable) |
| 99 |
{ |
| 100 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 101 |
&set->layout->bindings[binding]; |
| 102 |
|
| 103 |
struct panvk_sampler *sampler; |
| 104 |
|
| 105 |
if (binding_layout->immutable_samplers) { |
| 106 |
if (!write_immutable) |
| 107 |
return; |
| 108 |
sampler = binding_layout->immutable_samplers[elem]; |
| 109 |
} else { |
| 110 |
if (!pImageInfo) |
| 111 |
return; |
| 112 |
sampler = panvk_sampler_from_handle(pImageInfo->sampler); |
| 113 |
} |
| 114 |
|
| 115 |
if (!sampler) { |
| 116 |
for (uint8_t plane = 0; plane < binding_layout->samplers_per_desc; |
| 117 |
plane++) |
| 118 |
write_nulldesc(set, binding, elem, |
| 119 |
get_sampler_subdesc_info(binding_layout->type, plane)); |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
for (uint8_t plane = 0; plane < sampler->desc_count; plane++) { |
| 124 |
write_desc(set, binding, elem, &sampler->descs[plane], |
| 125 |
get_sampler_subdesc_info(binding_layout->type, plane)); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
static void |
| 130 |
write_image_view_desc(struct panvk_descriptor_set *set, |
| 131 |
const VkDescriptorImageInfo *const pImageInfo, |
| 132 |
uint32_t binding, uint32_t elem, VkDescriptorType type) |
| 133 |
{ |
| 134 |
if (!pImageInfo) |
| 135 |
return; |
| 136 |
|
| 137 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 138 |
&set->layout->bindings[binding]; |
| 139 |
|
| 140 |
if (pImageInfo->imageView == VK_NULL_HANDLE) { |
| 141 |
for (uint8_t plane = 0; plane < binding_layout->textures_per_desc; |
| 142 |
plane++) |
| 143 |
write_nulldesc(set, binding, elem, |
| 144 |
get_sampler_subdesc_info(binding_layout->type, plane)); |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
VK_FROM_HANDLE(panvk_image_view, view, pImageInfo->imageView); |
| 149 |
|
| 150 |
uint8_t plane_count = vk_format_get_plane_count(view->vk.format); |
| 151 |
for (uint8_t plane = 0; plane < plane_count; plane++) { |
| 152 |
struct panvk_subdesc_info subdesc = get_tex_subdesc_info(type, plane); |
| 153 |
#if PAN_ARCH >= 9 |
| 154 |
if (type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) |
| 155 |
write_desc(set, binding, elem, &view->descs.storage_tex[plane], |
| 156 |
subdesc); |
| 157 |
else |
| 158 |
write_desc(set, binding, elem, &view->descs.tex[plane], subdesc); |
| 159 |
#else |
| 160 |
if (type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) |
| 161 |
write_desc(set, binding, elem, &view->descs.img_attrib_buf, |
| 162 |
NO_SUBDESC); |
| 163 |
else |
| 164 |
write_desc(set, binding, elem, &view->descs.tex[plane], subdesc); |
| 165 |
#endif |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
static void |
| 170 |
write_buffer_desc(struct panvk_descriptor_set *set, |
| 171 |
const VkDescriptorBufferInfo *const info, uint32_t binding, |
| 172 |
uint32_t elem, VkDescriptorType type) |
| 173 |
{ |
| 174 |
if (info->buffer == VK_NULL_HANDLE) { |
| 175 |
write_nulldesc(set, binding, elem, NO_SUBDESC); |
| 176 |
return; |
| 177 |
} |
| 178 |
|
| 179 |
VK_FROM_HANDLE(panvk_buffer, buffer, info->buffer); |
| 180 |
const uint64_t range = panvk_buffer_range(buffer, info->offset, info->range); |
| 181 |
assert(range <= UINT32_MAX); |
| 182 |
|
| 183 |
#if PAN_ARCH < 9 |
| 184 |
if (type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) { |
| 185 |
struct panvk_ssbo_addr desc = { |
| 186 |
.base_addr = panvk_buffer_gpu_ptr(buffer, info->offset), |
| 187 |
.size = align(range, 4), |
| 188 |
}; |
| 189 |
|
| 190 |
write_desc(set, binding, elem, &desc, NO_SUBDESC); |
| 191 |
} else { |
| 192 |
struct { |
| 193 |
struct mali_uniform_buffer_packed ubo; |
| 194 |
uint32_t pad[6]; |
| 195 |
} padded_desc = {0}; |
| 196 |
|
| 197 |
pan_pack(&padded_desc.ubo, UNIFORM_BUFFER, cfg) { |
| 198 |
cfg.pointer = panvk_buffer_gpu_ptr(buffer, info->offset); |
| 199 |
cfg.entries = DIV_ROUND_UP(range, 16); |
| 200 |
} |
| 201 |
|
| 202 |
write_desc(set, binding, elem, &padded_desc, NO_SUBDESC); |
| 203 |
} |
| 204 |
#else |
| 205 |
const bool is_ssbo = type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; |
| 206 |
struct mali_buffer_packed desc; |
| 207 |
|
| 208 |
pan_pack(&desc, BUFFER, cfg) { |
| 209 |
cfg.address = panvk_buffer_gpu_ptr(buffer, info->offset); |
| 210 |
cfg.size = align(range, is_ssbo ? 4 : 16); |
| 211 |
} |
| 212 |
write_desc(set, binding, elem, &desc, NO_SUBDESC); |
| 213 |
#endif |
| 214 |
} |
| 215 |
|
| 216 |
static void |
| 217 |
write_dynamic_buffer_desc(struct panvk_descriptor_set *set, |
| 218 |
const VkDescriptorBufferInfo *const info, |
| 219 |
uint32_t binding, uint32_t elem) |
| 220 |
{ |
| 221 |
/* Default to memory sink (OOB address) */ |
| 222 |
uint64_t dev_addr = 0x8ull << 60; |
| 223 |
uint64_t range = 0; |
| 224 |
|
| 225 |
if (info->buffer != VK_NULL_HANDLE) { |
| 226 |
VK_FROM_HANDLE(panvk_buffer, buffer, info->buffer); |
| 227 |
|
| 228 |
dev_addr = panvk_buffer_gpu_ptr(buffer, info->offset); |
| 229 |
range = panvk_buffer_range(buffer, info->offset, info->range); |
| 230 |
} |
| 231 |
|
| 232 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 233 |
&set->layout->bindings[binding]; |
| 234 |
uint32_t dyn_buf_idx = binding_layout->desc_idx + elem; |
| 235 |
|
| 236 |
assert(range <= UINT32_MAX); |
| 237 |
assert(dyn_buf_idx < ARRAY_SIZE(set->dyn_bufs)); |
| 238 |
|
| 239 |
set->dyn_bufs[dyn_buf_idx].dev_addr = dev_addr; |
| 240 |
set->dyn_bufs[dyn_buf_idx].size = range; |
| 241 |
} |
| 242 |
|
| 243 |
static void |
| 244 |
write_buffer_view_desc(struct panvk_descriptor_set *set, |
| 245 |
const VkBufferView bufferView, uint32_t binding, |
| 246 |
uint32_t elem, VkDescriptorType type) |
| 247 |
{ |
| 248 |
if (bufferView == VK_NULL_HANDLE) { |
| 249 |
write_nulldesc(set, binding, elem, NO_SUBDESC); |
| 250 |
return; |
| 251 |
} |
| 252 |
|
| 253 |
VK_FROM_HANDLE(panvk_buffer_view, view, bufferView); |
| 254 |
|
| 255 |
#if PAN_ARCH < 9 |
| 256 |
struct { |
| 257 |
struct mali_attribute_buffer_packed attr_buf_desc; |
| 258 |
struct mali_attribute_packed attr_desc; |
| 259 |
uint32_t pad[2]; |
| 260 |
} padded_desc = { |
| 261 |
.attr_buf_desc = view->descs.attrib_buf, |
| 262 |
.attr_desc = view->descs.attrib, |
| 263 |
}; |
| 264 |
|
| 265 |
write_desc(set, binding, elem, &padded_desc, NO_SUBDESC); |
| 266 |
#else |
| 267 |
write_desc(set, binding, elem, &view->descs.buf, NO_SUBDESC); |
| 268 |
#endif |
| 269 |
} |
| 270 |
|
| 271 |
static void |
| 272 |
write_iub(struct panvk_descriptor_set *set, uint32_t binding, |
| 273 |
uint32_t dst_offset, uint32_t count, const void *data) |
| 274 |
{ |
| 275 |
/* First slot is the actual buffer descriptor. */ |
| 276 |
write_desc_data(set, binding, 1, NO_SUBDESC, dst_offset, data, count); |
| 277 |
} |
| 278 |
|
| 279 |
static void |
| 280 |
panvk_desc_pool_free_set(struct panvk_descriptor_pool *pool, |
| 281 |
struct panvk_descriptor_set *set) |
| 282 |
{ |
| 283 |
uintptr_t set_idx = set - pool->sets; |
| 284 |
assert(set_idx < pool->max_sets); |
| 285 |
|
| 286 |
if (!BITSET_TEST(pool->free_sets, set_idx)) { |
| 287 |
if (set->desc_count) |
| 288 |
util_vma_heap_free( |
| 289 |
&pool->desc_heap, |
| 290 |
pool->host_only_mem ? (uintptr_t)set->descs.host : set->descs.dev, |
| 291 |
set->desc_count * PANVK_DESCRIPTOR_SIZE); |
| 292 |
|
| 293 |
BITSET_SET(pool->free_sets, set_idx); |
| 294 |
|
| 295 |
/* Discard constness to call vk_descriptor_set_layout_unref(). */ |
| 296 |
struct panvk_descriptor_set_layout *set_layout = |
| 297 |
(struct panvk_descriptor_set_layout *)set->layout; |
| 298 |
|
| 299 |
vk_descriptor_set_layout_unref(pool->base.device, &set_layout->vk); |
| 300 |
vk_object_base_finish(&set->base); |
| 301 |
memset(set, 0, sizeof(*set)); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
static void |
| 306 |
panvk_destroy_descriptor_pool(struct panvk_device *device, |
| 307 |
const VkAllocationCallbacks *pAllocator, |
| 308 |
struct panvk_descriptor_pool *pool) |
| 309 |
{ |
| 310 |
for (uint32_t i = 0; i < pool->max_sets; i++) |
| 311 |
panvk_desc_pool_free_set(pool, &pool->sets[i]); |
| 312 |
|
| 313 |
if (pool->desc_bo) { |
| 314 |
util_vma_heap_finish(&pool->desc_heap); |
| 315 |
panvk_priv_bo_unref(pool->desc_bo); |
| 316 |
} else if (pool->host_only_mem) { |
| 317 |
util_vma_heap_finish(&pool->desc_heap); |
| 318 |
vk_free2(&device->vk.alloc, pAllocator, (void *)pool->host_only_mem); |
| 319 |
pool->host_only_mem = 0; |
| 320 |
} |
| 321 |
|
| 322 |
vk_object_free(&device->vk, pAllocator, pool); |
| 323 |
} |
| 324 |
|
| 325 |
static VkResult |
| 326 |
panvk_init_pool_memory(struct panvk_device *device, |
| 327 |
struct panvk_descriptor_pool *pool, |
| 328 |
const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 329 |
uint64_t pool_size, |
| 330 |
const VkAllocationCallbacks *pAllocator) |
| 331 |
{ |
| 332 |
if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_EXT)) { |
| 333 |
uint32_t bo_flags = |
| 334 |
panvk_device_adjust_bo_flags(device, PAN_KMOD_BO_FLAG_WB_MMAP); |
| 335 |
VkResult result = panvk_priv_bo_create(device, pool_size, bo_flags, |
| 336 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT, |
| 337 |
&pool->desc_bo); |
| 338 |
if (result != VK_SUCCESS) |
| 339 |
return result; |
| 340 |
|
| 341 |
uint64_t bo_size = pool->desc_bo->bo->size; |
| 342 |
assert(pool_size <= bo_size); |
| 343 |
|
| 344 |
util_vma_heap_init(&pool->desc_heap, pool->desc_bo->addr.dev, bo_size); |
| 345 |
} else { |
| 346 |
void *pool_mem = vk_alloc2(&device->vk.alloc, pAllocator, pool_size, 8, |
| 347 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 348 |
if (!pool_mem) |
| 349 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 350 |
|
| 351 |
/* A host-only pool has no bo backing it. */ |
| 352 |
pool->desc_bo = NULL; |
| 353 |
pool->host_only_mem = (uintptr_t)pool_mem; |
| 354 |
util_vma_heap_init(&pool->desc_heap, pool->host_only_mem, pool_size); |
| 355 |
} |
| 356 |
|
| 357 |
return VK_SUCCESS; |
| 358 |
} |
| 359 |
|
| 360 |
VkResult |
| 361 |
panvk_per_arch(CreateDescriptorPool)( |
| 362 |
VkDevice _device, const VkDescriptorPoolCreateInfo *pCreateInfo, |
| 363 |
const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) |
| 364 |
{ |
| 365 |
VK_FROM_HANDLE(panvk_device, device, _device); |
| 366 |
|
| 367 |
VK_MULTIALLOC(ma); |
| 368 |
VK_MULTIALLOC_DECL(&ma, struct panvk_descriptor_pool, pool, 1); |
| 369 |
VK_MULTIALLOC_DECL(&ma, BITSET_WORD, free_sets, |
| 370 |
BITSET_WORDS(pCreateInfo->maxSets)); |
| 371 |
VK_MULTIALLOC_DECL(&ma, struct panvk_descriptor_set, sets, |
| 372 |
pCreateInfo->maxSets); |
| 373 |
|
| 374 |
if (!vk_object_multizalloc(&device->vk, &ma, pAllocator, |
| 375 |
VK_OBJECT_TYPE_DESCRIPTOR_POOL)) |
| 376 |
return panvk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 377 |
|
| 378 |
uint32_t desc_count = 0; |
| 379 |
for (unsigned i = 0; i < pCreateInfo->poolSizeCount; ++i) { |
| 380 |
if (!vk_descriptor_type_is_dynamic(pCreateInfo->pPoolSizes[i].type)) { |
| 381 |
const struct panvk_descriptor_set_binding_layout layout = { |
| 382 |
.type = pCreateInfo->pPoolSizes[i].type, |
| 383 |
.textures_per_desc = PANVK_MAX_PLANES, |
| 384 |
.samplers_per_desc = PANVK_MAX_DESCS_PER_SAMPLER, |
| 385 |
}; |
| 386 |
desc_count += panvk_get_desc_stride(&layout) * |
| 387 |
pCreateInfo->pPoolSizes[i].descriptorCount; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
/* initialize to all ones to indicate all sets are free */ |
| 392 |
BITSET_SET_COUNT(free_sets, 0, pCreateInfo->maxSets); |
| 393 |
pool->free_sets = free_sets; |
| 394 |
pool->sets = sets; |
| 395 |
pool->max_sets = pCreateInfo->maxSets; |
| 396 |
|
| 397 |
if (desc_count) { |
| 398 |
/* adjust desc_count to account for 1 dummy sampler per descriptor set */ |
| 399 |
desc_count += pool->max_sets; |
| 400 |
|
| 401 |
uint64_t pool_size = desc_count * PANVK_DESCRIPTOR_SIZE; |
| 402 |
VkResult result = panvk_init_pool_memory(device, pool, pCreateInfo, |
| 403 |
pool_size, pAllocator); |
| 404 |
if (result != VK_SUCCESS) { |
| 405 |
panvk_destroy_descriptor_pool(device, pAllocator, pool); |
| 406 |
return result; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
*pDescriptorPool = panvk_descriptor_pool_to_handle(pool); |
| 411 |
return VK_SUCCESS; |
| 412 |
} |
| 413 |
|
| 414 |
void |
| 415 |
panvk_per_arch(DestroyDescriptorPool)(VkDevice _device, VkDescriptorPool _pool, |
| 416 |
const VkAllocationCallbacks *pAllocator) |
| 417 |
{ |
| 418 |
VK_FROM_HANDLE(panvk_device, device, _device); |
| 419 |
VK_FROM_HANDLE(panvk_descriptor_pool, pool, _pool); |
| 420 |
|
| 421 |
if (pool) |
| 422 |
panvk_destroy_descriptor_pool(device, pAllocator, pool); |
| 423 |
} |
| 424 |
|
| 425 |
static void |
| 426 |
desc_set_write_immutable_samplers(struct panvk_descriptor_set *set, |
| 427 |
uint32_t variable_count) |
| 428 |
{ |
| 429 |
const struct panvk_descriptor_set_layout *layout = set->layout; |
| 430 |
|
| 431 |
for (uint32_t b = 0; b < layout->binding_count; b++) { |
| 432 |
if (layout->bindings[b].type != VK_DESCRIPTOR_TYPE_SAMPLER && |
| 433 |
layout->bindings[b].type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) |
| 434 |
continue; |
| 435 |
|
| 436 |
if (layout->bindings[b].immutable_samplers == NULL) |
| 437 |
continue; |
| 438 |
|
| 439 |
uint32_t array_size = layout->bindings[b].desc_count; |
| 440 |
|
| 441 |
if (layout->bindings[b].flags & |
| 442 |
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT) |
| 443 |
array_size = variable_count; |
| 444 |
|
| 445 |
for (uint32_t j = 0; j < array_size; j++) { |
| 446 |
struct panvk_sampler *sampler = |
| 447 |
layout->bindings[b].immutable_samplers[j]; |
| 448 |
if (!sampler) { |
| 449 |
for (uint8_t plane = 0; |
| 450 |
plane < layout->bindings[b].samplers_per_desc; plane++) |
| 451 |
write_nulldesc( |
| 452 |
set, b, j, |
| 453 |
get_sampler_subdesc_info(layout->bindings[b].type, plane)); |
| 454 |
continue; |
| 455 |
} |
| 456 |
for (uint8_t plane = 0; plane < sampler->desc_count; plane++) { |
| 457 |
write_desc(set, b, j, |
| 458 |
&sampler->descs[plane], |
| 459 |
get_sampler_subdesc_info(layout->bindings[b].type, |
| 460 |
plane)); |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
static void |
| 467 |
panvk_init_iub(struct panvk_descriptor_set *set, uint32_t binding, |
| 468 |
uint32_t variable_count) |
| 469 |
{ |
| 470 |
const struct panvk_descriptor_set_binding_layout *binding_layout = |
| 471 |
&set->layout->bindings[binding]; |
| 472 |
|
| 473 |
bool has_variable_count = |
| 474 |
binding_layout->flags & |
| 475 |
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT; |
| 476 |
|
| 477 |
/* The first element is the buffer descriptor. */ |
| 478 |
uint32_t iub_data_offset = |
| 479 |
panvk_get_desc_index(binding_layout, 1, NO_SUBDESC) * |
| 480 |
PANVK_DESCRIPTOR_SIZE; |
| 481 |
uint64_t iub_data_dev = set->descs.dev + iub_data_offset; |
| 482 |
uint32_t iub_desc_count = has_variable_count ? |
| 483 |
panvk_get_iub_desc_count(variable_count) : binding_layout->desc_count; |
| 484 |
uint32_t iub_size_dev = panvk_get_iub_size(iub_desc_count); |
| 485 |
|
| 486 |
#if PAN_ARCH < 9 |
| 487 |
struct { |
| 488 |
struct mali_uniform_buffer_packed ubo; |
| 489 |
uint32_t pad[6]; |
| 490 |
} padded_desc = {0}; |
| 491 |
|
| 492 |
pan_pack(&padded_desc.ubo, UNIFORM_BUFFER, cfg) { |
| 493 |
cfg.pointer = iub_data_dev; |
| 494 |
cfg.entries = iub_size_dev; |
| 495 |
} |
| 496 |
write_desc(set, binding, 0, &padded_desc, NO_SUBDESC); |
| 497 |
#else |
| 498 |
struct mali_buffer_packed desc; |
| 499 |
|
| 500 |
pan_pack(&desc, BUFFER, cfg) { |
| 501 |
cfg.address = iub_data_dev; |
| 502 |
cfg.size = align(iub_size_dev, 16); |
| 503 |
} |
| 504 |
write_desc(set, binding, 0, &desc, NO_SUBDESC); |
| 505 |
#endif |
| 506 |
} |
| 507 |
|
| 508 |
static VkResult |
| 509 |
panvk_desc_pool_allocate_set(struct panvk_descriptor_pool *pool, |
| 510 |
struct panvk_descriptor_set_layout *layout, |
| 511 |
uint32_t variable_count, |
| 512 |
struct panvk_descriptor_set **out) |
| 513 |
{ |
| 514 |
uint32_t num_descs = layout->desc_count; |
| 515 |
|
| 516 |
if (layout->binding_count) { |
| 517 |
uint32_t last_binding = layout->binding_count - 1; |
| 518 |
|
| 519 |
if ((layout->bindings[last_binding].flags & |
| 520 |
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT) && |
| 521 |
!vk_descriptor_type_is_dynamic(layout->bindings[last_binding].type)) { |
| 522 |
if (layout->bindings[last_binding].type == |
| 523 |
VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) { |
| 524 |
num_descs -= layout->bindings[last_binding].desc_count; |
| 525 |
num_descs += panvk_get_iub_desc_count(variable_count); |
| 526 |
} else { |
| 527 |
uint32_t desc_stride = |
| 528 |
panvk_get_desc_stride(&layout->bindings[last_binding]); |
| 529 |
|
| 530 |
num_descs -= layout->bindings[last_binding].desc_count * desc_stride; |
| 531 |
num_descs += variable_count * desc_stride; |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
uint64_t descs_size = num_descs * PANVK_DESCRIPTOR_SIZE; |
| 537 |
uint32_t first_free_set = |
| 538 |
__bitset_ffs(pool->free_sets, BITSET_WORDS(pool->max_sets)); |
| 539 |
if (first_free_set == 0 || pool->desc_heap.free_size < descs_size) |
| 540 |
return panvk_error(pool, VK_ERROR_OUT_OF_POOL_MEMORY); |
| 541 |
|
| 542 |
uint64_t descs_dev_addr = 0; |
| 543 |
if (num_descs) { |
| 544 |
descs_dev_addr = util_vma_heap_alloc(&pool->desc_heap, descs_size, |
| 545 |
PANVK_DESCRIPTOR_SIZE); |
| 546 |
if (!descs_dev_addr) |
| 547 |
return panvk_error(pool, VK_ERROR_FRAGMENTED_POOL); |
| 548 |
} |
| 549 |
struct panvk_descriptor_set *set = &pool->sets[first_free_set - 1]; |
| 550 |
|
| 551 |
vk_object_base_init(pool->base.device, &set->base, |
| 552 |
VK_OBJECT_TYPE_DESCRIPTOR_SET); |
| 553 |
vk_descriptor_set_layout_ref(&layout->vk); |
| 554 |
set->pool = pool; |
| 555 |
set->layout = layout; |
| 556 |
set->desc_count = num_descs; |
| 557 |
if (pool->desc_bo) { |
| 558 |
set->descs.dev = descs_dev_addr; |
| 559 |
set->descs.host = |
| 560 |
pool->desc_bo->addr.host + set->descs.dev - pool->desc_bo->addr.dev; |
| 561 |
} else { |
| 562 |
/* This cast is fine because the heap is initialized from a host |
| 563 |
* pointer in case of a host only pool. */ |
| 564 |
set->descs.host = (void *)(uintptr_t)descs_dev_addr; |
| 565 |
} |
| 566 |
set->descs.dirty_min = SIZE_MAX; |
| 567 |
set->descs.dirty_max = 0; |
| 568 |
desc_set_write_immutable_samplers(set, variable_count); |
| 569 |
BITSET_CLEAR(pool->free_sets, first_free_set - 1); |
| 570 |
|
| 571 |
for (uint32_t b = 0; b < layout->binding_count; ++b) { |
| 572 |
if (layout->bindings[b].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) |
| 573 |
panvk_init_iub(set, b, variable_count); |
| 574 |
} |
| 575 |
|
| 576 |
*out = set; |
| 577 |
return VK_SUCCESS; |
| 578 |
} |
| 579 |
|
| 580 |
VkResult |
| 581 |
panvk_per_arch(AllocateDescriptorSets)( |
| 582 |
VkDevice _device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 583 |
VkDescriptorSet *pDescriptorSets) |
| 584 |
{ |
| 585 |
VK_FROM_HANDLE(panvk_descriptor_pool, pool, pAllocateInfo->descriptorPool); |
| 586 |
VkResult result = VK_SUCCESS; |
| 587 |
unsigned i; |
| 588 |
|
| 589 |
struct panvk_descriptor_set *set = NULL; |
| 590 |
|
| 591 |
const VkDescriptorSetVariableDescriptorCountAllocateInfo *var_desc_count = |
| 592 |
vk_find_struct_const( |
| 593 |
pAllocateInfo->pNext, |
| 594 |
DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO); |
| 595 |
|
| 596 |
/* allocate a set of buffers for each shader to contain descriptors */ |
| 597 |
for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) { |
| 598 |
VK_FROM_HANDLE(panvk_descriptor_set_layout, layout, |
| 599 |
pAllocateInfo->pSetLayouts[i]); |
| 600 |
/* If descriptorSetCount is zero or this structure is not included in |
| 601 |
* the pNext chain, then the variable lengths are considered to be zero. |
| 602 |
*/ |
| 603 |
const uint32_t variable_count = |
| 604 |
var_desc_count && var_desc_count->descriptorSetCount > 0 |
| 605 |
? var_desc_count->pDescriptorCounts[i] |
| 606 |
: 0; |
| 607 |
|
| 608 |
result = panvk_desc_pool_allocate_set(pool, layout, variable_count, &set); |
| 609 |
if (result != VK_SUCCESS) |
| 610 |
goto err_free_sets; |
| 611 |
|
| 612 |
pDescriptorSets[i] = panvk_descriptor_set_to_handle(set); |
| 613 |
} |
| 614 |
|
| 615 |
return VK_SUCCESS; |
| 616 |
|
| 617 |
err_free_sets: |
| 618 |
panvk_per_arch(FreeDescriptorSets)(_device, pAllocateInfo->descriptorPool, i, |
| 619 |
pDescriptorSets); |
| 620 |
for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) |
| 621 |
pDescriptorSets[i] = VK_NULL_HANDLE; |
| 622 |
|
| 623 |
return result; |
| 624 |
} |
| 625 |
|
| 626 |
VkResult |
| 627 |
panvk_per_arch(FreeDescriptorSets)(VkDevice _device, |
| 628 |
VkDescriptorPool descriptorPool, |
| 629 |
uint32_t descriptorSetCount, |
| 630 |
const VkDescriptorSet *pDescriptorSets) |
| 631 |
{ |
| 632 |
VK_FROM_HANDLE(panvk_descriptor_pool, pool, descriptorPool); |
| 633 |
|
| 634 |
for (unsigned i = 0; i < descriptorSetCount; i++) { |
| 635 |
VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorSets[i]); |
| 636 |
|
| 637 |
if (set) |
| 638 |
panvk_desc_pool_free_set(pool, set); |
| 639 |
} |
| 640 |
return VK_SUCCESS; |
| 641 |
} |
| 642 |
|
| 643 |
VkResult |
| 644 |
panvk_per_arch(ResetDescriptorPool)(VkDevice _device, VkDescriptorPool _pool, |
| 645 |
VkDescriptorPoolResetFlags flags) |
| 646 |
{ |
| 647 |
VK_FROM_HANDLE(panvk_descriptor_pool, pool, _pool); |
| 648 |
|
| 649 |
for (uint32_t i = 0; i < pool->max_sets; i++) |
| 650 |
panvk_desc_pool_free_set(pool, &pool->sets[i]); |
| 651 |
|
| 652 |
BITSET_SET_COUNT(pool->free_sets, 0, pool->max_sets); |
| 653 |
return VK_SUCCESS; |
| 654 |
} |
| 655 |
|
| 656 |
VkResult |
| 657 |
panvk_per_arch(descriptor_set_write)(struct panvk_descriptor_set *set, |
| 658 |
const VkWriteDescriptorSet *write, |
| 659 |
bool write_immutable_samplers) |
| 660 |
{ |
| 661 |
switch (write->descriptorType) { |
| 662 |
case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 663 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 664 |
write_sampler_desc(set, write->pImageInfo + j, write->dstBinding, |
| 665 |
write->dstArrayElement + j, |
| 666 |
write_immutable_samplers); |
| 667 |
} |
| 668 |
break; |
| 669 |
|
| 670 |
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 671 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 672 |
write_image_view_desc(set, write->pImageInfo + j, write->dstBinding, |
| 673 |
write->dstArrayElement + j, |
| 674 |
write->descriptorType); |
| 675 |
write_sampler_desc(set, write->pImageInfo + j, write->dstBinding, |
| 676 |
write->dstArrayElement + j, |
| 677 |
write_immutable_samplers); |
| 678 |
} |
| 679 |
break; |
| 680 |
|
| 681 |
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 682 |
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 683 |
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 684 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 685 |
write_image_view_desc(set, write->pImageInfo + j, write->dstBinding, |
| 686 |
write->dstArrayElement + j, |
| 687 |
write->descriptorType); |
| 688 |
} |
| 689 |
break; |
| 690 |
|
| 691 |
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 692 |
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 693 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 694 |
write_buffer_view_desc(set, write->pTexelBufferView[j], |
| 695 |
write->dstBinding, write->dstArrayElement + j, |
| 696 |
write->descriptorType); |
| 697 |
} |
| 698 |
break; |
| 699 |
|
| 700 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 701 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 702 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 703 |
write_buffer_desc(set, write->pBufferInfo + j, write->dstBinding, |
| 704 |
write->dstArrayElement + j, write->descriptorType); |
| 705 |
} |
| 706 |
break; |
| 707 |
|
| 708 |
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: { |
| 709 |
const VkWriteDescriptorSetInlineUniformBlock *inline_info = |
| 710 |
vk_find_struct_const(write->pNext, |
| 711 |
WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK); |
| 712 |
write_iub(set, write->dstBinding, write->dstArrayElement, |
| 713 |
write->descriptorCount, inline_info->pData); |
| 714 |
break; |
| 715 |
} |
| 716 |
|
| 717 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 718 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 719 |
for (uint32_t j = 0; j < write->descriptorCount; j++) { |
| 720 |
write_dynamic_buffer_desc(set, write->pBufferInfo + j, |
| 721 |
write->dstBinding, |
| 722 |
write->dstArrayElement + j); |
| 723 |
} |
| 724 |
break; |
| 725 |
|
| 726 |
default: |
| 727 |
UNREACHABLE("Unsupported descriptor type"); |
| 728 |
} |
| 729 |
return VK_SUCCESS; |
| 730 |
} |
| 731 |
|
| 732 |
static VkResult |
| 733 |
panvk_descriptor_set_copy(const VkCopyDescriptorSet *copy) |
| 734 |
{ |
| 735 |
VK_FROM_HANDLE(panvk_descriptor_set, src_set, copy->srcSet); |
| 736 |
VK_FROM_HANDLE(panvk_descriptor_set, dst_set, copy->dstSet); |
| 737 |
|
| 738 |
const struct panvk_descriptor_set_binding_layout *dst_binding_layout = |
| 739 |
&dst_set->layout->bindings[copy->dstBinding]; |
| 740 |
const struct panvk_descriptor_set_binding_layout *src_binding_layout = |
| 741 |
&src_set->layout->bindings[copy->srcBinding]; |
| 742 |
|
| 743 |
ASSERTED const bool src_mutable = |
| 744 |
src_binding_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_EXT; |
| 745 |
ASSERTED const bool dst_mutable = |
| 746 |
dst_binding_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_EXT; |
| 747 |
assert(dst_binding_layout->type == src_binding_layout->type || src_mutable || dst_mutable); |
| 748 |
|
| 749 |
switch (src_binding_layout->type) { |
| 750 |
case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 751 |
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 752 |
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 753 |
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 754 |
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 755 |
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 756 |
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 757 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 758 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 759 |
case VK_DESCRIPTOR_TYPE_MUTABLE_EXT: |
| 760 |
for (uint32_t i = 0; i < copy->descriptorCount; i++) { |
| 761 |
const void *src = get_desc_slot_ptr(src_set, copy->srcBinding, |
| 762 |
copy->srcArrayElement + i, |
| 763 |
NO_SUBDESC); |
| 764 |
const size_t copy_size = |
| 765 |
PANVK_DESCRIPTOR_SIZE * panvk_get_desc_stride(src_binding_layout); |
| 766 |
write_desc_data(dst_set, copy->dstBinding, copy->dstArrayElement + i, |
| 767 |
NO_SUBDESC, 0, src, copy_size); |
| 768 |
} |
| 769 |
break; |
| 770 |
|
| 771 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 772 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 773 |
uint32_t dst_dyn_buf_idx = |
| 774 |
dst_binding_layout->desc_idx + copy->dstArrayElement; |
| 775 |
uint32_t src_dyn_buf_idx = |
| 776 |
src_binding_layout->desc_idx + copy->srcArrayElement; |
| 777 |
|
| 778 |
memcpy( |
| 779 |
&dst_set->dyn_bufs[dst_dyn_buf_idx], |
| 780 |
&src_set->dyn_bufs[src_dyn_buf_idx], |
| 781 |
copy->descriptorCount * sizeof(dst_set->dyn_bufs[dst_dyn_buf_idx])); |
| 782 |
break; |
| 783 |
} |
| 784 |
|
| 785 |
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: { |
| 786 |
const void *src = |
| 787 |
get_desc_slot_ptr(src_set, copy->srcBinding, 0, NO_SUBDESC); |
| 788 |
src += PANVK_DESCRIPTOR_SIZE + copy->srcArrayElement; |
| 789 |
write_iub(dst_set, copy->dstBinding, copy->dstArrayElement, |
| 790 |
copy->descriptorCount, src); |
| 791 |
break; |
| 792 |
} |
| 793 |
|
| 794 |
default: |
| 795 |
UNREACHABLE("Unsupported descriptor type"); |
| 796 |
} |
| 797 |
|
| 798 |
return VK_SUCCESS; |
| 799 |
} |
| 800 |
|
| 801 |
void |
| 802 |
panvk_per_arch(UpdateDescriptorSets)( |
| 803 |
VkDevice _device, uint32_t descriptorWriteCount, |
| 804 |
const VkWriteDescriptorSet *pDescriptorWrites, uint32_t descriptorCopyCount, |
| 805 |
const VkCopyDescriptorSet *pDescriptorCopies) |
| 806 |
{ |
| 807 |
for (uint32_t i = 0; i < descriptorWriteCount; i++) { |
| 808 |
VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorWrites[i].dstSet); |
| 809 |
|
| 810 |
panvk_per_arch(descriptor_set_write)(set, &pDescriptorWrites[i], false); |
| 811 |
} |
| 812 |
|
| 813 |
for (uint32_t i = 0; i < descriptorCopyCount; i++) |
| 814 |
panvk_descriptor_set_copy(&pDescriptorCopies[i]); |
| 815 |
|
| 816 |
/* Flush at the end so we call into the kernel as few times as possible. |
| 817 |
* Note that redundant flushes do nothing. |
| 818 |
*/ |
| 819 |
for (uint32_t i = 0; i < descriptorWriteCount; i++) { |
| 820 |
VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorWrites[i].dstSet); |
| 821 |
|
| 822 |
panvk_per_arch(descriptor_set_flush)(set); |
| 823 |
} |
| 824 |
|
| 825 |
for (uint32_t i = 0; i < descriptorCopyCount; i++) { |
| 826 |
VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorCopies[i].dstSet); |
| 827 |
|
| 828 |
panvk_per_arch(descriptor_set_flush)(set); |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
void |
| 833 |
panvk_per_arch(descriptor_set_write_template)( |
| 834 |
struct panvk_descriptor_set *set, |
| 835 |
const struct vk_descriptor_update_template *template, const void *data, |
| 836 |
bool write_immutable_samplers) |
| 837 |
{ |
| 838 |
for (uint32_t i = 0; i < template->entry_count; i++) { |
| 839 |
const struct vk_descriptor_template_entry *entry = &template->entries[i]; |
| 840 |
|
| 841 |
switch (entry->type) { |
| 842 |
case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 843 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 844 |
const VkDescriptorImageInfo *info = |
| 845 |
data + entry->offset + j * entry->stride; |
| 846 |
|
| 847 |
write_sampler_desc(set, info, entry->binding, |
| 848 |
entry->array_element + j, |
| 849 |
write_immutable_samplers); |
| 850 |
} |
| 851 |
break; |
| 852 |
|
| 853 |
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 854 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 855 |
const VkDescriptorImageInfo *info = |
| 856 |
data + entry->offset + j * entry->stride; |
| 857 |
write_image_view_desc(set, info, entry->binding, |
| 858 |
entry->array_element + j, entry->type); |
| 859 |
write_sampler_desc(set, info, entry->binding, |
| 860 |
entry->array_element + j, |
| 861 |
write_immutable_samplers); |
| 862 |
} |
| 863 |
break; |
| 864 |
|
| 865 |
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 866 |
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 867 |
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 868 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 869 |
const VkDescriptorImageInfo *info = |
| 870 |
data + entry->offset + j * entry->stride; |
| 871 |
|
| 872 |
write_image_view_desc(set, info, entry->binding, |
| 873 |
entry->array_element + j, entry->type); |
| 874 |
} |
| 875 |
break; |
| 876 |
|
| 877 |
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 878 |
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 879 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 880 |
const VkBufferView *bview = |
| 881 |
data + entry->offset + j * entry->stride; |
| 882 |
|
| 883 |
write_buffer_view_desc(set, *bview, entry->binding, |
| 884 |
entry->array_element + j, entry->type); |
| 885 |
} |
| 886 |
break; |
| 887 |
|
| 888 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 889 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 890 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 891 |
const VkDescriptorBufferInfo *info = |
| 892 |
data + entry->offset + j * entry->stride; |
| 893 |
|
| 894 |
write_buffer_desc(set, info, entry->binding, |
| 895 |
entry->array_element + j, entry->type); |
| 896 |
} |
| 897 |
break; |
| 898 |
|
| 899 |
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 900 |
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 901 |
for (uint32_t j = 0; j < entry->array_count; j++) { |
| 902 |
const VkDescriptorBufferInfo *info = |
| 903 |
data + entry->offset + j * entry->stride; |
| 904 |
|
| 905 |
write_dynamic_buffer_desc(set, info, entry->binding, |
| 906 |
entry->array_element + j); |
| 907 |
} |
| 908 |
break; |
| 909 |
|
| 910 |
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: |
| 911 |
write_iub(set, entry->binding, entry->array_element, |
| 912 |
entry->array_count, data + entry->offset); |
| 913 |
break; |
| 914 |
|
| 915 |
default: |
| 916 |
UNREACHABLE("Unsupported descriptor type"); |
| 917 |
} |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
void |
| 922 |
panvk_per_arch(UpdateDescriptorSetWithTemplate)( |
| 923 |
VkDevice _device, VkDescriptorSet descriptorSet, |
| 924 |
VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void *pData) |
| 925 |
{ |
| 926 |
VK_FROM_HANDLE(panvk_descriptor_set, set, descriptorSet); |
| 927 |
VK_FROM_HANDLE(vk_descriptor_update_template, template, |
| 928 |
descriptorUpdateTemplate); |
| 929 |
|
| 930 |
panvk_per_arch(descriptor_set_write_template)(set, template, pData, false); |
| 931 |
panvk_per_arch(descriptor_set_flush)(set); |
| 932 |
} |
| 933 |
|
| 934 |
void panvk_per_arch(descriptor_set_flush)(struct panvk_descriptor_set *set) |
| 935 |
{ |
| 936 |
if (set->descs.dirty_max <= set->descs.dirty_min) { |
| 937 |
assert(set->descs.dirty_max == 0); |
| 938 |
assert(set->descs.dirty_min == SIZE_MAX); |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
if (set->pool->desc_bo) { |
| 943 |
assert(set->descs.dev >= set->pool->desc_bo->addr.dev); |
| 944 |
uint64_t set_offset = set->descs.dev - set->pool->desc_bo->addr.dev; |
| 945 |
assert(set_offset < set->pool->desc_bo->bo->size); |
| 946 |
|
| 947 |
assert(set_offset + set->descs.dirty_max <= set->pool->desc_bo->bo->size); |
| 948 |
size_t offset = set_offset + set->descs.dirty_min; |
| 949 |
size_t range = set->descs.dirty_max - set->descs.dirty_min; |
| 950 |
|
| 951 |
panvk_priv_bo_flush(set->pool->desc_bo, offset, range); |
| 952 |
} |
| 953 |
|
| 954 |
set->descs.dirty_min = SIZE_MAX; |
| 955 |
set->descs.dirty_max = 0; |
| 956 |
} |