Add CommandExecutor slot count setting

This commit is contained in:
Billy Laws
2022-10-16 20:50:06 +01:00
parent 1a0819fb76
commit 576bc6f37e
9 changed files with 41 additions and 11 deletions

View File

@ -109,8 +109,6 @@ namespace skyline::gpu {
lock.unlock();
chainedCycles.Iterate([&](const auto &cycle) {
if (!cycle->Find(this))
raise(SIGTRAP);
cycle->WaitSubmit();
});
lock.lock();
@ -129,7 +127,7 @@ namespace skyline::gpu {
return;
}
chainedCycles.Iterate([shouldDestroy, this](auto &cycle) {
chainedCycles.Iterate([shouldDestroy](auto &cycle) {
cycle->Wait(shouldDestroy);
});

View File

@ -2,12 +2,17 @@
// Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <range/v3/view.hpp>
#include <common/settings.h>
#include <loader/loader.h>
#include <gpu.h>
#include "command_executor.h"
namespace skyline::gpu::interconnect {
CommandRecordThread::CommandRecordThread(const DeviceState &state) : state{state}, thread{&CommandRecordThread::Run, this} {}
CommandRecordThread::CommandRecordThread(const DeviceState &state)
: state{state},
incoming{*state.settings->executorSlotCount},
outgoing{*state.settings->executorSlotCount},
thread{&CommandRecordThread::Run, this} {}
static vk::raii::CommandBuffer AllocateRaiiCommandBuffer(GPU &gpu, vk::raii::CommandPool &pool) {
return {gpu.vkDevice, (*gpu.vkDevice).allocateCommandBuffers(
@ -31,6 +36,13 @@ namespace skyline::gpu::interconnect {
semaphore{gpu.vkDevice, vk::SemaphoreCreateInfo{}},
cycle{std::make_shared<FenceCycle>(gpu.vkDevice, *fence, *semaphore, true)} {}
CommandRecordThread::Slot::Slot(Slot &&other)
: commandPool{std::move(other.commandPool)},
commandBuffer{std::move(other.commandBuffer)},
fence{std::move(other.fence)},
semaphore{std::move(other.semaphore)},
cycle{std::move(other.cycle)} {}
std::shared_ptr<FenceCycle> CommandRecordThread::Slot::Reset(GPU &gpu) {
cycle->Wait();
cycle = std::make_shared<FenceCycle>(*cycle);
@ -79,7 +91,10 @@ namespace skyline::gpu::interconnect {
void CommandRecordThread::Run() {
auto &gpu{*state.gpu};
std::array<Slot, ActiveRecordSlots> slots{{gpu, gpu, gpu, gpu, gpu, gpu}};
std::vector<Slot> slots{};
std::generate_n(std::back_inserter(slots), *state.settings->executorSlotCount, [&] () -> Slot { return gpu; });
outgoing.AppendTranform(span<Slot>(slots), [](auto &slot) { return &slot; });
if (int result{pthread_setname_np(pthread_self(), "Sky-CmdRecord")})
@ -116,7 +131,8 @@ namespace skyline::gpu::interconnect {
}
CommandExecutor::CommandExecutor(const DeviceState &state)
: gpu{*state.gpu},
: state{state},
gpu{*state.gpu},
recordThread{state},
tag{AllocateTag()} {
RotateRecordSlot();
@ -401,7 +417,7 @@ namespace skyline::gpu::interconnect {
allocator->Reset();
// Periodically clear preserve attachments just in case there are new waiters which would otherwise end up waiting forever
if ((submissionNumber % CommandRecordThread::ActiveRecordSlots * 2) == 0) {
if ((submissionNumber % (*state.settings->executorSlotCount * 2)) == 0) {
preserveAttachedBuffers.clear();
preserveAttachedTextures.clear();
}

View File

@ -15,7 +15,6 @@ namespace skyline::gpu::interconnect {
*/
class CommandRecordThread {
public:
static constexpr size_t ActiveRecordSlots{6}; //!< Maximum number of simultaneously active slots
/**
* @brief Single execution slot, buffered back and forth between the GPFIFO thread and the record thread
@ -32,6 +31,8 @@ namespace skyline::gpu::interconnect {
Slot(GPU &gpu);
Slot(Slot &&other);
/**
* @brief Waits on the fence and resets the command buffer
* @note A new fence cycle for the reset command buffer
@ -41,10 +42,10 @@ namespace skyline::gpu::interconnect {
private:
const DeviceState &state;
std::thread thread;
CircularQueue<Slot *> incoming; //!< Slots pending recording
CircularQueue<Slot *> outgoing; //!< Slots that have been submitted, may still be active on the GPU
CircularQueue<Slot *> incoming{ActiveRecordSlots}; //!< Slots pending recording
CircularQueue<Slot *> outgoing{ActiveRecordSlots}; //!< Slots that have been submitted, may still be active on the GPU
std::thread thread;
void ProcessSlot(Slot *slot);
@ -70,6 +71,7 @@ namespace skyline::gpu::interconnect {
*/
class CommandExecutor {
private:
const DeviceState &state;
GPU &gpu;
CommandRecordThread recordThread;
CommandRecordThread::Slot *slot{};