Skip to content

fix(fast3d): upload RAW block-load textures by per-line stride, not block size#1136

Open
bassdr wants to merge 1 commit into
Kenix3:port-maintenancefrom
bassdr:pr/raw-blockload-upload-dims
Open

fix(fast3d): upload RAW block-load textures by per-line stride, not block size#1136
bassdr wants to merge 1 commit into
Kenix3:port-maintenancefrom
bassdr:pr/raw-blockload-upload-dims

Conversation

@bassdr

@bassdr bassdr commented Jun 24, 2026

Copy link
Copy Markdown
corrupted_buttons

Summary

Alt-asset / HD texture-pack textures that are loaded via LoadBlock (button prompts, C-button symbols, etc.) render as garbage stripes or a solid block. Vanilla is unaffected; it only appears with a replacement pack enabled.

Root cause

Regression from #1118. It rewrote ImportTextureRaw's fallback upload to describe the buffer with loaded_texture.line_size_bytes:

uint32_t uploadWidth  = safeLineSizeBytes / 4;
uint32_t uploadHeight = safeLineSizeBytes > 0 ? safeLoadedBytes / safeLineSizeBytes : 0;

For a block-loaded texture, line_size_bytes spans the entire image (a LoadBlock is one contiguous "line"), so this collapses the upload to an N x 1 strip. Instrumented, a 768x256 RGBA32 button replacement (gCBtnSymbolsTex):

fast=false   (block load reports origH = 736/48 = 15 rows -> newH 240 != resH 256)
FALLBACK  upW=188416  upH=1          <- uploaded as 188416 x 1
          altWidth(resultNewLineSize/4)=768   <- correct per-row stride

The fast path is skipped because the block load reports a non-integer original height (736 bytes / 48-byte line = 15.33 -> 15), so resultNewHeight (240) != resource height (256). Before #1118 the fallback used resultNewLineSize / 4 = 768 (correct width).

Fix

Describe the buffer by the per-line HD stride resultNewLineSize (tile line_size x h_byte_scale) -- the true per-row stride for both block and tile loads -- and derive height from the loaded bytes. The OOB clamp added by #1118 is preserved.

uint32_t uploadWidth  = resultNewLineSize / 4;                                          // 768
uint32_t uploadHeight = resultNewLineSize > 0 ? safeLoadedBytes / resultNewLineSize : 0; // 245

Scope and testing

Fixes any alt-asset/HD replacement loaded via LoadBlock. Tested with an Xbox/N64 button texture pack: the in-game equip prompt and C-button symbols now render correctly. Fast-path textures (the vast majority of HD textures) are untouched since they never reach this fallback.

Same root PR (#1118) as #1135.

…lock size

Kenix3#1118 changed ImportTextureRaw's fallback to describe the upload buffer using
loaded_texture.line_size_bytes. For a block-loaded texture that value spans the
whole image (a LoadBlock is a single contiguous "line"), so width =
line_size_bytes/4 became the entire image and height collapsed to 1 -- e.g. a
768x256 HD button replacement uploaded as 188416x1, corrupting any alt-asset/HD
texture loaded via LoadBlock (button prompts, C-button symbols).

resultNewLineSize (tile line_size * h_byte_scale) is the true per-row stride for
both block and tile loads. Use it for the upload dimensions; the OOB clamp added
by Kenix3#1118 is preserved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bassdr added a commit to bassdr/Shipwright that referenced this pull request Jun 24, 2026
Bumps libultraship to bassdr/main-bassdr including the ImportTextureRaw
fix (Kenix3/libultraship#1136) for alt-asset/HD textures loaded via
LoadBlock rendering as garbage (button prompts, C-button symbols).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bassdr added a commit to bassdr/Shipwright that referenced this pull request Jun 27, 2026
Bumps libultraship to bassdr/main-bassdr including the ImportTextureRaw
fix (Kenix3/libultraship#1136) for alt-asset/HD textures loaded via
LoadBlock rendering as garbage (button prompts, C-button symbols).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant