Skip to content

Model K (HIP): exposure rule on the GPU, exact input stage by default, no reset on a size change - #198

Merged
phantoslayer21 merged 3 commits into
mainfrom
k/hip-exposure
Nov 14, 2026
Merged

phantoslayer21 merged 3 commits into
mainfrom
k/hip-exposure

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Refs #15. Stacked on #194 (the diff here is against that branch; once #194 is merged it is against main).

Second piece of bringing Preset K back: the HIP side of the exposure rule, the exact input stage as the default, and no history reset on a render-size change. All of it was already written for the private line; this is the part that the D3D12 ports and the visual fixes build on.

What changes

  • k_io.hip k_expo_scalars: now (st, src, measured, xs, KExpoArgs). [HDR] E_cur is the front end's value, the game's exposure texel, or 1 when the game gives none; E_aux is the measured auto-exposure value when it ran, else E_cur; E_prev is the previous frame's E_cur (E_cur on the first frame and on a reset). [LDR] everything is 1. The raw values go to a 4-float state; the scalars then use the same FP32 operations as k_io.py. KExpoArgs is {value; src_mode, aux, first, hdr, reset; e1, e2, inv_pi} (36 bytes).
  • runtime_k.cpp/.h:
    • applies the rule; auto-exposure (HDR only) also runs next to a game texture and then acts only through lambda;
    • resets only on the game's flag and the first frame (a render-size change keeps the history);
    • runs the input stage from k_io_exact.co (tag kx) unless k_fast_in=1, k_in_exact=0 or k_fast=1 is named; k_in_exact=1 with either fast option is refused;
    • new buffers exposure.pair ([E_cur, E_prev, E_aux], raw) and exposure.measured;
    • k_expo_rule=v051 restores the old rule for A/B only.
  • runner/build.py: k_io_exact.co is built into a K-enabled runtime library.
  • k_frame.py, k_io.py: KFrame and reference_frame apply the rule (game_exposure, measured, exposure_scale) and the new reset behaviour; KExpoArgs has the new fields.
  • Tests: test_k_exposure_rule.py gains reference_frame tests with recorder stages (CPU); test_k_frame_emu.py (needs the Linux lane emulator, skipped on Windows) and test_k_runtime_gpu.py (GPU) follow the new behaviour; the GPU test adds the exposure-source and reset cases and the exact/fast input checks.
  • Docs: FORMATS.md, README.md for the new kernel signature, options and reset rule.

No approximation is added: the exact input stage becomes the default, and the opt-in options that already existed keep their meaning.

Tested

  • CPU: python -m unittest clean.k.tests.test_k_exposure_rule: 7 tests pass.
  • GPU (a Radeon RX 9000-series card, one slot, runtime library built from this branch with the HIP SDK): python -m unittest -v clean.k.tests.test_k_runtime_gpu: 20 tests pass (HDR and LDR, value / texel / auto-exposure sources, texel with auto-exposure, pre-exposure, raw inputs, k_head=full, reset=2, k_fast_in=1, network=fused16, k_expo_rule=v051). The runtime's frames equal KFrame's bit for bit.
  • public_gates.py: must-pass gates pass; LOOK counts equal main's.

Not tested

  • test_k_frame_emu.py (skipped without the Linux lane emulator).
  • Games.
  • D3D12 (no D3D12 change here).

…ge by default, no history reset on a render-size change

Refs #15. k_expo_scalars takes the game's exposure (value, texel, or none) as E_cur and the auto-exposure value as E_aux, keeps the previous frame's E_cur for E_prev, and writes the raw values for the buffers exposure.pair and exposure.measured. The runtime applies the rule, runs auto-exposure beside a game texture, and resets history only on the game's flag and the first frame. The input stage is the exact one (k_io_exact.co, embedded in the runtime library) unless k_fast_in=1, k_in_exact=0 or k_fast=1 is named. KFrame and reference_frame take the same rule and reset behaviour. k_expo_rule=v051 restores the old rule for A/B.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 merged commit e231746 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the k/hip-exposure 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.

1 participant