From 611d3bbbeb3520fffdcabf34b120cf6f87af3c78 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 9 Oct 2013 23:18:22 -0700 Subject: [PATCH] Adding in D3D11 GPU skeleton. --- src/xenia/gpu/d3d11/d3d11_graphics_driver.cc | 88 ++++++++++++++++++++ src/xenia/gpu/d3d11/d3d11_graphics_driver.h | 52 ++++++++++++ src/xenia/gpu/d3d11/d3d11_graphics_system.cc | 11 +-- src/xenia/gpu/d3d11/d3d11_graphics_system.h | 3 +- src/xenia/gpu/d3d11/sources.gypi | 2 + src/xenia/gpu/gpu-private.h | 2 +- src/xenia/gpu/gpu.cc | 48 ++++++++--- src/xenia/gpu/gpu.h | 5 ++ src/xenia/gpu/nop/nop_graphics_driver.cc | 11 ++- src/xenia/gpu/sources.gypi | 2 +- 10 files changed, 198 insertions(+), 26 deletions(-) create mode 100644 src/xenia/gpu/d3d11/d3d11_graphics_driver.cc create mode 100644 src/xenia/gpu/d3d11/d3d11_graphics_driver.h diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc new file mode 100644 index 000000000..4d8021e07 --- /dev/null +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.cc @@ -0,0 +1,88 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include + +#include +#include + + +using namespace xe; +using namespace xe::gpu; +using namespace xe::gpu::d3d11; +using namespace xe::gpu::xenos; + + +D3D11GraphicsDriver::D3D11GraphicsDriver(xe_memory_ref memory) : + GraphicsDriver(memory) { +} + +D3D11GraphicsDriver::~D3D11GraphicsDriver() { +} + +void D3D11GraphicsDriver::Initialize() { +} + +void D3D11GraphicsDriver::InvalidateState( + uint32_t mask) { + if (mask == XE_GPU_INVALIDATE_MASK_ALL) { + XELOGGPU("D3D11: (invalidate all)"); + } + if (mask & XE_GPU_INVALIDATE_MASK_VERTEX_SHADER) { + XELOGGPU("D3D11: invalidate vertex shader"); + } + if (mask & XE_GPU_INVALIDATE_MASK_PIXEL_SHADER) { + XELOGGPU("D3D11: invalidate pixel shader"); + } +} + +void D3D11GraphicsDriver::SetShader( + XE_GPU_SHADER_TYPE type, + uint32_t address, + uint32_t start, + uint32_t length) { + // Swap shader words. + uint32_t dword_count = length / 4; + XEASSERT(dword_count <= 512); + if (dword_count > 512) { + XELOGGPU("D3D11: ignoring shader %d at %0.8X (%db): too long", + type, address, length); + return; + } + uint8_t* p = xe_memory_addr(memory_, address); + uint32_t dwords[512] = {0}; + for (uint32_t n = 0; n < dword_count; n++) { + dwords[n] = XEGETUINT32BE(p + n * 4); + } + + // Disassemble. + const char* source = DisassembleShader(type, dwords, dword_count); + if (!source) { + source = ""; + } + XELOGGPU("D3D11: set shader %d at %0.8X (%db):\n%s", + type, address, length, source); + if (source) { + xe_free((void*)source); + } +} + +void D3D11GraphicsDriver::DrawIndexed( + XE_GPU_PRIMITIVE_TYPE prim_type, + uint32_t index_count) { + XELOGGPU("D3D11: draw indexed %d (%d indicies)", + prim_type, index_count); + + // TODO(benvanik): + // program control + // context misc + // interpolator control + // shader constants / bools / integers + // fetch constants +} diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_driver.h b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h new file mode 100644 index 000000000..12529dbed --- /dev/null +++ b/src/xenia/gpu/d3d11/d3d11_graphics_driver.h @@ -0,0 +1,52 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2013 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_GPU_D3D11_D3D11_GRAPHICS_DRIVER_H_ +#define XENIA_GPU_D3D11_D3D11_GRAPHICS_DRIVER_H_ + +#include + +#include +#include +#include + + +namespace xe { +namespace gpu { +namespace d3d11 { + + +class D3D11GraphicsDriver : public GraphicsDriver { +public: + D3D11GraphicsDriver(xe_memory_ref memory); + virtual ~D3D11GraphicsDriver(); + + virtual void Initialize(); + + virtual void InvalidateState( + uint32_t mask); + virtual void SetShader( + xenos::XE_GPU_SHADER_TYPE type, + uint32_t address, + uint32_t start, + uint32_t length); + virtual void DrawIndexed( + xenos::XE_GPU_PRIMITIVE_TYPE prim_type, + uint32_t index_count); + +protected: +}; + + +} // namespace d3d11 +} // namespace gpu +} // namespace xe + + +#endif // XENIA_GPU_D3D11_D3D11_GRAPHICS_DRIVER_H_ diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc index b5df269e9..210ea7bc4 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.cc +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.cc @@ -10,6 +10,7 @@ #include #include +#include using namespace xe; @@ -24,11 +25,7 @@ D3D11GraphicsSystem::D3D11GraphicsSystem(const CreationParams* params) : D3D11GraphicsSystem::~D3D11GraphicsSystem() { } -uint64_t D3D11GraphicsSystem::ReadRegister(uint32_t r) { - XELOGGPU("ReadRegister(%.4X)", r); - return 0; -} - -void D3D11GraphicsSystem::WriteRegister(uint32_t r, uint64_t value) { - XELOGGPU("WriteRegister(%.4X, %.8X)", r, value); +void D3D11GraphicsSystem::Initialize() { + XEASSERTNULL(driver_); + driver_ = new D3D11GraphicsDriver(memory_); } diff --git a/src/xenia/gpu/d3d11/d3d11_graphics_system.h b/src/xenia/gpu/d3d11/d3d11_graphics_system.h index cc7e1b4cc..6684c7960 100644 --- a/src/xenia/gpu/d3d11/d3d11_graphics_system.h +++ b/src/xenia/gpu/d3d11/d3d11_graphics_system.h @@ -29,8 +29,7 @@ public: D3D11GraphicsSystem(const CreationParams* params); virtual ~D3D11GraphicsSystem(); - virtual uint64_t ReadRegister(uint32_t r); - virtual void WriteRegister(uint32_t r, uint64_t value); + virtual void Initialize(); }; diff --git a/src/xenia/gpu/d3d11/sources.gypi b/src/xenia/gpu/d3d11/sources.gypi index d30840704..4a87b9e54 100644 --- a/src/xenia/gpu/d3d11/sources.gypi +++ b/src/xenia/gpu/d3d11/sources.gypi @@ -4,6 +4,8 @@ 'd3d11-private.h', 'd3d11.cc', 'd3d11.h', + 'd3d11_graphics_driver.cc', + 'd3d11_graphics_driver.h', 'd3d11_graphics_system.cc', 'd3d11_graphics_system.h', ], diff --git a/src/xenia/gpu/gpu-private.h b/src/xenia/gpu/gpu-private.h index e0b177a62..89ebdffaa 100644 --- a/src/xenia/gpu/gpu-private.h +++ b/src/xenia/gpu/gpu-private.h @@ -13,7 +13,7 @@ #include -// DECLARE_ flags here +DECLARE_string(gpu); #endif // XENIA_GPU_PRIVATE_H_ diff --git a/src/xenia/gpu/gpu.cc b/src/xenia/gpu/gpu.cc index 42b95a055..0c8b4fb20 100644 --- a/src/xenia/gpu/gpu.cc +++ b/src/xenia/gpu/gpu.cc @@ -10,27 +10,49 @@ #include #include -#if XE_PLATFORM(WIN32) -//#include -#endif // WIN32 -#include using namespace xe; using namespace xe::gpu; -// DEFINE_ flags here. +DEFINE_string(gpu, "any", + "Graphics system. Use: [any, nop, d3d11]"); -GraphicsSystem* xe::gpu::Create(const CreationParams* params) { - // TODO(benvanik): use flags to determine system, check support, etc. - return xe::gpu::nop::Create(params); -// #if XE_PLATFORM(WIN32) -// return xe::gpu::d3d11::Create(params); -// #endif // WIN32 -} - +#include GraphicsSystem* xe::gpu::CreateNop(const CreationParams* params) { return xe::gpu::nop::Create(params); } + + +#if XE_PLATFORM(WIN32) +#include +GraphicsSystem* xe::gpu::CreateD3D11(const CreationParams* params) { + return xe::gpu::d3d11::Create(params); +} +#endif // WIN32 + + +GraphicsSystem* xe::gpu::Create(const CreationParams* params) { + if (FLAGS_gpu.compare("nop") == 0) { + return CreateNop(params); +#if XE_PLATFORM(WIN32) + } else if (FLAGS_gpu.compare("d3d11") == 0) { + return CreateD3D11(params); +#endif // WIN32 + } else { + // Create best available. + GraphicsSystem* best = NULL; + +#if XE_PLATFORM(WIN32) + best = CreateD3D11(params); + if (best) { + return best; + } +#endif // WIN32 + + // Fallback to nop. + return CreateNop(params); + } +} diff --git a/src/xenia/gpu/gpu.h b/src/xenia/gpu/gpu.h index 7dd9f6e3f..1b5342846 100644 --- a/src/xenia/gpu/gpu.h +++ b/src/xenia/gpu/gpu.h @@ -18,8 +18,13 @@ namespace gpu { GraphicsSystem* Create(const CreationParams* params); + GraphicsSystem* CreateNop(const CreationParams* params); +#if XE_PLATFORM(WIN32) +GraphicsSystem* CreateD3D11(const CreationParams* params); +#endif // WIN32 + } // namespace gpu } // namespace xe diff --git a/src/xenia/gpu/nop/nop_graphics_driver.cc b/src/xenia/gpu/nop/nop_graphics_driver.cc index c9718e0a0..b20a78db7 100644 --- a/src/xenia/gpu/nop/nop_graphics_driver.cc +++ b/src/xenia/gpu/nop/nop_graphics_driver.cc @@ -76,6 +76,13 @@ void NopGraphicsDriver::SetShader( void NopGraphicsDriver::DrawIndexed( XE_GPU_PRIMITIVE_TYPE prim_type, uint32_t index_count) { - XELOGGPU("NOP: draw indexed %d (%d indicies)", - prim_type, index_count); + XELOGGPU("NOP: draw indexed %d (%d indicies)", + prim_type, index_count); + + // TODO(benvanik): + // program control + // context misc + // interpolator control + // shader constants / bools / integers + // fetch constants } diff --git a/src/xenia/gpu/sources.gypi b/src/xenia/gpu/sources.gypi index 554316a0a..8d0443eb2 100644 --- a/src/xenia/gpu/sources.gypi +++ b/src/xenia/gpu/sources.gypi @@ -21,7 +21,7 @@ 'conditions': [ ['OS == "win"', { 'includes': [ - #'d3d11/sources.gypi', + 'd3d11/sources.gypi', ], }], ],