Mesa (master): venus: fix render pass without attachments
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon May 3 20:50:56 UTC 2021
Module: Mesa
Branch: master
Commit: a9a75edc2416598976bce006a5151c0ebcf3c61d
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a9a75edc2416598976bce006a5151c0ebcf3c61d
Author: Chia-I Wu <olvaffe at gmail.com>
Date: Fri Apr 30 21:15:52 2021 -0700
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: 174fca5498e ("venus: handle VK_IMAGE_LAYOUT_PRESENT_SRC_KHR transfer")
Signed-off-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei at chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10592>
---
src/virtio/vulkan/vn_render_pass.c | 104 ++++++++++++++++++++-----------------
1 file changed, 56 insertions(+), 48 deletions(-)
diff --git a/src/virtio/vulkan/vn_render_pass.c b/src/virtio/vulkan/vn_render_pass.c
index fa87a662fe0..b7f4db0ba53 100644
--- a/src/virtio/vulkan/vn_render_pass.c
+++ b/src/virtio/vulkan/vn_render_pass.c
@@ -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;
More information about the mesa-commit
mailing list