Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/TextureCacheVulkan.h
5664 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/GPUState.h"
22
#include "Common/GPU/Vulkan/VulkanContext.h"
23
#include "GPU/Common/TextureCacheCommon.h"
24
#include "GPU/Common/TextureShaderCommon.h"
25
#include "GPU/Vulkan/VulkanUtil.h"
26
27
struct VirtualFramebuffer;
28
class FramebufferManagerVulkan;
29
class DepalShaderCacheVulkan;
30
class ShaderManagerVulkan;
31
class DrawEngineVulkan;
32
33
class VulkanContext;
34
class VulkanTexture;
35
36
class SamplerCache {
37
public:
38
SamplerCache(VulkanContext *vulkan) : vulkan_(vulkan), cache_(16) {}
39
~SamplerCache();
40
VkSampler GetOrCreateSampler(const SamplerCacheKey &key);
41
42
void DeviceLost();
43
void DeviceRestore(VulkanContext *vulkan);
44
45
std::vector<std::string> DebugGetSamplerIDs() const;
46
static std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
47
48
private:
49
VulkanContext *vulkan_;
50
DenseHashMap<SamplerCacheKey, VkSampler> cache_;
51
};
52
53
class TextureCacheVulkan : public TextureCacheCommon {
54
public:
55
TextureCacheVulkan(Draw::DrawContext *draw, Draw2D *draw2D, VulkanContext *vulkan);
56
~TextureCacheVulkan();
57
58
void StartFrame() override;
59
60
void DeviceLost() override;
61
void DeviceRestore(Draw::DrawContext *draw) override;
62
63
void SetFramebufferManager(FramebufferManagerVulkan *fbManager);
64
void SetDrawEngine(DrawEngineVulkan *td) {
65
drawEngine_ = td;
66
}
67
68
void ForgetLastTexture() override {}
69
void NotifyConfigChanged() override;
70
71
void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) {
72
imageView = imageView_;
73
sampler = curSampler_;
74
}
75
76
bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;
77
78
void GetStats(char *ptr, size_t size);
79
80
std::vector<std::string> DebugGetSamplerIDs() const;
81
std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
82
83
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
84
85
protected:
86
void BindTexture(TexCacheEntry *entry) override;
87
void Unbind() override;
88
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
89
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
90
void ApplySamplingParams(const SamplerCacheKey &key) override;
91
void BoundFramebufferTexture() override;
92
93
private:
94
void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
95
static VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) ;
96
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
97
98
void BuildTexture(TexCacheEntry *const entry) override;
99
100
void CompileScalingShader();
101
102
VulkanComputeShaderManager computeShaderManager_;
103
104
SamplerCache samplerCache_;
105
106
DrawEngineVulkan *drawEngine_;
107
108
std::string textureShader_;
109
VkShaderModule uploadCS_ = VK_NULL_HANDLE;
110
111
// Bound state to emulate an API similar to the others
112
VkImageView imageView_ = VK_NULL_HANDLE;
113
VkSampler curSampler_ = VK_NULL_HANDLE;
114
115
VkSampler samplerNearest_ = VK_NULL_HANDLE;
116
};
117
118
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);
119
120