Skip to content

Model K on D3D12: the exact tiled input stage, byte-identical to HIP - #208

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

phantoslayer21 merged 2 commits into
mainfrom
k/d3d12-input

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #15. Stacked on #206 (the wide stages) and #207 (the visual fixes, merged into this branch): until those are merged the diff here includes theirs.

Preset K's exact tiled input stage on D3D12, byte-identical to its HIP kernel k_in_tiled of k_io_exact.co. This stage is what #207's motion and alpha behaviour is defined against.

What changes

  • clean/k/dx12/kernels/k_in.hlsl: kx/k_in_tiled (the tag kx is the exact input code object, as in the runtime). One workgroup of 256 lanes per 8 x 8 base positions, KInParams by value (s200:p4.b128.p5). Exactly HIP's operations in its order: log2 and 2^x correctly rounded (with the binary64 fallback), every division and reciprocal correctly rounded, FP16 rounding to nearest even (never the driver's round-toward-zero), the cases of a reset frame, the exposure scalars from the device buffer.
  • hlsl/k_fp.hlsli, hlsl/k_frame.hlsli: the scalar FP32 / FP16 / binary64 helpers and the frame-input fetch helpers shared with the output stage. Where the D3D12 compiler could merge two of HIP's roundings (a product by a uniform feeding an add, a regrouped constant chain) the product goes through an opaque XOR barrier (kf_opq).
  • gen_k_fp_tables.py: computes the helpers' constants and tables as bit patterns from their binary64 series; build_dx12.py runs it at every K build into <out>/dx12/gen (nothing is stored).
  • The port uses binary64 fma and division, so its manifest entry is marked fp64: ext (Model K on D3D12: --model-k, struct arguments, the port check, k_expo_scalars and k_warm #201) and an adapter without DoublePrecisionFloatShaderOps gets no port.
  • Not declared yet: the forms with KiHost in the arguments (k_in_tiled_uniform) and the forms that read the game's textures (_direct). They are in the sources for the runtime's use and are declared and checked with the runtime wiring.
  • kernel_sets.json: kx/k_in_tiled. k_port_check.py: the input family.

Tested

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

  • input: 48 of 48 cases raw-byte identical to HIP (16 flag sets: HDR, low-resolution motion, inverted depth, reset; base grids 1 x 1, 7 x 9, 8 x 8, 9 x 7, 33 x 17; the exposure scalars from a device buffer, the host values wrong on purpose; 18 cases with infinity, huge values, zero and -0 in the colour, depth, motion and histories, 12 more with NaN as well; none differs, not even in a NaN's sign). Every slack byte kept its sentinel (HIP 0xA5, D3D12 0x5A). Negative control (half grid) caught, 5408 bytes differ.
  • The earlier families still pass in the same run: expo 108 of 108, warm 18 of 18, narrow 180 of 180, wide 126 of 126; control (Model M scale_rgb) identical; replay exit 0.
  • Record: pr5-input.json (counts and verdicts only).
  • DXILs: 12 Model M and Model L kernels built from current main (77f6785) and from this branch: all 12 digests identical. No Model M or Model L source changed.
  • CPU: test_kernel_sets, test_k_plan_bridge pass; 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 (sample of 12).
  • k_in_tiled_uniform and the _direct forms (next PRs).
  • 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 (the inputs keep clear of them).

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.

…dentical to HIP

Refs #15. Port of kx/k_in_tiled (KInParams; the exact path: correctly rounded log2, 2^x, divisions and reciprocals, FP16 rounding to nearest even; binary64 fma and division from the D3D12 extended doubles, marked fp64=ext so an adapter without them gets no port). Shared headers k_fp.hlsli and k_frame.hlsli; the FP constants and tables are generated at every build by gen_k_fp_tables.py (nothing stored). The forms with KiHost arguments and the forms reading the game's textures are in the source but not declared yet.

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