summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Treat <adam.treat@qt.io>2018-01-25 15:14:44 -0500
committerTomi Korpipää <tomi.korpipaa@qt.io>2018-02-02 09:03:18 +0000
commit5b64017784de460d2f128df9c730e65ee79bfeae (patch)
tree9936cd26a1a5f06aba51eaf2b12cd768d542f67f /src
parent73ba12ae0a5ad26871d7c52e38e12ad8ca9bb1e5 (diff)
Fix runtime shader cache
The shader cache has been broken (both at runtime and when persistence is enabled) because a prefix for shader cache key was added when for seemingly debug purposes. The result has been a missed lookup because the key in the cache does not match the one we use for lookup. Change-Id: Ib95cb0402979513c1516e5682054763d358ca42d Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShaderCache.h3
-rw-r--r--src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp7
-rw-r--r--src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderDefaultMaterialShaderGenerator.cpp3
-rw-r--r--src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderShaderCache.cpp14
4 files changed, 21 insertions, 6 deletions
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShaderCache.h b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShaderCache.h
index 09996bf2..47e76f36 100644
--- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShaderCache.h
+++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderShaderCache.h
@@ -129,7 +129,8 @@ namespace render {
ForceCompileProgram(CRegisteredString inKey, const char8_t *inVert, const char8_t *inFrag,
const char8_t *inTessCtrl, const char8_t *inTessEval,
const char8_t *inGeom, const SShaderCacheProgramFlags &inFlags,
- TShaderFeatureSet inFeatures, bool separableProgram) = 0;
+ TShaderFeatureSet inFeatures, bool separableProgram,
+ bool fromDisk = false) = 0;
// It is up to the caller to ensure that inFeatures contains unique keys.
// It is also up the the caller to ensure the keys are ordered in some way.
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp
index e17458f7..040bf3d9 100644
--- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp
+++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp
@@ -554,7 +554,11 @@ namespace render {
// This is time consuming but I feel like it doesn't happen all that often and is very
// useful to users
// looking at the log file.
+ QLatin1String logPrefix("mesh subset pipeline-- ");
+
m_GeneratedShaderString.clear();
+ m_GeneratedShaderString.assign(logPrefix.data());
+
SShaderDefaultMaterialKey theKey(inRenderable.m_ShaderDescription);
theKey.ToString(m_GeneratedShaderString, m_DefaultMaterialShaderKeyProperties);
IShaderCache &theCache = m_qt3dsContext.GetShaderCache();
@@ -570,7 +574,8 @@ namespace render {
return m_qt3dsContext.GetDefaultMaterialShaderGenerator().GenerateShader(
inRenderable.m_Material, inRenderable.m_ShaderDescription, pipeline, inFeatureSet,
m_CurrentLayer->m_Lights, inRenderable.m_FirstImage,
- inRenderable.m_RenderableFlags.HasTransparency(), "mesh subset pipeline-- ");
+ inRenderable.m_RenderableFlags.HasTransparency(),
+ logPrefix.data());
}
// -------------- Special cases for shadows -------------------
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderDefaultMaterialShaderGenerator.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderDefaultMaterialShaderGenerator.cpp
index f4e64541..be28e2c7 100644
--- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderDefaultMaterialShaderGenerator.cpp
+++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderDefaultMaterialShaderGenerator.cpp
@@ -1503,7 +1503,10 @@ struct SShaderGenerator : public IDefaultMaterialShaderGenerator
// This is time consuming but I feel like it doesn't happen all that often and is very
// useful to users
// looking at the log file.
+
+ m_GeneratedShaderString.clear();
m_GeneratedShaderString.assign(nonNull(inShaderPrefix));
+
SShaderDefaultMaterialKey theKey(Key());
theKey.ToString(m_GeneratedShaderString, m_DefaultMaterialShaderKeyProperties);
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderShaderCache.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderShaderCache.cpp
index 63d7cace..a3e70778 100644
--- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderShaderCache.cpp
+++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderShaderCache.cpp
@@ -456,7 +456,7 @@ struct ShaderCache : public IShaderCache
const char8_t *inTessCtrl, const char8_t *inTessEval, const char8_t *inGeom,
const SShaderCacheProgramFlags &inFlags,
NVConstDataRef<SShaderPreprocessorFeature> inFeatures,
- bool separableProgram) override
+ bool separableProgram, bool fromDisk = false) override
{
if (m_ShaderCompilationEnabled == false)
return NULL;
@@ -465,6 +465,14 @@ struct ShaderCache : public IShaderCache
tempKey.GenerateHashCode();
eastl::pair<TShaderMap::iterator, bool> theInserter = m_Shaders.insert(tempKey);
+ if (fromDisk) {
+ qCInfo(TRACE_INFO) << "Loading from persistent shader cache: '<"
+ << tempKey.m_Key << ">'";
+ } else {
+ qCInfo(TRACE_INFO) << "Compiling into shader cache: '"
+ << tempKey.m_Key << ">'";
+ }
+
if (!inVert)
inVert = "";
if (!inTessCtrl)
@@ -497,8 +505,6 @@ struct ShaderCache : public IShaderCache
if (inFlags.IsGeometryShaderEnabled())
AddShaderPreprocessor(m_GeometryCode, inKey, ShaderType::Geometry, inFeatures);
- qCInfo(TRACE_INFO, "Shader compiler - compiling shader %s", inKey.c_str());
-
theInserter.first->second =
m_RenderContext
.CompileSource(inKey, m_VertexCode.c_str(), m_VertexCode.size(),
@@ -706,7 +712,7 @@ struct ShaderCache : public IShaderCache
loadGeometryData.c_str(), theFlags,
qt3ds::foundation::toDataRef(theFeatures.data(),
(QT3DSU32)theFeatures.size()),
- false);
+ false, true /*fromDisk*/);
// If something doesn't save or load correctly, get the runtime
// to re-generate.
if (!theShader)