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 #407

Open
opened 2026-11-27 17:00:52 +00:00 by Sandile-0511 · 4 comments
Sandile-0511 commented 2026-11-27 17:00:52 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T17:00:52Z.


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 #386 and #387 are about. #400 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 #386 and #387. #387'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 #386 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: #387 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 #387 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".

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6651039403 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T17:00:52Z. --- 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 #386 and #387 are about. #400 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 #386 and #387.** #387'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 #386 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: #387 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 #387 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 commented 2026-11-27 17:01:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T17:01:03Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223930782 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7223930782). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T17:01:03Z. --- /claim
github-actions[bot] commented 2026-11-27 17:01:13 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T17:01:13Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223934054 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7223934054). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T17:01:13Z. --- Claimed by @Sandile-0511. Open a draft pull request with `Refs #407` in its description within 24 hours, or the claim expires.
Olima34 commented 2026-11-28 02:40:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T02:40:29Z.


/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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7232519847 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7232519847). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T02:40:29Z. --- /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.
github-actions[bot] commented 2026-11-28 02:40:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T02:40:39Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7232521702 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/407#issuecomment-7232521702). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T02:40:39Z. --- @Olima34 this is already claimed by @Sandile-0511. Pick another issue, or ask them here.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#407
No description provided.