29 #include <EASTL/array.h>
30 #include <EASTL/atomic.h>
31 #include <EASTL/functional.h>
32 #include <EASTL/utility.h>
35 #include "common/hardware/hwregs.h"
36 #include "psyqo/primitives.hh"
60 enum class Resolution { W256, W320, W368, W512, W640 };
61 enum class VideoMode { AUTO, NTSC, PAL };
62 enum class ColorMode { C15BITS, C24BITS };
63 enum class Interlace { PROGRESSIVE, INTERLACED };
66 static constexpr uint32_t US_PER_HBLANK = 64;
105 void getClear(Prim::FastFill &ff,
Color bg = {{0, 0, 0}})
const;
157 DMA::DmaCallback dmaCallback = DMA::FROM_MAIN_LOOP);
165 template <
typename Fragment>
167 sendFragment(&fragment.head + 1, fragment.getActualFragmentSize());
179 template <
typename Fragment>
181 DMA::DmaCallback dmaCallback = DMA::FROM_MAIN_LOOP) {
225 static void sendRaw(uint32_t data) { GPU_DATA = data; }
226 template <
typename Primitive>
235 static_assert((
sizeof(Primitive) % 4) == 0,
"Primitive's size must be a multiple of 4");
237 const uint32_t *ptr =
reinterpret_cast<const uint32_t *
>(&primitive);
238 size_t size =
sizeof(Primitive) /
sizeof(uint32_t);
239 for (
int i = 0; i < size; i++) {
257 template <
typename Fragment>
259 chain(&fragment.head, fragment.getActualFragmentSize());
316 uint32_t
now()
const {
return m_currentTime; }
410 DMA::DmaCallback dmaCallback);
411 void chain(uint32_t *head,
size_t count);
414 unsigned m_refreshRate = 0;
415 bool m_fromISR =
false;
416 bool m_flushCacheAfterDMA =
false;
419 uint32_t m_currentTime = 0;
420 uint32_t m_frameCount = 0;
421 uint32_t m_previousFrameCount = 0;
423 uint32_t *m_chainHead =
nullptr;
424 uint32_t *m_chainTail =
nullptr;
425 size_t m_chainTailCount = 0;
426 enum { CHAIN_IDLE, CHAIN_TRANSFERRING, CHAIN_TRANSFERRED } m_chainStatus;
428 uint16_t m_lastHSyncCounter = 0;
429 bool m_interlaced =
false;
431 friend class Application;
436 #include "psyqo/internal/gpu/configuration.hh"
Definition: function.h:30
The singleton GPU class.
Definition: gpu.hh:57
void sendFragment(const Fragment &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:180
bool isChainIdle() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition: gpu.cpp:389
uint32_t getFrameCount() const
Returns the number of frames rendered by the GPU so far.
Definition: gpu.hh:84
void chain(Fragment &fragment)
Chains a fragment to the next DMA chain transfer.
Definition: gpu.hh:258
uintptr_t armTimer(uint32_t deadline, eastl::function< void(uint32_t)> &&callback)
Creates a single-use timer.
Definition: gpu.cpp:404
void disableScissor()
Immediately disables the scissoring of the VRAM.
Definition: gpu.cpp:181
void getClear(Prim::FastFill &ff, Color bg={{0, 0, 0}}) const
Sets a FastFill primitive to clear the current drawing buffer.
Definition: gpu.cpp:220
static void sendPrimitive(const Primitive &primitive)
Sends a primitive to the GPU. This is a blocking call.
Definition: gpu.hh:234
unsigned armPeriodicTimer(uint32_t period, eastl::function< void(uint32_t)> &&callback)
Creates a periodic timer.
Definition: gpu.cpp:409
void enableScissor()
Enables the scissoring of the VRAM.
Definition: gpu.cpp:186
static void waitReady()
Waits until the GPU is ready to send a command.
Definition: gpu.cpp:41
void getNextScissor(Prim::Scissor &scissor)
Gets the next scissoring region.
Definition: gpu.cpp:203
uint32_t now() const
Gets the current timestamp in microseconds.
Definition: gpu.hh:316
unsigned getRefreshRate() const
Returns the refresh rate of the GPU.
Definition: gpu.hh:74
void sendChain()
Immediately sends the current DMA chain.
Definition: gpu.cpp:356
void changeTimerPeriod(uintptr_t id, uint32_t period, bool reset=false)
Changes the period of a periodic timer.
Definition: gpu.cpp:414
void pauseTimer(uintptr_t id)
Pauses a timer.
Definition: gpu.cpp:430
void pumpCallbacks()
Runs one round of event processing.
Definition: gpu.cpp:458
void cancelTimer(uintptr_t id)
Cancels a timer.
Definition: gpu.cpp:450
bool isChainTransferred() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition: gpu.cpp:399
void uploadToVRAM(const uint16_t *data, Rect region)
Uploads a buffer to the VRAM as a blocking call.
Definition: gpu.cpp:236
void getNextClear(Prim::FastFill &ff, Color bg={{0, 0, 0}}) const
Sets a FastFill primitive to clear the next drawing buffer.
Definition: gpu.cpp:228
static void sendRaw(uint32_t data)
Sends a raw 32 bits value to the GP0 register of the GPU.
Definition: gpu.hh:225
void sendFragment(const Fragment &fragment)
Immediately sends a fragment to the GPU. This is a blocking operation. See the fragments....
Definition: gpu.hh:166
void resumeTimer(uintptr_t id)
Resumes a paused timer.
Definition: gpu.cpp:440
bool isChainTransferring() const
Gets the status of the background DMA transfer operation when initiated by a frame flip.
Definition: gpu.cpp:394
void clear(Color bg={{0, 0, 0}})
Immediately clears the drawing buffer.
Definition: gpu.cpp:214
void getScissor(Prim::Scissor &scissor)
Gets the current scissoring region.
Definition: gpu.cpp:192
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result)
Definition: copy_help.h:170
Definition: configuration.hh:29
A compounded Scissor primitive.
Definition: control.hh:104
The Color struct.
Definition: common.hh:91