diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-09-03 17:36:07 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-09-12 06:43:23 +0300 |
commit | 82574e7d6317898600958c356053cfdaa7321c32 (patch) | |
tree | d4d099d426094292a01e81cbb3f389a20a961cfc /src/api/studio3dqml | |
parent | 0d6360909793aab11c66f4b8f7001f71cbacfee7 (diff) |
Implement shader caching
Currently loaded shaders can now cached with an API call in either
source code or binary format.
It is necessary to do it that way as the shader cache can only be
created in the target hardware.
Task-number: QT3DS-3914
Change-Id: I094e8624943904c311ada2259a84b8c183f792f5
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/api/studio3dqml')
-rw-r--r-- | src/api/studio3dqml/q3dsrenderer.cpp | 26 | ||||
-rw-r--r-- | src/api/studio3dqml/q3dsruntimeInitializerthread.cpp | 5 | ||||
-rw-r--r-- | src/api/studio3dqml/q3dsruntimeInitializerthread_p.h | 3 | ||||
-rw-r--r-- | src/api/studio3dqml/q3dsstudio3d.cpp | 25 |
4 files changed, 35 insertions, 24 deletions
diff --git a/src/api/studio3dqml/q3dsrenderer.cpp b/src/api/studio3dqml/q3dsrenderer.cpp index 274c691..5a99aad 100644 --- a/src/api/studio3dqml/q3dsrenderer.cpp +++ b/src/api/studio3dqml/q3dsrenderer.cpp @@ -104,8 +104,11 @@ void Q3DSRenderer::synchronize(QQuickFramebufferObject *inView) m_presentation->setVariantList(m_commands.m_variantList); m_presentation->setSource(m_commands.m_source); m_presentation->setDelayedLoading(m_commands.m_delayedLoading); + m_presentation->setShaderCacheFile(m_commands.m_shaderCacheFile); m_commands.m_sourceChanged = false; m_commands.m_variantListChanged = false; + m_commands.m_delayedLoadingChanged = false; + m_commands.m_shaderCacheFileChanged = false; m_initialized = false; m_initializationFailure = false; m_error.clear(); @@ -243,7 +246,7 @@ bool Q3DSRenderer::initializeRuntime(QOpenGLFramebufferObject *inFbo) m_runtime, theWidth, theHeight, QOpenGLContext::currentContext()->format(), int(inFbo->handle()), localSource, m_presentation->variantList(), m_presentation->delayedLoading(), m_visitor, context, - m_asyncInitSurface); + m_asyncInitSurface, m_presentation->d_ptr->loadShaderCache()); connect(m_runtimeInitializerThread, &Q3DSRuntimeInitializerThread::initDone, this, &Q3DSRenderer::handleRuntimeInitializedAsync, Qt::QueuedConnection); context->moveToThread(m_runtimeInitializerThread); @@ -254,6 +257,7 @@ bool Q3DSRenderer::initializeRuntime(QOpenGLFramebufferObject *inFbo) int(inFbo->handle()), localSource, m_presentation->variantList(), m_presentation->delayedLoading(), true, + m_presentation->d_ptr->loadShaderCache(), m_visitor)) { m_error = m_runtime->error(); releaseRuntime(); @@ -472,6 +476,12 @@ void Q3DSRenderer::processCommands() command.m_data = nullptr; break; } + case CommandType_PreloadSlide: + m_runtime->preloadSlide(cmd.m_elementPath); + break; + case CommandType_UnloadSlide: + m_runtime->unloadSlide(cmd.m_elementPath); + break; case CommandType_RequestSlideInfo: { int current = 0; int previous = 0; @@ -486,7 +496,6 @@ void Q3DSRenderer::processCommands() requestData->append(QVariant(previousName)); Q_EMIT requestResponse(cmd.m_elementPath, cmd.m_commandType, requestData); - break; } case CommandType_RequestDataInputs: { @@ -518,12 +527,15 @@ void Q3DSRenderer::processCommands() Q_EMIT requestResponse(cmd.m_elementPath, cmd.m_commandType, requestData); break; } - case CommandType_PreloadSlide: - m_runtime->preloadSlide(cmd.m_elementPath); - break; - case CommandType_UnloadSlide: - m_runtime->unloadSlide(cmd.m_elementPath); + case CommandType_RequestExportShaderCache: { + QByteArray shaderCache = m_runtime->exportShaderCache(cmd.m_boolValue); + QVariantList *requestData = new QVariantList(); + requestData->append(QVariant(shaderCache)); + + Q_EMIT requestResponse({}, cmd.m_commandType, requestData); break; + } + default: qWarning() << __FUNCTION__ << "Unrecognized CommandType in command list!"; } diff --git a/src/api/studio3dqml/q3dsruntimeInitializerthread.cpp b/src/api/studio3dqml/q3dsruntimeInitializerthread.cpp index 677b61a..bc021aa 100644 --- a/src/api/studio3dqml/q3dsruntimeInitializerthread.cpp +++ b/src/api/studio3dqml/q3dsruntimeInitializerthread.cpp @@ -39,7 +39,7 @@ Q3DSRuntimeInitializerThread::Q3DSRuntimeInitializerThread( Q3DSViewer::Q3DSViewerApp *runtime, int width, int height, const QSurfaceFormat &format, int offscreenID, const QString &source, const QStringList &variantList, bool delayedLoading, qt3ds::Qt3DSAssetVisitor *assetVisitor, - QOpenGLContext *context, QSurface *surface) + QOpenGLContext *context, QSurface *surface, const QByteArray &shaderCache) : m_runtime(runtime) , m_width(width) , m_height(height) @@ -51,6 +51,7 @@ Q3DSRuntimeInitializerThread::Q3DSRuntimeInitializerThread( , m_assetVisitor(assetVisitor) , m_context(context) , m_surface(surface) + , m_shaderCache(shaderCache) { } @@ -60,7 +61,7 @@ void Q3DSRuntimeInitializerThread::run() m_context->makeCurrent(m_surface); m_success = m_runtime->InitializeApp(m_width, m_height, m_format, m_offscreenId, m_source, m_variantList, m_delayedLoading, false, - m_assetVisitor); + m_shaderCache, m_assetVisitor); m_context->doneCurrent(); delete m_context; diff --git a/src/api/studio3dqml/q3dsruntimeInitializerthread_p.h b/src/api/studio3dqml/q3dsruntimeInitializerthread_p.h index 42dcf67..9aba691 100644 --- a/src/api/studio3dqml/q3dsruntimeInitializerthread_p.h +++ b/src/api/studio3dqml/q3dsruntimeInitializerthread_p.h @@ -64,7 +64,7 @@ public: int offscreenID, const QString &source, const QStringList &variantList, bool delayedLoading, qt3ds::Qt3DSAssetVisitor *assetVisitor, QOpenGLContext *context, - QSurface *surface); + QSurface *surface, const QByteArray &shaderCache); void run() override; @@ -86,6 +86,7 @@ private: qt3ds::Qt3DSAssetVisitor *m_assetVisitor; QOpenGLContext *m_context; QSurface *m_surface; + QByteArray m_shaderCache; bool m_success = false; }; diff --git a/src/api/studio3dqml/q3dsstudio3d.cpp b/src/api/studio3dqml/q3dsstudio3d.cpp index 19cf09b..4cb0850 100644 --- a/src/api/studio3dqml/q3dsstudio3d.cpp +++ b/src/api/studio3dqml/q3dsstudio3d.cpp @@ -366,7 +366,11 @@ void Q3DSStudio3D::reset() m_pendingCommands.m_sourceChanged = true; m_pendingCommands.m_source = m_presentation ? m_presentation->source() : QString(); m_pendingCommands.m_variantListChanged = true; - m_pendingCommands.m_variantList = m_presentation ? m_presentation->variantList() : QStringList(); + m_pendingCommands.m_variantList = m_presentation ? m_presentation->variantList() + : QStringList(); + m_pendingCommands.m_shaderCacheFileChanged = true; + m_pendingCommands.m_shaderCacheFile = m_presentation ? m_presentation->shaderCacheFile() + : QString(); } /*! @@ -385,23 +389,16 @@ void Q3DSStudio3D::requestResponseHandler(const QString &elementPath, CommandTyp qWarning() << __FUNCTION__ << "RequestSlideInfo response got for unregistered scene."; break; } - case CommandType_RequestDataInputs: { + case CommandType_RequestDataInputs: + case CommandType_RequestDataOutputs: + case CommandType_RequestExportShaderCache: + { Q3DSPresentation *handler = qobject_cast<Q3DSPresentation *>(m_presentation); if (handler) { handler->d_ptr->requestResponseHandler(commandType, requestData); } else { - qWarning() << __FUNCTION__ - << "RequestDataInputs response got for invalid presentation."; - } - break; - } - case CommandType_RequestDataOutputs: { - Q3DSPresentation *handler = qobject_cast<Q3DSPresentation *>(m_presentation); - if (handler) { - handler->d_ptr->requestResponseHandler(commandType, requestData); - } else { - qWarning() << __FUNCTION__ - << "RequestDataOutputs response got for invalid presentation."; + qWarning() << __FUNCTION__ << "Command " << commandType + << "response got for invalid presentation."; } break; } |