Skip to content

Model K direct route: allocate the legacy input stage's intermediates; never pack a null one - #264

Merged
phantoslayer21 merged 1 commit into
mainfrom
clean/k-direct-cpre
Nov 16, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
clean/k-direct-cpre

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

What

On main, a Model K context on the native direct route did not allocate the legacy input stage's intermediates cpre (R×16 bytes) and cpre2 (R×8), where R is the declared maximum render size in pixels. A frame on the legacy input path still runs kx/k_in_color_direct, then kx/k_in_reset or kx/k_in_base_direct, which write and read them. The legacy path covers a render size above 0.68 × the output (DLAA), a jitter outside [-0.5, 0.5], and input_tiled=0. The null pointers were packed as arena offset 0 (clean/runtime/struct_args.h), so the frame overwrote the start of the arena and read it back.

  • clean/k/runtime/runtime_k.cpp
    • cpre / cpre2 are allocated for every context. A direct context needs R×24 more bytes of arena, the same as the buffer route already has (about 199 MB at a 4K DLAA declared maximum).
    • Create refuses when a buffer that an input-stage kernel of the context can be handed is not allocated.
    • A legacy input kernel is never launched with a null cpre / cpre2: the frame is refused with one line instead.
  • clean/k/tests/test_k_direct_legacy.py (new, GPU): test_interop_d3d12.exe dx12same runs the same 6 frames (resets at 1 and 5) through executor=hip (the exact reference, buffer route) and the native direct route ("inputs read directly 1"). Every output byte must be identical. Cases: DLAA, a jitter outside the guard, input_tiled=0, and the tiled Quality control.
  • clean/runtime/interop/tests/test_interop_d3d12.cpp: dx12same takes WG_TEST_JITTER_OUT=1, a jitter of (0.75, -0.8) on every frame. It exists in this test program only. clean/tests/check_no_dev_diagnostics.py refuses a runtime library, payload or package file that names it (clean/tests/test_dev_diagnostics_off.py).

A refusal of every null struct pointer in struct_args.h is not part of this change. Model K passes null on purpose for buffers a kernel does not read (absent block / skip / merged / head stages, and the direct kernels' dense input pointers), so that needs per-field declarations. It is on the 0.6.6 list.

Evidence

Developer builds, synthetic model, 1280×720 output (Quality: 853×480 render), 6 frames, resets at frames 1 and 5. The counts are output bytes that differ from the exact reference, out of 7,372,800 per frame.

Main 25429c5 (test_k_direct_legacy.py FAILS):

Case Frame 1 2 3 4 5 6
DLAA 2,492,269 3,763,197 3,554,070 3,567,844 2,295,382 3,808,443
jitter outside the guard 2,901,723 3,736,064 3,653,639 3,709,517 2,831,700 3,810,732
input_tiled=0 2,766,608 3,767,084 3,645,784 3,756,813 2,671,814 3,841,056
control: tiled Quality 0 0 0 0 0 0

The null pointer reached the launch: a build with only the launch-time check, without the allocation, refuses the first legacy frame of each of the three cases with model K: kx/k_in_color_direct would get a null cpre / cpre2 (arena offset 0); the frame is refused. The tiled control is unaffected. This stands in for an arena sentinel, which the interop harness cannot reach.

With this change (test_k_direct_legacy.py passes): DLAA, jitter outside the guard, input_tiled=0 and the control are 0 bytes different on all 6 frames.

Other runs on the fixed build:

  • test_interop_d3d12.exe matrix at 1080p and 2160p: 40 direct-route contexts (every usual ratio, HDR / LDR, both declared maximum sizes), 0 refusals, every frame run.
  • test_k_runtime_d3d12.py: 26 / 26 (each test in its own process).

Files

clean/k/runtime/runtime_k.cpp, clean/k/tests/test_k_direct_legacy.py (new), clean/runtime/interop/tests/test_interop_d3d12.cpp (test program), clean/tests/check_no_dev_diagnostics.py, clean/tests/test_dev_diagnostics_off.py. No shader, no clean/dx12/build_dx12.py, nothing under clean/dx12/hlsl, clean/dx12/kernels or clean/rr_f.

… (cpre, cpre2); never pack a null one

A native direct context skipped cpre (R*16) and cpre2 (R*8), but a frame on the legacy input path (a render size above
0.68 x the output, such as DLAA; a jitter outside [-0.5, 0.5]; input_tiled=0) runs kx/k_in_color_direct, then
kx/k_in_reset or kx/k_in_base_direct, which write and read them. The null pointers were packed as arena offset 0
(clean/runtime/struct_args.h), so the frame overwrote the start of the arena and read it back: the output differed from
the exact reference on every such frame, and the overwritten allocation was corrupted.

- runtime_k.cpp: cpre / cpre2 are allocated for every context (+R*24 bytes of arena for a direct context, as the buffer
  route already has). Create refuses when a buffer an input-stage kernel can be handed is not allocated. A legacy input
  kernel is never launched with a null cpre / cpre2 (one line, the frame refused).
- test_k_direct_legacy.py (new, GPU): test_interop_d3d12.exe dx12same, executor=hip (exact reference) against the
  native direct route, 6 frames with resets: DLAA, a jitter outside the guard, input_tiled=0, and the tiled control,
  every output byte identical.
- test_interop_d3d12.cpp: dx12same WG_TEST_JITTER_OUT=1 (a jitter outside [-0.5, 0.5] on every frame; this test
  program only). check_no_dev_diagnostics.py refuses a runtime library, payload or package file that names it
  (test_dev_diagnostics_off.py).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 merged commit 32ed000 into main Nov 16, 2026
10 checks passed
@phantoslayer21
phantoslayer21 deleted the clean/k-direct-cpre branch November 16, 2026 10:09
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