Debian Codegraph @

Source/Core/VideoCommon/PixelEngine.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <mutex>
7
8 #include "Common/BitField.h"
9 #include "Common/CommonTypes.h"
10
11 class PointerWrap;
12
13 namespace Core
14 {
15 class System;
16 }
17 namespace CoreTiming
18 {
19 struct EventType;
20 }
21 namespace MMIO
22 {
23 class Mapping;
24 }
25
26 namespace PixelEngine
27 {
28 // internal hardware addresses
29 enum
30 {
31 PE_ZCONF = 0x00, // Z Config
32 PE_ALPHACONF = 0x02, // Alpha Config
33 PE_DSTALPHACONF = 0x04, // Destination Alpha Config
34 PE_ALPHAMODE = 0x06, // Alpha Mode Config
35 PE_ALPHAREAD = 0x08, // Alpha Read
36 PE_CTRL_REGISTER = 0x0a, // Control
37 PE_TOKEN_REG = 0x0e, // Token
38 PE_BBOX_LEFT = 0x10, // Bounding Box Left Pixel
39 PE_BBOX_RIGHT = 0x12, // Bounding Box Right Pixel
40 PE_BBOX_TOP = 0x14, // Bounding Box Top Pixel
41 PE_BBOX_BOTTOM = 0x16, // Bounding Box Bottom Pixel
42
43 // NOTE: Order not verified
44 // These indicate the number of quads that are being used as input/output for each particular
45 // stage
46 PE_PERF_ZCOMP_INPUT_ZCOMPLOC_L = 0x18,
47 PE_PERF_ZCOMP_INPUT_ZCOMPLOC_H = 0x1a,
48 PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L = 0x1c,
49 PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_H = 0x1e,
50 PE_PERF_ZCOMP_INPUT_L = 0x20,
51 PE_PERF_ZCOMP_INPUT_H = 0x22,
52 PE_PERF_ZCOMP_OUTPUT_L = 0x24,
53 PE_PERF_ZCOMP_OUTPUT_H = 0x26,
54 PE_PERF_BLEND_INPUT_L = 0x28,
55 PE_PERF_BLEND_INPUT_H = 0x2a,
56 PE_PERF_EFB_COPY_CLOCKS_L = 0x2c,
57 PE_PERF_EFB_COPY_CLOCKS_H = 0x2e,
58 };
59
60 // ReadMode specifies the returned alpha channel for EFB peeks
61 enum class AlphaReadMode : u16
62 {
63 Read00 = 0, // Always read 0x00
64 ReadFF = 1, // Always read 0xFF
65 ReadNone = 2, // Always read the real alpha value
66 };
67
68 // Note: These enums are (assumed to be) identical to the one in BPMemory, but the base type is set
69 // to u16 instead of u32 for BitField
70 enum class CompareMode : u16
71 {
72 Never = 0,
73 Less = 1,
74 Equal = 2,
75 LEqual = 3,
76 Greater = 4,
77 NEqual = 5,
78 GEqual = 6,
79 Always = 7
80 };
81
82 union UPEZConfReg
83 {
84 u16 hex = 0;
85 BitField<0, 1, bool, u16> z_comparator_enable;
86 BitField<1, 3, CompareMode, u16> function;
87 BitField<4, 1, bool, u16> z_update_enable;
88 };
89
90 enum class SrcBlendFactor : u16
91 {
92 Zero = 0,
93 One = 1,
94 DstClr = 2,
95 InvDstClr = 3,
96 SrcAlpha = 4,
97 InvSrcAlpha = 5,
98 DstAlpha = 6,
99 InvDstAlpha = 7
100 };
101
102 enum class DstBlendFactor : u16
103 {
104 Zero = 0,
105 One = 1,
106 SrcClr = 2,
107 InvSrcClr = 3,
108 SrcAlpha = 4,
109 InvSrcAlpha = 5,
110 DstAlpha = 6,
111 InvDstAlpha = 7
112 };
113
114 enum class LogicOp : u16
115 {
116 Clear = 0,
117 And = 1,
118 AndReverse = 2,
119 Copy = 3,
120 AndInverted = 4,
121 NoOp = 5,
122 Xor = 6,
123 Or = 7,
124 Nor = 8,
125 Equiv = 9,
126 Invert = 10,
127 OrReverse = 11,
128 CopyInverted = 12,
129 OrInverted = 13,
130 Nand = 14,
131 Set = 15
132 };
133
134 union UPEAlphaConfReg
135 {
136 u16 hex = 0;
137 BitField<0, 1, bool, u16> blend; // Set for GX_BM_BLEND or GX_BM_SUBTRACT
138 BitField<1, 1, bool, u16> logic; // Set for GX_BM_LOGIC
139 BitField<2, 1, bool, u16> dither;
140 BitField<3, 1, bool, u16> color_update_enable;
141 BitField<4, 1, bool, u16> alpha_update_enable;
142 BitField<5, 3, DstBlendFactor, u16> dst_factor;
143 BitField<8, 3, SrcBlendFactor, u16> src_factor;
144 BitField<11, 1, bool, u16> subtract; // Set for GX_BM_SUBTRACT
145 BitField<12, 4, LogicOp, u16> logic_op;
146 };
147
148 union UPEDstAlphaConfReg
149 {
150 u16 hex = 0;
151 BitField<0, 8, u8, u16> alpha;
152 BitField<8, 1, bool, u16> enable;
153 };
154
155 union UPEAlphaModeConfReg
156 {
157 u16 hex = 0;
158 BitField<0, 8, u8, u16> threshold;
159 // Yagcd and libogc use 8 bits for this, but the enum only needs 3
160 BitField<8, 3, CompareMode, u16> compare_mode;
161 };
162
163 union UPEAlphaReadReg
164 {
165 u16 hex = 0;
166 BitField<0, 2, AlphaReadMode, u16> read_mode;
167 };
168
169 // fifo Control Register
170 union UPECtrlReg
171 {
172 u16 hex = 0;
173 BitField<0, 1, bool, u16> pe_token_enable;
174 BitField<1, 1, bool, u16> pe_finish_enable;
175 BitField<2, 1, bool, u16> pe_token; // Write only
176 BitField<3, 1, bool, u16> pe_finish; // Write only
177 };
178
179 class PixelEngineManager
180 {
181 public:
182 explicit PixelEngineManager(Core::System& system);
183
184 void Init();
185 void DoState(PointerWrap& p);
186
187 void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
188
189 // gfx backend support
190 void SetToken(const u16 token, const bool interrupt, int cycle_delay);
191 void SetFinish(int cycle_delay);
192 AlphaReadMode GetAlphaReadMode() const { return m_alpha_read.read_mode; }
193
194 private:
195 void RaiseEvent(int cycles_into_future);
196 void UpdateInterrupts();
197 void SetTokenFinish_OnMainThread(u64 userdata, s64 cycles_late);
198
199 static void SetTokenFinish_OnMainThread_Static(Core::System& system, u64 userdata,
200 s64 cycles_late);
201
202 // STATE_TO_SAVE
203 UPEZConfReg m_z_conf;
204 UPEAlphaConfReg m_alpha_conf;
205 UPEDstAlphaConfReg m_dst_alpha_conf;
206 UPEAlphaModeConfReg m_alpha_mode_conf;
207 UPEAlphaReadReg m_alpha_read;
208 UPECtrlReg m_control;
209
210 std::mutex m_token_finish_mutex;
211 u16 m_token = 0;
212 u16 m_token_pending = 0;
213 bool m_token_interrupt_pending = false;
214 bool m_finish_interrupt_pending = false;
215 bool m_event_raised = false;
216
217 bool m_signal_token_interrupt = false;
218 bool m_signal_finish_interrupt = false;
219
220 CoreTiming::EventType* m_event_type_set_token_finish = nullptr;
221
222 Core::System& m_system;
223 };
224
225 } // namespace PixelEngine