Repository navigation
Recompiler: direct DXIL folds 64-bit and float constants - #1923
Closed
nFaktorial wants to merge 1 commit into
Closed
nFaktorial wants to merge 1 commit into
nFaktorial wants to merge 1 commit into
Conversation
Module::optimize left every i64 instruction alone so that the Int64Ops
shader flag, set while building, kept matching the code. The memory
window address math of the direct translator is i64 (zext, shl, or,
add of an offset, lshr, trunc), and much of it has constant operands,
so it reached the driver as written.
i64 instructions are now folded and removed like 32-bit ones, and
Shader::infer_type_features drops Int64Ops when no i64 instruction is
left: the validator refuses the flag without one ("Flags must match
usage"). Doubles stay as they were.
Float constants fold too: a bitcast of a 32-bit constant is the
constant of the other type (registers are i32, so every float literal
arrives as a bitcast), and fcmp of two constants is decided at build
time, except for denormals, which a driver may flush. A legacy multiply
by a literal loses its "is the literal zero" compare.
Measured on 2 989 programs of a retail shader pack (xcl shaders
--direct --sample 3000 --seed 7 --split 1 --windows 4, against main
689f2db): DXIL 1.41 % smaller in total (median -1.30 %, 2 913 smaller,
58 up to 0.64 % larger); all 3 000 validate with DXC 1.9.2602. On a 292-program sample (seed 1): 2.9 % fewer instructions
(3 011 771 instead of 3 102 808 in the dxc -dumpbin listings), lines
with an i64 101 495 instead of 153 220 (on main 177cd40).
TRANSLATOR_VERSION goes to 8: the emitted containers change.
Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
NVIDIA run: RTX 3070 8 GB (Ampere, split wave64), driver 616.56, Windows 11, debug,
Overlap with #1906 is proposed on #1607. AI-assisted (Claude Code). Synthetic tests only. |
Contributor
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The direct DXIL backend's optimizer (
Module::optimize) skipped every i64 instruction, so that theInt64Opsflag set while building kept matching the code. The memory-window address math is i64 (zext,shl,or,addof an offset,lshr,trunc), and much of it has constant operands, so it reached the driver as written. Float literals also stayed asbitcast i32 <constant> to floatinstructions. Part of #1269.i64 instructions are now folded and removed like 32-bit ones, and
Shader::infer_type_featuresdropsInt64Opsonce no i64 instruction is left (the validator refuses the flag without one: "Flags must match usage"). Doubles are unchanged. A bitcast of a 32-bit constant becomes the constant of the other type, andfcmpof two float constants is decided at build time, except for denormals, which a driver may flush. A legacy multiply by a literal loses its "is the literal zero" compare.On a retail shader pack, against
main689f2db(xcl shaders --direct --sample 3000 --seed 7 --split 1 --windows 4): DXIL 1.41 % smaller in total over 2 989 programs (median −1.30 %; 2 913 smaller, 58 up to 0.64 % larger). On a 292-program sample: 2.9 % fewer instructions (3 011 771 instead of 3 102 808 in thedxc -dumpbinlistings), lines with an i64 101 495 instead of 153 220. A small, safe cut; it does not change the per-lane work or the EXEC guards.What is in it
Recompiler: direct DXIL folds 64-bit and float constantscrates/xcl/src/gpu/dxil/module/opt.rs: i64 folding and dead-code removal (doubles excluded as before), float constant bitcasts and compares, alow_bitshelper for 64-bit masks.crates/xcl/src/gpu/dxil/shader.rs:infer_type_featuresremovesInt64Opswhen no i64 instruction remains.crates/xcl/src/gpu/dxil/ops_tests.rs:constant_i64_and_float_operations_fold_awaychecks the listing (no i64 left, the literal's compare gone, the denormal's kept), the validator and the GPU results. Without theshader.rschange the validator rejects it ("Flags must match usage").crates/xcl/src/gpu/dxil/kernel.rs:TRANSLATOR_VERSION7 → 8 (the containers change).Tested
df10025.cargo test --workspace -- --test-threads=4with the SDK's DXC 1.7.2308.16: 976 passed, 0 failed, 45 ignored; 88SKIPPED, 65 of them the validation step (validator 1.7 < 1.8).XCL_DXC_DIRset to DXC 1.9.2602.17, so the DXIL tests run their validation step: 976 passed, 0 failed, 45 ignored; 23SKIPPED: 18no wave64, 3 per-lane f16 /V_CVT_F16_F32refusals,no heap windows, and the PSO measurement (Developer Mode off).xcl shaders --direct ... --validateover the 3 000-program sample: 0 validator failures (DXC 1.9.2602.17).XCL_DIRECT_DXIL=1, an earlier pair of 120 s runs of the same tree (main689f2dbagainst this change): both built the same three compute pipelines, with 3.2 %, 1.7 % and 1.9 % less DXIL here (80 520 → 77 928, 27 500 → 27 032, 38 888 → 38 168 B), 1 776 against 1 772 frames, no device removal or crash.Regression run
main:This PR:
Both runs:
XCL_DIRECT_DXIL=1 XCL_PSO_PRELOAD=0, A pressed every 4 s from 20 s, 120 s. In these two the title took the first A press only after 100 s, so they stay in its first menus (mainbuilt one compute pipeline, this branch none).Not tested
CreateComputePipelineState) of the smaller DXIL was not measured; the three title pipelines are too few to time.no wave64).AI use
🤖 Generated with Claude Code