Repository navigation
Conversation
…lowering Compact five scalar/half conversion paths in the direct RDNA2 -> DXIL emitter without changing RDNA2 rounding or NaN semantics: - Default binary16 RNE (`lower_wide.rs`): round subnormal magnitudes with one native RNE addition at 0.5 (2^-24 binary32 ulp) and round normal significands with a retained parity bit (51 -> 21 SSA ops, -72,820 B across 329 validated shaders). - Directed binary16 rounding (`lower_wide.rs`): derive directed results from the nearest binary16 value by comparing widened unsigned magnitude bits (-13,340 B). - `f16_rtz` and `cvt_u32` (`prelude.rs`): drop redundant `IsNaN` checks and the zero-magnitude guard in `f16_rtz` via unordered `<= 0.0` / ordered `>` comparisons (-51,888 B combined; builds on @ramon-victor's xcl-dev#2289). - Normalized D16 buffer loads (`lower_mem.rs`): scale the recovered magnitude into half-significand units and round with a 32-bit unsigned quotient instead of 64-bit division (-8,544 B). Combined offline savings: ~146.6 KB across 329 validated shaders (0 validation errors). Adds disassembly/validation unit tests in `core_tests.rs` and `lower_mem.rs`. Co-Authored-By: Codex (GPT-6) <noreply@openai.com> Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
Reduce emitted DXIL instruction count and container size for buffer accesses and formatted stores in `crates/xcl/src/gpu/dxil/lower_mem.rs`: - Formatted stores: pack components by the actual GFX10 dword layouts instead of scattering every component into four words (-63,872 B), and rotate dynamic format four-component stores through one numeric encoder loop (-146,160 B). - Fragmented byte stores: select the descriptor-heap window once before lowering fragments (-114,308 B), and emit runtime byte-count stores as a bounded word loop while keeping straight-line stores for constant counts (-77,400 B main / -72,780 B auxiliary dispatch pieces). - Multiword buffer loads/stores: share one remaining byte limit across dwords (-10,640 B). - Scalar flat reads: check the carried window validity once instead of per carry arm (-2,992 B). - Buffer address windows: reuse the 32-bit lane-stride product when IDXEN is clear instead of emitting a wide multiply (-11,248 B). Combined offline savings: ~426.6 KB main (+72.8 KB auxiliary) across 329 validated shaders (0 validation errors). Adds focused unit/validation tests in `lower_mem.rs`. Co-Authored-By: Codex (GPT-6) <noreply@openai.com> Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
|
Review (head 4f39cd1, diff read, not a merge-check):
Fine: By reading, the new RNE sequence matches what main computes. The subnormal rounding through the 0.5 add relies on f32 AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
merge-check |
|
Thanks @Foniass and @vasanex for the review and merge-checks! Leaving |
bmjask
left a comment
There was a problem hiding this comment.
Review of 4f39cd19: 1 finding(s) (1 medium), most severe first.
- Medium
crates/xcl/src/gpu/dxil/prelude.rs:21: Not certain about this one, since it depends on how drivers treat float compares in these modules:cvt_u32drops the explicitdx.op.isSpecialFloatIsNaN check and relies on the unorderedfcmp ulebeing true for NaN, andf16_rtz(.... (inline)
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| let z = self.fc(0.0); | ||
| let le = self.fcmp(Pred::FOLe, f, z); | ||
| let low = self.lor(n, le); | ||
| let low = self.fcmp(Pred::FULe, f, z); |
There was a problem hiding this comment.
Medium: Not certain about this one, since it depends on how drivers treat float compares in these modules: cvt_u32 drops the explicit dx.op.isSpecialFloat IsNaN check and relies on the unordered fcmp ule being true for NaN, and f16_rtz (prelude.rs:69) drops its isnan(f) guard and relies on the ordered fcmp ogt being false for NaN. These modules don't set DisableMathRefactoring by default. If a driver treats the compares as NaN-free, v_cvt_u32_f32 on NaN returns ftoui(NaN) (driver-defined) instead of 0, and v_cvt_pkrtz_f16_f32 or a 16-bit FLOAT store turns a NaN encoded as 0x7C01/0xFC01 into ±infinity. The HLSL path still has both isnan guards, so the two paths can disagree on NaN inputs. Keeping the explicit IsNaN checks costs a few instructions and removes the dependence.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
|
Thanks @bmjask for checking this — leaving
|
Compacts emitted direct-DXIL IR for binary16/float/D16 conversions, formatted buffer stores, and buffer address/bounds lowering across 4 files (
+447/-242, 2 commits), without changing RDNA2 rounding, NaN, or bounds semantics.What is in it
lower_wide.rs,prelude.rs,lower_mem.rs,core_tests.rs):f32_to_f16_rnesubnormal magnitudes with a single native RNE add at0.5(2^-24binary32 ulp) and round normal significands with a retained parity bit (51 → 21SSA ops;-72,820 Bacross 329 validated shaders).f32_to_f16_rmrounding fromf32_to_f16_rneby comparing widened unsigned magnitude bits (-13,340 B).IsNaNchecks incvt_u32(fcmp ule <= 0.0) andf16_rtz(orderedfcmp ogtis already false for NaN and zero halves, also dropping the zero-magnitude guard) (-51,888 Bcombined; builds on @ramon-victor's Recompiler: drop redundant IsNaN checks in direct DXIL cvt_u32 and f16_rtz #2289, which is currently conflicting onmain).-8,544 B).lower_mem.rs):-63,872 B), and rotate dynamic-format four-component stores through one numeric encoder loop (-146,160 B).-114,308 B) and emit runtime byte-count fragmented stores as a bounded word loop while keeping straight-line stores for constant counts (-77,400 Bmain,-72,780 Bauxiliary dispatch pieces).-10,640 B), check the carried scalar flat-read window validity once (-2,992 B), and reuse the 32-bit lane-stride product in buffer window calculations whenIDXENis clear (-11,248 B).~146.6 KBfrom Commit 1 +~426.6 KBmain /72.8 KBauxiliary from Commit 2) across the individual before/after measurements on 329 validated shaders.4f39cd191vsmain 1c8b55147):1267vs1387frames shown (91.3%),60 60 61presents per 2 s, peak commit15112 MBvs17480 MB(-2368 MB/-13.5%),0device removals,0crashes.Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5(debug + release).scripts/test.ps1(cargo build --workspace,cargo bench -p xcl --bench '*' -- --test,cargo test --workspace -- --test-threads=4): 2921 passed, 0 failed, 51 ignored across all 43 test targets (24 SKIPPED GPU tests on this adapter: 22no wave64, 2no heap windows).gpu::dxil::core_testsandgpu::dxil::lower_mem::stage_guard_tests(all passing with DXC1.9.2609.5validation).cargo build --release -p xcl: clean (39 warnings, 0 new vsmain).Regression run
Baseline (
main):PR head:
Not tested
XCL_HEAP_WINDOWS=1GPU tests (2 skipped under defaultscripts/test.ps1).main+ this PR alone (individual 329-shader corpus byte savings were recorded during the offline validation sweep before cherry-picking).AI use
GPT-6) wrote the individual binary16/float/D16 and buffer/store lowering improvements and unit tests during the offline DXIL size sweep.Gemini 4 Neon) audited and cherry-picked themain-independent subset ontomain, adapted the directed binary16 unit test for inlinef32_to_f16_rne, rancargo build --release,scripts/test.ps1, and the 60 s smoke run, and drafted this description.