2024-04-29 22:23:28 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/io_file.h"
|
2024-05-10 19:48:01 +00:00
|
|
|
#include "common/thread.h"
|
2024-04-29 22:23:28 +00:00
|
|
|
#include "video_core/amdgpu/liverpool.h"
|
|
|
|
#include "video_core/amdgpu/pm4_cmds.h"
|
|
|
|
|
|
|
|
namespace AmdGpu {
|
|
|
|
|
|
|
|
Liverpool::Liverpool() = default;
|
|
|
|
|
|
|
|
void Liverpool::ProcessCmdList(u32* cmdbuf, u32 size_in_bytes) {
|
2024-05-10 19:48:01 +00:00
|
|
|
Common::SetCurrentThreadName("CommandProcessor_Gfx");
|
|
|
|
|
2024-04-29 22:23:28 +00:00
|
|
|
auto* header = reinterpret_cast<PM4Header*>(cmdbuf);
|
|
|
|
u32 processed_cmd_size = 0;
|
|
|
|
|
|
|
|
while (processed_cmd_size < size_in_bytes) {
|
|
|
|
PM4Header* next_header{};
|
|
|
|
const u32 type = header->type;
|
|
|
|
switch (type) {
|
|
|
|
case 3: {
|
|
|
|
const PM4ItOpcode opcode = header->type3.opcode;
|
|
|
|
const u32 count = header->type3.NumWords();
|
|
|
|
switch (opcode) {
|
|
|
|
case PM4ItOpcode::Nop:
|
|
|
|
break;
|
|
|
|
case PM4ItOpcode::SetContextReg: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* set_data = reinterpret_cast<PM4CmdSetData*>(header);
|
2024-05-01 16:29:06 +00:00
|
|
|
std::memcpy(®s.reg_array[ContextRegWordOffset + set_data->reg_offset],
|
|
|
|
header + 2, (count - 1) * sizeof(u32));
|
2024-04-29 22:23:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::SetShReg: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* set_data = reinterpret_cast<PM4CmdSetData*>(header);
|
2024-05-01 16:29:06 +00:00
|
|
|
std::memcpy(®s.reg_array[ShRegWordOffset + set_data->reg_offset], header + 2,
|
2024-04-29 22:23:28 +00:00
|
|
|
(count - 1) * sizeof(u32));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::SetUconfigReg: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* set_data = reinterpret_cast<PM4CmdSetData*>(header);
|
2024-05-01 16:29:06 +00:00
|
|
|
std::memcpy(®s.reg_array[UconfigRegWordOffset + set_data->reg_offset],
|
|
|
|
header + 2, (count - 1) * sizeof(u32));
|
2024-04-29 22:23:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::IndexType: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* index_type = reinterpret_cast<PM4CmdDrawIndexType*>(header);
|
2024-04-29 22:23:28 +00:00
|
|
|
regs.index_buffer_type.raw = index_type->raw;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::DrawIndex2: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* draw_index = reinterpret_cast<PM4CmdDrawIndex2*>(header);
|
2024-05-01 16:29:06 +00:00
|
|
|
regs.max_index_size = draw_index->max_size;
|
|
|
|
regs.index_base_address.base_addr_lo = draw_index->index_base_lo;
|
|
|
|
regs.index_base_address.base_addr_hi.Assign(draw_index->index_base_hi);
|
|
|
|
regs.num_indices = draw_index->index_count;
|
|
|
|
regs.draw_initiator = draw_index->draw_initiator;
|
2024-04-29 22:23:28 +00:00
|
|
|
// rasterizer->DrawIndex();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::DrawIndexAuto: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* draw_index = reinterpret_cast<PM4CmdDrawIndexAuto*>(header);
|
2024-04-29 22:23:28 +00:00
|
|
|
regs.num_indices = draw_index->index_count;
|
|
|
|
regs.draw_initiator = draw_index->draw_initiator;
|
|
|
|
// rasterizer->DrawIndex();
|
|
|
|
break;
|
|
|
|
}
|
2024-05-08 21:27:56 +00:00
|
|
|
case PM4ItOpcode::DispatchDirect: {
|
|
|
|
// const auto* dispatch_direct = reinterpret_cast<PM4CmdDispatchDirect*>(header);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::EventWriteEos: {
|
2024-05-10 09:55:04 +00:00
|
|
|
const auto* event_eos = reinterpret_cast<PM4CmdEventWriteEos*>(header);
|
2024-05-10 19:48:01 +00:00
|
|
|
event_eos->SignalFence();
|
2024-05-08 21:27:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-04-29 22:23:28 +00:00
|
|
|
case PM4ItOpcode::EventWriteEop: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* event_eop = reinterpret_cast<PM4CmdEventWriteEop*>(header);
|
2024-05-10 19:48:01 +00:00
|
|
|
event_eop->SignalFence();
|
2024-04-29 22:23:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::DmaData: {
|
2024-05-08 21:27:56 +00:00
|
|
|
const auto* dma_data = reinterpret_cast<PM4DmaData*>(header);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::WriteData: {
|
|
|
|
const auto* write_data = reinterpret_cast<PM4CmdWriteData*>(header);
|
2024-05-09 20:59:35 +00:00
|
|
|
ASSERT(write_data->dst_sel.Value() == 2 || write_data->dst_sel.Value() == 5);
|
|
|
|
const u32 data_size = (header->type3.count.Value() - 2) * 4;
|
|
|
|
if (!write_data->wr_one_addr.Value()) {
|
2024-05-10 21:51:24 +00:00
|
|
|
std::memcpy(write_data->Address<void*>(), write_data->data, data_size);
|
2024-05-09 20:59:35 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2024-05-08 21:27:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::AcquireMem: {
|
|
|
|
// const auto* acquire_mem = reinterpret_cast<PM4CmdAcquireMem*>(header);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PM4ItOpcode::WaitRegMem: {
|
|
|
|
const auto* wait_reg_mem = reinterpret_cast<PM4CmdWaitRegMem*>(header);
|
2024-05-09 20:59:35 +00:00
|
|
|
ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me);
|
2024-05-10 19:48:01 +00:00
|
|
|
while (!wait_reg_mem->Test()) {
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
std::this_thread::sleep_for(1ms);
|
2024-05-09 20:59:35 +00:00
|
|
|
}
|
2024-04-29 22:23:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE_MSG("Unknown PM4 type 3 opcode {:#x} with count {}",
|
|
|
|
static_cast<u32>(opcode), count);
|
|
|
|
}
|
|
|
|
next_header = header + header->type3.NumWords() + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE_MSG("Invalid PM4 type {}", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
processed_cmd_size += uintptr_t(next_header) - uintptr_t(header);
|
|
|
|
header = next_header;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace AmdGpu
|