Gx2Memory namespace
GPU-visible memory of the GX2 backend.
The Wii U's GPU (the R700-class "Latte") reads system memory directly, so unlike the PlayStation 3's RSX there is no address window and no offset translation: a block is a plain CPU pointer that is also the address the GPU fetches from. What the CPU has to do is keep its caches out of the way. The Espresso's data cache is not coherent with the GPU, so every CPU write the GPU is meant to see has to be flushed with FlushCpuWrites() (GX2Invalidate() with the matching mode, which also drops the GPU's own cache lines for that range) before the draw that reads it is submitted.
MEM2 by default, MEM1 for the hottest render targets. Buffers, ordinary textures and anything else that has to survive the background come from the default heap in MEM2 (MEMAllocFromDefaultHeapEx()). MEM1 (32 MB of fast on-chip memory) is owned by wiiu-sdl2: its video driver puts a heap over all of it when the application gets the foreground and destroys that heap when it loses it (HOME menu). Colour surfaces are taken from that heap through GX2R (AllocColorSurfaceMem1()), which allocates with the allocator SDL installed (GX2RSetAllocator()). Such a block is only valid while in the foreground: Gx2Device::
Classes
- struct Block
- One allocation;
Baseis both the CPU and the GPU address.
Functions
-
auto Alloc(std::
uint32_t size, std:: uint32_t alignment) -> Block - Allocates GPU-visible memory from MEM2.
- auto AllocColorSurfaceMem1(const GX2Surface& surface) -> Block
- Allocates the image of a colour surface in MEM1, or returns an invalid block if it doesn't fit.
- void Free(Block& block)
- Releases a block and resets it; the caller must know the GPU is done with it.
-
void FlushCpuWrites(const void* base,
std::
uint32_t size, std:: uint32_t mode) - Flushes CPU writes to a range out of the data cache and invalidates the GPU caches given by
mode. -
auto GetAllocatedBytes() -> std::
uint32_t - Bytes currently allocated through Alloc().
-
auto GetMem1Bytes() -> std::
uint32_t - Bytes currently allocated through AllocColorSurfaceMem1().
Function documentation
Block nCine:: RHI:: GX2:: Gx2Memory:: Alloc(std:: uint32_t size,
std:: uint32_t alignment)
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Allocates GPU-visible memory from MEM2.
| Parameters | |
|---|---|
| size | Requested size in bytes |
| alignment | Required alignment. Vertex and index buffers need 64 bytes (GX2_VERTEX_BUFFER_ALIGNMENT), uniform blocks 256 (GX2_UNIFORM_BLOCK_ALIGNMENT) and surfaces whatever GX2CalcSurfaceSizeAndAlignment() reports |
Block nCine:: RHI:: GX2:: Gx2Memory:: AllocColorSurfaceMem1(const GX2Surface& surface)
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Allocates the image of a colour surface in MEM1, or returns an invalid block if it doesn't fit.
Only valid while the application is in the foreground (see the namespace description). The surface's size and alignment must have been computed (GX2CalcSurfaceSizeAndAlignment()); the surface itself is not modified. The block is released with Free() like any other.
void nCine:: RHI:: GX2:: Gx2Memory:: Free(Block& block)
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Releases a block and resets it; the caller must know the GPU is done with it.
void nCine:: RHI:: GX2:: Gx2Memory:: FlushCpuWrites(const void* base,
std:: uint32_t size,
std:: uint32_t mode)
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Flushes CPU writes to a range out of the data cache and invalidates the GPU caches given by mode.
std:: uint32_t nCine:: RHI:: GX2:: Gx2Memory:: GetAllocatedBytes()
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Bytes currently allocated through Alloc().
std:: uint32_t nCine:: RHI:: GX2:: Gx2Memory:: GetMem1Bytes()
#include <nCine/Graphics/RHI/GX2/Gx2Memory.h>
Bytes currently allocated through AllocColorSurfaceMem1().