diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-03 11:59:24 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-09 20:42:38 +0200 |
commit | 7af6649e884f4ba9fa3fde0333090b93f62a13c0 (patch) | |
tree | 50c8123a114b6f29a949c910751ce999e9bc7c81 /src/gui/rhi/qrhid3d11_p_p.h | |
parent | 89d0a03c067b42155b1a2d310f8514f595abfd61 (diff) |
rhi: gl, metal, d3d: Reuse shader objects when source is the same
Now that Qt Quick's batch renderer misses one level of shader source
caching due to the nature of pipeline state objects, it can be useful
to keep and reuse shader objects when the hash of the source code
matches.
The goal here is to allow Qt Quick to be on par with what the direct
OpenGL path has when it comes to caching shader sources and compilation
results. The program binary disk cache is not in scope in this patch.
Also adds QRhi::releaseCachedResources(), similarly to what the scenegraph
has. This can be called to clear caches such as the shader object
cache we keep here.
Change-Id: Ie3d81d823f61fa65ec814439e882c498f7774d43
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhid3d11_p_p.h')
-rw-r--r-- | src/gui/rhi/qrhid3d11_p_p.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h index 582146315d..cd44519aaa 100644 --- a/src/gui/rhi/qrhid3d11_p_p.h +++ b/src/gui/rhi/qrhid3d11_p_p.h @@ -632,6 +632,7 @@ public: const QRhiNativeHandles *nativeHandles() override; void sendVMemStatsToProfiler() override; void makeThreadLocalNativeContextCurrent() override; + void releaseCachedResources() override; void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD, int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc); @@ -646,6 +647,7 @@ public: DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount) const; void finishActiveReadbacks(); void reportLiveObjects(ID3D11Device *device); + void clearShaderCache(); bool debugLayer = false; bool importedDevice = false; @@ -684,6 +686,14 @@ public: QRhiTexture::Format format; }; QVector<ActiveReadback> activeReadbacks; + + struct Shader { + Shader() = default; + Shader(IUnknown *s, const QByteArray &bytecode) : s(s), bytecode(bytecode) { } + IUnknown *s; + QByteArray bytecode; + }; + QHash<QRhiShaderStage, Shader> m_shaderCache; }; Q_DECLARE_TYPEINFO(QRhiD3D11::ActiveReadback, Q_MOVABLE_TYPE); |