mirror of
https://github.com/games-on-whales/gst-wayland-display.git
synced 2026-10-15 12:51:57 +00:00
[PR #67] [CLOSED] fix(cuda): give each CUDAContext wrapper its own reference #66
Labels
No labels
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
games-on-whales/gst-wayland-display#66
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/games-on-whales/gst-wayland-display/pull/67
Author: @xerhab
Created: 10/14/2026
Status: ❌ Closed
Base:
stable← Head:fix/cuda-context-slot-ownership📝 Commits (1)
58c55f7fix(cuda): give each CUDAContext wrapper its own reference📊 Changes
2 files changed (+149 additions, -98 deletions)
View changed files
📝
gst-plugin-wayland-display/src/waylandsrc/imp.rs(+8 -13)📝
wayland-display-core/src/utils/allocator/cuda/mod.rs(+141 -85)📄 Description
Summary: An application that hands
waylanddisplaysrcone shared CUDA context for every pipeline (as Wolf does) no longer loses a reference to it per pipeline, so streams stop freezing after a few reconnects.Why
Answering NEED_CONTEXT with a context the application keeps loses one reference per pipeline. Wolf caches one (
app_state->gst_context), so after a few streams it is finalized under a live pipeline:gst_cuda_context_push: assertion 'GST_IS_CUDA_CONTEXT (ctx)' failed,Cached CUDA context appears to be invalid (push failed),gst_object_unref: assertion 'ref_count > 0' failed, then the next stream's encoder freezes.Root cause: the answer re-enters
set_context()whilenew_from_gstreamer()is still insidegst_cuda_ensure_element_context(). The innernew_from_set_context()fills the slot with the one referencegst_cuda_handle_set_context()transfers and stores a wrapper owning it. The outer call sees the slot go from NULL to set, treats that as a transfer to itself, and builds and drops a second wrapper owning the same reference.adopt_slot_ref()(#42) handles the helper creating the context, where the slot is already set at re-entry; the slot's before/after values cannot tell the two apart.What changed
CudaContextSlot) owns the helpers'(transfer full)reference and releases it with the element.CUDAContextbuilt from it takes its own reference (from_slot), so no call infers a transfer. Replacesadopt_slot_ref().Settingsonto the element, since the helpers write it while re-enteringset_context(), which takes theSettingslock.Risk
Low. Only the CUDA context acquisition in
waylanddisplaysrcchanges. A mistake would show as a leaked context per element (memory) or as the same over-release. Both paths were checked with refcounts and the leaks tracer (below). Revert this commit to roll back.Testing
QA result: PASS — refcounts checked on a GPU for both context sources (application-provided and self-created); regression test proven to fail on the old rule.
Not tested: a full Wolf build with this commit (tested with the plugin built against GStreamer 1.26.7 from Wolf's base image); AMD/Intel paths (untouched,
cudafeature only).Test evidence
test_application_context_survives_pipelines: answers NEED_CONTEXT from a bus sync handler that re-entersnew_from_set_context()on the same slot, three times, and checks the application's context returns to its baseline refcount. With the old ownership rule restored it fails (left: 1, right: 2).GstCudaContexthanded to sixwaylanddisplaysrc ! fakesinkpipelines in turn), RTX 3090, GStreamer 1.26.7. Before: ref_count 2 → 1 → 0 (finalized,invalid unclassed pointerCRITICALs) by the 2nd pipeline. After: 2 after every pipeline.gst_deinit(), before and after.cargo fmt --all --checkclean.test_cuda_bufferfails on hosts without/dev/dri/renderD129(hardcoded node), with or without this change.Follow-ups
test_cuda_bufferhardcodes/dev/dri/renderD129— not changed here.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.