Skip to content

[rlsw] First batch of embedded optimizations and compiler requirements Pico 2#5994

Merged
raysan5 merged 10 commits into
raysan5:masterfrom
NighthowlerStudios:embedded-optimizations-pico
Jul 21, 2026
Merged

[rlsw] First batch of embedded optimizations and compiler requirements Pico 2#5994
raysan5 merged 10 commits into
raysan5:masterfrom
NighthowlerStudios:embedded-optimizations-pico

Conversation

@NighthowlerStudios

@NighthowlerStudios NighthowlerStudios commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Backbuffer for RLSW

This implements the backbuffer approach being talked about in #5993

The "secret option" RLSW_BACKBUFFER has been thoroughly tested and confirmed working, as well as confirmed a serious performance boost, similar findings to the ESP32's approach, though this one has less to it, and a bit more manual control needed by the embedded developer to take hold of the buffer and transmit it themselves at the right time.

For example, the developer is still required to add in their own mutex methodology to prevent their video transmission from overlapping with the new buffer pointer submission.

Use pico_rand.h to get true random seed on startup, fixes compiler error

The Pico 2 does not include a hardware clock that measures real time. Because of this, the Pico SDK only includes an incomplete stub of time.h. When compiling to Pico 2, if left alone, time(NULL) will actually throw unsupported relocation on GCC, as it cannot link everything inside of time() needed.

With the Pico 2 we have an alternate approach available. The RP2350 has a hardware "True Random Unit." This true random unit listens to electrical noise surrounding the chip (with Ring Oscillators) and uses that to seed itself. This would be much unlike getting "time since startup".

So this commit suggests using the hardware True Random Unit to get the first seed. Then we can let Raylib take control of the random maths from there, to inline the behaviour with how Raylib runs on other platforms by keeping Raylib's actual algorithm active.

Note that the first fetch costs about 20,000 cycles as the ring oscillators need time to spin up. But this is in trade-off for getting the seed completely randomized instead of predictable (start up time each reboot would be about the same give or take a few microseconds). It doesn't make sense for us to use the hardware randomizer to replace Raylib's Xoshiro implementation to fetch the actual values, because the hardware TRNG has a limitation where the seventh read will always trigger a recycle of the oscillators to refresh the values, the previously mentioned 20,000 cycle penalty. Way too heavy compared to Xoshiro's average of 10 to 20 cycles.

In short, TRNG once to seed, then existing Xoshiro for fastest random streaming.

@NighthowlerStudios NighthowlerStudios changed the title [rlsw] Embedded optimizations Pico 2 [rlsw] First batch of embedded optimizations and compiler requirements Pico 2 Jul 18, 2026
Comment thread src/external/rlsw.h
Comment thread src/external/rlsw.h Outdated
@Bigfoot71

Bigfoot71 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

As for the changes to rlsw, the addition looks good to me.

@raysan5 Please, if this PR is going to be merged, merge it before my other PR #5996 in case there are any conflicts to resolve.

Especially since I asked a question there about the consistency of the configuration define prefixes, and RLSW_BACKBUFFER is being added here:

@raysan5

raysan5 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

@Bigfoot71 thanks for the review, it looks good to me. I can merge it before the following PR.

@NighthowlerStudios Please, could you rename the flag to SW_DOUBLE_BUFFERING?

@NighthowlerStudios

NighthowlerStudios commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@NighthowlerStudios Please, could you rename the flag to SW_DOUBLE_BUFFERING?

@raysan5 Sure thing. c64ed57

@raysan5
raysan5 merged commit 78535d2 into raysan5:master Jul 21, 2026
16 checks passed
@raysan5

raysan5 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

@NighthowlerStudios thanks for the improvement! Also answered on the issue.

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

Successfully merging this pull request may close these issues.

3 participants