venus: fix render pass without attachments

It was treated as VK_ERROR_OUT_OF_HOST_MEMORY because
vn_get_intercepted_attachments would return NULL.  This fixes various
dEQP tests.

Fixes: 174fca5498 ("venus: handle VK_IMAGE_LAYOUT_PRESENT_SRC_KHR transfer")
Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10592>
This commit is contained in:
Chia-I Wu 2021-04-30 21:15:52 -07:00 committed by Marge Bot
parent 9fa587ae96
commit a9a75edc24

View file

@ -15,6 +15,38 @@
#include "vn_device.h"
static bool
vn_render_pass_has_present_src(const VkRenderPassCreateInfo *create_info)
{
/* XXX drop the #ifdef after fixing common wsi */
#ifdef ANDROID
for (uint32_t i = 0; i < create_info->attachmentCount; i++) {
const VkAttachmentDescription *att = &create_info->pAttachments[i];
if (att->initialLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
att->finalLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
return true;
}
#endif
return false;
}
static bool
vn_render_pass_has_present_src2(const VkRenderPassCreateInfo2 *create_info)
{
/* XXX drop the #ifdef after fixing common wsi */
#ifdef ANDROID
for (uint32_t i = 0; i < create_info->attachmentCount; i++) {
const VkAttachmentDescription2 *att = &create_info->pAttachments[i];
if (att->initialLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
att->finalLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
return true;
}
#endif
return false;
}
/* render pass commands */
static const VkAttachmentDescription *
@ -22,19 +54,6 @@ vn_get_intercepted_attachments(const VkAttachmentDescription *attachments,
uint32_t count,
const VkAllocationCallbacks *alloc)
{
/* XXX drop the #ifdef after fixing common wsi */
#ifdef ANDROID
bool has_present_src = false;
for (uint32_t i = 0; i < count; i++) {
if (attachments[i].initialLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
attachments[i].finalLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
has_present_src = true;
break;
}
}
if (!has_present_src)
return attachments;
size_t size = sizeof(VkAttachmentDescription) * count;
VkAttachmentDescription *out_attachments = vk_alloc(
alloc, size, VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
@ -49,9 +68,6 @@ vn_get_intercepted_attachments(const VkAttachmentDescription *attachments,
out_attachments[i].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
}
return out_attachments;
#else
return attachments;
#endif
}
VkResult
@ -72,19 +88,23 @@ vn_CreateRenderPass(VkDevice device,
vn_object_base_init(&pass->base, VK_OBJECT_TYPE_RENDER_PASS, &dev->base);
VkRenderPassCreateInfo local_pass_info = *pCreateInfo;
local_pass_info.pAttachments = vn_get_intercepted_attachments(
pCreateInfo->pAttachments, pCreateInfo->attachmentCount, alloc);
if (!local_pass_info.pAttachments) {
vk_free(alloc, pass);
return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkRenderPassCreateInfo local_pass_info;
if (vn_render_pass_has_present_src(pCreateInfo)) {
local_pass_info = *pCreateInfo;
local_pass_info.pAttachments = vn_get_intercepted_attachments(
pCreateInfo->pAttachments, pCreateInfo->attachmentCount, alloc);
if (!local_pass_info.pAttachments) {
vk_free(alloc, pass);
return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
}
pCreateInfo = &local_pass_info;
}
VkRenderPass pass_handle = vn_render_pass_to_handle(pass);
vn_async_vkCreateRenderPass(dev->instance, device, &local_pass_info, NULL,
vn_async_vkCreateRenderPass(dev->instance, device, pCreateInfo, NULL,
&pass_handle);
if (local_pass_info.pAttachments != pCreateInfo->pAttachments)
if (pCreateInfo == &local_pass_info)
vk_free(alloc, (void *)local_pass_info.pAttachments);
*pRenderPass = pass_handle;
@ -97,19 +117,6 @@ vn_get_intercepted_attachments2(const VkAttachmentDescription2 *attachments,
uint32_t count,
const VkAllocationCallbacks *alloc)
{
/* XXX drop the #ifdef after fixing common wsi */
#ifdef ANDROID
bool has_present_src = false;
for (uint32_t i = 0; i < count; i++) {
if (attachments[i].initialLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ||
attachments[i].finalLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
has_present_src = true;
break;
}
}
if (!has_present_src)
return attachments;
size_t size = sizeof(VkAttachmentDescription2) * count;
VkAttachmentDescription2 *out_attachments = vk_alloc(
alloc, size, VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
@ -124,9 +131,6 @@ vn_get_intercepted_attachments2(const VkAttachmentDescription2 *attachments,
out_attachments[i].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
}
return out_attachments;
#else
return attachments;
#endif
}
VkResult
@ -147,19 +151,23 @@ vn_CreateRenderPass2(VkDevice device,
vn_object_base_init(&pass->base, VK_OBJECT_TYPE_RENDER_PASS, &dev->base);
VkRenderPassCreateInfo2 local_pass_info = *pCreateInfo;
local_pass_info.pAttachments = vn_get_intercepted_attachments2(
pCreateInfo->pAttachments, pCreateInfo->attachmentCount, alloc);
if (!local_pass_info.pAttachments) {
vk_free(alloc, pass);
return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
VkRenderPassCreateInfo2 local_pass_info;
if (vn_render_pass_has_present_src2(pCreateInfo)) {
local_pass_info = *pCreateInfo;
local_pass_info.pAttachments = vn_get_intercepted_attachments2(
pCreateInfo->pAttachments, pCreateInfo->attachmentCount, alloc);
if (!local_pass_info.pAttachments) {
vk_free(alloc, pass);
return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
}
pCreateInfo = &local_pass_info;
}
VkRenderPass pass_handle = vn_render_pass_to_handle(pass);
vn_async_vkCreateRenderPass2(dev->instance, device, &local_pass_info, NULL,
vn_async_vkCreateRenderPass2(dev->instance, device, pCreateInfo, NULL,
&pass_handle);
if (local_pass_info.pAttachments != pCreateInfo->pAttachments)
if (pCreateInfo == &local_pass_info)
vk_free(alloc, (void *)local_pass_info.pAttachments);
*pRenderPass = pass_handle;