diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 0a97623fce7..dddd68ee0a8 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -405,7 +405,7 @@ qt_internal_extend_target(Gui CONDITION WIN32 platform/windows/qwindowsguieventdispatcher.cpp platform/windows/qwindowsguieventdispatcher_p.h platform/windows/qwindowsmimeconverter.h platform/windows/qwindowsmimeconverter.cpp platform/windows/qwindowsnativeinterface.cpp - rhi/qrhid3d11.cpp rhi/qrhid3d11_p.h + rhi/qrhid3d11.cpp rhi/qrhid3d11_p.h rhi/qrhid3dhelpers_p.h rhi/vs_test_p.h rhi/qrhid3d12.cpp rhi/qrhid3d12_p.h rhi/cs_mipmap_p.h @@ -425,7 +425,6 @@ qt_internal_extend_target(Gui CONDITION WIN32 d3d11 dxgi dxguid - dcomp d3d12 ) diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index f8284462eed..9354de92d68 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -6,11 +6,9 @@ #include "vs_test_p.h" #include #include -#include #include #include - -#include +#include "qrhid3dhelpers_p.h" QT_BEGIN_NAMESPACE @@ -4242,18 +4240,6 @@ static inline D3D11_BLEND_OP toD3DBlendOp(QRhiGraphicsPipeline::BlendOp op) } } -static pD3DCompile resolveD3DCompile() -{ - for (const wchar_t *libraryName : {L"D3DCompiler_47", L"D3DCompiler_43"}) { - QSystemLibrary library(libraryName); - if (library.load()) { - if (auto symbol = library.resolve("D3DCompile")) - return reinterpret_cast(symbol); - } - } - return nullptr; -} - static inline QByteArray sourceHash(const QByteArray &source) { // taken from the GL backend, use the same mechanism to get a key @@ -4319,7 +4305,7 @@ QByteArray QRhiD3D11::compileHlslShaderSource(const QShader &shader, QShader::Va return cacheIt.value(); } - static const pD3DCompile d3dCompile = resolveD3DCompile(); + static const pD3DCompile d3dCompile = QRhiD3D::resolveD3DCompile(); if (d3dCompile == nullptr) { qWarning("Unable to resolve function D3DCompile()"); return QByteArray(); @@ -4974,26 +4960,19 @@ bool QD3D11SwapChain::newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI return true; } -static const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM; -static const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; - bool QRhiD3D11::ensureDirectCompositionDevice() { if (dcompDevice) return true; qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)"); - - HRESULT hr = DCompositionCreateDevice(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast(&dcompDevice)); - if (FAILED(hr)) { - qWarning("Failed to Direct Composition device: %s", - qPrintable(QSystemError::windowsComString(hr))); - return false; - } - - return true; + dcompDevice = QRhiD3D::createDirectCompositionDevice(); + return dcompDevice ? true : false; } +static const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM; +static const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + bool QD3D11SwapChain::createOrResize() { // Can be called multiple times due to window resizes - that is not the diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index e4f519cb259..857297b79c5 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -5,13 +5,10 @@ #include "qshader.h" #include #include -#include #include #include - -#include #include - +#include "qrhid3dhelpers_p.h" #include "cs_mipmap_p.h" #if __has_include() @@ -4835,18 +4832,6 @@ QD3D12ObjectHandle QD3D12ShaderResourceBindings::createRootSignature(const QD3D1 // the old shader compiler (so like fxc, not dxc) to generate shader model 5.0 // output. Some day this should be moved to the new compiler and DXIL. -static pD3DCompile resolveD3DCompile() -{ - for (const wchar_t *libraryName : {L"D3DCompiler_47", L"D3DCompiler_43"}) { - QSystemLibrary library(libraryName); - if (library.load()) { - if (auto symbol = library.resolve("D3DCompile")) - return reinterpret_cast(symbol); - } - } - return nullptr; -} - static inline void makeHlslTargetString(char target[7], const char stage[3], int version) { const int smMajor = version / 10; @@ -4919,7 +4904,7 @@ static QByteArray compileHlslShaderSource(const QShader &shader, break; } - static const pD3DCompile d3dCompile = resolveD3DCompile(); + static const pD3DCompile d3dCompile = QRhiD3D::resolveD3DCompile(); if (!d3dCompile) { qWarning("Unable to resolve function D3DCompile()"); return QByteArray(); @@ -5884,25 +5869,19 @@ QRhiRenderPassDescriptor *QD3D12SwapChain::newCompatibleRenderPassDescriptor() return rpD; } -static const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM; -static const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; - bool QRhiD3D12::ensureDirectCompositionDevice() { if (dcompDevice) return true; qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)"); - - HRESULT hr = DCompositionCreateDevice(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast(&dcompDevice)); - if (FAILED(hr)) { - qWarning("Failed to Direct Composition device: %s", qPrintable(QSystemError::windowsComString(hr))); - return false; - } - - return true; + dcompDevice = QRhiD3D::createDirectCompositionDevice(); + return dcompDevice ? true : false; } +static const DXGI_FORMAT DEFAULT_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM; +static const DXGI_FORMAT DEFAULT_SRGB_FORMAT = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + void QD3D12SwapChain::chooseFormats() { colorFormat = DEFAULT_FORMAT; diff --git a/src/gui/rhi/qrhid3dhelpers_p.h b/src/gui/rhi/qrhid3dhelpers_p.h new file mode 100644 index 00000000000..f20c042860c --- /dev/null +++ b/src/gui/rhi/qrhid3dhelpers_p.h @@ -0,0 +1,67 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QRHID3DHELPERS_P_H +#define QRHID3DHELPERS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QRhiD3D { + +inline pD3DCompile resolveD3DCompile() +{ + for (const wchar_t *libraryName : {L"D3DCompiler_47", L"D3DCompiler_43"}) { + QSystemLibrary library(libraryName); + if (library.load()) { + if (auto symbol = library.resolve("D3DCompile")) + return reinterpret_cast(symbol); + } + } + return nullptr; +} + +inline IDCompositionDevice *createDirectCompositionDevice() +{ + QSystemLibrary dcomplib(QStringLiteral("dcomp")); + typedef HRESULT (__stdcall *DCompositionCreateDeviceFuncPtr)( + _In_opt_ IDXGIDevice *dxgiDevice, + _In_ REFIID iid, + _Outptr_ void **dcompositionDevice); + DCompositionCreateDeviceFuncPtr func = reinterpret_cast( + dcomplib.resolve("DCompositionCreateDevice")); + if (!func) { + qWarning("Unable to resolve DCompositionCreateDevice, perhaps dcomp.dll is missing?"); + return nullptr; + } + IDCompositionDevice *device = nullptr; + HRESULT hr = func(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast(&device)); + if (FAILED(hr)) { + qWarning("Failed to Direct Composition device: %s", + qPrintable(QSystemError::windowsComString(hr))); + return nullptr; + } + return device; +} + +} // namespace + +QT_END_NAMESPACE + +#endif