Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fox_std_lib.c : gSPInvalidateTexCache invalidates entire texture cache #94

Open
shizukachan opened this issue Dec 29, 2024 · 0 comments

Comments

@shizukachan
Copy link

Note, marked as

// TODO

in the code

This is worth a significant amount of (CPU) perf whenever we have a Lib_Texture_Scroll or Lib_Texture_Mottle call, because libultraship has to regenerate the texture cache after it is invalidated.

For Lib_Texture_Scroll, I believe invalidating the texture argument is probably correct. Easiest to check at the beginning of the Corneria level, look for the clouds in the Arwing cockpit canopy (clouds should scroll by on the canopy).

For Lib_Texture_Mottle this is not clear, invalidating the dst argument is normally correct, but sometimes this is not a texture uploaded to the RDP, eg. in fox_hud.c : HUD_Texture_Warp. This causes the invalidate to fail with resource not loaded; if that error is ignored, the invalidate fails and causes the texture not to be invalidated, generating graphical errors because the texture is updated on the CPU (Starship) side but not on the GPU (RDP/libultraship) side.

It also turns out that the 64x64 Venom cloud texture is actually uploaded to the RDP as two 64x32 textures, and adding an implied invalidation to Lib_Texture_Mottle only invalidates one of those, despite operating on a 64x64 texture. It is not simple to find all cases where:

  1. a texture is mottled, and
  2. the same texture is split and uploaded separately to the RDP

...so I have added an explicit texture cache invalidate for the second (half of the) texture as a workaround. But perhaps a more elegant solution has the code track texture sizes, and implicitly do all necessary invalidations based on the texture size regardless of how it's uploaded to the RDP. This depends on how closely Starship wants to stay to the decompilation.

I have no PR currently, because I don't have a good way to verify that I'm not breaking anything:

  • In the code, Lib_Texture_Mottle is used for Corneria, Aquas, Zoness* (water texture), Solar, System Map* (Venom). For the ones without *, I haven't figured out how the mottle is being used visually, eg. I can't see a difference.
  • Lib_Texture_Scroll is everywhere, eg. in Corneria* ("good luck!" and canopy clouds texture in intro).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant