Rewriting memory manager.
This commit is contained in:
@@ -456,7 +456,7 @@ void CommandProcessor::EnableReadPointerWriteBack(uint32_t ptr,
|
||||
uint32_t block_size) {
|
||||
// CP_RB_RPTR_ADDR Ring Buffer Read Pointer Address 0x70C
|
||||
// ptr = RB_RPTR_ADDR, pointer to write back the address to.
|
||||
read_ptr_writeback_ptr_ = (primary_buffer_ptr_ & ~0x1FFFFFFF) + ptr;
|
||||
read_ptr_writeback_ptr_ = ptr;
|
||||
// CP_RB_CNTL Ring Buffer Control 0x704
|
||||
// block_size = RB_BLKSZ, number of quadwords read between updates of the
|
||||
// read pointer.
|
||||
@@ -966,7 +966,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingbufferReader* reader,
|
||||
bool CommandProcessor::ExecutePacketType3_INDIRECT_BUFFER(
|
||||
RingbufferReader* reader, uint32_t packet, uint32_t count) {
|
||||
// indirect buffer dispatch
|
||||
uint32_t list_ptr = reader->Read();
|
||||
uint32_t list_ptr = CpuToGpu(reader->Read());
|
||||
uint32_t list_length = reader->Read();
|
||||
ExecuteIndirectBuffer(GpuToCpu(list_ptr), list_length);
|
||||
return true;
|
||||
@@ -993,7 +993,7 @@ bool CommandProcessor::ExecutePacketType3_WAIT_REG_MEM(RingbufferReader* reader,
|
||||
poll_reg_addr &= ~0x3;
|
||||
value = xe::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
|
||||
value = GpuSwap(value, endianness);
|
||||
trace_writer_.WriteMemoryRead(poll_reg_addr, 4);
|
||||
trace_writer_.WriteMemoryRead(CpuToGpu(poll_reg_addr), 4);
|
||||
} else {
|
||||
// Register.
|
||||
assert_true(poll_reg_addr < RegisterFile::kRegisterCount);
|
||||
@@ -1093,7 +1093,7 @@ bool CommandProcessor::ExecutePacketType3_COND_WRITE(RingbufferReader* reader,
|
||||
// Memory.
|
||||
auto endianness = static_cast<Endian>(poll_reg_addr & 0x3);
|
||||
poll_reg_addr &= ~0x3;
|
||||
trace_writer_.WriteMemoryRead(poll_reg_addr, 4);
|
||||
trace_writer_.WriteMemoryRead(CpuToGpu(poll_reg_addr), 4);
|
||||
value = xe::load<uint32_t>(memory_->TranslatePhysical(poll_reg_addr));
|
||||
value = GpuSwap(value, endianness);
|
||||
} else {
|
||||
@@ -1136,7 +1136,7 @@ bool CommandProcessor::ExecutePacketType3_COND_WRITE(RingbufferReader* reader,
|
||||
write_reg_addr &= ~0x3;
|
||||
write_data = GpuSwap(write_data, endianness);
|
||||
xe::store(memory_->TranslatePhysical(write_reg_addr), write_data);
|
||||
trace_writer_.WriteMemoryWrite(write_reg_addr, 4);
|
||||
trace_writer_.WriteMemoryWrite(CpuToGpu(write_reg_addr), 4);
|
||||
} else {
|
||||
// Register.
|
||||
WriteRegister(write_reg_addr, write_data);
|
||||
@@ -1182,7 +1182,7 @@ bool CommandProcessor::ExecutePacketType3_EVENT_WRITE_SHD(
|
||||
address &= ~0x3;
|
||||
data_value = GpuSwap(data_value, endianness);
|
||||
xe::store(memory_->TranslatePhysical(address), data_value);
|
||||
trace_writer_.WriteMemoryWrite(address, 4);
|
||||
trace_writer_.WriteMemoryWrite(CpuToGpu(address), 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1208,7 +1208,7 @@ bool CommandProcessor::ExecutePacketType3_EVENT_WRITE_EXT(
|
||||
xe::copy_and_swap_16_aligned(
|
||||
reinterpret_cast<uint16_t*>(memory_->TranslatePhysical(address)), extents,
|
||||
xe::countof(extents));
|
||||
trace_writer_.WriteMemoryWrite(address, sizeof(extents));
|
||||
trace_writer_.WriteMemoryWrite(CpuToGpu(address), sizeof(extents));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1364,7 +1364,7 @@ bool CommandProcessor::ExecutePacketType3_LOAD_ALU_CONSTANT(
|
||||
assert_always();
|
||||
return true;
|
||||
}
|
||||
trace_writer_.WriteMemoryRead(address, size_dwords * 4);
|
||||
trace_writer_.WriteMemoryRead(CpuToGpu(address), size_dwords * 4);
|
||||
for (uint32_t n = 0; n < size_dwords; n++, index++) {
|
||||
uint32_t data = xe::load_and_swap<uint32_t>(
|
||||
memory_->TranslatePhysical(address + n * 4));
|
||||
@@ -1395,7 +1395,7 @@ bool CommandProcessor::ExecutePacketType3_IM_LOAD(RingbufferReader* reader,
|
||||
uint32_t start = start_size >> 16;
|
||||
uint32_t size_dwords = start_size & 0xFFFF; // dwords
|
||||
assert_true(start == 0);
|
||||
trace_writer_.WriteMemoryRead(addr, size_dwords * 4);
|
||||
trace_writer_.WriteMemoryRead(CpuToGpu(addr), size_dwords * 4);
|
||||
LoadShader(shader_type, addr, memory_->TranslatePhysical<uint32_t*>(addr),
|
||||
size_dwords);
|
||||
return true;
|
||||
@@ -2106,29 +2106,31 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateBlendState() {
|
||||
|
||||
draw_batcher_.Flush(DrawBatcher::FlushMode::kStateChange);
|
||||
|
||||
static const GLenum blend_map[] = {/* 0 */ GL_ZERO,
|
||||
/* 1 */ GL_ONE,
|
||||
/* 2 */ GL_ZERO, // ?
|
||||
/* 3 */ GL_ZERO, // ?
|
||||
/* 4 */ GL_SRC_COLOR,
|
||||
/* 5 */ GL_ONE_MINUS_SRC_COLOR,
|
||||
/* 6 */ GL_SRC_ALPHA,
|
||||
/* 7 */ GL_ONE_MINUS_SRC_ALPHA,
|
||||
/* 8 */ GL_DST_COLOR,
|
||||
/* 9 */ GL_ONE_MINUS_DST_COLOR,
|
||||
/* 10 */ GL_DST_ALPHA,
|
||||
/* 11 */ GL_ONE_MINUS_DST_ALPHA,
|
||||
/* 12 */ GL_CONSTANT_COLOR,
|
||||
/* 13 */ GL_ONE_MINUS_CONSTANT_COLOR,
|
||||
/* 14 */ GL_CONSTANT_ALPHA,
|
||||
/* 15 */ GL_ONE_MINUS_CONSTANT_ALPHA,
|
||||
/* 16 */ GL_SRC_ALPHA_SATURATE,
|
||||
static const GLenum blend_map[] = {
|
||||
/* 0 */ GL_ZERO,
|
||||
/* 1 */ GL_ONE,
|
||||
/* 2 */ GL_ZERO, // ?
|
||||
/* 3 */ GL_ZERO, // ?
|
||||
/* 4 */ GL_SRC_COLOR,
|
||||
/* 5 */ GL_ONE_MINUS_SRC_COLOR,
|
||||
/* 6 */ GL_SRC_ALPHA,
|
||||
/* 7 */ GL_ONE_MINUS_SRC_ALPHA,
|
||||
/* 8 */ GL_DST_COLOR,
|
||||
/* 9 */ GL_ONE_MINUS_DST_COLOR,
|
||||
/* 10 */ GL_DST_ALPHA,
|
||||
/* 11 */ GL_ONE_MINUS_DST_ALPHA,
|
||||
/* 12 */ GL_CONSTANT_COLOR,
|
||||
/* 13 */ GL_ONE_MINUS_CONSTANT_COLOR,
|
||||
/* 14 */ GL_CONSTANT_ALPHA,
|
||||
/* 15 */ GL_ONE_MINUS_CONSTANT_ALPHA,
|
||||
/* 16 */ GL_SRC_ALPHA_SATURATE,
|
||||
};
|
||||
static const GLenum blend_op_map[] = {/* 0 */ GL_FUNC_ADD,
|
||||
/* 1 */ GL_FUNC_SUBTRACT,
|
||||
/* 2 */ GL_MIN,
|
||||
/* 3 */ GL_MAX,
|
||||
/* 4 */ GL_FUNC_REVERSE_SUBTRACT,
|
||||
static const GLenum blend_op_map[] = {
|
||||
/* 0 */ GL_FUNC_ADD,
|
||||
/* 1 */ GL_FUNC_SUBTRACT,
|
||||
/* 2 */ GL_MIN,
|
||||
/* 3 */ GL_MAX,
|
||||
/* 4 */ GL_FUNC_REVERSE_SUBTRACT,
|
||||
};
|
||||
for (int i = 0; i < xe::countof(regs.rb_blendcontrol); ++i) {
|
||||
uint32_t blend_control = regs.rb_blendcontrol[i];
|
||||
@@ -2181,23 +2183,25 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateDepthStencilState() {
|
||||
|
||||
draw_batcher_.Flush(DrawBatcher::FlushMode::kStateChange);
|
||||
|
||||
static const GLenum compare_func_map[] = {/* 0 */ GL_NEVER,
|
||||
/* 1 */ GL_LESS,
|
||||
/* 2 */ GL_EQUAL,
|
||||
/* 3 */ GL_LEQUAL,
|
||||
/* 4 */ GL_GREATER,
|
||||
/* 5 */ GL_NOTEQUAL,
|
||||
/* 6 */ GL_GEQUAL,
|
||||
/* 7 */ GL_ALWAYS,
|
||||
static const GLenum compare_func_map[] = {
|
||||
/* 0 */ GL_NEVER,
|
||||
/* 1 */ GL_LESS,
|
||||
/* 2 */ GL_EQUAL,
|
||||
/* 3 */ GL_LEQUAL,
|
||||
/* 4 */ GL_GREATER,
|
||||
/* 5 */ GL_NOTEQUAL,
|
||||
/* 6 */ GL_GEQUAL,
|
||||
/* 7 */ GL_ALWAYS,
|
||||
};
|
||||
static const GLenum stencil_op_map[] = {/* 0 */ GL_KEEP,
|
||||
/* 1 */ GL_ZERO,
|
||||
/* 2 */ GL_REPLACE,
|
||||
/* 3 */ GL_INCR_WRAP,
|
||||
/* 4 */ GL_DECR_WRAP,
|
||||
/* 5 */ GL_INVERT,
|
||||
/* 6 */ GL_INCR,
|
||||
/* 7 */ GL_DECR,
|
||||
static const GLenum stencil_op_map[] = {
|
||||
/* 0 */ GL_KEEP,
|
||||
/* 1 */ GL_ZERO,
|
||||
/* 2 */ GL_REPLACE,
|
||||
/* 3 */ GL_INCR_WRAP,
|
||||
/* 4 */ GL_DECR_WRAP,
|
||||
/* 5 */ GL_INVERT,
|
||||
/* 6 */ GL_INCR,
|
||||
/* 7 */ GL_DECR,
|
||||
};
|
||||
// A2XX_RB_DEPTHCONTROL_Z_ENABLE
|
||||
if (regs.rb_depthcontrol & 0x00000002) {
|
||||
|
||||
@@ -74,7 +74,7 @@ X_STATUS GL4GraphicsSystem::Setup(cpu::Processor* processor,
|
||||
[this](const SwapParameters& swap_params) { SwapHandler(swap_params); });
|
||||
|
||||
// Let the processor know we want register access callbacks.
|
||||
memory_->AddMappedRange(
|
||||
memory_->AddVirtualMappedRange(
|
||||
0x7FC80000, 0xFFFF0000, 0x0000FFFF, this,
|
||||
reinterpret_cast<cpu::MMIOReadCallback>(MMIOReadRegisterThunk),
|
||||
reinterpret_cast<cpu::MMIOWriteCallback>(MMIOWriteRegisterThunk));
|
||||
@@ -275,7 +275,7 @@ void GL4GraphicsSystem::SwapHandler(const SwapParameters& swap_params) {
|
||||
});
|
||||
}
|
||||
|
||||
uint64_t GL4GraphicsSystem::ReadRegister(uint64_t addr) {
|
||||
uint64_t GL4GraphicsSystem::ReadRegister(uint32_t addr) {
|
||||
uint32_t r = addr & 0xFFFF;
|
||||
|
||||
switch (r) {
|
||||
@@ -295,7 +295,7 @@ uint64_t GL4GraphicsSystem::ReadRegister(uint64_t addr) {
|
||||
return register_file_.values[r].u32;
|
||||
}
|
||||
|
||||
void GL4GraphicsSystem::WriteRegister(uint64_t addr, uint64_t value) {
|
||||
void GL4GraphicsSystem::WriteRegister(uint32_t addr, uint64_t value) {
|
||||
uint32_t r = addr & 0xFFFF;
|
||||
|
||||
switch (r) {
|
||||
|
||||
@@ -50,13 +50,13 @@ class GL4GraphicsSystem : public GraphicsSystem {
|
||||
private:
|
||||
void MarkVblank();
|
||||
void SwapHandler(const SwapParameters& swap_params);
|
||||
uint64_t ReadRegister(uint64_t addr);
|
||||
void WriteRegister(uint64_t addr, uint64_t value);
|
||||
uint64_t ReadRegister(uint32_t addr);
|
||||
void WriteRegister(uint32_t addr, uint64_t value);
|
||||
|
||||
static uint64_t MMIOReadRegisterThunk(GL4GraphicsSystem* gs, uint64_t addr) {
|
||||
static uint64_t MMIOReadRegisterThunk(GL4GraphicsSystem* gs, uint32_t addr) {
|
||||
return gs->ReadRegister(addr);
|
||||
}
|
||||
static void MMIOWriteRegisterThunk(GL4GraphicsSystem* gs, uint64_t addr,
|
||||
static void MMIOWriteRegisterThunk(GL4GraphicsSystem* gs, uint32_t addr,
|
||||
uint64_t value) {
|
||||
gs->WriteRegister(addr, value);
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ TextureCache::TextureEntry* TextureCache::LookupOrInsertTexture(
|
||||
// Add a write watch. If any data in the given range is touched we'll get a
|
||||
// callback and evict the texture. We could reuse the storage, though the
|
||||
// driver is likely in a better position to pool that kind of stuff.
|
||||
entry->write_watch_handle = memory_->AddWriteWatch(
|
||||
entry->write_watch_handle = memory_->AddPhysicalWriteWatch(
|
||||
texture_info.guest_address, texture_info.input_length,
|
||||
[](void* context_ptr, void* data_ptr, uint32_t address) {
|
||||
auto self = reinterpret_cast<TextureCache*>(context_ptr);
|
||||
@@ -735,7 +735,8 @@ bool TextureCache::UploadTexture2D(GLuint texture,
|
||||
auto bpp = (bytes_per_block >> 2) +
|
||||
((bytes_per_block >> 1) >> (bytes_per_block >> 2));
|
||||
for (uint32_t y = 0, output_base_offset = 0;
|
||||
y < texture_info.size_2d.block_height;
|
||||
y < std::min(texture_info.size_2d.block_height,
|
||||
texture_info.size_2d.logical_height);
|
||||
y++, output_base_offset += texture_info.size_2d.output_pitch) {
|
||||
auto input_base_offset = TextureInfo::TiledOffset2DOuter(
|
||||
offset_y + y, (texture_info.size_2d.input_width /
|
||||
|
||||
@@ -771,7 +771,15 @@ class TracePlayer : public TraceReader {
|
||||
: loop_(loop),
|
||||
graphics_system_(graphics_system),
|
||||
current_frame_index_(0),
|
||||
current_command_index_(-1) {}
|
||||
current_command_index_(-1) {
|
||||
// Need to allocate all of physical memory so that we can write to it
|
||||
// during playback.
|
||||
graphics_system_->memory()
|
||||
->LookupHeapByType(true, 4096)
|
||||
->AllocFixed(0, 0x1FFFFFFF, 4096,
|
||||
kMemoryAllocationReserve | kMemoryAllocationCommit,
|
||||
kMemoryProtectRead | kMemoryProtectWrite);
|
||||
}
|
||||
~TracePlayer() = default;
|
||||
|
||||
GraphicsSystem* graphics_system() const { return graphics_system_; }
|
||||
|
||||
Reference in New Issue
Block a user