summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/vk_sampler_cache.h
blob: c6394dc8779d5a470592d6cea2072a82662787fe (plain) (blame)
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
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <unordered_map>

#include "common/common_types.h"
#include "video_core/renderer_vulkan/declarations.h"
#include "video_core/textures/texture.h"

namespace Vulkan {

class VKDevice;

struct SamplerCacheKey final : public Tegra::Texture::TSCEntry {
    std::size_t Hash() const;

    bool operator==(const SamplerCacheKey& rhs) const;

    bool operator!=(const SamplerCacheKey& rhs) const {
        return !operator==(rhs);
    }
};

} // namespace Vulkan

namespace std {

template <>
struct hash<Vulkan::SamplerCacheKey> {
    std::size_t operator()(const Vulkan::SamplerCacheKey& k) const noexcept {
        return k.Hash();
    }
};

} // namespace std

namespace Vulkan {

class VKSamplerCache {
public:
    explicit VKSamplerCache(const VKDevice& device);
    ~VKSamplerCache();

    vk::Sampler GetSampler(const Tegra::Texture::TSCEntry& tsc);

private:
    UniqueSampler CreateSampler(const Tegra::Texture::TSCEntry& tsc);

    const VKDevice& device;
    std::unordered_map<SamplerCacheKey, UniqueSampler> cache;
};

} // namespace Vulkan