From 883126d497ed8c70297b368286fd20a9d1d0f1c3 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 27 Jun 2015 09:11:03 -0700 Subject: [PATCH] Simplifying GPU creation. Part of #296. --- libxenia.vcxproj | 3 --- libxenia.vcxproj.filters | 9 ------- src/xenia/emulator.cc | 4 +-- src/xenia/gpu/gl4/gl4_gpu-private.h | 12 --------- src/xenia/gpu/gl4/gl4_gpu.cc | 33 ------------------------ src/xenia/gpu/gl4/gl4_gpu.h | 27 ------------------- src/xenia/gpu/gl4/gl4_graphics_system.cc | 22 ++++++++++++++++ src/xenia/gpu/gl4/gl4_graphics_system.h | 2 ++ src/xenia/gpu/gpu-private.h | 6 ++--- src/xenia/gpu/gpu.cc | 27 ------------------- src/xenia/gpu/gpu.h | 29 --------------------- src/xenia/gpu/graphics_system.cc | 20 ++++++++++++++ src/xenia/gpu/graphics_system.h | 7 +++++ 13 files changed, 56 insertions(+), 145 deletions(-) delete mode 100644 src/xenia/gpu/gl4/gl4_gpu.h delete mode 100644 src/xenia/gpu/gpu.h diff --git a/libxenia.vcxproj b/libxenia.vcxproj index b3dce1255..efc72cbe9 100644 --- a/libxenia.vcxproj +++ b/libxenia.vcxproj @@ -329,7 +329,6 @@ - @@ -375,7 +374,6 @@ - @@ -384,7 +382,6 @@ - diff --git a/libxenia.vcxproj.filters b/libxenia.vcxproj.filters index 9ff5950a3..1606185fd 100644 --- a/libxenia.vcxproj.filters +++ b/libxenia.vcxproj.filters @@ -840,9 +840,6 @@ src\xenia\base - - src\xenia\cpu - src\xenia\cpu @@ -1062,9 +1059,6 @@ src\xenia\cpu\compiler\passes - - src\xenia\gpu - src\xenia\gpu @@ -1116,9 +1110,6 @@ src\xenia\gpu\gl4 - - src\xenia\gpu\gl4 - src\xenia\gpu\gl4 diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index a2d9a70ea..9ecc8c95d 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -15,7 +15,7 @@ #include "xenia/base/assert.h" #include "xenia/base/clock.h" #include "xenia/base/string.h" -#include "xenia/gpu/gpu.h" +#include "xenia/gpu/graphics_system.h" #include "xenia/hid/hid.h" #include "xenia/kernel/kernel.h" #include "xenia/kernel/kernel_state.h" @@ -121,7 +121,7 @@ X_STATUS Emulator::Setup() { xma_decoder_ = std::move(std::make_unique(this)); // Initialize the GPU. - graphics_system_ = std::move(xe::gpu::Create(this)); + graphics_system_ = std::move(xe::gpu::GraphicsSystem::Create(this)); if (!graphics_system_) { return X_STATUS_NOT_IMPLEMENTED; } diff --git a/src/xenia/gpu/gl4/gl4_gpu-private.h b/src/xenia/gpu/gl4/gl4_gpu-private.h index 1306cda2b..84bf94b96 100644 --- a/src/xenia/gpu/gl4/gl4_gpu-private.h +++ b/src/xenia/gpu/gl4/gl4_gpu-private.h @@ -12,8 +12,6 @@ #include -#include "xenia/gpu/gl4/gl4_gpu.h" - DECLARE_bool(thread_safe_gl); DECLARE_bool(disable_gl_context_reset); @@ -28,14 +26,4 @@ DECLARE_bool(disable_textures); #define FINE_GRAINED_DRAW_SCOPES 0 -namespace xe { -namespace gpu { -namespace gl4 { - -// - -} // namespace gl4 -} // namespace gpu -} // namespace xe - #endif // XENIA_GPU_GL4_GL4_GPU_PRIVATE_H_ diff --git a/src/xenia/gpu/gl4/gl4_gpu.cc b/src/xenia/gpu/gl4/gl4_gpu.cc index 0ace4447f..f6e4d71b9 100644 --- a/src/xenia/gpu/gl4/gl4_gpu.cc +++ b/src/xenia/gpu/gl4/gl4_gpu.cc @@ -7,10 +7,7 @@ ****************************************************************************** */ -#include "xenia/gpu/gl4/gl4_gpu.h" - #include "xenia/gpu/gl4/gl4_gpu-private.h" -#include "xenia/gpu/gl4/gl4_graphics_system.h" DEFINE_bool(thread_safe_gl, false, "Only allow one GL context to be active at a time."); @@ -30,33 +27,3 @@ DEFINE_bool(vendor_gl_extensions, false, DEFINE_bool(disable_framebuffer_readback, false, "Disable framebuffer readback."); DEFINE_bool(disable_textures, false, "Disable textures and use colors only."); - -namespace xe { -namespace gpu { -namespace gl4 { - -void InitializeIfNeeded(); -void CleanupOnShutdown(); - -void InitializeIfNeeded() { - static bool has_initialized = false; - if (has_initialized) { - return; - } - has_initialized = true; - - // - - atexit(CleanupOnShutdown); -} - -void CleanupOnShutdown() {} - -std::unique_ptr Create(Emulator* emulator) { - InitializeIfNeeded(); - return std::make_unique(emulator); -} - -} // namespace gl4 -} // namespace gpu -} // namespace xe diff --git a/src/xenia/gpu/gl4/gl4_gpu.h b/src/xenia/gpu/gl4/gl4_gpu.h deleted file mode 100644 index a36429a21..000000000 --- a/src/xenia/gpu/gl4/gl4_gpu.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2014 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#ifndef XENIA_GPU_GL4_GL4_GPU_H_ -#define XENIA_GPU_GL4_GL4_GPU_H_ - -#include - -#include "xenia/gpu/graphics_system.h" - -namespace xe { -namespace gpu { -namespace gl4 { - -std::unique_ptr Create(Emulator* emulator); - -} // namespace gl4 -} // namespace gpu -} // namespace xe - -#endif // XENIA_GPU_GL4_GL4_GPU_H_ diff --git a/src/xenia/gpu/gl4/gl4_graphics_system.cc b/src/xenia/gpu/gl4/gl4_graphics_system.cc index b47b0f992..d2e17c769 100644 --- a/src/xenia/gpu/gl4/gl4_graphics_system.cc +++ b/src/xenia/gpu/gl4/gl4_graphics_system.cc @@ -27,6 +27,28 @@ namespace gl4 { extern "C" GLEWContext* glewGetContext(); +void InitializeIfNeeded(); +void CleanupOnShutdown(); + +void InitializeIfNeeded() { + static bool has_initialized = false; + if (has_initialized) { + return; + } + has_initialized = true; + + // + + atexit(CleanupOnShutdown); +} + +void CleanupOnShutdown() {} + +std::unique_ptr GL4GraphicsSystem::Create(Emulator* emulator) { + InitializeIfNeeded(); + return std::make_unique(emulator); +} + GL4GraphicsSystem::GL4GraphicsSystem(Emulator* emulator) : GraphicsSystem(emulator), worker_running_(false) {} diff --git a/src/xenia/gpu/gl4/gl4_graphics_system.h b/src/xenia/gpu/gl4/gl4_graphics_system.h index 9f3a3cd2c..fd589620e 100644 --- a/src/xenia/gpu/gl4/gl4_graphics_system.h +++ b/src/xenia/gpu/gl4/gl4_graphics_system.h @@ -27,6 +27,8 @@ class GL4GraphicsSystem : public GraphicsSystem { GL4GraphicsSystem(Emulator* emulator); ~GL4GraphicsSystem() override; + static std::unique_ptr Create(Emulator* emulator); + X_STATUS Setup(cpu::Processor* processor, ui::PlatformLoop* target_loop, ui::PlatformWindow* target_window) override; void Shutdown() override; diff --git a/src/xenia/gpu/gpu-private.h b/src/xenia/gpu/gpu-private.h index bf6c9a77f..e5a09e248 100644 --- a/src/xenia/gpu/gpu-private.h +++ b/src/xenia/gpu/gpu-private.h @@ -7,8 +7,8 @@ ****************************************************************************** */ -#ifndef XENIA_GPU_PRIVATE_H_ -#define XENIA_GPU_PRIVATE_H_ +#ifndef XENIA_GPU_GPU_PRIVATE_H_ +#define XENIA_GPU_GPU_PRIVATE_H_ #include @@ -21,4 +21,4 @@ DECLARE_string(dump_shaders); DECLARE_bool(vsync); -#endif // XENIA_GPU_PRIVATE_H_ +#endif // XENIA_GPU_GPU_PRIVATE_H_ diff --git a/src/xenia/gpu/gpu.cc b/src/xenia/gpu/gpu.cc index b2ebd0a11..6a20a8b03 100644 --- a/src/xenia/gpu/gpu.cc +++ b/src/xenia/gpu/gpu.cc @@ -7,12 +7,8 @@ ****************************************************************************** */ -#include "xenia/gpu/gpu.h" #include "xenia/gpu/gpu-private.h" -// TODO(benvanik): based on platform. -#include "xenia/gpu/gl4/gl4_gpu.h" - DEFINE_string(gpu, "any", "Graphics system. Use: [any, gl4]"); DEFINE_string(trace_gpu_prefix, "scratch/gpu/gpu_trace_", @@ -23,26 +19,3 @@ DEFINE_string(dump_shaders, "", "Path to write GPU shaders to as they are compiled."); DEFINE_bool(vsync, true, "Enable VSYNC."); - -namespace xe { -namespace gpu { - -std::unique_ptr Create(Emulator* emulator) { - if (FLAGS_gpu.compare("gl4") == 0) { - return xe::gpu::gl4::Create(emulator); - } else { - // Create best available. - std::unique_ptr best; - - best = xe::gpu::gl4::Create(emulator); - if (best) { - return best; - } - - // Nothing! - return nullptr; - } -} - -} // namespace gpu -} // namespace xe diff --git a/src/xenia/gpu/gpu.h b/src/xenia/gpu/gpu.h deleted file mode 100644 index b9965229d..000000000 --- a/src/xenia/gpu/gpu.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - ****************************************************************************** - * 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_GPU_H_ -#define XENIA_GPU_GPU_H_ - -#include - -#include "xenia/gpu/graphics_system.h" - -namespace xe { -class Emulator; -} // namespace xe - -namespace xe { -namespace gpu { - -std::unique_ptr Create(Emulator* emulator); - -} // namespace gpu -} // namespace xe - -#endif // XENIA_GPU_GPU_H_ diff --git a/src/xenia/gpu/graphics_system.cc b/src/xenia/gpu/graphics_system.cc index e36b75825..972dcc470 100644 --- a/src/xenia/gpu/graphics_system.cc +++ b/src/xenia/gpu/graphics_system.cc @@ -15,9 +15,29 @@ #include "xenia/gpu/gpu-private.h" #include "xenia/kernel/objects/xthread.h" +// TODO(benvanik): based on platform/build support. +#include "xenia/gpu/gl4/gl4_graphics_system.h" + namespace xe { namespace gpu { +std::unique_ptr GraphicsSystem::Create(Emulator* emulator) { + if (FLAGS_gpu.compare("gl4") == 0) { + return xe::gpu::gl4::GL4GraphicsSystem::Create(emulator); + } else { + // Create best available. + std::unique_ptr best; + + best = xe::gpu::gl4::GL4GraphicsSystem::Create(emulator); + if (best) { + return best; + } + + // Nothing! + return nullptr; + } +} + GraphicsSystem::GraphicsSystem(Emulator* emulator) : emulator_(emulator), memory_(nullptr), diff --git a/src/xenia/gpu/graphics_system.h b/src/xenia/gpu/graphics_system.h index 3fc7a4424..e7a2c32d7 100644 --- a/src/xenia/gpu/graphics_system.h +++ b/src/xenia/gpu/graphics_system.h @@ -11,6 +11,7 @@ #define XENIA_GPU_GRAPHICS_SYSTEM_H_ #include +#include #include #include "xenia/cpu/processor.h" @@ -18,6 +19,10 @@ #include "xenia/ui/main_window.h" #include "xenia/xbox.h" +namespace xe { +class Emulator; +} // namespace xe + namespace xe { namespace gpu { @@ -25,6 +30,8 @@ class GraphicsSystem { public: virtual ~GraphicsSystem(); + static std::unique_ptr Create(Emulator* emulator); + Emulator* emulator() const { return emulator_; } Memory* memory() const { return memory_; } cpu::Processor* processor() const { return processor_; }