Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qrhid3dhelpers_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QRHID3DHELPERS_P_H
5#define QRHID3DHELPERS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qsystemlibrary_p.h>
19#include <QtCore/private/qsystemerror_p.h>
20
21#include <dcomp.h>
22#include <d3dcompiler.h>
23
24#if __has_include(<dxcapi.h>)
25#include <dxcapi.h>
26#define QRHI_D3D12_HAS_DXC
27#endif
28
30
31namespace QRhiD3D {
32
33inline pD3DCompile resolveD3DCompile()
34{
35 for (const wchar_t *libraryName : {L"D3DCompiler_47", L"D3DCompiler_43"}) {
36 QSystemLibrary library(libraryName);
37 if (library.load()) {
38 if (auto symbol = library.resolve("D3DCompile"))
39 return reinterpret_cast<pD3DCompile>(symbol);
40 } else {
41 qWarning("Failed to load D3DCompiler_47/43.dll");
42 }
43 }
44 return nullptr;
45}
46
47inline IDCompositionDevice *createDirectCompositionDevice()
48{
49 QSystemLibrary dcomplib(QStringLiteral("dcomp"));
50 typedef HRESULT (__stdcall *DCompositionCreateDeviceFuncPtr)(
51 _In_opt_ IDXGIDevice *dxgiDevice,
52 _In_ REFIID iid,
53 _Outptr_ void **dcompositionDevice);
54 DCompositionCreateDeviceFuncPtr func = reinterpret_cast<DCompositionCreateDeviceFuncPtr>(
55 dcomplib.resolve("DCompositionCreateDevice"));
56 if (!func) {
57 qWarning("Unable to resolve DCompositionCreateDevice, perhaps dcomp.dll is missing?");
58 return nullptr;
59 }
60 IDCompositionDevice *device = nullptr;
61 HRESULT hr = func(nullptr, __uuidof(IDCompositionDevice), reinterpret_cast<void **>(&device));
62 if (FAILED(hr)) {
63 qWarning("Failed to create Direct Composition device: %s",
64 qPrintable(QSystemError::windowsComString(hr)));
65 return nullptr;
66 }
67 return device;
68}
69
70#ifdef QRHI_D3D12_HAS_DXC
71inline std::pair<IDxcCompiler *, IDxcLibrary *> createDxcCompiler()
72{
73 QSystemLibrary dxclib(QStringLiteral("dxcompiler"));
74 // this will not be in the system library location, hence onlySystemDirectory==false
75 if (!dxclib.load(false)) {
76 qWarning("Failed to load dxcompiler.dll");
77 return {};
78 }
79 DxcCreateInstanceProc func = reinterpret_cast<DxcCreateInstanceProc>(dxclib.resolve("DxcCreateInstance"));
80 if (!func) {
81 qWarning("Unable to resolve DxcCreateInstance");
82 return {};
83 }
84 IDxcCompiler *compiler = nullptr;
85 HRESULT hr = func(CLSID_DxcCompiler, __uuidof(IDxcCompiler), reinterpret_cast<void**>(&compiler));
86 if (FAILED(hr)) {
87 qWarning("Failed to create dxc compiler instance: %s",
88 qPrintable(QSystemError::windowsComString(hr)));
89 return {};
90 }
91 IDxcLibrary *library = nullptr;
92 hr = func(CLSID_DxcLibrary, __uuidof(IDxcLibrary), reinterpret_cast<void**>(&library));
93 if (FAILED(hr)) {
94 qWarning("Failed to create dxc library instance: %s",
95 qPrintable(QSystemError::windowsComString(hr)));
96 return {};
97 }
98 return { compiler, library };
99}
100#endif
101
102} // namespace
103
105
106#endif
IOBluetoothDevice * device
pD3DCompile resolveD3DCompile()
IDCompositionDevice * createDirectCompositionDevice()
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:162
GLenum func
Definition qopenglext.h:663
#define qPrintable(string)
Definition qstring.h:1391
#define QStringLiteral(str)
long HRESULT