From 1af7fb5ed86c659ebea53e6f0316cac008cb89ed Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 28 Apr 2020 16:30:32 +0200 Subject: [PATCH] rhi: Warn better in D3D/Vulkan for incompatible multisample resolve formats Attempting to resolve a multisample image into a non-multisample one is only valid when the formats are the same, as per Vulkan spec and D3D docs. With Vulkan, this is sometimes not fatal, some implementations can apparently deal with some format combinations, so the problem may not be trivial to catch, although with validation layer enabled a warning is shown at least. To make it easier to discover, have our own warning. Task-number: QTBUG-83707 Change-Id: I8fc87471de91cd65a445fbe8cedbf31a8295db53 Reviewed-by: Paul Olav Tvete --- src/gui/rhi/qrhid3d11.cpp | 6 ++++-- src/gui/rhi/qrhivulkan.cpp | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 8336d43ff6..05ee415502 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -1707,7 +1707,8 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource if (srcTexD) { cmd.args.resolveSubRes.src = srcTexD->tex; if (srcTexD->dxgiFormat != dstTexD->dxgiFormat) { - qWarning("Resolve source and destination formats do not match"); + qWarning("Resolve source (%d) and destination (%d) formats do not match", + int(srcTexD->dxgiFormat), int(dstTexD->dxgiFormat)); continue; } if (srcTexD->sampleDesc.Count <= 1) { @@ -1721,7 +1722,8 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource } else { cmd.args.resolveSubRes.src = srcRbD->tex; if (srcRbD->dxgiFormat != dstTexD->dxgiFormat) { - qWarning("Resolve source and destination formats do not match"); + qWarning("Resolve source (%d) and destination (%d) formats do not match", + int(srcRbD->dxgiFormat), int(dstTexD->dxgiFormat)); continue; } if (srcRbD->m_pixelSize != dstTexD->m_pixelSize) { diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 16de7e0aea..b46b0b819c 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -1219,12 +1219,24 @@ bool QRhiVulkan::createOffscreenRenderPass(QVkRenderPassDescriptor *rpD, for (auto it = firstColorAttachment; it != lastColorAttachment; ++it) { if (it->resolveTexture()) { QVkTexture *rtexD = QRHI_RES(QVkTexture, it->resolveTexture()); + const VkFormat dstFormat = rtexD->vkformat; if (rtexD->samples > VK_SAMPLE_COUNT_1_BIT) qWarning("Resolving into a multisample texture is not supported"); + QVkTexture *texD = QRHI_RES(QVkTexture, it->texture()); + QVkRenderBuffer *rbD = QRHI_RES(QVkRenderBuffer, it->renderBuffer()); + const VkFormat srcFormat = texD ? texD->vkformat : rbD->vkformat; + if (srcFormat != dstFormat) { + // This is a validation error. But some implementations survive, + // actually. Warn about it however, because it's an error with + // some other backends (like D3D) as well. + qWarning("Multisample resolve between different formats (%d and %d) is not supported.", + int(srcFormat), int(dstFormat)); + } + VkAttachmentDescription attDesc; memset(&attDesc, 0, sizeof(attDesc)); - attDesc.format = rtexD->vkformat; + attDesc.format = dstFormat; attDesc.samples = VK_SAMPLE_COUNT_1_BIT; attDesc.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; // ignored attDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;