⚡ Optimize license plate texture copying#237
Open
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
Open
⚡ Optimize license plate texture copying#237CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
CanerKaraca23 wants to merge 1 commit intouser-grinch:mainfrom
Conversation
Reversed the nested loops when rendering license plate texts to ensure that destination writes are contiguous. This optimization significantly reduces memory access overhead by enabling cache lines and write combining, resulting in a ~50% speedup compared to row-by-row character jumping, while continuing to respect C++ strict aliasing and alignment rules.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the license plate text blit routine to improve write locality when copying glyph pixels from the charset raster into the destination plate raster.
Changes:
- Precomputes per-character source pointers into the charset raster.
- Reorders the copy loops to iterate outer-by-row and inner-by-character, making destination writes contiguous across each row.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
251
to
+255
| const auto charsRasterStride = RwRasterGetStride(charsRaster); | ||
| if (!charsRasterStride) | ||
| return false; | ||
|
|
||
| // Copy each character from charset raster to plate raster | ||
| // Going from left to right | ||
| // Size of a pixel (texel) in `pCharsetLockedData`. It's in 32 bit BGRA format |
Comment on lines
+259
to
261
| RwUInt8* charRasterBases[MAX_TEXT_LENGTH]; | ||
| for (auto letter = 0; letter < MAX_TEXT_LENGTH; letter++) | ||
| { |
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 optimizes the way license plate character data is transferred from the charset texture to the destination license plate texture.
Previously, the routine copied characters entirely (row-by-row within the character) before moving on to the next character in the string. Because the license plate destination pixels for different characters are adjacent horizontally but spaced vertically in the destination raster, this approach caused many scattered writes jumping across raster pitches.
By reversing the loops (outer: row iteration, inner: character iteration), the destination writes are now strictly contiguous and horizontal across the raster width for each row. This significantly improves L1/L2 cache locality and write-combining during memory transfer. Strict aliasing and memory alignment behaviors correctly rely on modern compiler behavior regarding
memcpy.