29#include <EASTL/array.h>
30#include <EASTL/atomic.h>
31#include <EASTL/fixed_list.h>
32#include <EASTL/functional.h>
33#include <EASTL/utility.h>
59namespace timer_literals {
90 TimerAwaiter(
GPU &gpu,
uint32_t deadline) : m_gpu(gpu), m_deadline(deadline) {}
92 constexpr bool await_ready()
const {
return false; }
93 void await_suspend(std::coroutine_handle<> handle) {
94 m_gpu.armTimer(m_deadline, [handle](
uint32_t) { handle.resume(); });
96 void await_resume() {}
169 void getClear(Prim::FastFill &ff,
Color bg = {{0, 0, 0}})
const;
220 void uploadToVRAM(
const uint16_t *data, Rect region, eastl::function<
void()> &&callback,
229 template <Fragment Frag>
231 sendFragment(&fragment.head + 1, fragment.getActualFragmentSize());
243 template <Fragment Frag>
244 void sendFragment(
const Frag &fragment, eastl::function<
void()> &&callback,
246 sendFragment(&fragment.head + 1, fragment.getActualFragmentSize(), eastl::move(callback), dmaCallback);
302 template <Primitive Prim>
306 constexpr size_t size =
sizeof(Prim) /
sizeof(
uint32_t);
307 for (
int i = 0; i <
size; i++) {
326 template <Fragment Frag>
328 chain(&fragment.head, &fragment.head, fragment.getActualFragmentSize());
340 template <Fragment Frag1, Fragment Frag2>
341 void chain(Frag1 *first, Frag2 *last) {
342 auto count = last->getActualFragmentSize();
344 chain(&first->head, &last->head, last->getActualFragmentSize());
355 template <
size_t N, Safe safety = Safe::Yes>
357 chain(&table.m_table[N], &table.m_table[0], 0);
358 scheduleOTC(&table.m_table[N], N + 1);
529 GPU(
const GPU &) =
delete;
531 GPU &operator=(
const GPU &) =
delete;
532 GPU &operator=(
GPU &&) =
delete;
536 void scheduleNormalDMA(uintptr_t data,
size_t count);
537 void scheduleChainedDMA(uintptr_t head);
540 void checkOTCAndTriggerCallback();
541 void prepareForTakeover();
543 eastl::function<
void(
void)> m_dmaCallback =
nullptr;
544 unsigned m_refreshRate = 0;
550 unsigned m_parity = 0;
553 size_t m_chainTailCount = 0;
554 enum { CHAIN_IDLE, CHAIN_TRANSFERRING, CHAIN_TRANSFERRED } m_chainStatus = CHAIN_IDLE;
559 int32_t pausedRemaining;
563 eastl::fixed_list<Timer, 32> m_timers;
564 struct ScheduledOTC {
568 eastl::fixed_list<ScheduledOTC, 32> m_OTCs[2];
571 uint16_t m_lastHSyncCounter = 0;
572 bool m_interlaced =
false;
573 bool m_fromISR =
false;
574 bool m_flushCacheAfterDMA =
false;
The application class.
Definition application.hh:49
The singleton GPU class.
Definition gpu.hh:88
bool isChainIdle() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition gpu.cpp:484
unsigned getParity() const
Get the index of the current display buffer.
Definition gpu.hh:148
void sendFragment(const Frag &fragment)
Immediately sends a fragment to the GPU. This is a blocking operation. See the fragments....
Definition gpu.hh:230
static constexpr uint32_t US_PER_HBLANK
Definition gpu.hh:110
void sendPrimitive(const Prim &primitive)
Sends a primitive to the GPU. This is a blocking call.
Definition gpu.hh:303
void waitChainIdle()
Waits until the background DMA transfer operation initiated by a frame flip is complete.
Definition gpu.hh:402
uint32_t getFrameCount() const
Returns the number of frames rendered by the GPU so far.
Definition gpu.hh:133
Interlace
Definition gpu.hh:106
uintptr_t armTimer(uint32_t deadline, eastl::function< void(uint32_t)> &&callback)
Creates a single-use timer.
Definition gpu.cpp:499
void sendFragment(const Frag &fragment, eastl::function< void()> &&callback, DMA::DmaCallback dmaCallback=DMA::FROM_MAIN_LOOP)
Sends a fragment to the GPU as a non-blocking call.
Definition gpu.hh:244
void disableScissor()
Immediately disables the scissoring of the VRAM.
Definition gpu.cpp:262
void getClear(Prim::FastFill &ff, Color bg={{0, 0, 0}}) const
Sets a FastFill primitive to clear the current drawing buffer.
Definition gpu.cpp:301
void chain(Frag1 *first, Frag2 *last)
Chains an already constructed DMA chain to the next DMA chain transfer.
Definition gpu.hh:341
TimerAwaiter delay(uint32_t microseconds)
Delays the coroutine for a specified amount of time.
Definition gpu.hh:455
unsigned armPeriodicTimer(uint32_t period, eastl::function< void(uint32_t)> &&callback)
Creates a periodic timer.
Definition gpu.cpp:504
void enableScissor()
Enables the scissoring of the VRAM.
Definition gpu.cpp:267
void waitReady()
Waits until the GPU is ready to send a command.
Definition gpu.cpp:42
void getNextScissor(Prim::Scissor &scissor)
Gets the next scissoring region.
Definition gpu.cpp:284
uint32_t now() const
Gets the current timestamp in microseconds.
Definition gpu.hh:423
void chain(OrderingTable< N, safety > &table)
Chains an ordering table to the next DMA chain transfer.
Definition gpu.hh:356
void initialize(const Configuration &config)
Definition gpu.cpp:54
unsigned getRefreshRate() const
Returns the refresh rate of the GPU.
Definition gpu.hh:119
MiscSetting
Definition gpu.hh:107
void sendChain()
Immediately sends the current DMA chain.
Definition gpu.cpp:440
ColorMode
Definition gpu.hh:105
void changeTimerPeriod(uintptr_t id, uint32_t period, bool reset=false)
Changes the period of a periodic timer.
Definition gpu.cpp:509
void pauseTimer(uintptr_t id)
Pauses a timer.
Definition gpu.cpp:525
void pumpCallbacks()
Runs one round of event processing.
Definition gpu.cpp:553
Resolution
Definition gpu.hh:103
void cancelTimer(uintptr_t id)
Cancels a timer.
Definition gpu.cpp:545
bool isChainTransferred() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition gpu.cpp:494
VideoMode
Definition gpu.hh:104
void uploadToVRAM(const uint16_t *data, Rect region)
Uploads a buffer to the VRAM as a blocking call.
Definition gpu.cpp:317
void getNextClear(Prim::FastFill &ff, Color bg={{0, 0, 0}}) const
Sets a FastFill primitive to clear the next drawing buffer.
Definition gpu.cpp:309
static void sendRaw(uint32_t data)
Sends a raw 32 bits value to the Data register of the GPU.
Definition gpu.hh:294
void waitFifo()
Waits until the GPU's FIFO is ready to receive data.
Definition gpu.cpp:48
void resumeTimer(uintptr_t id)
Resumes a paused timer.
Definition gpu.cpp:535
bool isChainTransferring() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition gpu.cpp:489
void clear(Color bg={{0, 0, 0}})
Immediately clears the drawing buffer.
Definition gpu.cpp:295
void chain(Frag &fragment)
Chains a fragment to the next DMA chain transfer.
Definition gpu.hh:327
static constexpr unsigned c_chainThreshold
Definition gpu.hh:111
void getScissor(Prim::Scissor &scissor)
Gets the current scissoring region.
Definition gpu.cpp:273
The ordering table. Used to sort fragments before sending them to the GPU.
Definition ordering-table.hh:59
volatile uint32_t * ptr
Definition cop0.c:80
DmaCallback
Definition gpu.hh:52
@ FROM_MAIN_LOOP
Definition gpu.hh:54
@ FROM_ISR
Definition gpu.hh:53
Register< 0x0810 > Data
Definition gpu.cpp:29
void assert(bool condition, const char *message, std::source_location location=std::source_location::current())
A simple assert macro.
Definition kernel.hh:300
void takeOverKernel()
Takes over the kernel. Can only be called once inside the main function.
Definition kernel.cpp:135
Definition cdrom-loader.hh:39
static int size
Definition string.h:32
Definition configuration.hh:29
A compounded Scissor primitive.
Definition control.hh:156
static int value
Definition syscalls.h:534
static const void size_t count
Definition syscalls.h:145
void uint32_t(classId, spec)
The Color struct.
Definition common.hh:91