mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
VideoCommon: Eliminate EFBAccessType enum. Eliminate union and switch statement handler in AsyncRequests.
This commit is contained in:
@ -4,10 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Flag.h"
|
||||
|
||||
struct EfbPokeData;
|
||||
@ -16,70 +17,6 @@ class PointerWrap;
|
||||
class AsyncRequests
|
||||
{
|
||||
public:
|
||||
struct Event
|
||||
{
|
||||
Event() {}
|
||||
|
||||
enum Type
|
||||
{
|
||||
EFB_POKE_COLOR,
|
||||
EFB_POKE_Z,
|
||||
EFB_PEEK_COLOR,
|
||||
EFB_PEEK_Z,
|
||||
SWAP_EVENT,
|
||||
BBOX_READ,
|
||||
FIFO_RESET,
|
||||
PERF_QUERY,
|
||||
DO_SAVE_STATE,
|
||||
} type;
|
||||
u64 time;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
u16 x;
|
||||
u16 y;
|
||||
u32 data;
|
||||
} efb_poke;
|
||||
|
||||
struct
|
||||
{
|
||||
u16 x;
|
||||
u16 y;
|
||||
u32* data;
|
||||
} efb_peek;
|
||||
|
||||
struct
|
||||
{
|
||||
u32 xfbAddr;
|
||||
u32 fbWidth;
|
||||
u32 fbStride;
|
||||
u32 fbHeight;
|
||||
TimePoint presentation_time;
|
||||
} swap_event;
|
||||
|
||||
struct
|
||||
{
|
||||
int index;
|
||||
u16* data;
|
||||
} bbox;
|
||||
|
||||
struct
|
||||
{
|
||||
} fifo_reset;
|
||||
|
||||
struct
|
||||
{
|
||||
} perf_query;
|
||||
|
||||
struct
|
||||
{
|
||||
PointerWrap* p;
|
||||
} do_save_state;
|
||||
};
|
||||
};
|
||||
|
||||
AsyncRequests();
|
||||
|
||||
void PullEvents()
|
||||
@ -87,16 +24,47 @@ public:
|
||||
if (!m_empty.IsSet())
|
||||
PullEventsInternal();
|
||||
}
|
||||
void PushEvent(const Event& event, bool blocking = false);
|
||||
void WaitForEmptyQueue();
|
||||
void SetEnable(bool enable);
|
||||
void SetPassthrough(bool enable);
|
||||
|
||||
template <typename F>
|
||||
void PushEvent(F&& callback)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
if (m_passthrough)
|
||||
{
|
||||
std::invoke(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
QueueEvent(Event{std::forward<F>(callback)});
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
auto PushBlockingEvent(F&& callback) -> std::invoke_result_t<F>
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
if (m_passthrough)
|
||||
return std::invoke(callback);
|
||||
|
||||
std::packaged_task task{std::forward<F>(callback)};
|
||||
QueueEvent(Event{[&] { task(); }});
|
||||
|
||||
lock.unlock();
|
||||
return task.get_future().get();
|
||||
}
|
||||
|
||||
static AsyncRequests* GetInstance() { return &s_singleton; }
|
||||
|
||||
private:
|
||||
using Event = std::function<void()>;
|
||||
|
||||
void QueueEvent(Event&& event);
|
||||
|
||||
void PullEventsInternal();
|
||||
void HandleEvent(const Event& e);
|
||||
|
||||
static AsyncRequests s_singleton;
|
||||
|
||||
@ -105,7 +73,6 @@ private:
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_cond;
|
||||
|
||||
bool m_wake_me_up_again = false;
|
||||
bool m_enable = false;
|
||||
bool m_passthrough = true;
|
||||
};
|
||||
|
Reference in New Issue
Block a user