aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/scenegraph/d3d12/qsgd3d12rendercontext.cpp2
-rw-r--r--src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp36
2 files changed, 25 insertions, 13 deletions
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12rendercontext.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12rendercontext.cpp
index 7e62421380..84b12303d9 100644
--- a/src/plugins/scenegraph/d3d12/qsgd3d12rendercontext.cpp
+++ b/src/plugins/scenegraph/d3d12/qsgd3d12rendercontext.cpp
@@ -153,7 +153,7 @@ QSGRendererInterface::ShaderCompilationTypes QSGD3D12RenderContext::shaderCompil
QSGRendererInterface::ShaderSourceTypes QSGD3D12RenderContext::shaderSourceType() const
{
- return ShaderSourceString | ShaderByteCode;
+ return ShaderSourceString | ShaderSourceFile | ShaderByteCode;
}
QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp
index baf7571910..d459ec29ab 100644
--- a/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp
+++ b/src/plugins/scenegraph/d3d12/qsgd3d12shadereffectnode.cpp
@@ -840,16 +840,19 @@ void QSGD3D12ShaderCompileTask::run()
emit mgr->logAndStatusChanged();
}
+static const int BYTECODE_MAGIC = 0x43425844; // 'DXBC'
+
void QSGD3D12GuiThreadShaderEffectManager::prepareShaderCode(ShaderInfo::Type typeHint, const QByteArray &src, ShaderInfo *result)
{
// The D3D12 backend's ShaderEffect implementation supports both HLSL
- // source strings and bytecode in files as input. The latter is strongly
- // recommended, but in order to make ShaderEffect users' (and
- // qtgraphicaleffects') life easier, and since we link to d3dcompiler
+ // source strings and bytecode or source in files as input. Bytecode is
+ // strongly recommended, but in order to make ShaderEffect users' (and
+ // anything that stiches shader strings together dynamically, e.g.
+ // qtgraphicaleffects) life easier, and since we link to d3dcompiler
// anyways, compiling from source is also supported.
- // For simplicity, assume that file = bytecode, string = HLSL.
- QUrl srcUrl(src);
+ QByteArray shaderSourceCode = src;
+ QUrl srcUrl(QString::fromUtf8(src));
if (!srcUrl.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) || srcUrl.isLocalFile()) {
if (!m_fileSelector) {
m_fileSelector = new QFileSelector(this);
@@ -862,16 +865,25 @@ void QSGD3D12GuiThreadShaderEffectManager::prepareShaderCode(ShaderInfo::Type ty
emit shaderCodePrepared(false, typeHint, src, result);
return;
}
- result->blob = f.readAll();
+ QByteArray blob = f.readAll();
f.close();
- const bool ok = reflect(result);
- m_status = ok ? Compiled : Error;
- emit shaderCodePrepared(ok, typeHint, src, result);
- emit logAndStatusChanged();
- return;
+ if (blob.size() > 4) {
+ const quint32 *p = reinterpret_cast<const quint32 *>(blob.constData());
+ if (*p == BYTECODE_MAGIC) {
+ // already compiled D3D bytecode, skip straight to reflection
+ result->blob = blob;
+ const bool ok = reflect(result);
+ m_status = ok ? Compiled : Error;
+ emit shaderCodePrepared(ok, typeHint, src, result);
+ emit logAndStatusChanged();
+ return;
+ }
+ // assume the file contained HLSL source code
+ shaderSourceCode = blob;
+ }
}
- QThreadPool::globalInstance()->start(new QSGD3D12ShaderCompileTask(this, typeHint, src, result));
+ QThreadPool::globalInstance()->start(new QSGD3D12ShaderCompileTask(this, typeHint, shaderSourceCode, result));
}
bool QSGD3D12GuiThreadShaderEffectManager::reflect(ShaderInfo *result)