shader: how should pixel_aot represent v_cmpx (EXEC-writing compares)? Proposed first stage on the #651 region #925
Closed
opened 2026-11-23 17:44:24 +00:00 by MasterDomino
·
6 comments
No Branch/Tag specified
main
codex/indirect-large-backed-views
codex/word3-preflight-check
codex/vertex-table-two-records
codex/live-index-alias
codex/copied-vertex-buffer-srv
codex/windows-stage-test-output
codex/preserve-live-srv-retirement
codex/share-render-target-tracking
codex/sgd5-negative-offset-fixture
coverage-dashboard
codex/mesh-loose-root
codex/mesh86-cache-padding
codex/xmem-scatter-preflight
codex/mesh-depth-ps
codex/indirect-dispatch-refresh
codex/compute-container-index
codex/startup-compute-formatted-load
codex/compute-indirect-producer
codex/compute-atomic-soffset
codex/mesh-dual-handoff
codex/startup-run-sh-watcher-control
codex/queue31-page-alias
codex/indexed-indirect-compute-root
codex/typed-buffer-view-metadata
codex/translated-indexed-address-alias
codex/fixed-mesh-create-result
codex/xmem-section-lease
codex/startup-slot86-mesh-cache
codex/restore-mesh-barrier-iteration
codex/translated-indirect-upload-index
codex/xapu-completion-opt-in
codex/translated-indexed-rect
codex/translated-indexed-indirect
codex/startup-mesh-lds-integration
codex/startup-console-ms24
codex/startup-slot57-mesh-request
codex/indirect-copy-provenance
codex/present-color-producer-trace
codex/compute-dispatch-binding-trace
codex/translated-indirect-table-buffers
codex/indirect-copy-provenance-base
codex/mix-half-literal-source
codex/translated-indirect-draw
codex/xmem-scatter-diagnostics
codex/slot148-recording-upload
codex/slot70-loading-art-verified
codex/command-list-upload-arena
codex/recover-failed-command-list
codex/startup-heap-timing-notes
codex/align-audio-input-timeline
codex/synthetic-depth-export-control
codex/startup-texture1d-on-windows
codex/1629-packed-position-fixture
codex/cpu-srv-refresh
codex/stream-root-srv-draw
codex/audio-mixer-timer
codex/startup-reload-published-shader
codex/priority-integrate-1284
codex/guest-sixteen-page-record
codex/aot-placed-dxr-batch
codex/guest-directory-selection
codex/gamesave-enumerate-read
codex/readme-archive-to-pixels
codex/pe-placed-view-draw
codex/archive-directory-gpu
codex/slot133-dxr-build
codex/materialize-placed-vertex-view
codex/dstorage-directory-offsets
codex/xg-nine-bc-copy
codex/xg-slot10-bc64-arrays
codex/dxr-guest-address-readback
codex/gpu-va-high-bits
codex/clarify-diagnostic-startup-scope
codex/xg-six-levels
codex/typed-derived-blend
codex/english-legal-text-progress
codex/address-bc-4ks
codex/dstorage-bounded-file-read
codex/wide-srv-offsets-menu
codex/startup-memory-srv
codex/bound-view-tail
codex/language-selector-readback
codex/setup-menu-progress
codex/cpu-plane-refresh
codex/startup-ubyte-vertex
codex/presenter-window-selection
codex/startup-uniform-buffer-lane
codex/intro-loop-timing
codex/static-clzero-loops
codex/document-rtx-intro
codex/startup-insertq
codex/nv12-startup-texture
codex/stream-stage-draw
codex/startup-null-uav-format
codex/startup-draw-capture
codex/shorten-windows-checks
codex/dstorage-rfc1950
codex/startup-dump-fence
codex/pr1135-review-base
codex/startup-stream-requests
codex/startup-chroma-view
codex/readme-graphics-pipeline-streams
codex/static-crt-free-tls
codex/arc-140t-rtx-5080-laptop-gpu-reports
codex/main-startup-progress-entry
codex/signed-dxil-catalogue
codex/reloc-free-preferred-base
codex/quad-dpp-bit-mask
codex/raw-srv-bounds
codex/rx9070-31044-hardware-report
codex/gpu-page-source-provenance
codex/runtime-placeholder-interior
codex/gpu-copy-queue-tile-order
codex/pe-pin-external-providers
codex/xmem-placeholder-reservations
codex/xmem-shared-physical-pages
codex/pe-package-startup
codex/xmem-tools-memory-query
codex/cpu-stack-output-import
codex/pe-load-security-cookie
codex/record-three-bvh-retests
codex/cpu-rbp-frame-anchor
codex/xmem-default-startup
codex/record-rtx-3050-ti-9597
codex/docs-readme-start-here
codex/check-compute-mad24-truncation
codex/docs-discord-community
codex/bound-rcx-branch-mutants
codex/rtx5060ti-bvh-62114
codex/837-neutral-readme-disclaimer
codex/record-rtx-3070-ti
codex/title-neutral-public-wording
codex/exe-shadow-frame-submissions
codex/exe-shadow-runtime-chain
codex/readme-polish
codex/gpu-coverage-nov23
codex/spirv-minlod
codex/shadow-shim-device
codex/exe-two-shadow-frames
codex/shim-dispatch-cleanup
codex/fix-spirv-cache-probe
codex/sampler-use
codex/ballot-bit-extract
codex/packed-fma-release
codex/cpu-packed-fma-o2
codex/publish-coverage-dashboard
codex/mesh-cbv-binding-order
codex/spirv-window-fixture
codex/ps-e32-float-uint
codex/ps-cbuffer-reads
codex/fixed-profile-rescan
codex/shim-compute-integration
codex/readme-visible-coverage
codex/readme-research-navigation
codex/integrate-pr-256
codex/indexed-mesh
codex/sampled-coverage
codex/first-ms
codex/dual-ps
codex/ps-attribute
codex/compute-first
codex/ps-export
codex/readme-research-status
codex/ps-layout
codex/blast-window
codex/chart-caption
codex/reviewer-roles
codex/blast-aot
codex/archive-program
codex/crc-stream-program
codex/exe-image-data-chain
codex/local-cpu-fixture-coverage
codex/exe-bound-frame-chain
codex/exe-mapped-comparison
codex/contribution-dependencies
codex/exe-entry-aot
codex/bink-frame-heap-integration
docs/hardware-seven-reports
codex/bink-custom-heap
codex/bink-heap-callers
codex/discussions-entry-points
codex/gpu-community-batch-64
codex/ffx-scratch-writers
codex/generic-project-documentation
codex/ffx-dispatch-rcas
codex/four-windows-gpu-reports
codex/title-neutral-project-wording
codex/community-coverage-provenance
codex/rcas-packed-texels
codex/community-gpu-retests
codex/community-build-and-gpu-reports
codex/ffx-provider-loop
codex/ffx-recurrent-views
codex/ffx-recurrent-resource
codex/amd-wave64-reports
codex/ffx-backend-slots
codex/upscaler-device-init
codex/ffx-context-lifecycle
codex/ffx-version-query
codex/ffx-provider-contract
codex/typed-object-callback
codex/cpu-ordinal-import
codex/chained-cpu-ranges
codex/cpu-import-call
codex/cpu-direct-call
codex/cpu-leaf-aot
codex/community-project-status
codex/script-state-path-replay
codex/script-state-evidence
codex/bc7-resident-tail
codex/bcpack-mip-tail
codex/bc7-texture-draw
codex/asset-ranges
codex/pixel-constants
codex/pixel-aot
codex/pre-exe-workloads
codex/root-signature-device-coverage
engineering/packed-bvh-leaves
engineering/bvh-build-and-update
engineering/intake-root-roundtrip
community/gpu-check-release
community/english-contributor-entry
gpu-check-v0.1.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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
R0Y00/Xbox2Windows#925
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T17:44:24Z.
Question
How should
tools/pixel_aot.pyrepresentv_cmpx_*, the compares that write their result to EXEC? What is the smallest first stage you would accept?lower()rejects everyv_cmpx_*form today. Indocs/coverage/gfx1013.tsvthey are 95 VOPC (_e32), 95 VOP3 (_e64) and 62 SDWA forms, 252 of the 1,968 forms. #338 listed them among the rejected forms. #651 then landed the stage-one masked region (s_and_saveexec_b64from a tracked comparison, optionals_cbranch_execzto the matching restore,s_or_b64 exec, exec, s[a:b], per-lane selects at the restore). I found no issue or PR since then that coversv_cmpx.I would like to propose, and then implement, the stage below. I won't start without your direction.
Proposed first stage
Accept the region opener that LLVM 15 emits for gfx10.3:
as equivalent to the existing
v_cmp_<op>_<type> vcc, …+s_and_saveexec_b64 s[a:b], vccopener. It would reuse the current region state, body restrictions and restore-time selects.v_cmp_*already lowers (f32, f16, i16/u16, i32/u32, i64/u64 andclassf16/f32), in both_e32and_e64. That is 156 forms. f64 (34 forms) and SDWA (62 forms) stay rejected.s_mov_b64save immediately before thev_cmpx, and the optionals_cbranch_execzonly at the matching restore.v_cmpxuse stays rejected. That includes av_cmpxwith no saved EXEC, and so the whole-program discard pattern.Evidence so far
The ISA definition. The AMD "RDNA 2" ISA reference guide §6.2.2 (p. 42 of 283) says: "All V_CMPX instructions write the result of their comparison (one bit per thread) the EXEC mask." §12.9 "VOPC Instructions" (p. 152) gives e.g.
V_CMPX_GT_F32: EXEC[threadId] = (S0 > S1). The same section 6.2.2 says "A thread only writes a result if the associated bit in the EXEC mask is set to 1." This is the RDNA 2 guide, not a gfx1013-specific document.gfx1013 has no separate destination on
_e64. LLVM 15.0.7llvm-mc -mcpu=gfx1013assemblesv_cmpx_gt_f32_e32 v12, v13,v_cmpx_gt_f32_e64 v12, v13,v_cmpx_gt_f32_e64 v12, s44andv_cmpx_class_f32_e64 v12, 3, and rejects an explicitexecors[0:1]destination on_e64.v_cmpx_gt_f32_sdwaassembles; the DPP form is rejected ("dpp variant of this instruction is not supported").Where LLVM 15 emits it (
llc -O2, wave64, a pixel shader with a non-flattenableif):s_mov_b64 s[0:1], exec/v_cmpx_gt_f32_e32 v0, v1/ … /s_or_b64 exec, exec, s[0:1].v_cmp_gt_f32_e32 vcc, v0, v1/s_and_saveexec_b64 s[0:1], vcc, which #651 already handles.llvm.amdgcn.kill, LLVM 15 emits nov_cmpxfor either target.So LLVM itself doesn't produce this pattern for gfx1013. I don't know whether the compiler that built the gfx1013 programs uses
v_cmpx, or how often. An aggregate count from someone with a local input, like the counts in #711, would set the priority.Inference, not measured. The proposal assumes the inactive-lane rule (a thread writes only if its EXEC bit is set), so the new mask is
EXEC_old & cond. That would make the opener equivalent tos_and_saveexec_b64from a full entry mask. LLVM's gfx10.3 rewrite ofv_cmp+s_and_saveexecintos_mov+v_cmpxdepends on the same equivalence. I haven't checked this on hardware.Questions for you
s_mov_b64save +v_cmpx" as an alternative region opener the right first stage? Or would you rather modelv_cmpxas a general EXEC write first?EXEC_old & conddefinition acceptable, given the ISA text and the LLVM equivalence, or do you want separate evidence?_e32and_e64land together, or one encoding first?Completion condition (for the first stage)
llvm-mc/llvm-objdumpfor gfx1013, using thepixel_aot_check.py binarypath.FORM_COVERAGE_RECORD, runs the cmpx-opened regions on WARP:R32G32B32A32_UINTtarget._e64, a source swap on a non-commutative comparison.v_cmpxwith no preceding save, a save that isn't immediately before it, nesting, f64, SDWA, and a body instruction outsideREGION_ALU.Required environment
The translation and LLVM 15 round trip run on Linux. The WARP draws need Windows (CI on the PR). No physical GPU and no game files.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T17:54:19Z.
Aggregate counts from one local input, for the priority question above. It is the same population as #711: 12,101 PS records. Only counts here; no names, paths or disassembly from the input.
Method.
tools/extract_shaders.py --stage pixel --format native, then decoded withtools/disasm_rdna2.py(whattools/scan_unsupported_shaders.pyuses), ata8a88e1. Cross-check: on a random sample of 300 records, LLVM 15.0.7 (pixel_aot.disassemble, gfx1013) over the same byte ranges gives the samev_cmpxcount (3,764 in both). The Python decoder stops at the firsts_endpgm, so the numbers below are lower bounds.v_cmpx_*v_cmpx_*instructions_e32173,316,_e64885, no SDWAeq_u3253,180 ·lt_f3239,471 ·ne_u3226,800 ·gt_f3221,063 ·lg_f3211,281 ·lt_i324,499 ·gt_u324,468 ·ge_f323,256v_cmpxdirectly preceded bys_mov_b64 s[a:b], execs_mov_b32 s, exec_lo), in 6,677 recordsWhat the first EXEC write after a saved
v_cmpxis (58,198 savedv_cmpx; the wave32_b32/exec_loforms are counted with their_b64equivalents):s_mov_b64 exec, s[a:b](restore)s_andn2_b64 exec, s[a:b], exec(else branch)v_cmpx(nested or chained)s_and_saveexec_*(nested)s_mov/s_andto EXEC from another register)s_or_b64 exec, exec, s[a:b]So this compiler restores with
s_mov_b64 exec, s[a:b], not thes_or_b64 exec, exec, s[a:b]the proposal assumed. 14,450 of the restores, in 4,379 records (36%), have the shape below: no branch in the body other than at most ones_cbranch_execz. I did not check the branch target or whether the body stays withinREGION_ALU.Revised first-stage proposal. Same as above, except that the region closes with either
s_mov_b64 exec, s[a:b]ors_or_b64 exec, exec, s[a:b]naming the saved pair. With a full entry mask and theEXEC_old & conddefinition, the region mask is a subset of the saved mask, so the two restores give the same EXEC. That again rests on the inactive-lane inference, not a hardware measurement. Unchanged from above:_e32and_e64;s_andn2_b64 exec, saved, exec), chainedv_cmpx, f64 and SDWA stay rejected.The else branch and nesting are the next most common shapes, and I'd suggest them as later stages.
Side observation: the 64-bit shifts in #928 are rare in this input. Only
v_lshlrev_b64occurs: 255 records (2.1%), 3,083 instructions.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:30:15Z.
The structured opener fits #651. Please start with VOPC
_e32and already-supported 32-bit comparisons. Allow the immediate EXEC save and exacts_mov_b64 exec, savedrestore. The existing OR restore is also equivalent for lane selection when the inner mask is a subset of the saved mask. Keep the two restore instructions distinct for SCC: MOV preserves it and OR writes it. CMPX does not write VCC. Preserve those observable values or reject readers of any state this profile cannot track.Use the known entry mask and the existing pure per-lane body, no nesting or side effects, and verify any optional EXECZ branch targets the actual restore instruction. Under that supported entry state, intersect the compare result with the incoming EXEC. General partial-entry masks, chained CMPX, wave32 save/restore, kill/else, and _e64 can follow separately if independently validated. The 4,379 records are structural candidates until the target and body checks run.
Please include LLVM 15 gfx1013 binary round-trips and mixed/empty/full bit-exact WARP cases. Keep the reversed predicate, ignored mask, wrong branch target, overwritten save pair, and unsupported body controls. WARP establishes the translated behavior of the source-built fixture.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T18:46:07Z.
Taking the first stage you scoped above. It's up as #957: VOPC
_e32v_cmpxon the binary32 and 32-bit integer predicates (32 forms) with the immediates_mov_b64save; thes_mov_b64ands_or_b64restores kept distinct for SCC; VCC untouched; the optionals_cbranch_execzchecked against the actual restore.Re-measured with those rules, as you asked, on the same local input (aggregates only): 3,719 records have the save +
v_cmpx+ restore shape, but only 152 regions in 112 records (0.9%) also pass the existing #651 body rule. The rest are blocked mainly by scalar loads,s_nop, conversions andv_rcpin the body. Details are in the PR.The WARP draws will run for the first time in that PR's CI.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T18:51:09Z.
Proposal for the next stage, which I'd like to take after #957: widen the masked-region body. This is about the body, not the opener.
The #651 body rule (
REGION_ALU:v_mov_b32and binary32add/sub/subrev/mul/min/max) is what blocks almost all real regions. Same local input as above (aggregates only), counting the regions #957 accepts structurally: save + f32/i32/u32_e32v_cmpx+ restore of the same pair. That is 10,827 regions in 3,719 records.I added body instructions one at a time, greedily, and leave out any region containing a further branch (nesting stays out of scope):
REGION_ALUv_fmac_f32_e32,v_mul_legacy_f32_e32v_cvt_f32_ubyte2_e32v_rcp_f32_e32,v_rsq_f32_e32v_cvt_f32_ubyte1_e32,v_fma_f32,v_sqrt_f32_e32,v_med3_f32,v_mul_legacy_f32_e64v_mac_f32_e32,v_mad_f32,v_cvt_f32_ubyte0/3)A record also needs everything outside its regions to translate, so these count regions, not translatable shaders.
Proposed stage 2. Admit to the region body the per-lane binary32 VALU forms that
lower()already handles outside regions, each through its existing lowering and the existing restore-time select:v_fmac,v_macv_mul_legacy(e32/e64)v_cvt_f32_ubyte0..3v_rcp,v_rsq,v_sqrtv_fma,v_mad,v_med3Like the current body, they write only VGPRs, read only VGPRs, SGPRs and constants, and have no side effects or traps. A false lane's speculated value, including a NaN or infinity from
rcp/rsq/sqrtout of domain, is discarded by the select. The accumulator forms (fmac/mac) read their destination, so a destination still conditional from an earlier region would reject, as reads do today.Out of this stage:
s_mov_b32,s_waitcnt, scalar loads). They run regardless of EXEC but are skipped with the region bys_cbranch_execz;ds_swizzle;Questions for you:
I won't start until #957 has your verdict, so the two don't overlap.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:18:16Z.
#957 is merged, thanks. Starting stage 2 as proposed above. The body set is exactly the listed per-lane binary32 forms, in the encodings measured:
v_fmac_f32_e32,v_mac_f32_e32,v_mul_legacy_f32_e32/_e64,v_cvt_f32_ubyte0..3_e32,v_rcp/v_rsq/v_sqrt_f32_e32,v_fma_f32,v_mad_f32andv_med3_f32. Each form gets its own in-region draw: inner and outer values differ per lane, and a wrong reference that ignores the mask must mismatch. Please redirect if you'd prefer a different set or one draw per family.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:19:54Z.
The scoped stage one from this thread merged in #957. The translated source-built cases passed on WARP and RTX 4060 Laptop, and LLVM 15 round-tripped the gfx1013 binary fixtures. The tests cover mixed, empty and full masks, both restore forms, genuine skip targets and wrong-predicate/wrong-mask controls. This closes the VOPC e32 32-bit structured region stage. General EXEC writes, wave32 save/restore, nesting, class forms and e64 remain separate.