Skip to content

D3D12 l_post_recon(_p12): smaller and faster, byte for byte the same (l_post=own speed, step 1) - #166

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/lpost-p12-speed
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/lpost-p12-speed

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Step 1 of the l_post=own speed work: a smaller and faster D3D12 l_post_recon / l_post_recon_p12, byte for byte the same as before (and as HIP). Stacked on #162; its diff against #162 is one kernel file and one check file.

Why

In the profile on #162, l_post_recon_p12 was 0.894 ms at 1080p Quality, against 0.323 ms for Model M's whole fused post. Its D3D12 code was 93.9 KB: every tap, the unstaged fallback inside every tap, and both rows of the finish were unrolled. Every FP16 rounding was software (wg_f2h), and the history divisions were software IEEE divisions.

What (clean/dx12/kernels/l_post.hlsl)

  • Taps. They run column by column in a loop: i outer, j inner, each pixel's sums in the same order as before. Per column, the eight tap weights (four rows, two pixels) are rounded to FP16 by one driver conversion (wg_to_f16_ags, v_cvt_f16_f32: the same bits as wg_f2h).
  • Texel staging. It runs in wave-uniform rounds, so its six roundings also use the driver conversion: E_in of the colour, and the kernel shape's products as round-to-odd values (wg_mul_f16's single rounding). The unstaged route uses the same loader.
  • The codes' k / 255. They come from a per-workgroup LDS table of their FP16 bits: each lane computes one code with wg_div, then the driver conversion.
  • The two rows of a pair. They run in a loop. Each row's full-history and display values go through one conversion.
  • D(h) / e_prev. This uses the direct route's per-launch reciprocal window (native_direct_pi.h, native_direct_color_div3): three fused operations on lanes whose |a| is in [lo, hi), wg_div everywhere else (NaN, infinity, zero, quotients near the FP32 range ends, an e_prev outside the window's domain).
  • Every value going into a driver conversion is opaque (opq) or a round-to-odd value, so the driver can't fold an FP32 operation into the conversion.
  • Result. ISA 93.9 KB → 44.9 KB (RGA, gfx1201). VGPRs 138 in both builds (96 / 115 in intermediate forms); no scratch.

clean/l/runner/l_d3d12_ops_check.py: two post cases whose exposure pair holds an extreme or invalid e_prev (1e-30, 3e-38, 1e30, 3e38, NaN, -1.5, infinity, 2^-126). They exercise the division fallback.

Byte identity (GPU, one slot per run)

check result
l_d3d12_ops_check.py --seeds 6, against HIP's l_post_recon (sentinels HIP 0xA5 / D3D12 0x5A, slack, raw bytes; specials; extreme exposures) l_post_recon 72 / 72 identical; l_post_recon_p12 72 / 72 (2,271,840 bytes each); HIP p12 = base 72 / 72
↳ negative control (half grid) caught
↳ Model M control swin_block_c96_nc 36 / 36
fallback chain (l_d3d12_fallback_check.py --seeds 2: unpacked l_coef → l_post_recon → filter, edge tiles) 10 / 10 per step; Model M control 12 / 12; negative control caught
frame: D3D12 l_post=own against the HIP Model L frame (l_d3d12_own_post_check.py) 11 / 11 byte-identical, post outputs included; negative control caught; per stage against the reference 11 / 11; defaults against stages 11 / 11
direct against staged (native_direct_test, Model L, l_post=own, matrix) 96 / 96 frames, all 24 colour / depth / motion / output formats; 0 debug-layer errors; mutation caught
default route (native_direct_test without the option) 16 / 16

Timing

clean/l/runner/l_d3d12_profile.py, 200 frames, synthetic model, GPU timestamps (attribution; the frame span is measured without timestamps).

before (#162) this PR Model M's fused post (the default route)
l_post_recon_p12, 1080p Quality 0.894 ms 0.593 ms
l_post_recon_p12, 1440p Quality 1.606 ms 1.050 ms
reconstruction + filter, 1080p Q 0.968 ms 0.668 ms 0.329 ms
reconstruction + filter, 1440p Q 1.761 ms 1.206 ms 0.569 ms
frame span, 1080p Q 2.662 ms 2.372 ms 2.079 ms
frame span, 1440p Q 4.570 ms 4.052 ms 3.504 ms

Where the remaining 0.59 ms (1080p Q) goes, from throwaway ablations that are not in this PR:

  • the finish (steps 3–5 and the stores): about 0.32 ms; history fetches about 0.17 ms of that, the second history candidate about 0.09 ms;
  • the 16-tap gather: about 0.18 ms;
  • staging and setup: about 0.07 ms.

The synthetic frames have random motion, so their history reads scatter more than a game's would. Next steps: fusing the filter and the store (step 2), folding l_direct_color (step 3), then the history fetch.

Tested

  • The GPU records above.
  • CPU: clean/l/runtime/tests (33).
  • Public gates: LOOK lines at the baseline, none in these files. Leak scan 0 hits.

Not tested

  • A game run (the release lead's).
  • Real-model frames: the timing and frame checks use the synthetic model.

Update: on main after #162 (merge d555032)

Base is now main (93461bb, #162 merged). The merge brings only #162's last commit (the raw-byte check API); the D3D12
kernel source of this PR is unchanged. Re-checked on the merged tree with l_d3d12_own_post_check.py (raw-byte API,
sentinels HIP 0xA5 / D3D12 0x5A / D3D12 stages 0x3C), GPU record:

  • against the HIP run, raw bytes: 11 of 11 frames identical, 28 outputs compared, 0 differing; negative controls 4 of 4
    caught (dropped history write, dropped reduced write, whole reduced write, missing output);
  • per stage against the reference under Model L's post acceptance: 11 of 11, post over the run passes (history,
    display);
  • default kernels against the stages run, raw bytes: 11 of 11 identical, negative controls caught.

- The taps run column by column in a loop; per column the eight tap weights (four rows, two pixels)
  are rounded to FP16 by one driver conversion (v_cvt_f16_f32: the same bits as wg_f2h).
- The texel staging runs in wave-uniform rounds, so its six roundings (E_in of the colour, the kernel
  shape's products as round-to-odd values) use the driver conversion too; the unstaged route uses the
  same loader. The codes' k / 255 come from a per-workgroup LDS table of their FP16 bits (wg_div,
  then the driver conversion).
- The pair's two rows run in a loop; each row's full-history and display values in one conversion.
- D(h) / e_prev: the per-launch reciprocal window of the direct route's colour division
  (native_direct_pi.h; three fused operations on the lanes in the window, wg_div elsewhere).
- l_d3d12_ops_check.py: post cases with extreme or invalid e_prev in the exposure pair.

1080p Quality: 0.894 -> 0.593 ms; 1440p Quality: 1.606 -> 1.050 ms (synthetic model, GPU timestamps).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Base automatically changed from model-l/d3d12-own-post to main November 14, 2026 13:28
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 13:57
@phantoslayer21
phantoslayer21 merged commit f0fd94c into main Nov 14, 2026
9 of 18 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/lpost-p12-speed branch November 14, 2026 13:58
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