2015-10-10 14:41:19 +00: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
|
|
|
|
|
2016-01-03 22:09:37 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "GPU/GPUInterface.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/GPUState.h"
|
2016-02-21 19:21:24 +00:00
|
|
|
#include "Common/Vulkan/VulkanContext.h"
|
2016-01-03 22:09:37 +00:00
|
|
|
#include "GPU/Vulkan/TextureScalerVulkan.h"
|
|
|
|
#include "GPU/Common/TextureCacheCommon.h"
|
|
|
|
|
|
|
|
struct VirtualFramebuffer;
|
|
|
|
class FramebufferManagerVulkan;
|
|
|
|
class DepalShaderCacheVulkan;
|
|
|
|
class ShaderManagerVulkan;
|
|
|
|
class DrawEngineVulkan;
|
|
|
|
|
|
|
|
class VulkanContext;
|
2016-03-17 10:56:43 +00:00
|
|
|
class VulkanTexture;
|
2016-03-20 08:35:10 +00:00
|
|
|
class VulkanPushBuffer;
|
2016-01-09 00:23:32 +00:00
|
|
|
|
|
|
|
struct SamplerCacheKey {
|
2016-01-09 20:19:18 +00:00
|
|
|
SamplerCacheKey() : fullKey(0) {}
|
|
|
|
|
|
|
|
union {
|
|
|
|
u32 fullKey;
|
|
|
|
struct {
|
|
|
|
bool mipEnable : 1;
|
|
|
|
bool minFilt : 1;
|
|
|
|
bool mipFilt : 1;
|
|
|
|
bool magFilt : 1;
|
|
|
|
bool sClamp : 1;
|
|
|
|
bool tClamp : 1;
|
|
|
|
int lodBias : 4;
|
|
|
|
int maxLevel : 4;
|
|
|
|
};
|
|
|
|
};
|
2016-01-09 00:23:32 +00:00
|
|
|
|
|
|
|
bool operator < (const SamplerCacheKey &other) const {
|
2016-01-09 20:19:18 +00:00
|
|
|
return fullKey < other.fullKey;
|
2016-01-09 00:23:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-09 10:07:14 +00:00
|
|
|
class CachedTextureVulkan {
|
|
|
|
public:
|
2016-01-09 20:19:18 +00:00
|
|
|
CachedTextureVulkan() : texture_(nullptr) {
|
|
|
|
}
|
2016-03-17 10:56:43 +00:00
|
|
|
~CachedTextureVulkan();
|
|
|
|
|
2016-01-09 20:19:18 +00:00
|
|
|
// TODO: Switch away from VulkanImage to some kind of smart suballocating texture pool.
|
|
|
|
VulkanTexture *texture_;
|
2016-01-09 10:07:14 +00:00
|
|
|
};
|
2016-01-09 00:23:32 +00:00
|
|
|
|
|
|
|
class SamplerCache {
|
|
|
|
public:
|
|
|
|
SamplerCache(VulkanContext *vulkan) : vulkan_(vulkan) {}
|
|
|
|
~SamplerCache();
|
|
|
|
VkSampler GetOrCreateSampler(const SamplerCacheKey &key);
|
2016-01-09 10:07:14 +00:00
|
|
|
|
2016-01-09 00:23:32 +00:00
|
|
|
private:
|
|
|
|
VulkanContext *vulkan_;
|
|
|
|
std::map<SamplerCacheKey, VkSampler> cache_;
|
|
|
|
};
|
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
class TextureCacheVulkan : public TextureCacheCommon {
|
|
|
|
public:
|
2016-01-03 22:09:37 +00:00
|
|
|
TextureCacheVulkan(VulkanContext *vulkan);
|
|
|
|
~TextureCacheVulkan();
|
|
|
|
|
2016-03-14 22:25:00 +00:00
|
|
|
void SetTexture(VulkanPushBuffer *uploadBuffer);
|
2016-01-03 22:09:37 +00:00
|
|
|
virtual bool SetOffsetTexture(u32 offset) override;
|
|
|
|
|
|
|
|
void Clear(bool delete_them);
|
|
|
|
void StartFrame();
|
|
|
|
void Invalidate(u32 addr, int size, GPUInvalidationType type);
|
|
|
|
void InvalidateAll(GPUInvalidationType type);
|
|
|
|
void ClearNextFrame();
|
|
|
|
|
|
|
|
void SetFramebufferManager(FramebufferManagerVulkan *fbManager) {
|
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
|
|
|
void SetDepalShaderCache(DepalShaderCacheVulkan *dpCache) {
|
|
|
|
depalShaderCache_ = dpCache;
|
|
|
|
}
|
|
|
|
void SetShaderManager(ShaderManagerVulkan *sm) {
|
|
|
|
shaderManager_ = sm;
|
|
|
|
}
|
|
|
|
void SetTransformDrawEngine(DrawEngineVulkan *td) {
|
|
|
|
transformDraw_ = td;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t NumLoadedTextures() const {
|
|
|
|
return cache.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForgetLastTexture() {
|
|
|
|
lastBoundTexture = nullptr;
|
|
|
|
gstate_c.textureChanged |= TEXCHANGE_PARAMSONLY;
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
2016-01-03 22:09:37 +00:00
|
|
|
|
|
|
|
void ApplyTexture(VkImageView &imageView, VkSampler &sampler);
|
|
|
|
|
2016-01-06 22:08:26 +00:00
|
|
|
protected:
|
|
|
|
void DownloadFramebufferForClut(u32 clutAddr, u32 bytes);
|
2016-01-03 22:09:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Decimate(); // Run this once per frame to get rid of old textures.
|
|
|
|
void DeleteTexture(TexCache::iterator it);
|
|
|
|
void *ReadIndexedTex(int level, const u8 *texptr, int bytesPerIndex, VkFormat dstFmt, int bufw);
|
2016-01-09 20:19:18 +00:00
|
|
|
void UpdateSamplingParams(TexCacheEntry &entry, SamplerCacheKey &key);
|
2016-03-14 22:25:00 +00:00
|
|
|
void LoadTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, bool replaceImages, int scaleFactor, VkFormat dstFmt);
|
2016-01-03 22:09:37 +00:00
|
|
|
VkFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
|
2016-03-26 20:33:18 +00:00
|
|
|
void *DecodeTextureLevel(u8 *out, int outPitch, GETextureFormat format, GEPaletteFormat clutformat, uint32_t texaddr, int level, VkFormat dstFmt, int scaleFactor, int bufw);
|
2016-01-03 22:09:37 +00:00
|
|
|
TexCacheEntry::Status CheckAlpha(const u32 *pixelData, VkFormat dstFmt, int stride, int w, int h);
|
|
|
|
template <typename T>
|
|
|
|
const T *GetCurrentClut();
|
|
|
|
u32 GetCurrentClutHash();
|
|
|
|
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple);
|
2016-01-02 23:46:41 +00:00
|
|
|
bool AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, u32 texaddrOffset = 0) override;
|
2016-01-03 22:09:37 +00:00
|
|
|
void SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer);
|
|
|
|
void ApplyTextureFramebuffer(VkCommandBuffer cmd, TexCacheEntry *entry, VirtualFramebuffer *framebuffer, VkImageView &image, VkSampler &sampler);
|
|
|
|
void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key);
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-03 22:09:37 +00:00
|
|
|
VulkanContext *vulkan_;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-03 22:09:37 +00:00
|
|
|
TexCache secondCache;
|
|
|
|
u32 secondCacheSizeEstimate_;
|
|
|
|
|
|
|
|
bool clearCacheNextFrame_;
|
|
|
|
bool lowMemoryMode_;
|
|
|
|
|
2016-01-09 00:23:32 +00:00
|
|
|
SamplerCache samplerCache_;
|
|
|
|
|
2016-01-03 22:09:37 +00:00
|
|
|
TextureScalerVulkan scaler;
|
|
|
|
|
|
|
|
u32 *clutBuf_;
|
|
|
|
u32 clutHash_;
|
|
|
|
// True if the clut is just alpha values in the same order (RGBA4444-bit only.)
|
|
|
|
bool clutAlphaLinear_;
|
|
|
|
u16 clutAlphaLinearColor_;
|
|
|
|
|
|
|
|
CachedTextureVulkan *lastBoundTexture;
|
|
|
|
|
|
|
|
int decimationCounter_;
|
|
|
|
int texelsScaledThisFrame_;
|
|
|
|
int timesInvalidatedAllThisFrame_;
|
|
|
|
|
|
|
|
FramebufferManagerVulkan *framebufferManager_;
|
|
|
|
DepalShaderCacheVulkan *depalShaderCache_;
|
|
|
|
ShaderManagerVulkan *shaderManager_;
|
|
|
|
DrawEngineVulkan *transformDraw_;
|
2015-10-10 14:41:19 +00:00
|
|
|
};
|
2016-01-03 22:09:37 +00:00
|
|
|
|
|
|
|
VkFormat getClutDestFormatVulkan(GEPaletteFormat format);
|