Skip to content

Model L D3D12: the q map in a 20-byte form on the le route (byte-identical; enc0 -10/-27/-11 us) - #203

Merged
phantoslayer21 merged 1 commit into
mainfrom
model-l/q20
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
model-l/q20

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Refs #89

On Model L's D3D12 le route, the q map loses its 12 always-zero bytes per halo pixel. The input encoder now writes only the 20 value bytes and the encoder block reads only those; the network's outputs are byte-identical.

What changes

  • encoder.hlsl: new WG_ENC_Q20 forms lev/input_encoder_q20 and lev/input_encoder_direct_q20. They compute the same values as the input encoder, but write each halo pixel's 20 value bytes in two planes: bytes 0..15 of every pixel, then bytes 16..19 of every pixel. Every store stays aligned.
  • swin_block.hlsl, SW_SRC 3: l_swin_block_c32_enc_lin_nc reads that form.
    • Lane half 0 loads 16 bytes from the first plane.
    • Lane half 1 loads bytes 16..19 from the second plane and takes zeros for bytes 20..31, exactly the fragments it read from the 32-byte map.
    • All loads stay aligned. An unaligned 20-byte stride was measured first: the block got slower and ate most of the gain.
  • Runtime: fusion le now also needs the q20 input encoder of the route (buffer or direct). Without it, the 32-byte route runs: input encoder, linears, plain block.
  • Unchanged: the 32-byte input encoders and every other existing DXIL. l.narrow is an internal map, not a checked output.
  • Also updated:
    • build_dx12.py: the two kernels go in MODEL_L_ONLY.
    • kernel_sets.json.
    • FORMATS.md: the q map's 20-byte form.
    • runtime_frame_trace.cpp: the q20 kernel's argument kinds.
    • test_l_runtime_frame.py: argument roles for the q20 form, plus a fallback subtest without the q20 kernel.
    • l_enclin_check.py: q's bytes 20..31 are zero, as the map format says, and the fused kernel reads the 20-byte form.

Timing

Synthetic models; main (ae3cf4e kernels and runtime) against this branch, interleaved, 5 rounds, each run in its own GPU slot. Values are medians in ms. Records: q20c-timing.json and its per-run records q20c-{skrt,q20rtc}-<shape>-r1..5.json.

shape enc0 main enc0 this PR difference input encoder encoder block gather
1080p Quality 0.4524 0.4425 −9.9 µs 0.1174 → 0.1092 0.2923 → 0.2911 0.0427 → 0.0422
1440p Quality 0.8424 0.8150 −27.4 µs 0.2167 → 0.1965 0.5234 → 0.5229 0.1023 → 0.0957
1440p Performance 0.4588 0.4483 −10.5 µs 0.1250 → 0.1150 0.2915 → 0.2910 0.0424 → 0.0422

Every PR run's enc0 was below every main run's at all three shapes.

Tested

  • Encoder block: l_enclin_check.py --seeds 2 on the 20-byte input. Record q20-enclin-identity.json.
    • 28/28 cases byte-identical across the fused kernel, the D3D12 sequence (l_linear_32_32_fused → l_swin_block_c32_enc_nc) and the HIP sequence.
    • Negative control: caught. Model M control: 8/8.
  • Frame check: main's raw frame check (l_frame_check.py --run --backend d3d12 / d3d12-stages, then --compare-d3d12), both models, pass, with all negative controls caught. This also covers lev/input_encoder_q20 end to end. Record q20-framecheck-raw-d3d12.json.
  • Frames against main: every recorded D3D12 array, both models, both configurations, 11 frames, byte for byte: 0 differing. Record q20-frames-vs-main.json.
  • DXILs: full build_dx12.py --model-l build against main's DXIL set. Only l_swin_block_c32_enc_lin_nc differs, and two kernels are new (the q20 encoders). Every other DXIL, Model M's and the 32-byte encoders' included, is unchanged. The three changed or new DXILs are the ones tested and timed.
  • Unit tests: test_l_runtime_frame.py (21 tests), test_kernel_sets.py, fused_swin_gen.py --check.
  • Gates: public_gates.py passes. The LOOK lines carry no hit in this branch's files.

Not tested

  • lev/input_encoder_direct_q20 on the GPU: no harness runs the direct-resource route. It's the same code as the buffer form with the direct texture loads, and it compiles (117 VGPRs, as the 32-byte direct form).
  • HIP: unchanged.
  • Real models and real game frames.

…bytes out)

lev/input_encoder_q20 and lev/input_encoder_direct_q20 (encoder.hlsl WG_ENC_Q20) write each halo pixel's 20 value
bytes without the 12 zero bytes, in two planes (bytes 0..15 of every pixel, then bytes 16..19), and the encoder block
with the linears as its prologue (l_swin_block_c32_enc_lin_nc, SW_SRC 3) reads that form: lane half 1 takes bytes
16..19 from the second plane and zeros for 20..31, the fragments it read from the 32-byte map. 12 of q's 32 bytes per
halo pixel are neither written nor read; every load and store stays aligned. Fusion le now needs the q20 input
encoder too; without it the 32-byte route (input encoder, linears, plain block) runs. The 32-byte input encoders and
every other existing DXIL are unchanged.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 21:25
@phantoslayer21
phantoslayer21 merged commit 7b63d23 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/q20 branch November 14, 2026 21:25
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