Repository navigation
Conversation
The source texture already holds the pixels for a duplicate frame. Keep uploading when the debug HUD or fade-in modifies those pixels.
Only the debug HUD, fade-in and ambient LEDs need the RGBA frame on the CPU. When none of them is active, upload the core's RGB565 buffer directly. Draw duplicates from the texture because there is no CPU copy.
Uploading to a texture that the current frame still samples makes the PowerVR driver allocate storage on every frame. Upload to the texture that the previous frame did not use.
A duplicate frame ran every user shader pass again on the same source texture. Reuse the output in the FBO textures and run only the final draw to the screen.
…, and hash shader cache keys Keep packed RGB565 frames across duplicate callbacks and context resets, track dual source texture storage per slot with GL allocation error checks, keep SDL presentation safe across source changes, include source FNV-1a hash in shader cache keys, and allow direct RGB565 upload during fast-forward.
…L swap Cache MVPMatrix, VertexCoord, and TexCoord locations at shader link time, keep one persistent FBO per shader pass instead of re-attaching every frame, and drop per-frame glGetError/glIsTexture/glCheckFramebufferStatus queries (checking completeness on attach). Move SDL_RenderClear() out of PLAT_blitRenderer() into the non-GL PLAT_flip() blit path to avoid per-frame SDL GL context switches, and clear FBO 0 inside PLAT_GL_Swap() before the final pass.
… to 15 Hz Allow direct RGB565 texture upload during ambient LED mode by sampling average color directly from RGB565, rate-limit ambient sampling and LED hardware writes to ~15 Hz (66 ms), and serialize LED profile/color updates across the main and battery threads with a cancellation-safe mutex.
Author
This branch has not been deployed
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.
This PR reduces the CPU and sysfs overhead of Ambient LED mode during gameplay so users can keep reactive LEDs enabled without forcing extra pixel conversion or writing to hardware 60 times a second.
Ambient LED mode now keeps direct RGB565 texture uploads (eliminating full-frame CPU RGBA conversion), cuts ambient color sampling and LED hardware writes by 4× (from 60 Hz to ~15 Hz), and fixes a cross-thread race between gameplay LED updates and the background battery monitor.
Changes
workspace/all/common/api.c,api.h,workspace/all/minarch/ma_video.c): BecauseGFX_setAmbientColor()only accepted RGBA buffers, turning on Ambient LEDs forced full-frame CPU RGB565→RGBA conversion (~0.2–0.9 ms/frame) on every frame. TeachingGFX_setAmbientColor()to sample RGB565 directly with its matching pitch lets Ambient mode keep direct RGB565 texture uploads and eliminates that conversion cost.workspace/all/common/api.c,GFX_setAmbientColor,LEDS_setProfile): Ambient mode sampled pixels and pushed hardware LED writes on every video frame (up to 15 sysfs writes per frame on Brick Pro, ~1.2 ms/frame). Rate-limiting sampling and hardware updates to once every 66 ms (~15 Hz)—while applying mode changes immediately and still updating all zones per push so H700 UART commits andEAGAINretries stay intact—cuts LED write overhead 4×.workspace/all/common/api.c,LEDS_lock/LEDS_unlock): Both the main thread (ambient sampling and profile rules) and the background battery monitor thread read and wrote LED profile state and hardware simultaneously, risking interleaved writes or stale profiles. GuardinglightsAmbientwrites,LEDS_setProfile(), andLEDS_updateLeds()with a cancellation-safe mutex serializes LED updates without risking deadlock whenPWR_quit()cancels the battery thread.Results
EAGAINretry behavior.Blast Radius
api.c,api.h) andminarch's singleGFX_setAmbientColor()call site (ma_video.c).tg5040,h700,tg5050, etc.). Non-ambient LED profiles (charging, low battery, sleep, default) still switch immediately with zero throttling.Testing and Verification
minarchcleanly for bothtg5040andh700toolchains with zero warnings.tg5040) on battery.EAGAINretries: A per-LED color-delta cache would skip the last zone (which triggers H700's UART commit) on left-only changes and suppress retries after transientEAGAIN; updating all zones at 15 Hz viaLEDS_updateLeds()avoids both issues and also preserves effect-only changes.pthread_cancelsafety: SerializedlightsAmbientwrites,LEDS_setProfile(), and directLEDS_updateLeds()calls (e.g., fromledcontrol) under a mutex wrapped withPTHREAD_CANCEL_DISABLEsoPWR_quit()'spthread_cancel()cannot deadlock while holding the lock.