Translate texture size queries at a descriptor index (#407) #549

Closed
github-bot wants to merge 9 commits from github-bot/gh-545 into main AGit
Owner

@⁠Olima34 on GitHub · 2026-11-28 02:44 UTC · original
LakshanSivakumar:fix/image-size-query-as-image → main · +864 −118 · 8 files · 9 commits · closed without merging

Refs #411

A four-dword descriptor load at a whole descriptor index whose readers keep only size fields is lowered as a texture size query, not a buffer read, so the 723 programs refused with "a view address field the table gives 0: a buffer's stride or swizzle" translate. The null test of dword 1 is answered through bit 0 of the table's dword 1 (a guess, documented); a buffer entry gives 0 there, an image entry 1.

A program that both samples a descriptor and reads its tail dwords (5-7) as data — the console compiler re-loads a descriptor to size from it — is built those dwords from the view instead of being refused: the console's SQ_IMG_RSRC_WORD5-7, i.e. the array pitch of a writable view (1, 0 otherwise), the last level (MAX_MIP) and the tuning value 4 (PERF_MOD), with the compression fields 0 and 0 for a null descriptor.

A descriptor's address words read as data are served from the host's view addresses: dword 0 of both kinds (the view's address in title memory, the BVH's SRV the family was found with), and a buffer's dword 1 (its address's high half with the binding's stride above it, which the programs that rebuild a resource from those words expect). The table entry becomes 32 bytes, as a heap record is; a null entry reads all eight dwords as 0. Continues the same chain: serving a field uncovers the next one's readers.

Offline corpus, each change against its own parent on this branch's tree: the size-query change alone translated 723; the tail-dword change adds 11 (3 compute, 8 pixel); the address-word change adds 48 (39 blocked on a buffer's dword 0 — 21 pixel, 18 vertex —, 8 on a buffer's dword 1, one on a lane-mask join behind a descriptor read), with 0 regressions and 0 changed outputs anywhere. Totals: 1,532 refused / 2,597 translated before, 1,484 / 2,645 after. The families this PR opens are all at 0.

Tests: lowering (accepted shapes, the kept refusals, the tail dwords), and on the host an image, a writable view, a null entry, a buffer's two address words and a write with the values checked on hardware and WARP. Clippy (Windows target) and cargo xtask policy clean, cargo test -p victory-shader green.

Not verified on the game yet; a world run follows.

**@⁠Olima34** on GitHub · 2026-11-28 02:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/545) `LakshanSivakumar:fix/image-size-query-as-image` → `main` · +864 −118 · 8 files · 9 commits · closed without merging Refs #411 A four-dword descriptor load at a whole descriptor index whose readers keep only size fields is lowered as a texture size query, not a buffer read, so the 723 programs refused with "a view address field the table gives 0: a buffer's stride or swizzle" translate. The null test of dword 1 is answered through bit 0 of the table's dword 1 (a guess, documented); a buffer entry gives 0 there, an image entry 1. A program that both samples a descriptor and reads its tail dwords (5-7) as data — the console compiler re-loads a descriptor to size from it — is built those dwords from the view instead of being refused: the console's `SQ_IMG_RSRC_WORD5-7`, i.e. the array pitch of a writable view (1, 0 otherwise), the last level (MAX_MIP) and the tuning value 4 (PERF_MOD), with the compression fields 0 and 0 for a null descriptor. A descriptor's address words read as data are served from the host's view addresses: dword 0 of both kinds (the view's address in title memory, the BVH's SRV the family was found with), and a buffer's dword 1 (its address's high half with the binding's stride above it, which the programs that rebuild a resource from those words expect). The table entry becomes 32 bytes, as a heap record is; a null entry reads all eight dwords as 0. Continues the same chain: serving a field uncovers the next one's readers. Offline corpus, each change against its own parent on this branch's tree: the size-query change alone translated 723; the tail-dword change adds 11 (3 compute, 8 pixel); the address-word change adds 48 (39 blocked on a buffer's dword 0 — 21 pixel, 18 vertex —, 8 on a buffer's dword 1, one on a lane-mask join behind a descriptor read), with 0 regressions and 0 changed outputs anywhere. Totals: 1,532 refused / 2,597 translated before, 1,484 / 2,645 after. The families this PR opens are all at 0. Tests: lowering (accepted shapes, the kept refusals, the tail dwords), and on the host an image, a writable view, a null entry, a buffer's two address words and a write with the values checked on hardware and WARP. Clippy (Windows target) and `cargo xtask policy` clean, `cargo test -p victory-shader` green. Not verified on the game yet; a world run follows.
The largest refusal on main, "a view address field the table gives as 0: a
buffer's stride or swizzle" (723 programs), is a texture size query: the
compiler scales a descriptor index to whole descriptors, loads the four
dwords of the entry and keeps only the width (dword 1 bits 30-31), the
width and height (dword 2), the levels (dword 3) and the null test of
dword 1 against 0. The view-address table holds those bits, but the four-
dword shape is also a buffer's, where dword 1 is the address high bits,
the stride and the swizzle.

A four-dword load at a whole descriptor index is now read as an image size
query when every reader keeps only a size field with a constant AND or BFE
or tests dword 1 against 0, and no dword reaches a join. Any other reader
keeps the buffer reading and its refusals. The null test needs dword 1 to
be 0 for a null entry and never 0 for a view; the table's dword 1 carries
no format field, so a texture of width 4k + 1 reads as null. Guessed, as
nothing documents the word: bit 0 of the table's dword 1 (always 0, the
width being in bits 30-31) carries the answer, set when the entry's dword 0
(a buffer's address) or dword 3 (an image's 0xFAC and levels) is nonzero.

Corpus (offline, refusals of main): 723 newly translated, 0 regressions,
0 lost; the 723 have moved off the reason and 662 onto another, mostly the
lane-mask and image-dwords families #466/#537/#448 hold.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 02:49:19 +00:00
The size query reads the entry's image words; a buffer entry's table dwords 2
and 3 are 0, so the image reading of a buffer would size it 0 and the program
would use that wrong size. Set bit 0 of dword 1 only when dword 3 is nonzero
(an image's 0xFAC and levels): a buffer now reads as a null entry and takes
its own null branch. Host test covers the buffer case.
A program that samples a descriptor and reads its later dwords as data
(the console compiler re-loads a descriptor to size from it) was refused
on dword 5. Rebuild dwords 5-7 as the console has them: the array pitch
of a writable view, the last level and the tuning value; the compression
fields are 0, a null descriptor gives 0 for all three. Tests: the
translation, and the values on hardware and WARP.
A program that reads a descriptor's dword 0 as data wants the view's
address in title memory: the BVH's SRV in its `s_load_dwordx8` is the
shape the family was found with, and no host table held it, so it was
refused. The host's view addresses hold a pointer per view, which is what
a buffer's dword 0 already was (`buffer_bytes`); an image's is its data's
now, and both kinds' dword 0 is served.

A buffer's dword 1 is served with it: its address's high half in bits
0-15 (the table's) and the binding's stride above them (bits 16-29), which
is a property of the draw and not of the record. The descriptors that
rebuild a resource from these words (`s_and_b32 dword1, 0xc000ffff`, then
a store through it) read exactly that.

The table entry becomes 32 bytes, as a heap record is: the eight dwords
`image_words` gives, the array's tail fields included, and bit 0 of an
image's dword 1 is the host's marker for "a texture" (the size query's
null test needs a nonzero dword 1 for a view and 0 for nothing), with the
width's low two bits kept in bits 30-31 beside it. A null entry reads all
eight as 0, a buffer's dwords 2 and 3 stay 0 and so read as null.

The tests build the table the new way, take dword 0 for both kinds and
dword 1 for a buffer, and the debug switch this work needed
(`VICTORY_DEBUG_MISSING`) is declared among the translator's reads.
Says what dword 0 and a buffer's dword 1 hold, that the entry is 32 bytes
with the identity swizzle, the marker bit the size query's null test needs,
and the `VICTORY_DEBUG_MISSING` switch that names the reader of a value
the translator has no source for.
The table became eight dwords an entry and `view_addresses` fills it at
`8 * index`, but the per-view update `mirror` makes kept the old four-dword
step: every entry written after the table was made went 16 bytes early, so
each covered the second half of the entry before it and left the upper half
of its own slot to whatever was there. A shader sizing a view from the
table then read its neighbour's words: the game was worse with the address
words than without them.

The heap tests that mirror two entries and read the second one's address
cover it (they need a device, so only the WARP CI runs them here).
A load taken for its size fields alone walked the view addresses for a
dword 0 nobody reads, which needs the heap index and the root view bound.
The program's reads decide now, so a program that only wants an image's
size keeps the code it had.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 18:25 UTC · original

CI diagnosis (run 46109430075, check job, Windows): the only failure is descriptor::host::tests::a_texture_view_gives_its_image_descriptor_size_fields (crates/victory-gpu/src/descriptor/host.rs:2100) — 315 passed, 1 failed. That module is #[cfg(windows)], so it can't be reproduced on a Mac locally; I worked it out statically instead.

On the head bc3f2966, image_words (descriptor.rs:979) now takes at and returns [u32; 8] in the new layout — word 2 = (w>>2 & 0x3FFF) | (h & 0xFFFF) << 14, word 3 = 0xFAC | first<<12 | last<<16 | ty<<28, word 5 = unordered | (count-1)<<4 | 4<<20. The test still asserts the previous layout. For its first case (1000x600, view levels 2-4, at 0x1234_5678_9ABC) the code correctly produces exactly what CI printed as left:

[0x5678_9ABC, 0xC000_2469, 249 | 599<<14, 0xFAC | 2<<12 | 4<<16 | 9<<28, 0, 2<<4 | 4<<20, 0, 0]
= [1450744508, 3221234793, 9814265, 2416193452, 0, 4194336, 0, 0]

So the fix is to update the expected array in that test to the new layout (the later words[3] assertions still hold, since the 0xFAC word is index 3 in both layouts).

One more thing for when you rebase: #581 (approved, closes #577) fixes the UAV MipSlice read from d[4] to d[2] in image_words and updates this same test's unordered line (let uav = [0, 4, 3, 0, 0, ...]). Taking that hunk will keep this test consistent with the fix. And #567 (approved) covers the remaining size-query programs of #411 on current main, in case any of this branch is already landed there via 5cb68393/3a435b56.

**@⁠AnastasisKon** on GitHub · 2026-11-28 18:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/545#issuecomment-7243780548) CI diagnosis (run 46109430075, `check` job, Windows): the only failure is `descriptor::host::tests::a_texture_view_gives_its_image_descriptor_size_fields` (crates/victory-gpu/src/descriptor/host.rs:2100) — 315 passed, 1 failed. That module is `#[cfg(windows)]`, so it can't be reproduced on a Mac locally; I worked it out statically instead. On the head bc3f2966, `image_words` (descriptor.rs:979) now takes `at` and returns `[u32; 8]` in the new layout — word 2 = `(w>>2 & 0x3FFF) | (h & 0xFFFF) << 14`, word 3 = `0xFAC | first<<12 | last<<16 | ty<<28`, word 5 = `unordered | (count-1)<<4 | 4<<20`. The test still asserts the previous layout. For its first case (1000x600, view levels 2-4, at 0x1234_5678_9ABC) the code correctly produces exactly what CI printed as `left`: ``` [0x5678_9ABC, 0xC000_2469, 249 | 599<<14, 0xFAC | 2<<12 | 4<<16 | 9<<28, 0, 2<<4 | 4<<20, 0, 0] = [1450744508, 3221234793, 9814265, 2416193452, 0, 4194336, 0, 0] ``` So the fix is to update the expected array in that test to the new layout (the later `words[3]` assertions still hold, since the 0xFAC word is index 3 in both layouts). One more thing for when you rebase: #581 (approved, closes #577) fixes the UAV `MipSlice` read from `d[4]` to `d[2]` in `image_words` and updates this same test's unordered line (`let uav = [0, 4, 3, 0, 0, ...]`). Taking that hunk will keep this test consistent with the fix. And #567 (approved) covers the remaining size-query programs of #411 on current main, in case any of this branch is already landed there via 5cb68393/3a435b56.
github-bot closed this pull request 2026-11-30 09:18:46 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-30 09:17 UTC · original

Closing: this landed in BareMetalVI as 0c263675 ("Translate texture size queries at a descriptor index (#411)"). The project lives at BareMetalVI/BareMetalVI now.

**@⁠Olima34** on GitHub · 2026-11-30 09:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/545#issuecomment-7273996880) Closing: this landed in BareMetalVI as 0c263675 ("Translate texture size queries at a descriptor index (#411)"). The project lives at BareMetalVI/BareMetalVI now.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.