rhi: d3d: Load DirectComposition library dynamically
Only for dev and 6.6, includes D3D12. 6.5 has its own dedicated version of the patch. Fixes: QTBUG-114775 Task-number: QTBUG-114115 Pick-to: 6.6 Change-Id: I36c96e046ba611b228fd5c320e5780ca4d180165 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
parent
b7d9b7fa69
commit
e7405dc14a
@ -405,7 +405,7 @@ qt_internal_extend_target(Gui CONDITION WIN32
|
|||||||
platform/windows/qwindowsguieventdispatcher.cpp platform/windows/qwindowsguieventdispatcher_p.h
|
platform/windows/qwindowsguieventdispatcher.cpp platform/windows/qwindowsguieventdispatcher_p.h
|
||||||
platform/windows/qwindowsmimeconverter.h platform/windows/qwindowsmimeconverter.cpp
|
platform/windows/qwindowsmimeconverter.h platform/windows/qwindowsmimeconverter.cpp
|
||||||
platform/windows/qwindowsnativeinterface.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/vs_test_p.h
|
||||||
rhi/qrhid3d12.cpp rhi/qrhid3d12_p.h
|
rhi/qrhid3d12.cpp rhi/qrhid3d12_p.h
|
||||||
rhi/cs_mipmap_p.h
|
rhi/cs_mipmap_p.h
|
||||||
@ -425,7 +425,6 @@ qt_internal_extend_target(Gui CONDITION WIN32
|
|||||||
d3d11
|
d3d11
|
||||||
dxgi
|
dxgi
|
||||||
dxguid
|
dxguid
|
||||||
dcomp
|
|
||||||
d3d12
|
d3d12
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
#include "vs_test_p.h"
|
#include "vs_test_p.h"
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
#include <private/qsystemlibrary_p.h>
|
|
||||||
#include <QtCore/qcryptographichash.h>
|
#include <QtCore/qcryptographichash.h>
|
||||||
#include <QtCore/private/qsystemerror_p.h>
|
#include <QtCore/private/qsystemerror_p.h>
|
||||||
|
#include "qrhid3dhelpers_p.h"
|
||||||
#include <d3dcompiler.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
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<pD3DCompile>(symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QByteArray sourceHash(const QByteArray &source)
|
static inline QByteArray sourceHash(const QByteArray &source)
|
||||||
{
|
{
|
||||||
// taken from the GL backend, use the same mechanism to get a key
|
// 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();
|
return cacheIt.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const pD3DCompile d3dCompile = resolveD3DCompile();
|
static const pD3DCompile d3dCompile = QRhiD3D::resolveD3DCompile();
|
||||||
if (d3dCompile == nullptr) {
|
if (d3dCompile == nullptr) {
|
||||||
qWarning("Unable to resolve function D3DCompile()");
|
qWarning("Unable to resolve function D3DCompile()");
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
@ -4974,26 +4960,19 @@ bool QD3D11SwapChain::newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI
|
|||||||
return true;
|
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()
|
bool QRhiD3D11::ensureDirectCompositionDevice()
|
||||||
{
|
{
|
||||||
if (dcompDevice)
|
if (dcompDevice)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)");
|
qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)");
|
||||||
|
dcompDevice = QRhiD3D::createDirectCompositionDevice();
|
||||||
HRESULT hr = DCompositionCreateDevice(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast<void **>(&dcompDevice));
|
return dcompDevice ? true : false;
|
||||||
if (FAILED(hr)) {
|
|
||||||
qWarning("Failed to Direct Composition device: %s",
|
|
||||||
qPrintable(QSystemError::windowsComString(hr)));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 QD3D11SwapChain::createOrResize()
|
bool QD3D11SwapChain::createOrResize()
|
||||||
{
|
{
|
||||||
// Can be called multiple times due to window resizes - that is not the
|
// Can be called multiple times due to window resizes - that is not the
|
||||||
|
@ -5,13 +5,10 @@
|
|||||||
#include "qshader.h"
|
#include "qshader.h"
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
#include <private/qsystemlibrary_p.h>
|
|
||||||
#include <QtCore/qcryptographichash.h>
|
#include <QtCore/qcryptographichash.h>
|
||||||
#include <QtCore/private/qsystemerror_p.h>
|
#include <QtCore/private/qsystemerror_p.h>
|
||||||
|
|
||||||
#include <d3dcompiler.h>
|
|
||||||
#include <comdef.h>
|
#include <comdef.h>
|
||||||
|
#include "qrhid3dhelpers_p.h"
|
||||||
#include "cs_mipmap_p.h"
|
#include "cs_mipmap_p.h"
|
||||||
|
|
||||||
#if __has_include(<pix.h>)
|
#if __has_include(<pix.h>)
|
||||||
@ -4835,18 +4832,6 @@ QD3D12ObjectHandle QD3D12ShaderResourceBindings::createRootSignature(const QD3D1
|
|||||||
// the old shader compiler (so like fxc, not dxc) to generate shader model 5.0
|
// 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.
|
// 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<pD3DCompile>(symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void makeHlslTargetString(char target[7], const char stage[3], int version)
|
static inline void makeHlslTargetString(char target[7], const char stage[3], int version)
|
||||||
{
|
{
|
||||||
const int smMajor = version / 10;
|
const int smMajor = version / 10;
|
||||||
@ -4919,7 +4904,7 @@ static QByteArray compileHlslShaderSource(const QShader &shader,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const pD3DCompile d3dCompile = resolveD3DCompile();
|
static const pD3DCompile d3dCompile = QRhiD3D::resolveD3DCompile();
|
||||||
if (!d3dCompile) {
|
if (!d3dCompile) {
|
||||||
qWarning("Unable to resolve function D3DCompile()");
|
qWarning("Unable to resolve function D3DCompile()");
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
@ -5884,25 +5869,19 @@ QRhiRenderPassDescriptor *QD3D12SwapChain::newCompatibleRenderPassDescriptor()
|
|||||||
return rpD;
|
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()
|
bool QRhiD3D12::ensureDirectCompositionDevice()
|
||||||
{
|
{
|
||||||
if (dcompDevice)
|
if (dcompDevice)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)");
|
qCDebug(QRHI_LOG_INFO, "Creating Direct Composition device (needed for semi-transparent windows)");
|
||||||
|
dcompDevice = QRhiD3D::createDirectCompositionDevice();
|
||||||
HRESULT hr = DCompositionCreateDevice(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast<void **>(&dcompDevice));
|
return dcompDevice ? true : false;
|
||||||
if (FAILED(hr)) {
|
|
||||||
qWarning("Failed to Direct Composition device: %s", qPrintable(QSystemError::windowsComString(hr)));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
void QD3D12SwapChain::chooseFormats()
|
||||||
{
|
{
|
||||||
colorFormat = DEFAULT_FORMAT;
|
colorFormat = DEFAULT_FORMAT;
|
||||||
|
67
src/gui/rhi/qrhid3dhelpers_p.h
Normal file
67
src/gui/rhi/qrhid3dhelpers_p.h
Normal file
@ -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 <QtCore/private/qsystemlibrary_p.h>
|
||||||
|
#include <QtCore/private/qsystemerror_p.h>
|
||||||
|
|
||||||
|
#include <dcomp.h>
|
||||||
|
#include <d3dcompiler.h>
|
||||||
|
|
||||||
|
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<pD3DCompile>(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<DCompositionCreateDeviceFuncPtr>(
|
||||||
|
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<void **>(&device));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
qWarning("Failed to Direct Composition device: %s",
|
||||||
|
qPrintable(QSystemError::windowsComString(hr)));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user