summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/AsyncRequests.h
blob: 5271426f1f17bceb81e1c82be86816f8db7bb361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2015 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <condition_variable>
#include <mutex>
#include <queue>
#include <vector>

#include "Common/CommonTypes.h"
#include "Common/Flag.h"

struct EfbPokeData;
class PointerWrap;

class AsyncRequests
{
public:
  struct 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;
      } swap_event;

      struct
      {
        int index;
        u16* data;
      } bbox;

      struct
      {
      } fifo_reset;

      struct
      {
      } perf_query;

      struct
      {
        PointerWrap* p;
      } do_save_state;
    };
  };

  AsyncRequests();

  void PullEvents()
  {
    if (!m_empty.IsSet())
      PullEventsInternal();
  }
  void PushEvent(const Event& event, bool blocking = false);
  void WaitForEmptyQueue();
  void SetEnable(bool enable);
  void SetPassthrough(bool enable);

  static AsyncRequests* GetInstance() { return &s_singleton; }

private:
  void PullEventsInternal();
  void HandleEvent(const Event& e);

  static AsyncRequests s_singleton;

  Common::Flag m_empty;
  std::queue<Event> m_queue;
  std::mutex m_mutex;
  std::condition_variable m_cond;

  bool m_wake_me_up_again = false;
  bool m_enable = false;
  bool m_passthrough = true;

  std::vector<EfbPokeData> m_merged_efb_pokes;
};