From 4539073ce1d8fd6df03263e826d3805b4909e055 Mon Sep 17 00:00:00 2001 From: ameerj Date: Thu, 30 Jul 2020 15:41:11 -0400 Subject: Address feedback. Bruteforce delete duplicates --- src/video_core/renderer_vulkan/vk_graphics_pipeline.h | 2 +- src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 16 +++++++++------- src/video_core/renderer_vulkan/vk_pipeline_cache.h | 19 +++++++++++++++++-- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 18 ++++++++++-------- src/video_core/renderer_vulkan/vk_rasterizer.h | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) (limited to 'src/video_core/renderer_vulkan') diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h index 39c73a139..d50bd347c 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h @@ -54,7 +54,7 @@ public: return renderpass; } - const GraphicsPipelineCacheKey& GetCacheKey() { + const GraphicsPipelineCacheKey& GetCacheKey() const { return m_key; } diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 45d4dcb8c..a7ce621ca 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -205,20 +205,20 @@ std::array VKPipelineCache::GetShaders() { return last_shaders = shaders; } -VKGraphicsPipeline& VKPipelineCache::GetGraphicsPipeline( +VKGraphicsPipeline* VKPipelineCache::GetGraphicsPipeline( const GraphicsPipelineCacheKey& key, VideoCommon::Shader::AsyncShaders& async_shaders) { MICROPROFILE_SCOPE(Vulkan_PipelineCache); if (last_graphics_pipeline && last_graphics_key == key) { - return *last_graphics_pipeline; + return last_graphics_pipeline; } last_graphics_key = key; if (device.UseAsynchronousShaders()) { auto work = async_shaders.GetCompletedWork(); - for (std::size_t i = 0; i < work.size(); ++i) { - auto& entry = graphics_cache.at(work[i].pipeline->GetCacheKey()); - entry = std::move(work[i].pipeline); + for (auto& w : work) { + auto& entry = graphics_cache.at(w.pipeline->GetCacheKey()); + entry = std::move(w.pipeline); } const auto [pair, is_cache_miss] = graphics_cache.try_emplace(key); if (is_cache_miss) { @@ -227,7 +227,8 @@ VKGraphicsPipeline& VKPipelineCache::GetGraphicsPipeline( async_shaders.QueueVulkanShader(this, bindings, program, key.renderpass_params, key.padding, key.shaders, key.fixed_state); } - return *(last_graphics_pipeline = graphics_cache.at(key).get()); + last_graphics_pipeline = graphics_cache.at(key).get(); + return last_graphics_pipeline; } const auto [pair, is_cache_miss] = graphics_cache.try_emplace(key); @@ -239,7 +240,8 @@ VKGraphicsPipeline& VKPipelineCache::GetGraphicsPipeline( update_descriptor_queue, renderpass_cache, key, bindings, program); } - return *(last_graphics_pipeline = entry.get()); + last_graphics_pipeline = entry.get(); + return last_graphics_pipeline; } VKComputePipeline& VKPipelineCache::GetComputePipeline(const ComputePipelineCacheKey& key) { diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h index c70da6da4..404f2b3f7 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h @@ -153,31 +153,46 @@ public: std::array GetShaders(); - VKGraphicsPipeline& GetGraphicsPipeline(const GraphicsPipelineCacheKey& key, + VKGraphicsPipeline* GetGraphicsPipeline(const GraphicsPipelineCacheKey& key, VideoCommon::Shader::AsyncShaders& async_shaders); VKComputePipeline& GetComputePipeline(const ComputePipelineCacheKey& key); - const VKDevice& GetDevice() { + const VKDevice& GetDevice() const { return device; } VKScheduler& GetScheduler() { return scheduler; } + const VKScheduler& GetScheduler() const { + return scheduler; + } VKDescriptorPool& GetDescriptorPool() { return descriptor_pool; } + const VKDescriptorPool& GetDescriptorPool() const { + return descriptor_pool; + } + VKUpdateDescriptorQueue& GetUpdateDescriptorQueue() { return update_descriptor_queue; } + const VKUpdateDescriptorQueue& GetUpdateDescriptorQueue() const { + return update_descriptor_queue; + } + VKRenderPassCache& GetRenderpassCache() { return renderpass_cache; } + const VKRenderPassCache& GetRenderpassCache() const { + return renderpass_cache; + } + protected: void OnShaderRemoval(Shader* shader) final; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 6310e898c..fc1b51a96 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -404,10 +404,12 @@ RasterizerVulkan::RasterizerVulkan(Core::System& system, Core::Frontend::EmuWind wfi_event{device.GetLogical().CreateNewEvent()}, async_shaders{renderer} { scheduler.SetQueryCache(query_cache); if (device.UseAsynchronousShaders()) { + // The following is subject to move into the allocate workers method, to be api agnostic + // Max worker threads we should allow - constexpr auto MAX_THREADS = 2u; + constexpr u32 MAX_THREADS = 4; // Amount of threads we should reserve for other parts of yuzu - constexpr auto RESERVED_THREADS = 6u; + constexpr u32 RESERVED_THREADS = 6; // Get the amount of threads we can use(this can return zero) const auto cpu_thread_count = std::max(RESERVED_THREADS, std::thread::hardware_concurrency()); @@ -456,16 +458,16 @@ void RasterizerVulkan::Draw(bool is_indexed, bool is_instanced) { key.renderpass_params = GetRenderPassParams(texceptions); key.padding = 0; - auto& pipeline = pipeline_cache.GetGraphicsPipeline(key, async_shaders); - if (&pipeline == nullptr || pipeline.GetHandle() == VK_NULL_HANDLE) { + auto pipeline = pipeline_cache.GetGraphicsPipeline(key, async_shaders); + if (pipeline == nullptr || pipeline->GetHandle() == VK_NULL_HANDLE) { // Async graphics pipeline was not ready. system.GPU().TickWork(); return; } - scheduler.BindGraphicsPipeline(pipeline.GetHandle()); + scheduler.BindGraphicsPipeline(pipeline->GetHandle()); - const auto renderpass = pipeline.GetRenderPass(); + const auto renderpass = pipeline->GetRenderPass(); const auto [framebuffer, render_area] = ConfigureFramebuffers(renderpass); scheduler.RequestRenderpass(renderpass, framebuffer, render_area); @@ -475,8 +477,8 @@ void RasterizerVulkan::Draw(bool is_indexed, bool is_instanced) { BeginTransformFeedback(); - const auto pipeline_layout = pipeline.GetLayout(); - const auto descriptor_set = pipeline.CommitDescriptorSet(); + const auto pipeline_layout = pipeline->GetLayout(); + const auto descriptor_set = pipeline->CommitDescriptorSet(); scheduler.Record([pipeline_layout, descriptor_set, draw_params](vk::CommandBuffer cmdbuf) { if (descriptor_set) { cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 27604b9a3..f640ba649 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h @@ -287,7 +287,6 @@ private: VKMemoryManager& memory_manager; StateTracker& state_tracker; VKScheduler& scheduler; - VideoCommon::Shader::AsyncShaders async_shaders; VKStagingBufferPool staging_pool; VKDescriptorPool descriptor_pool; @@ -307,6 +306,7 @@ private: vk::Buffer default_buffer; VKMemoryCommit default_buffer_commit; vk::Event wfi_event; + VideoCommon::Shader::AsyncShaders async_shaders; std::array color_attachments; View zeta_attachment; -- cgit v1.2.3