resonance 1.0.1
Loading...
Searching...
No Matches
vram.h File Reference
#include <libgraph.h>
#include "rndartt/abitmap.h"
Include dependency graph for vram.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  VramPalEntry
 One entry of the GS video memory palette table. More...
class  Rnd::VRAM
 Cache of GS video memory, divided into a reserved palette region and a pool of texture blocks. More...
class  Rnd::VRAM::Entry
 One entry of the GS video memory block table. More...

Namespaces

namespace  Rnd
 The rendering engine.

Enumerations

enum  VramBlockKind { kVramBlockKindNone = 0 , kVramBlockKindTexture = 2 , kVramBlockKindRenderTarget = 3 , kVramBlockKindFree = 4 }
 Kind of block a table record describes. More...
enum  VramList { kVramListFree = 0 , kVramListUsed = 1 , kVramListPool = 2 }
 Which of the table's three record lists a record belongs to. More...
enum  GsPixelStorageMode {
  kGsPsmCt32 = 0 , kGsPsmCt24 = 1 , kGsPsmCt16 = 2 , kGsPsmT8 = 19 ,
  kGsPsmT4 = 20
}
 GS pixel storage modes this unit distinguishes. More...

Variables

constexpr int kVramBlockBytes = 256
 Bytes in one GS video memory block, the unit every address and size in this unit uses.
constexpr int kVramBlocks = 0x4000
 Blocks of GS video memory on the console, 4 MiB divided by the block size.
constexpr int kVramPageBlocks = 32
 Blocks in one GS page, which is 8 KiB.
constexpr int kVramTableEntries = 1024
 Records in the block table, all of them file scope and linked into one pool at start-up.
constexpr int kVramPalEntries = 1024
 Records in the palette table.
constexpr int kVramPalSlots = 192
 Palette slots the reserved palette region divides into.
constexpr int kVramPalSlotWords = 6
 Words of the palette occupancy bitmap, one bit per slot.
constexpr int kVramPalBlocks = 4
 Blocks one palette occupies, so 1 KiB for a 256 entry 32-bit table.
constexpr int kVramPalAreaBlocks = kVramPalSlots * kVramPalBlocks
 Blocks the palette region reserves, which is every slot at its full size.
constexpr int kVramLockGenerations = 3
 Rotating lock generations, so a block locked for one packet is released two packets later.
constexpr int kVramListCount = 3
 Record lists the table maintains, which is one head and one tail array of this length.
constexpr int kVramLockedPerGeneration = 128
 Records one generation may lock.
constexpr int kVramPalSlotsPerWord = 32
 Slots one word of the palette occupancy bitmap covers.
constexpr int kVramPalSwapOutLimit = 16
 Palettes SwapOutOldest() releases at most in one pass.
constexpr int kVramPalTbw = 1
 Buffer width, in 64 texel units, that a palette transfer uses.
constexpr int kGsTexelsPerTbwUnit = 64
 Texels one unit of a GS transfer buffer width covers.
constexpr int kVramFrameCounterBytes = 28
 Bytes of the frame counter run EndFrame() clears, from mSwaps through mSpareFrameCounter.
constexpr int kVramWipeTileTexels = 64
 Texels along each edge of a tile Rnd::VRAM::WipeVram() writes.
constexpr int kVramWipeRows = 512
 Texel rows Rnd::VRAM::WipeVram() walks.
constexpr int kVramWipeBlocksPerRow = 64
 Blocks Rnd::VRAM::WipeVram() advances its destination by for each texel row.
constexpr int kVramWipeTileBytes = kVramWipeTileTexels * kVramWipeTileTexels * 4
 Bytes of zeros Rnd::VRAM::WipeVram() builds, one tile at four bytes per texel.
constexpr int kVramSwapBudgetMultiple = 4
 Multiple of a request that eviction frees before the allocator retries its search.
constexpr int kVramLockPinned = 8
 Bit of a record's lock mask that pins it against eviction until a caller clears it.
constexpr int kVramLockGenerationMask = 7
 Bits of a record's lock mask the rotating generations own.
const int g_anGsPixelStorageModes [kABitmapFormatCount]
 GS storage mode of each ABitmapFormat, indexed by the format code.
const int g_anBitsPerPixelTable [kABitmapFormatCount]
 Bits per texel of each ABitmapFormat once it reaches GS memory, indexed by the format code.
VRAM Rnd::TheVRAM
 The video memory cache.
Rnd::VRAM::Entry g_vramEntries [kVramTableEntries]
 Every block table record.
VramPalEntry g_vramPalEntries [kVramPalEntries]
 Every palette table record.
VramPalEntry * g_pVramPalFree
 First unused palette record.
VramPalEntry * g_pVramPalUsed
 First resident palette record, most recently used first.
unsigned g_adVramPalSlots [kVramPalSlotWords]
 Occupancy of the palette region, one bit per slot.
int g_anVramLockCount [kVramLockGenerations]
 Block records each generation has locked.
int g_anVramPalLockCount [kVramLockGenerations]
 Palette records each generation has locked.
Rnd::VRAM::Entry * g_apVramLocked [kVramLockGenerations][kVramLockedPerGeneration]
 Block records each generation has locked, in the order they were locked.
VramPalEntry * g_apVramPalLocked [kVramLockGenerations][kVramLockedPerGeneration]
 Palette records each generation has locked, in the order they were locked.
int g_nVramLoadsLastFrame
 Transfers the previous frame performed.
int g_nVramLoadBlocksLastFrame
 Blocks the previous frame's transfers moved.
sceGsLoadImage g_vramUploadLoadImage
 Transfer descriptor Rnd::VRAM::Entry::UploadImage() reuses.
sceGsLoadImage g_vramUploadSubLoadImage
 Transfer descriptor Rnd::VRAM::Entry::UploadSubImage() reuses.
sceGsLoadImage g_vramPalLoadImage
 Transfer descriptor VramPalEntry::UploadClut() reuses.
sceGsLoadImage g_vramWipeLoadImage
 Transfer descriptor Rnd::VRAM::WipeVram() reuses.
sceGsStoreImage g_vramReadBackStoreImage
 Transfer descriptor Rnd::VRAM::ReadBackBitmap() reuses, and therefore Rnd::VRAM::Screendump().
int g_nScreendumpIndex
 Number the next Rnd::VRAM::Screendump() file takes, advanced after each dump.

Enumeration Type Documentation

◆ VramBlockKind

Kind of block a table record describes.

The value is a single byte at +0x04. Only four of its values appear in the image, and the two that arrive from outside come from Rnd::PsTex. The titles of the first three are inferred from the call sites; only kVramBlockKindFree is settled, because Rnd::VRAM::Entry::MakeFree() writes it and Rnd::VRAM::AllocBlock() tests for it when deciding whether a block may be split.

Enumerator
kVramBlockKindNone 

Written by Rnd::VRAM::Entry::Reset() on a released record.

kVramBlockKindTexture 

Passed by Rnd::PsTex::RestoreSurfaces().

kVramBlockKindRenderTarget 

Rounded up to a page by GetBlockAddr().

kVramBlockKindFree 

Unallocated space the allocator may split.

◆ VramList

enum VramList

Which of the table's three record lists a record belongs to.

Rnd::VRAM::UnlinkEntry() takes the value as an index into the head and tail arrays. The three lists therefore share one pair of arrays rather than six separate pointers. Every title is inferred from what the list is walked for.

Enumerator
kVramListFree 

Blocks available for allocation, walked best fit.

kVramListUsed 

Blocks a surface owns, walked for the least recently used victim.

kVramListPool 

Records describing no block, the supply GetAvailEntry() draws from.

◆ GsPixelStorageMode

GS pixel storage modes this unit distinguishes.

Three of these select a page shape other than the default. The remaining modes take the 64 by 32 texel page Rnd::VRAM::Entry::ComputeBlockSize() falls back to, and the jump table the routine dispatches through routes PSMCT16S to that fallback rather than to the 64 by 64 page the hardware gives it. The two 32-bit and 24-bit modes appear because g_anGsPixelStorageModes maps bitmap formats onto them.

Enumerator
kGsPsmCt32 

Thirty-two bits per texel, direct colour.

kGsPsmCt24 

Twenty-four bits per texel, direct colour.

kGsPsmCt16 

Sixteen bits per texel, direct colour.

kGsPsmT8 

Eight bits per texel, indexed.

kGsPsmT4 

Four bits per texel, indexed.

Variable Documentation

◆ kVramBlockBytes

int kVramBlockBytes = 256
constexpr

Bytes in one GS video memory block, the unit every address and size in this unit uses.

◆ kVramBlocks

int kVramBlocks = 0x4000
constexpr

Blocks of GS video memory on the console, 4 MiB divided by the block size.

◆ kVramPageBlocks

int kVramPageBlocks = 32
constexpr

Blocks in one GS page, which is 8 KiB.

◆ kVramTableEntries

int kVramTableEntries = 1024
constexpr

Records in the block table, all of them file scope and linked into one pool at start-up.

◆ kVramPalEntries

int kVramPalEntries = 1024
constexpr

Records in the palette table.

◆ kVramPalSlots

int kVramPalSlots = 192
constexpr

Palette slots the reserved palette region divides into.

◆ kVramPalSlotWords

int kVramPalSlotWords = 6
constexpr

Words of the palette occupancy bitmap, one bit per slot.

◆ kVramPalBlocks

int kVramPalBlocks = 4
constexpr

Blocks one palette occupies, so 1 KiB for a 256 entry 32-bit table.

◆ kVramPalAreaBlocks

int kVramPalAreaBlocks = kVramPalSlots * kVramPalBlocks
constexpr

Blocks the palette region reserves, which is every slot at its full size.

◆ kVramLockGenerations

int kVramLockGenerations = 3
constexpr

Rotating lock generations, so a block locked for one packet is released two packets later.

◆ kVramListCount

int kVramListCount = 3
constexpr

Record lists the table maintains, which is one head and one tail array of this length.

◆ kVramLockedPerGeneration

int kVramLockedPerGeneration = 128
constexpr

Records one generation may lock.

◆ kVramPalSlotsPerWord

int kVramPalSlotsPerWord = 32
constexpr

Slots one word of the palette occupancy bitmap covers.

◆ kVramPalSwapOutLimit

int kVramPalSwapOutLimit = 16
constexpr

Palettes SwapOutOldest() releases at most in one pass.

◆ kVramPalTbw

int kVramPalTbw = 1
constexpr

Buffer width, in 64 texel units, that a palette transfer uses.

A palette is never wider.

◆ kGsTexelsPerTbwUnit

int kGsTexelsPerTbwUnit = 64
constexpr

Texels one unit of a GS transfer buffer width covers.

◆ kVramFrameCounterBytes

int kVramFrameCounterBytes = 28
constexpr

Bytes of the frame counter run EndFrame() clears, from mSwaps through mSpareFrameCounter.

◆ kVramWipeTileTexels

int kVramWipeTileTexels = 64
constexpr

Texels along each edge of a tile Rnd::VRAM::WipeVram() writes.

◆ kVramWipeRows

int kVramWipeRows = 512
constexpr

Texel rows Rnd::VRAM::WipeVram() walks.

◆ kVramWipeBlocksPerRow

int kVramWipeBlocksPerRow = 64
constexpr

Blocks Rnd::VRAM::WipeVram() advances its destination by for each texel row.

◆ kVramWipeTileBytes

int kVramWipeTileBytes = kVramWipeTileTexels * kVramWipeTileTexels * 4
constexpr

Bytes of zeros Rnd::VRAM::WipeVram() builds, one tile at four bytes per texel.

◆ kVramSwapBudgetMultiple

int kVramSwapBudgetMultiple = 4
constexpr

Multiple of a request that eviction frees before the allocator retries its search.

◆ kVramLockPinned

int kVramLockPinned = 8
constexpr

Bit of a record's lock mask that pins it against eviction until a caller clears it.

◆ kVramLockGenerationMask

int kVramLockGenerationMask = 7
constexpr

Bits of a record's lock mask the rotating generations own.

◆ g_anGsPixelStorageModes

const int g_anGsPixelStorageModes[kABitmapFormatCount]
extern

GS storage mode of each ABitmapFormat, indexed by the format code.

The run-length format maps to PSMT8, the form it is decompressed into before upload.

Ghidra address:
NTSC-U/C: 0x0070d3d0
Ghidra address:
PAL: 0x007512c0

◆ g_anBitsPerPixelTable

const int g_anBitsPerPixelTable[kABitmapFormatCount]
extern

Bits per texel of each ABitmapFormat once it reaches GS memory, indexed by the format code.

Ghidra address:
NTSC-U/C: 0x0070d3e8
Ghidra address:
PAL: 0x007512d8

◆ g_vramEntries

Rnd::VRAM::Entry g_vramEntries[kVramTableEntries]
extern

Every block table record.

Ghidra address:
NTSC-U/C: 0x0070d468
Ghidra address:
PAL: 0x00751358

◆ g_vramPalEntries

VramPalEntry g_vramPalEntries[kVramPalEntries]
extern

Every palette table record.

Ghidra address:
NTSC-U/C: 0x00714468
Ghidra address:
PAL: 0x00758358

◆ g_pVramPalFree

VramPalEntry* g_pVramPalFree
extern

First unused palette record.

Ghidra address:
NTSC-U/C: 0x0086f6c0
Ghidra address:
PAL: 0x008b3da0

◆ g_pVramPalUsed

VramPalEntry* g_pVramPalUsed
extern

First resident palette record, most recently used first.

Ghidra address:
NTSC-U/C: 0x0086f6c4
Ghidra address:
PAL: 0x008b3da4

◆ g_adVramPalSlots

unsigned g_adVramPalSlots[kVramPalSlotWords]
extern

Occupancy of the palette region, one bit per slot.

Ghidra address:
NTSC-U/C: 0x008ef098
Ghidra address:
PAL: 0x00934098

◆ g_anVramLockCount

int g_anVramLockCount[kVramLockGenerations]
extern

Block records each generation has locked.

Ghidra address:
NTSC-U/C: 0x008ef5a0
Ghidra address:
PAL: 0x009345a0

◆ g_anVramPalLockCount

int g_anVramPalLockCount[kVramLockGenerations]
extern

Palette records each generation has locked.

Ghidra address:
NTSC-U/C: 0x008ef6f0
Ghidra address:
PAL: 0x009346f0

◆ g_apVramLocked

Block records each generation has locked, in the order they were locked.

Ghidra address:
NTSC-U/C: 0x00902380
Ghidra address:
PAL: 0x009473a0

◆ g_apVramPalLocked

Palette records each generation has locked, in the order they were locked.

Ghidra address:
NTSC-U/C: 0x008f0140
Ghidra address:
PAL: 0x00935140

◆ g_nVramLoadsLastFrame

int g_nVramLoadsLastFrame
extern

Transfers the previous frame performed.

Ghidra address:
NTSC-U/C: 0x0089df80
Ghidra address:
PAL: 0x008e2fc0

◆ g_nVramLoadBlocksLastFrame

int g_nVramLoadBlocksLastFrame
extern

Blocks the previous frame's transfers moved.

Ghidra address:
NTSC-U/C: 0x0089df84
Ghidra address:
PAL: 0x008e2fc4

◆ g_vramUploadLoadImage

sceGsLoadImage g_vramUploadLoadImage
extern

Transfer descriptor Rnd::VRAM::Entry::UploadImage() reuses.

Ghidra address:
NTSC-U/C: 0x0089de60
Ghidra address:
PAL: 0x008e2ea0

◆ g_vramUploadSubLoadImage

sceGsLoadImage g_vramUploadSubLoadImage
extern

Transfer descriptor Rnd::VRAM::Entry::UploadSubImage() reuses.

Ghidra address:
NTSC-U/C: 0x0089dec0
Ghidra address:
PAL: 0x008e2f00

◆ g_vramPalLoadImage

sceGsLoadImage g_vramPalLoadImage
extern

Transfer descriptor VramPalEntry::UploadClut() reuses.

Ghidra address:
NTSC-U/C: 0x0089df20
Ghidra address:
PAL: 0x008e2f60

◆ g_vramWipeLoadImage

sceGsLoadImage g_vramWipeLoadImage
extern

Transfer descriptor Rnd::VRAM::WipeVram() reuses.

Ghidra address:
NTSC-U/C: 0x0089de00
Ghidra address:
PAL: 0x008e2e40

◆ g_vramReadBackStoreImage

sceGsStoreImage g_vramReadBackStoreImage
extern

Transfer descriptor Rnd::VRAM::ReadBackBitmap() reuses, and therefore Rnd::VRAM::Screendump().

Ghidra address:
NTSC-U/C: 0x0089dd90
Ghidra address:
PAL: 0x008e2dd0

◆ g_nScreendumpIndex

int g_nScreendumpIndex
extern

Number the next Rnd::VRAM::Screendump() file takes, advanced after each dump.

Ghidra address:
NTSC-U/C: 0x00718468
Ghidra address:
PAL: 0x0075c358