fix(gum): create the VFPU context in whichever gum function runs first - #207
Merged
sajattack merged 1 commit intoSep 2, 2026
Merged
Conversation
sajattack
force-pushed
the
fix-gum-cold-vfpu-context
branch
from
August 30, 2026 23:43
06745f3 to
f1c949a
Compare
Collaborator
|
@ItsNoHax plz resolve conflicts. |
Only `sceGumLoadIdentity` and `sceGumLoadMatrix` created `VFPU_CONTEXT`. Every
other gum function went through `get_context_unchecked`, which resolved a `None`
context with `core::intrinsics::unreachable`. Opening with any of them -- most
naturally `sceGumMatrixMode`, which is the first call in most setup code -- is
therefore undefined behaviour, and in practice traps:
E CPU: CPU exception: break instruction hit at 0881ba7c
psp::sys::gum::get_context_unchecked
sceGumMatrixMode
Replace the helper with `get_context`, which creates the context on demand, and
use it everywhere including the two functions that previously did this inline.
The context is a zeroed matrix set with no saved registers, so creating it from
any entry point is the same work `sceGumLoadIdentity` was already doing.
Adds a case to the gum tests that opens with `sceGumMatrixMode` and reads the
resulting matrix back. Only the first gum call in a process is cold, so it runs
before the rest of the module. `reset` loses the `sceGumLoadIdentity` it carried
purely to warm the context up, along with the comment pointing at this issue.
Against master the run stops at the first `reset` with no final token; with this
change the suite ends FINAL_SUCCESS.
Fixes overdrivenpotato#189.
ItsNoHax
force-pushed
the
fix-gum-cold-vfpu-context
branch
from
September 2, 2026 16:10
f1c949a to
fc6ace5
Compare
Contributor
Author
|
done @sajattack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #189. Rebased onto master after #206; the overlap in
ci/testsis resolved below.The bug
VFPU_CONTEXTis created bysceGumLoadIdentityandsceGumLoadMatrixonly. Every other gumfunction reaches it through
get_context_unchecked, which resolves aNonecontext withcore::intrinsics::unreachable. Opening with any of them is undefined behaviour, and on adebug build it traps:
That is the report's
sceGumMatrixModefailure exactly. It is easy to hit becausesceGumMatrixModeis what most setup code calls first — as in the issue's tutorial, which selectsa matrix mode before loading anything into it.
The fix
get_context_uncheckedbecomesget_context, which creates the context on demand, and the twofunctions that were doing that inline now go through it too. Creating a
Contextis a zeroedmatrix set with an empty
savedmask, so doing it from any entry point is the same worksceGumLoadIdentityalready did — the choice of which function got to do it was arbitrary.Tests
One case added to the gum tests from #206: open with
sceGumMatrixModeon a cold context, thenbuild a translation and read it back with
sceGumStoreMatrixto show the context it created isusable. No rendering, so it needs no GU.
Only the first gum call in a process is cold, so there is one case to be had and it runs before the
rest of the module. That also lets
resetdrop the leadingsceGumLoadIdentityit was carryingpurely to warm the context up — and the comment on it, which pointed at this issue and is now
false. With
resetopening on a mode switch, the cold path is exercised by the suite's ordinaryfirst call rather than by a special case.
Before (master, 13d5bf3) the run stops at the first
resetand never reaches a final token, so CIfails on the missing
FINAL_SUCCESS:After — all 51 cases pass, including #206's four, which confirms the simplified
resetstill setsthe matrix up the way they expect:
Run locally with the same invocation as
.github/workflows/pipeline.yml.cargo fmtis clean forboth
pspandci/tests.