diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-07-02 16:20:06 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-07-02 22:39:11 +0200 |
commit | 3d87ea91af766d99dffc17f233b35e941eeefaf1 (patch) | |
tree | c5c4d5ff3f23df171ab9c793256be7f885118823 | |
parent | dce7dbecb0135501eb8641c8f5ec8e98bddc808c (diff) |
RHI/D3D11: Remove hard dependency on D3DCompiler library
Varying versions of the library may be available depending on build tool
chain or Windows version. Try to dynamically resolve the D3DCompile
function.
Fixes: QTBUG-76845
Change-Id: Ib7eb3b8c454e9c25731eb2ba9ba45e54fe3f1283
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 21 | ||||
-rw-r--r-- | src/gui/rhi/rhi.pri | 2 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index eea2a13d8c..a8a490eb5c 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -39,6 +39,7 @@ #include <QWindow> #include <QOperatingSystemVersion> #include <qmath.h> +#include <private/qsystemlibrary_p.h> #include <d3dcompiler.h> #include <comdef.h> @@ -3218,6 +3219,18 @@ 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 QByteArray compileHlslShaderSource(const QShader &shader, QShader::Variant shaderVariant, QString *error) { QShaderCode dxbc = shader.shader({ QShader::DxbcShader, 50, shaderVariant }); @@ -3255,9 +3268,15 @@ static QByteArray compileHlslShaderSource(const QShader &shader, QShader::Varian return QByteArray(); } + static const pD3DCompile d3dCompile = resolveD3DCompile(); + if (d3dCompile == nullptr) { + qWarning("Unable to resolve function D3DCompile()"); + return QByteArray(); + } + ID3DBlob *bytecode = nullptr; ID3DBlob *errors = nullptr; - HRESULT hr = D3DCompile(hlslSource.shader().constData(), hlslSource.shader().size(), + HRESULT hr = d3dCompile(hlslSource.shader().constData(), hlslSource.shader().size(), nullptr, nullptr, nullptr, hlslSource.entryPoint().constData(), target, 0, 0, &bytecode, &errors); if (FAILED(hr) || !bytecode) { diff --git a/src/gui/rhi/rhi.pri b/src/gui/rhi/rhi.pri index d8607f1024..4297a5602b 100644 --- a/src/gui/rhi/rhi.pri +++ b/src/gui/rhi/rhi.pri @@ -40,7 +40,7 @@ win32 { SOURCES += \ rhi/qrhid3d11.cpp - LIBS += -ld3d11 -ldxgi -ldxguid -ld3dcompiler + LIBS += -ld3d11 -ldxgi -ldxguid } # darwin { |