mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-28 02:26:07 +00:00
coroutine code prettification
This commit is contained in:
parent
714605c6a7
commit
9737df614c
|
@ -57,3 +57,6 @@ enum MarkersPalette : int {
|
||||||
tracy::SourceLocationData{nullptr, name, TracyFile, (uint32_t)TracyLine, 0};
|
tracy::SourceLocationData{nullptr, name, TracyFile, (uint32_t)TracyLine, 0};
|
||||||
|
|
||||||
#define FRAME_END FrameMark
|
#define FRAME_END FrameMark
|
||||||
|
|
||||||
|
#define FIBER_ENTER(name) TracyFiberEnter(name)
|
||||||
|
#define FIBER_EXIT TracyFiberLeave
|
||||||
|
|
|
@ -290,7 +290,7 @@ void EmitContext::DefineInputs() {
|
||||||
});
|
});
|
||||||
// Note that we pass index rather than Id
|
// Note that we pass index rather than Id
|
||||||
input_params[attrib.semantic] = SpirvAttribute{
|
input_params[attrib.semantic] = SpirvAttribute{
|
||||||
.id = rate_idx,
|
.id = {rate_idx},
|
||||||
.pointer_type = input_u32,
|
.pointer_type = input_u32,
|
||||||
.component_type = U32[1],
|
.component_type = U32[1],
|
||||||
.num_components = std::min<u16>(attrib.num_elements, num_components),
|
.num_components = std::min<u16>(attrib.num_elements, num_components),
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
@ -18,7 +20,38 @@ namespace AmdGpu {
|
||||||
|
|
||||||
static const char* dcb_task_name{"DCB_TASK"};
|
static const char* dcb_task_name{"DCB_TASK"};
|
||||||
static const char* ccb_task_name{"CCB_TASK"};
|
static const char* ccb_task_name{"CCB_TASK"};
|
||||||
static const char* acb_task_name{"ACB_TASK"};
|
|
||||||
|
#define MAX_NAMES 56
|
||||||
|
static_assert(Liverpool::NumComputeRings <= MAX_NAMES);
|
||||||
|
|
||||||
|
#define NAME_NUM(z, n, name) BOOST_PP_STRINGIZE(name) BOOST_PP_STRINGIZE(n),
|
||||||
|
#define NAME_ARRAY(name, num) {BOOST_PP_REPEAT(num, NAME_NUM, name)}
|
||||||
|
|
||||||
|
static const char* acb_task_name[] = NAME_ARRAY(ACB_TASK, MAX_NAMES);
|
||||||
|
|
||||||
|
#define YIELD(name) \
|
||||||
|
FIBER_EXIT; \
|
||||||
|
co_yield {}; \
|
||||||
|
FIBER_ENTER(name)
|
||||||
|
|
||||||
|
#define YIELD_GFX \
|
||||||
|
mapped_queues[GfxQueueId].cs_state = regs.cs_program; \
|
||||||
|
FIBER_EXIT; \
|
||||||
|
co_yield {}; \
|
||||||
|
FIBER_ENTER(dcb_task_name); \
|
||||||
|
regs.cs_program = mapped_queues[GfxQueueId].cs_state;
|
||||||
|
|
||||||
|
#define YIELD_ASC(id) \
|
||||||
|
mapped_queues[id].cs_state = regs.cs_program; \
|
||||||
|
FIBER_EXIT; \
|
||||||
|
co_yield {}; \
|
||||||
|
FIBER_ENTER(acb_task_name[id]); \
|
||||||
|
regs.cs_program = mapped_queues[id].cs_state;
|
||||||
|
|
||||||
|
#define RESUME(task, name) \
|
||||||
|
FIBER_EXIT; \
|
||||||
|
task.handle.resume(); \
|
||||||
|
FIBER_ENTER(name);
|
||||||
|
|
||||||
std::array<u8, 48_KB> Liverpool::ConstantEngine::constants_heap;
|
std::array<u8, 48_KB> Liverpool::ConstantEngine::constants_heap;
|
||||||
|
|
||||||
|
@ -119,7 +152,7 @@ void Liverpool::Process(std::stop_token stoken) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
|
Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
|
||||||
TracyFiberEnter(ccb_task_name);
|
FIBER_ENTER(ccb_task_name);
|
||||||
|
|
||||||
while (!ccb.empty()) {
|
while (!ccb.empty()) {
|
||||||
const auto* header = reinterpret_cast<const PM4Header*>(ccb.data());
|
const auto* header = reinterpret_cast<const PM4Header*>(ccb.data());
|
||||||
|
@ -155,9 +188,7 @@ Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
|
||||||
case PM4ItOpcode::WaitOnDeCounterDiff: {
|
case PM4ItOpcode::WaitOnDeCounterDiff: {
|
||||||
const auto diff = it_body[0];
|
const auto diff = it_body[0];
|
||||||
while ((cblock.de_count - cblock.ce_count) >= diff) {
|
while ((cblock.de_count - cblock.ce_count) >= diff) {
|
||||||
TracyFiberLeave;
|
YIELD(ccb_task_name);
|
||||||
co_yield {};
|
|
||||||
TracyFiberEnter(ccb_task_name);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -165,13 +196,12 @@ Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
|
||||||
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
||||||
auto task =
|
auto task =
|
||||||
ProcessCeUpdate({indirect_buffer->Address<const u32>(), indirect_buffer->ib_size});
|
ProcessCeUpdate({indirect_buffer->Address<const u32>(), indirect_buffer->ib_size});
|
||||||
while (!task.handle.done()) {
|
RESUME(task, ccb_task_name);
|
||||||
task.handle.resume();
|
|
||||||
|
|
||||||
TracyFiberLeave;
|
while (!task.handle.done()) {
|
||||||
co_yield {};
|
YIELD(ccb_task_name);
|
||||||
TracyFiberEnter(ccb_task_name);
|
RESUME(task, ccb_task_name);
|
||||||
};
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -182,11 +212,11 @@ Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
|
||||||
ccb = NextPacket(ccb, header->type3.NumWords() + 1);
|
ccb = NextPacket(ccb, header->type3.NumWords() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TracyFiberLeave;
|
FIBER_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<const u32> ccb) {
|
Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<const u32> ccb) {
|
||||||
TracyFiberEnter(dcb_task_name);
|
FIBER_ENTER(dcb_task_name);
|
||||||
|
|
||||||
cblock.Reset();
|
cblock.Reset();
|
||||||
|
|
||||||
|
@ -197,9 +227,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
if (!ccb.empty()) {
|
if (!ccb.empty()) {
|
||||||
// In case of CCB provided kick off CE asap to have the constant heap ready to use
|
// In case of CCB provided kick off CE asap to have the constant heap ready to use
|
||||||
ce_task = ProcessCeUpdate(ccb);
|
ce_task = ProcessCeUpdate(ccb);
|
||||||
TracyFiberLeave;
|
RESUME(ce_task, dcb_task_name);
|
||||||
ce_task.handle.resume();
|
|
||||||
TracyFiberEnter(dcb_task_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto base_addr = reinterpret_cast<uintptr_t>(dcb.data());
|
const auto base_addr = reinterpret_cast<uintptr_t>(dcb.data());
|
||||||
|
@ -613,11 +641,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
case PM4ItOpcode::Rewind: {
|
case PM4ItOpcode::Rewind: {
|
||||||
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
|
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
|
||||||
while (!rewind->Valid()) {
|
while (!rewind->Valid()) {
|
||||||
mapped_queues[GfxQueueId].cs_state = regs.cs_program;
|
YIELD_GFX;
|
||||||
TracyFiberLeave;
|
|
||||||
co_yield {};
|
|
||||||
TracyFiberEnter(dcb_task_name);
|
|
||||||
regs.cs_program = mapped_queues[GfxQueueId].cs_state;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -633,11 +657,7 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
vo_port->WaitVoLabel([&] { return wait_reg_mem->Test(); });
|
vo_port->WaitVoLabel([&] { return wait_reg_mem->Test(); });
|
||||||
}
|
}
|
||||||
while (!wait_reg_mem->Test()) {
|
while (!wait_reg_mem->Test()) {
|
||||||
mapped_queues[GfxQueueId].cs_state = regs.cs_program;
|
YIELD_GFX;
|
||||||
TracyFiberLeave;
|
|
||||||
co_yield {};
|
|
||||||
TracyFiberEnter(dcb_task_name);
|
|
||||||
regs.cs_program = mapped_queues[GfxQueueId].cs_state;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -645,13 +665,12 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
||||||
auto task = ProcessGraphics(
|
auto task = ProcessGraphics(
|
||||||
{indirect_buffer->Address<const u32>(), indirect_buffer->ib_size}, {});
|
{indirect_buffer->Address<const u32>(), indirect_buffer->ib_size}, {});
|
||||||
while (!task.handle.done()) {
|
RESUME(task, dcb_task_name);
|
||||||
task.handle.resume();
|
|
||||||
|
|
||||||
TracyFiberLeave;
|
while (!task.handle.done()) {
|
||||||
co_yield {};
|
YIELD_GFX;
|
||||||
TracyFiberEnter(dcb_task_name);
|
RESUME(task, dcb_task_name);
|
||||||
};
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PM4ItOpcode::IncrementDeCounter: {
|
case PM4ItOpcode::IncrementDeCounter: {
|
||||||
|
@ -660,9 +679,8 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
}
|
}
|
||||||
case PM4ItOpcode::WaitOnCeCounter: {
|
case PM4ItOpcode::WaitOnCeCounter: {
|
||||||
while (cblock.ce_count <= cblock.de_count) {
|
while (cblock.ce_count <= cblock.de_count) {
|
||||||
TracyFiberLeave;
|
RESUME(ce_task, dcb_task_name);
|
||||||
ce_task.handle.resume();
|
YIELD_GFX;
|
||||||
TracyFiberEnter(dcb_task_name);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -686,11 +704,11 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
|
||||||
ce_task.handle.destroy();
|
ce_task.handle.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
TracyFiberLeave;
|
FIBER_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
||||||
TracyFiberEnter(acb_task_name);
|
FIBER_ENTER(acb_task_name[vqid]);
|
||||||
|
|
||||||
auto base_addr = reinterpret_cast<uintptr_t>(acb.data());
|
auto base_addr = reinterpret_cast<uintptr_t>(acb.data());
|
||||||
while (!acb.empty()) {
|
while (!acb.empty()) {
|
||||||
|
@ -713,13 +731,12 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
||||||
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
|
||||||
auto task = ProcessCompute(
|
auto task = ProcessCompute(
|
||||||
{indirect_buffer->Address<const u32>(), indirect_buffer->ib_size}, vqid);
|
{indirect_buffer->Address<const u32>(), indirect_buffer->ib_size}, vqid);
|
||||||
while (!task.handle.done()) {
|
RESUME(task, acb_task_name[vqid]);
|
||||||
task.handle.resume();
|
|
||||||
|
|
||||||
TracyFiberLeave;
|
while (!task.handle.done()) {
|
||||||
co_yield {};
|
YIELD_ASC(vqid);
|
||||||
TracyFiberEnter(acb_task_name);
|
RESUME(task, acb_task_name[vqid]);
|
||||||
};
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PM4ItOpcode::DmaData: {
|
case PM4ItOpcode::DmaData: {
|
||||||
|
@ -757,11 +774,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
||||||
case PM4ItOpcode::Rewind: {
|
case PM4ItOpcode::Rewind: {
|
||||||
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
|
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
|
||||||
while (!rewind->Valid()) {
|
while (!rewind->Valid()) {
|
||||||
mapped_queues[vqid].cs_state = regs.cs_program;
|
YIELD_ASC(vqid);
|
||||||
TracyFiberLeave;
|
|
||||||
co_yield {};
|
|
||||||
TracyFiberEnter(acb_task_name);
|
|
||||||
regs.cs_program = mapped_queues[vqid].cs_state;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -803,11 +816,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
||||||
const auto* wait_reg_mem = reinterpret_cast<const PM4CmdWaitRegMem*>(header);
|
const auto* wait_reg_mem = reinterpret_cast<const PM4CmdWaitRegMem*>(header);
|
||||||
ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me);
|
ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me);
|
||||||
while (!wait_reg_mem->Test()) {
|
while (!wait_reg_mem->Test()) {
|
||||||
mapped_queues[vqid].cs_state = regs.cs_program;
|
YIELD_ASC(vqid);
|
||||||
TracyFiberLeave;
|
|
||||||
co_yield {};
|
|
||||||
TracyFiberEnter(acb_task_name);
|
|
||||||
regs.cs_program = mapped_queues[vqid].cs_state;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -824,7 +833,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
|
||||||
acb = NextPacket(acb, header->type3.NumWords() + 1);
|
acb = NextPacket(acb, header->type3.NumWords() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TracyFiberLeave;
|
FIBER_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::span<const u32>, std::span<const u32>> Liverpool::CopyCmdBuffers(
|
std::pair<std::span<const u32>, std::span<const u32>> Liverpool::CopyCmdBuffers(
|
||||||
|
@ -881,11 +890,11 @@ void Liverpool::SubmitGfx(std::span<const u32> dcb, std::span<const u32> ccb) {
|
||||||
submit_cv.notify_one();
|
submit_cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Liverpool::SubmitAsc(u32 vqid, std::span<const u32> acb) {
|
void Liverpool::SubmitAsc(u32 gnm_vqid, std::span<const u32> acb) {
|
||||||
ASSERT_MSG(vqid >= 0 && vqid < NumTotalQueues, "Invalid virtual ASC queue index");
|
ASSERT_MSG(gnm_vqid > 0 && gnm_vqid < NumTotalQueues, "Invalid virtual ASC queue index");
|
||||||
auto& queue = mapped_queues[vqid];
|
auto& queue = mapped_queues[gnm_vqid];
|
||||||
|
|
||||||
const auto& task = ProcessCompute(acb, vqid);
|
const auto& task = ProcessCompute(acb, gnm_vqid);
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{queue.m_access};
|
std::scoped_lock lock{queue.m_access};
|
||||||
queue.submits.emplace(task.handle);
|
queue.submits.emplace(task.handle);
|
||||||
|
|
|
@ -45,7 +45,8 @@ struct Liverpool {
|
||||||
static constexpr u32 NumGfxRings = 1u; // actually 2, but HP is reserved by system software
|
static constexpr u32 NumGfxRings = 1u; // actually 2, but HP is reserved by system software
|
||||||
static constexpr u32 NumComputePipes = 7u; // actually 8, but #7 is reserved by system software
|
static constexpr u32 NumComputePipes = 7u; // actually 8, but #7 is reserved by system software
|
||||||
static constexpr u32 NumQueuesPerPipe = 8u;
|
static constexpr u32 NumQueuesPerPipe = 8u;
|
||||||
static constexpr u32 NumTotalQueues = NumGfxRings + (NumComputePipes * NumQueuesPerPipe);
|
static constexpr u32 NumComputeRings = NumComputePipes * NumQueuesPerPipe;
|
||||||
|
static constexpr u32 NumTotalQueues = NumGfxRings + NumComputeRings;
|
||||||
static_assert(NumTotalQueues < 64u); // need to fit into u64 bitmap for ffs
|
static_assert(NumTotalQueues < 64u); // need to fit into u64 bitmap for ffs
|
||||||
|
|
||||||
static constexpr u32 NumColorBuffers = 8;
|
static constexpr u32 NumColorBuffers = 8;
|
||||||
|
@ -1258,7 +1259,7 @@ public:
|
||||||
~Liverpool();
|
~Liverpool();
|
||||||
|
|
||||||
void SubmitGfx(std::span<const u32> dcb, std::span<const u32> ccb);
|
void SubmitGfx(std::span<const u32> dcb, std::span<const u32> ccb);
|
||||||
void SubmitAsc(u32 vqid, std::span<const u32> acb);
|
void SubmitAsc(u32 gnm_vqid, std::span<const u32> acb);
|
||||||
|
|
||||||
void SubmitDone() noexcept {
|
void SubmitDone() noexcept {
|
||||||
std::scoped_lock lk{submit_mutex};
|
std::scoped_lock lk{submit_mutex};
|
||||||
|
|
Loading…
Reference in a new issue