From e03b8e899e14a2a57bf32ad539f7f987edc5b24c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 19 Jan 2019 00:27:09 +1000 Subject: [PATCH] Vulkan: Move texture upload buffer to ObjectCache --- Source/Core/VideoBackends/Vulkan/ObjectCache.cpp | 9 +++++++++ Source/Core/VideoBackends/Vulkan/ObjectCache.h | 2 ++ Source/Core/VideoBackends/Vulkan/TextureCache.cpp | 14 -------------- Source/Core/VideoBackends/Vulkan/TextureCache.h | 3 --- Source/Core/VideoBackends/Vulkan/VKTexture.cpp | 2 +- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp index 8f5721b4d3..1de68b8349 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.cpp @@ -54,6 +54,15 @@ bool ObjectCache::Initialize() if (!CreateStaticSamplers()) return false; + m_texture_upload_buffer = + StreamBuffer::Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, INITIAL_TEXTURE_UPLOAD_BUFFER_SIZE, + MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE); + if (!m_texture_upload_buffer) + { + PanicAlert("Failed to create texture upload buffer"); + return false; + } + m_utility_shader_vertex_buffer = StreamBuffer::Create(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, 1024 * 1024, 4 * 1024 * 1024); m_utility_shader_uniform_buffer = diff --git a/Source/Core/VideoBackends/Vulkan/ObjectCache.h b/Source/Core/VideoBackends/Vulkan/ObjectCache.h index 5b7939f95b..c3502f7c66 100644 --- a/Source/Core/VideoBackends/Vulkan/ObjectCache.h +++ b/Source/Core/VideoBackends/Vulkan/ObjectCache.h @@ -58,6 +58,7 @@ public: { return m_utility_shader_uniform_buffer.get(); } + StreamBuffer* GetTextureUploadBuffer() const { return m_texture_upload_buffer.get(); } // Static samplers VkSampler GetPointSampler() const { return m_point_sampler; } @@ -94,6 +95,7 @@ private: std::unique_ptr m_utility_shader_vertex_format; std::unique_ptr m_utility_shader_vertex_buffer; std::unique_ptr m_utility_shader_uniform_buffer; + std::unique_ptr m_texture_upload_buffer; VkSampler m_point_sampler = VK_NULL_HANDLE; VkSampler m_linear_sampler = VK_NULL_HANDLE; diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp index e9b92ba1e1..3f26b28a7c 100644 --- a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp @@ -45,11 +45,6 @@ VkShaderModule TextureCache::GetCopyShader() const return m_copy_shader; } -StreamBuffer* TextureCache::GetTextureUploadBuffer() const -{ - return m_texture_upload_buffer.get(); -} - TextureCache* TextureCache::GetInstance() { return static_cast(g_texture_cache.get()); @@ -57,15 +52,6 @@ TextureCache* TextureCache::GetInstance() bool TextureCache::Initialize() { - m_texture_upload_buffer = - StreamBuffer::Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, INITIAL_TEXTURE_UPLOAD_BUFFER_SIZE, - MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE); - if (!m_texture_upload_buffer) - { - PanicAlert("Failed to create texture upload buffer"); - return false; - } - m_texture_converter = std::make_unique(); if (!m_texture_converter->Initialize()) { diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.h b/Source/Core/VideoBackends/Vulkan/TextureCache.h index fd6b57981a..35b3b6c360 100644 --- a/Source/Core/VideoBackends/Vulkan/TextureCache.h +++ b/Source/Core/VideoBackends/Vulkan/TextureCache.h @@ -49,7 +49,6 @@ public: TLUTFormat palette_format) override; VkShaderModule GetCopyShader() const; - StreamBuffer* GetTextureUploadBuffer() const; private: void CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, const EFBRectangle& src_rect, @@ -57,8 +56,6 @@ private: float gamma, bool clamp_top, bool clamp_bottom, const CopyFilterCoefficientArray& filter_coefficients) override; - std::unique_ptr m_texture_upload_buffer; - std::unique_ptr m_texture_converter; VkShaderModule m_copy_shader = VK_NULL_HANDLE; diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index 304c5cc908..929307edb3 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -290,7 +290,7 @@ void VKTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* if (upload_size <= STAGING_TEXTURE_UPLOAD_THRESHOLD && upload_size <= MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE) { - StreamBuffer* stream_buffer = TextureCache::GetInstance()->GetTextureUploadBuffer(); + StreamBuffer* stream_buffer = g_object_cache->GetTextureUploadBuffer(); if (!stream_buffer->ReserveMemory(upload_size, upload_alignment)) { // Execute the command buffer first.