CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/TextureCacheVulkan.h
Views: 1401
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/GPUInterface.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
VulkanDeviceAllocator *GetAllocator() { return allocator_; }
82
83
std::vector<std::string> DebugGetSamplerIDs() const;
84
std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
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
void *GetNativeTextureView(const TexCacheEntry *entry) override;
94
95
private:
96
void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
97
static VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) ;
98
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
99
100
void BuildTexture(TexCacheEntry *const entry) override;
101
102
void CompileScalingShader();
103
104
VulkanDeviceAllocator *allocator_ = nullptr;
105
106
VulkanComputeShaderManager computeShaderManager_;
107
108
SamplerCache samplerCache_;
109
110
DrawEngineVulkan *drawEngine_;
111
112
std::string textureShader_;
113
VkShaderModule uploadCS_ = VK_NULL_HANDLE;
114
115
// Bound state to emulate an API similar to the others
116
VkImageView imageView_ = VK_NULL_HANDLE;
117
VkSampler curSampler_ = VK_NULL_HANDLE;
118
119
VkSampler samplerNearest_ = VK_NULL_HANDLE;
120
};
121
122
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);
123
124