Commit Graph

11 Commits

Author SHA1 Message Date
Mark Satterthwaite
03314a3e3f In the shader-cache associate logged draw states with a 'streaming key' so that they may be batched and predrawn only when that 'streaming key' is active. This limits predrawing to only those states that are currently relevant. Added comments as to the purpose and operation of the shader-cache for posterity.
#codereview michael.trepka

[CL 2514492 by Mark Satterthwaite in Main branch]
2015-04-16 12:46:30 -04:00
Mark Satterthwaite
608acb6e7c Fix non-unity builds.
#codereview michael.trepka

[CL 2493613 by Mark Satterthwaite in Main branch]
2015-03-27 08:10:31 -04:00
Mark Satterthwaite
9d690116a6 Further optimisations for ShaderCache.
- Several GetTypeHash would produce only very narrow hash distributions, so these have been modified.
- FShaderDrawKey::GetTypeHash was particularly slow (around 4% of sampled time in Mac UT in Instruments) almost all in MemCrc32, so this has been replaced with a much simpler hash routine to bring it down to ~1% sampled time.
- FShaderDrawKey::operator== comparison order changed to try and fail earlier by testing from most-to-least varying attributes.
- Changed the way sampler-state & texture look-up works to avoid unnecessary map lookup.
#codereview michael.trepka

[CL 2493570 by Mark Satterthwaite in Main branch]
2015-03-27 07:20:23 -04:00
Mark Satterthwaite
9fe63a4308 In the shader-cache precompute the object hashes wherever possible to reduce the time spent searching maps, serialising the hashes to boot. Increments the current cache format version.
#codereview michael.trepka

[CL 2493555 by Mark Satterthwaite in Main branch]
2015-03-27 07:00:56 -04:00
Mark Satterthwaite
1f39e8f541 Fix a bug in early submission of compute shaders in the ShaderCache not using the correct hash.
#codereview michael.trepka, dmitry.rekman

[CL 2493544 by Mark Satterthwaite in Main branch]
2015-03-27 06:52:22 -04:00
Mark Satterthwaite
1e3b08f7f7 Disable the ShaderCache's draw-state logging by default in all circumstances since it is currently a significant performance impact and not all project use Shipping builds for release.
#codereview michael.trepka, dmitry.rekman

[CL 2493527 by Mark Satterthwaite in Main branch]
2015-03-27 06:31:34 -04:00
Mark Satterthwaite
835e8be727 Prevent the shader-cache from instantiating incompatible shader resources & crashing the RHI, requires exposing the existing ArePlatformsCompatible function from FShaderResource.
#codereview michael.trepka, dmitry.rekman

[CL 2493508 by Mark Satterthwaite in Main branch]
2015-03-27 06:12:37 -04:00
Marc Audy
daf220d485 Fix shadowed variables
[CL 2466748 by Marc Audy in Main branch]
2015-03-02 15:12:31 -05:00
Mark Satterthwaite
65e1a105de Shader caching has been updated to include the option to record draw-states used for each shader so that they may be pre-drawn to reduce in-driver hitching.
- This is especially important on OS X OpenGL where these hitches can be equivalent to several frames, so it is enabled by default for this platform.
- The logging of draw calls is turned on/off with r.UseShaderDrawLog and incurs a fixed overhead as all RHI state is tracked & recorded into the shader cache.
- The actual predrawing is turned on/off with r.UseShaderPredraw and requires an existing cache to be useful, the predrawing takes place at frame-end and can be controlled with r.PredrawBatchTime which the time in ms to spend predrawing each frame until complete, or -1 to do it in one go (currently the default).
- The shader cache is now also versioned with the game able to supply a version distinct from the engine, so that old caches may be invalidated if/when required.
- The shader cache is now compatible with OpenGL SM4 & SM5 on Windows & probably Linux too.
- It may not work correctly with desktop ES2 emulation as that is still untested.
- To make it easier to add to other RHIs the API has been made simper to avoid lots of exposed branches.

#codereview michael.trepka, dmitry.rekman

[CL 2460109 by Mark Satterthwaite in Main branch]
2015-02-25 08:13:48 -05:00
Mark Satterthwaite
165c5a749c [INTEGRATE] Merged CL #2425500 from UE4-UT to Main
Fix crash on shutdown when ShaderCache has not been initialised.

[CL 2425502 by Mark Satterthwaite in Main branch]
2015-01-30 06:25:26 -05:00
Mark Satterthwaite
a511ded42a Initial ShaderCore-level cache to start addressing shader hitches [UE-7536]. At present it is only configured by Mac OpenGL, though other APIs could use it. As all shaders & programs are cached it is inappropriate for memory constrained devices so it is only enabled by Desktop platforms.
- The consolve variable "r.UseShaderCaching" controls whether the cache should be used.
   - The cache has to be initialised and shutdown by the RHI.
   - All RHI shader types now contain the SHA hash of the compiled source when the cache is in use so that they can be identified efficiently.
   - All shaders are fetched from the cache rather than being created on-demand.
   - On shader deserialisation the new shader is sent to the render thread for creation & caching.
   - After each shader is cached all complete bound-shader-states that include that shader are constructed and cached.
   - Wrapped OpenGL glCreateShader & glCreateProgram to use name-caching as these operations can synchronise the entire OpenGL pipeline on OS X.

[CL 2423996 by Mark Satterthwaite in Main branch]
2015-01-29 12:34:05 -05:00