diff --git a/README.md b/README.md index 6739a4ec..af431c3b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -This is Qt 6.6.2 backport that runs on Windows 7 (what?). The repository contains patched source files from the qtbase module. +This is Qt 6.6.3 backport that runs on Windows 7 (what?). The repository contains patched source files from the qtbase module. Approach is based on this [forum thread](https://forum.qt.io/topic/133002/qt-creator-6-0-1-and-qt-6-2-2-running-on-windows-7/60) but better: many improvements amongst important fallbacks to default Qt 6 behaviour when running on newer Windows. You can use [our prebuild binaries](https://github.com/crystalidea/qt6windows7/releases) (we used Visual C++ 2019 with OpenSSL 3.0.13 statically linked, see [compile_win.pl](https://github.com/crystalidea/qt-build-tools/tree/master/6.6.2) script) or compile Qt yourself. diff --git a/qtbase/src/gui/rhi/qrhid3d11.cpp b/qtbase/src/gui/rhi/qrhid3d11.cpp index 70f7c5e5..d5b60b7e 100644 --- a/qtbase/src/gui/rhi/qrhid3d11.cpp +++ b/qtbase/src/gui/rhi/qrhid3d11.cpp @@ -437,19 +437,13 @@ QList QRhiD3D11::supportedSampleCounts() const return { 1, 2, 4, 8 }; } -DXGI_SAMPLE_DESC QRhiD3D11::effectiveSampleCount(int sampleCount) const +DXGI_SAMPLE_DESC QRhiD3D11::effectiveSampleDesc(int sampleCount) const { DXGI_SAMPLE_DESC desc; desc.Count = 1; desc.Quality = 0; - // Stay compatible with QSurfaceFormat and friends where samples == 0 means the same as 1. - int s = qBound(1, sampleCount, 64); - - if (!supportedSampleCounts().contains(s)) { - qWarning("Attempted to set unsupported sample count %d", sampleCount); - return desc; - } + const int s = effectiveSampleCount(sampleCount); desc.Count = UINT(s); if (s > 1) @@ -1461,9 +1455,9 @@ static inline DXGI_FORMAT toD3DTextureFormat(QRhiTexture::Format format, QRhiTex case QRhiTexture::D16: return DXGI_FORMAT_R16_TYPELESS; case QRhiTexture::D24: - return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + return DXGI_FORMAT_R24G8_TYPELESS; case QRhiTexture::D24S8: - return DXGI_FORMAT_D24_UNORM_S8_UINT; + return DXGI_FORMAT_R24G8_TYPELESS; case QRhiTexture::D32F: return DXGI_FORMAT_R32_TYPELESS; @@ -3043,7 +3037,7 @@ bool QD3D11RenderBuffer::create() return false; QRHI_RES_RHI(QRhiD3D11); - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount); D3D11_TEXTURE2D_DESC desc = {}; desc.Width = UINT(m_pixelSize.width()); @@ -3185,7 +3179,7 @@ static inline DXGI_FORMAT toD3DDepthTextureDSVFormat(QRhiTexture::Format format) case QRhiTexture::Format::D16: return DXGI_FORMAT_D16_UNORM; case QRhiTexture::Format::D24: - return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + return DXGI_FORMAT_D24_UNORM_S8_UINT; case QRhiTexture::Format::D24S8: return DXGI_FORMAT_D24_UNORM_S8_UINT; case QRhiTexture::Format::D32F: @@ -3214,7 +3208,7 @@ bool QD3D11Texture::prepareCreate(QSize *adjustedSize) QRHI_RES_RHI(QRhiD3D11); dxgiFormat = toD3DTextureFormat(m_format, m_flags); mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount); if (sampleDesc.Count > 1) { if (isCube) { qWarning("Cubemap texture cannot be multisample"); @@ -4390,7 +4384,7 @@ bool QD3D11GraphicsPipeline::create() rastDesc.SlopeScaledDepthBias = m_slopeScaledDepthBias; rastDesc.DepthClipEnable = true; rastDesc.ScissorEnable = m_flags.testFlag(UsesScissor); - rastDesc.MultisampleEnable = rhiD->effectiveSampleCount(m_sampleCount).Count > 1; + rastDesc.MultisampleEnable = rhiD->effectiveSampleDesc(m_sampleCount).Count > 1; HRESULT hr = rhiD->dev->CreateRasterizerState(&rastDesc, &rastState); if (FAILED(hr)) { qWarning("Failed to create rasterizer state: %s", @@ -4857,8 +4851,12 @@ void QD3D11SwapChain::destroy() } QRHI_RES_RHI(QRhiD3D11); - if (rhiD) + if (rhiD) { rhiD->unregisterResource(this); + // See Deferred Destruction Issues with Flip Presentation Swap Chains in + // https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-flush + rhiD->context->Flush(); + } } QRhiCommandBuffer *QD3D11SwapChain::currentFrameCommandBuffer() @@ -5074,7 +5072,7 @@ bool QD3D11SwapChain::createOrResize() swapChainFlags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; if (!swapChain) { - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount); colorFormat = DEFAULT_FORMAT; srgbAdjustedColorFormat = m_flags.testFlag(sRGB) ? DEFAULT_SRGB_FORMAT : DEFAULT_FORMAT; @@ -5187,8 +5185,11 @@ bool QD3D11SwapChain::createOrResize() } } if (FAILED(hr)) { - qWarning("Failed to create D3D11 swapchain: %s", - qPrintable(QSystemError::windowsComString(hr))); + qWarning("Failed to create D3D11 swapchain: %s" + " (Width=%u Height=%u Format=%u SampleCount=%u BufferCount=%u Scaling=%u SwapEffect=%u Stereo=%u)", + qPrintable(QSystemError::windowsComString(hr)), + desc.Width, desc.Height, UINT(desc.Format), desc.SampleDesc.Count, + desc.BufferCount, UINT(desc.Scaling), UINT(desc.SwapEffect), UINT(desc.Stereo)); return false; } } else { diff --git a/qtbase/src/gui/rhi/qrhid3d11_p.h b/qtbase/src/gui/rhi/qrhid3d11_p.h index 328323c9..ce4114c1 100644 --- a/qtbase/src/gui/rhi/qrhid3d11_p.h +++ b/qtbase/src/gui/rhi/qrhid3d11_p.h @@ -738,7 +738,7 @@ public: bool offsetOnlyChange); void resetShaderResources(); void executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *timestampSwapChain = nullptr); - DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount) const; + DXGI_SAMPLE_DESC effectiveSampleDesc(int sampleCount) const; void finishActiveReadbacks(); void reportLiveObjects(ID3D11Device *device); void clearShaderCache(); diff --git a/qtbase/src/gui/rhi/qrhid3d12.cpp b/qtbase/src/gui/rhi/qrhid3d12.cpp index 8edf734d..5e5fee4e 100644 --- a/qtbase/src/gui/rhi/qrhid3d12.cpp +++ b/qtbase/src/gui/rhi/qrhid3d12.cpp @@ -469,8 +469,10 @@ void QRhiD3D12::destroy() cbvSrvUavPool.destroy(); for (int i = 0; i < QD3D12_FRAMES_IN_FLIGHT; ++i) { - cmdAllocators[i]->Release(); - cmdAllocators[i] = nullptr; + if (cmdAllocators[i]) { + cmdAllocators[i]->Release(); + cmdAllocators[i] = nullptr; + } } if (fullFenceEvent) { @@ -1505,6 +1507,10 @@ QRhi::FrameOpResult QRhiD3D12::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame { presentFlags |= DXGI_PRESENT_ALLOW_TEARING; } + if (!swapChainD->swapChain) { + qWarning("Failed to present, no swapchain"); + return QRhi::FrameOpError; + } HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags); if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { qWarning("Device loss detected in Present()"); @@ -2913,24 +2919,18 @@ void QRhiD3D12::waitGpu() } } -DXGI_SAMPLE_DESC QRhiD3D12::effectiveSampleCount(int sampleCount, DXGI_FORMAT format) const +DXGI_SAMPLE_DESC QRhiD3D12::effectiveSampleDesc(int sampleCount, DXGI_FORMAT format) const { DXGI_SAMPLE_DESC desc; desc.Count = 1; desc.Quality = 0; - // Stay compatible with QSurfaceFormat and friends where samples == 0 means the same as 1. - int s = qBound(1, sampleCount, 64); - - if (!supportedSampleCounts().contains(s)) { - qWarning("Attempted to set unsupported sample count %d", sampleCount); - return desc; - } + const int s = effectiveSampleCount(sampleCount); if (s > 1) { D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaInfo = {}; msaaInfo.Format = format; - msaaInfo.SampleCount = s; + msaaInfo.SampleCount = UINT(s); if (SUCCEEDED(dev->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaInfo, sizeof(msaaInfo)))) { if (msaaInfo.NumQualityLevels > 0) { desc.Count = UINT(s); @@ -3801,7 +3801,7 @@ bool QD3D12RenderBuffer::create() case QRhiRenderBuffer::Color: { dxgiFormat = toD3DTextureFormat(backingFormat(), {}); - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount, dxgiFormat); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, dxgiFormat); D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resourceDesc.Width = UINT64(m_pixelSize.width()); @@ -3842,7 +3842,7 @@ bool QD3D12RenderBuffer::create() case QRhiRenderBuffer::DepthStencil: { dxgiFormat = DS_FORMAT; - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount, dxgiFormat); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, dxgiFormat); D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resourceDesc.Width = UINT64(m_pixelSize.width()); @@ -3998,7 +3998,7 @@ bool QD3D12Texture::prepareCreate(QSize *adjustedSize) QRHI_RES_RHI(QRhiD3D12); dxgiFormat = toD3DTextureFormat(m_format, m_flags); mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1); - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount, dxgiFormat); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, dxgiFormat); if (sampleDesc.Count > 1) { if (isCube) { qWarning("Cubemap texture cannot be multisample"); @@ -4152,7 +4152,7 @@ bool QD3D12Texture::create() bool needsOptimizedClearValueSpecified = false; UINT resourceFlags = 0; - if (m_flags.testFlag(RenderTarget)) { + if (m_flags.testFlag(RenderTarget) || sampleDesc.Count > 1) { if (isDepth) resourceFlags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; else @@ -5328,7 +5328,7 @@ bool QD3D12GraphicsPipeline::create() } QD3D12RenderPassDescriptor *rpD = QRHI_RES(QD3D12RenderPassDescriptor, m_renderPassDesc); - const DXGI_SAMPLE_DESC sampleDesc = rhiD->effectiveSampleCount(m_sampleCount, DXGI_FORMAT(rpD->colorFormat[0])); + const DXGI_SAMPLE_DESC sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, DXGI_FORMAT(rpD->colorFormat[0])); D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {}; psoDesc.pRootSignature = rootSig; @@ -5951,7 +5951,7 @@ void QD3D12SwapChain::chooseFormats() "(or Use HDR is Off in the Display Settings), ignoring HDR format request"); } } - sampleDesc = rhiD->effectiveSampleCount(m_sampleCount, colorFormat); + sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, colorFormat); } bool QD3D12SwapChain::createOrResize() @@ -5982,7 +5982,7 @@ bool QD3D12SwapChain::createOrResize() if (!dcompTarget) { hr = rhiD->dcompDevice->CreateTargetForHwnd(hwnd, true, &dcompTarget); if (FAILED(hr)) { - qWarning("Failed to create Direct Compsition target for the window: %s", + qWarning("Failed to create Direct Composition target for the window: %s", qPrintable(QSystemError::windowsComString(hr))); } } @@ -6078,7 +6078,11 @@ bool QD3D12SwapChain::createOrResize() } } if (FAILED(hr)) { - qWarning("Failed to create D3D12 swapchain: %s", qPrintable(QSystemError::windowsComString(hr))); + qWarning("Failed to create D3D12 swapchain: %s" + " (Width=%u Height=%u Format=%u SampleCount=%u BufferCount=%u Scaling=%u SwapEffect=%u Stereo=%u)", + qPrintable(QSystemError::windowsComString(hr)), + desc.Width, desc.Height, UINT(desc.Format), desc.SampleDesc.Count, + desc.BufferCount, UINT(desc.Scaling), UINT(desc.SwapEffect), UINT(desc.Stereo)); return false; } diff --git a/qtbase/src/plugins/platforms/windows/qwindowscontext.cpp b/qtbase/src/plugins/platforms/windows/qwindowscontext.cpp index 0b510475..2e9692bc 100644 --- a/qtbase/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/qtbase/src/plugins/platforms/windows/qwindowscontext.cpp @@ -639,6 +639,8 @@ QString QWindowsContext::classNamePrefix() # define xstr(s) str(s) # define str(s) #s str << xstr(QT_NAMESPACE); +# undef str +# undef xstr #endif } return result; diff --git a/qtbase/src/plugins/platforms/windows/qwindowswindow.cpp b/qtbase/src/plugins/platforms/windows/qwindowswindow.cpp index 7f29c7ff..4218df86 100644 --- a/qtbase/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/qtbase/src/plugins/platforms/windows/qwindowswindow.cpp @@ -429,11 +429,7 @@ static inline bool windowIsAccelerated(const QWindow *w) { switch (w->surfaceType()) { case QSurface::OpenGLSurface: - return true; - case QSurface::RasterGLSurface: - return qt_window_private(const_cast(w))->compositing; case QSurface::VulkanSurface: - return true; case QSurface::Direct3DSurface: return true; default: @@ -2819,15 +2815,16 @@ void QWindowsWindow::calculateFullFrameMargins() const auto systemMargins = testFlag(DisableNonClientScaling) ? QWindowsGeometryHint::frameOnPrimaryScreen(window(), m_data.hwnd) : frameMargins_sys(); + const QMargins actualMargins = systemMargins + customMargins(); const int yDiff = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top); - const bool typicalFrame = (systemMargins.left() == systemMargins.right()) - && (systemMargins.right() == systemMargins.bottom()); + const bool typicalFrame = (actualMargins.left() == actualMargins.right()) + && (actualMargins.right() == actualMargins.bottom()); const QMargins adjustedMargins = typicalFrame ? - QMargins(systemMargins.left(), (yDiff - systemMargins.bottom()), - systemMargins.right(), systemMargins.bottom()) - : systemMargins + customMargins(); + QMargins(actualMargins.left(), (yDiff - actualMargins.bottom()), + actualMargins.right(), actualMargins.bottom()) + : actualMargins; setFullFrameMargins(adjustedMargins); } @@ -3449,24 +3446,6 @@ void QWindowsWindow::registerTouchWindow() qErrnoWarning("RegisterTouchWindow() failed for window '%s'.", qPrintable(window()->objectName())); } -void QWindowsWindow::aboutToMakeCurrent() -{ -#ifndef QT_NO_OPENGL - // For RasterGLSurface windows, that become OpenGL windows dynamically, it might be - // time to set up some GL specifics. This is particularly important for layered - // windows (WS_EX_LAYERED due to alpha > 0). - const bool isCompositing = qt_window_private(window())->compositing; - if (isCompositing != testFlag(Compositing)) { - if (isCompositing) - setFlag(Compositing); - else - clearFlag(Compositing); - - updateGLWindowSettings(window(), m_data.hwnd, m_data.flags, m_opacity); - } -#endif -} - void QWindowsWindow::setHasBorderInFullScreenStatic(QWindow *window, bool border) { if (QPlatformWindow *handle = window->handle())