[rpcsx-gpu] Implemented swapchain

This commit is contained in:
DH 2023-06-25 16:54:49 +03:00
parent 2ab5cfb1f3
commit 1e733facaa
8 changed files with 698 additions and 490 deletions

View file

@ -7,12 +7,9 @@
namespace amdgpu::bridge {
enum class CommandId : std::uint32_t {
Nop,
SetUpSharedMemory,
ProtectMemory,
CommandBuffer,
Flip,
DoFlip,
SetBuffer
Flip
};
struct CmdMemoryProt {
@ -28,7 +25,6 @@ struct CmdCommandBuffer {
};
struct CmdBuffer {
std::uint32_t bufferIndex;
std::uint32_t width;
std::uint32_t height;
std::uint32_t pitch;
@ -106,22 +102,10 @@ struct BridgePusher {
sendCommand(CommandId::CommandBuffer, {queue, address, size});
}
void sendSetBuffer(std::uint32_t bufferIndex, std::uint64_t address,
std::uint32_t width, std::uint32_t height,
std::uint32_t pitch, std::uint32_t pixelFormat,
std::uint32_t tilingMode) {
sendCommand(CommandId::SetBuffer,
{static_cast<std::uint64_t>(bufferIndex) << 32 | tilingMode,
address, static_cast<std::uint64_t>(width) << 32 | height,
static_cast<std::uint64_t>(pitch) << 32 | pixelFormat});
}
void sendFlip(std::uint32_t bufferIndex, std::uint64_t arg) {
sendCommand(CommandId::Flip, {bufferIndex, arg});
}
void sendDoFlip() { sendCommand(CommandId::DoFlip, {}); }
void wait() {
while (header->pull != header->push)
;
@ -137,7 +121,7 @@ private:
std::size_t cmdSize = args.size() + 1;
std::uint64_t pos = getPushPosition(cmdSize);
header->commands[pos++] = makeCommandHeader(CommandId::Flip, cmdSize);
header->commands[pos++] = makeCommandHeader(id, cmdSize);
for (auto arg : args) {
header->commands[pos++] = arg;
}
@ -211,8 +195,6 @@ private:
switch (command) {
case CommandId::Nop:
case CommandId::SetUpSharedMemory:
case CommandId::DoFlip:
return result;
case CommandId::ProtectMemory:
@ -231,16 +213,6 @@ private:
result.flip.bufferIndex = args[0];
result.flip.arg = args[1];
return result;
case CommandId::SetBuffer:
result.buffer.bufferIndex = static_cast<std::uint32_t>(args[0] >> 32);
result.buffer.address = args[1];
result.buffer.width = static_cast<std::uint32_t>(args[2] >> 32);
result.buffer.height = static_cast<std::uint32_t>(args[2]);
result.buffer.pitch = static_cast<std::uint32_t>(args[3] >> 32);
result.buffer.pixelFormat = static_cast<std::uint32_t>(args[3]);
result.buffer.tilingMode = static_cast<std::uint32_t>(args[0]);
return result;
}
__builtin_trap();

View file

@ -1477,11 +1477,11 @@ void dispatch(RemoteMemory memory, DrawContext &ctxt, std::size_t dimX,
std::size_t dimY, std::size_t dimZ);
void handleCommandBuffer(RemoteMemory memory, DrawContext &ctxt,
std::uint32_t *cmds, std::uint32_t count);
void setVkDevice(VkDevice device, VkPhysicalDeviceMemoryProperties properties);
void setVkDevice(VkDevice device, VkPhysicalDeviceMemoryProperties memProperties, VkPhysicalDeviceProperties devProperties);
class AmdgpuDevice final {
amdgpu::device::DrawContext mDc;
char *internalMemory = nullptr;
struct AmdgpuDevice {
amdgpu::device::DrawContext dc;
amdgpu::bridge::BridgeHeader *bridge;
RemoteMemory memory;
std::uint64_t memorySize = 0;
int memoryFd = -1;
@ -1492,6 +1492,7 @@ class AmdgpuDevice final {
struct RenderBuffer {
void *memory;
std::uint64_t address;
std::uint32_t pitch;
std::uint32_t width;
std::uint32_t height;
@ -1511,30 +1512,15 @@ class AmdgpuDevice final {
bool flipWasRequested = false;
void handleSetUpSharedMemory(std::uint64_t address, std::uint64_t size,
std::uint64_t internalSize,
const char *name);
void handleSetFlipStatus(std::uint64_t shmOffset);
void handleProtectMemory(std::uint64_t address, std::uint64_t size,
std::uint32_t prot);
void handleCommandBuffer(std::uint64_t address, std::uint64_t size);
void handleFlip(std::uint32_t bufferIndex, std::uint64_t arg);
void handleSetBuffer(std::uint32_t bufferIndex, std::uint64_t address,
std::uint32_t width, std::uint32_t height,
std::uint32_t pitch, std::uint32_t pixelFormat,
std::uint32_t tilingMode);
void handleDoFlip();
void updateFlipStatus();
public:
AmdgpuDevice(amdgpu::device::DrawContext dc);
~AmdgpuDevice();
void handleCommands() {
// while (mBridge.processCommand(this) && !flipWasRequested) {
// ;
// }
}
bool handleFlip(std::uint32_t bufferIndex, std::uint64_t arg, VkCommandBuffer cmd, VkImage targetImage, VkExtent2D targetExtent, std::vector<VkBuffer> &usedBuffers);
AmdgpuDevice(amdgpu::device::DrawContext dc, amdgpu::bridge::BridgeHeader *bridge, RemoteMemory memory, std::uint64_t memorySize)
: dc(dc), bridge(bridge), memory(memory), memorySize(memorySize) {}
};
} // namespace amdgpu::device

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@ struct RemoteMemory {
char *shmPointer;
template <typename T = void> T *getPointer(std::uint64_t address) const {
return address ? reinterpret_cast<T *>(shmPointer + address) : nullptr;
return address ? reinterpret_cast<T *>(shmPointer + address - 0x40000) : nullptr;
}
};
} // namespace amdgpu

View file

@ -297,19 +297,19 @@ amdgpu::shader::Shader amdgpu::shader::convert(
entryBlock = scf::structurize(scfContext, entryBB);
}
std::printf("========== stage: %u, user sgprs: %zu\n", (unsigned)stage,
userSpgrs.size());
std::printf("structurized CFG:\n");
// std::printf("========== stage: %u, user sgprs: %zu\n", (unsigned)stage,
// userSpgrs.size());
// std::printf("structurized CFG:\n");
auto basicBlockPrinter = [memory](const scf::PrintOptions &opts,
unsigned depth, scf::BasicBlock *bb) {
printInstructions(opts, depth,
memory.getPointer<std::uint32_t>(bb->getAddress()),
bb->getSize());
};
// auto basicBlockPrinter = [memory](const scf::PrintOptions &opts,
// unsigned depth, scf::BasicBlock *bb) {
// printInstructions(opts, depth,
// memory.getPointer<std::uint32_t>(bb->getAddress()),
// bb->getSize());
// };
entryBlock->print({.blockPrinter = basicBlockPrinter}, 0);
std::printf("==========\n");
// entryBlock->print({.blockPrinter = basicBlockPrinter}, 0);
// std::printf("==========\n");
auto mainFunction = ctxt.createFunction(0);
mainFunction->userSgprs = userSpgrs;