Commit f9ed0bdd authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Handle the unlikely case of changing the window for a swapchain object

parent 1fb0bd9f
......@@ -2482,7 +2482,9 @@ bool QD3D11SwapChain::buildOrResize()
// same as a simple release+build (as with other resources). Just need to
// resize the buffers then.
Q_ASSERT(!swapChain || window == m_window);
// except if the window actually changes
if (window && window != m_window)
release();
window = m_window;
m_currentPixelSize = surfacePixelSize();
......
......@@ -2263,6 +2263,8 @@ QRhiRenderTarget *QMetalSwapChain::currentFrameRenderTarget()
QSize QMetalSwapChain::surfacePixelSize()
{
// may be called before build, must not access other than m_*
NSView *v = (NSView *) m_window->winId();
if (v) {
CAMetalLayer *layer = (CAMetalLayer *) [v layer];
......@@ -2303,15 +2305,20 @@ void QMetalSwapChain::chooseFormats()
bool QMetalSwapChain::buildOrResize()
{
// no release(), this is intentional
Q_ASSERT(m_window);
if (m_window->surfaceType() != QSurface::MetalSurface) {
if (window && window != m_window)
release();
// else no release(), this is intentional
window = m_window;
if (window->surfaceType() != QSurface::MetalSurface) {
qWarning("QMetalSwapChain only supports MetalSurface windows");
return false;
}
NSView *v = (NSView *) m_window->winId();
NSView *v = (NSView *) window->winId();
d->layer = (CAMetalLayer *) [v layer];
Q_ASSERT(d->layer);
......
......@@ -231,6 +231,7 @@ struct QMetalSwapChain : public QRhiSwapChain
void chooseFormats();
QWindow *window = nullptr;
QSize pixelSize;
int currentFrame = 0; // 0..QMTL_FRAMES_IN_FLIGHT-1
int samples = 1;
......
......@@ -4186,6 +4186,11 @@ bool QVkSwapChain::buildOrResize()
// same as a simple release+build (as with other resources). Thus no
// release() here. See recreateSwapChain().
// except if the window actually changes
if (window && window != m_window)
release();
window = m_window;
m_currentPixelSize = surfacePixelSize();
pixelSize = m_currentPixelSize;
......
......@@ -270,6 +270,7 @@ struct QVkSwapChain : public QRhiSwapChain
static const int MAX_BUFFER_COUNT = 3;
QVulkanWindow *wrapWindow = nullptr;
QWindow *window = nullptr;
QSize pixelSize;
bool supportsReadback = false;
VkSwapchainKHR sc = VK_NULL_HANDLE;
......
......@@ -11,7 +11,6 @@ resource import/export, what's the interop story
multi window? (multi swapchain) -> trouble
what if window is changed on swapchain (vk, d3d may break as of now)
should istexformatsupported should check srgb combinations
vk: image in wrong layout when beginFrame-endFrame without a pass in it
vk: rendering hangs sometimes when minimize and back on some systems?
......@@ -52,6 +51,7 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
what if window is changed on swapchain (vk, d3d may break as of now)
mtl: finish()
mtl: readback (tex, backbuffer)
mtl: rhi without a window, offscreen frame
......
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