WIP: fix(video): decode movie pictures on a worker #2912

Closed
omgitsgela wants to merge 3 commits from omgitsgela/Longshot:fix/movie-decode-worker into main
Member

Summary

A movie's pictures were decoded on the thread that has to hand one to the game every 16.7 ms. A 3.2 to 4.0 ms decode, with a worst picture of 94 to 128 ms, therefore sat directly in the Acquire path. On the Deck LCD the opening movie skipped 532 pictures in its first minute and 593 over all 5,947 pictures.

This changes the movie path in three parts:

  1. host/nn_video.c: each decoder owns a native worker. dec_submit copies the compressed packet into an owned packet and wakes the worker; the worker decodes into the existing bounded host-picture ring; dec_acquire only leases a free guest pool, detaches a ready picture, copies, and returns the completed fence. dec_flush, dec_stop and dec_finalize join the worker. Acquire no longer decodes or performs the catch-up decode.
  2. gpu/vk/vk_draw.cpp: the movie upscale pipeline and one dummy dispatch are made at startup, so the first movie frame no longer pays the driver's first-dispatch compile.
  3. gpu/vk/vk_shader.cpp: a program rejected as a network left out on this card is remembered by key in cache/longshot_left_out.bin. Later runs skip its translation before doing it again. No program keys are hardcoded.

Fixes #73.

Testing

Tested: Steam Deck LCD (AMD Custom GPU 0405, RADV VANGOGH, Vulkan 1.4), base ec889d9d with the n320-fix pack, HOS_VIDEO_LOG=1, 1280x800, 60 fps cap, test user copy. The opening 5,947-picture movie was measured over its first 60 seconds and over the whole movie. The stock base was staged from the same base without the pack and run through the same harness.

The fix log contains vk: movie upscale pipeline prewarmed: yes and vk: movie upscale dispatch prewarmed: yes. Its first launch paid the renderer-changing preparation (309.6 s); the full measurement was the warm second launch.

Still to test:

  • Windows: the Media Foundation AV1 path has not run the worker; it shares decode_next but its callback thread affinity needs its own review (by hand, on a Windows PC with an AV1 movie).
  • Other Linux GPUs: run the same opening movie on an AMD discrete card and an Intel GPU, expecting no Acquire stalls and no regression in the non-AV1 movies (by hand or @Beanstalk).
  • Unit tests: the existing video fixtures still model the old Acquire-decodes path and need adapting to the worker (see checklist).

Measurements

Verdict: The worker removes nearly all of the movie's skipped pictures: 532 to 16 in the first minute and 593 to 34 over the whole 5,947-picture movie on the Deck LCD.

Setup: Steam Deck LCD, RADV VANGOGH, Vulkan 1.4, 1280x800, 60 fps cap, same base ec889d9d, test user, one first-minute run and one full-movie run per arm. The fix's full run was warm (the first launch prepared the changed renderer).

Before: stock base ec889d9d After: worker pack
Skipped in the first 60 s 532 16
First six skip events [6,7,1,1,2,1,1,1] (18) [2,2,1,1,1,2,1,1] (9)
Skipped over the full 5,947 pictures 593 34
Decode each 4.0 ms 3.2 ms
Worst decode 128.4 ms 94.3 ms
Times the last picture was shown again 23 1514
Submissions put off while 16 waited 3924 4583

Risks

  • The worker adds one native thread and an owned compressed-packet queue per decoder. The host-picture ring stays at its production MAX_QUEUE of 8 pictures; the worker blocks at the queue limit instead of discarding a picture.
  • dec_flush, dec_stop and dec_finalize now join the worker. The tests for Flush, EOS and finalize still need to be adapted to the worker; a hang there would be a lifecycle bug, not a picture-timing one.
  • The Media Foundation path is not exercised on the Deck. Its callback still calls queue_frame, and the worker life-cycle is shared; it needs a Windows run.
  • The startup cache is written on first use. A fresh install still pays the first translation (and the first dispatch prewarm covers that cost separately); later launches use the cache. The cache file is inside the game's cache/.
  • Nothing changes in saves or longshot_options.ini.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (the video fixtures that model the old Acquire-decodes path still need adapting; this is the remaining test work).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here. The runtime A/B is above; the source fixtures are being adapted.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • MKWVK_API_VERSION bumped (MkwVkHost or MkwVkRenderer in gpu/vk/vk_api.h changed). No API change.
  • The SPIR-V headers regenerated (a shader changed). No shader change.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Linux built here; Windows still to run.
  • Screenshots of the same spot on main and here, for a change that shows on screen. The change is timing, not a visual.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Assisted-by: Hermes Agent

## Summary A movie's pictures were decoded on the thread that has to hand one to the game every 16.7 ms. A 3.2 to 4.0 ms decode, with a worst picture of 94 to 128 ms, therefore sat directly in the Acquire path. On the Deck LCD the opening movie skipped 532 pictures in its first minute and 593 over all 5,947 pictures. This changes the movie path in three parts: 1. `host/nn_video.c`: each decoder owns a native worker. `dec_submit` copies the compressed packet into an owned packet and wakes the worker; the worker decodes into the existing bounded host-picture ring; `dec_acquire` only leases a free guest pool, detaches a ready picture, copies, and returns the completed fence. `dec_flush`, `dec_stop` and `dec_finalize` join the worker. Acquire no longer decodes or performs the catch-up decode. 2. `gpu/vk/vk_draw.cpp`: the movie upscale pipeline and one dummy dispatch are made at startup, so the first movie frame no longer pays the driver's first-dispatch compile. 3. `gpu/vk/vk_shader.cpp`: a program rejected as a network left out on this card is remembered by key in `cache/longshot_left_out.bin`. Later runs skip its translation before doing it again. No program keys are hardcoded. Fixes #73. ## Testing **Tested:** Steam Deck LCD (AMD Custom GPU 0405, RADV VANGOGH, Vulkan 1.4), base `ec889d9d` with the `n320-fix` pack, `HOS_VIDEO_LOG=1`, 1280x800, 60 fps cap, test user copy. The opening 5,947-picture movie was measured over its first 60 seconds and over the whole movie. The stock base was staged from the same base without the pack and run through the same harness. The fix log contains `vk: movie upscale pipeline prewarmed: yes` and `vk: movie upscale dispatch prewarmed: yes`. Its first launch paid the renderer-changing preparation (309.6 s); the full measurement was the warm second launch. **Still to test:** - Windows: the Media Foundation AV1 path has not run the worker; it shares `decode_next` but its callback thread affinity needs its own review (by hand, on a Windows PC with an AV1 movie). - Other Linux GPUs: run the same opening movie on an AMD discrete card and an Intel GPU, expecting no Acquire stalls and no regression in the non-AV1 movies (by hand or @Beanstalk). - Unit tests: the existing video fixtures still model the old Acquire-decodes path and need adapting to the worker (see checklist). ## Measurements **Verdict:** The worker removes nearly all of the movie's skipped pictures: 532 to 16 in the first minute and 593 to 34 over the whole 5,947-picture movie on the Deck LCD. Setup: Steam Deck LCD, RADV VANGOGH, Vulkan 1.4, 1280x800, 60 fps cap, same base `ec889d9d`, test user, one first-minute run and one full-movie run per arm. The fix's full run was warm (the first launch prepared the changed renderer). | | Before: stock base `ec889d9d` | After: worker pack | |---|---|---| | Skipped in the first 60 s | 532 | **16** | | First six skip events | `[6,7,1,1,2,1,1,1]` (18) | `[2,2,1,1,1,2,1,1]` (9) | | Skipped over the full 5,947 pictures | 593 | **34** | | Decode each | 4.0 ms | 3.2 ms | | Worst decode | 128.4 ms | 94.3 ms | | Times the last picture was shown again | 23 | 1514 | | Submissions put off while 16 waited | 3924 | 4583 | ## Risks - The worker adds one native thread and an owned compressed-packet queue per decoder. The host-picture ring stays at its production `MAX_QUEUE` of 8 pictures; the worker blocks at the queue limit instead of discarding a picture. - `dec_flush`, `dec_stop` and `dec_finalize` now join the worker. The tests for Flush, EOS and finalize still need to be adapted to the worker; a hang there would be a lifecycle bug, not a picture-timing one. - The Media Foundation path is not exercised on the Deck. Its callback still calls `queue_frame`, and the worker life-cycle is shared; it needs a Windows run. - The startup cache is written on first use. A fresh install still pays the first translation (and the first dispatch prewarm covers that cost separately); later launches use the cache. The cache file is inside the game's `cache/`. - Nothing changes in saves or `longshot_options.ini`. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (the video fixtures that model the old Acquire-decodes path still need adapting; this is the remaining test work). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. The runtime A/B is above; the source fixtures are being adapted. - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [ ] A check under `tests/` that reads changed source is updated, not weakened. - [ ] `MKWVK_API_VERSION` bumped (`MkwVkHost` or `MkwVkRenderer` in `gpu/vk/vk_api.h` changed). No API change. - [ ] The SPIR-V headers regenerated (a shader changed). No shader change. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Linux built here; Windows still to run. - [ ] Screenshots of the same spot on `main` and here, for a change that shows on screen. The change is timing, not a visual. - [ ] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. Assisted-by: Hermes Agent
fix(video): decode movie pictures on a worker
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
PR description / Title and description (pull_request_target) Successful in 15s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
CI / Workflow lint (actionlint) (pull_request) Successful in 18s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Failing after 20m2s
ea2bacc6bc
The movie decoder decoded on the Acquire thread, so a 3.2-4.0 ms picture (worst 94-128 ms) sat in the path that must return one picture every 16.7 ms. A movie skipped 532 pictures in its first minute and 593 over all 5,947 on the Deck LCD.

Decode on a per-decoder native worker instead. Submissions queue owned packets; the worker decodes them into the existing bounded host-picture ring; Acquire only leases a free pool slot and copies a ready picture. Flush, Stop and Finalize join the worker. Acquire no longer decodes or catches up.

Also prewarm the movie upscale compute pipeline and its first dispatch at startup, and remember left-out network keys in cache/longshot_left_out.bin so later runs skip that translation. No program keys are hardcoded.

Measured on the Deck LCD against the same ec889d9d base: first minute 532 -> 16 skipped, full 5,947 movie 593 -> 34 skipped, decode 4.0 -> 3.2 ms, worst 128.4 -> 94.3 ms.
Author
Member

Tested in game: Steam Deck LCD (RADV VANGOGH, Vulkan 1.4), base ec889d9d: first-minute skips 532 -> 16; full 5,947-picture movie 593 -> 34; decode 4.0 -> 3.2 ms, worst 128.4 -> 94.3 ms; startup prewarm lines present.

Tested in game: Steam Deck LCD (RADV VANGOGH, Vulkan 1.4), base ec889d9d: first-minute skips 532 -> 16; full 5,947-picture movie 593 -> 34; decode 4.0 -> 3.2 ms, worst 128.4 -> 94.3 ms; startup prewarm lines present.
Author
Member

Superseded by #2913. This branch was based on ec889d9d and carried two unrelated BC3 pilot commits; #2913 is the same worker/prewarm/cache change rebased onto current main d193d12d with only the three movie files.

Superseded by #2913. This branch was based on ec889d9d and carried two unrelated BC3 pilot commits; #2913 is the same worker/prewarm/cache change rebased onto current main d193d12d with only the three movie files.
omgitsgela closed this pull request 2026-11-30 17:30:28 +00:00
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
PR description / Title and description (pull_request_target) Successful in 15s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
CI / Workflow lint (actionlint) (pull_request) Successful in 18s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Failing after 20m2s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2912
No description provided.