resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::VRAM Class Reference

Cache of GS video memory, divided into a reserved palette region and a pool of texture blocks. More...

#include <vram.h>

Collaboration diagram for Rnd::VRAM:

Classes

class  Entry
 One entry of the GS video memory block table. More...

Public Member Functions

 ~VRAM ()
 Destroy the table.
void Init ()
 Reserve the palette region above the display buffers and link every record into the pool.
void Clear (int bClearPalettes)
 Release every allocation and rebuild the pool as one free run covering the texture pool.
void BeginFrame ()
 Start a frame.
void EndFrame ()
 Release every lock, fold the frame counters into the running totals, and reset them.
void AdvanceLockCycle ()
 Move to the next lock generation and release everything the generation it arrives at locked.
void PrintStats (const char *pszPrefix)
 Report occupancy and the cache counters through the log.
void GetLastFrameLoads (int *pnLoads, int *pnBlocks) const
 Report the loads the previous frame performed.
Entry * GetAvailEntry ()
 Take an unused record from the pool.
VramPalEntry * AllocPalEntry ()
 Take an unused record from the palette free list.
void AllocBlock (Entry *pEntry, unsigned short nBlocks)
 Find blocks for a record, evicting resident blocks when the free list cannot serve it.
void FreeBlock (Entry *pEntry)
 Put a record on the free list and merge it with whichever neighbours are also free.
void RemoveFromChain (Entry *pEntry)
 Take a record out of the address ordered chain and merge across the gap it leaves behind.
void UnlinkEntry (Entry *pEntry, int nList)
 Take a record off one of the three lists.
void ReleaseEntry (Entry *pEntry)
 Return a record to the pool and forget which blocks it described.
void MergeBlocks (Entry *pKeep, Entry *pAbsorb)
 Absorb one free run into the free run below it.
void ReadBackBitmap (ABitmap *pBitmap, unsigned short nMemAddr)
 Move a region of video memory back into a bitmap.
void Screendump (const char *pszName)
 Write the display buffer to a numbered file.

Static Public Member Functions

static void WipeVram ()
 Fill the whole of video memory with zeros, one 64 by 64 tile at a time.

Public Attributes

int mSwaps
 Blocks released by eviction this frame.
int mLoads
 Transfers into video memory this frame.
int mLoadBlocks
 Blocks those transfers moved.
int mMisses
 Lookups this frame that found their record not resident.
int mFreeMerges
 Merges of adjacent free runs this frame.
int mRequests
 Lookups this frame, which is the divisor of the two reported percentages.
int mSpareFrameCounter
int mAccumSwaps
 Running total of mSwaps.
int mAccumLoads
 Running total of mLoads.
int mAccumLoadBlocks
 Running total of mLoadBlocks.
int mAccumMisses
 Running total of mMisses.
int mAccumFreeMerges
 Running total of mFreeMerges.
int mReserved30
int mBlocksInUse
 Blocks currently allocated out of the texture pool.
int mFlushCount
 Packets submitted, advanced by GfxDevice::FlushGifPacket() through AdvanceLockCycle().
Entry * mpChainHead
 Lowest record of the address ordered chain.
Entry * mpChainTail
 Highest record of the address ordered chain.
Entry * mpListHead [kVramListCount]
 First record of each of the three lists, indexed by VramList.
Entry * mpListTail [kVramListCount]
 Last record of each of the three lists, indexed by VramList.
int mPaletteBase
 First block of the palette region.
int mPaletteEnd
 First block above the palette region, where the texture pool begins.
unsigned char mLockGeneration
 Generation, from one to kVramLockGenerations, that a lookup locks into.

Detailed Description

Cache of GS video memory, divided into a reserved palette region and a pool of texture blocks.

The class is not polymorphic and has no RTTI. Its name comes from the debugging symbols of the North American demo release. The demo's PrintStats() has the same instructions as PrintStats() here. The methods AllocBlock() and Clear() appear verbatim in the unit's own diagnostics, as do the members mMemAddr, mpPrev, and mpNext, the index vpalIndex, the word "lockmask", and the phrases "VRAM table entry" and "VRAM pal entry".

The table is a single file scope instance. Its records are two separate file scope arrays rather than members. The start-up glue constructs the two arrays element by element and the instance not at all, and Init() addresses both arrays absolutely while addressing its members through the instance pointer.

Allocation is best fit over the free list. When no free run is large enough the least recently used unlocked resident block of sufficient size is taken instead, and when no such block exists either, resident blocks are released until four times the request has been freed and the search restarts. Recency is the packet counter mFlushCount rather than a frame counter, because GfxDevice::FlushGifPacket() advances it.

Eviction is held off by a rotating lock. Every lookup within a packet adds its record to the current generation's lock list, and AdvanceLockCycle() moves to the next generation and releases everything the generation it arrives at locked. With kVramLockGenerations generations a record stays locked for the two packets after the one that used it.

The recovered size is 0x65 bytes, which is a lower bound from the highest member written. No derived class and no allocation pins it from outside, and the record arrays begin at the next four byte boundary above it.

The image records no access control. The allocator internals are reached only from inside the unit, but from Entry rather than from the table. A friend declaration fits the image as well as the public section written here.

Constructor & Destructor Documentation

◆ ~VRAM()

Rnd::VRAM::~VRAM ( )

Destroy the table.

The body is empty. The start-up glue's shutdown branch calls it for the file scope instance, which is what identifies it as the destructor. GfxDevice::Terminate() also calls it explicitly on Rnd::TheVRAM as its last step.

Ghidra address:
NTSC-U/C: 0x005149f0
Ghidra address:
PAL: 0x00554d20

Member Function Documentation

◆ Init()

void Rnd::VRAM::Init ( )

Reserve the palette region above the display buffers and link every record into the pool.

Ghidra address:
NTSC-U/C: 0x00512850
Ghidra address:
PAL: 0x00552b38

◆ Clear()

void Rnd::VRAM::Clear ( int bClearPalettes)

Release every allocation and rebuild the pool as one free run covering the texture pool.

A record still locked when the table is cleared is reported through "Clear() - resetting lock on entry %d".

Parameters
bClearPalettesNon-zero to release resident palettes as well as blocks.
Ghidra address:
NTSC-U/C: 0x00512970
Ghidra address:
PAL: 0x00552c58

◆ BeginFrame()

void Rnd::VRAM::BeginFrame ( )

Start a frame.

The body is empty. GfxDevice::BeginFrame() calls it.

Ghidra address:
NTSC-U/C: 0x00514cd8
Ghidra address:
PAL: 0x00555008

◆ EndFrame()

void Rnd::VRAM::EndFrame ( )

Release every lock, fold the frame counters into the running totals, and reset them.

Ghidra address:
NTSC-U/C: 0x00513190
Ghidra address:
PAL: 0x00553478

◆ AdvanceLockCycle()

void Rnd::VRAM::AdvanceLockCycle ( )

Move to the next lock generation and release everything the generation it arrives at locked.

A record whose lock bit is already clear is reported through "VRAM should have lockmask %d set but instead has %d".

Ghidra address:
NTSC-U/C: 0x00513298
Ghidra address:
PAL: 0x00553580

◆ PrintStats()

void Rnd::VRAM::PrintStats ( const char * pszPrefix)

Report occupancy and the cache counters through the log.

No call site survives.

Parameters
pszPrefixText written before each line.
Ghidra address:
NTSC-U/C: 0x00513438
Ghidra address:
PAL: 0x00553720

◆ GetLastFrameLoads()

void Rnd::VRAM::GetLastFrameLoads ( int * pnLoads,
int * pnBlocks ) const

Report the loads the previous frame performed.

Parameters
pnLoadsReceives the transfers.
pnBlocksReceives the blocks those transfers moved.
Ghidra address:
NTSC-U/C: 0x00514ce0
Ghidra address:
PAL: 0x00555010

◆ GetAvailEntry()

Entry * Rnd::VRAM::GetAvailEntry ( )

Take an unused record from the pool.

Exhaustion is reported through "Out of VRAM Table Entries!!!" and the routine then returns null, which every caller dereferences without checking.

Returns
The record, or null once the pool is empty.
Ghidra address:
NTSC-U/C: 0x005149f8
Ghidra address:
PAL: 0x00554d28

◆ AllocPalEntry()

VramPalEntry * Rnd::VRAM::AllocPalEntry ( )

Take an unused record from the palette free list.

Returns
The record.
Ghidra address:
NTSC-U/C: 0x00515360
Ghidra address:
PAL: 0x00555690

◆ AllocBlock()

void Rnd::VRAM::AllocBlock ( Entry * pEntry,
unsigned short nBlocks )

Find blocks for a record, evicting resident blocks when the free list cannot serve it.

The title is attested, through the diagnostic of the palette allocator of the same name. On success the record is resident and joins the address ordered chain in place of the run it took, and any remainder of that run becomes a new free record. When no free run is large enough, the least recently used unlocked resident block that is large enough is taken whole before any block is evicted.

Parameters
pEntryRecord to make resident.
nBlocksBlocks to find.
Ghidra address:
NTSC-U/C: 0x00512e08
Ghidra address:
PAL: 0x005530f0

◆ FreeBlock()

void Rnd::VRAM::FreeBlock ( Entry * pEntry)

Put a record on the free list and merge it with whichever neighbours are also free.

Parameters
pEntryRecord to free.
Ghidra address:
NTSC-U/C: 0x00512b50
Ghidra address:
PAL: 0x00552e38

◆ RemoveFromChain()

void Rnd::VRAM::RemoveFromChain ( Entry * pEntry)

Take a record out of the address ordered chain and merge across the gap it leaves behind.

No call site survives. The body appears inline inside AllocBlock() and FreeBlock().

Parameters
pEntryRecord to remove.
Ghidra address:
NTSC-U/C: 0x00512cf0
Ghidra address:
PAL: 0x00552fd8

◆ UnlinkEntry()

void Rnd::VRAM::UnlinkEntry ( Entry * pEntry,
int nList )

Take a record off one of the three lists.

Parameters
pEntryRecord to unlink.
nListOne of VramList.
Ghidra address:
NTSC-U/C: 0x00514a48
Ghidra address:
PAL: 0x00554d78

◆ ReleaseEntry()

void Rnd::VRAM::ReleaseEntry ( Entry * pEntry)

Return a record to the pool and forget which blocks it described.

Parameters
pEntryRecord to release.
Ghidra address:
NTSC-U/C: 0x00514b60
Ghidra address:
PAL: 0x00554e90

◆ MergeBlocks()

void Rnd::VRAM::MergeBlocks ( Entry * pKeep,
Entry * pAbsorb )

Absorb one free run into the free run below it.

The image calls the routine nowhere. It is the out of line copy of a body the compiler expanded into AllocBlock(), FreeBlock(), and RemoveFromChain(), and those three use it here.

Parameters
pKeepRecord that grows.
pAbsorbRecord immediately above it, which is released.
Ghidra address:
NTSC-U/C: 0x00514bb8
Ghidra address:
PAL: 0x00554ee8

◆ WipeVram()

void Rnd::VRAM::WipeVram ( )
static

Fill the whole of video memory with zeros, one 64 by 64 tile at a time.

No call site survives, so the receiver is unverified and the routine reads no member. Each tile is reported through "Clearing vram at addr: %d ($%x)".

Ghidra address:
NTSC-U/C: 0x00514db8
Ghidra address:
PAL: 0x005550e8

◆ ReadBackBitmap()

void Rnd::VRAM::ReadBackBitmap ( ABitmap * pBitmap,
unsigned short nMemAddr )

Move a region of video memory back into a bitmap.

The region starts at the top left of nMemAddr and has the bitmap's size, with the buffer width rounded up to whole 64-texel units and the storage mode taken from g_anGsPixelStorageModes. The data cache is written back first, and the GS paths are drained before and after the transfer.

Parameters
pBitmapBitmap to fill, which supplies the shape and the destination.
nMemAddrFirst block to read.
Ghidra address:
NTSC-U/C: 0x00514d00
Ghidra address:
PAL: 0x00555030

◆ Screendump()

void Rnd::VRAM::Screendump ( const char * pszName)

Write the display buffer to a numbered file.

The zone "temp" is reset and supplies a 16-bit bitmap of the display size, which ReadBackBitmap() fills from block 0. The red and blue channels are swapped without testing g_nSkipColorSwap, and AGfxFile::Write() writes <pszName>_<n>.bmp, n being g_nScreendumpIndex before it advances. The previous zone is selected again once the pixels are allocated.

Parameters
pszNameStem of the file to write.
Ghidra address:
NTSC-U/C: 0x00513528
Ghidra address:
PAL: 0x00553810

Member Data Documentation

◆ mSwaps

int Rnd::VRAM::mSwaps

Blocks released by eviction this frame.

◆ mLoads

int Rnd::VRAM::mLoads

Transfers into video memory this frame.

◆ mLoadBlocks

int Rnd::VRAM::mLoadBlocks

Blocks those transfers moved.

◆ mMisses

int Rnd::VRAM::mMisses

Lookups this frame that found their record not resident.

◆ mFreeMerges

int Rnd::VRAM::mFreeMerges

Merges of adjacent free runs this frame.

◆ mRequests

int Rnd::VRAM::mRequests

Lookups this frame, which is the divisor of the two reported percentages.

A seventh frame counter, cleared with the others and never advanced or read. +0x18

◆ mSpareFrameCounter

int Rnd::VRAM::mSpareFrameCounter

◆ mAccumSwaps

int Rnd::VRAM::mAccumSwaps

Running total of mSwaps.

◆ mAccumLoads

int Rnd::VRAM::mAccumLoads

Running total of mLoads.

◆ mAccumLoadBlocks

int Rnd::VRAM::mAccumLoadBlocks

Running total of mLoadBlocks.

◆ mAccumMisses

int Rnd::VRAM::mAccumMisses

Running total of mMisses.

◆ mAccumFreeMerges

int Rnd::VRAM::mAccumFreeMerges

Running total of mFreeMerges.

◆ mReserved30

int Rnd::VRAM::mReserved30

No instruction reads or writes it. +0x30

◆ mBlocksInUse

int Rnd::VRAM::mBlocksInUse

Blocks currently allocated out of the texture pool.

◆ mFlushCount

int Rnd::VRAM::mFlushCount

Packets submitted, advanced by GfxDevice::FlushGifPacket() through AdvanceLockCycle().

◆ mpChainHead

Entry* Rnd::VRAM::mpChainHead

Lowest record of the address ordered chain.

◆ mpChainTail

Entry* Rnd::VRAM::mpChainTail

Highest record of the address ordered chain.

◆ mpListHead

Entry* Rnd::VRAM::mpListHead[kVramListCount]

First record of each of the three lists, indexed by VramList.

◆ mpListTail

Entry* Rnd::VRAM::mpListTail[kVramListCount]

Last record of each of the three lists, indexed by VramList.

◆ mPaletteBase

int Rnd::VRAM::mPaletteBase

First block of the palette region.

◆ mPaletteEnd

int Rnd::VRAM::mPaletteEnd

First block above the palette region, where the texture pool begins.

◆ mLockGeneration

unsigned char Rnd::VRAM::mLockGeneration

Generation, from one to kVramLockGenerations, that a lookup locks into.


The documentation for this class was generated from the following file: