Moving threads to XHostThread and making shutdown not crash.
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include "xenia/gpu/sampler_info.h"
|
||||
#include "xenia/gpu/texture_info.h"
|
||||
#include "xenia/gpu/xenos.h"
|
||||
#include "xenia/emulator.h"
|
||||
#include "xenia/kernel/objects/xthread.h"
|
||||
#include "xenia/profiling.h"
|
||||
|
||||
#include "third_party/xxhash/xxhash.h"
|
||||
@@ -99,12 +101,12 @@ bool CommandProcessor::Initialize(std::unique_ptr<GLContext> context) {
|
||||
context_ = std::move(context);
|
||||
|
||||
worker_running_ = true;
|
||||
worker_thread_ = std::thread([this]() {
|
||||
xe::threading::set_name("GL4 Worker");
|
||||
xe::Profiler::ThreadEnter("GL4 Worker");
|
||||
WorkerMain();
|
||||
xe::Profiler::ThreadExit();
|
||||
});
|
||||
worker_thread_ = new kernel::XHostThread(
|
||||
graphics_system_->emulator()->kernel_state(), 128 * 1024, 0, [this]() {
|
||||
WorkerThreadMain();
|
||||
return 0;
|
||||
});
|
||||
worker_thread_->Create();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -114,7 +116,8 @@ void CommandProcessor::Shutdown() {
|
||||
|
||||
worker_running_ = false;
|
||||
SetEvent(write_ptr_index_event_);
|
||||
worker_thread_.join();
|
||||
worker_thread_->Wait(0, 0, 0, nullptr);
|
||||
worker_thread_->Release();
|
||||
|
||||
all_pipelines_.clear();
|
||||
all_shaders_.clear();
|
||||
@@ -160,14 +163,16 @@ void CommandProcessor::EndTracing() {
|
||||
|
||||
void CommandProcessor::CallInThread(std::function<void()> fn) {
|
||||
if (pending_fns_.empty() &&
|
||||
worker_thread_.get_id() == std::this_thread::get_id()) {
|
||||
worker_thread_ == kernel::XThread::GetCurrentThread()) {
|
||||
fn();
|
||||
} else {
|
||||
pending_fns_.push(std::move(fn));
|
||||
}
|
||||
}
|
||||
|
||||
void CommandProcessor::WorkerMain() {
|
||||
void CommandProcessor::WorkerThreadMain() {
|
||||
xe::threading::set_name("GL4 Worker");
|
||||
|
||||
context_->MakeCurrent();
|
||||
if (!SetupGL()) {
|
||||
XEFATAL("Unable to setup command processor GL state");
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,6 +27,12 @@
|
||||
#include "xenia/gpu/xenos.h"
|
||||
#include "xenia/memory.h"
|
||||
|
||||
namespace xe {
|
||||
namespace kernel {
|
||||
class XHostThread;
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
@@ -134,7 +139,7 @@ class CommandProcessor {
|
||||
} handles;
|
||||
};
|
||||
|
||||
void WorkerMain();
|
||||
void WorkerThreadMain();
|
||||
bool SetupGL();
|
||||
void ShutdownGL();
|
||||
GLuint CreateGeometryProgram(const std::string& source);
|
||||
@@ -226,8 +231,9 @@ class CommandProcessor {
|
||||
TraceState trace_state_;
|
||||
std::wstring trace_frame_path_;
|
||||
|
||||
std::thread worker_thread_;
|
||||
std::atomic<bool> worker_running_;
|
||||
kernel::XHostThread* worker_thread_;
|
||||
|
||||
std::unique_ptr<GLContext> context_;
|
||||
SwapHandler swap_handler_;
|
||||
std::queue<std::function<void()>> pending_fns_;
|
||||
|
||||
@@ -47,9 +47,9 @@ void InitializeIfNeeded() {
|
||||
|
||||
void CleanupOnShutdown() {}
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create() {
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator) {
|
||||
InitializeIfNeeded();
|
||||
return std::make_unique<GL4GraphicsSystem>();
|
||||
return std::make_unique<GL4GraphicsSystem>(emulator);
|
||||
}
|
||||
|
||||
} // namespace gl4
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace xe {
|
||||
namespace gpu {
|
||||
namespace gl4 {
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create();
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace gl4
|
||||
} // namespace gpu
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace gl4 {
|
||||
|
||||
extern "C" GLEWContext* glewGetContext();
|
||||
|
||||
GL4GraphicsSystem::GL4GraphicsSystem()
|
||||
: GraphicsSystem(), timer_queue_(nullptr), vsync_timer_(nullptr) {}
|
||||
GL4GraphicsSystem::GL4GraphicsSystem(Emulator* emulator)
|
||||
: GraphicsSystem(emulator), timer_queue_(nullptr), vsync_timer_(nullptr) {}
|
||||
|
||||
GL4GraphicsSystem::~GL4GraphicsSystem() = default;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace gl4 {
|
||||
|
||||
class GL4GraphicsSystem : public GraphicsSystem {
|
||||
public:
|
||||
GL4GraphicsSystem();
|
||||
GL4GraphicsSystem(Emulator* emulator);
|
||||
~GL4GraphicsSystem() override;
|
||||
|
||||
X_STATUS Setup(cpu::Processor* processor, ui::PlatformLoop* target_loop,
|
||||
|
||||
@@ -27,14 +27,14 @@ DEFINE_bool(vsync, true, "Enable VSYNC.");
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create() {
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator) {
|
||||
if (FLAGS_gpu.compare("gl4") == 0) {
|
||||
return xe::gpu::gl4::Create();
|
||||
return xe::gpu::gl4::Create(emulator);
|
||||
} else {
|
||||
// Create best available.
|
||||
std::unique_ptr<GraphicsSystem> best;
|
||||
|
||||
best = xe::gpu::gl4::Create();
|
||||
best = xe::gpu::gl4::Create(emulator);
|
||||
if (best) {
|
||||
return best;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ class Emulator;
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
std::unique_ptr<GraphicsSystem> Create();
|
||||
|
||||
std::unique_ptr<GraphicsSystem> CreateGL4();
|
||||
std::unique_ptr<GraphicsSystem> Create(Emulator* emulator);
|
||||
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
GraphicsSystem::GraphicsSystem()
|
||||
: memory_(nullptr),
|
||||
GraphicsSystem::GraphicsSystem(Emulator* emulator)
|
||||
: emulator_(emulator),
|
||||
memory_(nullptr),
|
||||
processor_(nullptr),
|
||||
target_loop_(nullptr),
|
||||
target_window_(nullptr),
|
||||
|
||||
@@ -25,6 +25,7 @@ class GraphicsSystem {
|
||||
public:
|
||||
virtual ~GraphicsSystem();
|
||||
|
||||
Emulator* emulator() const { return emulator_; }
|
||||
Memory* memory() const { return memory_; }
|
||||
cpu::Processor* processor() const { return processor_; }
|
||||
|
||||
@@ -54,8 +55,9 @@ class GraphicsSystem {
|
||||
virtual void ClearCaches() {}
|
||||
|
||||
protected:
|
||||
GraphicsSystem();
|
||||
GraphicsSystem(Emulator* emulator);
|
||||
|
||||
Emulator* emulator_;
|
||||
Memory* memory_;
|
||||
cpu::Processor* processor_;
|
||||
ui::PlatformLoop* target_loop_;
|
||||
|
||||
Reference in New Issue
Block a user