Skip to content

vo_gpu_next: only re-upload OSD textures when they change - #18352

Open
rlauuzo wants to merge 2 commits into
mpv-player:masterfrom
rlauuzo:osd-upload-cache
Open

vo_gpu_next: only re-upload OSD textures when they change#18352
rlauuzo wants to merge 2 commits into
mpv-player:masterfrom
rlauuzo:osd-upload-cache

Conversation

@rlauuzo

@rlauuzo rlauuzo commented Aug 8, 2026

Copy link
Copy Markdown

update_overlays() uploaded every sub_bitmaps item into its texture on every call, and draw_frame() calls it unconditionally, so a static OSD was re-uploaded at display refresh rate rather than at the rate it actually changes.

vo_gpu already avoids this: gen_osd_cb() compares sub_bitmaps.change_id against a cached copy and skips upload_osd() when they match. osd_render() computes that change_id for both VOs, so vo_gpu_next had the information and simply did not read it. Cache the id next to the texture and skip pl_tex_upload() when it matches.

A change_id of 0 means the texture contents are unknown (osd.h guarantees 0 is never a real id), and it is written at every point where that becomes true: when an entry takes a recycled texture from the sub_tex pool, and on reallocation, before pl_tex_recreate() runs, so a failed recreate cannot leave a stale id behind. The upload check itself is then a single comparison.

pl_tex_recreate() is now only called when the size or format actually has to change: libplacebo documents that the call invalidates the texture's contents even when it does not reallocate, so calling it every frame would defeat the cache by contract. The old code could call it unconditionally because it always uploaded straight afterwards.

AI Disclosure: The patch was written with AI assistance. I understand what it does and why. The change is submitted under the same licence as video/out/vo_gpu_next.c (LGPLv2.1+).

`update_overlays()` uploads every `sub_bitmaps` item to its texture on every call, and `draw_frame()` calls it unconditionally, so an OSD that is not changing is re-uploaded at the display refresh rate rather than at the rate it actually changes.

`vo_gpu` already avoids this: `gen_osd_cb()` compares `sub_bitmaps.change_id` against a cached copy and skips `upload_osd()` when they match. `osd_render()` computes that `change_id` for both VOs, so `vo_gpu_next` has the information and simply does not read it. This caches the id next to the texture and skips `pl_tex_upload()` when it matches.

It also restricts `pl_tex_recreate()` to the cases where the size or format really has to change. That is not tidying: a reallocated texture has undefined contents, so the cached id would stop describing it. Restricting the call also removes any dependence on `pl_tex_recreate()` preserving contents when it is a no-op.
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