Skip to content

l_post=own direct route: the filter writes the game's texture (speed step 2) - #167

Merged
phantoslayer21 merged 3 commits into
mainfrom
model-l/lpost-filter-direct
Nov 14, 2026
Merged

phantoslayer21 merged 3 commits into
mainfrom
model-l/lpost-filter-direct

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Step 2 of the l_post=own speed work. On the direct-resource route (games), the filter now writes the game's texture itself. l_direct_store and the FP32 output buffer's round trip are gone. Stacked on #166.

What

  • clean/dx12/kernels/post_filter.hlsl: new l_post_filter_direct (co=-, rs=direct, D3D12 only). It is the analytic filter w64/post_filter_c1_s4 with its output going to the game's output texture instead of out_p, which it doesn't write.
    • Stored values: what the FP32 output followed by l_direct_store stored. That is, times pi via native_direct_scale when pi != 1; framebuffer_half's bytes with output_rne16 (±65504 clamp, round to nearest even; NaN kept); alpha 1.
    • Each lane still computes one channel. The channel-0 lane of a pixel gathers channels 1 and 2 from lanes 3g + 1 and 3g + 2, which belong to the same pixel and so share its loop exits, and stores the texel.
    • The buffer form w64/post_filter_c1_s4 is unchanged: its RGA ISA is identical to D3D12 l_post_recon(_p12): smaller and faster, byte for byte the same (l_post=own speed, step 1) #166's.
  • Runtime, l_post=own on the direct route: launches l_post_filter_direct in place of the filter + l_direct_store. No FP32 output buffer is allocated there; only color_net for l_direct_color. The port list names l_post_filter_direct.
  • clean/dx12/kernels/l_post_direct.hlsl: l_direct_store removed; l_direct_color kept.
  • clean/dx12/tests/post_tf_d3d12_check.py --store: now runs l_post_filter_direct on the display image against HIP's output copy of it.
  • kernel_sets.json: l_post_filter_direct replaces l_direct_store in Model L's set. Model M: 46.

Byte identity (GPU, one slot per run)

check result
post_tf_d3d12_check.py --store --seeds 2: l_post_filter_direct → RGBA16F texture with output_rne16, against HIP post_filter_c1_s4_o16 (pi 1) / post_filter_h (pi 1.25, 1.375, 30000) rows; 2 cases: RGBA32F texture against HIP's FP32 output + alpha 1 26 / 26 identical; 12,569,632 texture bytes. The texture is filled with 0x5A first (every texel must be written); out_p untouched
↳ stored values among those NaN 34,068; past ±65504 57,618 (7,680 infinite); FP16 subnormal range 107,121; exact rounding ties 432
↳ w64/post_filter_c1_s4 (FP32) against HIP, same cases identical, 14,425,872 bytes
↳ negative control (half grid) caught, 16,837 bytes
Model M control on the same harness (--direct) orig_w64/post_tf_f32_p12_diet_vsit_direct and the analytic direct forms identical; negative control caught
frame: D3D12 l_post=own against the HIP Model L frame (l_d3d12_own_post_check.py) 11 / 11 byte-identical; negative control caught; per stage 11 / 11
direct against staged (native_direct_test, Model L, l_post=own, matrix) 96 / 96 frames, all 24 formats, 0 debug-layer errors; mutation caught
↳ launch trace of that run l_post_filter_direct on the 96 direct frames (no l_direct_store); the staged frames keep the filter + scale_rgb
default route (native_direct_test without the option) 16 / 16

Timing

native_direct_test ... bench, Model L, l_post=own, synthetic model. GPU frame span, median of 1,500 samples (3 rounds of 500, every measurement window valid). #166's program against this branch's, the same ports.

direct route #166 (filter + l_direct_store) this PR staged route, both programs (control)
1080p Quality 2.517 ms 2.497 ms (−0.020) 2.614 / 2.614 ms
1440p Quality 4.411 ms 4.310 ms (−0.101) 4.605 / 4.600 ms

The buffer route (l_d3d12_profile.py) runs the same kernels as in #166.

Negative result: the full reconstruction + filter fusion (not in this PR)

The first step 2 was a true fusion: l_post_tf_p12, reconstruction and the analytic filter in one kernel, walking output strips with a ring of filtered rows in LDS as Model M's fused post does.

  • It was byte-identical to HIP: 18 / 18 replay cases (buffer and direct forms, RGBA16F output_rne16 at pi 1.375, the unstaged route, chunk edges), the frame check 11 / 11, and direct against staged 96 / 96.
  • It was slower than the pair:
reconstruction + filter pair (#166) fused, 8 row pairs per step (512 lanes) fused, 4 row pairs per step (256 lanes) Model M's fused post
1080p Quality 0.668 ms 0.951 ms 0.806 ms 0.328 ms
1440p Quality 1.206 ms 1.655 ms – 0.567 ms

Why: fusion can only save the filter launch and the display image's write and read, about 0.05–0.08 ms. In exchange, every step of the strip walk holds the whole workgroup at four barriers while the slow, scattered history reads finish, and the large workgroups leave fewer workgroups resident. The bigger workgroup was the slower one although it stages fewer redundant texel rows, so the barrier stalls dominate, not the staging. Model M gains from fusion because its reconstruction is cheap next to its display traffic; Model L's reconstruction is the expensive part. The code is kept locally as a record, not proposed.

Notes

  • The synthetic frames have random motion, so their history reads scatter more than a game's would. The next game run gives the real gap.
  • Next: step 3, the history reads inside l_post_recon_p12.

Tested

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

Not tested

  • A game run.
  • The buffer route's timing (unchanged kernels).

Update: on main after #166 (merge 8972cbc)

Base is now main (f0fd94c, #166 merged). The merges bring #162's raw-byte check API and #166 (already in this branch);
this PR's own change is unchanged. Re-checked on the merged tree (same tree as the record) 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;
  • per stage against the reference under Model L's post acceptance: 11 of 11, post over the run passes;
  • default kernels against the stages run, raw bytes: 11 of 11 identical, negative controls caught.
    The DXILs of l_post_filter_direct, w64/post_filter_c1_s4 and l_direct_color on the merged tree are byte-identical to
    those of the direct-store record above (26 of 26), so that record stands.

…_filter_direct)

- clean/dx12/kernels/post_filter.hlsl: l_post_filter_direct (co=-, rs=direct), the analytic filter
  w64/post_filter_c1_s4 with the output in the game's output texture: times pi (native_direct_scale),
  framebuffer_half's bytes with output_rne16, alpha 1 (what the FP32 output then l_direct_store stored).
  The lane of channel 0 gathers channels 1, 2 from its neighbour lanes. The buffer form's ISA is unchanged.
- runtime: the direct route launches it in place of the filter + l_direct_store; no FP32 output buffer
  there. l_direct_store is removed (l_post_direct.hlsl keeps l_direct_color).
- post_tf_d3d12_check.py --store: l_post_filter_direct against HIP's output-copy rows (and an RGBA32F
  texture against HIP's FP32 output); its out_p untouched.
- kernel_sets.json: l_post_filter_direct for l_direct_store in Model L's set (Model M: 46).

Direct route, 1440p Quality: 4.411 -> 4.310 ms frame span; 1080p Quality: 2.517 -> 2.497 ms.

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