From bbc585881a69b899bfaa9c2982c87a2034d4331e Mon Sep 17 00:00:00 2001 From: Merry Date: Thu, 7 Apr 2022 19:32:40 +0100 Subject: [PATCH] video_core: Replace lock_guard with scoped_lock --- src/video_core/gpu.cpp | 6 +++--- src/video_core/gpu_thread.cpp | 2 +- src/video_core/renderer_opengl/gl_graphics_pipeline.cpp | 2 +- src/video_core/renderer_opengl/gl_shader_cache.cpp | 4 ++-- src/video_core/renderer_vulkan/pipeline_statistics.cpp | 4 ++-- src/video_core/renderer_vulkan/vk_compute_pipeline.cpp | 2 +- src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | 2 +- src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 4 ++-- src/video_core/renderer_vulkan/vk_render_pass_cache.cpp | 2 +- src/video_core/renderer_vulkan/vk_scheduler.cpp | 6 +++--- src/video_core/shader_cache.cpp | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index ba9ba082f..789af452d 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -230,7 +230,7 @@ struct GPU::Impl { void IncrementSyncPoint(u32 syncpoint_id) { auto& syncpoint = syncpoints.at(syncpoint_id); syncpoint++; - std::lock_guard lock{sync_mutex}; + std::scoped_lock lock{sync_mutex}; sync_cv.notify_all(); auto& interrupt = syncpt_interrupts.at(syncpoint_id); if (!interrupt.empty()) { @@ -252,7 +252,7 @@ struct GPU::Impl { } void RegisterSyncptInterrupt(u32 syncpoint_id, u32 value) { - std::lock_guard lock{sync_mutex}; + std::scoped_lock lock{sync_mutex}; auto& interrupt = syncpt_interrupts.at(syncpoint_id); bool contains = std::any_of(interrupt.begin(), interrupt.end(), [value](u32 in_value) { return in_value == value; }); @@ -263,7 +263,7 @@ struct GPU::Impl { } [[nodiscard]] bool CancelSyncptInterrupt(u32 syncpoint_id, u32 value) { - std::lock_guard lock{sync_mutex}; + std::scoped_lock lock{sync_mutex}; auto& interrupt = syncpt_interrupts.at(syncpoint_id); const auto iter = std::find_if(interrupt.begin(), interrupt.end(), diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 9547f277a..4e8999915 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -56,7 +56,7 @@ static void RunThread(std::stop_token stop_token, Core::System& system, if (next.block) { // We have to lock the write_lock to ensure that the condition_variable wait not get a // race between the check and the lock itself. - std::lock_guard lk(state.write_lock); + std::scoped_lock lk{state.write_lock}; state.cv.notify_all(); } } diff --git a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp index 9e6732abd..fd40966d5 100644 --- a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp +++ b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp @@ -253,7 +253,7 @@ GraphicsPipeline::GraphicsPipeline( } } if (in_parallel) { - std::lock_guard lock{built_mutex}; + std::scoped_lock lock{built_mutex}; built_fence.Create(); // Flush this context to ensure compilation commands and fence are in the GPU pipe. glFlush(); diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 6423992c3..05c5e702c 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -258,7 +258,7 @@ void ShaderCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading, [this, key, env = std::move(env), &state, &callback](Context* ctx) mutable { ctx->pools.ReleaseContents(); auto pipeline{CreateComputePipeline(ctx->pools, key, env)}; - std::lock_guard lock{state.mutex}; + std::scoped_lock lock{state.mutex}; if (pipeline) { compute_cache.emplace(key, std::move(pipeline)); } @@ -280,7 +280,7 @@ void ShaderCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading, } ctx->pools.ReleaseContents(); auto pipeline{CreateGraphicsPipeline(ctx->pools, key, MakeSpan(env_ptrs), false)}; - std::lock_guard lock{state.mutex}; + std::scoped_lock lock{state.mutex}; if (pipeline) { graphics_cache.emplace(key, std::move(pipeline)); } diff --git a/src/video_core/renderer_vulkan/pipeline_statistics.cpp b/src/video_core/renderer_vulkan/pipeline_statistics.cpp index bfec931a6..7ccadf084 100644 --- a/src/video_core/renderer_vulkan/pipeline_statistics.cpp +++ b/src/video_core/renderer_vulkan/pipeline_statistics.cpp @@ -57,7 +57,7 @@ void PipelineStatistics::Collect(VkPipeline pipeline) { stage_stats.basic_block_count = GetUint64(statistic); } } - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; collected_stats.push_back(stage_stats); } } @@ -66,7 +66,7 @@ void PipelineStatistics::Report() const { double num{}; Stats total; { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; for (const Stats& stats : collected_stats) { total.code_size += stats.code_size; total.register_count += stats.register_count; diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp index de36bcdb7..97b3594c2 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp @@ -77,7 +77,7 @@ ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descript if (pipeline_statistics) { pipeline_statistics->Collect(*pipeline); } - std::lock_guard lock{build_mutex}; + std::scoped_lock lock{build_mutex}; is_built = true; build_condvar.notify_one(); if (shader_notify) { diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index d514b71d0..8959d6059 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -258,7 +258,7 @@ GraphicsPipeline::GraphicsPipeline( pipeline_statistics->Collect(*pipeline); } - std::lock_guard lock{build_mutex}; + std::scoped_lock lock{build_mutex}; is_built = true; build_condvar.notify_one(); if (shader_notify) { diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 27e59df73..336d1e9dc 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -404,7 +404,7 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading workers.QueueWork([this, key, env = std::move(env), &state, &callback]() mutable { ShaderPools pools; auto pipeline{CreateComputePipeline(pools, key, env, state.statistics.get(), false)}; - std::lock_guard lock{state.mutex}; + std::scoped_lock lock{state.mutex}; if (pipeline) { compute_cache.emplace(key, std::move(pipeline)); } @@ -434,7 +434,7 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading auto pipeline{CreateGraphicsPipeline(pools, key, MakeSpan(env_ptrs), state.statistics.get(), false)}; - std::lock_guard lock{state.mutex}; + std::scoped_lock lock{state.mutex}; graphics_cache.emplace(key, std::move(pipeline)); ++state.built; if (state.has_loaded) { diff --git a/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp b/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp index 451ffe019..d22bb6694 100644 --- a/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp @@ -36,7 +36,7 @@ VkAttachmentDescription AttachmentDescription(const Device& device, PixelFormat RenderPassCache::RenderPassCache(const Device& device_) : device{&device_} {} VkRenderPass RenderPassCache::Get(const RenderPassKey& key) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto [pair, is_new] = cache.try_emplace(key); if (!is_new) { return *pair->second; diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index ad320991b..6a9416457 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp @@ -73,7 +73,7 @@ void VKScheduler::DispatchWork() { return; } { - std::lock_guard lock{work_mutex}; + std::scoped_lock lock{work_mutex}; work_queue.push(std::move(chunk)); } work_cv.notify_one(); @@ -157,7 +157,7 @@ void VKScheduler::WorkerThread(std::stop_token stop_token) { if (has_submit) { AllocateWorkerCommandBuffer(); } - std::lock_guard reserve_lock{reserve_mutex}; + std::scoped_lock reserve_lock{reserve_mutex}; chunk_reserve.push_back(std::move(work)); } while (!stop_token.stop_requested()); } @@ -282,7 +282,7 @@ void VKScheduler::EndRenderPass() { } void VKScheduler::AcquireNewChunk() { - std::lock_guard lock{reserve_mutex}; + std::scoped_lock lock{reserve_mutex}; if (chunk_reserve.empty()) { chunk = std::make_unique(); return; diff --git a/src/video_core/shader_cache.cpp b/src/video_core/shader_cache.cpp index 87636857d..75031767a 100644 --- a/src/video_core/shader_cache.cpp +++ b/src/video_core/shader_cache.cpp @@ -25,7 +25,7 @@ void ShaderCache::InvalidateRegion(VAddr addr, size_t size) { } void ShaderCache::OnCPUWrite(VAddr addr, size_t size) { - std::lock_guard lock{invalidation_mutex}; + std::scoped_lock lock{invalidation_mutex}; InvalidatePagesInRegion(addr, size); }