2015-10-10 16:41:19 +02:00
|
|
|
// Copyright (c) 2015- PPSSPP Project.
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2020-10-05 20:58:33 +02:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2024-12-02 10:32:57 +01:00
|
|
|
#include "GPU/GPUCommon.h"
|
2015-10-10 16:41:19 +02:00
|
|
|
#include "GPU/GPUState.h"
|
2020-10-04 23:24:14 +02:00
|
|
|
#include "Common/GPU/Vulkan/VulkanContext.h"
|
2016-01-03 23:09:37 +01:00
|
|
|
#include "GPU/Common/TextureCacheCommon.h"
|
2022-08-22 12:20:21 +02:00
|
|
|
#include "GPU/Common/TextureShaderCommon.h"
|
2017-12-11 11:26:05 +01:00
|
|
|
#include "GPU/Vulkan/VulkanUtil.h"
|
2016-01-03 23:09:37 +01:00
|
|
|
|
|
|
|
|
struct VirtualFramebuffer;
|
|
|
|
|
class FramebufferManagerVulkan;
|
|
|
|
|
class DepalShaderCacheVulkan;
|
|
|
|
|
class ShaderManagerVulkan;
|
|
|
|
|
class DrawEngineVulkan;
|
|
|
|
|
|
|
|
|
|
class VulkanContext;
|
2016-03-17 11:56:43 +01:00
|
|
|
class VulkanTexture;
|
2016-01-09 01:23:32 +01:00
|
|
|
|
|
|
|
|
class SamplerCache {
|
|
|
|
|
public:
|
2017-08-20 19:03:16 +02:00
|
|
|
SamplerCache(VulkanContext *vulkan) : vulkan_(vulkan), cache_(16) {}
|
2016-01-09 01:23:32 +01:00
|
|
|
~SamplerCache();
|
|
|
|
|
VkSampler GetOrCreateSampler(const SamplerCacheKey &key);
|
2016-01-09 11:07:14 +01:00
|
|
|
|
2016-10-09 11:26:44 -07:00
|
|
|
void DeviceLost();
|
|
|
|
|
void DeviceRestore(VulkanContext *vulkan);
|
|
|
|
|
|
2017-12-06 16:01:56 +01:00
|
|
|
std::vector<std::string> DebugGetSamplerIDs() const;
|
2024-04-05 17:04:31 +03:00
|
|
|
static std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
|
2017-12-06 16:01:56 +01:00
|
|
|
|
2016-01-09 01:23:32 +01:00
|
|
|
private:
|
|
|
|
|
VulkanContext *vulkan_;
|
2023-09-11 12:02:56 +02:00
|
|
|
DenseHashMap<SamplerCacheKey, VkSampler> cache_;
|
2016-01-09 01:23:32 +01:00
|
|
|
};
|
|
|
|
|
|
2015-10-10 16:41:19 +02:00
|
|
|
class TextureCacheVulkan : public TextureCacheCommon {
|
|
|
|
|
public:
|
2022-08-23 11:11:04 +02:00
|
|
|
TextureCacheVulkan(Draw::DrawContext *draw, Draw2D *draw2D, VulkanContext *vulkan);
|
2016-01-03 23:09:37 +01:00
|
|
|
~TextureCacheVulkan();
|
|
|
|
|
|
2022-08-05 13:27:55 +02:00
|
|
|
void StartFrame() override;
|
2016-01-03 23:09:37 +01:00
|
|
|
|
2023-02-25 23:04:27 +01:00
|
|
|
void DeviceLost() override;
|
|
|
|
|
void DeviceRestore(Draw::DrawContext *draw) override;
|
2016-10-09 11:26:44 -07:00
|
|
|
|
2017-02-08 15:58:46 +01:00
|
|
|
void SetFramebufferManager(FramebufferManagerVulkan *fbManager);
|
2017-02-04 11:47:19 +01:00
|
|
|
void SetDrawEngine(DrawEngineVulkan *td) {
|
|
|
|
|
drawEngine_ = td;
|
2016-01-03 23:09:37 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-20 23:57:43 +02:00
|
|
|
void ForgetLastTexture() override {}
|
2020-08-01 22:00:04 -07:00
|
|
|
void NotifyConfigChanged() override;
|
|
|
|
|
|
2017-02-19 23:19:55 +01:00
|
|
|
void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) {
|
|
|
|
|
imageView = imageView_;
|
2017-10-30 15:50:02 +01:00
|
|
|
sampler = curSampler_;
|
2017-02-19 23:19:55 +01:00
|
|
|
}
|
2016-01-03 23:09:37 +01:00
|
|
|
|
2022-10-10 22:35:42 -07:00
|
|
|
bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;
|
2017-10-18 13:03:49 +02:00
|
|
|
|
2017-12-03 10:29:41 +01:00
|
|
|
void GetStats(char *ptr, size_t size);
|
|
|
|
|
|
|
|
|
|
VulkanDeviceAllocator *GetAllocator() { return allocator_; }
|
|
|
|
|
|
2017-12-06 16:01:56 +01:00
|
|
|
std::vector<std::string> DebugGetSamplerIDs() const;
|
2023-12-14 14:23:31 +03:00
|
|
|
std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);
|
2017-12-06 16:01:56 +01:00
|
|
|
|
2024-12-10 22:09:51 +01:00
|
|
|
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
|
|
|
|
|
|
2016-01-06 23:08:26 +01:00
|
|
|
protected:
|
2017-02-19 23:07:00 +01:00
|
|
|
void BindTexture(TexCacheEntry *entry) override;
|
2017-02-08 15:43:53 +01:00
|
|
|
void Unbind() override;
|
2017-02-23 17:31:24 +01:00
|
|
|
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
|
2022-08-24 09:31:47 +02:00
|
|
|
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
|
2022-08-05 12:34:29 +02:00
|
|
|
void ApplySamplingParams(const SamplerCacheKey &key) override;
|
2022-08-05 15:09:33 +02:00
|
|
|
void BoundFramebufferTexture() override;
|
2016-01-03 23:09:37 +01:00
|
|
|
|
|
|
|
|
private:
|
2022-12-10 20:32:12 -08:00
|
|
|
void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
|
2024-04-05 17:04:31 +03:00
|
|
|
static VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) ;
|
2017-02-20 00:05:23 +01:00
|
|
|
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
|
2016-01-03 23:09:37 +01:00
|
|
|
|
2018-03-25 10:49:28 +02:00
|
|
|
void BuildTexture(TexCacheEntry *const entry) override;
|
2016-05-01 17:27:14 -07:00
|
|
|
|
2020-08-01 22:00:04 -07:00
|
|
|
void CompileScalingShader();
|
|
|
|
|
|
2017-11-10 12:40:51 +01:00
|
|
|
VulkanDeviceAllocator *allocator_ = nullptr;
|
2016-01-03 23:09:37 +01:00
|
|
|
|
2017-12-11 13:23:06 +01:00
|
|
|
VulkanComputeShaderManager computeShaderManager_;
|
2017-12-11 11:26:05 +01:00
|
|
|
|
2016-01-09 01:23:32 +01:00
|
|
|
SamplerCache samplerCache_;
|
|
|
|
|
|
2017-02-04 11:47:19 +01:00
|
|
|
DrawEngineVulkan *drawEngine_;
|
2017-02-19 23:19:55 +01:00
|
|
|
|
2020-08-01 22:00:04 -07:00
|
|
|
std::string textureShader_;
|
2017-12-11 12:22:24 +01:00
|
|
|
VkShaderModule uploadCS_ = VK_NULL_HANDLE;
|
|
|
|
|
|
2017-02-19 23:19:55 +01:00
|
|
|
// Bound state to emulate an API similar to the others
|
|
|
|
|
VkImageView imageView_ = VK_NULL_HANDLE;
|
2017-10-30 15:50:02 +01:00
|
|
|
VkSampler curSampler_ = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
|
|
VkSampler samplerNearest_ = VK_NULL_HANDLE;
|
2015-10-10 16:41:19 +02:00
|
|
|
};
|
2016-01-03 23:09:37 +01:00
|
|
|
|
|
|
|
|
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);
|