Compute texture layout sizes in 64 bits, so a garbled descriptor cannot wrap to a small size.

nvn_tex.c multiplied a level's width by its samples and its blocks by their bytes in 32 bits, and
nvn_tex_linear_stride did the same: a descriptor with a width past 2^30 (garbled, or not set up yet) wrapped to a small
size, and the texture got a small allocation for a large image. Block counts, row bytes and GOB counts are now 64-bit
(mip, blk, pick_tile and adj_tile take 64-bit sizes), and the linear stride saturates at 2^32 - 1 instead of wrapping.
Real textures lay out as before.

Checked: --probe-nvn-tex gains two cases (an RGBA8 texture 2^30 + 64 texels wide, and its linear stride). Before, the
first failed: 2,048 bytes against 2^35 + 2,048. After, all 135 cases pass, the 40 layout goldens of the original SDK
among them; --probe-nvn shows the same four failures as the baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 17:29:46 -05:00
parent c60abba2e5
commit 79b36044b0
3 changed files with 33 additions and 18 deletions

View File

@@ -14,9 +14,11 @@ void nvn_tex_level_tiles(const nvn_texdesc *d, unsigned level, unsigned *tileH,
/* LINEAR_RENDER_TARGET (0x40) uses pitch storage even without LINEAR (0x10).
NX2NAVI's CPU-loaded water height/mask textures use that flag alone. */
static inline int nvn_tex_is_linear(const nvn_texdesc *d) { return (d->flags & 0x50) != 0; }
// computed in 64 bits; a stride past 32 bits (a garbled descriptor) saturates instead of wrapping to a small one
static inline uint32_t nvn_tex_linear_stride(const nvn_texdesc *d) {
if (d->stride) return d->stride;
int bw, bh; int bpb = nvn_fmt_bpb(d->format, &bw, &bh);
uint32_t align = (d->flags & 0x40) ? 128 : 32;
return (((d->width + bw - 1) / bw) * bpb + align - 1) & ~(align - 1);
uint64_t align = (d->flags & 0x40) ? 128 : 32;
uint64_t s = ((((uint64_t)d->width + bw - 1) / bw) * bpb + align - 1) & ~(align - 1);
return s > UINT32_MAX ? UINT32_MAX : (uint32_t)s;
}