Skip to content

Commit

Permalink
gpu: implement compute queue
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Oct 15, 2024
1 parent 1f28918 commit 4fe8574
Show file tree
Hide file tree
Showing 12 changed files with 827 additions and 474 deletions.
1 change: 1 addition & 0 deletions orbis-kernel/include/orbis/KernelContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
Ref<RcBase> blockpoolDevice;
shared_mutex gpuDeviceMtx;
Ref<RcBase> gpuDevice;
Ref<RcBase> dceDevice;
uint sdkVersion{};
uint fwSdkVersion{};
uint safeMode{};
Expand Down
8 changes: 4 additions & 4 deletions rpcsx/gpu/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Device::Device() : vkContext(createVkContext(this)) {

for (int i = 0; i < kGfxPipeCount; ++i) {
graphicsPipes[i].setDeQueue(
Queue{
Ring{
.base = mainGfxRings[i],
.size = sizeof(mainGfxRings[i]) / sizeof(mainGfxRings[i][0]),
.rptr = mainGfxRings[i],
Expand Down Expand Up @@ -474,7 +474,7 @@ void Device::start() {
}
}

void Device::submitCommand(Queue &ring,
void Device::submitCommand(Ring &ring,
std::span<const std::uint32_t> command) {
std::scoped_lock lock(writeCommandMtx);
if (ring.wptr + command.size() > ring.base + ring.size) {
Expand Down Expand Up @@ -599,12 +599,12 @@ void Device::onCommandBuffer(std::uint32_t pid, int cmdHeader,
auto op = rx::getBits(cmdHeader, 15, 8);

if (op == gnm::IT_INDIRECT_BUFFER_CNST) {
graphicsPipes[0].setCeQueue(Queue::createFromRange(
graphicsPipes[0].setCeQueue(Ring::createFromRange(
process.vmId, memory.getPointer<std::uint32_t>(address),
size / sizeof(std::uint32_t)));
} else if (op == gnm::IT_INDIRECT_BUFFER) {
graphicsPipes[0].setDeQueue(
Queue::createFromRange(process.vmId,
Ring::createFromRange(process.vmId,
memory.getPointer<std::uint32_t>(address),
size / sizeof(std::uint32_t)),
1);
Expand Down
2 changes: 1 addition & 1 deletion rpcsx/gpu/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct Device : orbis::RcBase, DeviceContext {
return caches[vmId].createComputeTag(scheduler);
}

void submitCommand(Queue &ring, std::span<const std::uint32_t> command);
void submitCommand(Ring &ring, std::span<const std::uint32_t> command);
void submitGfxCommand(int gfxPipe, std::span<const std::uint32_t> command);

void mapProcess(std::uint32_t pid, int vmId);
Expand Down
44 changes: 44 additions & 0 deletions rpcsx/gpu/DeviceCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,49 @@ void DeviceCtl::registerBufferAttribute(std::uint32_t pid,
process.bufferAttributes[attr.attrId] = attr;
}

void DeviceCtl::mapComputeQueue(int vmId, std::uint32_t meId,
std::uint32_t pipeId, std::uint32_t queueId,
std::uint32_t vqueueId,
orbis::uint64_t ringBaseAddress,
orbis::uint64_t readPtrAddress,
orbis::uint64_t doorbell,
orbis::uint64_t ringSize) {
if (meId != 1) {
rx::die("unexpected ME %d", meId);
}

auto &pipe = mDevice->computePipes[pipeId];
auto lock = pipe.lockQueue(queueId);
auto memory = RemoteMemory{vmId};
auto base = memory.getPointer<std::uint32_t>(ringBaseAddress);
pipe.mapQueue(queueId,
Ring{
.vmId = vmId,
.indirectLevel = 0,
.doorbell = memory.getPointer<std::uint32_t>(doorbell),
.base = base,
.size = ringSize,
.rptr = base,
.wptr = base,
.rptrReportLocation =
memory.getPointer<std::uint32_t>(readPtrAddress),
},
lock);

auto config = std::bit_cast<amdgpu::Registers::ComputeConfig *>(doorbell);
config->state = 1;
}

void DeviceCtl::submitComputeQueue(std::uint32_t meId, std::uint32_t pipeId,
std::uint32_t queueId,
std::uint64_t offset) {
if (meId != 1) {
rx::die("unexpected ME %d", meId);
}

auto &pipe = mDevice->computePipes[pipeId];
pipe.submit(queueId, offset);
}

void DeviceCtl::start() { mDevice->start(); }
void DeviceCtl::waitForIdle() { mDevice->waitForIdle(); }
9 changes: 9 additions & 0 deletions rpcsx/gpu/DeviceCtl.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "DeviceContext.hpp"
#include "orbis-config.hpp"
#include "orbis/utils/Rc.hpp"
#include <cstdint>
#include <span>
Expand Down Expand Up @@ -40,6 +41,14 @@ class DeviceCtl {
std::uint64_t address, std::uint64_t size, int prot);
void registerBuffer(std::uint32_t pid, Buffer buffer);
void registerBufferAttribute(std::uint32_t pid, BufferAttribute attr);

void mapComputeQueue(int vmId, std::uint32_t meId, std::uint32_t pipeId,
std::uint32_t queueId, std::uint32_t vqueueId,
orbis::uint64_t ringBaseAddress,
orbis::uint64_t readPtrAddress, orbis::uint64_t doorbell,
orbis::uint64_t ringSize);
void submitComputeQueue(std::uint32_t meId, std::uint32_t pipeId,
std::uint32_t queueId, std::uint64_t offset);
void start();
void waitForIdle();

Expand Down
Loading

0 comments on commit 4fe8574

Please sign in to comment.