Skip to content

shader: keep structured-to-raw descriptor words at compute joins - #3687

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Not-Saii:shader/raw-conversion-join
Dec 1, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Not-Saii:shader/raw-conversion-join

Conversation

@Not-Saii

@Not-Saii Not-Saii commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Refs #2274

Change

At a branch target, tools/startup/gfx2hlsl.py keeps a descriptor word only when every path brings the same
symbol and names_one_value() accepts it. The tags that raw_descriptor_alu() adds to the words of the
structured-to-raw conversion (stride0, byte_count, oob3) were not accepted. A compute buffer access after a
join therefore refused with descriptor operand s[a:b]: sN holds a word joined at a branch target, even when every
path brought the same converted words.

raw_conversion_word() accepts those words at compute joins only (names_one_value() is unchanged). Vertex stages
are unchanged. The spill path still refuses a modified word, as startup_gfx2hlsl_compute_spill_check.py requires.
The joined_word note in docs/experiments/startup-gfx2hlsl-cselect-descnum.md gains one sentence.

The byte-count tag covers both products (NUM_RECORDS * stride and NUM_RECORDS * max(stride, 1)). No compute
consumer reads the count: raw loads and stores are unbounded, and a numeric read of a descriptor word is
refused. #3100 gives the clamped product its own tag (('byte_count', 'min1')). The new helper checks only the
first tag, so either merge order keeps both forms at a join.

Fixture

tests/startup_gfx2hlsl_load_desc_check.py (compute case A, source-built words) gains joins after the conversion:

  • Kept, and the load translates as on one path: both arms convert; both arms run the clamped conversion; one arm
    runs the clamped conversion and the other the plain one; both arms clear the stride.
  • Refused with joined at a branch target: one arm converts and the other does not; one arm clears the stride
    only; a loop enters the load with the loaded words and converts them before its back edge.
  • Refused with numeric use of ...: a vector read of the joined byte-count word, and of a scalar computed from it,
    after the clamped/plain diamond.
  • Mutant control: with raw_conversion_word replaced by lambda sym: False, the kept diamond refuses again.

Evidence

Commit under test: be5efdf7 on main 1a9ccbc4 (fixture and join checks rerun after the rebase; the retranslation numbers are from fbb76499 on a3bfd019).

Single checks, all exit 0:

python -B tests/startup_gfx2hlsl_load_desc_check.py
python -B tests/startup_gfx2hlsl_join_symbols_check.py
python -B tests/startup_gfx2hlsl_compute_spill_check.py
python -B tests/startup_gfx2hlsl_buffer_store_check.py
python -B tests/startup_gfx2hlsl_cselect_descnum_check.py
python -B tests/startup_compute_tg_size_check.py
python -B tests/startup_gfx2hlsl_compute_check.py
python -B tests/docs_links_check.py

Offline retranslation of a local set of compute requests that refused with this message (37 programs): none
refuse with it now. 3 translate, and their HLSL compiles with DXC (cs_6_0). The rest stop at later, separate
refusals: a readfirstlane waterfall body, s_cbranch_execz joins, and a descriptor used for both a load and a store.
The other 119 requests of the same local batch refuse with the same text as before. A further 223 local compute
requests that already translated give byte-identical HLSL and manifests before and after the change. These are
local results and say nothing about run-time behavior.

🤖 Generated with Claude Code

At a branch target gfx2hlsl keeps a descriptor word only when every path
brings the same symbol and names_one_value() accepts it. The tags that
raw_descriptor_alu() puts on the converted words (stride cleared, byte
count, OOB_SELECT 3) were not accepted, so a compute buffer access after a
join refused with "descriptor operand ...: sN holds a word joined at a
branch target" even when every path brought the same converted words.

raw_conversion_word() accepts those words at compute joins only. A spill
of a modified word stays refused, and vertex stages are unchanged. Joins
that mix a converted word with another word, and a loop whose back edge
converts the words the header entered with, still refuse. A numeric read
of the joined byte count refuses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed be5efdf7 by reading the diff; not built or run.

Verdict: approve. A compute join now keeps the converted words only when every path brings the identical symbol, and the only readers check the whole converted descriptor, never the count. No MUST, no SHOULD.

  • Checked, no finding:
    • stride0 and oob3 name one value on every path. oob3 is word | 0x30000000, whether or not the oob0 mask ran first, so the two spellings that share the tag give the same bits.
    • byte_count is the one tag that can stand for two values: NUM_RECORDS * stride and NUM_RECORDS * max(stride, 1) differ when the stride is 0. Its only readers, load_descriptor and store_descriptor (gfx2hlsl.py:7504-7552), compare the four-word tuple and emit an unbounded raw access without reading the count. A single path with either product was already accepted, so the clamped/plain join adds no new run-time case. The two numeric-read controls pin the other way the count could be used.
    • A partly converted set (oob0 only, or the stride cleared on one arm) still fails at the use, because the consumers need the full (w0, stride0, byte_count, oob3) tuple. The "one arm clears the stride only" control covers the join side of that.
    • The gate is kind == 'cs', and names_one_value is unchanged, so spill proofs and other stages behave as before.
  • Loop control: the back edge brings converted words into a header entered with plain ones, and the join refuses. This is the case a first-visit kept entry could otherwise get wrong.

Tests: the four kept diamonds prove the join path (gfx2hlsl.py:4257-4259) translates the same load as one path does. The refused diamonds, the loop and the mutant (raw_conversion_word = lambda sym: False) prove the new condition is what keeps them. CI did not run startup_gfx2hlsl_load_desc_check.py: it is not in the Windows pr filter or in the Linux job's script list, so the author's local run is the only one.

@R0Y00
R0Y00 merged commit ca0d01c into R0Y00:main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants