Initial Alloy implementation.

This is a regression in functionality and performance, but a much better
foundation for the future of the project (I think). It can run basic
apps under an SSA interpreter but doesn't support some of the features
required to do real 360 apps yet.
This commit is contained in:
Ben Vanik
2013-12-06 22:57:16 -08:00
parent 68b8737a58
commit fdb6a5cfa3
215 changed files with 20167 additions and 16704 deletions

View File

@@ -21,7 +21,7 @@ using namespace xe::gpu::xenos;
D3D11GraphicsDriver::D3D11GraphicsDriver(
xe_memory_ref memory, ID3D11Device* device) :
Memory* memory, ID3D11Device* device) :
GraphicsDriver(memory) {
device_ = device;
device_->AddRef();
@@ -78,7 +78,7 @@ void D3D11GraphicsDriver::SetShader(
uint32_t start,
uint32_t length) {
// Find or create shader in the cache.
uint8_t* p = xe_memory_addr(memory_, address);
uint8_t* p = memory_->Translate(address);
Shader* shader = shader_cache_->FindOrCreate(
type, p, length);
@@ -420,7 +420,7 @@ int D3D11GraphicsDriver::PrepareVertexFetcher(
XESAFERELEASE(buffer);
return 1;
}
uint32_t* src = (uint32_t*)xe_memory_addr(memory_, address);
uint32_t* src = (uint32_t*)memory_->Translate(address);
uint32_t* dest = (uint32_t*)res.pData;
for (uint32_t n = 0; n < size_dwords; n++) {
// union {
@@ -481,7 +481,7 @@ int D3D11GraphicsDriver::PrepareIndexBuffer(
D3D11_MAPPED_SUBRESOURCE res;
context_->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res);
if (index_32bit) {
uint32_t* src = (uint32_t*)xe_memory_addr(memory_, address);
uint32_t* src = (uint32_t*)memory_->Translate(address);
uint32_t* dest = (uint32_t*)res.pData;
for (uint32_t n = 0; n < index_count; n++) {
uint32_t d = { XESWAP32(src[n]) };
@@ -489,7 +489,7 @@ int D3D11GraphicsDriver::PrepareIndexBuffer(
dest[n] = d;
}
} else {
uint16_t* src = (uint16_t*)xe_memory_addr(memory_, address);
uint16_t* src = (uint16_t*)memory_->Translate(address);
uint16_t* dest = (uint16_t*)res.pData;
for (uint32_t n = 0; n < index_count; n++) {
uint16_t d = XESWAP16(src[n]);

View File

@@ -30,7 +30,7 @@ class D3D11VertexShader;
class D3D11GraphicsDriver : public GraphicsDriver {
public:
D3D11GraphicsDriver(xe_memory_ref memory, ID3D11Device* device);
D3D11GraphicsDriver(Memory* memory, ID3D11Device* device);
virtual ~D3D11GraphicsDriver();
virtual void Initialize();

View File

@@ -14,13 +14,10 @@ using namespace xe;
using namespace xe::gpu;
GraphicsDriver::GraphicsDriver(xe_memory_ref memory) :
address_translation_(0) {
memory_ = xe_memory_retain(memory);
GraphicsDriver::GraphicsDriver(Memory* memory) :
memory_(memory), address_translation_(0) {
memset(&register_file_, 0, sizeof(register_file_));
}
GraphicsDriver::~GraphicsDriver() {
xe_memory_release(memory_);
}

View File

@@ -23,7 +23,7 @@ class GraphicsDriver {
public:
virtual ~GraphicsDriver();
xe_memory_ref memory() const { return memory_; }
Memory* memory() const { return memory_; }
xenos::RegisterFile* register_file() { return &register_file_; };
void set_address_translation(uint32_t value) {
address_translation_ = value;
@@ -48,9 +48,9 @@ public:
uint32_t index_count) = 0;
protected:
GraphicsDriver(xe_memory_ref memory);
GraphicsDriver(Memory* memory);
xe_memory_ref memory_;
Memory* memory_;
xenos::RegisterFile register_file_;
uint32_t address_translation_;

View File

@@ -17,18 +17,16 @@
using namespace xe;
using namespace xe::cpu::ppc;
using namespace xe::cpu;
using namespace xe::gpu;
using namespace xe::gpu::xenos;
GraphicsSystem::GraphicsSystem(Emulator* emulator) :
emulator_(emulator),
emulator_(emulator), memory_(emulator->memory()),
thread_(0), running_(false), driver_(0), worker_(0),
interrupt_callback_(0), interrupt_callback_data_(0),
last_interrupt_time_(0), swap_pending_(false) {
memory_ = xe_memory_retain(emulator->memory());
// Create the run loop used for any windows/etc.
// This must be done on the thread we create the driver.
run_loop_ = xe_run_loop_create();
@@ -43,7 +41,6 @@ GraphicsSystem::~GraphicsSystem() {
delete worker_;
xe_run_loop_release(run_loop_);
xe_memory_release(memory_);
}
X_STATUS GraphicsSystem::Setup() {
@@ -132,11 +129,11 @@ void GraphicsSystem::EnableReadPointerWriteBack(uint32_t ptr,
worker_->EnableReadPointerWriteBack(ptr, block_size);
}
bool GraphicsSystem::HandlesRegister(uint32_t addr) {
bool GraphicsSystem::HandlesRegister(uint64_t addr) {
return (addr & 0xFFFF0000) == 0x7FC80000;
}
uint64_t GraphicsSystem::ReadRegister(uint32_t addr) {
uint64_t GraphicsSystem::ReadRegister(uint64_t addr) {
uint32_t r = addr & 0xFFFF;
XELOGGPU("ReadRegister(%.4X)", r);
@@ -155,7 +152,7 @@ uint64_t GraphicsSystem::ReadRegister(uint32_t addr) {
return regs->values[r].u32;
}
void GraphicsSystem::WriteRegister(uint32_t addr, uint64_t value) {
void GraphicsSystem::WriteRegister(uint64_t addr, uint64_t value) {
uint32_t r = addr & 0xFFFF;
XELOGGPU("WriteRegister(%.4X, %.8X)", r, value);

View File

@@ -30,7 +30,7 @@ public:
virtual ~GraphicsSystem();
Emulator* emulator() const { return emulator_; }
xe_memory_ref memory() const { return memory_; }
Memory* memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
virtual X_STATUS Setup();
@@ -39,9 +39,9 @@ public:
void InitializeRingBuffer(uint32_t ptr, uint32_t page_count);
void EnableReadPointerWriteBack(uint32_t ptr, uint32_t block_size);
bool HandlesRegister(uint32_t addr);
virtual uint64_t ReadRegister(uint32_t addr);
virtual void WriteRegister(uint32_t addr, uint64_t value);
bool HandlesRegister(uint64_t addr);
virtual uint64_t ReadRegister(uint64_t addr);
virtual void WriteRegister(uint64_t addr, uint64_t value);
void MarkVblank();
void DispatchInterruptCallback(uint32_t source, uint32_t cpu = 0xFFFFFFFF);
@@ -59,13 +59,13 @@ private:
}
void ThreadStart();
static bool HandlesRegisterThunk(GraphicsSystem* gs, uint32_t addr) {
static bool HandlesRegisterThunk(GraphicsSystem* gs, uint64_t addr) {
return gs->HandlesRegister(addr);
}
static uint64_t ReadRegisterThunk(GraphicsSystem* gs, uint32_t addr) {
static uint64_t ReadRegisterThunk(GraphicsSystem* gs, uint64_t addr) {
return gs->ReadRegister(addr);
}
static void WriteRegisterThunk(GraphicsSystem* gs, uint32_t addr,
static void WriteRegisterThunk(GraphicsSystem* gs, uint64_t addr,
uint64_t value) {
gs->WriteRegister(addr, value);
}
@@ -74,7 +74,7 @@ protected:
GraphicsSystem(Emulator* emulator);
Emulator* emulator_;
xe_memory_ref memory_;
Memory* memory_;
cpu::Processor* processor_;
xe_run_loop_ref run_loop_;

View File

@@ -19,7 +19,7 @@ using namespace xe::gpu::nop;
using namespace xe::gpu::xenos;
NopGraphicsDriver::NopGraphicsDriver(xe_memory_ref memory) :
NopGraphicsDriver::NopGraphicsDriver(Memory* memory) :
GraphicsDriver(memory) {
shader_cache_ = new ShaderCache();
}
@@ -50,7 +50,7 @@ void NopGraphicsDriver::SetShader(
uint32_t start,
uint32_t length) {
// Find or create shader in the cache.
uint8_t* p = xe_memory_addr(memory_, address);
uint8_t* p = memory_->Translate(address);
Shader* shader = shader_cache_->FindOrCreate(
type, p, length);

View File

@@ -27,7 +27,7 @@ namespace nop {
class NopGraphicsDriver : public GraphicsDriver {
public:
NopGraphicsDriver(xe_memory_ref memory);
NopGraphicsDriver(Memory* memory);
virtual ~NopGraphicsDriver();
virtual void Initialize();

View File

@@ -25,7 +25,7 @@ using namespace xe::gpu::xenos;
RingBufferWorker::RingBufferWorker(
GraphicsSystem* graphics_system, xe_memory_ref memory) :
GraphicsSystem* graphics_system, Memory* memory) :
graphics_system_(graphics_system), memory_(memory), driver_(0) {
write_ptr_index_event_ = CreateEvent(
NULL, FALSE, FALSE, NULL);
@@ -87,7 +87,7 @@ void RingBufferWorker::UpdateWritePointer(uint32_t value) {
}
void RingBufferWorker::Pump() {
uint8_t* p = xe_memory_addr(memory_);
uint8_t* p = memory_->membase();
if (write_ptr_index_ == 0xBAADF00D ||
read_ptr_index_ == write_ptr_index_) {
@@ -189,7 +189,7 @@ void RingBufferWorker::AdvancePtr(PacketArgs& args, uint32_t n) {
XEGETUINT32BE(p + args.ptr); ADVANCE_PTR(1);
uint32_t RingBufferWorker::ExecutePacket(PacketArgs& args) {
uint8_t* p = xe_memory_addr(memory_);
uint8_t* p = memory_->membase();
RegisterFile* regs = driver_->register_file();
uint32_t packet_ptr = args.ptr;
@@ -730,7 +730,7 @@ void RingBufferWorker::WriteRegister(
uint32_t scratch_reg = index - XE_GPU_REG_SCRATCH_REG0;
if ((1 << scratch_reg) & regs->values[XE_GPU_REG_SCRATCH_UMSK].u32) {
// Enabled - write to address.
uint8_t* p = xe_memory_addr(memory_);
uint8_t* p = memory_->membase();
uint32_t scratch_addr = regs->values[XE_GPU_REG_SCRATCH_ADDR].u32;
uint32_t mem_addr = scratch_addr + (scratch_reg * 4);
XESETUINT32BE(p + GpuToCpu(primary_buffer_ptr_, mem_addr), value);

View File

@@ -23,10 +23,10 @@ class GraphicsSystem;
class RingBufferWorker {
public:
RingBufferWorker(GraphicsSystem* graphics_system, xe_memory_ref memory);
RingBufferWorker(GraphicsSystem* graphics_system, Memory* memory);
virtual ~RingBufferWorker();
xe_memory_ref memory();
Memory* memory() const { return memory_; }
uint64_t QueryTime();
uint32_t counter() const { return counter_; }
@@ -54,7 +54,7 @@ private:
void WriteRegister(uint32_t packet_ptr, uint32_t index, uint32_t value);
protected:
xe_memory_ref memory_;
Memory* memory_;
GraphicsSystem* graphics_system_;
GraphicsDriver* driver_;