Skip to content

Model K on D3D12: the output stage, byte-identical to HIP - #210

Merged
phantoslayer21 merged 2 commits into
mainfrom
k/d3d12-output
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
k/d3d12-output

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #15. Stacked on #208 (the input stage; through it #206, #204, #201, #198, #207): the diff is against that branch.

Preset K's output stage on D3D12, byte-identical to its HIP kernels in k_io.co on the exact path. With this PR every network stage and both I/O stages of the exact path have a D3D12 port; the runtime wiring is the next PR.

What changes

  • clean/k/dx12/kernels/k_out.hlsl and hlsl/k_out.hlsli: k_out_color (per render pixel: the stored colour tap and the filter-tap value), k_out_pixel_c (compact pixel head, the default) and k_out_pixel (the 40-channel head map, k_head=full). Same lane-to-pixel mapping and launch geometry as HIP (64 x 2 pixels per workgroup of 128 lanes, one row per wave64, the group exchange of the luma through LDS). KOutParams by value as s312:...: the fields that are dead in the runtime (subrect bases, the host's kappa / rho / lambda, which the kernels take from the device scalars, padding and the emulator's 2^E table) are skipped; the header says why each is dead. The output's fourth channel is the colour input's alpha through the current-colour bilinear, on all three game-output formats (issue Preset K: visual fixes (output alpha, motion rounding) #26, as Model K: output alpha follows the colour input's alpha; motion rounding on the raw-buffer routes #207).
  • Where HIP rounds a product that meets an addition, or the D3D12 compiler could regroup a chain of products, the intermediate goes through an opaque XOR barrier; FP16 steps use native half arithmetic with nearest-even rounding; divisions are HIP's correctly rounded ones; the hardware estimates (v_rcp_f32, v_exp_f16) are used where HIP uses them. The source lists each deviation from HIP and why it gives the same bits.
  • Not ported, on purpose: the _f kernels of k_fast=1 and k_out_hidden (they keep running on HIP). The forms that read the game's textures (_direct) are in the sources for the runtime's use but are not declared yet; they are declared and checked with the runtime wiring.
  • kernel_sets.json: three kernels. k_port_check.py: the output family.

Tested

k_port_check.py --run --family expo,warm,narrow,wide,input,output --seeds 3, one GPU slot (the whole stack in one run):

  • output: 48 of 48 cases raw-byte identical to HIP, k_out_pixel_c 25 and k_out_pixel 23; all three game-output formats; 16 flag sets (HDR, low-resolution motion, inverted depth, reset) on base grids 1 x 1, 7 x 9, 8 x 8, 9 x 7, 33 x 17; exposure scalars from a device buffer; alphas negative, above 1 and 7e4; 18 cases with infinity, huge values, zero and -0 in the colour, depth, motion, head map and histories, 12 more with NaN as well; none differs, not even in a NaN's sign. The image (out), the luma and colour histories and k_out_color's tap buffers are compared; every slack byte kept its sentinel (HIP 0xA5, D3D12 0x5A). Negative control (half grid) caught, 23203 bytes differ.
  • The other families still pass in the same run: expo 108 of 108, warm 18 of 18, narrow 180 of 180, wide 126 of 126, input 48 of 48; control (Model M scale_rgb) identical; replay exit 0.
  • Record: pr8-output.json (counts and verdicts only).
  • DXILs: no Model M or Model L source or build code changed in this PR (the 12-kernel sample of Model K on D3D12: the exact tiled input stage, byte-identical to HIP #208 was identical to main's).
  • CPU: test_kernel_sets passes; line endings clean. public_gates.py: must-pass gates pass, LOOK counts equal main's.

Not tested

  • The full Model M plus Model L DXIL set.
  • The _direct forms; the runtime on D3D12 (next PR); whole frames; real inputs.
  • Known limit, shared with Model M's ports: D3D12 flushes FP32 denormals to zero and HIP keeps them; none occur in the checked frames.

Accepted exceptions (review decision, 2026-11-14)

  • NaN sign: with NaN in the inputs, the decoder stages produce NaN at exactly the same elements on D3D12 and HIP, but the NaN sign can differ. Every non-NaN byte is identical. A NaN sign carries no value (NaN propagates), so this is accepted as a documented exception to raw-byte identity; the port check keeps counting these elements separately.
  • FP32 denormals: D3D12 flushes FP32 denormals where HIP keeps them, the same accepted behaviour as the Model M ports. The check inputs avoid denormals.

Refs #15. Ports of k_out_color, k_out_pixel_c (compact pixel head) and k_out_pixel (full head map): the exact path only (the k_fast _f kernels and k_out_hidden keep running on HIP). KOutParams by value as s312 (the fields that are dead in the runtime are skipped); the output's fourth channel is the colour input's alpha through the current-colour bilinear on every output format (issue 26). The forms that read the game's textures are in the source but not declared yet.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
… forms

With the D3D12 input and output ports in the tree the source checks of test_k_direct_motion run; the check of the k_out_pixel_direct declaration applies once the direct forms are declared (with the runtime wiring).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 22:29
Base automatically changed from k/d3d12-input to main November 14, 2026 22:49
@phantoslayer21
phantoslayer21 merged commit 25407f2 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the k/d3d12-output branch November 14, 2026 22:49
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