Skip to content

Spout2 source does not synchronize texture accesses #86

Description

@hoshinolina

Spout2 expects shared texture accesses to use a Keyed mutex to synchronize access to the texture with the sender. In OBS, the equivalent functionality is implemented here, which is called via gs_texture_acquire_sync().

The plugin does not currently call those functions as far as I can tell, so it is doing unsynchronized texture reads. At the very least that can cause tearing, but it could be worse. If the sender app is rendering directly to the texture and not just copying a complete frame, it would cause OBS to read out incomplete renders, causing glitching. Additionally, if the texture uses a lossless compressed format (which, as far as I can tell, drivers are allowed to transparently do), it would cause corruption as compressed formats cannot support unsynchronized accesses.

To correctly synchronize, the plugin needs to bracket the texture draw in gs_texture_acquire_sync(context->texture, 0, 67); and gs_texture_release_sync(context->texture, 0); (checking the return value of the first, if it is not 0 then the acquire failed and rendering should not proceed, nor should release_sync be called).

Obviously there is some cost to the synchronization and people are using the plugin today without it, so maybe it should be a configurable option? I don't have a reproducer for the issue, I'm just filing this because I'm deep in spout2 internals and I noticed the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions