|
resonance 1.0.1
|
Cache of GS video memory, divided into a reserved palette region and a pool of texture blocks. More...
#include <vram.h>

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. | |
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.
| 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.
| void Rnd::VRAM::Init | ( | ) |
Reserve the palette region above the display buffers and link every record into the pool.
| 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".
| bClearPalettes | Non-zero to release resident palettes as well as blocks. |
| void Rnd::VRAM::BeginFrame | ( | ) |
Start a frame.
The body is empty. GfxDevice::BeginFrame() calls it.
| void Rnd::VRAM::EndFrame | ( | ) |
Release every lock, fold the frame counters into the running totals, and reset them.
| 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".
| void Rnd::VRAM::PrintStats | ( | const char * | pszPrefix | ) |
Report occupancy and the cache counters through the log.
No call site survives.
| pszPrefix | Text written before each line. |
| void Rnd::VRAM::GetLastFrameLoads | ( | int * | pnLoads, |
| int * | pnBlocks ) const |
Report the loads the previous frame performed.
| pnLoads | Receives the transfers. |
| pnBlocks | Receives the blocks those transfers moved. |
| 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.
| VramPalEntry * Rnd::VRAM::AllocPalEntry | ( | ) |
Take an unused record from the palette free list.
| 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.
| pEntry | Record to make resident. |
| nBlocks | Blocks to find. |
| void Rnd::VRAM::FreeBlock | ( | Entry * | pEntry | ) |
Put a record on the free list and merge it with whichever neighbours are also free.
| pEntry | Record to free. |
| 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().
| pEntry | Record to remove. |
| void Rnd::VRAM::UnlinkEntry | ( | Entry * | pEntry, |
| int | nList ) |
Take a record off one of the three lists.
| pEntry | Record to unlink. |
| nList | One of VramList. |
| void Rnd::VRAM::ReleaseEntry | ( | Entry * | pEntry | ) |
Return a record to the pool and forget which blocks it described.
| pEntry | Record to release. |
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.
| pKeep | Record that grows. |
| pAbsorb | Record immediately above it, which is released. |
|
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)".
| 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.
| pBitmap | Bitmap to fill, which supplies the shape and the destination. |
| nMemAddr | First block to read. |
| 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.
| pszName | Stem of the file to write. |
| int Rnd::VRAM::mSwaps |
Blocks released by eviction this frame.
| int Rnd::VRAM::mLoads |
Transfers into video memory this frame.
| int Rnd::VRAM::mLoadBlocks |
Blocks those transfers moved.
| int Rnd::VRAM::mMisses |
Lookups this frame that found their record not resident.
| int Rnd::VRAM::mFreeMerges |
Merges of adjacent free runs this frame.
| 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
| int Rnd::VRAM::mSpareFrameCounter |
| int Rnd::VRAM::mAccumSwaps |
Running total of mSwaps.
| int Rnd::VRAM::mAccumLoads |
Running total of mLoads.
| int Rnd::VRAM::mAccumLoadBlocks |
Running total of mLoadBlocks.
| int Rnd::VRAM::mAccumMisses |
Running total of mMisses.
| int Rnd::VRAM::mAccumFreeMerges |
Running total of mFreeMerges.
| int Rnd::VRAM::mReserved30 |
No instruction reads or writes it. +0x30
| int Rnd::VRAM::mBlocksInUse |
Blocks currently allocated out of the texture pool.
| int Rnd::VRAM::mFlushCount |
Packets submitted, advanced by GfxDevice::FlushGifPacket() through AdvanceLockCycle().
| Entry* Rnd::VRAM::mpChainHead |
Lowest record of the address ordered chain.
| Entry* Rnd::VRAM::mpChainTail |
Highest record of the address ordered chain.
| Entry* Rnd::VRAM::mpListHead[kVramListCount] |
First record of each of the three lists, indexed by VramList.
| Entry* Rnd::VRAM::mpListTail[kVramListCount] |
Last record of each of the three lists, indexed by VramList.
| int Rnd::VRAM::mPaletteBase |
First block of the palette region.
| int Rnd::VRAM::mPaletteEnd |
First block above the palette region, where the texture pool begins.
| unsigned char Rnd::VRAM::mLockGeneration |
Generation, from one to kVramLockGenerations, that a lookup locks into.