GxmShaderCache class
On-disk cache of the GXP binaries SceShaccCg produced for the PS Vita's Cg stage sources.
sceGxm consumes compiled GXP binaries and the SDK ships no offline compiler for them, so every stage of every program is compiled on the console at startup by the firmware's own Cg compiler (see GxmShaderProgram::sceShaccCgCompileProgram() hands over is exactly what sceGxmShaderPatcherRegisterProgram() takes later, so keeping it means the compiler never has to run for that stage again - and, when nothing is missing, never has to be loaded either (libshacccg.suprx is only brought up on the first miss, see GxmDevice::
How an entry is invalidated. Every entry is keyed by a 64-bit hash of the exact Cg source string it was compiled from. Those sources are generated artifacts (Shaders/Generated/CgGeneratedShaders.h), so editing a ".shader" file and regenerating changes the hash of every stage it produced and leaves the rest of the cache alone: the changed stages miss and are recompiled, everything else is still a hit. There is no version number for anyone to remember to bump - a stale entry cannot be found, only orphaned, and an orphan is dropped the next time the pack is written because the pack is rewritten from what this run actually used. The file header adds the two invalidations a per-entry source hash cannot express: FileVersion, for a change in this format or in how the engine consumes a GXP, and a fingerprint of the libshacccg.suprx the entries were produced by, so a different compiler build does not have its output handed to a different driver. Either mismatch rejects the whole pack, as does a truncated or corrupt one - in every case the console recompiles and writes a fresh pack rather than failing, so a cache is never something the game needs to have.
Two packs. A read-only one shipped in the VPK next to the content (PrebakedPath) is loaded first, then the writable one under the cache path is loaded over it. Writes only ever go to the writable one. That is what makes "precompiled offline" work without an offline compiler: run once on a console, pull the written pack back, and ship it - and because entries are keyed by source hash, a shipped pack that was forgotten at the last shader change is not wrong, only incomplete.
Public static variables
-
static std::
uint8_t Signature constexpr - Signature every pack file starts with.
-
static std::
uint16_t FileVersion constexpr - Format revision; bump when the layout below changes or a GXP is consumed differently.
- static const char* FileName constexpr
- Name both packs carry.
- static const char* PrebakedPath constexpr
- Where a pack shipped inside the VPK is looked for, read-only.
Public static functions
-
static void Initialize(StringView writablePath,
std::
uint32_t compilerFingerprint) - Loads the prebaked pack and then the writable one over it.
- static void Shutdown()
- Writes the pack back if this run changed it, then releases everything.
- static auto IsAvailable() -> bool
- Whether a cache directory was configured (the lookups below are no-ops when it was not).
-
static auto GetEntryCount() -> std::
uint32_t - Number of entries currently held, from either pack plus whatever this run compiled.
-
static auto Lookup(const char* source,
bool vertexStage,
std::
uint32_t& sizeInBytes) -> SceGxmProgram* - Returns the cached GXP for
source, ornullptrwhen there is none. -
static void Store(const char* source,
bool vertexStage,
const void* binary,
std::
uint32_t sizeInBytes) - Records the GXP a compile produced for
source, replacing any entry already under its key. - static void Flush()
- Writes the pack back if this run changed it (also done by Shutdown()).
Constructors, destructors, conversion operators
- GxmShaderCache() deleted
- ~GxmShaderCache() deleted
Function documentation
static void nCine:: RHI:: GXM:: GxmShaderCache:: Initialize(StringView writablePath,
std:: uint32_t compilerFingerprint)
Loads the prebaked pack and then the writable one over it.
| Parameters | |
|---|---|
| writablePath | Directory the pack is written back to (empty disables the cache entirely) |
| compilerFingerprint | Identifies the on-console Cg compiler the entries were produced by |
Neither pack has to exist. A pack whose header does not match is reported and ignored.
static SceGxmProgram* nCine:: RHI:: GXM:: GxmShaderCache:: Lookup(const char* source,
bool vertexStage,
std:: uint32_t& sizeInBytes)
Returns the cached GXP for source, or nullptr when there is none.
The returned block is allocated with std::malloc() and owned by the caller, which is the contract GxmShaderProgram::
Variable documentation
static const char* nCine:: RHI:: GXM:: GxmShaderCache:: PrebakedPath constexpr
Where a pack shipped inside the VPK is looked for, read-only.
The application's own directory is mounted at "app0:" and the content travels inside the VPK, so this is the content path on this platform. It is spelled here rather than plumbed down from the application because only this backend has a shipped shader cache at all - the path is as much a property of the console as "ur0:/data/" is.