video_core: Replace lock_guard with scoped_lock

master
Merry 2022-04-07 19:32:40 +07:00
parent 159ae5e47c
commit bbc585881a
11 changed files with 18 additions and 18 deletions

@ -230,7 +230,7 @@ struct GPU::Impl {
void IncrementSyncPoint(u32 syncpoint_id) { void IncrementSyncPoint(u32 syncpoint_id) {
auto& syncpoint = syncpoints.at(syncpoint_id); auto& syncpoint = syncpoints.at(syncpoint_id);
syncpoint++; syncpoint++;
std::lock_guard lock{sync_mutex}; std::scoped_lock lock{sync_mutex};
sync_cv.notify_all(); sync_cv.notify_all();
auto& interrupt = syncpt_interrupts.at(syncpoint_id); auto& interrupt = syncpt_interrupts.at(syncpoint_id);
if (!interrupt.empty()) { if (!interrupt.empty()) {
@ -252,7 +252,7 @@ struct GPU::Impl {
} }
void RegisterSyncptInterrupt(u32 syncpoint_id, u32 value) { 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); auto& interrupt = syncpt_interrupts.at(syncpoint_id);
bool contains = std::any_of(interrupt.begin(), interrupt.end(), bool contains = std::any_of(interrupt.begin(), interrupt.end(),
[value](u32 in_value) { return in_value == value; }); [value](u32 in_value) { return in_value == value; });
@ -263,7 +263,7 @@ struct GPU::Impl {
} }
[[nodiscard]] bool CancelSyncptInterrupt(u32 syncpoint_id, u32 value) { [[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); auto& interrupt = syncpt_interrupts.at(syncpoint_id);
const auto iter = const auto iter =
std::find_if(interrupt.begin(), interrupt.end(), std::find_if(interrupt.begin(), interrupt.end(),

@ -56,7 +56,7 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
if (next.block) { if (next.block) {
// We have to lock the write_lock to ensure that the condition_variable wait not get a // 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. // 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(); state.cv.notify_all();
} }
} }

@ -253,7 +253,7 @@ GraphicsPipeline::GraphicsPipeline(
} }
} }
if (in_parallel) { if (in_parallel) {
std::lock_guard lock{built_mutex}; std::scoped_lock lock{built_mutex};
built_fence.Create(); built_fence.Create();
// Flush this context to ensure compilation commands and fence are in the GPU pipe. // Flush this context to ensure compilation commands and fence are in the GPU pipe.
glFlush(); glFlush();

@ -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 { [this, key, env = std::move(env), &state, &callback](Context* ctx) mutable {
ctx->pools.ReleaseContents(); ctx->pools.ReleaseContents();
auto pipeline{CreateComputePipeline(ctx->pools, key, env)}; auto pipeline{CreateComputePipeline(ctx->pools, key, env)};
std::lock_guard lock{state.mutex}; std::scoped_lock lock{state.mutex};
if (pipeline) { if (pipeline) {
compute_cache.emplace(key, std::move(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(); ctx->pools.ReleaseContents();
auto pipeline{CreateGraphicsPipeline(ctx->pools, key, MakeSpan(env_ptrs), false)}; auto pipeline{CreateGraphicsPipeline(ctx->pools, key, MakeSpan(env_ptrs), false)};
std::lock_guard lock{state.mutex}; std::scoped_lock lock{state.mutex};
if (pipeline) { if (pipeline) {
graphics_cache.emplace(key, std::move(pipeline)); graphics_cache.emplace(key, std::move(pipeline));
} }

@ -57,7 +57,7 @@ void PipelineStatistics::Collect(VkPipeline pipeline) {
stage_stats.basic_block_count = GetUint64(statistic); stage_stats.basic_block_count = GetUint64(statistic);
} }
} }
std::lock_guard lock{mutex}; std::scoped_lock lock{mutex};
collected_stats.push_back(stage_stats); collected_stats.push_back(stage_stats);
} }
} }
@ -66,7 +66,7 @@ void PipelineStatistics::Report() const {
double num{}; double num{};
Stats total; Stats total;
{ {
std::lock_guard lock{mutex}; std::scoped_lock lock{mutex};
for (const Stats& stats : collected_stats) { for (const Stats& stats : collected_stats) {
total.code_size += stats.code_size; total.code_size += stats.code_size;
total.register_count += stats.register_count; total.register_count += stats.register_count;

@ -77,7 +77,7 @@ ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descript
if (pipeline_statistics) { if (pipeline_statistics) {
pipeline_statistics->Collect(*pipeline); pipeline_statistics->Collect(*pipeline);
} }
std::lock_guard lock{build_mutex}; std::scoped_lock lock{build_mutex};
is_built = true; is_built = true;
build_condvar.notify_one(); build_condvar.notify_one();
if (shader_notify) { if (shader_notify) {

@ -258,7 +258,7 @@ GraphicsPipeline::GraphicsPipeline(
pipeline_statistics->Collect(*pipeline); pipeline_statistics->Collect(*pipeline);
} }
std::lock_guard lock{build_mutex}; std::scoped_lock lock{build_mutex};
is_built = true; is_built = true;
build_condvar.notify_one(); build_condvar.notify_one();
if (shader_notify) { if (shader_notify) {

@ -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 { workers.QueueWork([this, key, env = std::move(env), &state, &callback]() mutable {
ShaderPools pools; ShaderPools pools;
auto pipeline{CreateComputePipeline(pools, key, env, state.statistics.get(), false)}; auto pipeline{CreateComputePipeline(pools, key, env, state.statistics.get(), false)};
std::lock_guard lock{state.mutex}; std::scoped_lock lock{state.mutex};
if (pipeline) { if (pipeline) {
compute_cache.emplace(key, std::move(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), auto pipeline{CreateGraphicsPipeline(pools, key, MakeSpan(env_ptrs),
state.statistics.get(), false)}; state.statistics.get(), false)};
std::lock_guard lock{state.mutex}; std::scoped_lock lock{state.mutex};
graphics_cache.emplace(key, std::move(pipeline)); graphics_cache.emplace(key, std::move(pipeline));
++state.built; ++state.built;
if (state.has_loaded) { if (state.has_loaded) {

@ -36,7 +36,7 @@ VkAttachmentDescription AttachmentDescription(const Device& device, PixelFormat
RenderPassCache::RenderPassCache(const Device& device_) : device{&device_} {} RenderPassCache::RenderPassCache(const Device& device_) : device{&device_} {}
VkRenderPass RenderPassCache::Get(const RenderPassKey& key) { 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); const auto [pair, is_new] = cache.try_emplace(key);
if (!is_new) { if (!is_new) {
return *pair->second; return *pair->second;

@ -73,7 +73,7 @@ void VKScheduler::DispatchWork() {
return; return;
} }
{ {
std::lock_guard lock{work_mutex}; std::scoped_lock lock{work_mutex};
work_queue.push(std::move(chunk)); work_queue.push(std::move(chunk));
} }
work_cv.notify_one(); work_cv.notify_one();
@ -157,7 +157,7 @@ void VKScheduler::WorkerThread(std::stop_token stop_token) {
if (has_submit) { if (has_submit) {
AllocateWorkerCommandBuffer(); AllocateWorkerCommandBuffer();
} }
std::lock_guard reserve_lock{reserve_mutex}; std::scoped_lock reserve_lock{reserve_mutex};
chunk_reserve.push_back(std::move(work)); chunk_reserve.push_back(std::move(work));
} while (!stop_token.stop_requested()); } while (!stop_token.stop_requested());
} }
@ -282,7 +282,7 @@ void VKScheduler::EndRenderPass() {
} }
void VKScheduler::AcquireNewChunk() { void VKScheduler::AcquireNewChunk() {
std::lock_guard lock{reserve_mutex}; std::scoped_lock lock{reserve_mutex};
if (chunk_reserve.empty()) { if (chunk_reserve.empty()) {
chunk = std::make_unique<CommandChunk>(); chunk = std::make_unique<CommandChunk>();
return; return;

@ -25,7 +25,7 @@ void ShaderCache::InvalidateRegion(VAddr addr, size_t size) {
} }
void ShaderCache::OnCPUWrite(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); InvalidatePagesInRegion(addr, size);
} }