Skip to content

Model K: output alpha follows the colour input's alpha; motion rounding on the raw-buffer routes - #207

Merged
phantoslayer21 merged 1 commit into
mainfrom
k/visual-fixes
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
k/visual-fixes

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Fixes #26. Stacked on #198 (the diff is against that branch; once it is merged, against main).

Both fixes of #26 for Preset K, on the HIP executor and the interop; the D3D12 ports of the input and output stages follow this behaviour (a later PR) and need it to be byte-identical to HIP.

What changes

Output alpha follows the input's alpha, on every K output path.

  • The output's fourth channel is the colour input's alpha of the frame, spatial only: the fourth channel of the output stage's current-colour 2 x 2 bilinear (each tap's alpha rounded to FP16, the four FP16 weights, then the same FP16 steps as the colour taps), as it is: no exposure, no clamp, no history, nothing from the network. HDR and LDR alike. A colour format without an alpha channel gives 1.
  • RGBA16F rows (the interop's output copy) store it; a new dense RGBA f32 result (FrameIo.out_rgba32f, 16 bytes per pixel) carries it to the interop's output pass for model K; the runtime's own output buffer can hold either. wg_rt_upload_inputs_rgba is the test path with an RGBA colour (wg_rt_upload_inputs gives model K alpha 1).
  • The interop's input passes keep the colour texel's alpha for model K (Converter::set_model_k); the output pass, the output pass on a result texture and the fallback store the carried alpha. Model M is unchanged in all of them (colour alpha +0 in, alpha 1 out); the HLSL changes are under a flag only model K sets or in a pass only model K runs.

Motion rounding on the raw-buffer routes.

  • On the interop's raw-buffer route (input copies and K's compact input pass, KIO_M16) K used to scale every raw motion texel (ms * r + mo, two roundings) and then apply a factor with scale 1; the reference and the buffer forms fold the scale into the factor and the offset (as RN(mo / ms)) into raw units. k_io.hip now does the latter on the raw texel at both use sites (input ki_fine, output k_out_pixel).
  • The interop's FP32 input pass (the route when the colour or motion texture is not FP16) writes the raw texels for model K and the backend passes motion_scale and the raw-unit offset in WgRtFrame, so K folds them the same way. A zero scale keeps the pass's conversion. Model M: unchanged.

Files: k_io.hip, runtime_k.cpp/.h, interop/convert.cpp/.h, backend.cpp, executor.h, executor_hip.cpp, runtime.cpp, runtime_core.h, wg_runtime.h, the two FORMATS.md, and tests (test_k_alpha.py, test_k_m16_alpha.py, test_k_route3_motion.py, test_k_direct_motion.py, test_k_runtime_gpu.py).

Tested

  • CPU: test_k_alpha, test_k_m16_alpha, test_k_route3_motion, test_k_direct_motion: 27 tests pass, 4 skip (the source checks of the D3D12 input and output ports skip while those ports are not in the tree and run once they are). They check: the alpha rule's CPU form against exact rational arithmetic and against the output-stage reference's fourth channel (gradient, random, negative, above-1 and out-of-FP16-range alphas; HDR and LDR; several sizes and jitters; render-rectangle edges); spatial-only (no change with history, network output, motion, exposure, pre-exposure; chained frames take their own colour's alpha); no clamp; the FP32 arithmetic of the old and new motion routes (the new one equals the buffer form on every value, signed zeros, infinities and NaN included, the old one differs for a share of the values); the interop's run-time HLSL (each alpha-carry text present, model M's texts absent) and that all its passes compile with d3dcompiler_47.
  • GPU, one slot, runtime library built from this branch: test_k_runtime_gpu 20 of 20: HDR and LDR, the three exposure sources, the raw input-copy route with the scale and offset folded (frame outputs bit for bit KFrame's), RGBA16F rows whose alpha equals the reference's fourth channel (negative and above-1 alphas in the inputs), k_head=full, reset=2, network=fused16, k_fast_in=1.
  • Line endings clean; public_gates.py must-pass gates pass, LOOK counts equal main's.

Not tested

  • The interop passes on a real game or a D3D12 device (test_k_alpha_gpu.py needs the D3D12 K ports; it comes with them).
  • Model M frames after the converter change (the HLSL change is flag-gated and checked as text; no M frame comparison was run).
  • The D3D12 ports of these stages (a later PR).

…unding on the raw-buffer routes

Fixes #26. Output alpha: the colour input's alpha of the frame (spatial only: the fourth channel of the current-colour 2 x 2 bilinear, FP16 steps as the colour taps, no exposure and no clamp) is the output's fourth channel on every K output path: RGBA16F rows, a new dense RGBA f32 result for the interop's output pass (FrameIo.out_rgba32f), and the runtime's own buffer; the interop's input passes keep the colour texel's alpha for model K (model M: +0 in, alpha 1 out, unchanged); a colour format without alpha gives 1. Motion rounding: on the raw-buffer routes (the interop's input copies and its compact input pass, KIO_M16) and on the FP32 input pass, K takes the raw motion texel and folds the scale into its motion factor and RN(offset / scale) into raw units, as the reference and the buffer forms do, instead of a per-texel scale * raw + offset followed by a factor of 1.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 22:06
Base automatically changed from k/hip-exposure to main November 14, 2026 22:34
@phantoslayer21
phantoslayer21 merged commit 6569af4 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the k/visual-fixes branch November 14, 2026 22:34
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.

Preset K: visual fixes (output alpha, motion rounding)

1 participant