5 Commits

Author SHA1 Message Date
Matthew Stanley 81dc805e8d Preserve final-pass history and reset each shader chain clock on reload 2026-10-24 10:25:45 -07:00
yacineolivier-maker 3ad83c910b Post effects: depth and history inputs, u_time / u_proj, live uniforms
For title-specific lighting presets ([video] post_shader):
- `input <sampler> depth`: view depth sz (GTE screen z) of the presented frame,
  R32F at window size, rebuilt from the surfaces' PGXP depth; 0 where nothing
  3D drew. Only built while a loaded chain reads it.
- `input <sampler> history`: the pass's own target from the last real frame
  (trails, temporal filters); generated frames do not update it.
- `u_time` (seconds since the chain loaded) and `u_proj` (latest GTE
  projection: 240/H, screen centre in uv, aspect) in every pass.
- Live uniforms: psx_host_set_post_uniform(name, x, y, z, w) sets a preset
  `uniform` from game state (e.g. a light source projected to the screen);
  the preset value applies until the first call.
- Debug: TCP {"cmd":"post_shader"} reports the loaded preset, its parse status
  and the live values; {"cmd":"post_shader","path":"..."} reloads a preset
  (or loads another) without restarting, for shader work.
docs/POST_EFFECTS.md documents the inputs and the uniforms.

Used by a lighting preset for R4 (sun and tunnel light shafts, lamp halos,
speed streaks, paint reflections on the player's car from live car pose),
about 0.7 ms of GPU at 1080p on an RTX 3060.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rkyma8rbyPiccs9n2bkyG6
2026-10-24 09:04:33 -07:00
Shokunin 8dbe2165ff bloom: cost of real and generated frames
Smooth motion lost most of its generated frames with bloom on (R4 race,
120 Hz: ~30% of bloom-off). Measured and fixed in order of cost:

- Depth-stencil blits (CPU milliseconds each on macOS) are gone:
  generation surfaces no longer copy the marks and are not marked while
  drawn (generated frames reuse the newer real frame's mask); the
  native-wide centre copy is colour only again and the mask takes the
  centre's marks from the hr surface; the mask itself is resolved in the
  presented surface's own pixels through an R8 target that shares the
  surface's depth-stencil renderbuffer, then mapped to the window.
- Marking needs one pass per batch, not two: 3D batches only set, 2D
  opaque ones only clear, semi-transparent ones only set; only batches of
  unknown make (queued replays, lines) still do both.
- No full-size copy of the image: `source_down` (a blit straight to the
  pass's size) feeds the bright pass, and the composite screen-blends onto
  the window (`blend screen`; unlit pixels are discarded, so they keep their
  exact value). The debug split/bloom-only views go with the copy.

M4, R4 race, render thread + reprojection, PSX_FRAME_GEN_FORCE, a host
loaded by other work (absolute rates low): bloom pass on real / generated
frames 1.2 / 0.7 ms at 1080p, 1.3 / 0.9 ms at 1440p, 2.6 / 1.6 ms at 4K
(glFinish-bracketed); generated frames with bloom 79-80% of bloom-off at
all three (was ~30%). A 1/8-resolution blur chain was tried and kept no
more frames, so the 1/4 chain (the look) stays.

Tests: parser (blend, source_down, bloom preset reads no full copy), GL
fixture (source_down + blend screen chain exact; HUD and mask checks
unchanged), FXAA unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 04:03:35 -07:00
Shokunin 8eccea1612 post effects: no per-frame GL queries; CRLF presets tested
- Uniform locations are looked up once per program (each lookup can be a
  driver round trip on a threaded GL; the executor runs per present,
  generated frames included).
- State save queries only capability flags and the viewport. The mask pass
  no longer clears (it draws 0 then 1), so the clear colour is never
  touched; the present's window target and texture unit 0 are left bound.
  The GL fixture checks exactly that contract.
- postfx_chain_test: a preset with CRLF line ends parses the same, and the
  import check writes its shader in binary mode (it failed on Windows).
- docs/POST_EFFECTS.md: `generated reuse`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 02:15:46 -07:00
Shokunin 74dadc6004 GL: one post-effect pipeline; bloom and FXAA as built-in chains, user chains via [video] post_shader
Post effects now run as chains of full-screen fragment passes on one
executor (gl_postfx.inc), as asked in review. A chain is a small .pfx preset
(postfx_chain.c, GL-free): passes with a shader (a file next to the preset or
builtin:<name>), inputs (source, the optional primitive-derived mask,
previous or a named earlier pass), a scale, format, filter and uniforms.
The executor owns target allocation and lifetime, program build/cache,
uniform binding (u_rcp, u_size, u_org) and GL state save/restore.

Stages, in order, each from a fresh copy of the image: the built-in "bloom"
chain ([video] bloom), a user chain ([video] post_shader / PSX_POST_SHADER,
elective, off by default), and the built-in "fxaa"/"fxaa_hq" chain
([video] antialiasing_mode). FXAA folds in as a one-pass chain and its
output is byte-identical to the former fixed pass; it still runs on real
frames only. Generated (Smooth motion) frames run bloom and the user chain.

The "may glow" mask is an optional pipeline input: draws keep stencil bit 1
only while an active chain reads `mask`, and the window-sized mask texture is
built once per present for the chains that use it.

Tests: postfx_chain_test (format, built-ins, errors, file import, no GL);
gl_bloom_test gains an imported two-pass chain (byte-exact invert), the mask
input (HUD unlit, 3D lit), a bad preset, a pass that does not compile, and GL
state restored with bloom + a mask chain + FXAA on, all on the caller thread
and the render thread. docs/POST_EFFECTS.md documents the format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 02:15:46 -07:00