Skip to content

perf(libobs-opengl): update a dynamic texture in place on unmap (#3191) - #3382

Merged
zackees merged 2 commits into
masterfrom
perf/3191-gl-texsubimage
Nov 1, 2026
Merged

zackees merged 2 commits into
masterfrom
perf/3191-gl-texsubimage

Conversation

@zackees

@zackees zackees commented Nov 1, 2026

Copy link
Copy Markdown
Member

Refs #3191

RED (guard and measurement) c7aa78b: a new cmocka test, test_gl_dynamic_texture, runs the real libobs-opengl module under xvfb (Mesa software GL on Linux; skips without a display), as test_ffmpeg_mux_unwritable_path already does. That covers the real-GL harness the /investigate note asked for. For 15 frames at 1080p and at 4K it maps a GS_DYNAMIC BGRA texture, writes a frame-specific pattern, unmaps it, reads it back through a stage surface and requires the exact bytes. It prints the median time of map, write and unmap. It passes on master; it is the guard that the in-place update is bit-exact.

GREEN 8b8e4ad: gs_texture_unmap uploads from the pixel buffer with glTexSubImage2D instead of glTexImage2D. The texture's storage is already specified at creation (upload_texture_2d → gl_init_face), so re-specifying level 0 on every frame only invites the driver to reallocate. Format, type and unpack alignment are unchanged, and the test reads back the same bytes.

Measured, honestly a null result on software GL (median ms per map, write and unmap; each line is a separate container run):

master this PR
1080p 4.75, 7.97, 4.45 5.12, 4.95
4K 17.96, 23.48, 18.69 19.70, 21.96

llvmpipe shows no difference beyond its ±25% run-to-run noise. It apparently reuses storage when glTexImage2D repeats the same size, so the reallocation the issue describes doesn't happen there. The win, if any, is on real GPU drivers (apitrace or Nsight on hardware), which I can't run here. Hence Refs, not Fixes: the hardware numbers the issue asks for are still open.

Dropped from the plan: orphaning the pixel buffer with glBufferData(NULL) before each map. On llvmpipe it was slower (5.52 / 21.08 ms in one run), probably a fresh allocation per map, and it can do the same on other drivers. It should come back only with hardware traces that show the map stall.

Tiers: libobs-opengl C only. Tier 2: the new test. Tiers 1, 3 and 4 do not apply. ./lint passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant