From be5efdf730455e47000c037eda78a8beb6e057be Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Tue, 1 Dec 2026 02:46:13 +0200 Subject: [PATCH] shader: keep structured-to-raw descriptor words at compute joins 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 --- .../startup-gfx2hlsl-cselect-descnum.md | 4 +- tests/startup_gfx2hlsl_load_desc_check.py | 66 +++++++++++++++++++ tools/startup/gfx2hlsl.py | 17 ++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/docs/experiments/startup-gfx2hlsl-cselect-descnum.md b/docs/experiments/startup-gfx2hlsl-cselect-descnum.md index 1e33a3f2fc..06bcead289 100644 --- a/docs/experiments/startup-gfx2hlsl-cselect-descnum.md +++ b/docs/experiments/startup-gfx2hlsl-cselect-descnum.md @@ -29,7 +29,9 @@ Nothing reads that symbol as a value: refuses with `descriptor operand s[N:M]: sK holds a word joined at a branch target` (`Stage.joined_word`). A join of different symbols leaves only that mark, so a select that reaches a descriptor word on one path, or through a loop back edge, would otherwise be dropped. This also refuses compute joins that bring two different non-select - words there. Main translates those, ignoring the difference, as in #2901. + words there. Main translates those, ignoring the difference, as in #2901. A join where every path brings the + same word of the structured-to-raw conversion (stride cleared, byte count, OOB_SELECT 3) keeps it + (`raw_conversion_word`); `tests/startup_gfx2hlsl_load_desc_check.py` has the kept and refused joins. - The select still refuses with `scc from descriptor data in s_cselect_b32` when its SCC came from an ALU instruction on descriptor data, because that SCC is not emitted. diff --git a/tests/startup_gfx2hlsl_load_desc_check.py b/tests/startup_gfx2hlsl_load_desc_check.py index 597f201589..6ca890775b 100644 --- a/tests/startup_gfx2hlsl_load_desc_check.py +++ b/tests/startup_gfx2hlsl_load_desc_check.py @@ -110,6 +110,72 @@ def check_refusals(): except G.Unsupported as e: assert 'buffer load through a modified descriptor' in str(e), f'unexpected refusal: {e}' + # 6b. Joins after the conversion. Both arms of a uniform branch convert the load descriptor and join at the load: + # every path brings the same converted words, so the join keeps them and the load translates as on one path. + # A join that mixes a converted word with another word refuses, and so does a loop whose back edge rewrites one. + def sopp(op, simm): + return struct.pack(' 4 and isinstance(sym[4], int) else 4 + return len(sym) > loaded and sym[loaded] in ('stride0', 'byte_count', 'oob3') and names_one_value(sym[:loaded]) + + def descriptor_select(sym): """True for what Stage.scalar_select records for a compute s_cselect_b32 with a descnum arm: ('descnum', 'cselect', select offset, arm, arm). It has no run-time value, so no consumer may read it as one.""" @@ -4241,7 +4254,9 @@ def translate(self): if any(reg not in w for _, w in arriving) and any(p and not run_time_symbol(p) for p in paths): self.sym[reg] = ('joined at a branch target',) continue - if force is None and paths and names_one_value(paths[0]) and all(p == paths[0] for p in paths): + if (force is None and paths and all(p == paths[0] for p in paths) and ( + names_one_value(paths[0]) or getattr(self, 'kind', None) == 'cs' + and raw_conversion_word(paths[0]))): self.sym[reg] = kept[off][reg] = paths[0] continue if force == 'refuse' or any(p and not run_time_symbol(p) for p in paths):