CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Vulkan/TextureCacheVulkan.h
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "Common/Data/Collections/Hashmaps.h"20#include "GPU/GPUInterface.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"2627struct VirtualFramebuffer;28class FramebufferManagerVulkan;29class DepalShaderCacheVulkan;30class ShaderManagerVulkan;31class DrawEngineVulkan;3233class VulkanContext;34class VulkanTexture;3536class SamplerCache {37public:38SamplerCache(VulkanContext *vulkan) : vulkan_(vulkan), cache_(16) {}39~SamplerCache();40VkSampler GetOrCreateSampler(const SamplerCacheKey &key);4142void DeviceLost();43void DeviceRestore(VulkanContext *vulkan);4445std::vector<std::string> DebugGetSamplerIDs() const;46static std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);4748private:49VulkanContext *vulkan_;50DenseHashMap<SamplerCacheKey, VkSampler> cache_;51};5253class TextureCacheVulkan : public TextureCacheCommon {54public:55TextureCacheVulkan(Draw::DrawContext *draw, Draw2D *draw2D, VulkanContext *vulkan);56~TextureCacheVulkan();5758void StartFrame() override;5960void DeviceLost() override;61void DeviceRestore(Draw::DrawContext *draw) override;6263void SetFramebufferManager(FramebufferManagerVulkan *fbManager);64void SetDrawEngine(DrawEngineVulkan *td) {65drawEngine_ = td;66}6768void ForgetLastTexture() override {}69void NotifyConfigChanged() override;7071void GetVulkanHandles(VkImageView &imageView, VkSampler &sampler) {72imageView = imageView_;73sampler = curSampler_;74}7576bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;7778void GetStats(char *ptr, size_t size);7980VulkanDeviceAllocator *GetAllocator() { return allocator_; }8182std::vector<std::string> DebugGetSamplerIDs() const;83std::string DebugGetSamplerString(const std::string &id, DebugShaderStringType stringType);8485protected:86void BindTexture(TexCacheEntry *entry) override;87void Unbind() override;88void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;89void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;90void ApplySamplingParams(const SamplerCacheKey &key) override;91void BoundFramebufferTexture() override;92void *GetNativeTextureView(const TexCacheEntry *entry) override;9394private:95void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);96static VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) ;97void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;9899void BuildTexture(TexCacheEntry *const entry) override;100101void CompileScalingShader();102103VulkanDeviceAllocator *allocator_ = nullptr;104105VulkanComputeShaderManager computeShaderManager_;106107SamplerCache samplerCache_;108109DrawEngineVulkan *drawEngine_;110111std::string textureShader_;112VkShaderModule uploadCS_ = VK_NULL_HANDLE;113114// Bound state to emulate an API similar to the others115VkImageView imageView_ = VK_NULL_HANDLE;116VkSampler curSampler_ = VK_NULL_HANDLE;117118VkSampler samplerNearest_ = VK_NULL_HANDLE;119};120121VkFormat getClutDestFormatVulkan(GEPaletteFormat format);122123124