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

PlayStation 2 texture, owner of the GS residency of its mip levels. More...

#include <pstex.h>

Inheritance diagram for Rnd::PsTex:
Collaboration diagram for Rnd::PsTex:

Public Member Functions

 PsTex (const HxStr &name)
 Construct a texture with no GS residency.
virtual ~PsTex ()
 Release the GS residency and the texture.
virtual ACanvas * LockMipBitmap (int nMip, int nReserved, int nFlags)
 Give the caller the canvas over a mip level to draw into.
virtual void UnlockMipBitmap ()
 Take back the canvas LockMipBitmap() handed out.
virtual void SetPalette (APalette *pPalette, int nReserved)
 Replace the palette of the texture.
virtual void SetGsPageInUse (bool bInUse)
 Pin the video memory block of mip 0 against eviction, or release the pin.
virtual void FreeLoadedBitmaps ()
 Release every loaded bitmap and every GS surface.
virtual void RestoreSurfaces ()
 Rebuild the GS state of the whole texture from the loaded bitmaps.
bool BindToGsSlot (unsigned nTexFunc)
 Make the texture current on the GS, with the given texture function.
void BindAsRenderTarget ()
 Make mip 0 the surface the GS draws into.
int UploadBitmapMipToGs (int nMip)
 Upload one mip level into the video memory block of its level.
int UploadMipAndBuildMipTbp (int nMip, bool bSkipIfResident)
 Resolve one mip level's GS block address, uploading the level when needed.
void UploadPendingMips ()
 Upload every level whose dirty bit is set, then clear the mask.
Public Member Functions inherited from Rnd::Tex
 Tex (const HxStr &name)
 Construct a texture with no bitmap.
virtual ~Tex ()
 Free the loaded bitmaps and drop every reference to this texture.
int GetBitmapInfo (int &nWidth, int &nHeight, int &nBitsPerPixel, int &nBytes)
 Report the size of mip level 0 and the bytes every loaded level occupies.
const HxStr & GetRelativeBitmapPath () const
 Report mBitmapPath relative to FilePath::sRoot.
virtual void DumpText (Dbg &sink)
 Write the dimensions, the mip selector, the path, and the flag names to sink.
virtual void Save (Stream &stream)
 Write revision 4, the three dimensions, the path, mFlags, and mMipSelect.
virtual void Replace (Object *pFrom, Object *pTo)
 Do nothing.
virtual const HxStr & ClassName () const
 Report the registered class name, "Tex".
virtual void Copy (const Object *pSource, unsigned nFlags)
 Take the dimensions, path, mip selector, and flags of another texture and reload.
virtual void Load (Stream &stream)
 Replace this texture's configuration from stream and reload.
bool IsLoadComplete ()
 Report whether every requested mip level has finished loading.
void SetBitmapConfig (int nWidth, int nHeight, int nBitsPerPixel, const HxStr &path, int nMipSelect, int nFlags)
 Point the texture at a bitmap and restart its load.
bool PollAsyncMips ()
 Advance the asynchronous mip loads and report whether any level is still outstanding.
void AllocateBitmapFromStream ()
 Start loading the configured bitmap, or build a blank one when no path is set.
void CancelPendingMips ()
 Cancel whatever mip reads are still outstanding and drop every mip handle.
virtual void ReloadBitmaps ()
 Release the loaded bitmaps and start loading from the configured path again.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().

Static Public Member Functions

static void Init ()
 Install this class as the texture the renderer builds and program the default filtering.
Static Public Member Functions inherited from Rnd::Tex
static void * operator new (size_t nSize)
 Allocate a texture block under the tag "Rnd::Tex".
static void operator delete (void *pBlock)
 Release a texture block under the same tag.

Protected Member Functions

virtual void OnMipLoaded (int nMip)
 Take delivery of one mip level whose read has just finished.
Protected Member Functions inherited from Rnd::Tex
void WaitForMipsLoaded ()
 Block until every requested mip level has arrived, pumping the asynchronous reads meanwhile.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.

Additional Inherited Members

Public Types inherited from Rnd::Tex
enum  TexFunc { kTexFuncModulate = 0 , kTexFuncDecal = 1 , kTexFuncHighlight = 2 , kTexFuncHighlight2 = 3 }
 Texture function, the GS TEX0.TFX field, which decides how a texel meets the vertex. More...
Public Attributes inherited from Rnd::Tex
int mWidth
int mHeight
int mBitsPerPixel
int mFlags
 Flag word SetBitmapConfig() records and DumpText() labels " flags:".
int mMipSelect
 Mip selector SetBitmapConfig() records, starting at -0x80.
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal
Static Public Attributes inherited from Rnd::Tex
static Tex *(* sNew )(const HxStr &name)
 Creator the registered "Tex" class builds through.
static HxStr sClassName
 Registered class name of Rnd::Tex, the string "Tex".
Protected Attributes inherited from Rnd::Tex
std::vector< int > mMipHandles
unsigned char mPendingMipMask
FilePath mBitmapPath
int mZone
std::vector< ABitmap * > mLoadedBitmaps
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

PlayStation 2 texture, owner of the GS residency of its mip levels.

Its RTTI descriptor is at 0x008efec0. It has Rnd::Tex as its one public base at offset 0. The vtable is at 0x008318c0 and has the same sixteen entries as the Rnd::Tex table. Slot 0 is the compiler-generated type_info accessor at 0x0059a4c8, slot 1 the destructor, slots 2 through 7 the Rnd::Object virtuals, and slots 8 through 15 the eight Rnd::Tex declares. This class overrides slots 9 through 15 and supplies its own destructor.

Slot 8 is a special case. The Rnd::PsTex table points at 0x0059a8c8 where the Rnd::Tex table points at 0x004e73c8, and the two bodies are identical. Both invoke the slot 13 virtual and then Rnd::Tex::AllocateBitmapFromStream(). The second copy exists because the member is defined inline in the class body, and each translation unit that emits a vtable emits its own copy. Slot 8 is therefore not an override of this class and is not declared here.

A texture becomes a Rnd::PsTex through the creator hook. Init() installs NewPsTex() over Rnd::Tex::sNew, and GfxDevice::Init() runs Init() at 0x0049af50. Every texture the renderer loads from a file on this target is therefore a Rnd::PsTex.

The object is 0x4b0 bytes and the subclass occupies +0x58 through +0x4af. Four of the GS register images the class assembles are 64-bit, and RestoreSurfaces() builds them from the mip 0 bitmap: TEX0 receives TBP0, TBW, PSM, TW, TH, TCC, TFX, CBP, and CLD, TEX1 receives MXL, MMAG, MMIN, and the LOD bias K from Rnd::Tex::mMipSelect, and MIPTBP1 and MIPTBP2 receive the base page and the buffer width of levels 1 through 6. BindToGsSlot() programs all four through GfxDevice::SetGsReg().

Small levels of an eight-bit texture share a GS page. RestoreSurfaces() records in mFirstPackedMip the first level whose larger side is 32 pixels or less, and UploadMipAndBuildMipTbp() places every level from there on inside the page of the level before it at the offsets in g_anPackedMipPageOffsets. Levels below that point each have a page.

Two routines have their original names from their own diagnostics rather than from inference. RestoreSurfaces() takes its name from the report "ERROR - RestoreSurfaces(%s), mipmap %d has no bm!" at 0x00831690. The palette comparison RestoreSurfaces() inlines takes its name from the four "CheckPalEqual(%s)" reports from 0x008315a0 onwards, and its out-of-line copy is at 0x0059a908.

Every data member is private. BindToGsSlot() is public because Rnd::PsMat calls it through a Rnd::Tex pointer it has downcast.

Constructor & Destructor Documentation

◆ PsTex()

Rnd::PsTex::PsTex ( const HxStr & name)

Construct a texture with no GS residency.

Only the residency vector, the CLUT staging palette, and mPaletteVram are initialised. The four GS register images and mLockedMip start indeterminate, and RestoreSurfaces() fills them once mip 0 has arrived.

Parameters
nameThe object name, passed to the Rnd::Object constructor.
Ghidra address:
NTSC-U/C: 0x00596f80
Ghidra address:
PAL: 0x005da388

◆ ~PsTex()

virtual Rnd::PsTex::~PsTex ( )
virtual

Release the GS residency and the texture.

Vtable slot 1. The Rnd::Tex destructor body is inlined into this one in the shipped build.

Ghidra address:
NTSC-U/C: 0x0059a558
Ghidra address:
PAL: 0x005dd9c8

Member Function Documentation

◆ LockMipBitmap()

virtual ACanvas * Rnd::PsTex::LockMipBitmap ( int nMip,
int nReserved,
int nFlags )
virtual

Give the caller the canvas over a mip level to draw into.

Vtable slot 9. Waits for the outstanding mip reads, then yields null unless the level is in range and loaded. Bit 1 of nFlags reads the current GS contents back over the loaded bitmap first, making the lock read-modify-write. The level is recorded for UnlockMipBitmap().

Parameters
nMipThe mip level.
nReservedThe second parameter. This override does not read it.
nFlagsBit 1 requests the read-back.
Returns
The canvas to draw into, or null.
Ghidra address:
NTSC-U/C: 0x0059aa48
Ghidra address:
PAL: 0x005ddec8

Reimplemented from Rnd::Tex.

◆ UnlockMipBitmap()

virtual void Rnd::PsTex::UnlockMipBitmap ( )
virtual

Take back the canvas LockMipBitmap() handed out.

Vtable slot 10, empty in Rnd::Tex. Marks the recorded level dirty. The next bind uploads that level again.

Ghidra address:
NTSC-U/C: 0x0059ab30
Ghidra address:
PAL: 0x005ddfb0

Reimplemented from Rnd::Tex.

◆ SetPalette()

virtual void Rnd::PsTex::SetPalette ( APalette * pPalette,
int nReserved )
virtual

Replace the palette of the texture.

Vtable slot 11, empty in Rnd::Tex. Copies the incoming entries over the mip 0 palette, rebuilds the CLUT staging palette, and sets the dirty-CLUT bit. A null palette rebuilds the staging palette from the entries already present.

Parameters
pPaletteThe replacement palette, or null to rebuild from the current entries.
nReservedNot read.
Ghidra address:
NTSC-U/C: 0x0059ab78
Ghidra address:
PAL: 0x005ddff8

Reimplemented from Rnd::Tex.

◆ SetGsPageInUse()

virtual void Rnd::PsTex::SetGsPageInUse ( bool bInUse)
virtual

Pin the video memory block of mip 0 against eviction, or release the pin.

Vtable slot 12, empty in Rnd::Tex. Waits for the outstanding mip reads first. The name is inferred.

Parameters
bInUseTrue to pin the block, false to release it.
Ghidra address:
NTSC-U/C: 0x0059a818
Ghidra address:
PAL: 0x005ddc98

Reimplemented from Rnd::Tex.

◆ FreeLoadedBitmaps()

virtual void Rnd::PsTex::FreeLoadedBitmaps ( )
virtual

Release every loaded bitmap and every GS surface.

Vtable slot 13.

Ghidra address:
NTSC-U/C: 0x0059a7e8
Ghidra address:
PAL: 0x005ddc68

Reimplemented from Rnd::Tex.

◆ RestoreSurfaces()

virtual void Rnd::PsTex::RestoreSurfaces ( )
virtual

Rebuild the GS state of the whole texture from the loaded bitmaps.

Vtable slot 14. Falls back to the Rnd::Tex body while mip 0 has not arrived. Otherwise it rebuilds the CLUT and allocates its slot for a paletted texture, sizes the residency vector to one entry per level, records mGsPsm and mBitsPerPixel from the bitmap format, finds mFirstPackedMip for an eight-bit format, assembles TEX0 and TEX1, and then for every level validates the dimensions against a power of two of at least 8, validates the format and the palette against level 0, records the level's buffer width in MIPTBP1 or MIPTBP2, marks the level dirty, builds its canvas, and allocates its GS block. A level that fails validation is blanked but still made resident. The Rnd::Tex body runs last.

Ghidra address:
NTSC-U/C: 0x00597210
Ghidra address:
PAL: 0x005da618

Reimplemented from Rnd::Tex.

◆ BindToGsSlot()

bool Rnd::PsTex::BindToGsSlot ( unsigned nTexFunc)

Make the texture current on the GS, with the given texture function.

Waits for the outstanding mip reads, then reports false when no mip 0 bitmap or no residency entry exists. Otherwise it uploads the pending levels, merges the texture function into TEX0, refreshes the CLUT base page when a palette slot exists, and refreshes TBP0. A CLUT or a mip 0 block found evicted is uploaded again. TEX0_1 and TEX1_1 are then programmed, every further level is made resident, and MIPTBP1_1 follows when the texture has more than one level and MIPTBP2_1 when it has more than four.

The method is not virtual. Rnd::PsMat calls it through a downcast Rnd::Tex pointer.

Parameters
nTexFuncThe Rnd::Tex::TexFunc, of which the low two bits go into TEX0.
Returns
True once the texture is resident and bound.
Ghidra address:
NTSC-U/C: 0x00598000
Ghidra address:
PAL: 0x005db408

◆ BindAsRenderTarget()

void Rnd::PsTex::BindAsRenderTarget ( )

Make mip 0 the surface the GS draws into.

Waits for the outstanding mip reads. A mip 0 block that is not a render target is released and replaced by a new render target record of the bitmap's shape, and a block that is not resident is allocated without a transfer. FRAME_1 then addresses the block with the buffer width and storage mode of TEX0, XYOFFSET_1 centres the surface in the GS coordinate space, ZBUF_1 masks depth writes, and TEST_1 passes every depth test.

Rnd::PsCam::DrawShowing() is the one caller. The routine was previously labelled after surface restoration.

Ghidra address:
NTSC-U/C: 0x00596d68
Ghidra address:
PAL: 0x005da170

◆ UploadBitmapMipToGs()

int Rnd::PsTex::UploadBitmapMipToGs ( int nMip)

Upload one mip level into the video memory block of its level.

A level of the run-length format is decompressed into the temporary zone buffer and uploaded as PSMT8 at 8 bits per pixel. Every other level is uploaded from its pixels using mGsPsm and mBitsPerPixel.

Parameters
nMipThe mip level.
Returns
The first block of the level in video memory.
Ghidra address:
NTSC-U/C: 0x00597d50
Ghidra address:
PAL: 0x005db158

◆ UploadMipAndBuildMipTbp()

int Rnd::PsTex::UploadMipAndBuildMipTbp ( int nMip,
bool bSkipIfResident )

Resolve one mip level's GS block address, uploading the level when needed.

A level at or beyond mFirstPackedMip takes its address from the block of the level before that point plus the packed offset for its distance past it, and uploads nothing. Any other level is uploaded unless bSkipIfResident is set and its block is still resident. Uploading the level just below mFirstPackedMip also uploads every packed level into its block. The address then goes into TEX0, MIPTBP1, or MIPTBP2 for levels 0 through 6.

Parameters
nMipThe mip level.
bSkipIfResidentTrue to upload only a level whose block was evicted.
Returns
The first block of the level, or zero when the texture has no residency.
Ghidra address:
NTSC-U/C: 0x005982a0
Ghidra address:
PAL: 0x005db6a8

◆ UploadPendingMips()

void Rnd::PsTex::UploadPendingMips ( )

Upload every level whose dirty bit is set, then clear the mask.

Returns at once while mDirtyMips is clear or mip 0 is missing. A dirty CLUT is uploaded again and its block merged into TEX0, and a dirty CLUT with no palette slot reports "Dirty Palette bit, but no pPaletteVram.. rgba %p" instead. A clean CLUT has its block refreshed and is uploaded again only when found evicted.

Ghidra address:
NTSC-U/C: 0x00597e38
Ghidra address:
PAL: 0x005db240

◆ Init()

void Rnd::PsTex::Init ( )
static

Install this class as the texture the renderer builds and program the default filtering.

Writes NewPsTex() into Rnd::Tex::sNew, then programs the MXL, MMAG, and MMIN fields of GS TEX1_1. GfxDevice::Init() is the one caller.

Ghidra address:
NTSC-U/C: 0x0059a888
Ghidra address:
PAL: 0x005ddd08

◆ OnMipLoaded()

virtual void Rnd::PsTex::OnMipLoaded ( int nMip)
protectedvirtual

Take delivery of one mip level whose read has just finished.

Vtable slot 15. Runs the Rnd::Tex body, then halves the alpha of the level, converting 0 to 255 source alpha into the GS range of 0 to 128. A paletted level is converted in its palette and a 32-bit level texel by texel. A level of any other unpaletted format is not converted.

Parameters
nMipThe mip level that arrived.
Ghidra address:
NTSC-U/C: 0x00596fd8
Ghidra address:
PAL: 0x005da3e0

Reimplemented from Rnd::Tex.


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