From 24d0ffbdd7af55849d8035a6df472ed6e64adab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Tue, 20 Oct 2020 14:26:03 +0300 Subject: Remove shader cache export restriction Task-number: QT3DS-4145 Change-Id: I5710595aeb6c738af4c8e2d5182be8f1974dccbe Reviewed-by: Miikka Heikkinen --- src/runtimerender/Qt3DSRenderShaderCache.cpp | 33 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/runtimerender/Qt3DSRenderShaderCache.cpp b/src/runtimerender/Qt3DSRenderShaderCache.cpp index b1a8c4b..15c1b45 100644 --- a/src/runtimerender/Qt3DSRenderShaderCache.cpp +++ b/src/runtimerender/Qt3DSRenderShaderCache.cpp @@ -126,6 +126,7 @@ struct ShaderCache : public IShaderCache IInputStreamFactory &m_InputStreamFactory; bool m_ShaderCompilationEnabled = true; bool m_shadersInitializedFromCache = false; + bool m_binaryShaderCache = false; volatile QT3DSI32 mRefCount = 0; struct ShaderSource @@ -459,22 +460,22 @@ struct ShaderCache : public IShaderCache theInserter.first->second = res.mShader; errors = res.errors; - // This is unnecessary memory waste in final deployed product, so we don't store this - // information when shaders were initialized from a cache. - // Unfortunately it is not practical to just regenerate shader source from scratch, when we - // want to export it, as the triggers and original sources are spread all over the place. - if (!m_shadersInitializedFromCache && theInserter.first->second) { + if (theInserter.first->second) { // Store sources for possible cache generation later ShaderSource ss; for (QT3DSU32 i = 0, end = inFeatures.size(); i < end; ++i) ss.features.append(inFeatures[i]); ss.key = inKey; ss.flags = inFlags; - ss.vertexCode = inVert; - ss.fragmentCode = inFrag; - ss.tessCtrlCode = inTessCtrl; - ss.tessEvalCode = inTessEval; - ss.geometryCode = inGeom; + // Do not store shader sources for binary cache + if (!m_shadersInitializedFromCache + || (m_shadersInitializedFromCache && !m_binaryShaderCache)) { + ss.vertexCode = inVert; + ss.fragmentCode = inFrag; + ss.tessCtrlCode = inTessCtrl; + ss.tessEvalCode = inTessEval; + ss.geometryCode = inGeom; + } m_shaderSourceCache.append(ss); } @@ -504,9 +505,13 @@ struct ShaderCache : public IShaderCache QByteArray exportShaderCache(bool binaryShaders) override { if (m_shadersInitializedFromCache) { - qWarning() << __FUNCTION__ << "Warning: Shader cache export is not supported when" - " shaders were originally imported from a cache file."; - return {}; + if (m_binaryShaderCache != binaryShaders) { + qWarning() << __FUNCTION__ << "Warning: Shader cache export and" + " import mode mismatch."; + return {}; + } + qWarning() << __FUNCTION__ << "Warning: Shader cache export while also imported" + " from the cache. This might not be intended."; } // The assumption is that cache was generated on the same environment it will be read. @@ -600,6 +605,8 @@ struct ShaderCache : public IShaderCache #undef BAILOUT + m_binaryShaderCache = isBinary; + IStringTable &stringTable(m_RenderContext.GetStringTable()); int progCount; -- cgit v1.2.3