diff options
| author | Stenzek <stenzek@gmail.com> | 2016-10-22 20:50:36 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2016-11-03 22:01:54 +1000 |
| commit | b066d51dfa03b960028fc6f88c8de133eb6db1da (patch) | |
| tree | f35267e1877f00694e726e6939a14311f7df35d0 /Source/Core/VideoBackends/Vulkan/TextureCache.cpp | |
| parent | ab9f539233172b9266745ec266d345966e8c6207 (diff) | |
Vulkan: Remove parameters/members of single-instance classes
There's not a lot of point in passing these around or storing them
(texture cache/state tracker mainly) as there will only ever be a single
instance of the class.
Also adds downcast helpers such as Vulkan::Renderer::GetInstance().
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/TextureCache.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/TextureCache.cpp | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp index 60790c687f..9795492d5a 100644 --- a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp @@ -44,9 +44,13 @@ TextureCache::~TextureCache() TextureCache::DeleteShaders(); } -bool TextureCache::Initialize(StateTracker* state_tracker) +TextureCache* TextureCache::GetInstance() +{ + return static_cast<TextureCache*>(g_texture_cache.get()); +} + +bool TextureCache::Initialize() { - m_state_tracker = state_tracker; m_texture_upload_buffer = StreamBuffer::Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, INITIAL_TEXTURE_UPLOAD_BUFFER_SIZE, MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE); @@ -99,8 +103,8 @@ void TextureCache::ConvertTexture(TCacheEntryBase* base_entry, TCacheEntryBase* if (unconverted->IsEfbCopy()) { command_buffer = g_command_buffer_mgr->GetCurrentCommandBuffer(); - m_state_tracker->EndRenderPass(); - m_state_tracker->SetPendingRebind(); + StateTracker::GetInstance()->EndRenderPass(); + StateTracker::GetInstance()->SetPendingRebind(); } else { @@ -109,9 +113,9 @@ void TextureCache::ConvertTexture(TCacheEntryBase* base_entry, TCacheEntryBase* } m_palette_texture_converter->ConvertTexture( - m_state_tracker, command_buffer, GetRenderPassForTextureUpdate(entry->GetTexture()), - entry->GetFramebuffer(), unconverted->GetTexture(), entry->config.width, entry->config.height, - palette, format, unconverted->format); + command_buffer, GetRenderPassForTextureUpdate(entry->GetTexture()), entry->GetFramebuffer(), + unconverted->GetTexture(), entry->config.width, entry->config.height, palette, format, + unconverted->format); // Render pass transitions to SHADER_READ_ONLY. entry->GetTexture()->OverrideImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); @@ -121,12 +125,8 @@ void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_ u32 num_blocks_y, u32 memory_stride, PEControl::PixelFormat src_format, const EFBRectangle& src_rect, bool is_intensity, bool scale_by_half) { - // A better way of doing this would be nice. - FramebufferManager* framebuffer_mgr = - static_cast<FramebufferManager*>(g_framebuffer_manager.get()); - // Flush EFB pokes first, as they're expected to be included. - framebuffer_mgr->FlushEFBPokes(m_state_tracker); + FramebufferManager::GetInstance()->FlushEFBPokes(); // MSAA case where we need to resolve first. // TODO: Do in one pass. @@ -134,24 +134,26 @@ void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_ VkRect2D region = {{scaled_src_rect.left, scaled_src_rect.top}, {static_cast<u32>(scaled_src_rect.GetWidth()), static_cast<u32>(scaled_src_rect.GetHeight())}}; - Texture2D* src_texture = (src_format == PEControl::Z24) ? - framebuffer_mgr->ResolveEFBDepthTexture(m_state_tracker, region) : - framebuffer_mgr->ResolveEFBColorTexture(m_state_tracker, region); + Texture2D* src_texture; + if (src_format == PEControl::Z24) + src_texture = FramebufferManager::GetInstance()->ResolveEFBDepthTexture(region); + else + src_texture = FramebufferManager::GetInstance()->ResolveEFBColorTexture(region); // End render pass before barrier (since we have no self-dependencies) - m_state_tracker->EndRenderPass(); - m_state_tracker->SetPendingRebind(); - m_state_tracker->InvalidateDescriptorSets(); - m_state_tracker->OnReadback(); + StateTracker::GetInstance()->EndRenderPass(); + StateTracker::GetInstance()->SetPendingRebind(); + StateTracker::GetInstance()->InvalidateDescriptorSets(); + StateTracker::GetInstance()->OnReadback(); // Transition to shader resource before reading. VkImageLayout original_layout = src_texture->GetLayout(); src_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - m_texture_encoder->EncodeTextureToRam(m_state_tracker, src_texture->GetView(), dst, format, - native_width, bytes_per_row, num_blocks_y, memory_stride, - src_format, is_intensity, scale_by_half, src_rect); + m_texture_encoder->EncodeTextureToRam(src_texture->GetView(), dst, format, native_width, + bytes_per_row, num_blocks_y, memory_stride, src_format, + is_intensity, scale_by_half, src_rect); // Transition back to original state src_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), original_layout); @@ -207,7 +209,7 @@ TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntry texture->GetLayout(), &clear_value, 1, &clear_range); } - return new TCacheEntry(config, this, std::move(texture), framebuffer); + return new TCacheEntry(config, std::move(texture), framebuffer); } bool TextureCache::CreateRenderPasses() @@ -319,20 +321,17 @@ VkRenderPass TextureCache::GetRenderPassForTextureUpdate(const Texture2D* textur return m_update_render_pass; } -TextureCache::TCacheEntry::TCacheEntry(const TCacheEntryConfig& config_, TextureCache* parent, +TextureCache::TCacheEntry::TCacheEntry(const TCacheEntryConfig& config_, std::unique_ptr<Texture2D> texture, VkFramebuffer framebuffer) - : TCacheEntryBase(config_), m_parent(parent), m_texture(std::move(texture)), - m_framebuffer(framebuffer) + : TCacheEntryBase(config_), m_texture(std::move(texture)), m_framebuffer(framebuffer) { } TextureCache::TCacheEntry::~TCacheEntry() { - // Texture is automatically cleaned up, however, we don't want to leave it bound to the state - // tracker. - m_parent->m_state_tracker->UnbindTexture(m_texture->GetView()); - + // Texture is automatically cleaned up, however, we don't want to leave it bound. + StateTracker::GetInstance()->UnbindTexture(m_texture->GetView()); if (m_framebuffer != VK_NULL_HANDLE) g_command_buffer_mgr->DeferFramebufferDestruction(m_framebuffer); } @@ -376,14 +375,14 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height, (upload_size + upload_alignment) <= MAXIMUM_TEXTURE_UPLOAD_BUFFER_SIZE) { // Assume tightly packed rows, with no padding as the buffer source. - StreamBuffer* upload_buffer = m_parent->m_texture_upload_buffer.get(); + StreamBuffer* upload_buffer = TextureCache::GetInstance()->m_texture_upload_buffer.get(); // Allocate memory from the streaming buffer for the texture data. if (!upload_buffer->ReserveMemory(upload_size, g_vulkan_context->GetBufferImageGranularity())) { // Execute the command buffer first. WARN_LOG(VIDEO, "Executing command list while waiting for space in texture upload buffer"); - Util::ExecuteCurrentCommandsAndRestoreState(m_parent->m_state_tracker, false); + Util::ExecuteCurrentCommandsAndRestoreState(false); // Try allocating again. This may cause a fence wait. if (!upload_buffer->ReserveMemory(upload_size, g_vulkan_context->GetBufferImageGranularity())) @@ -470,23 +469,25 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat bool is_depth_copy = (src_format == PEControl::Z24); // Flush EFB pokes first, as they're expected to be included. - framebuffer_mgr->FlushEFBPokes(m_parent->m_state_tracker); + framebuffer_mgr->FlushEFBPokes(); // Has to be flagged as a render target. _assert_(m_framebuffer != VK_NULL_HANDLE); // Can't be done in a render pass, since we're doing our own render pass! - StateTracker* state_tracker = m_parent->m_state_tracker; VkCommandBuffer command_buffer = g_command_buffer_mgr->GetCurrentCommandBuffer(); - state_tracker->EndRenderPass(); + StateTracker::GetInstance()->EndRenderPass(); // Transition EFB to shader resource before binding VkRect2D region = {{scaled_src_rect.left, scaled_src_rect.top}, {static_cast<u32>(scaled_src_rect.GetWidth()), static_cast<u32>(scaled_src_rect.GetHeight())}}; - Texture2D* src_texture = is_depth_copy ? - framebuffer_mgr->ResolveEFBDepthTexture(state_tracker, region) : - framebuffer_mgr->ResolveEFBColorTexture(state_tracker, region); + Texture2D* src_texture; + if (is_depth_copy) + src_texture = FramebufferManager::GetInstance()->ResolveEFBDepthTexture(region); + else + src_texture = FramebufferManager::GetInstance()->ResolveEFBColorTexture(region); + VkSampler src_sampler = scale_by_half ? g_object_cache->GetLinearSampler() : g_object_cache->GetPointSampler(); VkImageLayout original_layout = src_texture->GetLayout(); @@ -494,9 +495,10 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat UtilityShaderDraw draw( command_buffer, g_object_cache->GetPushConstantPipelineLayout(), - m_parent->GetRenderPassForTextureUpdate(m_texture.get()), + TextureCache::GetInstance()->GetRenderPassForTextureUpdate(m_texture.get()), g_object_cache->GetPassthroughVertexShader(), g_object_cache->GetPassthroughGeometryShader(), - is_depth_copy ? m_parent->m_efb_depth_to_tex_shader : m_parent->m_efb_color_to_tex_shader); + is_depth_copy ? TextureCache::GetInstance()->m_efb_depth_to_tex_shader : + TextureCache::GetInstance()->m_efb_color_to_tex_shader); draw.SetPushConstants(colmat, (is_depth_copy ? sizeof(float) * 20 : sizeof(float) * 28)); draw.SetPSSampler(0, src_texture->GetView(), src_sampler); @@ -512,7 +514,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat draw.EndRenderPass(); // We touched everything, so put it back. - state_tracker->SetPendingRebind(); + StateTracker::GetInstance()->SetPendingRebind(); // Transition the EFB back to its original layout. src_texture->TransitionToLayout(command_buffer, original_layout); @@ -553,7 +555,7 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture(const TCacheEntryBase* }; // Must be called outside of a render pass. - m_parent->m_state_tracker->EndRenderPass(); + StateTracker::GetInstance()->EndRenderPass(); source_vk->m_texture->TransitionToLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); m_texture->TransitionToLayout(command_buffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); @@ -569,8 +571,8 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture(const TCacheEntryBase* } // Can't do this within a game render pass. - m_parent->m_state_tracker->EndRenderPass(); - m_parent->m_state_tracker->SetPendingRebind(); + StateTracker::GetInstance()->EndRenderPass(); + StateTracker::GetInstance()->SetPendingRebind(); // Can't render to a non-rendertarget (no framebuffer). _assert_msg_(VIDEO, config.rendertarget, @@ -578,8 +580,9 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture(const TCacheEntryBase* UtilityShaderDraw draw( g_command_buffer_mgr->GetCurrentCommandBuffer(), g_object_cache->GetStandardPipelineLayout(), - m_parent->GetRenderPassForTextureUpdate(m_texture.get()), - g_object_cache->GetPassthroughVertexShader(), VK_NULL_HANDLE, m_parent->m_copy_shader); + TextureCache::GetInstance()->GetRenderPassForTextureUpdate(m_texture.get()), + g_object_cache->GetPassthroughVertexShader(), VK_NULL_HANDLE, + TextureCache::GetInstance()->m_copy_shader); VkRect2D region = { {dst_rect.left, dst_rect.top}, @@ -597,7 +600,7 @@ void TextureCache::TCacheEntry::CopyRectangleFromTexture(const TCacheEntryBase* void TextureCache::TCacheEntry::Bind(unsigned int stage) { - m_parent->m_state_tracker->SetTexture(stage, m_texture->GetView()); + StateTracker::GetInstance()->SetTexture(stage, m_texture->GetView()); } bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int level) @@ -617,7 +620,7 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l // since we'll be executing the command buffer. m_texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - m_parent->m_state_tracker->EndRenderPass(); + StateTracker::GetInstance()->EndRenderPass(); // Copy to download buffer. staging_texture->CopyFromImage(g_command_buffer_mgr->GetCurrentCommandBuffer(), @@ -630,8 +633,8 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l // Block until the GPU has finished copying to the staging texture. g_command_buffer_mgr->ExecuteCommandBuffer(false, true); - m_parent->m_state_tracker->InvalidateDescriptorSets(); - m_parent->m_state_tracker->SetPendingRebind(); + StateTracker::GetInstance()->InvalidateDescriptorSets(); + StateTracker::GetInstance()->SetPendingRebind(); // Map the staging texture so we can copy the contents out. if (staging_texture->Map()) |
