VERY experimental Nintendo Switch 2 emulator
C++
video_core: Replace lock_guard with scoped_lock
Merrye8a60754e967
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cppindex ba9ba082f2..789af452d1 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.cppindex 9547f277a0..4e89999157 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.cppindex 9e6732abd4..fd40966d50 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.cppindex 6423992c3f..05c5e702cc 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.cppindex bfec931a66..7ccadf0841 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.cppindex de36bcdb7e..97b3594c24 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& descriptif (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.cppindex d514b71d09..8959d6059c 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.cppindex 27e59df73b..336d1e9dc6 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_loadingworkers.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_loadingauto 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.cppindex 451ffe0197..d22bb6694c 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, PixelFormatRenderPassCache::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.cppindex ad320991b2..6a94164574 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<CommandChunk>();return;diff --git a/src/video_core/shader_cache.cpp b/src/video_core/shader_cache.cppindex 87636857d9..75031767a7 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);}