Skip to content

L post recon (D3D12): fewer VALU in the tap, history and encode paths, byte-identical, with a guarded conversion fold (draft) - #231

Merged
phantoslayer21 merged 9 commits into
mainfrom
kspeed/l-post-fable
Nov 15, 2026
Merged

phantoslayer21 merged 9 commits into
mainfrom
kspeed/l-post-fable

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Draft. Speed change to Model L's reconstruction kernels (D3D12 port, wave32), byte-identical to HIP on any driver: no step depends on a driver fold. The history-encode fold that an earlier revision of this PR carried, with its start-up probe and self-test, moved to a follow-up PR.

What changes

clean/dx12/kernels/l_post.hlsl, shared by the four post kernels (l_post_recon, l_post_recon_p12, and their LDR forms):

  1. nz: each FP16 product opqh(a * b) becomes mulh(a, b) = fma(a, b, -0) with an opaque -0: one instruction instead of a multiply plus v_xor_b16, and the driver cannot fuse it into the following add. RN16(a b + -0) = RN16(a b) for every non-NaN pair, zeros included.
  2. ix: the staged LDS index without per-tap multiplies; integer identity.
  3. hs: an interior fast path for the history sample (span loads, same texels, same sums and mad order), as Model M's history_cr_span. It is taken only when every sampling lane's 4 x 4 footprint is inside the history, and only for a history of at least 4 x 4. Below that size the unsigned bounds would wrap, so smaller images take the clamped path.
  4. ml: and() / or() in place of short-circuit && / ||, and opq(x) * k as fma(x, k, opaque -0) (as Model M's post).
  5. sl: Model M's flag form of the candidate selection; the same selected values.
  6. dp: Model M's wave-level skip of the decode polynomial (the exponential for every lane, the polynomial only when some lane of the wave needs it; the same per-lane select).

The history encode is unchanged: the round-to-odd product into the driver's conversion, exact without any fold.

Tests:

  • l_frame_check.py adds two frames whose colour alternates dark and bright blocks of 8 columns, so one wave holds lanes on both sides of a per-lane branch. Without them, a wrong wave-level test in item 6 went undetected.
  • clean/l/runner/l_post_edge_check.py (new) runs the four post kernels at 14 history sizes (1 x 1 to 97 x 35: sides below 4, odd sizes, a tile's interior boundary in the middle of a wave) and 12 motion kinds (random; every lane at the centre or just inside each edge; the fast path's footprint boundary from inside and outside; waves that mix inside and edge lanes). It compares D3D12 with HIP raw bytes, reports the full history per edge band, checks HIP against Model L's reference, and counts the waves taking the fast path in a test build (LP_HSCOUNT) against expectations simulated from the kernel's grid. Every leg starts from an emptied output folder and counts only when the replay exits 0 and every case wrote every output at full size, so a failed mutant run is never taken as caught.
  • clean/dx12/tests/test_post_edge_cases.py (CPU): the guarded predicate equals the footprint test at every size from 1 x 1, the old one reads outside images with a side below 4, and each edge-check kind samples where it says.
  • build_dx12.py --define builds such test variants. LP_MUT 1, 2, 4 ... 9 are negative-control mutants (never shipped; 8: the fast path's predicate always false, 9: the predicate without its size guard).

Results

  • Frame check (l_d3d12_own_post_check.py, 13 frames incl. the mixed ones; raw bytes against the HIP frame, sentinels, record-level negative controls):

    • D3D12 vs HIP: 13/13 frames identical;
    • default kernels vs the stages run: 13/13;
    • post against Model L's reference: passes on every frame and over the run (history and display).
  • LDR leg (l_frame_check --ldr, D3D12 vs HIP): 13/13.

  • Edge check:

    • D3D12 vs HIP, raw bytes: 672/672 cases identical, 0 differing pixels in each of the four edge bands; every leg complete;
    • counter: all 140 "must enter" and 500 "must not enter" expectations met;
    • mutant 8 caught by the counter (140 expectations fail); mutant 9 caught (9 cases differ, at sizes with a side of 3); a half-grid control caught;
    • HIP vs the reference: 336/336 cases pass (the cases under 100 pixels judged together).
  • Mutants of the frame check (earlier revision, same code for these items):

    mutant result
    nz: wrong factor 0/13 frames identical
    ix: wrong texel 0/13
    hs: wrong span 2/13
    ml: wrong bound 2/13
    dp: wrong wave test 11/13 (caught by the mixed frames)
    sl: wrong candidate 2/13
  • Timing on the direct route (test_interop_d3d12 hipbench, executor dx12, runtime timing log), 1440p Quality, synthetic L model, 5 interleaved rounds. The base is the same runtime library (built from this branch; no runtime code changes) with main's kernels:

    base this PR
    TOTAL 3.987 ms 3.8815 ms
    post part 1.262 ms 1.1405 ms

    Paired rounds: -79.5 to -123 us, median -110 us.

Tested

  • The frame check on HIP and D3D12 (HDR and LDR), the edge check with its counter and mutants, the frame-check mutants above, the timing above, and the CPU tests clean/dx12/tests/test_post_edge_cases.py and test_kernel_sets.py.

Not tested

  • An in-game run, other resolutions in the timing.

…LDS index without per-tap multiplies, history encode through the conversion fold

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…loads, same texels and sums)

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…the driver's conversion fold with a start-up probe and a no-fold port, an ISA check in the build, mixed-lane frames in the L frame check

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21 phantoslayer21 changed the title L post recon (D3D12): fewer VALU in the tap and history paths, byte-identical (draft) L post recon (D3D12): fewer VALU in the tap, history and encode paths, byte-identical, with a guarded conversion fold (draft) Nov 15, 2026
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…/ no-fold post ports, history fast path guarded for images under 4 x 4, edge-size check

- device_d3d12: after l_fold_probe, the native device runs l_post_recon_p12's fold port and no-fold port on one
  crafted frame (clean/runtime/fold_selftest.h from gen_fold_selftest.py: FP32-product ties of both sides on each of
  the six encode sites, zero and FP16-subnormal products, the floor) and compares the raw output bytes; the fold
  ports run only when both steps pass (fail closed, also for a fold port without a self-test)
- build_dx12: isa= terms <op>@<literal> count only the x * literal + 0 sites; the fold port's rule is the six kEncK
  sites; --define for test variants
- l_post.hlsl: the interior predicate requires P_dw >= 4 and P_dh >= 4 before its unsigned tests; LP_MUT 8 / 9
  mutants and the LP_HSCOUNT test counter
- l_post_edge_check.py: the four post kernels and the no-fold port at 14 sizes (1 x 1 ... 97 x 35) and 12 motion
  kinds, D3D12 against HIP raw bytes with per-edge bands, the counter, the mutants and the oracle
- kernel_replay prints the device note

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…o-fold port is the only port; edge check legs must be complete

The fold, its start-up probe and self-test, the needs= / isa= port selection and their tests move to a follow-up
branch. l_post_recon_p12 is one port again: the round-to-odd history encode, exact on any driver. The edge check
drops its fold legs, empties each leg's output folder before the run, and counts a leg (mutants included) only when
kernel_replay exits 0 and every case wrote every output at full size.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 15, 2026 07:28
@phantoslayer21
phantoslayer21 merged commit cddc286 into main Nov 15, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the kspeed/l-post-fable branch November 15, 2026 07:35
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.

1 participant