2021-02-04 06:50:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2020 Valve Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2021-03-10 14:27:14 +00:00
|
|
|
#include "vk_alloc.h"
|
2021-02-04 06:50:54 +00:00
|
|
|
#include "vk_common_entrypoints.h"
|
|
|
|
#include "vk_device.h"
|
2021-02-04 07:13:33 +00:00
|
|
|
#include "vk_format.h"
|
2021-02-04 06:50:54 +00:00
|
|
|
#include "vk_util.h"
|
|
|
|
|
2021-02-04 07:13:33 +00:00
|
|
|
#include "util/log.h"
|
|
|
|
|
2021-02-04 06:50:54 +00:00
|
|
|
static void
|
|
|
|
translate_references(VkAttachmentReference2 **reference_ptr,
|
2021-02-04 07:13:33 +00:00
|
|
|
uint32_t reference_count,
|
2021-02-04 06:50:54 +00:00
|
|
|
const VkAttachmentReference *reference,
|
2021-02-04 07:13:33 +00:00
|
|
|
const VkRenderPassCreateInfo *pass_info,
|
|
|
|
bool is_input_attachment)
|
2021-02-04 06:50:54 +00:00
|
|
|
{
|
|
|
|
VkAttachmentReference2 *reference2 = *reference_ptr;
|
2021-02-04 07:13:33 +00:00
|
|
|
*reference_ptr += reference_count;
|
|
|
|
for (uint32_t i = 0; i < reference_count; i++) {
|
2021-02-04 06:50:54 +00:00
|
|
|
reference2[i] = (VkAttachmentReference2) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2,
|
|
|
|
.pNext = NULL,
|
|
|
|
.attachment = reference[i].attachment,
|
|
|
|
.layout = reference[i].layout,
|
|
|
|
};
|
2021-02-04 07:13:33 +00:00
|
|
|
|
|
|
|
if (is_input_attachment &&
|
|
|
|
reference2[i].attachment != VK_ATTACHMENT_UNUSED) {
|
|
|
|
assert(reference2[i].attachment < pass_info->attachmentCount);
|
|
|
|
const VkAttachmentDescription *att =
|
|
|
|
&pass_info->pAttachments[reference2[i].attachment];
|
|
|
|
reference2[i].aspectMask = vk_format_aspects(att->format);
|
|
|
|
}
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 06:24:23 +00:00
|
|
|
VKAPI_ATTR VkResult VKAPI_CALL
|
2021-02-04 06:50:54 +00:00
|
|
|
vk_common_CreateRenderPass(VkDevice _device,
|
|
|
|
const VkRenderPassCreateInfo *pCreateInfo,
|
|
|
|
const VkAllocationCallbacks *pAllocator,
|
|
|
|
VkRenderPass *pRenderPass)
|
|
|
|
{
|
|
|
|
VK_FROM_HANDLE(vk_device, device, _device);
|
|
|
|
|
|
|
|
uint32_t reference_count = 0;
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
|
|
|
|
reference_count += pCreateInfo->pSubpasses[i].inputAttachmentCount;
|
|
|
|
reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount;
|
|
|
|
if (pCreateInfo->pSubpasses[i].pResolveAttachments)
|
|
|
|
reference_count += pCreateInfo->pSubpasses[i].colorAttachmentCount;
|
|
|
|
if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment)
|
|
|
|
reference_count += 1;
|
|
|
|
}
|
2021-03-10 14:27:14 +00:00
|
|
|
|
|
|
|
VK_MULTIALLOC(ma);
|
2021-03-11 02:20:37 +00:00
|
|
|
VK_MULTIALLOC_DECL(&ma, VkRenderPassCreateInfo2, create_info, 1);
|
|
|
|
VK_MULTIALLOC_DECL(&ma, VkSubpassDescription2, subpasses,
|
|
|
|
pCreateInfo->subpassCount);
|
|
|
|
VK_MULTIALLOC_DECL(&ma, VkAttachmentDescription2, attachments,
|
|
|
|
pCreateInfo->attachmentCount);
|
|
|
|
VK_MULTIALLOC_DECL(&ma, VkSubpassDependency2, dependencies,
|
|
|
|
pCreateInfo->dependencyCount);
|
|
|
|
VK_MULTIALLOC_DECL(&ma, VkAttachmentReference2, references,
|
|
|
|
reference_count);
|
2021-03-10 14:27:14 +00:00
|
|
|
if (!vk_multialloc_alloc2(&ma, &device->alloc, pAllocator,
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND))
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
|
|
|
VkAttachmentReference2 *reference_ptr = references;
|
2021-02-04 06:50:54 +00:00
|
|
|
|
2021-02-04 07:13:33 +00:00
|
|
|
const VkRenderPassMultiviewCreateInfo *multiview_info = NULL;
|
|
|
|
const VkRenderPassInputAttachmentAspectCreateInfo *aspect_info = NULL;
|
2021-02-04 06:50:54 +00:00
|
|
|
vk_foreach_struct(ext, pCreateInfo->pNext) {
|
2021-02-04 07:13:33 +00:00
|
|
|
switch (ext->sType) {
|
|
|
|
case VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO:
|
|
|
|
aspect_info = (const VkRenderPassInputAttachmentAspectCreateInfo *)ext;
|
|
|
|
/* We don't care about this information */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO:
|
|
|
|
multiview_info = (const VkRenderPassMultiviewCreateInfo*) ext;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mesa_logd("%s: ignored VkStructureType %u\n", __func__, ext->sType);
|
2021-02-04 06:50:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
|
|
|
|
attachments[i] = (VkAttachmentDescription2) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2,
|
|
|
|
.pNext = NULL,
|
|
|
|
.flags = pCreateInfo->pAttachments[i].flags,
|
|
|
|
.format = pCreateInfo->pAttachments[i].format,
|
|
|
|
.samples = pCreateInfo->pAttachments[i].samples,
|
|
|
|
.loadOp = pCreateInfo->pAttachments[i].loadOp,
|
|
|
|
.storeOp = pCreateInfo->pAttachments[i].storeOp,
|
|
|
|
.stencilLoadOp = pCreateInfo->pAttachments[i].stencilLoadOp,
|
|
|
|
.stencilStoreOp = pCreateInfo->pAttachments[i].stencilStoreOp,
|
|
|
|
.initialLayout = pCreateInfo->pAttachments[i].initialLayout,
|
|
|
|
.finalLayout = pCreateInfo->pAttachments[i].finalLayout,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
|
|
|
|
subpasses[i] = (VkSubpassDescription2) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2,
|
|
|
|
.pNext = NULL,
|
|
|
|
.flags = pCreateInfo->pSubpasses[i].flags,
|
|
|
|
.pipelineBindPoint = pCreateInfo->pSubpasses[i].pipelineBindPoint,
|
|
|
|
.viewMask = 0,
|
|
|
|
.inputAttachmentCount = pCreateInfo->pSubpasses[i].inputAttachmentCount,
|
|
|
|
.colorAttachmentCount = pCreateInfo->pSubpasses[i].colorAttachmentCount,
|
2021-02-04 07:40:26 +00:00
|
|
|
.preserveAttachmentCount = pCreateInfo->pSubpasses[i].preserveAttachmentCount,
|
|
|
|
.pPreserveAttachments = pCreateInfo->pSubpasses[i].pPreserveAttachments,
|
2021-02-04 06:50:54 +00:00
|
|
|
};
|
|
|
|
|
2021-02-04 07:36:06 +00:00
|
|
|
if (multiview_info && multiview_info->subpassCount) {
|
|
|
|
assert(multiview_info->subpassCount == pCreateInfo->subpassCount);
|
2021-02-04 06:50:54 +00:00
|
|
|
subpasses[i].viewMask = multiview_info->pViewMasks[i];
|
2021-02-04 07:36:06 +00:00
|
|
|
}
|
2021-02-04 06:50:54 +00:00
|
|
|
|
|
|
|
subpasses[i].pInputAttachments = reference_ptr;
|
|
|
|
translate_references(&reference_ptr,
|
2021-02-04 07:13:33 +00:00
|
|
|
subpasses[i].inputAttachmentCount,
|
2021-02-04 06:50:54 +00:00
|
|
|
pCreateInfo->pSubpasses[i].pInputAttachments,
|
2021-02-04 07:13:33 +00:00
|
|
|
pCreateInfo, true);
|
2021-02-04 06:50:54 +00:00
|
|
|
subpasses[i].pColorAttachments = reference_ptr;
|
|
|
|
translate_references(&reference_ptr,
|
2021-02-04 07:13:33 +00:00
|
|
|
subpasses[i].colorAttachmentCount,
|
2021-02-04 06:50:54 +00:00
|
|
|
pCreateInfo->pSubpasses[i].pColorAttachments,
|
2021-02-04 07:13:33 +00:00
|
|
|
pCreateInfo, false);
|
2021-02-04 06:50:54 +00:00
|
|
|
subpasses[i].pResolveAttachments = NULL;
|
|
|
|
if (pCreateInfo->pSubpasses[i].pResolveAttachments) {
|
|
|
|
subpasses[i].pResolveAttachments = reference_ptr;
|
|
|
|
translate_references(&reference_ptr,
|
2021-02-04 07:13:33 +00:00
|
|
|
subpasses[i].colorAttachmentCount,
|
2021-02-04 06:50:54 +00:00
|
|
|
pCreateInfo->pSubpasses[i].pResolveAttachments,
|
2021-02-04 07:13:33 +00:00
|
|
|
pCreateInfo, false);
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|
|
|
|
subpasses[i].pDepthStencilAttachment = NULL;
|
|
|
|
if (pCreateInfo->pSubpasses[i].pDepthStencilAttachment) {
|
|
|
|
subpasses[i].pDepthStencilAttachment = reference_ptr;
|
2021-02-04 07:13:33 +00:00
|
|
|
translate_references(&reference_ptr, 1,
|
2021-02-04 06:50:54 +00:00
|
|
|
pCreateInfo->pSubpasses[i].pDepthStencilAttachment,
|
2021-02-04 07:13:33 +00:00
|
|
|
pCreateInfo, false);
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 14:27:14 +00:00
|
|
|
assert(reference_ptr == references + reference_count);
|
2021-02-04 06:50:54 +00:00
|
|
|
|
2021-02-04 07:13:33 +00:00
|
|
|
if (aspect_info != NULL) {
|
|
|
|
for (uint32_t i = 0; i < aspect_info->aspectReferenceCount; i++) {
|
|
|
|
const VkInputAttachmentAspectReference *ref =
|
|
|
|
&aspect_info->pAspectReferences[i];
|
|
|
|
|
|
|
|
assert(ref->subpass < pCreateInfo->subpassCount);
|
|
|
|
VkSubpassDescription2 *subpass = &subpasses[ref->subpass];
|
|
|
|
|
|
|
|
assert(ref->inputAttachmentIndex < subpass->inputAttachmentCount);
|
|
|
|
VkAttachmentReference2 *att = (VkAttachmentReference2 *)
|
|
|
|
&subpass->pInputAttachments[ref->inputAttachmentIndex];
|
|
|
|
|
|
|
|
att->aspectMask = ref->aspectMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 06:50:54 +00:00
|
|
|
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) {
|
|
|
|
dependencies[i] = (VkSubpassDependency2) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
|
|
|
|
.pNext = NULL,
|
|
|
|
.srcSubpass = pCreateInfo->pDependencies[i].srcSubpass,
|
|
|
|
.dstSubpass = pCreateInfo->pDependencies[i].dstSubpass,
|
|
|
|
.srcStageMask = pCreateInfo->pDependencies[i].srcStageMask,
|
|
|
|
.dstStageMask = pCreateInfo->pDependencies[i].dstStageMask,
|
|
|
|
.srcAccessMask = pCreateInfo->pDependencies[i].srcAccessMask,
|
|
|
|
.dstAccessMask = pCreateInfo->pDependencies[i].dstAccessMask,
|
|
|
|
.dependencyFlags = pCreateInfo->pDependencies[i].dependencyFlags,
|
|
|
|
.viewOffset = 0,
|
|
|
|
};
|
|
|
|
|
2021-02-04 07:36:06 +00:00
|
|
|
if (multiview_info && multiview_info->dependencyCount) {
|
|
|
|
assert(multiview_info->dependencyCount == pCreateInfo->dependencyCount);
|
2021-02-04 06:50:54 +00:00
|
|
|
dependencies[i].viewOffset = multiview_info->pViewOffsets[i];
|
2021-02-04 07:36:06 +00:00
|
|
|
}
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 14:27:14 +00:00
|
|
|
*create_info = (VkRenderPassCreateInfo2) {
|
2021-02-04 06:50:54 +00:00
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2,
|
|
|
|
.pNext = pCreateInfo->pNext,
|
|
|
|
.flags = pCreateInfo->flags,
|
|
|
|
.attachmentCount = pCreateInfo->attachmentCount,
|
|
|
|
.pAttachments = attachments,
|
|
|
|
.subpassCount = pCreateInfo->subpassCount,
|
|
|
|
.pSubpasses = subpasses,
|
|
|
|
.dependencyCount = pCreateInfo->dependencyCount,
|
|
|
|
.pDependencies = dependencies,
|
|
|
|
};
|
|
|
|
|
2021-02-04 07:36:06 +00:00
|
|
|
if (multiview_info && multiview_info->correlationMaskCount > 0) {
|
2021-03-10 14:27:14 +00:00
|
|
|
create_info->correlatedViewMaskCount = multiview_info->correlationMaskCount;
|
|
|
|
create_info->pCorrelatedViewMasks = multiview_info->pCorrelationMasks;
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 14:27:14 +00:00
|
|
|
VkResult result =
|
|
|
|
device->dispatch_table.CreateRenderPass2(_device, create_info,
|
|
|
|
pAllocator, pRenderPass);
|
|
|
|
|
|
|
|
vk_free2(&device->alloc, pAllocator, create_info);
|
|
|
|
|
|
|
|
return result;
|
2021-02-04 06:50:54 +00:00
|
|
|
}
|