Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_descriptor_set.c
4560 views
/*1* Copyright © 2021 Collabora Ltd.2*3* Derived from:4* Copyright © 2016 Red Hat.5* Copyright © 2016 Bas Nieuwenhuizen6*7* Permission is hereby granted, free of charge, to any person obtaining a8* copy of this software and associated documentation files (the "Software"),9* to deal in the Software without restriction, including without limitation10* the rights to use, copy, modify, merge, publish, distribute, sublicense,11* and/or sell copies of the Software, and to permit persons to whom the12* Software is furnished to do so, subject to the following conditions:13*14* The above copyright notice and this permission notice (including the next15* paragraph) shall be included in all copies or substantial portions of the16* Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL21* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER22* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING23* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER24* DEALINGS IN THE SOFTWARE.25*/26#include "panvk_private.h"2728#include <assert.h>29#include <fcntl.h>30#include <stdbool.h>31#include <string.h>32#include <unistd.h>3334#include "util/mesa-sha1.h"35#include "vk_descriptors.h"36#include "vk_util.h"3738#include "pan_bo.h"39#include "midgard_pack.h"4041VkResult42panvk_CreateDescriptorSetLayout(VkDevice _device,43const VkDescriptorSetLayoutCreateInfo *pCreateInfo,44const VkAllocationCallbacks *pAllocator,45VkDescriptorSetLayout *pSetLayout)46{47VK_FROM_HANDLE(panvk_device, device, _device);48struct panvk_descriptor_set_layout *set_layout;49VkDescriptorSetLayoutBinding *bindings = NULL;50unsigned num_bindings = 0;51VkResult result;5253if (pCreateInfo->bindingCount) {54result =55vk_create_sorted_bindings(pCreateInfo->pBindings,56pCreateInfo->bindingCount,57&bindings);58if (result != VK_SUCCESS)59return vk_error(device->instance, result);6061num_bindings = bindings[pCreateInfo->bindingCount - 1].binding + 1;62}6364unsigned num_immutable_samplers = 0;65for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {66if (bindings[i].pImmutableSamplers)67num_immutable_samplers += bindings[i].descriptorCount;68}6970size_t size = sizeof(*set_layout) +71(sizeof(struct panvk_descriptor_set_binding_layout) *72num_bindings) +73(sizeof(struct panvk_sampler *) * num_immutable_samplers);74set_layout = vk_object_zalloc(&device->vk, pAllocator, size,75VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);76if (!set_layout) {77result = VK_ERROR_OUT_OF_HOST_MEMORY;78goto err_free_bindings;79}8081struct panvk_sampler **immutable_samplers =82(struct panvk_sampler **)((uint8_t *)set_layout + sizeof(*set_layout) +83(sizeof(struct panvk_descriptor_set_binding_layout) *84num_bindings));8586set_layout->flags = pCreateInfo->flags;87set_layout->binding_count = num_bindings;8889unsigned sampler_idx = 0, tex_idx = 0, ubo_idx = 0, ssbo_idx = 0;90unsigned dynoffset_idx = 0, desc_idx = 0;9192for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {93const VkDescriptorSetLayoutBinding *binding = &bindings[i];94struct panvk_descriptor_set_binding_layout *binding_layout =95&set_layout->bindings[binding->binding];9697binding_layout->type = binding->descriptorType;98binding_layout->array_size = binding->descriptorCount;99binding_layout->shader_stages = binding->stageFlags;100if (binding->pImmutableSamplers) {101binding_layout->immutable_samplers = immutable_samplers;102immutable_samplers += binding_layout->array_size;103for (unsigned j = 0; j < binding_layout->array_size; j++) {104VK_FROM_HANDLE(panvk_sampler, sampler, binding->pImmutableSamplers[j]);105binding_layout->immutable_samplers[j] = sampler;106}107}108109binding_layout->desc_idx = desc_idx;110desc_idx += binding->descriptorCount;111switch (binding_layout->type) {112case VK_DESCRIPTOR_TYPE_SAMPLER:113binding_layout->sampler_idx = sampler_idx;114sampler_idx += binding_layout->array_size;115break;116case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:117binding_layout->sampler_idx = sampler_idx;118binding_layout->tex_idx = tex_idx;119sampler_idx += binding_layout->array_size;120tex_idx += binding_layout->array_size;121break;122case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:123case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:124case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:125case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:126case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:127binding_layout->tex_idx = tex_idx;128tex_idx += binding_layout->array_size;129break;130case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:131binding_layout->dynoffset_idx = dynoffset_idx;132dynoffset_idx += binding_layout->array_size;133FALLTHROUGH;134case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:135binding_layout->ubo_idx = ubo_idx;136ubo_idx += binding_layout->array_size;137break;138case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:139binding_layout->dynoffset_idx = dynoffset_idx;140dynoffset_idx += binding_layout->array_size;141FALLTHROUGH;142case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:143binding_layout->ssbo_idx = ssbo_idx;144ssbo_idx += binding_layout->array_size;145break;146default:147unreachable("Invalid descriptor type");148}149}150151set_layout->num_descs = desc_idx;152set_layout->num_samplers = sampler_idx;153set_layout->num_textures = tex_idx;154set_layout->num_ubos = ubo_idx;155set_layout->num_ssbos = ssbo_idx;156set_layout->num_dynoffsets = dynoffset_idx;157158free(bindings);159*pSetLayout = panvk_descriptor_set_layout_to_handle(set_layout);160return VK_SUCCESS;161162err_free_bindings:163free(bindings);164return vk_error(device->instance, result);165}166167void168panvk_DestroyDescriptorSetLayout(VkDevice _device,169VkDescriptorSetLayout _set_layout,170const VkAllocationCallbacks *pAllocator)171{172VK_FROM_HANDLE(panvk_device, device, _device);173VK_FROM_HANDLE(panvk_descriptor_set_layout, set_layout, _set_layout);174175if (!set_layout)176return;177178vk_object_free(&device->vk, pAllocator, set_layout);179}180181/* FIXME: make sure those values are correct */182#define PANVK_MAX_TEXTURES (1 << 16)183#define PANVK_MAX_SAMPLERS (1 << 16)184#define PANVK_MAX_UBOS 255185186void187panvk_GetDescriptorSetLayoutSupport(VkDevice _device,188const VkDescriptorSetLayoutCreateInfo *pCreateInfo,189VkDescriptorSetLayoutSupport *pSupport)190{191VK_FROM_HANDLE(panvk_device, device, _device);192193pSupport->supported = false;194195VkDescriptorSetLayoutBinding *bindings;196VkResult result =197vk_create_sorted_bindings(pCreateInfo->pBindings,198pCreateInfo->bindingCount,199&bindings);200if (result != VK_SUCCESS) {201vk_error(device->instance, result);202return;203}204205unsigned sampler_idx = 0, tex_idx = 0, ubo_idx = 0, ssbo_idx = 0, dynoffset_idx = 0;206for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {207const VkDescriptorSetLayoutBinding *binding = &bindings[i];208209switch (binding->descriptorType) {210case VK_DESCRIPTOR_TYPE_SAMPLER:211sampler_idx += binding->descriptorCount;212break;213case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:214sampler_idx += binding->descriptorCount;215tex_idx += binding->descriptorCount;216break;217case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:218case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:219case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:220case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:221case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:222tex_idx += binding->descriptorCount;223break;224case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:225dynoffset_idx += binding->descriptorCount;226FALLTHROUGH;227case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:228ubo_idx += binding->descriptorCount;229break;230case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:231dynoffset_idx += binding->descriptorCount;232FALLTHROUGH;233case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:234ssbo_idx += binding->descriptorCount;235break;236default:237unreachable("Invalid descriptor type");238}239}240241/* The maximum values apply to all sets attached to a pipeline since all242* sets descriptors have to be merged in a single array.243*/244if (tex_idx > PANVK_MAX_TEXTURES / MAX_SETS ||245sampler_idx > PANVK_MAX_SAMPLERS / MAX_SETS ||246ubo_idx > PANVK_MAX_UBOS / MAX_SETS)247return;248249pSupport->supported = true;250}251252/*253* Pipeline layouts. These have nothing to do with the pipeline. They are254* just multiple descriptor set layouts pasted together.255*/256257VkResult258panvk_CreatePipelineLayout(VkDevice _device,259const VkPipelineLayoutCreateInfo *pCreateInfo,260const VkAllocationCallbacks *pAllocator,261VkPipelineLayout *pPipelineLayout)262{263VK_FROM_HANDLE(panvk_device, device, _device);264struct panvk_pipeline_layout *layout;265struct mesa_sha1 ctx;266267layout = vk_object_zalloc(&device->vk, pAllocator, sizeof(*layout),268VK_OBJECT_TYPE_PIPELINE_LAYOUT);269if (layout == NULL)270return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);271272layout->num_sets = pCreateInfo->setLayoutCount;273_mesa_sha1_init(&ctx);274275unsigned sampler_idx = 0, tex_idx = 0, ssbo_idx = 0, ubo_idx = 0, dynoffset_idx = 0;276for (unsigned set = 0; set < pCreateInfo->setLayoutCount; set++) {277VK_FROM_HANDLE(panvk_descriptor_set_layout, set_layout,278pCreateInfo->pSetLayouts[set]);279layout->sets[set].layout = set_layout;280layout->sets[set].sampler_offset = sampler_idx;281layout->sets[set].tex_offset = tex_idx;282layout->sets[set].ubo_offset = ubo_idx;283layout->sets[set].ssbo_offset = ssbo_idx;284layout->sets[set].dynoffset_offset = dynoffset_idx;285sampler_idx += set_layout->num_samplers;286tex_idx += set_layout->num_textures;287ubo_idx += set_layout->num_ubos + (set_layout->num_dynoffsets != 0);288ssbo_idx += set_layout->num_ssbos;289dynoffset_idx += set_layout->num_dynoffsets;290291for (unsigned b = 0; b < set_layout->binding_count; b++) {292struct panvk_descriptor_set_binding_layout *binding_layout =293&set_layout->bindings[b];294295if (binding_layout->immutable_samplers) {296for (unsigned s = 0; s < binding_layout->array_size; s++) {297struct panvk_sampler *sampler = binding_layout->immutable_samplers[s];298299_mesa_sha1_update(&ctx, &sampler->desc, sizeof(sampler->desc));300}301}302_mesa_sha1_update(&ctx, &binding_layout->type, sizeof(binding_layout->type));303_mesa_sha1_update(&ctx, &binding_layout->array_size, sizeof(binding_layout->array_size));304_mesa_sha1_update(&ctx, &binding_layout->desc_idx, sizeof(binding_layout->sampler_idx));305_mesa_sha1_update(&ctx, &binding_layout->shader_stages, sizeof(binding_layout->shader_stages));306}307}308309layout->num_samplers = sampler_idx;310layout->num_textures = tex_idx;311layout->num_ubos = ubo_idx;312layout->num_ssbos = ssbo_idx;313layout->num_dynoffsets = dynoffset_idx;314315_mesa_sha1_final(&ctx, layout->sha1);316317*pPipelineLayout = panvk_pipeline_layout_to_handle(layout);318return VK_SUCCESS;319}320321void322panvk_DestroyPipelineLayout(VkDevice _device,323VkPipelineLayout _pipelineLayout,324const VkAllocationCallbacks *pAllocator)325{326VK_FROM_HANDLE(panvk_device, device, _device);327VK_FROM_HANDLE(panvk_pipeline_layout, pipeline_layout, _pipelineLayout);328329if (!pipeline_layout)330return;331332vk_object_free(&device->vk, pAllocator, pipeline_layout);333}334335VkResult336panvk_CreateDescriptorPool(VkDevice _device,337const VkDescriptorPoolCreateInfo *pCreateInfo,338const VkAllocationCallbacks *pAllocator,339VkDescriptorPool *pDescriptorPool)340{341VK_FROM_HANDLE(panvk_device, device, _device);342struct panvk_descriptor_pool *pool;343344pool = vk_object_zalloc(&device->vk, pAllocator,345sizeof(struct panvk_descriptor_pool),346VK_OBJECT_TYPE_DESCRIPTOR_POOL);347if (!pool)348return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);349350pool->max.sets = pCreateInfo->maxSets;351352for (unsigned i = 0; i < pCreateInfo->poolSizeCount; ++i) {353unsigned desc_count = pCreateInfo->pPoolSizes[i].descriptorCount;354355switch(pCreateInfo->pPoolSizes[i].type) {356case VK_DESCRIPTOR_TYPE_SAMPLER:357pool->max.samplers += desc_count;358break;359case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:360pool->max.combined_image_samplers += desc_count;361break;362case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:363pool->max.sampled_images += desc_count;364break;365case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:366pool->max.storage_images += desc_count;367break;368case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:369pool->max.uniform_texel_bufs += desc_count;370break;371case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:372pool->max.storage_texel_bufs += desc_count;373break;374case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:375pool->max.input_attachments += desc_count;376break;377case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:378pool->max.uniform_bufs += desc_count;379break;380case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:381pool->max.storage_bufs += desc_count;382break;383case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:384pool->max.uniform_dyn_bufs += desc_count;385break;386case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:387pool->max.storage_dyn_bufs += desc_count;388break;389default:390unreachable("Invalid descriptor type");391}392}393394*pDescriptorPool = panvk_descriptor_pool_to_handle(pool);395return VK_SUCCESS;396}397398void399panvk_DestroyDescriptorPool(VkDevice _device,400VkDescriptorPool _pool,401const VkAllocationCallbacks *pAllocator)402{403VK_FROM_HANDLE(panvk_device, device, _device);404VK_FROM_HANDLE(panvk_descriptor_pool, pool, _pool);405406if (pool)407vk_object_free(&device->vk, pAllocator, pool);408}409410VkResult411panvk_ResetDescriptorPool(VkDevice _device,412VkDescriptorPool _pool,413VkDescriptorPoolResetFlags flags)414{415VK_FROM_HANDLE(panvk_descriptor_pool, pool, _pool);416memset(&pool->cur, 0, sizeof(pool->cur));417return VK_SUCCESS;418}419420static VkResult421panvk_descriptor_set_create(struct panvk_device *device,422struct panvk_descriptor_pool *pool,423const struct panvk_descriptor_set_layout *layout,424struct panvk_descriptor_set **out_set)425{426const struct panfrost_device *pdev = &device->physical_device->pdev;427struct panvk_descriptor_set *set;428429/* TODO: Allocate from the pool! */430set = vk_object_zalloc(&device->vk, NULL,431sizeof(struct panvk_descriptor_set),432VK_OBJECT_TYPE_DESCRIPTOR_SET);433if (!set)434return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);435436set->layout = layout;437set->descs = vk_alloc(&device->vk.alloc,438sizeof(*set->descs) * layout->num_descs, 8,439VK_OBJECT_TYPE_DESCRIPTOR_SET);440if (!set->descs)441goto err_free_set;442443if (layout->num_ubos) {444set->ubos = vk_zalloc(&device->vk.alloc,445sizeof(*set->ubos) * layout->num_ubos, 8,446VK_OBJECT_TYPE_DESCRIPTOR_SET);447if (!set->ubos)448goto err_free_set;449}450451if (layout->num_samplers) {452set->samplers = vk_zalloc(&device->vk.alloc,453sizeof(*set->samplers) * layout->num_samplers, 8,454VK_OBJECT_TYPE_DESCRIPTOR_SET);455if (!set->samplers)456goto err_free_set;457}458459if (layout->num_textures) {460if (pan_is_bifrost(pdev)) {461set->textures.bifrost = vk_zalloc(&device->vk.alloc,462sizeof(*set->textures.bifrost) *463layout->num_textures,4648, VK_OBJECT_TYPE_DESCRIPTOR_SET);465} else {466set->textures.midgard = vk_zalloc(&device->vk.alloc,467sizeof(*set->textures.midgard) *468layout->num_textures,4698, VK_OBJECT_TYPE_DESCRIPTOR_SET);470}471472if (!set->textures.midgard)473goto err_free_set;474}475476for (unsigned i = 0; i < layout->binding_count; i++) {477if (!layout->bindings[i].immutable_samplers)478continue;479480for (unsigned j = 0; j < layout->bindings[i].array_size; j++) {481set->descs[layout->bindings[i].desc_idx].image.sampler =482layout->bindings[i].immutable_samplers[j];483}484}485486*out_set = set;487return VK_SUCCESS;488489err_free_set:490vk_free(&device->vk.alloc, set->textures.midgard);491vk_free(&device->vk.alloc, set->samplers);492vk_free(&device->vk.alloc, set->ubos);493vk_free(&device->vk.alloc, set->descs);494vk_object_free(&device->vk, NULL, set);495return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);496}497498static void499panvk_descriptor_set_destroy(struct panvk_device *device,500struct panvk_descriptor_pool *pool,501struct panvk_descriptor_set *set)502{503vk_free(&device->vk.alloc, set->textures.midgard);504vk_free(&device->vk.alloc, set->samplers);505vk_free(&device->vk.alloc, set->ubos);506vk_free(&device->vk.alloc, set->descs);507vk_object_free(&device->vk, NULL, set);508}509510VkResult511panvk_AllocateDescriptorSets(VkDevice _device,512const VkDescriptorSetAllocateInfo *pAllocateInfo,513VkDescriptorSet *pDescriptorSets)514{515VK_FROM_HANDLE(panvk_device, device, _device);516VK_FROM_HANDLE(panvk_descriptor_pool, pool, pAllocateInfo->descriptorPool);517VkResult result;518unsigned i;519520for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {521VK_FROM_HANDLE(panvk_descriptor_set_layout, layout,522pAllocateInfo->pSetLayouts[i]);523struct panvk_descriptor_set *set = NULL;524525result = panvk_descriptor_set_create(device, pool, layout, &set);526if (result != VK_SUCCESS)527goto err_free_sets;528529pDescriptorSets[i] = panvk_descriptor_set_to_handle(set);530}531532return VK_SUCCESS;533534err_free_sets:535panvk_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool, i, pDescriptorSets);536for (i = 0; i < pAllocateInfo->descriptorSetCount; i++)537pDescriptorSets[i] = VK_NULL_HANDLE;538539return result;540}541542VkResult543panvk_FreeDescriptorSets(VkDevice _device,544VkDescriptorPool descriptorPool,545uint32_t count,546const VkDescriptorSet *pDescriptorSets)547{548VK_FROM_HANDLE(panvk_device, device, _device);549VK_FROM_HANDLE(panvk_descriptor_pool, pool, descriptorPool);550551for (unsigned i = 0; i < count; i++) {552VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorSets[i]);553554if (set)555panvk_descriptor_set_destroy(device, pool, set);556}557return VK_SUCCESS;558}559560static void561panvk_set_image_desc(struct panvk_descriptor *desc,562const VkDescriptorImageInfo *pImageInfo)563{564VK_FROM_HANDLE(panvk_sampler, sampler, pImageInfo->sampler);565VK_FROM_HANDLE(panvk_image_view, image_view, pImageInfo->imageView);566desc->image.sampler = sampler;567desc->image.view = image_view;568desc->image.layout = pImageInfo->imageLayout;569}570571static void572panvk_set_texel_buffer_view_desc(struct panvk_descriptor *desc,573const VkBufferView *pTexelBufferView)574{575VK_FROM_HANDLE(panvk_buffer_view, buffer_view, *pTexelBufferView);576desc->buffer_view = buffer_view;577}578579static void580panvk_set_buffer_info_desc(struct panvk_descriptor *desc,581const VkDescriptorBufferInfo *pBufferInfo)582{583VK_FROM_HANDLE(panvk_buffer, buffer, pBufferInfo->buffer);584desc->buffer_info.buffer = buffer;585desc->buffer_info.offset = pBufferInfo->offset;586desc->buffer_info.range = pBufferInfo->range;587}588589static void590panvk_set_ubo_desc(void *ubo,591const VkDescriptorBufferInfo *pBufferInfo)592{593VK_FROM_HANDLE(panvk_buffer, buffer, pBufferInfo->buffer);594size_t size = pBufferInfo->range == VK_WHOLE_SIZE ?595(buffer->bo->size - pBufferInfo->offset) :596pBufferInfo->range;597598pan_pack(ubo, UNIFORM_BUFFER, cfg) {599cfg.pointer = buffer->bo->ptr.gpu + pBufferInfo->offset;600cfg.entries = DIV_ROUND_UP(size, 16);601}602}603604static void605panvk_set_sampler_desc(void *desc,606const VkDescriptorImageInfo *pImageInfo)607{608VK_FROM_HANDLE(panvk_sampler, sampler, pImageInfo->sampler);609610memcpy(desc, &sampler->desc, sizeof(sampler->desc));611}612613static void614panvk_set_bifrost_texture_desc(struct mali_bifrost_texture_packed *desc,615const VkDescriptorImageInfo *pImageInfo)616{617VK_FROM_HANDLE(panvk_image_view, view, pImageInfo->imageView);618619*desc = view->bifrost.tex_desc;620}621622static void623panvk_set_midgard_texture_desc(mali_ptr *desc,624const VkDescriptorImageInfo *pImageInfo)625{626VK_FROM_HANDLE(panvk_image_view, view, pImageInfo->imageView);627628*desc = view->bo->ptr.gpu;629}630631static void632panvk_write_descriptor_set(struct panvk_device *dev,633const VkWriteDescriptorSet *pDescriptorWrite)634{635const struct panfrost_device *pdev = &dev->physical_device->pdev;636VK_FROM_HANDLE(panvk_descriptor_set, set, pDescriptorWrite->dstSet);637const struct panvk_descriptor_set_layout *layout = set->layout;638unsigned dest_offset = pDescriptorWrite->dstArrayElement;639unsigned binding = pDescriptorWrite->dstBinding;640unsigned src_offset = 0;641642while (src_offset < pDescriptorWrite->descriptorCount &&643binding < layout->binding_count) {644const struct panvk_descriptor_set_binding_layout *binding_layout =645&layout->bindings[binding];646647if (!binding_layout->array_size) {648binding++;649dest_offset = 0;650continue;651}652653assert(pDescriptorWrite->descriptorType == binding_layout->type);654unsigned ndescs = MIN2(pDescriptorWrite->descriptorCount - src_offset,655binding_layout->array_size - dest_offset);656struct panvk_descriptor *descs = &set->descs[binding_layout->desc_idx + dest_offset];657assert(binding_layout->desc_idx + dest_offset + ndescs <= set->layout->num_descs);658659switch (pDescriptorWrite->descriptorType) {660case VK_DESCRIPTOR_TYPE_SAMPLER:661case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:662case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:663for (unsigned i = 0; i < ndescs; i++) {664const VkDescriptorImageInfo *info = &pDescriptorWrite->pImageInfo[src_offset + i];665666if (pDescriptorWrite->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||667pDescriptorWrite->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {668unsigned sampler = binding_layout->sampler_idx + dest_offset + i;669670panvk_set_sampler_desc(&set->samplers[sampler], info);671}672673if (pDescriptorWrite->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||674pDescriptorWrite->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {675unsigned tex = binding_layout->tex_idx + dest_offset + i;676677if (pan_is_bifrost(pdev))678panvk_set_bifrost_texture_desc(&set->textures.bifrost[tex], info);679else680panvk_set_midgard_texture_desc(&set->textures.midgard[tex], info);681}682}683break;684685case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:686case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:687for (unsigned i = 0; i < ndescs; i++)688panvk_set_image_desc(&descs[i], &pDescriptorWrite->pImageInfo[src_offset + i]);689break;690691case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:692case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:693for (unsigned i = 0; i < ndescs; i++)694panvk_set_texel_buffer_view_desc(&descs[i], &pDescriptorWrite->pTexelBufferView[src_offset + i]);695break;696697case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:698case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:699for (unsigned i = 0; i < ndescs; i++) {700unsigned ubo = binding_layout->ubo_idx + dest_offset + i;701panvk_set_ubo_desc(&set->ubos[ubo],702&pDescriptorWrite->pBufferInfo[src_offset + i]);703}704break;705706case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:707case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:708for (unsigned i = 0; i < ndescs; i++)709panvk_set_buffer_info_desc(&descs[i], &pDescriptorWrite->pBufferInfo[src_offset + i]);710break;711default:712unreachable("Invalid type");713}714715src_offset += ndescs;716binding++;717dest_offset = 0;718}719}720721static void722panvk_copy_descriptor_set(struct panvk_device *dev,723const VkCopyDescriptorSet *pDescriptorCopy)724{725VK_FROM_HANDLE(panvk_descriptor_set, dest_set, pDescriptorCopy->dstSet);726VK_FROM_HANDLE(panvk_descriptor_set, src_set, pDescriptorCopy->srcSet);727const struct panvk_descriptor_set_layout *dest_layout = dest_set->layout;728const struct panvk_descriptor_set_layout *src_layout = dest_set->layout;729unsigned dest_offset = pDescriptorCopy->dstArrayElement;730unsigned src_offset = pDescriptorCopy->srcArrayElement;731unsigned dest_binding = pDescriptorCopy->dstBinding;732unsigned src_binding = pDescriptorCopy->srcBinding;733unsigned desc_count = pDescriptorCopy->descriptorCount;734735while (desc_count && src_binding < src_layout->binding_count &&736dest_binding < dest_layout->binding_count) {737const struct panvk_descriptor_set_binding_layout *dest_binding_layout =738&src_layout->bindings[dest_binding];739740if (!dest_binding_layout->array_size) {741dest_binding++;742dest_offset = 0;743continue;744}745746const struct panvk_descriptor_set_binding_layout *src_binding_layout =747&src_layout->bindings[src_binding];748749if (!src_binding_layout->array_size) {750src_binding++;751src_offset = 0;752continue;753}754755assert(dest_binding_layout->type == src_binding_layout->type);756757unsigned ndescs = MAX3(desc_count,758dest_binding_layout->array_size - dest_offset,759src_binding_layout->array_size - src_offset);760761struct panvk_descriptor *dest_descs = dest_set->descs + dest_binding_layout->desc_idx + dest_offset;762struct panvk_descriptor *src_descs = src_set->descs + src_binding_layout->desc_idx + src_offset;763memcpy(dest_descs, src_descs, ndescs * sizeof(*dest_descs));764desc_count -= ndescs;765dest_offset += ndescs;766if (dest_offset == dest_binding_layout->array_size) {767dest_binding++;768dest_offset = 0;769continue;770}771src_offset += ndescs;772if (src_offset == src_binding_layout->array_size) {773src_binding++;774src_offset = 0;775continue;776}777}778779assert(!desc_count);780}781782void783panvk_UpdateDescriptorSets(VkDevice _device,784uint32_t descriptorWriteCount,785const VkWriteDescriptorSet *pDescriptorWrites,786uint32_t descriptorCopyCount,787const VkCopyDescriptorSet *pDescriptorCopies)788{789VK_FROM_HANDLE(panvk_device, dev, _device);790791for (unsigned i = 0; i < descriptorWriteCount; i++)792panvk_write_descriptor_set(dev, &pDescriptorWrites[i]);793for (unsigned i = 0; i < descriptorCopyCount; i++)794panvk_copy_descriptor_set(dev, &pDescriptorCopies[i]);795}796797VkResult798panvk_CreateDescriptorUpdateTemplate(VkDevice _device,799const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,800const VkAllocationCallbacks *pAllocator,801VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate)802{803panvk_stub();804return VK_SUCCESS;805}806807void808panvk_DestroyDescriptorUpdateTemplate(VkDevice _device,809VkDescriptorUpdateTemplate descriptorUpdateTemplate,810const VkAllocationCallbacks *pAllocator)811{812panvk_stub();813}814815void816panvk_UpdateDescriptorSetWithTemplate(VkDevice _device,817VkDescriptorSet descriptorSet,818VkDescriptorUpdateTemplate descriptorUpdateTemplate,819const void *pData)820{821panvk_stub();822}823824VkResult825panvk_CreateSamplerYcbcrConversion(VkDevice device,826const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,827const VkAllocationCallbacks *pAllocator,828VkSamplerYcbcrConversion *pYcbcrConversion)829{830panvk_stub();831return VK_SUCCESS;832}833834void835panvk_DestroySamplerYcbcrConversion(VkDevice device,836VkSamplerYcbcrConversion ycbcrConversion,837const VkAllocationCallbacks *pAllocator)838{839panvk_stub();840}841842843