Skip to content

shader: clear gfx2hlsl scalar min/max SCC on ties - #3435

Open
nanyoudegege wants to merge 1 commit into
R0Y00:mainfrom
nanyoudegege:shader/gfx2hlsl-minmax-scc-ties
Open

nanyoudegege wants to merge 1 commit into
R0Y00:mainfrom
nanyoudegege:shader/gfx2hlsl-minmax-scc-ties

Conversation

@nanyoudegege

@nanyoudegege nanyoudegege commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3434.

AMD's public RDNA 2 ISA reference, §12.1 (pp. 102–103, SOP2 opcodes 6–9), uses strict comparisons for the signed and unsigned scalar min/max instructions. Equal operands therefore leave the numerical min/max unchanged and clear SCC. The direct compute emitters already use strict comparisons. This patch changes only the gfx2hlsl SCC predicate, updates the Case S oracle and scalar-null test, and replaces the old negative control with one that restores the inclusive predicate.

Validation on Linux, based on 1a44cee5ee29ab7da2a4cd09eb5bc052020022ac:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and python3 -B tests/startup_gfx2hlsl_scalar_null_check.py: both fail with the updated tests on the old translator and pass with the patch. All 118 registered no-argument startup_gfx2hlsl Python checks passed (no skips); git diff --check was clean.
  • python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15: the source-built fixture matched its stored bytes. Case S compiled with DXC (dxc -T cs_6_0 -E main -Fo case-s.dxil case-s.hlsl).
  • An independent software Vulkan replay of the same 4×4 fixture matched all 320 words with Mesa llvmpipe. The old behavior differed on the four equal-input groups; restoring the inclusive unsigned-min condition also failed on those four groups (first word expected 00000000, got 00000100). The checked-in CTest selectors for Windows are ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute_(warp|s-min-inclusive_warp)$' -V if those targets are configured; no Windows WARP, physical GPU, or native direct-backend dispatch was run in this cloud environment.

AI-assisted implementation and independent review. Only the repository's source-built fixtures were used.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T08:18:52.330856Z 710fb44 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 710fb44d6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/startup/gfx2hlsl.py
return '(((((%s) ^ (%s)) & ((%s) ^ (%s))) >> 31) != 0)' % (a, b, a, result)
cast = 'int' if base.endswith('_i32') else ''
return '(%s(%s) %s %s(%s))' % (cast, a, '<=' if base.startswith('s_min') else '>=', cast, b)
return '(%s(%s) %s %s(%s))' % (cast, a, '<' if base.startswith('s_min') else '>', cast, b)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Invalidate cached translations for the new SCC semantics

When upgrading while retaining a populated X2W_SHADER_CACHE on the gfx2hlsl path, completed shaders continue using the inclusive predicate. pipeline_key() and compute_key() still use revision 29, matching the unchanged runtime constants in src/startup_stubs/d3d12_draw.inl, and pending_keys() skips existing manifest/bytecode pairs without checking translator changes. The bundled Case S produces different HLSL but retains its previous cache key, so affected cached shaders still set SCC on ties until the cache is manually cleared. Advance the affected cache revisions on both translator and runtime sides, or otherwise invalidate completed translations, alongside this semantic change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed on Linux with source-built inputs: the same warm cache caused gfx2hlsl.py --pending to skip Case S compute, a graphics pair, and a slot-57 mesh+pixel pair. Cold translation produced different DXIL for all three. The slot-57 pixel path shares this SCC lowering but has its own key; that key also names captured .mesh57-state / .s57 inputs, so a blanket bump needs a capture-compatibility plan. #3382 also uses 30/30cs for a different translation change. I’m leaving the review open rather than reusing those seeds. Would you prefer to stage the SCC invalidation after #3382 with a coordinated revision and slot-57 compatibility plan?

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 710fb44 by reading the diff; nothing built or run. It merges cleanly into main d58a9f6.

The only translator change is tools/startup/gfx2hlsl.py:11495, <=/>= to </>. With it gfx2hlsl gives the same SCC as the direct path for all four ops when S0 == S1 (SCC clear): src/gfx1013_direct_compute.inl:4007 at this head, cmp(sign + (... == "min" ? "lt" : "gt"), a, b), and src/gfx1013_compute_native.cpp:1329, scc=lhs < rhs / lhs > rhs (unsigned forms). The description cites an ISA reference (§12.1, SOP2 opcodes 6-9) for the strict rule and states that no WARP, hardware or direct-backend dispatch was run. The Case S oracle, the s-min-inclusive control (pinned at word 0, bit 8), check_scc_modelled and the four null strings in startup_gfx2hlsl_scalar_null_check.py follow the strict rule; no assertion of the inclusive rule is left.

Changes requested:

  • Cache revision: src/startup_stubs/d3d12_draw.inl:419-420 and gfx2hlsl.py:12966,12976 still use x2w-startup-shader-29 / 29cs, so translations already in the cache keep setting SCC on ties. #2778, which introduced the inclusive rule, advanced the revision (26 -> 27) on both sides. This change needs the same bump (src/shader_compute_request.cpp:180,191 and the tests and docs that pin 29 carry the string too).

Not covered:

  • No test compares the two paths, as #3434 suggested. Case S compares gfx2hlsl with a Python reference; the general s_min/s_max block of gfx1013-direct-cs still has no SCC test with S0 == S1.
  • The pr test preset filter does not match startup_gfx2hlsl_compute_warp or startup_gfx2hlsl_compute_s-min-inclusive_warp, so CI did not run the Case S dispatch or the new control.

@Leyukaka

Copy link
Copy Markdown
Collaborator

Either order works, as long as the revision is chosen at merge time. #3382 (open, 025f16d) moves only x2w-startup-shader-29/29cs to 30/30cs (at its head: d3d12_draw.inl:393-394, shader_compute_request.cpp:180/191, gfx2hlsl.py:12973/12983, tools/patch_manifest.py:24) and leaves x2w-startup-mesh-57-3 unchanged; this PR changes no revision string, and git merge-tree of the two heads is clean. Two identical 29 -> 30 edits would also merge without a conflict, and a cache filled between the two merges would then stay valid across the second change, so whichever PR merges second needs one more step (31/31cs here if #3382 lands first).
The slot-57 key does not depend on that order. At main 1cd0719, x2w-startup-mesh-57-3 seeds the request key and the variant that names req_<variant>.s57 and <variant>.mesh57-state (native_mesh57.inl:247-251, mesh57_pixel_entry.py:28-31); compile_dxil --rekey and shader_cache_rekey.py rekey the .m57/.ps57/.root requests but not those two files, so a bump of that key leaves existing archives and profiles under names that no longer match.
Nothing in src/ loads the .ms57.cso/.ps57.cso translation outputs (gfx2hlsl.py:13424: "No runtime path loads these names yet"), so translations cached under the unchanged mesh-57 key are not used at run time.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 710fb44d against main 77d1ba4d. Verdict: hold for Leyukaka's open change request (the cache revision bump). I found nothing else.

MUST

  1. The requested revision bump isn't on this head: git grep -n 'x2w-startup-shader-29' origin/main -- src tools still lists d3d12_draw.inl:420 and gfx2hlsl.py:12970, and this PR changes neither line. Leyukaka's comment above covers the ordering with shader: decode buffer FORMAT 47 (10_10_10_2 SSCALED) from hardware descriptors #3382.

What I checked and ran:

  • Semantics. Strict compares match the ISA (SCC is set only when S0 is the chosen operand, so ties clear it) and the direct compute path. The change brings gfx2hlsl in line.
  • On the merge (git merge-tree --write-tree origin/main 710fb44d → tree a36bd61e): tests/startup_gfx2hlsl_compute_check.py rc=0 and tests/startup_gfx2hlsl_scalar_null_check.py rc=0.
  • Negative control. The same tree with main's tools/startup/gfx2hlsl.py makes both checks fail. The compute check fails at AssertionError: ('s_min_u32 s23, s7, 4', ... in check_scc_modelled, so the updated tests do pin the strict rule.
  • Default launcher path. With X2W_NATIVE_SHADERS_ONLY=1, set since runtime: default to native shaders and Opus decoding #3449, gfx2hlsl compute manifests aren't loaded (load_compute_translation: if (native_shaders_only()) { ... return nullptr; }). So this fix reaches -Translate runs only, and the native path already uses strict compares.

Linux, Python 3.13, no WARP or GPU run.

AI-assisted.

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