Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/TextureCacheVulkan.h
3186 views
1
// Copyright (c) 2015- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include "Common/Data/Collections/Hashmaps.h"
21
#include "GPU/GPUCommon.h"
22
#include "GPU/GPUState.h"
23
#include "Common/GPU/Vulkan/VulkanContext.h"
24
#include "GPU/Common/TextureCacheCommon.h"
25
#include "GPU/Common/TextureShaderCommon.h"
26
#include "GPU/Vulkan/VulkanUtil.h"
27
28
struct VirtualFramebuffer;
29
class FramebufferManagerVulkan;
30
class DepalShaderCacheVulkan;
31
class ShaderManagerVulkan;
32
class DrawEngineVulkan;
33
34
class VulkanContext;
35
class VulkanTexture;
36
37
class SamplerCache {
38
public:
39
SamplerCache(VulkanContext *vulkan) : vulkan_(vulkan), cache_(16) {}
40
~SamplerCache();
41
VkSampler GetOrCreateSampler(const SamplerCacheKey &key);
42
43
void DeviceLost();
44
void DeviceRestore(VulkanContext *vulkan);
45
46
std::vector<std::string> DebugGetSamplerIDs() const;
47
static std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
48
49
private:
50
VulkanContext *vulkan_;
51
DenseHashMap<SamplerCacheKey, VkSampler> cache_;
52
};
53
54
class TextureCacheVulkan : public TextureCacheCommon {
55
public:
56
TextureCacheVulkan(Draw::DrawContext *draw, Draw2D *draw2D, VulkanContext *vulkan);
57
~TextureCacheVulkan();
58
59
void StartFrame() override;
60
61
void DeviceLost() override;
62
void DeviceRestore(Draw::DrawContext *draw) override;
63
64
void SetFramebufferManager(FramebufferManagerVulkan *fbManager);
65
void SetDrawEngine(DrawEngineVulkan *td) {
66
drawEngine_ = td;
67
}
68
69
void ForgetLastTexture() override {}
70
void NotifyConfigChanged() override;
71
72
void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) {
73
imageView = imageView_;
74
sampler = curSampler_;
75
}
76
77
bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;
78
79
void GetStats(char *ptr, size_t size);
80
81
std::vector<std::string> DebugGetSamplerIDs() const;
82
std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
83
84
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
85
86
protected:
87
void BindTexture(TexCacheEntry *entry) override;
88
void Unbind() override;
89
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
90
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
91
void ApplySamplingParams(const SamplerCacheKey &key) override;
92
void BoundFramebufferTexture() override;
93
94
private:
95
void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
96
static VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) ;
97
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
98
99
void BuildTexture(TexCacheEntry *const entry) override;
100
101
void CompileScalingShader();
102
103
VulkanComputeShaderManager computeShaderManager_;
104
105
SamplerCache samplerCache_;
106
107
DrawEngineVulkan *drawEngine_;
108
109
std::string textureShader_;
110
VkShaderModule uploadCS_ = VK_NULL_HANDLE;
111
112
// Bound state to emulate an API similar to the others
113
VkImageView imageView_ = VK_NULL_HANDLE;
114
VkSampler curSampler_ = VK_NULL_HANDLE;
115
116
VkSampler samplerNearest_ = VK_NULL_HANDLE;
117
};
118
119
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);
120
121