Hash :
8ba04f1c
Author :
Date :
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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
//
// Copyright 2023 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// mtl_library_cache.h:
// Defines classes for caching of mtl libraries
//
#ifndef LIBANGLE_RENDERER_METAL_MTL_LIBRARY_CACHE_H_
#define LIBANGLE_RENDERER_METAL_MTL_LIBRARY_CACHE_H_
#include "libANGLE/renderer/metal/mtl_utils.h"
#include <type_traits>
namespace rx
{
namespace mtl
{
class LibraryCache : angle::NonCopyable
{
public:
LibraryCache();
AutoObjCPtr<id<MTLLibrary>> get(const std::shared_ptr<const std::string> &source,
const std::map<std::string, std::string> ¯os,
bool disableFastMath,
bool usesInvariance);
AutoObjCPtr<id<MTLLibrary>> getOrCompileShaderLibrary(
ContextMtl *context,
const std::shared_ptr<const std::string> &source,
const std::map<std::string, std::string> ¯os,
bool disableFastMath,
bool usesInvariance,
AutoObjCPtr<NSError *> *errorOut);
private:
struct LibraryKey
{
LibraryKey() = default;
LibraryKey(const std::shared_ptr<const std::string> &source,
const std::map<std::string, std::string> ¯os,
bool disableFastMath,
bool usesInvariance);
std::shared_ptr<const std::string> source;
std::map<std::string, std::string> macros;
bool disableFastMath;
bool usesInvariance;
bool operator==(const LibraryKey &other) const;
};
struct LibraryKeyHasher
{
// Hash function
size_t operator()(const LibraryKey &k) const;
// Comparison
bool operator()(const LibraryKey &a, const LibraryKey &b) const;
};
struct LibraryCacheEntry : angle::NonCopyable
{
LibraryCacheEntry() = default;
~LibraryCacheEntry();
LibraryCacheEntry(LibraryCacheEntry &&moveFrom);
// library can only go from the null -> not null state. It is safe to check if the library
// already exists without locking.
AutoObjCPtr<id<MTLLibrary>> library;
// Lock for this specific library to avoid multiple threads compiling the same shader at
// once.
std::mutex lock;
};
LibraryCacheEntry &getCacheEntry(LibraryKey &&key);
static constexpr unsigned int kMaxCachedLibraries = 128;
// The cache tries to clean up this many states at once.
static constexpr unsigned int kGCLimit = 32;
// Lock for searching and adding new entries to the cache
std::mutex mCacheLock;
using CacheMap = angle::base::HashingMRUCache<LibraryKey, LibraryCacheEntry, LibraryKeyHasher>;
CacheMap mCache;
};
} // namespace mtl
} // namespace rx
#endif // LIBANGLE_RENDERER_METAL_MTL_LIBRARY_CACHE_H_