summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2020-10-20 14:26:03 +0300
committerAntti Määttä <antti.maatta@qt.io>2020-10-21 06:54:43 +0300
commit24d0ffbdd7af55849d8035a6df472ed6e64adab5 (patch)
treeba3e76a9d7b32e4dea4ec3ee9df5c1174676fdb1
parentddc70c4bfbd0c3819ecf859f53c9069844fd2ca6 (diff)
Remove shader cache export restriction
Task-number: QT3DS-4145 Change-Id: I5710595aeb6c738af4c8e2d5182be8f1974dccbe Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/runtimerender/Qt3DSRenderShaderCache.cpp33
1 files 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;