src/libANGLE/renderer/metal/mtl_library_cache.mm


Log

Author Commit Date CI Message
Kenneth Russell 8ba04f1c 2023-08-05T00:48:35 Metal: disable fastmath less often. Stop disabling fastmath if atan is used in the shader. Application developers will surely prefer the significant performance improvement of the fastmath optimizations over corner-case differences in precision. Make disabling fastmath more precise: only if it's forcibly disabled as a driver bug workaround, or if the shader uses invariance and preserveInvariance is not available. Suppress the test: dEQP-GLES[23].functional.shaders.invariance.lowp.loop_2 which fails when fastmath is enabled for shaders using atan and invariance. Fixed: chromium:1320111 Change-Id: I6e33b14b1d05faedc15373f24af3e22a4074a35b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4754018 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kenneth Russell <kbr@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Geoff Lang 8b0e5413 2023-06-14T13:27:42 Metal: Put a limit on the total MTLLibrary objects cached Use an MRU for holding the cached libraries in mtl::LibraryCache. Using a maximum cache size of 128 and a GC size of 32 yields the same ratio of cache hits as before (40%) while cycling out the more unique shaders that are not re-used. Lowering the cache size to 64 or 96 yields a hit rate of 30-35%. Bug: chromium:1329376 Change-Id: I75dd6b20cf3f8b67c4b3c31da4e05e1857ad61db Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4614362 Reviewed-by: Quyen Le <lehoangquyen@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Geoff Lang 70ecc80f 2023-06-14T11:12:52 Metal: Store MSL in shared pointers to immutable strings The translated metal shader source is quite large and we store copies in both ProgramMtl and mtl::LibraryCache. Instead, store the source in shared_ptrs to immutable strings. This has a nice side effect of simplifying the cache keys for mtl::Library cache and avoiding string copies. This saves about 4% GPU process memory. Since these strings are rarely accessed, the overhead of shared_ptr is not a concern. Bug: chromium:1329376 Change-Id: I507529ff1e25cc6aafead272fc9bb6ab0b8dbe88 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4614361 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Quyen Le <lehoangquyen@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Scott Violet 3e281219 2023-04-27T14:52:18 Adds feature to output blob cache key and source for shader Bug: chromium:1423136 Change-Id: Ic03e1b9971b2f1417c0b2e95c8d3846f28a01572 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4480976 Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Scott Violet <sky@chromium.org>
Scott Violet 059bfe89 2023-04-27T16:13:06 metal(ish): Adds platform function for logging cache hits/misses And adds call from metal. This way chrome can log overall cache stats. Bug: chromium:1423136 Change-Id: Iba5b3bd138adf15fe5e999d3dee0002f140edac1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4484260 Commit-Queue: Scott Violet <sky@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org>
Scott Violet 65f4d2a4 2023-04-17T10:08:18 Adds features to enable loading/saving metallibs to blobcache CompileMetalShaders results in the appropriate command line tool being run to generate metallib blobs from shader source. DisableProgramCaching results in not saving programs to BlobCache LoadMetalShadersFromBlobCache results in trying to load metallibs from BlobCache. Bug: chromium:1423136 Change-Id: I01a4d7a5d60ed5ac978fb99db01b741e0f19e76b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4434293 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Scott Violet <sky@chromium.org>
Geoff Lang 5a77200b 2023-02-08T17:10:28 Metal: Implement parallel shader linking. Update the Metal library cache to be thread safe. Change absl::flat_hash_map back to std::unordered_map because the value types now contain a mutex which must not move. Only generate async compilation tasks for shaders that were not already compiled and in the cache. Collapse some of the link methods in ProgramMtl that only had one call site. All linking is now done in ProgramMtl::link and ProgramMtl::load. Support disabling parallel linking using the new enableParallelMtlLibraryCompilation feature. Bug: chromium:1385510 Change-Id: I71ba71a34d994066729df7e4170911f88c89de4a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4234153 Reviewed-by: Quyen Le <lehoangquyen@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
Geoff Lang 46f68dba 2023-02-06T15:22:31 Metal: Support LibraryCache below c++20. Usage of generic lookup with is_transparent is supported in c++20 or any recent absl version. Add macros to feature test c++ and fall back to copying the keys if generic lookup is not supported. Bug: chromium:1385510 Change-Id: I4017890e2cc664afe127defd63b8dd50fb6f4163 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4224874 Commit-Queue: Kenneth Russell <kbr@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Auto-Submit: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
Geoff Lang 9b00af52 2023-02-01T11:10:32 Metal: Add an in-memory MTLLibrary cache. Add a small cache for (msl + compile parameters) -> MTLLibrary at the egl::Display level. In regular executions of Chrome, the same shaders (particularly vertex) are compiled multiple times in different programs. Tested for a regular Chrome startup + open wikipedia + motionmark 1.2: 112/282 (40%) cache hits. Several different caching methods were profiled (LinkProgram perf test) - struct key with std::map : 303309 - struct key with std::unordered_map : 308090 - binary blob key with std::map : 263595 - binary blob key with std::unordered_map : 286051 - struct key + is_transparent with std::unordered_map : 304877 - struct key + is_transparent with absl::flat_hash_map : 335686 Using is_transparent allows us to search the hash map without copying the shader source string to construct the key structure. Bug: chromium:1385510 Change-Id: Ieec4ba526fe286276a4af7114d89cde32a8f9e1d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4214012 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org>