xshader: fill texture size and buffer record count fields read from a descriptor #315
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/315"
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 brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T17:16:59Z.
A console program can read a texture's size or a buffer's record count out of the descriptor it loaded, instead of asking for it. A descriptor load writes nothing in the translation, so that arithmetic ran on whatever the registers held, usually zero: a 1×1 texture, or an empty buffer. The result was a translation that ran and computed with the wrong numbers.
Texture sizes (
e8fb84e6). The image descriptor keeps three fields (WIDTH_LO,WIDTH_HI,HEIGHTandBASE_LEVELofSQ_IMG_RSRC_WORD1..3in Mesa'sgfx10-rsrc.json):Compiled code computes
(field + 1) >> level. The load now fills those fields fromGetDimensions, with the size of the view's first mip and level 0. That gives the console's result for this computation only. So the values are followed from the descriptor words to the shift, across control flow, and a program that reads one of them any other way is refused.Buffer record counts (
1ad86d0b,f7e404cd). Word 2 of a buffer descriptor (SQ_BUF_RSRC_WORD2) is the record count, which is whatGetDimensionsreturned to the program's source: bytes for a raw buffer, elements for a structured or typed one.GetDimensionsof the buffer the translation declares for that slot. The view type PSV names decides which buffer that is. The count is the whole word, so every later use of it is right.Shared helpers (
80c57b38): a newhlsl/operand_fields.rssays which source fields an instruction reads, whether it touches memory, where the straight run before an instruction starts, and what literal a register holds there. The three-operand encoding has three source fields whatever the instruction reads, and an unread field decodes ass0. The number of fields read now follows the opcode, so a one- or two-operand instruction no longer looks like a read ofs0. This module is shared with the guest-memory work, which isn't part of this PR.Corpus effect against
65e3e48(27,116 recorded ProjectScarlett requests,.wave32ones with--wave32-host):Before, those 19 ran with a size or count of zero.
The same port stacked on the guest-memory branch changes a strict superset of these requests, plus 6 that depend on that branch's code. So this standalone form changes nothing that one didn't.
Tests (
src/tests/hlsl/descriptor_size.rs,src/tests/hlsl/operand_fields.rs):Two GPU checks compare the translated computation with real views of known size:
tools/check_descriptor_size.py(--only descriptor-size, 9 cases) andtools/check_buffer_count.py(--only buffer-count, 15 cases: raw, structured and typed views up to the largest the check allocates).Per commit (against its parent on
65e3e48, 27,116 recorded requests):80c57b38e8fb84e61ad86d0bf7e404cd1ad86d0b)The two filling commits overlap, so 1,944 requests change in total.
Checks
python tuxbox.py check --no-gpuonf7e404c: passed, all six steps.95480b5(94e4dfa), 146 gates each.descriptor-size: 9 cases, 0 mismatches;buffer-count: 15 cases, 0 mismatches.🤖 Generated with Claude Code