VideoCommon: Move abstract texture creation function to Renderer

This commit is contained in:
Stenzek 2017-09-30 16:25:36 +10:00
parent 5860c97144
commit 49a9c33bd7
24 changed files with 49 additions and 36 deletions

View File

@ -211,6 +211,11 @@ void Renderer::Create3DVisionTexture(int width, int height)
DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, &sys_data); DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, &sys_data);
} }
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<DXTexture>(config);
}
void Renderer::RenderText(const std::string& text, int left, int top, u32 color) void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{ {
D3D::DrawTextScaled(static_cast<float>(left + 1), static_cast<float>(top + 1), 20.f, 0.0f, D3D::DrawTextScaled(static_cast<float>(left + 1), static_cast<float>(top + 1), 20.f, 0.0f,

View File

@ -22,6 +22,8 @@ public:
~Renderer() override; ~Renderer() override;
StateCache& GetStateCache() { return m_state_cache; } StateCache& GetStateCache() { return m_state_cache; }
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void SetBlendingState(const BlendingState& state) override; void SetBlendingState(const BlendingState& state) override;
void SetScissorRect(const EFBRectangle& rc) override; void SetScissorRect(const EFBRectangle& rc) override;
void SetRasterizationState(const RasterizationState& state) override; void SetRasterizationState(const RasterizationState& state) override;

View File

@ -33,11 +33,6 @@ static const size_t MAX_COPY_BUFFERS = 32;
static ID3D11Buffer* s_efbcopycbuf[MAX_COPY_BUFFERS] = {0}; static ID3D11Buffer* s_efbcopycbuf[MAX_COPY_BUFFERS] = {0};
static std::unique_ptr<PSTextureEncoder> g_encoder; static std::unique_ptr<PSTextureEncoder> g_encoder;
std::unique_ptr<AbstractTexture> TextureCache::CreateTexture(const TextureConfig& config)
{
return std::make_unique<DXTexture>(config);
}
void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width, void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width,
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
const EFBRectangle& src_rect, bool scale_by_half) const EFBRectangle& src_rect, bool scale_by_half)

View File

@ -19,8 +19,6 @@ public:
~TextureCache(); ~TextureCache();
private: private:
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH, u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH,
bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf,
const EFBRectangle& source) const EFBRectangle& source)

View File

@ -4,6 +4,7 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "VideoBackends/Null/NullTexture.h"
#include "VideoBackends/Null/Render.h" #include "VideoBackends/Null/Render.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
@ -21,6 +22,11 @@ Renderer::~Renderer()
UpdateActiveConfig(); UpdateActiveConfig();
} }
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<NullTexture>(config);
}
void Renderer::RenderText(const std::string& text, int left, int top, u32 color) void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{ {
NOTICE_LOG(VIDEO, "RenderText: %s", text.c_str()); NOTICE_LOG(VIDEO, "RenderText: %s", text.c_str());

View File

@ -14,6 +14,8 @@ public:
Renderer(); Renderer();
~Renderer() override; ~Renderer() override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void RenderText(const std::string& pstr, int left, int top, u32 color) override; void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; } u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {} void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}

View File

@ -35,12 +35,6 @@ public:
bool scale_by_half, unsigned int cbuf_id, const float* colmat) override bool scale_by_half, unsigned int cbuf_id, const float* colmat) override
{ {
} }
private:
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override
{
return std::make_unique<NullTexture>(config);
}
}; };
} // Null name space } // Null name space

View File

@ -9,7 +9,6 @@
#include "VideoBackends/OGL/FramebufferManager.h" #include "VideoBackends/OGL/FramebufferManager.h"
#include "VideoBackends/OGL/OGLTexture.h" #include "VideoBackends/OGL/OGLTexture.h"
#include "VideoBackends/OGL/Render.h"
#include "VideoBackends/OGL/SamplerCache.h" #include "VideoBackends/OGL/SamplerCache.h"
#include "VideoBackends/OGL/TextureCache.h" #include "VideoBackends/OGL/TextureCache.h"

View File

@ -814,6 +814,11 @@ void Renderer::Init()
OpenGL_CreateAttributelessVAO(); OpenGL_CreateAttributelessVAO();
} }
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<OGLTexture>(config);
}
void Renderer::RenderText(const std::string& text, int left, int top, u32 color) void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{ {
u32 backbuffer_width = std::max(GLInterface->GetBackBufferWidth(), 1u); u32 backbuffer_width = std::max(GLInterface->GetBackBufferWidth(), 1u);

View File

@ -77,6 +77,8 @@ public:
void Init(); void Init();
void Shutdown(); void Shutdown();
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void SetBlendingState(const BlendingState& state) override; void SetBlendingState(const BlendingState& state) override;
void SetScissorRect(const EFBRectangle& rc) override; void SetScissorRect(const EFBRectangle& rc) override;
void SetRasterizationState(const RasterizationState& state) override; void SetRasterizationState(const RasterizationState& state) override;

View File

@ -33,11 +33,6 @@ namespace OGL
{ {
//#define TIME_TEXTURE_DECODING 1 //#define TIME_TEXTURE_DECODING 1
std::unique_ptr<AbstractTexture> TextureCache::CreateTexture(const TextureConfig& config)
{
return std::make_unique<OGLTexture>(config);
}
void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width, void TextureCache::CopyEFB(u8* dst, const EFBCopyParams& params, u32 native_width,
u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride, u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
const EFBRectangle& src_rect, bool scale_by_half) const EFBRectangle& src_rect, bool scale_by_half)

View File

@ -59,7 +59,6 @@ private:
bool valid = false; bool valid = false;
}; };
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette, void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
TLUTFormat format) override; TLUTFormat format) override;

View File

@ -14,6 +14,7 @@
#include "VideoBackends/Software/EfbCopy.h" #include "VideoBackends/Software/EfbCopy.h"
#include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/SWOGLWindow.h" #include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/BoundingBox.h" #include "VideoCommon/BoundingBox.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
@ -34,6 +35,11 @@ void SWRenderer::Shutdown()
UpdateActiveConfig(); UpdateActiveConfig();
} }
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<SW::SWTexture>(config);
}
void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 color) void SWRenderer::RenderText(const std::string& pstr, int left, int top, u32 color)
{ {
SWOGLWindow::s_instance->PrintText(pstr, left, top, color); SWOGLWindow::s_instance->PrintText(pstr, left, top, color);

View File

@ -16,6 +16,8 @@ public:
static void Init(); static void Init();
static void Shutdown(); static void Shutdown();
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void RenderText(const std::string& pstr, int left, int top, u32 color) override; void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override; u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {} void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}

View File

@ -25,11 +25,6 @@ public:
} }
private: private:
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override
{
return std::make_unique<SWTexture>(config);
}
void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect, void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect,
bool scale_by_half, unsigned int cbuf_id, const float* colmat) override bool scale_by_half, unsigned int cbuf_id, const float* colmat) override
{ {

View File

@ -159,6 +159,11 @@ void Renderer::DestroySemaphores()
} }
} }
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return VKTexture::Create(config);
}
void Renderer::RenderText(const std::string& text, int left, int top, u32 color) void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{ {
u32 backbuffer_width = m_swap_chain->GetWidth(); u32 backbuffer_width = m_swap_chain->GetWidth();

View File

@ -32,6 +32,8 @@ public:
static Renderer* GetInstance(); static Renderer* GetInstance();
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
SwapChain* GetSwapChain() const { return m_swap_chain.get(); } SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); } BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); }
bool Initialize(); bool Initialize();

View File

@ -178,11 +178,6 @@ void TextureCache::DecodeTextureOnGPU(TCacheEntry* entry, u32 dst_level, const u
} }
} }
std::unique_ptr<AbstractTexture> TextureCache::CreateTexture(const TextureConfig& config)
{
return VKTexture::Create(config);
}
bool TextureCache::CreateRenderPasses() bool TextureCache::CreateRenderPasses()
{ {
static constexpr VkAttachmentDescription update_attachment = { static constexpr VkAttachmentDescription update_attachment = {

View File

@ -31,8 +31,6 @@ public:
bool CompileShaders() override; bool CompileShaders() override;
void DeleteShaders() override; void DeleteShaders() override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette, void ConvertTexture(TCacheEntry* destination, TCacheEntry* source, const void* palette,
TLUTFormat format) override; TLUTFormat format) override;

View File

@ -731,7 +731,7 @@ void Renderer::UpdateFrameDumpTexture()
config.width = target_width; config.width = target_width;
config.height = target_height; config.height = target_height;
config.rendertarget = true; config.rendertarget = true;
m_dump_texture = g_texture_cache->CreateTexture(config); m_dump_texture = CreateTexture(config);
} }
m_dump_texture->CopyRectangleFromTexture(m_last_xfb_texture, m_last_xfb_region, m_dump_texture->CopyRectangleFromTexture(m_last_xfb_texture, m_last_xfb_region,
EFBRectangle{0, 0, target_width, target_height}); EFBRectangle{0, 0, target_width, target_height});

View File

@ -35,6 +35,7 @@
class AbstractRawTexture; class AbstractRawTexture;
class AbstractTexture; class AbstractTexture;
class PostProcessingShaderImplementation; class PostProcessingShaderImplementation;
struct TextureConfig;
enum class EFBAccessType; enum class EFBAccessType;
struct EfbPokeData struct EfbPokeData
@ -79,6 +80,8 @@ public:
virtual void RestoreState() {} virtual void RestoreState() {}
virtual void ResetAPIState() {} virtual void ResetAPIState() {}
virtual void RestoreAPIState() {} virtual void RestoreAPIState() {}
virtual std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) = 0;
// Ideal internal resolution - multiple of the native EFB resolution // Ideal internal resolution - multiple of the native EFB resolution
int GetTargetWidth() const { return m_target_width; } int GetTargetWidth() const { return m_target_width; }
int GetTargetHeight() const { return m_target_height; } int GetTargetHeight() const { return m_target_height; }

View File

@ -2090,7 +2090,7 @@ std::unique_ptr<AbstractTexture> TextureCacheBase::AllocateTexture(const Texture
} }
else else
{ {
entry = CreateTexture(config); entry = g_renderer->CreateTexture(config);
if (!entry) if (!entry)
return nullptr; return nullptr;

View File

@ -273,8 +273,6 @@ public:
void ScaleTextureCacheEntryTo(TCacheEntry* entry, u32 new_width, u32 new_height); void ScaleTextureCacheEntryTo(TCacheEntry* entry, u32 new_width, u32 new_height);
virtual std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) = 0;
protected: protected:
TextureCacheBase(); TextureCacheBase();

View File

@ -22,6 +22,13 @@ enum class AbstractTextureFormat : u32
struct TextureConfig struct TextureConfig
{ {
constexpr TextureConfig() = default; constexpr TextureConfig() = default;
constexpr TextureConfig(u32 width_, u32 height_, u32 levels_, u32 layers_,
AbstractTextureFormat format_, bool rendertarget_)
: width(width_), height(height_), levels(levels_), layers(layers_), format(format_),
rendertarget(rendertarget_)
{
}
bool operator==(const TextureConfig& o) const; bool operator==(const TextureConfig& o) const;
MathUtil::Rectangle<int> GetRect() const; MathUtil::Rectangle<int> GetRect() const;