You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: libobs-opengl: stop re-specifying the texture on every gs_texture_unmap #3191
libobs-opengl/gl-texture2d.c.h:227 calls glTexImage2D from the PBO after glUnmapBuffer, which may reallocate texture storage every async frame; gs_texture_map (:196-199) maps with no invalidate, so it can wait on the previous upload.
Proposed change
glTexSubImage2D on unmap; glMapBufferRange(GL_MAP_INVALIDATE_BUFFER_BIT) (or orphan with glBufferData(NULL)) on map.
Acceptance criteria
Before/after numbers (frame time of update_async_textures with a 1080p60 and a 4K30 async source (apitrace/Nsight)) in the PR; nothing lands unmeasured.
RED then GREEN; Tier 3 parity stays bit-exact unless this issue says otherwise.
Found by a read-only code scout and not yet measured. Parent: #3176.
Worker note: I skipped this for now. Every test/cmocka graphics test uses a fake device (for example test_texture_render.c), so a GL change here can't be checked in CI. Doing it properly needs a real-GL harness (EGL surfaceless on Mesa llvmpipe) that runs map, write, unmap and readback, plus a GPU-traced frame-time measurement. Whoever takes it should build that harness first.
/investigate needs a real-GL harness (EGL surfaceless on Mesa llvmpipe) for the RED test plus a GPU-traced frame-time measurement; CI graphics tests use a fake device.
Claiming: perf: libobs-opengl: stop re-specifying the texture on every gs_texture_unmap
On the /investigate note: the real-GL harness already exists in Tier 2. test_ffmpeg_mux_unwritable_path and test_encoder_error_stop start libobs with GRAPHICS_MODULE_PATH set to libobs-opengl and run on Mesa software GL under xvfb-run on Linux, skipping without a display. A texture test can use the same setup.
Plan, one PR:
RED: a new cmocka test in that style. It creates a GS_DYNAMIC BGRA texture (1920×1080 and 3840×2160) and, for several frames, runs gs_texture_map, writes a frame-specific pattern, runs gs_texture_unmap, then reads the texture back through a stage surface and requires the exact bytes. It also records the GL texture storage identity across unmaps: the texture name and GL_TEXTURE_IMMUTABLE_FORMAT/size via glGetTexLevelParameteriv, and counts glTexImage2D calls through a wrapped gl entry point if the loader allows it. Otherwise it checks the timing of a map/unmap loop. The readback check is the bit-exact guard; the RED failure is the per-unmap re-specification.
GREEN: gs_texture_unmap uploads from the PBO with glTexSubImage2D (storage was already specified at creation). gs_texture_map orphans the PBO with glBufferData(NULL) before mapping, so it doesn't wait on the previous frame's upload.
Numbers: the map/write/unmap loop time per frame at 1080p and 4K, before and after, on software GL in the test. I'll say plainly that llvmpipe is not a GPU. An apitrace/Nsight frame time on real hardware isn't available here.
Claim bot:@zackees, this can't be claimed yet: it needs investigation before anyone can implement it. Comment Claiming: investigation to take the research.
Change tried:gs_texture_map maps with glMapBufferRange(GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT) instead of glMapBuffer(GL_WRITE_ONLY). This matches D3D11's D3D11_MAP_WRITE_DISCARD in gs_texture_map (d3d11-subsystem.cpp.hpp:2742), so neither backend keeps the old contents across a map.
Result:test_gl_dynamic_texture passes, with exact bytes on every frame. Its median map + write + unmap times, under Mesa llvmpipe and xvfb, 3 runs each:
That's no difference. llvmpipe completes each upload synchronously at unmap, so there is never a pending upload for the invalidate to skip. The win this half targets (not stalling on the previous frame's DMA) only exists on a real GPU driver.
What's needed to land it: one before/after on real hardware, either test_gl_dynamic_texture on a Mesa radeonsi/iris or NVIDIA box, or an apitrace of update_async_textures with a 1080p60 async source. The one-hunk change is ready. Anyone with a GPU host can take it; I can't measure it on this headless host.
Backlog verification on origin/master d3953a2: the unmap half is already merged in #3382, commit 7f407fd. Checked libobs-opengl/gl-texture2d.c.h: gs_texture_unmap uses glTexSubImage2D (line 232); gs_texture_map still uses glMapBuffer(GL_WRITE_ONLY) (line 199). Do not recreate the in-place upload fix or its real-GL test_gl_dynamic_texture harness. What remains is hardware evidence at the requested async-source workloads, and a map-stall optimization only if those real GPU traces demonstrate a benefit. The thread already measured invalidate-map as a null result on llvmpipe, so that software-only timing is not acceptance evidence. Keep open for a GPU-equipped worker; no GPU measurement was run by this cleanup.
Activity
zackees commentedon Oct 31, 2026
Worker note: I skipped this for now. Every
test/cmockagraphics test uses a fake device (for exampletest_texture_render.c), so a GL change here can't be checked in CI. Doing it properly needs a real-GL harness (EGL surfaceless on Mesa llvmpipe) that runs map, write, unmap and readback, plus a GPU-traced frame-time measurement. Whoever takes it should build that harness first.zackees commentedon Oct 31, 2026
/investigate needs a real-GL harness (EGL surfaceless on Mesa llvmpipe) for the RED test plus a GPU-traced frame-time measurement; CI graphics tests use a fake device.
zackees commentedon Nov 1, 2026
Claiming: perf: libobs-opengl: stop re-specifying the texture on every gs_texture_unmap
On the /investigate note: the real-GL harness already exists in Tier 2.
test_ffmpeg_mux_unwritable_pathandtest_encoder_error_stopstart libobs withGRAPHICS_MODULE_PATHset tolibobs-opengland run on Mesa software GL underxvfb-runon Linux, skipping without a display. A texture test can use the same setup.Plan, one PR:
GS_DYNAMICBGRA texture (1920×1080 and 3840×2160) and, for several frames, runsgs_texture_map, writes a frame-specific pattern, runsgs_texture_unmap, then reads the texture back through a stage surface and requires the exact bytes. It also records the GL texture storage identity across unmaps: the texture name andGL_TEXTURE_IMMUTABLE_FORMAT/size viaglGetTexLevelParameteriv, and countsglTexImage2Dcalls through a wrappedglentry point if the loader allows it. Otherwise it checks the timing of a map/unmap loop. The readback check is the bit-exact guard; the RED failure is the per-unmap re-specification.gs_texture_unmapuploads from the PBO withglTexSubImage2D(storage was already specified at creation).gs_texture_maporphans the PBO withglBufferData(NULL)before mapping, so it doesn't wait on the previous frame's upload.First PR within a day.
github-actions commentedon Nov 1, 2026
Claim bot: @zackees, this can't be claimed yet: it needs investigation before anyone can implement it. Comment
Claiming: investigationto take the research.zackees commentedon Nov 1, 2026
The map half, measured. Not landing it yet.
Change tried:
gs_texture_mapmaps withglMapBufferRange(GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)instead ofglMapBuffer(GL_WRITE_ONLY). This matches D3D11'sD3D11_MAP_WRITE_DISCARDings_texture_map(d3d11-subsystem.cpp.hpp:2742), so neither backend keeps the old contents across a map.Result:
test_gl_dynamic_texturepasses, with exact bytes on every frame. Its median map + write + unmap times, under Mesa llvmpipe and xvfb, 3 runs each:That's no difference. llvmpipe completes each upload synchronously at unmap, so there is never a pending upload for the invalidate to skip. The win this half targets (not stalling on the previous frame's DMA) only exists on a real GPU driver.
What's needed to land it: one before/after on real hardware, either
test_gl_dynamic_textureon a Mesa radeonsi/iris or NVIDIA box, or an apitrace ofupdate_async_textureswith a 1080p60 async source. The one-hunk change is ready. Anyone with a GPU host can take it; I can't measure it on this headless host.perf(libobs-opengl): update a dynamic texture in place on unmap (obs-…
zackees commentedon Nov 7, 2026
Backlog verification on origin/master d3953a2: the unmap half is already merged in #3382, commit 7f407fd. Checked libobs-opengl/gl-texture2d.c.h: gs_texture_unmap uses glTexSubImage2D (line 232); gs_texture_map still uses glMapBuffer(GL_WRITE_ONLY) (line 199). Do not recreate the in-place upload fix or its real-GL test_gl_dynamic_texture harness. What remains is hardware evidence at the requested async-source workloads, and a map-stall optimization only if those real GPU traces demonstrate a benefit. The thread already measured invalidate-map as a null result on llvmpipe, so that software-only timing is not acceptance evidence. Keep open for a GPU-equipped worker; no GPU measurement was run by this cleanup.