startup: answer 4 KiB allocation-info requests for small 2D textures #2125
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2133"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T01:21:33Z.
Change
A console executable asks the device's allocation-info entries (slots 25 and 108) with
Alignment0x1000 for a texture that is not a render or depth target and whose top level, padded to 4 KiB blocks,
holds at most 0x80007 bits. It keeps the answer only when the returned alignment is 0x1000.
sanitized()dropped that request, so the stand-in forwarded the desktop answer: 64 KiB at 64 KiB alignment.
With that answer the executable records 16 pages for a texture the console sizes at one. Its streaming
read for that texture then runs 64 KiB through the following resources' compressed chunks and ends
inside one of them. The executable's own check rejects that read before submitting it, and the storage
stand-in refuses the request. This change corrects the size answer, so storage receives whole-chunk
requests and publishes the range it actually wrote (#1914).
What changes:
4 KiB thin-block size as AMD addrlib computes it (
src/startup_stubs/small_texture_4k.h). Each levelis padded to whole blocks until the first level no wider than half a block and no taller than a block;
that level and every smaller one share one block.
Alignment0x1000, one sample, one array slice,power-of-two sides up to 16384,
MipLevels0 up to the full chain, and no render-target or depth flag.The format must be single-plane at 4/8/16/32/64/128 bits a texel. The texture must be within the
executable's bound, and the desktop answer must not be a failure. Anything else, alignment 0 included,
keeps the desktop answer.
answer (32x32 R8G8B8A8: 0x1f80 bytes). For such a description, XG slot 2 (layout records), XG slot 8
(copy) and texture upload all use one compact linear plan: rows at their exact byte width (texels or
4x4 blocks), levels back to back. The plan ends inside the answer for every accepted shape.
last one, fails without writing or announcing a write.
the console's 4 KiB tiled order are therefore still not displayed correctly, as on
main. Thedifference is that the upload now reads strictly inside the allocation;
mainread the 256-byte-pitchfootprint, which ran past it.
any answer.
Overlap with #1469: its
Gfx10Textureuses the same tail rule, and itsgfx10_swizzle_from_descpicksSW_64KB_Sfor layout UNKNOWN. For descriptions this change answers atAlignment0x1000, that sideshould choose
SW_4KB_S. Its 4 KiB tiling plan can then replace the compact plan: the plan is used inexactly three places (slot 2, slot 8, upload). This PR does not depend on #1469.
Refs #1914. AI-assisted (Claude Code).
Verification
Release build at
d340e464, Windows 11 build 26300, debug layer off. Adapters:addrlib from
python tools/fetch_addrlib.py(Mesa 25.1.0, 5c142e46).Result: 20 of 20 passed, 0 failed, 0 skipped. Every device test ran on both WARP and the hardware
adapter.
The other draw tests that use the edited stream consumer
(
^startup_(packed_target_draw|stream_|mrt_|logical_view|slot57_blend_draw|placed_vertex|address_srv|address_buffer_srv))also pass: 26 of 27, with 1 capability skip.
startup_logical_view_warpskips because the adapteraccepts the descriptor count directly.
The tests:
startup_small_texture_4k, device-free:startup_small_texture_4k_whole_width_tail_controlexpects a tail one block wide and must fail.startup_small_texture_4k_addrlib: 4,943 shapes against addrlibADDR_SW_4KB_S, 0 mismatches. Itskips (77) without addrlib.
startup_small_texture_4k_device_warpand_hardware: slots 25 and 108 give the 4 KiB answer for 3descriptions and the desktop answer for 3 controls.
startup_small_texture_4k_xguses a 32x32 R8G8B8A8 texture with 2 mips at 0x1000:rows in both halves and per-mip sentinels;
startup_small_texture_4k_xg_no_limit_control: at an explicit 64 KiB alignment the desktop footprintdoes not fit before the guard page, so the run must fail.
startup_small_texture_4k_draw_warpand_hardware: the same texture is written through slot 8 infront of a guard page, placed (slot 133), sampled at both mips by a translated draw, and all 1,536
read-back pixels are compared.
startup_xg_*tests pass unchanged.Mutants, each run against the tests above: 8 of 8 killed. "Slot 8 rows at the caller's pitch" survived at
first, because every copy used a tight pitch. The XG check now copies mip 0 from a source with padded
160-byte rows, which kills it.
Evidence and follow-up
Byte correctness rests on the fixtures above, which are synthetic. The addrlib oracle is optional,
MIT-licensed and not vendored.
Author evidence, separate from byte correctness, from one console executable under the startup debugger:
executable's own check firing once. With this answer both counts were 0 to the same screen.
(272 shape groups) are spaced exactly at the answered size. These are counts only.
takes 0x4000.
Follow-up:
Checklist
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:28:06Z.
Review: CHANGES_REQUESTED
The 4 KiB size calculation is useful and the arithmetic fixture passes locally. I also reproduced the acceptance gap with the real XG shim: a 32x32 RGBA8 texture is advertised as 4 KiB, its mip footprint extends past that allocation, and slot 8 returns S_OK after writing only 16 of 32 rows. The translated upload then fills missing rows with zeros. Please keep the public layout, full copy and upload consistent for every shape that gets the new allocation answer. Use one shared compact or tiled plan across the relevant calls, or restrict the production answer to a proven complete subset and report unsupported copies without writing or announcing a new generation. A separate arithmetic-only PR can move first. Verify distinct rows in both halves, two mips with different sentinels, a guard at the returned allocation end, and actual rendered/read-back pixels. Coordinate the shared tiling code with #1469. Keep the observed application count improvement as author evidence, separate from the byte-correctness requirement.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:41:53Z.
Review: COMMENTED
Review of head
75287587ae0e0bc0f9075fd7f2fb2bd98a28ad9f(comment only, no approval).Summary: The size rule matches the GFX10 4 KiB thin-block layout. I checked the block table by hand: 128x64 at 4 bits, 64x64 at 8, 64x32 at 16, 32x32 at 32, 32x16 at 64 and 16x16 at 128 all give 4096 bytes. Scope checks, the failure passthrough (
~0ull), slots 25 and 108, the XG layout and the upload and copy limits read correctly. CI is green on the Windows build and the Linux Python checks. The/O2job and the chart job were skipped. Mergeable state wasUNKNOWNwhen I looked. No P1 found. Two P2 items and one nit are below.Commands executed locally (PR worktree,
origin/main...HEAD):git diff --stat origin/main...HEAD: 9 files, +714/-17.python3 tests/docs_links_check.py: pass (18 files, 391 links).python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: FAILS, see P2-1.tests/startup_small_texture_4k_check.cppwithx86_64-w64-mingw32-g++ -std=c++17 -Isrcand ran it under wine. The file as committed does not compile, see P2-1. With only the CR bytes removed, the run printsPASS (14 sizes, 19 refused descriptions, 256 format values, extent and span limits).P2-1:
tests/startup_small_texture_4k_check.cpphas CRLF line endings, plus a raw CR inside a string literal.tests/startup_tile64_plan_check.cppare LF.git diff --checkreports trailing whitespace on every line.std::printf("FAIL 2x2 BC1: a desktop failure was replaced<CR>\n");. The raw CR sits inside the string.missing terminating " character.\non that line normally.P2-2: the 8-level tail limit is not covered by the device-free literal run.
small_texture_4k_bytes, changemips - m <= 8tomips - m <= 7.rc=0).--addrlibrun, which skips with 77 when addrlib is absent, would compare these shapes. Please add one literal case whose tail level is chosen by the 8-level limit rather than by the half-block width, for example a case with more than 8 mips remaining where the width and height test is already true.Mutations run (each reverted with
git checkout -- .):h <= b.heightchanged toh <= b.height * 2: killed (FAIL 64x128 BC1 5 mips).mips - m <= 8changed to<= 7: survived (P2-2).offset >= extentchanged tooffset > extentinsmall_texture_4k_within: survived. This one is an equivalent mutant, because the clamp returns 0 either way.0x80007changed to0x80008: survived. Also equivalent, because padded bit counts are multiples of 4096.Nit: the doc and header say that XG mip records still describe the desktop footprint beyond the answer. That limit is documented in the code comment and handled by clamping in slot 8.
Windows proof: I did not run
python3 $P win2025. The Windows CI build and test job passed on this head (I did not inspect which tests it ran). A Win2025 run on the final head after the P2 fixes is still worth doing before this goes to Ready.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T02:58:26Z.
Thanks, agreed. Fixed in
d340e464with the first option: one plan for every call.For every shape that gets the 4 KiB answer, XG slot 2, XG slot 8 and texture upload now use one compact
linear plan. Rows have their exact byte width, and levels follow each other.
each one.
without writing or announcing a write.
New checks:
per mip, written into exactly the returned size before a guard page and compared byte for byte;
and on hardware.
The plan's texels are linear, not the 4 KiB swizzle, so bytes streamed in the console's tiled order are still not displayed correctly, as on
main; the upload now reads strictly inside the allocation. It is used in exactly those three places, so#1469's 4 KiB tiling plan can replace it there. That side would also need to pick
SW_4KB_Sfor thesedescriptions. The application counts are now listed as author evidence, separately from the byte
checks.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T02:58:27Z.
Thanks, both fixed in
d340e464.git diff --checkagainst the merge base is clean.along its longer side, so at most 7 levels can be in it. That makes
mips - m <= 7equivalent to theoriginal on every shape.
levels.
<= 6.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:03:05Z.
Review: COMMENTED
Review of head
d340e4645b1d8e62df08910560aa878b6b99fe2c(comment only, no approval).Summary: This head is reworked since the earlier review (13 files, +1085/-10). The 4 KiB size rule and the new compact linear plan for XG slots 2 and 8 read correctly. The earlier CRLF problem is gone. No P1 and no P2 found. CI is green on the Windows build and test job, the gfx1013 job and the Linux Python checks. The
/O2and chart jobs were skipped. The PR is mergeable and the title is neutral.Commands executed locally (PR worktree,
origin/main...HEAD):git diff --stat origin/main...HEAD: 13 files, +1085/-10.python3 tests/docs_links_check.py: pass (18 files, 401 links).python3 tests/bidi_controls_check.py: pass (1461 files).git diff --check origin/main...HEAD: clean.git ls-files --eolshows LF on all four new test files.tests/startup_small_texture_4k_check.cppwithx86_64-w64-mingw32-g++ -std=c++17 -Isrcand ran it under wine:PASS (15 sizes, 19 refused descriptions, 256 format values, extents, compact plans), 4943 accepted shapes, 0 past the answer.Mutations run (each reverted with
git checkout -- .):w <= b.width / 2changed tow <= b.width: killed (7 failures).bits * 2changed tobitsin the plan: killed (2 failures).0x80007doubled: killed (4 failures).mips > 1 &&insmall_texture_4k_bytes: survived. This is an equivalent mutant: with one level the tail branch returns one block, the same as the loop.Notes (nit, no action needed):
small_texture_4k.hstates that the XG mip records beyond the answer are compact. The device and XG tests (guard page,no-limitcontrol) cover this, but they need Windows, so I did not run them.Windows proof: I did not run
python3 $P win2025. The Windows CI job passed on this head. A Win2025 run is still worth doing before Ready, because the change touches the device wrapper, XG stubs and the draw path.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T03:42:06Z.
Ran the draw on hardware, since it needs
startup_stream_consumerbuilt first:RX 9070 XT, driver 32.0.32029.2010. The exact-size allocation, the no-access guard page and the two mips all read back as the reference, so the 4 KiB answer is not just accepted by the console path but actually writes where the draw reads.
Limits: AMD only, no NVIDIA here; and this tells nothing about the allocation answers other consoles ask for.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:54:43Z.
Review: COMMENTED
Review of head
c0db8308334d4a6331511aa6670558c6f05036b2(comment only, no approval).Summary: This head is the previous reviewed head (
d340e464) plus a merge oforigin/main. The PR's own files (small_texture_4k.h,xg_xs.cpp, the device and draw hooks, the four new tests) are unchanged by the merge, so the earlier read of the 4 KiB size rule and the compact plan still applies. No P1 and no P2 found. CI: Windows build and test, gfx1013 and Linux Python checks pass; the/O2and chart jobs are skipped. The PR is mergeable and the title is neutral.Commands executed locally (PR worktree,
origin/main...HEAD):git diff --stat origin/main...HEAD: 13 files, +1084/-10.python3 tests/docs_links_check.py: pass (18 files, 409 links).python3 tests/bidi_controls_check.py: pass (1501 files).git diff --check origin/main...HEAD: clean.tests/startup_small_texture_4k_check.cppwithx86_64-w64-mingw32-g++ -std=c++17 -Isrcand ran it under wine:PASS (15 sizes, 19 refused descriptions, 256 format values, extents, compact plans), 4943 accepted shapes, 0 past the answer.Mutations run (each reverted with
git checkout -- .):Alignment != 0x1000guard insmall_texture_4k: killed (2 failures).0x80007changed to0x8000F: survived. This is an equivalent mutant: the padded bit count is always a multiple of 0x8000, so no value lies between the two bounds.Not run: the Win2025 WARP job. The merge changed no shader or C++ code of this PR, and the previous head's review already covered the logic. The
startup_small_texture_4k_device,_xgand_drawCTest targets need Windows; I only ran the Linux-reachable size test.P1: none. P2: none.
Nit: none new.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T05:48:52Z.
Merged current
maininto the branch (c0db8308) to clear the conflict ind3d12_draw.inl:upload_texturenow returns a bool and #2214 added a console-layout total there. Upstream's code is kept and the compact plan sits beside it; its early exits return true like the neighbouring ones.I checked that the fence-safe sampling path from #2214 cannot bypass the plan: it requires a console swizzle mode in
Layout, while the 4 KiB answer requires layout UNKNOWN, so the two never apply to the same texture. Single-element textures stay on their own path.Behaviour is unchanged. Re-run on the merged head, WARP and RTX 5090:
ctest --preset release --no-tests=error -R "^(startup_small_texture_4k|startup_xg_|startup_address_single_element)"gives 20 of 20 passed, including both draw checks;git diff --checkis clean.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T06:24:17Z.
Review: APPROVED
The previous partial-row finding is resolved by the shared compact plan in allocation info, the XG layout and copy, and the upload reader. Independent Windows Release startup_small_texture_4k coverage: 8 pass, 1 AddrLib capability skip. Both WARP and RTX 4060 Laptop matched 1,536 pixels across two mips with a guard after the reported allocation. The XG no-limit negative also behaved as expected.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T11:16:21Z.
Small correction on wording: "the no-access guard page" is not something the log shows, and the fixture does not mention a guard page either. Strike it.
What the run does show, verbatim:
So the claim worth keeping is the exact-size allocation (0x2000, aligned 0x1000, a 4 KiB answer) and the two mips, not a guard page I cannot point to.
AI-assisted.