Skip to content

[0.6.6] L post recon (D3D12): history encode through the driver's conversion fold, with a start-up guard - #236

Draft
phantoslayer21 wants to merge 2 commits into
mainfrom
kspeed/l-post-fold
Draft

phantoslayer21 wants to merge 2 commits into
mainfrom
kspeed/l-post-fold

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Status: 0.6.6 (not for 0.6.5). Draft, not to be merged in this form. The fold is dropped for 0.6.5: Model L's speed for 0.6.5 is #231 + #240 as merged; this PR's extra -0.035 ms is given up.

Review findings

  • Open (P1, final re-check of head 1e03993): the guard runs the fold PSO with the params' pad1 non-zero (side output on), while real frames run it with pad1 = 0. The side stores consume the six conversion inputs, so the shader the driver compiles has two paths, and nothing establishes that the conversions executed with pad1 = 0 are the ones the guard tested (a driver may lower the six conversions differently per path). RGA shows the same six fold sites, but that is not the installed driver's lowering. References: clean/dx12/kernels/l_post.hlsl (the P_pad1 != 0 side output), clean/runtime/device_d3d12.cpp (the guard), clean/runtime/runtime.cpp (PostParams p = {} in frames).
  • Fixed in this PR during review: the separate control PSO was replaced by the own-value check in the same PSO; six single-site negative controls (LP_MUTSITE) on the GPU; bounded guard waits (a timeout fails device creation); the edge runner's mutant legs require a successful run with full outputs.
  • Known limit outside this PR: the existing borrowed-device driver probe runs before the guard with an unbounded wait.

For 0.6.6

Either an encode whose correctness does not depend on the driver's fold, or a guard that checks the output of the pad1 = 0 path itself (the exact PSO and path real frames run).


Follow-up to #231: Model L's history encode in l_post_recon_p12 (D3D12) through the driver's conversion fold, the part #231 left out. The fast port runs only after a start-up guard on the device has shown that the driver folds the encode in the real post shader. Otherwise the exact port from #231 runs.

What changes

  1. Two ports of l_post_recon_p12 (clean/dx12/kernels/l_post.hlsl, hlsl/l_post_encode.hlsli):

    The fold port has a self-test side output. When the params' pad1 word is non-zero (it is zero in every frame; the same compiled shader), the port also stores each pixel's three FP32 conversion inputs xe at that address.

  2. Build check (build_dx12.py): isa= rules count only the x * literal + 0 sites. The fold port must have exactly six v_fma_mixlo/mixhi_f16 .., 0x3dddf184, 0 (three channels, two rows) and no s_round_mode.

  3. Start-up guard (clean/runtime/device_d3d12.cpp). Every step must pass; otherwise, or on any error, the no-fold port runs:

    1. the probe l_fold_probe on adversarial inputs of the shared encode expression, against expected bytes from exact rationals (clean/runtime/fold_probe.h, gen_fold_probe.py);
    2. a self-test of the real post shader on one crafted 32 x 16 frame (clean/runtime/fold_selftest.h, gen_fold_selftest.py): the fold port, with its side output on, and the no-fold port, each with its outputs pre-filled with its own sentinel. The fold port's raw output bytes (full history, reduced history, display) must equal the no-fold port's. From the fold port's own values in the same PSO, its stored inputs xe and its stored history codes, each of the six encode sites (row of the pair x channel) must pass two checks:
      • (a) at least 8 inputs are FP32-product ties that a second rounding gets wrong;
      • (b) every stored code equals RN16(xe x kEncK), computed exactly on the host (the product is exact in a double; one rounding to FP16).

    The frame makes each full-history value exactly the render colour (render size = output size, jitter 0, reset, exposure 1, post scale 0, codes and kernel shape 0). Each history code is therefore the encode of a crafted value, with log2 computed by the shader. Per site it holds 13 FP32-product ties that a second rounding gets wrong. Each tie is placed at predicted-log2 offsets -8 to +8 ulp, so a device log2 up to 8 ulp off still lands on them. The frame also holds zero and FP16-subnormal products, the encode floor, and extra ties among negative products. Check (a) counts the ties among the values this device actually fed the conversion, whatever its log2 returned.

    Every queue wait of the guard is bounded (10 s). A timeout fails device creation, and its allocations are kept rather than freed under a running queue. The result appears once in the runtime's ready line. The hybrid device never takes the fold port.

  4. Tests:

    • clean/dx12/tests/test_fold_probe.py pins both headers to their generators and checks the ports and ISA rules. Its shift test moves every predicted log2 by the same e ulp, for each e from -8 to +8, and asserts at least N = 13 detecting ties per site.
    • clean/l/runner/l_post_edge_check.py gains the fold leg (the fold port must be selected) and the no-fold leg (WG_TEST_FOLD_PROBE_FAIL=1).
    • LP_MUTSITE 1..6 are single-site negative controls (never shipped): site k-1 = 3 x row + channel is rounded twice, the other five sites keep the fold.

Results

  • RGA (fold port with the side output, against the earlier fold port without it): the same six sites, v_fma_mixlo_f16 / v_fma_mixhi_f16 v#, v#, 0xf184, 0 (literal 0x3dddf184), no s_round_mode. The side output adds two buffer_store_b96 (one per row) and 23 VALU. Each store writes exactly the three registers its row's fold instructions read (row 0: v11-v13, row 1: v15-v17). The no-fold port has no such site. The build's ISA check passes.

  • Guard on the GPU (RX 9070 XT): "conversion-fold probe and self-test passed (detecting ties per site 22/22/19/18/18/20, every code the one-rounding encode): the fold ports run".

  • Six single-site mutants (LP_MUTSITE 1..6, each with exactly five fold sites in its ISA): each makes the guard choose the no-fold port on the GPU. The fold port differs from the no-fold port in 22, 22, 20, 18, 18 and 20 bytes. Applied offline to each run's dump, the own-value check finds wrong codes at exactly the mutated site (22, 22, 19, 18, 18, 20 values, its detecting ties) and none at the other five.

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

    • fold port: 13/13 identical;
    • no-fold port alone: 13/13;
    • default kernels vs the stages run: 13/13;
    • post against Model L's reference: passes on every frame and over the run.
  • LDR leg: 13/13.

  • Edge check (14 sizes x 12 motion kinds): fold port 672/672 identical, no-fold port 168/168, 0 differing pixels in each edge band, the counter's expectations met, both hs mutants and the half-grid control caught, HIP vs the reference 336/336.

  • Timing on the direct route (test_interop_d3d12 hipbench, executor dx12), 1440p Quality, synthetic L model, 5 interleaved rounds. The base is the same runtime library with main's kernels:

    base this PR
    TOTAL 3.8605 ms 3.833 ms
    post part 1.136 ms 1.098 ms

    Paired rounds: -27.5 to -46 us, median -35 us. Every timed run logged the guard passing.

Tested

  • RGA, the guard and its six single-site mutants on the GPU, the frame check (fold and no-fold), the LDR leg, the edge check, the timing above, and the CPU tests test_fold_probe.py, test_post_edge_cases.py, test_kernel_sets.py.

Not tested

  • Other drivers or GPUs, an in-game run, a real queue timeout during the guard, and the start-up cost of the guard. The guard compiles two post ports and runs three dispatches at device creation.

…fold, guarded by a start-up probe, a differential self-test of the real ports and a per-site sensitivity control

- l_post_recon_p12 gets three ports: needs=fold (the encode as mad(log2, kEncK, 0) into the RNE conversion, which the
  driver folds into v_fma_mixlo/mixhi_f16), needs=nofold (round to odd, exact on any driver) and needs=control (the
  encode rounded twice, never selected to run)
- start-up guard (device_d3d12 fold_probe), all steps must pass, else the no-fold port runs: l_fold_probe against
  exact expected bytes; the fold and no-fold ports on a crafted frame (fold_selftest.h: per encode site 13 FP32-product
  ties a second rounding gets wrong, each at predicted-log2 offsets -8..8 ulp) with equal raw bytes; the control port
  differing from the no-fold port at each of the six sites; bounded queue waits (a timeout fails device creation)
- build_dx12: needs=fold|nofold|control, isa= rules with literal-tied site counts (fold: six kEncK sites; control:
  none)
- l_post_edge_check: fold and no-fold legs; test_fold_probe: generated headers, the -8..8 ulp shift test (N = 13
  per site), ports and ISA rules

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…single-site mutants (review fixes)

- the fold port stores each pixel's three FP32 conversion inputs when the params' pad1 holds a side buffer (0 in
  every frame; the same compiled shader); RGA: the six v_fma_mixlo/hi_f16 .., 0x3dddf184, 0 sites keep their form,
  the side store writes exactly the registers they read, no s_round_mode
- the start-up guard: fold and no-fold ports equal in raw bytes, and from the fold port's own stored inputs and codes,
  per site (row of the pair x channel) at least 8 FP32-product ties a second rounding gets wrong and every code the
  exact one-rounding RN16(xe kEncK) computed on the host; else the no-fold port
- the separate control port is removed (needs=control gone from the build, the devices and the tests)
- LP_MUTSITE 1..6: one site (3 row + channel) rounded twice, the other five folded (negative controls, never shipped)

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21 phantoslayer21 changed the title L post recon (D3D12): history encode through the driver's conversion fold, with a start-up guard [0.6.6] L post recon (D3D12): history encode through the driver's conversion fold, with a start-up guard Nov 15, 2026
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