summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/vk_renderpass_cache.h
blob: 0e988b26bb805d2ef01317bd8442daac9ab183c0 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <type_traits>
#include <unordered_map>

#include <boost/container/static_vector.hpp>
#include <boost/functional/hash.hpp>

#include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_vulkan/wrapper.h"
#include "video_core/surface.h"

namespace Vulkan {

class VKDevice;

struct RenderPassParams {
    u8 num_color_attachments;
    std::array<u8, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> color_formats;
    u8 texceptions;

    u8 zeta_format;
    u8 zeta_texception;

    std::size_t Hash() const noexcept;

    bool operator==(const RenderPassParams& rhs) const noexcept;

    bool operator!=(const RenderPassParams& rhs) const noexcept {
        return !operator==(rhs);
    }
};
static_assert(std::has_unique_object_representations_v<RenderPassParams>);
static_assert(std::is_trivially_copyable_v<RenderPassParams>);
static_assert(std::is_trivially_constructible_v<RenderPassParams>);

} // namespace Vulkan

namespace std {

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

} // namespace std

namespace Vulkan {

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

    VkRenderPass GetRenderPass(const RenderPassParams& params);

private:
    vk::RenderPass CreateRenderPass(const RenderPassParams& params) const;

    const VKDevice& device;
    std::unordered_map<RenderPassParams, vk::RenderPass> cache;
};

} // namespace Vulkan