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);
101#ifdef QT_QUICK3D_HAS_RUNTIME_SHADERS
102static void initBakerForNonPersistentUse(QShaderBaker *baker, QRhi *rhi)
104 QVector<QShaderBaker::GeneratedShader> outputs;
105 switch (rhi->backend()) {
107 outputs.append({ QShader::HlslShader, QShaderVersion(50) });
110 outputs.append({ QShader::HlslShader, QShaderVersion(61) });
113#if defined(Q_OS_VISIONOS)
114 outputs.append({ QShader::MslShader, QShaderVersion(21) });
116 outputs.append({ QShader::MslShader, QShaderVersion(12) });
119 case QRhi::OpenGLES2:
121 QSurfaceFormat format = QSurfaceFormat::defaultFormat();
123 auto h =
static_cast<
const QRhiGles2NativeHandles *>(rhi->nativeHandles());
125 format = h->context->format();
127 if (format.profile() == QSurfaceFormat::CoreProfile && format.version() >= qMakePair(3, 3)) {
128 outputs.append({ QShader::GlslShader, QShaderVersion(330) });
129 outputs.append({ QShader::GlslShader, QShaderVersion(420) });
131 bool isGLESModule =
false;
133 isGLESModule = QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
135 if (format.renderableType() == QSurfaceFormat::OpenGLES || isGLESModule) {
136 if (format.majorVersion() >= 3) {
137 outputs.append({ QShader::GlslShader, QShaderVersion(300, QShaderVersion::GlslEs) });
138 outputs.append({ QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs) });
140 outputs.append({ QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs) });
157 if (format.version() >= qMakePair(3, 1))
158 outputs.append({ QShader::GlslShader, QShaderVersion(140) });
160 outputs.append({ QShader::GlslShader, QShaderVersion(130) });
166 outputs.append({ QShader::SpirvShader, QShaderVersion(100) });
170 baker->setGeneratedShaders(outputs);
171 baker->setGeneratedShaderVariants({ QShader::StandardShader });
174void QSSGShaderCache::initBakerForPersistentUse(QShaderBaker *baker, QRhi *)
176 QVector<QShaderBaker::GeneratedShader> outputs;
180 outputs.append({ QShader::SpirvShader, QShaderVersion(100) });
181 outputs.append({ QShader::HlslShader, QShaderVersion(50) });
182 outputs.append({ QShader::HlslShader, QShaderVersion(61) });
183#if defined(Q_OS_VISIONOS)
184 outputs.append({ QShader::MslShader, QShaderVersion(21) });
186 outputs.append({ QShader::MslShader, QShaderVersion(12) });
189 outputs.append({ QShader::GlslShader, QShaderVersion(420) });
190 outputs.append({ QShader::GlslShader, QShaderVersion(330) });
191 outputs.append({ QShader::GlslShader, QShaderVersion(140) });
192 outputs.append({ QShader::GlslShader, QShaderVersion(130) });
193 outputs.append({ QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs) });
195 outputs.append({ QShader::GlslShader, QShaderVersion(300, QShaderVersion::GlslEs) });
196 outputs.append({ QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs) });
210 baker->setBreakOnShaderTranslationError(
false);
212 baker->setGeneratedShaders(outputs);
213 baker->setGeneratedShaderVariants({ QShader::StandardShader });
221static void QSSGShaderCache::initBakerForPersistentUse(QShaderBaker *, QRhi *)
231 static const bool diskCacheDisabled = qEnvironmentVariableIntValue(
"QT_DISABLE_SHADER_DISK_CACHE")
232 || qEnvironmentVariableIntValue(
"QSG_RHI_DISABLE_DISK_CACHE");
233 const bool attrDiskCacheDisabled = (qApp ? qApp->testAttribute(Qt::AA_DisableShaderDiskCache) :
false);
240 QDir::root().mkpath(name);
241 return QFileInfo(name).isWritable();
246 static bool checked =
false;
247 static QString currentCacheDir;
248 static bool cacheWritable =
false;
251 return cacheWritable ? currentCacheDir : QString();
254 const QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
255 const QString subPath = QLatin1String(
"/q3dshadercache-") + QSysInfo::buildAbi() + QLatin1Char(
'/');
257 if (!cachePath.isEmpty()) {
258 currentCacheDir = cachePath + subPath;
259 cacheWritable = ensureWritableDir(currentCacheDir);
262 return cacheWritable ? currentCacheDir : QString();
267 const QString cacheDir = persistentQsbcDir();
268 if (!cacheDir.isEmpty())
269 return cacheDir + QLatin1String(
"q3dshadercache.qsbc");
274QSSGShaderCache::QSSGShaderCache(QSSGRhiContext &ctx,
275 const InitBakerFunc initBakeFn)
277 m_initBaker(initBakeFn),
278 m_builtInShaders(*
this)
280 if (isAutoDiskCacheEnabled()) {
281 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
282 m_persistentShaderStorageFileName = persistentQsbcFileName();
283 if (!m_persistentShaderStorageFileName.isEmpty()) {
284 const bool skipCacheFile = qEnvironmentVariableIntValue(
"QT_QUICK3D_NO_SHADER_CACHE_LOAD");
285 if (!skipCacheFile && QFileInfo::exists(m_persistentShaderStorageFileName)) {
287 qDebug(
"Attempting to seed material shader cache from %s", qPrintable(m_persistentShaderStorageFileName));
288 if (m_persistentShaderBakingCache.load(m_persistentShaderStorageFileName)) {
290 const int count = m_persistentShaderBakingCache.availableEntries().count();
291 qDebug(
"Loaded %d shader pipelines into the material shader cache", count);
306 m_initBaker = m_persistentShaderStorageFileName.isEmpty() ? initBakerForNonPersistentUse
307 : QSSGShaderCache::initBakerForPersistentUse;
311QSSGShaderCache::~QSSGShaderCache()
313 if (!m_persistentShaderStorageFileName.isEmpty())
314 m_persistentShaderBakingCache.save(m_persistentShaderStorageFileName);
317void QSSGShaderCache::releaseCachedResources()
319 m_builtInShaders.releaseCachedResources();
321 m_rhiShaders.clear();
327QSSGRhiShaderPipelinePtr QSSGShaderCache::tryGetRhiShaderPipeline(
const QByteArray &inKey,
328 const QSSGShaderFeatures &inFeatures)
330 QSSGShaderCacheKey cacheKey(inKey);
331 cacheKey.m_features = inFeatures;
332 cacheKey.updateHashCode();
333 const auto theIter = m_rhiShaders.constFind(cacheKey);
334 if (theIter != m_rhiShaders.cend())
335 return theIter.value();
340void QSSGShaderCache::addShaderPreprocessor(QByteArray &str,
341 const QByteArray &inKey,
342 ShaderType shaderType,
343 const QSSGShaderFeatures &inFeatures,
344 const QSSGUserShaderAugmentation &shaderAugmentation,
349 m_insertStr +=
"#version 440\n";
351 if (!inKey.isNull()) {
352 m_insertStr +=
"//Shader name -";
353 m_insertStr += inKey;
357 m_insertStr +=
"#define texture2D texture\n";
360 m_insertStr +=
"#define QSHADER_VIEW_COUNT ";
361 m_insertStr += QByteArray::number(viewCount);
364 str.insert(0, m_insertStr);
365 QString::size_type insertPos =
int(m_insertStr.size());
368 const bool fragOutputEnabled = (!inFeatures.isSet(QSSGShaderFeatures::Feature::DepthPass)) && shaderType == ShaderType::Fragment;
369 for (
const auto &def : DefineTable) {
370 m_insertStr.append(
"#define ");
371 m_insertStr.append(def.name);
372 m_insertStr.append(
" ");
373 m_insertStr.append(inFeatures.isSet(def.feature) ?
"1" :
"0");
374 m_insertStr.append(
"\n");
377 str.insert(insertPos, m_insertStr);
378 insertPos +=
int(m_insertStr.size());
381 if (fragOutputEnabled) {
382 if (shaderAugmentation.outputs.size() != 0) {
383 const auto &outputs = shaderAugmentation.outputs;
384 for (
int i = 0; i < outputs.size(); ++i) {
385 m_insertStr +=
"layout(location = ";
386 m_insertStr += QByteArray::number(i);
387 m_insertStr +=
") out vec4 ";
388 m_insertStr += outputs[i];
389 m_insertStr +=
";\n";
392 m_insertStr +=
"layout(location = 0) out vec4 fragOutput;\n";
396 str.insert(insertPos, m_insertStr);
399QByteArray QSSGShaderCache::resourceFolder()
401 return QByteArrayLiteral(
":/res/rhishaders/");
404QByteArray QSSGShaderCache::shaderCollectionFile()
406 return QByteArrayLiteral(
"qtappshaders.qsbc");
409QByteArray QSSGShaderCache::particleShaderCollectionFile()
411 return QByteArrayLiteral(
"qtparticleshaders.qsbc");
414QSSGRhiShaderPipelinePtr QSSGShaderCache::compileForRhi(
const QByteArray &inKey,
const QByteArray &inVert,
const QByteArray &inFrag,
415 const QSSGShaderFeatures &inFeatures, QSSGRhiShaderPipeline::StageFlags stageFlags,
416 const QSSGUserShaderAugmentation &shaderAugmentation,
418 bool perTargetCompilation)
420#ifdef QT_QUICK3D_HAS_RUNTIME_SHADERS
421 const QSSGRhiShaderPipelinePtr &rhiShaders = tryGetRhiShaderPipeline(inKey, inFeatures);
425 QSSGShaderCacheKey tempKey(inKey);
426 tempKey.m_features = inFeatures;
427 tempKey.updateHashCode();
429 QByteArray vertexCode = inVert;
430 QByteArray fragmentCode = inFrag;
432 if (!vertexCode.isEmpty())
433 addShaderPreprocessor(vertexCode, inKey, ShaderType::Vertex, inFeatures, shaderAugmentation, viewCount);
435 if (!fragmentCode.isEmpty())
436 addShaderPreprocessor(fragmentCode, inKey, ShaderType::Fragment, inFeatures, shaderAugmentation, viewCount);
440 QSSGRhiShaderPipelinePtr shaders;
441 QString vertErr, fragErr;
444 m_initBaker(&baker, m_rhiContext.rhi());
449 baker.setPerTargetCompilation(perTargetCompilation);
453 baker.setMultiViewCount(viewCount);
457 const bool mediumPrecision = qEnvironmentVariableIntValue(
"QT_QUICK3D_MEDIUM_PRECISION");
459 baker.setGlslOptions(QShaderBaker::GlslOption::GlslEsFragDefaultFloatPrecisionMedium);
461 const bool editorMode = QSSGRhiContextPrivate::editorMode();
463 const bool shaderDebug = !editorMode && QSSGRhiContextPrivate::shaderDebuggingEnabled();
465 static auto dumpShader = [](QShader::Stage stage,
const QByteArray &code) {
467 case QShader::Stage::VertexStage:
468 qDebug(
"VERTEX SHADER:\n*****\n");
470 case QShader::Stage::FragmentStage:
471 qDebug(
"FRAGMENT SHADER:\n*****\n");
474 qDebug(
"SHADER:\n*****\n");
477 const auto lines = code.split(
'\n');
478 for (
int i = 0; i < lines.size(); i++)
479 qDebug(
"%3d %s", i + 1, lines.at(i).constData());
483 static auto dumpShaderToFile = [](QShader::Stage stage,
const QByteArray &data) {
484 QFile f(dumpFilename(stage));
485 if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
488 qWarning(
"Failed to write to file: %s (%s)\n",
489 qPrintable(f.fileName()), qPrintable(f.errorString()));
493 baker.setSourceString(vertexCode, QShader::VertexStage);
494 QShader vertexShader = baker.bake();
495 const auto vertShaderValid = vertexShader.isValid();
496 if (!vertShaderValid) {
497 vertErr = baker.errorMessage();
499 qWarning(
"Failed to compile vertex shader: %s\n", qPrintable(vertErr));
501 qWarning() << inKey <<
'\n';
506 dumpShader(QShader::Stage::VertexStage, vertexCode);
507 if (!vertShaderValid)
508 dumpShaderToFile(QShader::Stage::VertexStage, vertexCode);
511 baker.setSourceString(fragmentCode, QShader::FragmentStage);
512 QShader fragmentShader = baker.bake();
513 const bool fragShaderValid = fragmentShader.isValid();
514 if (!fragShaderValid) {
515 fragErr = baker.errorMessage();
517 qWarning(
"Failed to compile fragment shader: %s\n", qPrintable(fragErr));
519 qWarning() << inKey <<
'\n';
524 dumpShader(QShader::Stage::FragmentStage, fragmentCode);
525 if (!fragShaderValid)
526 dumpShaderToFile(QShader::Stage::FragmentStage, fragmentCode);
529 if (vertShaderValid && fragShaderValid) {
530 shaders = std::make_shared<QSSGRhiShaderPipeline>(m_rhiContext);
531 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, vertexShader), stageFlags);
532 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, fragmentShader), stageFlags);
534 qDebug(
"Compilation for vertex and fragment stages succeeded");
537 if (editorMode && s_statusCallback) {
538 using namespace QtQuick3DEditorHelpers::ShaderBaker;
539 const auto vertStatus = vertShaderValid ? Status::Success : Status::Error;
540 const auto fragStatus = fragShaderValid ? Status::Success : Status::Error;
541 QMutexLocker locker(&*s_statusMutex);
542 s_statusCallback(inKey, vertStatus, vertErr, QShader::VertexStage);
543 s_statusCallback(inKey, fragStatus, fragErr, QShader::FragmentStage);
546 auto result = m_rhiShaders.insert(tempKey, shaders).value();
547 if (result && result->vertexStage() && result->fragmentStage()) {
548 QQsbCollection::EntryDesc entryDesc = {
550 QQsbCollection::toFeatureSet(inFeatures),
551 result->vertexStage()->shader(),
552 result->fragmentStage()->shader()
554 m_persistentShaderBakingCache.addEntry(entryDesc.generateSha(), entryDesc);
562 Q_UNUSED(inFeatures);
563 Q_UNUSED(stageFlags);
564 qWarning(
"Cannot compile and condition shaders at runtime because this build of Qt Quick 3D is not linking to Qt Shader Tools. "
565 "Only pre-processed materials are supported.");
570QSSGRhiShaderPipelinePtr QSSGShaderCache::newPipelineFromPregenerated(
const QByteArray &inKey,
571 const QSSGShaderFeatures &inFeatures,
572 QQsbCollection::Entry entry,
573 const QSSGRenderGraphObject &obj,
574 QSSGRhiShaderPipeline::StageFlags stageFlags)
583 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
585 qDebug(
"Loading pregenerated rhi shader(s)");
587 Q_TRACE_SCOPE(QSSG_loadShader);
588 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DLoadShader);
591 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
593 const QStringList collectionFiles
594 = {QString::fromLatin1(resourceFolder() + shaderCollectionFile()),
595 QString::fromLatin1(resourceFolder() + particleShaderCollectionFile())};
597 QQsbCollection::EntryDesc entryDesc;
598 QScopedPointer<QQsbIODeviceCollection> qsbc;
599 for (
const auto &collectionFile : collectionFiles) {
600 QFileInfo info(collectionFile);
604 qsbc.reset(
new QQsbIODeviceCollection(collectionFile));
605 if (qsbc->map(QQsbIODeviceCollection::Read)) {
606 if (qsbc->extractEntry(entry, entryDesc))
614 qWarning(
"Failed to open entry %s", entry.key.constData());
616 if (entryDesc.vertShader.isValid() && entryDesc.fragShader.isValid()) {
617 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, entryDesc.vertShader), stageFlags);
618 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, entryDesc.fragShader), stageFlags);
620 qDebug(
"Loading of vertex and fragment stages succeeded");
623#if !QT_CONFIG(qml_debug)
626 Q_QUICK3D_PROFILE_END_WITH_ID(QQuick3DProfiler::Quick3DLoadShader, 0, obj.profilingId);
629 QSSGShaderCacheKey cacheKey(inKey);
630 cacheKey.m_features = inFeatures;
631 cacheKey.updateHashCode();
633 const auto inserted = m_rhiShaders.insert(cacheKey, shaders);
636 return inserted.value();
639QSSGRhiShaderPipelinePtr QSSGShaderCache::tryNewPipelineFromPersistentCache(
const QByteArray &qsbcKey,
640 const QByteArray &inKey,
641 const QSSGShaderFeatures &inFeatures,
642 QSSGRhiShaderPipeline::StageFlags stageFlags)
651 QQsbCollection::EntryDesc entryDesc;
655 if (!m_persistentShaderBakingCache.extractEntry(QQsbCollection::Entry(qsbcKey), entryDesc))
658 if (entryDesc.vertShader.isValid() && entryDesc.fragShader.isValid()) {
659 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
661 qDebug(
"Loading rhi shaders from disk cache for %s (%s)", qsbcKey.constData(), inKey.constData());
663 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
664 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, entryDesc.vertShader), stageFlags);
665 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, entryDesc.fragShader), stageFlags);
666 QSSGShaderCacheKey cacheKey(inKey);
667 cacheKey.m_features = inFeatures;
668 cacheKey.updateHashCode();
669 return m_rhiShaders.insert(cacheKey, shaders).value();
675QSSGRhiShaderPipelinePtr QSSGShaderCache::loadBuiltinUncached(
const QByteArray &inKey,
int viewCount,
676 QSSGRhiShaderPipeline::StageFlags vertexStageFlags)
678 const bool shaderDebug = !QSSGRhiContextPrivate::editorMode() && QSSGRhiContextPrivate::shaderDebuggingEnabled();
680 qDebug(
"Loading builtin rhi shader: %s (view count: %d)", inKey.constData(), viewCount);
682 Q_TRACE_SCOPE(QSSG_loadShader);
683 Q_QUICK3D_PROFILE_START(QQuick3DProfiler::Quick3DLoadShader);
686 QSSGRhiShaderPipelinePtr shaders(
new QSSGRhiShaderPipeline(m_rhiContext));
691 const QString prefix = QString::fromUtf8(resourceFolder() + inKey);
692 QString vertexFileName = prefix + QLatin1String(
".vert.qsb");
693 QString fragmentFileName = prefix + QLatin1String(
".frag.qsb");
697 if (viewCount == 2) {
698 vertexFileName += QLatin1String(
".mv2qsb");
699 fragmentFileName += QLatin1String(
".mv2qsb");
702 QShader vertexShader;
703 QShader fragmentShader;
706 f.setFileName(vertexFileName);
707 if (f.open(QIODevice::ReadOnly)) {
708 const QByteArray vsData = f.readAll();
709 vertexShader = QShader::fromSerialized(vsData);
712 qWarning(
"Failed to open %s", qPrintable(f.fileName()));
714 f.setFileName(fragmentFileName);
715 if (f.open(QIODevice::ReadOnly)) {
716 const QByteArray fsData = f.readAll();
717 fragmentShader = QShader::fromSerialized(fsData);
720 qWarning(
"Failed to open %s", qPrintable(f.fileName()));
723 if (vertexShader.isValid() && fragmentShader.isValid()) {
724 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Vertex, vertexShader), vertexStageFlags);
725 shaders->addStage(QRhiShaderStage(QRhiShaderStage::Fragment, fragmentShader));
727 qDebug(
"Loading of vertex and fragment stages succeeded");
730 Q_QUICK3D_PROFILE_END_WITH_STRING(QQuick3DProfiler::Quick3DLoadShader, 0, inKey);
738 QMutexLocker locker(&*s_statusMutex);
739 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[]