The largest refusal on main, "a buffer's stride or swizzle" (723 shaders), is a texture size query through four dwords of an image descriptor #411

Open
opened 2026-11-27 17:05:42 +00:00 by github-bot · 4 comments
Owner

@⁠Sandile-0511 on GitHub · 2026-11-27 17:00 UTC · original

On main b998bb65 the largest refusal reason in my corpus (21,608 shaders: every shader the title registered in a run that reached the world; native host options) is "a view address field the table gives as 0: a buffer's stride or swizzle": 723 shaders (704 compute, 17 pixel, 2 vertex; 187 bound from the first world frame on). All 723 are one shape, and it reads a texture, not a buffer. Before #311, 614 of them were refused as "a descriptor read only as data", the message #389 and #390 are about. #404 reports that 290 of its 305 compute shaders reach this message next; I have not looked at which shape those are.

What is refused. A texture size query on a texture the program takes from the heap by index:

  • a waterfall loop over a per-lane heap index (v_readfirstlane_b32, v_cmpx_eq_i32, s_lshl_b32 by 5);
  • s_load_dwordx4 from the resource heap with that shifted index as the offset: the first four dwords of the descriptor, which nothing uses as a resource;
  • dword 1 is read by s_bfe_u32 (the 2 bits at bit 30) and tested with s_cmp_eq_i32 against 0, dword 2 by s_and_b32 (the low 14 bits) and in 52 shaders also by s_bfe_u32 (the 16 bits at bit 14), dword 3 by s_bfe_u32 (the 4 bits at bit 12); dword 0 is not read;
  • in the ones I read, s_lshl2_add_u32 and s_lshr_b32 then make the width (or width and height) of the view's first level, and s_cselect_b32 makes it 0 when dword 1 is 0.

Those bits are an image descriptor's width minus one (2 bits in dword 1, 14 in dword 2), height minus one (dword 2 bits 14-29) and base level (dword 3 bits 12-15). A buffer's record count would be read whole. 757 shaders hold this shape (710 compute, 45 pixel, 2 vertex), every one with exactly these readers: 723 are refused and 34 translate (see the end). No shader of the corpus reads a descriptor of a table or of the resource heap as data through an eight-dword load. So for a size query the compiler loads the half of the image descriptor it needs, not the whole.

Why. Lower::view_addresses takes the kind of view from the size of the load: eight dwords at a whole descriptor is IMAGE, anything else BUFFER. So bits 30-31 of dword 1 are taken for a buffer's swizzle, and dwords 2-3 for its record count and format. Read as IMAGE, the size fields are the ones the table holds (descriptor::texture_words). The test is the exception: the table holds an image's dword 1 as the width's low 2 bits only, so a compare with 0 would take a texture of width 4k + 1 (1, 5, 9, 257, 513) for a null view. docs/native-host.md ("Descriptor dwords read as data") keeps the shape refused for that reason.

Next to #389 and #390. #390's head (c091cbda, on 728845d1) reads dwords 0-3 for every such load (known = 4). Swept on my corpus against its base, by output: 421 newly translated, 0 regressions, 55 changed. 53 of the 421 (52 vertex, 1 compute) are reads of a buffer's record count, as #389 describes. The other 368 (352 compute, 14 pixel, 2 vertex) are this texture shape. They are all 69 of its gains that are bound in the world here, and all 64 of its gains among the shaders refused in a 4-minute run here. They translate there because a texture view's entry already holds texture_words, with the test inexact as above. On main the rebase meets the same point through seen_bits. So I suggest a split: #390 keeps the buffer fields, and this issue takes the texture half.

Plan.

  • In Lower::view_addresses, a four-dword load at a whole descriptor is IMAGE when every reader of its dwords is one of the field reads above (a constant s_bfe_u32 or s_and_b32 inside the size fields the table holds, the test of dword 1 against 0), dword 0 has no reader, no dword reaches a join, and the computed part of the offset is an s_lshl_b32 by 5. Any other reader keeps today's refusal.
  • The readers are judged as seen_bits judges them, with a constant s_bfe_u32 added (it keeps its field's bits).
  • The null test gets an exact answer without a change to the table: for such a load, dword 1 is given with bit 0 set where the entry holds a view (its dword 3 is not 0: texture_words gives every texture view the identity swizzle there). Only the test against 0 can see bit 0, because the other reader allowed keeps bits 30-31. So a texture of width 4k + 1 is not taken for a null view.
  • Marked as guesses, in the code and in docs/native-host.md: a real image descriptor's dword 1 is never 0 on the console (its format field is not 0) and a null view's is 0; an entry read this way holds an image view or nothing.
  • Tests: the lowering (the accepted form, and one refusal per condition), and on Metal a compute program that stores the width it reads this way for textures of width 1 and 5, for a first level above 0 and for an empty entry.
  • A by-output corpus sweep in the pull request.

Measured with a throwaway prototype of the rule (on 728845d1, whole corpus, by output): 368 gained, the same 368 shaders #390 gains for this shape; 0 regressed; 34 changed. The other 355 refused holders stop at a later refusal, most of them at lane-mask reasons. Five of the 64 from the run, for anyone with a dump of their own: 0161ea22debc4d43, 024c838b8e9b5ab6, 0841e6b5c06550d4, 0905d38ab31453e4, 0c7e2e34df0718ea.

The 34 changed are the shaders that hold the shape and translate today (6 compute, 28 pixel). All of them reach #256's path with this value: a join that a guarded write un-marked gets 0 on the edge that carries the refused size. With the rule the size exists, so they no longer depend on that.

One limit to know: the table holds zeros for a view whose resource the host does not know, so such a query reads "no texture".

**@⁠Sandile-0511** on GitHub · 2026-11-27 17:00 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407) On main `b998bb65` the largest refusal reason in my corpus (21,608 shaders: every shader the title registered in a run that reached the world; native host options) is "a view address field the table gives as 0: a buffer's stride or swizzle": 723 shaders (704 compute, 17 pixel, 2 vertex; 187 bound from the first world frame on). All 723 are one shape, and it reads a texture, not a buffer. Before #311, 614 of them were refused as "a descriptor read only as data", the message #389 and #390 are about. #404 reports that 290 of its 305 compute shaders reach this message next; I have not looked at which shape those are. **What is refused.** A texture size query on a texture the program takes from the heap by index: - a waterfall loop over a per-lane heap index (`v_readfirstlane_b32`, `v_cmpx_eq_i32`, `s_lshl_b32` by 5); - `s_load_dwordx4` from the resource heap with that shifted index as the offset: the first four dwords of the descriptor, which nothing uses as a resource; - dword 1 is read by `s_bfe_u32` (the 2 bits at bit 30) and tested with `s_cmp_eq_i32` against 0, dword 2 by `s_and_b32` (the low 14 bits) and in 52 shaders also by `s_bfe_u32` (the 16 bits at bit 14), dword 3 by `s_bfe_u32` (the 4 bits at bit 12); dword 0 is not read; - in the ones I read, `s_lshl2_add_u32` and `s_lshr_b32` then make the width (or width and height) of the view's first level, and `s_cselect_b32` makes it 0 when dword 1 is 0. Those bits are an image descriptor's width minus one (2 bits in dword 1, 14 in dword 2), height minus one (dword 2 bits 14-29) and base level (dword 3 bits 12-15). A buffer's record count would be read whole. 757 shaders hold this shape (710 compute, 45 pixel, 2 vertex), every one with exactly these readers: 723 are refused and 34 translate (see the end). No shader of the corpus reads a descriptor of a table or of the resource heap as data through an eight-dword load. So for a size query the compiler loads the half of the image descriptor it needs, not the whole. **Why.** `Lower::view_addresses` takes the kind of view from the size of the load: eight dwords at a whole descriptor is `IMAGE`, anything else `BUFFER`. So bits 30-31 of dword 1 are taken for a buffer's swizzle, and dwords 2-3 for its record count and format. Read as `IMAGE`, the size fields are the ones the table holds (`descriptor::texture_words`). The test is the exception: the table holds an image's dword 1 as the width's low 2 bits only, so a compare with 0 would take a texture of width 4k + 1 (1, 5, 9, 257, 513) for a null view. `docs/native-host.md` ("Descriptor dwords read as data") keeps the shape refused for that reason. **Next to #389 and #390.** #390's head (`c091cbda`, on `728845d1`) reads dwords 0-3 for every such load (`known = 4`). Swept on my corpus against its base, by output: 421 newly translated, 0 regressions, 55 changed. 53 of the 421 (52 vertex, 1 compute) are reads of a buffer's record count, as #389 describes. The other 368 (352 compute, 14 pixel, 2 vertex) are this texture shape. They are all 69 of its gains that are bound in the world here, and all 64 of its gains among the shaders refused in a 4-minute run here. They translate there because a texture view's entry already holds `texture_words`, with the test inexact as above. On main the rebase meets the same point through `seen_bits`. So I suggest a split: #390 keeps the buffer fields, and this issue takes the texture half. **Plan.** - In `Lower::view_addresses`, a four-dword load at a whole descriptor is `IMAGE` when every reader of its dwords is one of the field reads above (a constant `s_bfe_u32` or `s_and_b32` inside the size fields the table holds, the test of dword 1 against 0), dword 0 has no reader, no dword reaches a join, and the computed part of the offset is an `s_lshl_b32` by 5. Any other reader keeps today's refusal. - The readers are judged as `seen_bits` judges them, with a constant `s_bfe_u32` added (it keeps its field's bits). - The null test gets an exact answer without a change to the table: for such a load, dword 1 is given with bit 0 set where the entry holds a view (its dword 3 is not 0: `texture_words` gives every texture view the identity swizzle there). Only the test against 0 can see bit 0, because the other reader allowed keeps bits 30-31. So a texture of width 4k + 1 is not taken for a null view. - Marked as guesses, in the code and in `docs/native-host.md`: a real image descriptor's dword 1 is never 0 on the console (its format field is not 0) and a null view's is 0; an entry read this way holds an image view or nothing. - Tests: the lowering (the accepted form, and one refusal per condition), and on Metal a compute program that stores the width it reads this way for textures of width 1 and 5, for a first level above 0 and for an empty entry. - A by-output corpus sweep in the pull request. **Measured with a throwaway prototype of the rule** (on `728845d1`, whole corpus, by output): 368 gained, the same 368 shaders #390 gains for this shape; 0 regressed; 34 changed. The other 355 refused holders stop at a later refusal, most of them at lane-mask reasons. Five of the 64 from the run, for anyone with a dump of their own: `0161ea22debc4d43`, `024c838b8e9b5ab6`, `0841e6b5c06550d4`, `0905d38ab31453e4`, `0c7e2e34df0718ea`. The 34 changed are the shaders that hold the shape and translate today (6 compute, 28 pixel). All of them reach #256's path with this value: a join that a guarded write un-marked gets 0 on the edge that carries the refused size. With the rule the size exists, so they no longer depend on that. One limit to know: the table holds zeros for a view whose resource the host does not know, so such a query reads "no texture".
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:05:42 +00:00
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-27 17:01 UTC · original

/claim

**@⁠Sandile-0511** on GitHub · 2026-11-27 17:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7223930782) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 17:01 UTC · original

Claimed by @⁠Sandile-0511. Open a draft pull request with Refs #407 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 17:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7223934054) Claimed by @⁠Sandile-0511. Open a draft pull request with `Refs #407` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 02:40 UTC · original

/claim

Working on it locally: a four-dword load at a descriptor index whose readers keep only size fields is lowered as an image size query, with the null test of dword 1 answered through bit 0 of the table's dword 1 (always 0, the width being in bits 30-31) taken from dword 0 / dword 3 of the entry. Draft PR follows with the corpus sweep.

**@⁠Olima34** on GitHub · 2026-11-28 02:40 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7232519847) /claim Working on it locally: a four-dword load at a descriptor index whose readers keep only size fields is lowered as an image size query, with the null test of dword 1 answered through bit 0 of the table's dword 1 (always 0, the width being in bits 30-31) taken from dword 0 / dword 3 of the entry. Draft PR follows with the corpus sweep.
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 02:40 UTC · original

@⁠Olima34 this is already claimed by @⁠Sandile-0511. Pick another issue, or ask them here.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 02:40 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7232521702) @⁠Olima34 this is already claimed by @⁠Sandile-0511. Pick another issue, or ask them here.
This discussion has been locked. Commenting is limited to contributors.
No description provided.