7#include "graphobjects/qssgrendergraphobject_p.h"
11#include <QtQuick3DUtils/private/qssgutils_p.h>
12#include <QtQuick3DUtils/private/qquick3dprofiler_p.h>
14#include <QtQuick3DRuntimeRender/private/qssgruntimerenderlogging_p.h>
15#include <qtquick3d_tracepoints_p.h>
17#include <QCoreApplication>
18#include <QStandardPaths>
23#include <QtGui/qsurfaceformat.h>
25# include <QtGui/qopenglcontext.h>
28#ifdef QT_QUICK3D_HAS_RUNTIME_SHADERS
29#include <rhi/qshaderbaker.h>
32#include <QtCore/qmutex.h>
36Q_TRACE_POINT(qtquick3d, QSSG_loadShader_entry)
37Q_TRACE_POINT(qtquick3d, QSSG_loadShader_exit)
39static QtQuick3DEditorHelpers::ShaderBaker::StatusCallback s_statusCallback =
nullptr;
42size_t qHash(QSSGShaderFeatures features)
noexcept {
return (features.flags & (~QSSGShaderFeatures::IndexMask)); }
47 case QShader::VertexStage:
48 return QStringLiteral(
"failedvert.txt");
50 case QShader::FragmentStage:
51 return QStringLiteral(
"failedfrag.txt");
54 return QStringLiteral(
"failedshader.txt");
60 const char *
name =
nullptr;
65 {
"QSSG_ENABLE_LIGHT_PROBE", QSSGShaderFeatures::Feature::LightProbe },
66 {
"QSSG_ENABLE_IBL_ORIENTATION", QSSGShaderFeatures::Feature::IblOrientation },
67 {
"QSSG_ENABLE_SSM", QSSGShaderFeatures::Feature::Ssm },
68 {
"QSSG_ENABLE_SSAO", QSSGShaderFeatures::Feature::Ssao },
69 {
"QSSG_ENABLE_DEPTH_PASS", QSSGShaderFeatures::Feature::DepthPass },
70 {
"QSSG_ENABLE_ORTHO_SHADOW_PASS", QSSGShaderFeatures::Feature::OrthoShadowPass },
71 {
"QSSG_ENABLE_PERSPECTIVE_SHADOW_PASS", QSSGShaderFeatures::Feature::PerspectiveShadowPass },
72 {
"QSSG_ENABLE_LINEAR_TONEMAPPING", QSSGShaderFeatures::Feature::LinearTonemapping },
73 {
"QSSG_ENABLE_ACES_TONEMAPPING", QSSGShaderFeatures::Feature::AcesTonemapping },
74 {
"QSSG_ENABLE_HEJLDAWSON_TONEMAPPING", QSSGShaderFeatures::Feature::HejlDawsonTonemapping },
75 {
"QSSG_ENABLE_FILMIC_TONEMAPPING", QSSGShaderFeatures::Feature::FilmicTonemapping },
76 {
"QSSG_ENABLE_RGBE_LIGHT_PROBE", QSSGShaderFeatures::Feature::RGBELightProbe },
77 {
"QSSG_ENABLE_OPAQUE_DEPTH_PRE_PASS", QSSGShaderFeatures::Feature::OpaqueDepthPrePass },
78 {
"QSSG_ENABLE_REFLECTION_PROBE", QSSGShaderFeatures::Feature::ReflectionProbe },
79 {
"QSSG_REDUCE_MAX_NUM_LIGHTS", QSSGShaderFeatures::Feature::ReduceMaxNumLights },
80 {
"QSSG_ENABLE_LIGHTMAP", QSSGShaderFeatures::Feature::Lightmap },
81 {
"QSSG_DISABLE_MULTIVIEW", QSSGShaderFeatures::Feature::DisableMultiView },
82 {
"QSSG_FORCE_IBL_EXPOSURE", QSSGShaderFeatures::Feature::ForceIblExposure },
83 {
"QSSG_ENABLE_NORMAL_PASS", QSSGShaderFeatures::Feature::NormalPass },
84 {
"QSSG_ENABLE_USER_RENDER_PASS", QSSGShaderFeatures::Feature::UserRenderPass},
85 {
"QSSG_ENABLE_MOTION_VECTOR", QSSGShaderFeatures::Feature::MotionVector }
88static_assert(std::size(DefineTable) == QSSGShaderFeatures::Count,
"Missing feature define?");
90const char *QSSGShaderFeatures::asDefineString(QSSGShaderFeatures::Feature feature) {
return DefineTable[
static_cast<FlagType>(feature) & QSSGShaderFeatures::IndexMask].name; }
91QSSGShaderFeatures::Feature QSSGShaderFeatures::fromIndex(quint32 idx) {
return DefineTable[idx].feature; }
93void QSSGShaderFeatures::set(QSSGShaderFeatures::Feature feature,
bool val)
96 flags |= (
static_cast<FlagType>(feature) & ~IndexMask);
98 flags &= ~(
static_cast<FlagType>(feature) & ~IndexMask);
101QList<QShaderVersion> QSSGShaderCache::glslTargetsForContext(
const QSurfaceFormat &format,
bool isGLESModule)
103 QList<QShaderVersion> versions;
108 const auto fromVersion = [](
const std::pair<
int,
int> &version,
const QShaderVersion::Flags flags = {}) -> QShaderVersion {
109 return QShaderVersion(version.first * 100 + version.second * 10, flags);
112 const auto version = format.version();
114 if (format.profile() == QSurfaceFormat::CoreProfile && version >= qMakePair(3, 3)) {
117 versions.append(QShaderVersion(330));
119 if (version > qMakePair(3, 3))
120 versions.append(fromVersion(version));
121 }
else if (format.renderableType() == QSurfaceFormat::OpenGLES || isGLESModule) {
122 if (format.majorVersion() >= 3) {
125 versions.append(QShaderVersion(300, QShaderVersion::GlslEs));
127 if (version > qMakePair(3, 0))
128 versions.append(fromVersion(version, QShaderVersion::GlslEs));
130 versions.append(QShaderVersion(100, QShaderVersion::GlslEs));
147 versions.append(QShaderVersion(version >= qMakePair(3, 1) ? 140 : 130));
148 if (version >= qMakePair(3, 3))
149 versions.append(fromVersion(version));
155#ifdef QT_QUICK3D_HAS_RUNTIME_SHADERS
156static void initBakerForNonPersistentUse(QShaderBaker *baker, QRhi *rhi)
158 QVector<QShaderBaker::GeneratedShader> outputs;
159 switch (rhi->backend()) {
161 outputs.append({ QShader::HlslShader, QShaderVersion(50) });
164 outputs.append({ QShader::HlslShader, QShaderVersion(61) });
167#if defined(Q_OS_VISIONOS)
168 outputs.append({ QShader::MslShader, QShaderVersion(21) });
170 outputs.append({ QShader::MslShader, QShaderVersion(12) });
173 case QRhi::OpenGLES2:
175 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
176 bool isGLESModule =
false;
178 auto h =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
180 format = h->context->format();
181 isGLESModule = QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
183 const QList<QShaderVersion> versions = QSSGShaderCache::glslTargetsForContext(format, isGLESModule);
184 outputs.reserve(outputs.size() + versions.size());
185 for (
const QShaderVersion &version : versions)
186 outputs.append({ QShader::GlslShader, version });
190 outputs.append({ QShader::SpirvShader, QShaderVersion(100) });
196 baker->setBreakOnShaderTranslationError(
false);
197 baker->setGeneratedShaders(outputs);
198 baker->setGeneratedShaderVariants({ QShader::StandardShader });
201void QSSGShaderCache::initBakerForPersistentUse(QShaderBaker *baker, QRhi *)
203 QVector<QShaderBaker::GeneratedShader> outputs;
207 outputs.append({ QShader::SpirvShader, QShaderVersion(100) });
208 outputs.append({ QShader::HlslShader, QShaderVersion(50) });
209 outputs.append({ QShader::HlslShader, QShaderVersion(61) });
210#if defined(Q_OS_VISIONOS)
211 outputs.append({ QShader::MslShader, QShaderVersion(21) });
213 outputs.append({ QShader::MslShader, QShaderVersion(12) });
216 outputs.append({ QShader::GlslShader, QShaderVersion(430) });
217 outputs.append({ QShader::GlslShader, QShaderVersion(420) });
218 outputs.append({ QShader::GlslShader, QShaderVersion(330) });
219 outputs.append({ QShader::GlslShader, QShaderVersion(140) });
220 outputs.append({ QShader::GlslShader, QShaderVersion(130) });
221 outputs.append({ QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs) });
223 outputs.append({ QShader::GlslShader, QShaderVersion(300, QShaderVersion::GlslEs) });
224 outputs.append({ QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs) });
225 outputs.append({ QShader::GlslShader, QShaderVersion(320, QShaderVersion::GlslEs) });
239 baker->setBreakOnShaderTranslationError(
false);
241 baker->setGeneratedShaders(outputs);
242 baker->setGeneratedShaderVariants({ QShader::StandardShader });
250void QSSGShaderCache::initBakerForPersistentUse(QShaderBaker *, QRhi *)
260 static const bool diskCacheDisabled = qEnvironmentVariableIntValue(
"QT_DISABLE_SHADER_DISK_CACHE")
261 || qEnvironmentVariableIntValue(
"QSG_RHI_DISABLE_DISK_CACHE");
262 const bool attrDiskCacheDisabled = (qApp ? qApp->testAttribute(Qt::AA_DisableShaderDiskCache) :
false);
269 QDir::root().mkpath(name);
270 return QFileInfo(name).isWritable();
275 static bool checked =
false;
276 static QString currentCacheDir;
277 static bool cacheWritable =
false;
280 return cacheWritable ? currentCacheDir : QString();
283 const QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
284 const QString subPath = QLatin1String(
"/q3dshadercache-") + QSysInfo::buildAbi() + QLatin1Char(
'/');
286 if (!cachePath.isEmpty()) {
287 currentCacheDir = cachePath + subPath;
288 cacheWritable = ensureWritableDir(currentCacheDir);
291 return cacheWritable ? currentCacheDir : QString();
296 const QString cacheDir = persistentQsbcDir();
297 if (!cacheDir.isEmpty())
298 return cacheDir + QLatin1String(
"q3dshadercache.qsbc");
303QSSGShaderCache::QSSGShaderCache(QSSGRhiContext &ctx,
304 const InitBakerFunc initBakeFn)
306 m_initBaker(initBakeFn),
307 m_builtInShaders(*
this)
309 if (isAutoDiskCacheEnabled()) {
310 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
311 m_persistentShaderStorageFileName = persistentQsbcFileName();
312 if (!m_persistentShaderStorageFileName.isEmpty()) {
313 const bool skipCacheFile = qEnvironmentVariableIntValue(
"QT_QUICK3D_NO_SHADER_CACHE_LOAD");
314 if (!skipCacheFile && QFileInfo::exists(m_persistentShaderStorageFileName)) {
316 qDebug(
"Attempting to seed material shader cache from %s", qPrintable(m_persistentShaderStorageFileName));
317 if (m_persistentShaderBakingCache.load(m_persistentShaderStorageFileName)) {
319 const int count = m_persistentShaderBakingCache.availableEntries().count();
320 qDebug(
"Loaded %d shader pipelines into the material shader cache", count);
335 m_initBaker = m_persistentShaderStorageFileName.isEmpty() ? initBakerForNonPersistentUse
336 : QSSGShaderCache::initBakerForPersistentUse;
340QSSGShaderCache::~QSSGShaderCache()
342 if (!m_persistentShaderStorageFileName.isEmpty())
343 m_persistentShaderBakingCache.save(m_persistentShaderStorageFileName);
346void QSSGShaderCache::releaseCachedResources()
348 m_builtInShaders.releaseCachedResources();
350 m_rhiShaders.clear();
356QSSGRhiShaderPipelinePtr QSSGShaderCache::tryGetRhiShaderPipeline(
const QByteArray &inKey,
357 const QSSGShaderFeatures &inFeatures)
359 QSSGShaderCacheKey cacheKey(inKey);
360 cacheKey.m_features = inFeatures;
361 cacheKey.updateHashCode();
362 const auto theIter = m_rhiShaders.constFind(cacheKey);
363 if (theIter != m_rhiShaders.cend())
364 return theIter.value();
369void QSSGShaderCache::addShaderPreprocessor(QByteArray &str,
370 const QByteArray &inKey,
371 ShaderType shaderType,
372 const QSSGShaderFeatures &inFeatures,
373 const QSSGUserShaderAugmentation &shaderAugmentation,
378 m_insertStr +=
"#version 440\n";
380 if (!inKey.isNull()) {
381 m_insertStr +=
"//Shader name -";
382 m_insertStr += inKey;
386 m_insertStr +=
"#define texture2D texture\n";
389 m_insertStr +=
"#define QSHADER_VIEW_COUNT ";
390 m_insertStr += QByteArray::number(viewCount);
393 str.insert(0, m_insertStr);
394 QString::size_type insertPos =
int(m_insertStr.size());
397 const bool fragOutputEnabled = (!inFeatures.isSet(QSSGShaderFeatures::Feature::DepthPass)) && shaderType == ShaderType::Fragment;
398 for (
const auto &def : DefineTable) {
399 m_insertStr.append(
"#define ");
400 m_insertStr.append(def.name);
401 m_insertStr.append(
" ");
402 m_insertStr.append(inFeatures.isSet(def.feature) ?
"1" :
"0");
403 m_insertStr.append(
"\n");
406 str.insert(insertPos, m_insertStr);
407 insertPos +=
int(m_insertStr.size());
410 if (fragOutputEnabled) {
411 if (shaderAugmentation.outputs.size() != 0) {
412 const auto &outputs = shaderAugmentation.outputs;
413 for (
int i = 0; i < outputs.size(); ++i) {
414 m_insertStr +=
"layout(location = ";
415 m_insertStr += QByteArray::number(i);
416 m_insertStr +=
") out vec4 ";
417 m_insertStr += outputs[i];
418 m_insertStr +=
";\n";
421 m_insertStr +=
"layout(location = 0) out vec4 fragOutput;\n";
425 str.insert(insertPos, m_insertStr);
428QByteArray QSSGShaderCache::resourceFolder()
430 return QByteArrayLiteral(
":/res/rhishaders/");
433QByteArray QSSGShaderCache::shaderCollectionFile()
435 return QByteArrayLiteral(
"qtappshaders.qsbc");
438QByteArray QSSGShaderCache::particleShaderCollectionFile()
440 return QByteArrayLiteral(
"qtparticleshaders.qsbc");
443QSSGRhiShaderPipelinePtr QSSGShaderCache::compileForRhi(
const QByteArray &inKey,
const QByteArray &inVert,
const QByteArray &inFrag,
444 const QSSGShaderFeatures &inFeatures, QSSGRhiShaderPipeline::StageFlags stageFlags,
445 const QSSGUserShaderAugmentation &shaderAugmentation,
447 bool perTargetCompilation,
448 const QByteArray &inCacheKey)
450#ifdef QT_QUICK3D_HAS_RUNTIME_SHADERS
454 const QByteArray &cacheKeyString = inCacheKey.isEmpty() ? inKey : inCacheKey;
456 const QSSGRhiShaderPipelinePtr &rhiShaders = tryGetRhiShaderPipeline(cacheKeyString, inFeatures);
460 QSSGShaderCacheKey tempKey(cacheKeyString);
461 tempKey.m_features = inFeatures;
462 tempKey.updateHashCode();
464 QByteArray vertexCode = inVert;
465 QByteArray fragmentCode = inFrag;
467 if (!vertexCode.isEmpty())
468 addShaderPreprocessor(vertexCode, inKey, ShaderType::Vertex, inFeatures, shaderAugmentation, viewCount);
470 if (!fragmentCode.isEmpty())
471 addShaderPreprocessor(fragmentCode, inKey, ShaderType::Fragment, inFeatures, shaderAugmentation, viewCount);
475 QSSGRhiShaderPipelinePtr shaders;
476 QString vertErr, fragErr;
479 m_initBaker(&baker, m_rhiContext.rhi());
484 baker.setPerTargetCompilation(perTargetCompilation);
488 baker.setMultiViewCount(viewCount);
492 const bool mediumPrecision = qEnvironmentVariableIntValue(
"QT_QUICK3D_MEDIUM_PRECISION");
494 baker.setGlslOptions(QShaderBaker::GlslOption::GlslEsFragDefaultFloatPrecisionMedium);
496 const bool editorMode = QSSGRhiContextPrivate::editorMode();
498 const bool shaderDebug = !editorMode && QSSGRhiContextPrivate::shaderDebuggingEnabled();
500 static auto dumpShader = [](QShader::Stage stage,
const QByteArray &code) {
502 case QShader::Stage::VertexStage:
503 qDebug(
"VERTEX SHADER:\n*****\n");
505 case QShader::Stage::FragmentStage:
506 qDebug(
"FRAGMENT SHADER:\n*****\n");
509 qDebug(
"SHADER:\n*****\n");
512 const auto lines = code.split(
'\n');
513 for (
int i = 0; i < lines.size(); i++)
514 qDebug(
"%3d %s", i + 1, lines.at(i).constData());
518 static auto dumpShaderToFile = [](QShader::Stage stage,
const QByteArray &data) {
519 QFile f(dumpFilename(stage));
520 if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
523 qWarning(
"Failed to write to file: %s (%s)\n",
524 qPrintable(f.fileName()), qPrintable(f.errorString()));
528 baker.setSourceString(vertexCode, QShader::VertexStage);
529 QShader vertexShader = baker.bake();
530 const auto vertShaderValid = vertexShader.isValid();
531 if (!vertShaderValid) {
532 vertErr = baker.errorMessage();
534 qWarning(
"Failed to compile vertex shader: %s\n", qPrintable(vertErr));
536 qWarning() << inKey <<
'\n';
541 dumpShader(QShader::Stage::VertexStage, vertexCode);
542 if (!vertShaderValid)
543 dumpShaderToFile(QShader::Stage::VertexStage, vertexCode);
546 baker.setSourceString(fragmentCode, QShader::FragmentStage);
547 QShader fragmentShader = baker.bake();
548 const bool fragShaderValid = fragmentShader.isValid();
549 if (!fragShaderValid) {
550 fragErr = baker.errorMessage();
552 qWarning(
"Failed to compile fragment shader: %s\n", qPrintable(fragErr));
554 qWarning() << inKey <<
'\n';
559 dumpShader(QShader::Stage::FragmentStage, fragmentCode);
560 if (!fragShaderValid)
561 dumpShaderToFile(QShader::Stage::FragmentStage, fragmentCode);
564 if (vertShaderValid && fragShaderValid) {
565 shaders = std::make_shared<QSSGRhiShaderPipeline>(m_rhiContext);
566 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, vertexShader), stageFlags);
567 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, fragmentShader), stageFlags);
569 qDebug(
"Compilation for vertex and fragment stages succeeded");
572 if (editorMode && s_statusCallback) {
573 using namespace QtQuick3DEditorHelpers::ShaderBaker;
574 const auto vertStatus = vertShaderValid ? Status::Success : Status::Error;
575 const auto fragStatus = fragShaderValid ? Status::Success : Status::Error;
576 QMutexLocker locker(&*s_statusMutex);
577 s_statusCallback(inKey, vertStatus, vertErr, QShader::VertexStage);
578 s_statusCallback(inKey, fragStatus, fragErr, QShader::FragmentStage);
581 auto result = m_rhiShaders.insert(tempKey, shaders).value();
582 if (result && result->vertexStage() && result->fragmentStage()) {
583 QQsbCollection::EntryDesc entryDesc = {
585 QQsbCollection::toFeatureSet(inFeatures),
586 result->vertexStage()->shader(),
587 result->fragmentStage()->shader()
589 m_persistentShaderBakingCache.addEntry(entryDesc.generateSha(), entryDesc);
597 Q_UNUSED(inFeatures);
598 Q_UNUSED(stageFlags);
599 Q_UNUSED(inCacheKey);
600 qWarning(
"Cannot compile and condition shaders at runtime because this build of Qt Quick 3D is not linking to Qt Shader Tools. "
601 "Only pre-processed materials are supported.");
606QSSGRhiShaderPipelinePtr QSSGShaderCache::newPipelineFromPregenerated(
const QByteArray &inKey,
607 const QSSGShaderFeatures &inFeatures,
608 QQsbCollection::Entry entry,
609 const QSSGRenderGraphObject &obj,
610 QSSGRhiShaderPipeline::StageFlags stageFlags)
619 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
621 qDebug(
"Loading pregenerated rhi shader(s)");
623 Q_TRACE_SCOPE(QSSG_loadShader);
624 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DLoadShader);
627 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
629 const QStringList collectionFiles
630 = {QString::fromLatin1(resourceFolder() + shaderCollectionFile()),
631 QString::fromLatin1(resourceFolder() + particleShaderCollectionFile())};
633 QQsbCollection::EntryDesc entryDesc;
634 QScopedPointer<QQsbIODeviceCollection> qsbc;
635 for (
const auto &collectionFile : collectionFiles) {
636 QFileInfo info(collectionFile);
640 qsbc.reset(
new QQsbIODeviceCollection(collectionFile));
641 if (qsbc->map(QQsbIODeviceCollection::Read)) {
642 if (qsbc->extractEntry(entry, entryDesc))
650 qWarning(
"Failed to open entry %s", entry.key.constData());
652 if (entryDesc.vertShader.isValid() && entryDesc.fragShader.isValid()) {
653 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, entryDesc.vertShader), stageFlags);
654 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, entryDesc.fragShader), stageFlags);
656 qDebug(
"Loading of vertex and fragment stages succeeded");
659#if !QT_CONFIG(qml_debug)
662 Q_QUICK3D_PROFILE_END_WITH_ID(QQuick3DProfiler::Quick3DLoadShader, 0, obj.profilingId);
665 QSSGShaderCacheKey cacheKey(inKey);
666 cacheKey.m_features = inFeatures;
667 cacheKey.updateHashCode();
669 const auto inserted = m_rhiShaders.insert(cacheKey, shaders);
672 return inserted.value();
675QSSGRhiShaderPipelinePtr QSSGShaderCache::tryNewPipelineFromPersistentCache(
const QByteArray &qsbcKey,
676 const QByteArray &inKey,
677 const QSSGShaderFeatures &inFeatures,
678 QSSGRhiShaderPipeline::StageFlags stageFlags)
687 QQsbCollection::EntryDesc entryDesc;
691 if (!m_persistentShaderBakingCache.extractEntry(QQsbCollection::Entry(qsbcKey), entryDesc))
694 if (entryDesc.vertShader.isValid() && entryDesc.fragShader.isValid()) {
695 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
697 qDebug(
"Loading rhi shaders from disk cache for %s (%s)", qsbcKey.constData(), inKey.constData());
699 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
700 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, entryDesc.vertShader), stageFlags);
701 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, entryDesc.fragShader), stageFlags);
702 QSSGShaderCacheKey cacheKey(inKey);
703 cacheKey.m_features = inFeatures;
704 cacheKey.updateHashCode();
705 return m_rhiShaders.insert(cacheKey, shaders).value();
711QSSGRhiShaderPipelinePtr QSSGShaderCache::loadBuiltinUncached(
const QByteArray &inKey,
int viewCount,
712 QSSGRhiShaderPipeline::StageFlags vertexStageFlags)
714 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
716 qDebug(
"Loading builtin rhi shader: %s (view count: %d)", inKey.constData(), viewCount);
718 Q_TRACE_SCOPE(QSSG_loadShader);
719 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DLoadShader);
722 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
727 const QString prefix = QString::fromUtf8(resourceFolder() + inKey);
728 QString vertexFileName = prefix + QLatin1String(
".vert.qsb");
729 QString fragmentFileName = prefix + QLatin1String(
".frag.qsb");
733 if (viewCount == 2) {
734 vertexFileName += QLatin1String(
".mv2qsb");
735 fragmentFileName += QLatin1String(
".mv2qsb");
738 QShader vertexShader;
739 QShader fragmentShader;
742 f.setFileName(vertexFileName);
743 if (f.open(QIODevice::ReadOnly)) {
744 const QByteArray vsData = f.readAll();
745 vertexShader = QShader::fromSerialized(vsData);
748 qWarning(
"Failed to open %s", qPrintable(f.fileName()));
750 f.setFileName(fragmentFileName);
751 if (f.open(QIODevice::ReadOnly)) {
752 const QByteArray fsData = f.readAll();
753 fragmentShader = QShader::fromSerialized(fsData);
756 qWarning(
"Failed to open %s", qPrintable(f.fileName()));
759 if (vertexShader.isValid() && fragmentShader.isValid()) {
760 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, vertexShader), vertexStageFlags);
761 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, fragmentShader));
763 qDebug(
"Loading of vertex and fragment stages succeeded");
766 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DLoadShader, 0, inKey);
774 QMutexLocker locker(&*s_statusMutex);
775 s_statusCallback = cb;
Combined button and popup list for selecting options.
Q_QUICK3DRUNTIMERENDER_EXPORT void setStatusCallback(StatusCallback cb)
void(*)(const QByteArray &descKey, Status status, const QString &err, QShader::Stage stage) StatusCallback
Q_QUICK3DRUNTIMERENDER_EXPORT void setAutomaticDiskCache(bool enable)
Q_QUICK3DRUNTIMERENDER_EXPORT bool isAutomaticDiskCacheEnabled()
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)
static QString persistentQsbcFileName()
static bool isAutoDiskCacheEnabled()
size_t qHash(QSSGShaderFeatures features) noexcept
static bool ensureWritableDir(const QString &name)
static bool s_autoDiskCacheEnabled
static QString dumpFilename(QShader::Stage stage)
static QString persistentQsbcDir()
static void initBakerForNonPersistentUse(QShaderBaker *, QRhi *)
static constexpr DefineEntry DefineTable[]