mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-03 05:17:15 +02:00
[audio_core, hle, video_core] force inline of functions that only contain thread loops (#3970)
traditionally, when doing jthread:
```
jthread() calls function parameter operator()() with args
function operator()() calls the code within
code within is, say { ThreadMain(); }
3 calls because why not
```
now this just makes it be 2 calls, mainly benefits non-LTO builds
Signed-off-by: lizzie <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3970
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
parent
d761ecba8c
commit
37b5cf6003
7 changed files with 349 additions and 369 deletions
|
|
@ -59,7 +59,57 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_)
|
|||
|
||||
AcquireNewChunk();
|
||||
AllocateWorkerCommandBuffer();
|
||||
worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
|
||||
worker_thread = std::jthread([this](std::stop_token stop_token) {
|
||||
Common::SetCurrentThreadName("VulkanWorker");
|
||||
const auto TryPopQueue{[this](auto& work) -> bool {
|
||||
if (work_queue.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
work = std::move(work_queue.front());
|
||||
work_queue.pop();
|
||||
event_cv.notify_all();
|
||||
return true;
|
||||
}};
|
||||
|
||||
while (!stop_token.stop_requested()) {
|
||||
std::unique_ptr<CommandChunk> work;
|
||||
|
||||
{
|
||||
std::unique_lock lk{queue_mutex};
|
||||
|
||||
// Wait for work.
|
||||
event_cv.wait(lk, stop_token, [&] { return TryPopQueue(work); });
|
||||
|
||||
// If we've been asked to stop, we're done.
|
||||
if (stop_token.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Exchange lock ownership so that we take the execution lock before
|
||||
// the queue lock goes out of scope. This allows us to force execution
|
||||
// to complete in the next step.
|
||||
std::exchange(lk, std::unique_lock{execution_mutex});
|
||||
|
||||
// Perform the work, tracking whether the chunk was a submission
|
||||
// before executing.
|
||||
const bool has_submit = work->HasSubmit();
|
||||
work->ExecuteAll(current_cmdbuf, current_upload_cmdbuf);
|
||||
|
||||
// If the chunk was a submission, reallocate the command buffer.
|
||||
if (has_submit) {
|
||||
AllocateWorkerCommandBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock rl{reserve_mutex};
|
||||
|
||||
// Recycle the chunk back to the reserve.
|
||||
chunk_reserve.emplace_back(std::move(work));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Scheduler::~Scheduler() = default;
|
||||
|
|
@ -187,59 +237,6 @@ bool Scheduler::UpdateRescaling(bool is_rescaling) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Scheduler::WorkerThread(std::stop_token stop_token) {
|
||||
Common::SetCurrentThreadName("VulkanWorker");
|
||||
|
||||
const auto TryPopQueue{[this](auto& work) -> bool {
|
||||
if (work_queue.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
work = std::move(work_queue.front());
|
||||
work_queue.pop();
|
||||
event_cv.notify_all();
|
||||
return true;
|
||||
}};
|
||||
|
||||
while (!stop_token.stop_requested()) {
|
||||
std::unique_ptr<CommandChunk> work;
|
||||
|
||||
{
|
||||
std::unique_lock lk{queue_mutex};
|
||||
|
||||
// Wait for work.
|
||||
event_cv.wait(lk, stop_token, [&] { return TryPopQueue(work); });
|
||||
|
||||
// If we've been asked to stop, we're done.
|
||||
if (stop_token.stop_requested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Exchange lock ownership so that we take the execution lock before
|
||||
// the queue lock goes out of scope. This allows us to force execution
|
||||
// to complete in the next step.
|
||||
std::exchange(lk, std::unique_lock{execution_mutex});
|
||||
|
||||
// Perform the work, tracking whether the chunk was a submission
|
||||
// before executing.
|
||||
const bool has_submit = work->HasSubmit();
|
||||
work->ExecuteAll(current_cmdbuf, current_upload_cmdbuf);
|
||||
|
||||
// If the chunk was a submission, reallocate the command buffer.
|
||||
if (has_submit) {
|
||||
AllocateWorkerCommandBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock rl{reserve_mutex};
|
||||
|
||||
// Recycle the chunk back to the reserve.
|
||||
chunk_reserve.emplace_back(std::move(work));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scheduler::AllocateWorkerCommandBuffer() {
|
||||
current_cmdbuf = vk::CommandBuffer(command_pool->Commit(), device.GetDispatchLoader());
|
||||
current_cmdbuf.Begin({
|
||||
|
|
|
|||
|
|
@ -251,8 +251,6 @@ private:
|
|||
bool needs_state_enable_refresh = false;
|
||||
};
|
||||
|
||||
void WorkerThread(std::stop_token stop_token);
|
||||
|
||||
void AllocateWorkerCommandBuffer();
|
||||
|
||||
u64 SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_semaphore);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue