Skip to content

Commit

Permalink
liverpool: Correct compute queue context switches
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelthegreat committed Dec 10, 2024
1 parent f1b23c6 commit 0a1b45c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/libraries/gnmdriver/gnmdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,7 @@ void RegisterlibSceGnmDriver(Core::Loader::SymbolsResolver* sym) {
}

if (Config::copyGPUCmdBuffers()) {
liverpool->reserveCopyBufferSpace();
liverpool->ReserveCopyBufferSpace();
}

Platform::IrqC::Instance()->Register(Platform::InterruptId::GpuIdle, ResetSubmissionLock,
Expand Down
22 changes: 17 additions & 5 deletions src/video_core/amdgpu/liverpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
auto task =
ProcessCeUpdate({indirect_buffer->Address<const u32>(), indirect_buffer->ib_size});
task.handle.resume();
while (!task.handle.done()) {
task.handle.resume();

mapped_queues[GfxQueueId].cs_state = regs.cs_program;
TracyFiberLeave;
co_yield {};
TracyFiberEnter(ccb_task_name);
regs.cs_program = mapped_queues[GfxQueueId].cs_state;
task.handle.resume();
};
break;
}
Expand All @@ -187,6 +189,7 @@ Liverpool::Task Liverpool::ProcessCeUpdate(std::span<const u32> ccb) {

Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<const u32> ccb) {
TracyFiberEnter(dcb_task_name);
mapped_queues[GfxQueueId].cs_state = regs.cs_program;

cblock.Reset();

Expand Down Expand Up @@ -583,6 +586,8 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
dma_data->dst_sel == DmaDataDst::Memory) {
// LOG_WARNING(Render_Vulkan, "GDS memory read");
const u32 data = rasterizer->ReadDataFromGds(dma_data->src_addr_lo);
std::memcpy(dma_data->DstAddress<void*>(), &data, sizeof(data));
} else if (dma_data->src_sel == DmaDataSrc::Memory &&
dma_data->dst_sel == DmaDataDst::Memory) {
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
Expand Down Expand Up @@ -663,10 +668,12 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}

TracyFiberLeave;
regs.cs_program = mapped_queues[GfxQueueId].cs_state;
}

Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
TracyFiberEnter(acb_task_name);
regs.cs_program = mapped_queues[vqid].cs_state;

auto base_addr = reinterpret_cast<uintptr_t>(acb.data());
while (!acb.empty()) {
Expand All @@ -689,12 +696,14 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
const auto* indirect_buffer = reinterpret_cast<const PM4CmdIndirectBuffer*>(header);
auto task = ProcessCompute(
{indirect_buffer->Address<const u32>(), indirect_buffer->ib_size}, vqid);
task.handle.resume();
while (!task.handle.done()) {
task.handle.resume();

mapped_queues[vqid].cs_state = regs.cs_program;
TracyFiberLeave;
co_yield {};
TracyFiberEnter(acb_task_name);
regs.cs_program = mapped_queues[vqid].cs_state;
task.handle.resume();
};
break;
}
Expand All @@ -716,6 +725,8 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
dma_data->dst_sel == DmaDataDst::Memory) {
// LOG_WARNING(Render_Vulkan, "GDS memory read");
const u32 data = rasterizer->ReadDataFromGds(dma_data->src_addr_lo);
std::memcpy(dma_data->DstAddress<void*>(), &data, sizeof(data));
} else if (dma_data->src_sel == DmaDataSrc::Memory &&
dma_data->dst_sel == DmaDataDst::Memory) {
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
Expand Down Expand Up @@ -789,6 +800,7 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, int vqid) {
acb = NextPacket(acb, header->type3.NumWords() + 1);
}

mapped_queues[vqid].cs_state = regs.cs_program;
TracyFiberLeave;
}

Expand Down Expand Up @@ -847,7 +859,7 @@ void Liverpool::SubmitGfx(std::span<const u32> dcb, std::span<const u32> ccb) {
}

void Liverpool::SubmitAsc(u32 vqid, std::span<const u32> acb) {
ASSERT_MSG(vqid >= 0 && vqid < NumTotalQueues, "Invalid virtual ASC queue index");
ASSERT_MSG(vqid > 0 && vqid < NumTotalQueues, "Invalid virtual ASC queue index");
auto& queue = mapped_queues[vqid];

const auto& task = ProcessCompute(acb, vqid);
Expand Down
2 changes: 1 addition & 1 deletion src/video_core/amdgpu/liverpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ struct Liverpool {
submit_cv.notify_one();
}

void reserveCopyBufferSpace() {
void ReserveCopyBufferSpace() {
GpuQueue& gfx_queue = mapped_queues[GfxQueueId];
std::scoped_lock<std::mutex> lk(gfx_queue.m_access);

Expand Down

0 comments on commit 0a1b45c

Please sign in to comment.