Simplifying GPU creation.

Part of #296.
This commit is contained in:
Ben Vanik 2015-06-27 09:11:03 -07:00
parent 3439641101
commit 883126d497
13 changed files with 56 additions and 145 deletions

View File

@ -329,7 +329,6 @@
<ClInclude Include="src\xenia\cpu\compiler\passes\validation_pass.h" /> <ClInclude Include="src\xenia\cpu\compiler\passes\validation_pass.h" />
<ClInclude Include="src\xenia\cpu\compiler\passes\value_reduction_pass.h" /> <ClInclude Include="src\xenia\cpu\compiler\passes\value_reduction_pass.h" />
<ClInclude Include="src\xenia\cpu\cpu-private.h" /> <ClInclude Include="src\xenia\cpu\cpu-private.h" />
<ClInclude Include="src\xenia\cpu\cpu.h" />
<ClInclude Include="src\xenia\cpu\debug_info.h" /> <ClInclude Include="src\xenia\cpu\debug_info.h" />
<ClInclude Include="src\xenia\cpu\entry_table.h" /> <ClInclude Include="src\xenia\cpu\entry_table.h" />
<ClInclude Include="src\xenia\cpu\export_resolver.h" /> <ClInclude Include="src\xenia\cpu\export_resolver.h" />
@ -375,7 +374,6 @@
<ClInclude Include="src\xenia\gpu\gl4\command_processor.h" /> <ClInclude Include="src\xenia\gpu\gl4\command_processor.h" />
<ClInclude Include="src\xenia\gpu\gl4\draw_batcher.h" /> <ClInclude Include="src\xenia\gpu\gl4\draw_batcher.h" />
<ClInclude Include="src\xenia\gpu\gl4\gl4_gpu-private.h" /> <ClInclude Include="src\xenia\gpu\gl4\gl4_gpu-private.h" />
<ClInclude Include="src\xenia\gpu\gl4\gl4_gpu.h" />
<ClInclude Include="src\xenia\gpu\gl4\gl4_graphics_system.h" /> <ClInclude Include="src\xenia\gpu\gl4\gl4_graphics_system.h" />
<ClInclude Include="src\xenia\gpu\gl4\gl4_profiler_display.h" /> <ClInclude Include="src\xenia\gpu\gl4\gl4_profiler_display.h" />
<ClInclude Include="src\xenia\gpu\gl4\gl4_shader.h" /> <ClInclude Include="src\xenia\gpu\gl4\gl4_shader.h" />
@ -384,7 +382,6 @@
<ClInclude Include="src\xenia\gpu\gl4\texture_cache.h" /> <ClInclude Include="src\xenia\gpu\gl4\texture_cache.h" />
<ClInclude Include="src\xenia\gpu\gl4\wgl_control.h" /> <ClInclude Include="src\xenia\gpu\gl4\wgl_control.h" />
<ClInclude Include="src\xenia\gpu\gpu-private.h" /> <ClInclude Include="src\xenia\gpu\gpu-private.h" />
<ClInclude Include="src\xenia\gpu\gpu.h" />
<ClInclude Include="src\xenia\gpu\graphics_system.h" /> <ClInclude Include="src\xenia\gpu\graphics_system.h" />
<ClInclude Include="src\xenia\gpu\register_file.h" /> <ClInclude Include="src\xenia\gpu\register_file.h" />
<ClInclude Include="src\xenia\gpu\sampler_info.h" /> <ClInclude Include="src\xenia\gpu\sampler_info.h" />

View File

@ -840,9 +840,6 @@
<ClInclude Include="src\xenia\base\byte_order.h"> <ClInclude Include="src\xenia\base\byte_order.h">
<Filter>src\xenia\base</Filter> <Filter>src\xenia\base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\xenia\cpu\cpu.h">
<Filter>src\xenia\cpu</Filter>
</ClInclude>
<ClInclude Include="src\xenia\cpu\cpu-private.h"> <ClInclude Include="src\xenia\cpu\cpu-private.h">
<Filter>src\xenia\cpu</Filter> <Filter>src\xenia\cpu</Filter>
</ClInclude> </ClInclude>
@ -1062,9 +1059,6 @@
<ClInclude Include="src\xenia\cpu\compiler\passes\finalization_pass.h"> <ClInclude Include="src\xenia\cpu\compiler\passes\finalization_pass.h">
<Filter>src\xenia\cpu\compiler\passes</Filter> <Filter>src\xenia\cpu\compiler\passes</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\xenia\gpu\gpu.h">
<Filter>src\xenia\gpu</Filter>
</ClInclude>
<ClInclude Include="src\xenia\gpu\gpu-private.h"> <ClInclude Include="src\xenia\gpu\gpu-private.h">
<Filter>src\xenia\gpu</Filter> <Filter>src\xenia\gpu</Filter>
</ClInclude> </ClInclude>
@ -1116,9 +1110,6 @@
<ClInclude Include="src\xenia\gpu\gl4\wgl_control.h"> <ClInclude Include="src\xenia\gpu\gl4\wgl_control.h">
<Filter>src\xenia\gpu\gl4</Filter> <Filter>src\xenia\gpu\gl4</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\xenia\gpu\gl4\gl4_gpu.h">
<Filter>src\xenia\gpu\gl4</Filter>
</ClInclude>
<ClInclude Include="src\xenia\gpu\gl4\gl4_gpu-private.h"> <ClInclude Include="src\xenia\gpu\gl4\gl4_gpu-private.h">
<Filter>src\xenia\gpu\gl4</Filter> <Filter>src\xenia\gpu\gl4</Filter>
</ClInclude> </ClInclude>

View File

@ -15,7 +15,7 @@
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/clock.h" #include "xenia/base/clock.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include "xenia/gpu/gpu.h" #include "xenia/gpu/graphics_system.h"
#include "xenia/hid/hid.h" #include "xenia/hid/hid.h"
#include "xenia/kernel/kernel.h" #include "xenia/kernel/kernel.h"
#include "xenia/kernel/kernel_state.h" #include "xenia/kernel/kernel_state.h"
@ -121,7 +121,7 @@ X_STATUS Emulator::Setup() {
xma_decoder_ = std::move(std::make_unique<XmaDecoder>(this)); xma_decoder_ = std::move(std::make_unique<XmaDecoder>(this));
// Initialize the GPU. // Initialize the GPU.
graphics_system_ = std::move(xe::gpu::Create(this)); graphics_system_ = std::move(xe::gpu::GraphicsSystem::Create(this));
if (!graphics_system_) { if (!graphics_system_) {
return X_STATUS_NOT_IMPLEMENTED; return X_STATUS_NOT_IMPLEMENTED;
} }

View File

@ -12,8 +12,6 @@
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include "xenia/gpu/gl4/gl4_gpu.h"
DECLARE_bool(thread_safe_gl); DECLARE_bool(thread_safe_gl);
DECLARE_bool(disable_gl_context_reset); DECLARE_bool(disable_gl_context_reset);
@ -28,14 +26,4 @@ DECLARE_bool(disable_textures);
#define FINE_GRAINED_DRAW_SCOPES 0 #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_ #endif // XENIA_GPU_GL4_GL4_GPU_PRIVATE_H_

View File

@ -7,10 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include "xenia/gpu/gl4/gl4_gpu.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h" #include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gl4/gl4_graphics_system.h"
DEFINE_bool(thread_safe_gl, false, DEFINE_bool(thread_safe_gl, false,
"Only allow one GL context to be active at a time."); "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, DEFINE_bool(disable_framebuffer_readback, false,
"Disable framebuffer readback."); "Disable framebuffer readback.");
DEFINE_bool(disable_textures, false, "Disable textures and use colors only."); 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<GraphicsSystem> Create(Emulator* emulator) {
InitializeIfNeeded();
return std::make_unique<GL4GraphicsSystem>(emulator);
}
} // namespace gl4
} // namespace gpu
} // namespace xe

View File

@ -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 <memory>
#include "xenia/gpu/graphics_system.h"
namespace xe {
namespace gpu {
namespace gl4 {
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
} // namespace gl4
} // namespace gpu
} // namespace xe
#endif // XENIA_GPU_GL4_GL4_GPU_H_

View File

@ -27,6 +27,28 @@ namespace gl4 {
extern "C" GLEWContext* glewGetContext(); 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<GraphicsSystem> GL4GraphicsSystem::Create(Emulator* emulator) {
InitializeIfNeeded();
return std::make_unique<GL4GraphicsSystem>(emulator);
}
GL4GraphicsSystem::GL4GraphicsSystem(Emulator* emulator) GL4GraphicsSystem::GL4GraphicsSystem(Emulator* emulator)
: GraphicsSystem(emulator), worker_running_(false) {} : GraphicsSystem(emulator), worker_running_(false) {}

View File

@ -27,6 +27,8 @@ class GL4GraphicsSystem : public GraphicsSystem {
GL4GraphicsSystem(Emulator* emulator); GL4GraphicsSystem(Emulator* emulator);
~GL4GraphicsSystem() override; ~GL4GraphicsSystem() override;
static std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
X_STATUS Setup(cpu::Processor* processor, ui::PlatformLoop* target_loop, X_STATUS Setup(cpu::Processor* processor, ui::PlatformLoop* target_loop,
ui::PlatformWindow* target_window) override; ui::PlatformWindow* target_window) override;
void Shutdown() override; void Shutdown() override;

View File

@ -7,8 +7,8 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef XENIA_GPU_PRIVATE_H_ #ifndef XENIA_GPU_GPU_PRIVATE_H_
#define XENIA_GPU_PRIVATE_H_ #define XENIA_GPU_GPU_PRIVATE_H_
#include <gflags/gflags.h> #include <gflags/gflags.h>
@ -21,4 +21,4 @@ DECLARE_string(dump_shaders);
DECLARE_bool(vsync); DECLARE_bool(vsync);
#endif // XENIA_GPU_PRIVATE_H_ #endif // XENIA_GPU_GPU_PRIVATE_H_

View File

@ -7,12 +7,8 @@
****************************************************************************** ******************************************************************************
*/ */
#include "xenia/gpu/gpu.h"
#include "xenia/gpu/gpu-private.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(gpu, "any", "Graphics system. Use: [any, gl4]");
DEFINE_string(trace_gpu_prefix, "scratch/gpu/gpu_trace_", 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."); "Path to write GPU shaders to as they are compiled.");
DEFINE_bool(vsync, true, "Enable VSYNC."); DEFINE_bool(vsync, true, "Enable VSYNC.");
namespace xe {
namespace gpu {
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator) {
if (FLAGS_gpu.compare("gl4") == 0) {
return xe::gpu::gl4::Create(emulator);
} else {
// Create best available.
std::unique_ptr<GraphicsSystem> best;
best = xe::gpu::gl4::Create(emulator);
if (best) {
return best;
}
// Nothing!
return nullptr;
}
}
} // namespace gpu
} // namespace xe

View File

@ -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 <memory>
#include "xenia/gpu/graphics_system.h"
namespace xe {
class Emulator;
} // namespace xe
namespace xe {
namespace gpu {
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
} // namespace gpu
} // namespace xe
#endif // XENIA_GPU_GPU_H_

View File

@ -15,9 +15,29 @@
#include "xenia/gpu/gpu-private.h" #include "xenia/gpu/gpu-private.h"
#include "xenia/kernel/objects/xthread.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 xe {
namespace gpu { namespace gpu {
std::unique_ptr<GraphicsSystem> GraphicsSystem::Create(Emulator* emulator) {
if (FLAGS_gpu.compare("gl4") == 0) {
return xe::gpu::gl4::GL4GraphicsSystem::Create(emulator);
} else {
// Create best available.
std::unique_ptr<GraphicsSystem> best;
best = xe::gpu::gl4::GL4GraphicsSystem::Create(emulator);
if (best) {
return best;
}
// Nothing!
return nullptr;
}
}
GraphicsSystem::GraphicsSystem(Emulator* emulator) GraphicsSystem::GraphicsSystem(Emulator* emulator)
: emulator_(emulator), : emulator_(emulator),
memory_(nullptr), memory_(nullptr),

View File

@ -11,6 +11,7 @@
#define XENIA_GPU_GRAPHICS_SYSTEM_H_ #define XENIA_GPU_GRAPHICS_SYSTEM_H_
#include <atomic> #include <atomic>
#include <memory>
#include <thread> #include <thread>
#include "xenia/cpu/processor.h" #include "xenia/cpu/processor.h"
@ -18,6 +19,10 @@
#include "xenia/ui/main_window.h" #include "xenia/ui/main_window.h"
#include "xenia/xbox.h" #include "xenia/xbox.h"
namespace xe {
class Emulator;
} // namespace xe
namespace xe { namespace xe {
namespace gpu { namespace gpu {
@ -25,6 +30,8 @@ class GraphicsSystem {
public: public:
virtual ~GraphicsSystem(); virtual ~GraphicsSystem();
static std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
Emulator* emulator() const { return emulator_; } Emulator* emulator() const { return emulator_; }
Memory* memory() const { return memory_; } Memory* memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; } cpu::Processor* processor() const { return processor_; }