Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_pass.c
4560 views
/*1* Copyright © 2021 Collabora Ltd.2*3* Derived from tu_pass.c which is:4* Copyright © 2016 Red Hat.5* Copyright © 2016 Bas Nieuwenhuizen6* Copyright © 2015 Intel Corporation7*8* Permission is hereby granted, free of charge, to any person obtaining a9* copy of this software and associated documentation files (the "Software"),10* to deal in the Software without restriction, including without limitation11* the rights to use, copy, modify, merge, publish, distribute, sublicense,12* and/or sell copies of the Software, and to permit persons to whom the13* Software is furnished to do so, subject to the following conditions:14*15* The above copyright notice and this permission notice (including the next16* paragraph) shall be included in all copies or substantial portions of the17* Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER23* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING24* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25* DEALINGS IN THE SOFTWARE.26*/27#include "panvk_private.h"2829#include "vk_format.h"30#include "vk_util.h"3132VkResult33panvk_CreateRenderPass2(VkDevice _device,34const VkRenderPassCreateInfo2 *pCreateInfo,35const VkAllocationCallbacks *pAllocator,36VkRenderPass *pRenderPass)37{38VK_FROM_HANDLE(panvk_device, device, _device);39struct panvk_render_pass *pass;40size_t size;41size_t attachments_offset;42VkRenderPassMultiviewCreateInfo *multiview_info = NULL;4344assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2);4546size = sizeof(*pass);47size += pCreateInfo->subpassCount * sizeof(pass->subpasses[0]);48attachments_offset = size;49size += pCreateInfo->attachmentCount * sizeof(pass->attachments[0]);5051pass = vk_object_zalloc(&device->vk, pAllocator, size,52VK_OBJECT_TYPE_RENDER_PASS);53if (pass == NULL)54return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);5556pass->attachment_count = pCreateInfo->attachmentCount;57pass->subpass_count = pCreateInfo->subpassCount;58pass->attachments = (void *) pass + attachments_offset;5960vk_foreach_struct(ext, pCreateInfo->pNext) {61switch (ext->sType) {62case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO:63multiview_info = (VkRenderPassMultiviewCreateInfo *) ext;64break;65default:66break;67}68}6970for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {71struct panvk_render_pass_attachment *att = &pass->attachments[i];7273att->format = vk_format_to_pipe_format(pCreateInfo->pAttachments[i].format);74att->samples = pCreateInfo->pAttachments[i].samples;75att->load_op = pCreateInfo->pAttachments[i].loadOp;76att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;77att->initial_layout = pCreateInfo->pAttachments[i].initialLayout;78att->final_layout = pCreateInfo->pAttachments[i].finalLayout;79att->store_op = pCreateInfo->pAttachments[i].storeOp;80att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;81att->clear_subpass = ~0;82}8384uint32_t subpass_attachment_count = 0;85struct panvk_subpass_attachment *p;86for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {87const VkSubpassDescription2 *desc = &pCreateInfo->pSubpasses[i];8889subpass_attachment_count +=90desc->inputAttachmentCount + desc->colorAttachmentCount +91(desc->pResolveAttachments ? desc->colorAttachmentCount : 0) +92(desc->pDepthStencilAttachment != NULL);93}9495if (subpass_attachment_count) {96pass->subpass_attachments =97vk_alloc2(&device->vk.alloc, pAllocator,98subpass_attachment_count *99sizeof(struct panvk_subpass_attachment),1008, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);101if (pass->subpass_attachments == NULL) {102vk_object_free(&device->vk, pAllocator, pass);103return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);104}105}106107p = pass->subpass_attachments;108for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {109const VkSubpassDescription2 *desc = &pCreateInfo->pSubpasses[i];110struct panvk_subpass *subpass = &pass->subpasses[i];111112subpass->input_count = desc->inputAttachmentCount;113subpass->color_count = desc->colorAttachmentCount;114if (multiview_info)115subpass->view_mask = multiview_info->pViewMasks[i];116117if (desc->inputAttachmentCount > 0) {118subpass->input_attachments = p;119p += desc->inputAttachmentCount;120121for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {122subpass->input_attachments[j] = (struct panvk_subpass_attachment) {123.idx = desc->pInputAttachments[j].attachment,124.layout = desc->pInputAttachments[j].layout,125};126if (desc->pInputAttachments[j].attachment != VK_ATTACHMENT_UNUSED)127pass->attachments[desc->pInputAttachments[j].attachment]128.view_mask |= subpass->view_mask;129}130}131132if (desc->colorAttachmentCount > 0) {133subpass->color_attachments = p;134p += desc->colorAttachmentCount;135136for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {137uint32_t idx = desc->pColorAttachments[j].attachment;138139subpass->color_attachments[j] = (struct panvk_subpass_attachment) {140.idx = idx,141.layout = desc->pColorAttachments[j].layout,142};143144if (idx != VK_ATTACHMENT_UNUSED) {145pass->attachments[idx].view_mask |= subpass->view_mask;146if (pass->attachments[idx].clear_subpass == ~0) {147pass->attachments[idx].clear_subpass = i;148subpass->color_attachments[j].clear = true;149}150}151}152}153154if (desc->pResolveAttachments) {155subpass->resolve_attachments = p;156p += desc->colorAttachmentCount;157158for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {159uint32_t idx = desc->pResolveAttachments[j].attachment;160161subpass->resolve_attachments[j] = (struct panvk_subpass_attachment) {162.idx = idx,163.layout = desc->pResolveAttachments[j].layout,164};165166if (idx != VK_ATTACHMENT_UNUSED)167pass->attachments[idx].view_mask |= subpass->view_mask;168}169}170171unsigned idx = desc->pDepthStencilAttachment ?172desc->pDepthStencilAttachment->attachment :173VK_ATTACHMENT_UNUSED;174subpass->zs_attachment.idx = idx;175if (idx != VK_ATTACHMENT_UNUSED) {176subpass->zs_attachment.layout = desc->pDepthStencilAttachment->layout;177pass->attachments[idx].view_mask |= subpass->view_mask;178if (pass->attachments[idx].clear_subpass == ~0) {179pass->attachments[idx].clear_subpass = i;180subpass->zs_attachment.clear = true;181}182}183}184185*pRenderPass = panvk_render_pass_to_handle(pass);186return VK_SUCCESS;187}188189void190panvk_DestroyRenderPass(VkDevice _device,191VkRenderPass _pass,192const VkAllocationCallbacks *pAllocator)193{194VK_FROM_HANDLE(panvk_device, device, _device);195VK_FROM_HANDLE(panvk_render_pass, pass, _pass);196197if (!pass)198return;199200vk_free2(&device->vk.alloc, pAllocator, pass->subpass_attachments);201vk_object_free(&device->vk, pAllocator, pass);202}203204void205panvk_GetRenderAreaGranularity(VkDevice _device,206VkRenderPass renderPass,207VkExtent2D *pGranularity)208{209panvk_stub();210}211212213