2016-08-13 12:57:50 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2016-10-01 03:07:50 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "VideoBackends/Vulkan/StreamBuffer.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
|
|
|
|
namespace Vulkan
|
|
|
|
{
|
2016-11-19 13:25:23 +00:00
|
|
|
class TextureConverter;
|
2016-08-13 12:57:50 +00:00
|
|
|
class StateTracker;
|
|
|
|
class Texture2D;
|
|
|
|
|
|
|
|
class TextureCache : public TextureCacheBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct TCacheEntry : TCacheEntryBase
|
|
|
|
{
|
2016-10-22 10:50:36 +00:00
|
|
|
TCacheEntry(const TCacheEntryConfig& config_, std::unique_ptr<Texture2D> texture,
|
|
|
|
VkFramebuffer framebuffer);
|
2016-08-13 12:57:50 +00:00
|
|
|
~TCacheEntry();
|
|
|
|
|
|
|
|
Texture2D* GetTexture() const { return m_texture.get(); }
|
|
|
|
VkFramebuffer GetFramebuffer() const { return m_framebuffer; }
|
2017-04-16 09:45:22 +00:00
|
|
|
void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer,
|
|
|
|
size_t buffer_size) override;
|
2016-12-26 20:33:57 +00:00
|
|
|
void FromRenderTarget(bool is_depth_copy, const EFBRectangle& src_rect, bool scale_by_half,
|
|
|
|
unsigned int cbufid, const float* colmat) override;
|
2016-08-13 12:57:50 +00:00
|
|
|
void CopyRectangleFromTexture(const TCacheEntryBase* source,
|
|
|
|
const MathUtil::Rectangle<int>& src_rect,
|
|
|
|
const MathUtil::Rectangle<int>& dst_rect) override;
|
|
|
|
|
|
|
|
void Bind(unsigned int stage) override;
|
|
|
|
bool Save(const std::string& filename, unsigned int level) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<Texture2D> m_texture;
|
|
|
|
VkFramebuffer m_framebuffer;
|
|
|
|
};
|
|
|
|
|
2016-10-22 11:00:52 +00:00
|
|
|
TextureCache();
|
|
|
|
~TextureCache();
|
|
|
|
|
|
|
|
static TextureCache* GetInstance();
|
|
|
|
|
2016-11-19 14:43:50 +00:00
|
|
|
TextureConverter* GetTextureConverter() const { return m_texture_converter.get(); }
|
2016-10-22 11:00:52 +00:00
|
|
|
bool Initialize();
|
|
|
|
|
|
|
|
bool CompileShaders() override;
|
|
|
|
void DeleteShaders() override;
|
|
|
|
|
2016-08-13 12:57:50 +00:00
|
|
|
TCacheEntryBase* CreateTexture(const TCacheEntryConfig& config) override;
|
|
|
|
|
2016-10-22 11:00:52 +00:00
|
|
|
void ConvertTexture(TCacheEntryBase* base_entry, TCacheEntryBase* base_unconverted, void* palette,
|
|
|
|
TlutFormat format) override;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2017-04-04 13:55:36 +00:00
|
|
|
void CopyEFB(u8* dst, const EFBCopyFormat& format, u32 native_width, u32 bytes_per_row,
|
|
|
|
u32 num_blocks_y, u32 memory_stride, bool is_depth_copy,
|
|
|
|
const EFBRectangle& src_rect, bool scale_by_half) override;
|
2016-10-22 11:00:52 +00:00
|
|
|
|
2016-10-22 11:19:09 +00:00
|
|
|
void CopyRectangleFromTexture(TCacheEntry* dst_texture, const MathUtil::Rectangle<int>& dst_rect,
|
|
|
|
Texture2D* src_texture, const MathUtil::Rectangle<int>& src_rect);
|
|
|
|
|
2016-12-09 12:23:07 +00:00
|
|
|
bool SupportsGPUTextureDecode(TextureFormat format, TlutFormat palette_format) override;
|
|
|
|
|
|
|
|
void DecodeTextureOnGPU(TCacheEntryBase* entry, u32 dst_level, const u8* data, size_t data_size,
|
|
|
|
TextureFormat format, u32 width, u32 height, u32 aligned_width,
|
|
|
|
u32 aligned_height, u32 row_stride, const u8* palette,
|
|
|
|
TlutFormat palette_format) override;
|
|
|
|
|
2016-10-22 11:00:52 +00:00
|
|
|
private:
|
|
|
|
bool CreateRenderPasses();
|
2016-08-13 12:57:50 +00:00
|
|
|
|
2016-10-22 11:19:09 +00:00
|
|
|
// Copies the contents of a texture using vkCmdCopyImage
|
|
|
|
void CopyTextureRectangle(TCacheEntry* dst_texture, const MathUtil::Rectangle<int>& dst_rect,
|
|
|
|
Texture2D* src_texture, const MathUtil::Rectangle<int>& src_rect);
|
|
|
|
|
|
|
|
// Copies (and optionally scales) the contents of a texture using a framgent shader.
|
|
|
|
void ScaleTextureRectangle(TCacheEntry* dst_texture, const MathUtil::Rectangle<int>& dst_rect,
|
|
|
|
Texture2D* src_texture, const MathUtil::Rectangle<int>& src_rect);
|
|
|
|
|
2016-11-20 15:59:19 +00:00
|
|
|
VkRenderPass m_render_pass = VK_NULL_HANDLE;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
std::unique_ptr<StreamBuffer> m_texture_upload_buffer;
|
|
|
|
|
2016-11-19 13:25:23 +00:00
|
|
|
std::unique_ptr<TextureConverter> m_texture_converter;
|
2016-08-13 12:57:50 +00:00
|
|
|
|
|
|
|
VkShaderModule m_copy_shader = VK_NULL_HANDLE;
|
|
|
|
VkShaderModule m_efb_color_to_tex_shader = VK_NULL_HANDLE;
|
|
|
|
VkShaderModule m_efb_depth_to_tex_shader = VK_NULL_HANDLE;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|