summaryrefslogtreecommitdiff
path: root/src/video_core/sampler_cache.h
diff options
context:
space:
mode:
authorGravatar bunnei2019-04-17 21:45:56 -0400
committerGravatar GitHub2019-04-17 21:45:56 -0400
commit4294062516c91c8fdabbcb5b5bcde641c03c9218 (patch)
tree8420493647f54dbab66b3b654115e8c509f536d6 /src/video_core/sampler_cache.h
parentMerge pull request #2348 from FernandoS27/guest-bindless (diff)
parentgl_sampler_cache: Port sampler cache to OpenGL (diff)
downloadyuzu-4294062516c91c8fdabbcb5b5bcde641c03c9218.tar.gz
yuzu-4294062516c91c8fdabbcb5b5bcde641c03c9218.tar.xz
yuzu-4294062516c91c8fdabbcb5b5bcde641c03c9218.zip
Merge pull request #2318 from ReinUsesLisp/sampler-cache
gl_sampler_cache: Port sampler cache to OpenGL
Diffstat (limited to 'src/video_core/sampler_cache.h')
-rw-r--r--src/video_core/sampler_cache.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/video_core/sampler_cache.h b/src/video_core/sampler_cache.h
new file mode 100644
index 000000000..cbe3ad071
--- /dev/null
+++ b/src/video_core/sampler_cache.h
@@ -0,0 +1,60 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstddef>
8#include <unordered_map>
9
10#include "video_core/textures/texture.h"
11
12namespace VideoCommon {
13
14struct SamplerCacheKey final : public Tegra::Texture::TSCEntry {
15 std::size_t Hash() const;
16
17 bool operator==(const SamplerCacheKey& rhs) const;
18
19 bool operator!=(const SamplerCacheKey& rhs) const {
20 return !operator==(rhs);
21 }
22};
23
24} // namespace VideoCommon
25
26namespace std {
27
28template <>
29struct hash<VideoCommon::SamplerCacheKey> {
30 std::size_t operator()(const VideoCommon::SamplerCacheKey& k) const noexcept {
31 return k.Hash();
32 }
33};
34
35} // namespace std
36
37namespace VideoCommon {
38
39template <typename SamplerType, typename SamplerStorageType>
40class SamplerCache {
41public:
42 SamplerType GetSampler(const Tegra::Texture::TSCEntry& tsc) {
43 const auto [entry, is_cache_miss] = cache.try_emplace(SamplerCacheKey{tsc});
44 auto& sampler = entry->second;
45 if (is_cache_miss) {
46 sampler = CreateSampler(tsc);
47 }
48 return ToSamplerType(sampler);
49 }
50
51protected:
52 virtual SamplerStorageType CreateSampler(const Tegra::Texture::TSCEntry& tsc) const = 0;
53
54 virtual SamplerType ToSamplerType(const SamplerStorageType& sampler) const = 0;
55
56private:
57 std::unordered_map<SamplerCacheKey, SamplerStorageType> cache;
58};
59
60} // namespace VideoCommon \ No newline at end of file