Commit 1c951c31 authored by Laszlo Agocs's avatar Laszlo Agocs

Allow readbacks for msaa swapchain

No user control over resolving (unlike normal textures) so readbacks must
do an implicit resolve, when needed.
parent f1fb7bc9
......@@ -104,6 +104,7 @@ int main(int argc, char **argv)
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
fmt.setStencilBufferSize(8);
//fmt.setSamples(4); // enable 4x MSAA (except for the render-to-texture pass)
QSurfaceFormat::setDefaultFormat(fmt);
GlWindow w;
......
......@@ -343,6 +343,10 @@ struct Q_RHI_EXPORT QRhiReadbackDescription
{
QRhiReadbackDescription() { } // source is the back buffer of the swapchain of the current frame (if the swapchain supports readback)
QRhiReadbackDescription(QRhiTexture *texture_) : texture(texture_) { } // source is the specified texture
// Note that reading back an msaa image is only supported for swapchains
// (by inserting an implicit resolve). For multisample textures, do an
// explicit resolve first.
QRhiTexture *texture = nullptr;
int layer = 0;
int level = 0;
......
......@@ -897,6 +897,18 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
} else {
Q_ASSERT(contextState.currentSwapChain);
swapChainD = QRHI_RES(QD3D11SwapChain, contextState.currentSwapChain);
if (swapChainD->sampleDesc.Count > 1) {
// Unlike with textures, reading back a multisample swapchain image
// has to be supported. Insert a resolve.
QD3D11CommandBuffer::Command rcmd;
rcmd.cmd = QD3D11CommandBuffer::Command::ResolveSubRes;
rcmd.args.resolveSubRes.dst = swapChainD->tex[swapChainD->currentFrame];
rcmd.args.resolveSubRes.dstSubRes = 0;
rcmd.args.resolveSubRes.src = swapChainD->msaaTex[swapChainD->currentFrame];
rcmd.args.resolveSubRes.srcSubRes = 0;
rcmd.args.resolveSubRes.format = swapChainD->colorFormat;
cbD->commands.append(rcmd);
}
src = swapChainD->tex[swapChainD->currentFrame];
dxgiFormat = swapChainD->colorFormat;
pixelSize = swapChainD->pixelSize;
......
......@@ -1138,6 +1138,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
} else {
result->pixelSize = currentSwapChain->pixelSize;
result->format = QRhiTexture::RGBA8;
// readPixels handles multisample resolving implicitly
}
result->data.resize(result->pixelSize.width() * result->pixelSize.height() * 4);
f->glReadPixels(0, 0, result->pixelSize.width(), result->pixelSize.height(),
......
......@@ -2201,6 +2201,9 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
aRb.format = colorTextureFormatFromVkFormat(swapChainD->colorFormat, nullptr);
if (aRb.format == QRhiTexture::UnknownFormat)
continue;
// Multisample swapchains need nothing special since resolving
// happens when ending a renderpass.
}
textureFormatInfo(aRb.format, aRb.pixelSize, nullptr, &aRb.bufSize);
......
......@@ -32,7 +32,6 @@ vk: rendering hangs sometimes when minimize and back on some systems?
mtl: cbuffers, textures, samplers set should be batched too
cbuffer alignment rules - some things fail to translate (to hlsl e.g. with structs), which is fine but how to mitigate
what does image copy do for compressed formats?
does/should reading back an msaa swapchain buffer work? (breaks with vk, d3d at least)
figure sg out for minimizing viewport/scissor cmds
vk: test FrameOpDeviceLost somehow
d3d device loss?
......@@ -68,6 +67,7 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
msaa swapchain readback
d3d: resolveimage (color)
vk: resolveimage (color)
gl: resolveimage (color)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment