Skip to content

Model L: LDR reconstruction (HIP + D3D12) on every route; no Model M post route for Model L - #176

Merged
phantoslayer21 merged 6 commits into
mainfrom
model-l/lpost-ldr
Nov 14, 2026
Merged

phantoslayer21 merged 6 commits into
mainfrom
model-l/lpost-ldr

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Model L's reconstruction in LDR, HIP and D3D12, on every route the HDR own post has. Model M's post route for Model
L is removed: the only fallback is a refusal with the reason.

What changes

HIP (clean/l/kernels/l_post.hip)

  • l_post_recon_ldr / l_post_recon_p12_ldr: the LDR form, following spec preset L part 3 item 6, Q2 and Q1's LDR
    column:
    • identity transfer: the colour feature is h(colour); no decode of the history candidates or of C;
    • no exposure: the exposure pair is not read (e = e_prev = 1);
    • full history h(H^);
    • the display image is the output stage's unpack of the 11 / 11 / 10-bit codes: code = floor(clamp(fused(O^ N + 1/2),
      0, N)), stored h(code RN32(1/N)), with N = 2047, 2047, 1023 and NaN giving code 0;
    • reduced codes rint(clamp(mean, 0, 1) 1023).
  • l_post_filter_ldr (FP32) and l_post_filter_ldr_h (RGBA16F rows, pi folded in): the LDR output stage (Q2). It is
    Model M's 5-tap filter rows and passes (post.hip's filter_row_c1, lz5, unchanged) without the [1e-4, 3] clamp,
    the decode and the exposure.
  • The HDR kernels' ISA is unchanged: l_post_recon and l_post_recon_p12 are instruction-identical to main's (only
    end-of-code padding moves). post.hip is untouched.

D3D12, byte for byte

  • l_post.hlsl (LP_LDR): l_post_recon_ldr, l_post_recon_p12_ldr.
  • post_filter.hlsl (WG_FILTER_LDR): l_post_filter_ldr and the direct form l_post_filter_direct_ldr.
  • HIP folds the display store into one rounding (v_fma_mixlo_f16). The spec rounds twice (f32 product, then FP16).
    For every code 0 … N the two give the same FP16 value (checked for all 3072 codes), so the port may use either.
  • The HDR DXILs (l_post_recon, l_post_recon_p12, w64/post_filter_c1_s4, l_post_filter_direct) and Model M's
    DXILs are unchanged.
  • kernel_sets.json regenerated: Model L +4 kernels, Model M unchanged.

Runtime (clean/runtime/runtime.cpp)

  • Model L reconstructs with its own kernels only, HDR and LDR, on HIP and on native D3D12: the staged route, the direct
    route and the fallback frames (l_coef + l_post_recon[_ldr]).
  • HIP no longer refuses LDR for Model L. Its output copy (interop RGBA16F rows) uses l_post_filter_ldr_h.
  • LDR runs only the output stage its kernels implement (review P1): l_post_filter_ldr is the default filter's
    geometry (40 columns x 4 row pairs, 3 x f32 RGB), l_post_filter_ldr_h its RGBA16F rows for the output copy.
    Any other selection is refused at create, on every backend and for the output copy too (l_ldr_filter_unfit):
    another filter kernel or geometry (WG_FILTER_KERNEL / filter_kernel), an RGBA16F filter output (_o16), or
    output_filter=quality5 / quality9 / original. The error line names the selection and why: "Model L, LDR
    colour: its output stage is l_post_filter_ldr (the default filter's geometry, 40 columns x 4 row pairs, 3 x f32 RGB;
    RGBA16F rows for the output copy); the selected filter (...) has no LDR form".
  • No Model M post route for Model L:
    • l_post=m is refused: "Model L has no Model M post route (its reconstruction is l_post_recon[_ldr] only)".
    • l_post=own is kept as a no-op (existing scripts pass it).
    • Where Model L's route cannot run, creation is refused with the reason. l_post=m is not kept as a test switch:
      no check needs it.
      The old A/B record stays in clean/l/records/l_default_post_real_weights.json, and
      l_default_post_check.py still judges an old A record if one is present.
  • The l_own_post_fits rule, LDR included:
    • Model L's route runs on the default pack12 post route only: p12, the post_recon2_r_band_p12 / post_filter_c1_s4_band
      route, and no RGBA16F filter output.
    • Its D3D12 ports must be present:
      • HDR: l_post_recon_p12, l_post_recon, l_coef, w64/post_filter_c1_s4;
      • LDR: l_post_recon_p12_ldr, l_post_recon_ldr, l_coef, l_post_filter_ldr;
      • on the direct route also l_direct_color and l_post_filter_direct[_ldr].
    • Otherwise: "Model L on native D3D12 (HDR|LDR): ; Model L has no other reconstruction (no Model M post route)".
  • Test proving no M-post path: test_l_runtime_frame.D3D12.test_no_model_m_post_route.
    • Every route is traced: HDR and LDR, HIP and native D3D12, pack12 and fallback frames. Each frame launches Model L's
      reconstruction and no Model M post kernel (post_recon*, post_tf*, post_fused*, post_prep, pmo/*, *_band).
    • l_post=m is refused.
    • Each missing port (HDR and LDR sets) is refused by name.
    • Another of Model M's filter routes is refused.
  • Test for the LDR filter selection: test_l_runtime_frame.D3D12.test_ldr_filter_selection.
    • On HIP in LDR, post_filter (128 columns, S=8), post_filter_c1_s16 and post_filter_c1_s4_o16 and
      output_filter=quality5 are each refused with the exact error line; in HDR the same filter kernels still create.
    • quality9 is refused, and so is native D3D12 with a non-default selection.
    • The default LDR frame on HIP and on D3D12 launches l_post_filter_ldr on the kernel's own grid (cdiv(w,40) x
      cdiv(cdiv(h,2),8), block 64) with the display and output arguments.
    • test_own_post traces the own route's arguments and roles in HDR and LDR, and the D3D12 frame checks assert
      l_post_recon_p12 right after the coefficient store.

Checks (extended):

  • l_post_check.py --ldr;
  • l_frame_check.py --ldr, with an FP16 comparison where a non-finite value counts as agreeing only where the
    reference holds the same one, and an absolute tolerance for the LDR filter;
  • l_d3d12_ops_check.py, with the LDR kernels and filter;
  • l_d3d12_fallback_check.py --ldr;
  • post_tf_d3d12_check.py --store --ldr.

Records (GPU, gfx1201; clean/l/records/l_post_ldr_record.json, counts and digests only)

HIP LDR form against Model L's LDR oracle

  • Kernel level (l_post_check.py --ldr --seeds 6, synthetic): 60 of 60 cases pass.
    • History 0 and display 4 of 431784 values more than 1 ulp off.
    • Negative control caught.
    • Known answers hold: total weight 0 gives history NaN, display 0, code 0 (Q1 LDR); every FP16 weight 0 gives the
      candidate-1 history.
    • HDR unchanged: 6 of 431784.
  • Frames, real weights (the converter's Model L, model SHA-256 d3c04019…ad806, map 58e6d0e7…e857; synthetic
    frames, LDR colour; l_frame_check.py --ldr): Model L passes every stage on 11 of 11 frames.
    • Post over the run: history 0 and display 6 of 641520 values more than 1 ulp off. Worst frame: 2 display values
      (0.0034 %).
    • Reduced codes at most 1 off.
    • Default kernels equal the six-launch run on 11 of 11.
    • Model M control passes.
    • Synthetic weights: Model L passes (history 0, display 2 of 641520).

D3D12 byte-identical to HIP (raw bytes, sentinels HIP 0xA5 / D3D12 0x5A, 64 slack bytes)

Check Result
Kernels (l_d3d12_ops_check.py --seeds 6) l_post_recon_ldr 72/72, l_post_recon_p12_ldr 72/72, l_post_filter_ldr 30/30, HDR l_post_recon / _p12 72/72 each; p12 = base on HIP 72/72 (LDR and HDR); Model M control swin_block_c96_nc 36/36; one half-grid negative control per kernel, all caught: l_post_recon_ldr 8509 bytes differ, l_post_recon_p12_ldr 8509, l_post_filter_ldr 20461, HDR l_post_recon / _p12 8498 each
Frames, LDR, real weights 11 of 11 identical, 28 outputs, 0 differing (D3D12 runs l_post_recon_ldr); negative controls 4/4; Model M 11/11
Frames, LDR, synthetic 11 of 11 identical, 28 outputs, 0 differing
Fallback route, LDR (--ldr --seeds 2) l_coef 10/10, l_post_recon_ldr 10/10, l_post_filter_ldr 10/10; Model M control 12/12; negative control caught
Direct filter store, LDR (--store --ldr) 20/20; stored values clamped past 65504 28176, FP16 subnormal 44042, rounding ties 1098; negative control caught
Native direct route (native_direct_test matrix) LDR: PASS, 96 frames over 24 texture format combinations, mutation caught; kernels traced: l_direct_color, l_post_recon_p12_ldr, l_post_filter_direct_ldr (staged reference: l_post_filter_ldr); HDR: PASS 96

Model M unchanged: its fused posts and swin_block_c96_nc rebuilt from this tree, 16 of 16 DXILs byte-identical to
main's.

CPU tests:

  • test_l_runtime_frame 21 OK;
  • test_runtime_frame_trace + test_kernel_sets 10 OK;
  • test_l_recon 15 OK.

Merged main (#153, #155, #156, #158, #172; it changes Swin D3D12 kernels and device.cpp): on the merged tree, a
full D3D12 rebuild (68 kernels) and the runtime, real weights, both colour modes:

  • LDR: HIP against the LDR reference passes (history 0, display 6 of 641520); D3D12 against HIP 11 of 11 identical,
    28 outputs, 0 differing, negative controls caught; Model M 11 of 11.
  • HDR: passes (history 2, display 4 of 641520); D3D12 against HIP 11 of 11 identical; Model M 11 of 11.
  • The CPU tests above pass on the merged tree.

Review fix (P1) re-run on the fixed runtime, real weights, LDR, default frames: HIP against the LDR reference
passes (L and M; history 0, display 6 of 641520; default kernels equal the stages on 11 of 11); D3D12 against HIP 11 of
11 identical, 28 outputs, 0 differing, negative controls 4 of 4; Model M 11 of 11. The kernel ops check above was re-run
with the per-kernel negative controls. Merged main again (#43, #177, #178, #179; no runtime, Model L or D3D12 files):
CPU tests above pass on the merged tree.

For the spec side (flag, no change made)

  • In LDR the colour feature is the identity transfer, so a NaN colour stays NaN through the gather. HDR's E_in maps NaN
    to 0.
  • The oracle does the same, and item 6 says "identity transfer" without a NaN rule.
  • On the synthetic frames this gives about 9000 NaN history values per frame, identical in kernel and oracle.
  • If the original maps NaN to 0 in LDR too, it is a one-line change in both kernels and the oracle.

Tested / Not tested

  • Tested: everything above; leak scan 0 hits; public gates pass, LOOK lines at main's baseline (42 / 29 / 108; none in this PR's files).
  • Not tested: a game in LDR (no LDR game set up). The HIP output copy's LDR filter (l_post_filter_ldr_h) is the
    reference of the direct-store check above (its RGBA16F rows equal the D3D12 direct texture, 20/20); the HIP runtime's
    output-copy route itself runs only in the CPU trace.

…post route for Model L

- l_post.hip: l_post_recon_ldr / l_post_recon_p12_ldr, the LDR form of Model L's reconstruction (spec preset L part 3
  item 6, Q1, Q2): identity transfer (colour feature h(colour), no decode of the candidates or of C), no exposure, full
  history h(H^), display image h(code RN32(1 / N)) of the 11 / 11 / 10-bit codes floor(clamp(fused(O^ N + 1/2), 0, N)),
  reduced codes rint(clamp(mean, 0, 1) 1023); l_post_filter_ldr / l_post_filter_ldr_h, the LDR output stage (Model M's
  5-tap filter rows and passes, no clamp to [1e-4, 3], no decode, no exposure). The HDR kernels' ISA is unchanged.
- D3D12 ports, byte for byte: l_post.hlsl (LP_LDR), post_filter.hlsl (WG_FILTER_LDR: l_post_filter_ldr and the direct
  form l_post_filter_direct_ldr); the HDR and Model M DXILs are unchanged. kernel_sets.json regenerated (Model L +4).
- runtime.cpp: Model L reconstructs with its own kernels only, HDR and LDR, on HIP and native D3D12 (staged, direct and
  fallback routes). Model M's post route for Model L is gone: l_post=m is refused, l_post=own is a no-op, and where
  Model L's route cannot run (l_own_post_fits: the default pack12 post route and its ports, HDR or LDR) creation is
  refused with the reason. HIP no longer refuses LDR for Model L.
- Checks: l_post_check.py --ldr, l_frame_check.py --ldr (and NaN-aware FP16 comparison, LDR filter tolerance),
  l_d3d12_ops_check.py (LDR kernels and filter), l_d3d12_fallback_check.py --ldr, post_tf_d3d12_check.py --store --ldr;
  test_l_runtime_frame: the own route in HDR and LDR and test_no_model_m_post_route. Record:
  clean/l/records/l_post_ldr_record.json.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…s not implement (review P1); per-kernel negative controls

- runtime.cpp: with LDR colour Model L runs only l_post_filter_ldr (the default filter's geometry, 3 x f32; its direct
  form on native D3D12; l_post_filter_ldr_h for the HIP output copy). Another filter kernel or geometry, an RGBA16F
  filter output or output_filter=quality5 / quality9 / original is now refused at create with the reason
  (l_ldr_filter_unfit), on every backend and for the output copy too, instead of launching the LDR kernel with the
  selected filter's grid or output format.
- test_l_runtime_frame: test_ldr_filter_selection (an alternate geometry, _o16 and output_filter refused in LDR; HDR keeps
  the filter kernels; the default LDR filter launch on the default grid).
- l_d3d12_ops_check.py: a negative control per post kernel (each LDR form its own), all must be caught.
- Record updated (clean/l/records/l_post_ldr_record.json).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 merged commit 715206d into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/lpost-ldr branch November 14, 2026 17:57
phantoslayer21 added a commit that referenced this pull request Nov 14, 2026
Every game tried (Cyberpunk 2077, RESIDENT EVIL requiem with HDR off, LEGO Batman, Ratchet & Clank: Rift Apart) hands the upscaler HDR colour, so the SDR path (#176) has offline records only; the Known issues line says so plainly.

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
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