Skip to content

Conversation

@dkorkmazturk
Copy link

Gamescope implements explicit synchronization by creating DRM syncobjs from Vulkan timeline semaphores and importing DRM syncobj file descriptors directly as Vulkan timeline semaphores, using VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT for both operations.

However, even though this currently works on Mesa, the "opaque" in the name means that the internal structure of the file descriptor is implementation specific. Which means the DRM syncobj import/export operations used in Gamescope is not guaranteed to work on other drivers such as the proprietary NVIDIA driver, or even the future versions of Mesa.

Since currently there is no portable way to import DRM syncobj timelines into Vulkan timeline semaphores directly, this change refactors the Gamescope explicit sync logic to use DRM sync files while interfacing with Vulkan. Vulkan can export binary semaphores as DRM sync file fds and DRM sync file fds can be imported to Vulkan binary semaphores using VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT.

Fixes: #1662

done_ToVkSemaphore:
drmSyncobjDestroy( g_device.drmRenderFd(), uTmpSyncobj );

return g_device.ImportSyncFd( nSyncFd );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will skip the synchronization (I.e., it creates a VkSemaphore in the signaled state from my understanding) if there are any errors in this function. Is that the intent?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, that is the intent. I still need to take a closer look at error handling in this change, but I am not sure what else can be done if something goes wrong while importing the timeline point here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just wanted to verify my understanding. A CPU stall is another option I suppose, assuming it doesn't hinder forward progress guarantees, but falling through to a no-op and risking corruption is probably better than tossing an error up the stack that the caller probably can't do much with. Probably worth some sort of logging or assert though.

Gamescope implements explicit synchronization by creating DRM syncobjs
from Vulkan timeline semaphores and importing DRM syncobj file
descriptors directly as Vulkan timeline semaphores, using
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT for both operations.

However, even though this currently works on Mesa, the
"opaque" in the name means that the internal structure of the file
descriptor is implementation specific. Which means the DRM syncobj
import/export operations used in Gamescope is not guaranteed to work on
other drivers such as the proprietary NVIDIA driver, or even the future
versions of Mesa.

Since currently there is no portable way to import DRM syncobj timelines
into Vulkan timeline semaphores directly, this change refactors the
Gamescope explicit sync logic to use DRM sync files while interfacing
with Vulkan. Vulkan can export binary semaphores as DRM sync file fds
and DRM sync file fds can be imported to Vulkan binary semaphores using
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT.

Fixes: ValveSoftware#1662
@misyltoad
Copy link
Collaborator

I appreciate you guys taking the time to try and solve this, but I really don't like this approach.

This has massively changed the sync code in a few ugly ways that makes it really annoying to follow and reason about.

I also have some concerns about the manifestation of the sync point that the sync file is made from. Is that all okay? Will we end up stalling on CPU there? I see a WAIT going on now.

Generally, I want to think less about sync and have it be as easy to follow and reason about as I can.

If we want to solve this officially and nicely, we should just make some VK EXT for importing/exporting syncobj officially.

I think that or just NV accepting what we do now would be all I would be willing to merge.

@cubanismo
Copy link

If we want to solve this officially and nicely, we should just make some VK EXT for importing/exporting syncobj officially.

I think that or just NV accepting what we do now would be all I would be willing to merge.

For reference, an extension to implement that functionality is tracked by Khronos here: KhronosGroup/Vulkan-Docs#2473

@Arcitec
Copy link

Arcitec commented Jul 19, 2025

I think that or just NV accepting what we do now would be all I would be willing to merge.

Keep in mind that what you're doing now is not legal in the Vulkan spec. So I respect NVIDIA for refusing to violate the spec even if "Mesa does it".

But if there's interest in turning that violation into an official feature, let's discuss it here: KhronosGroup/Vulkan-Docs#2473

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.

[NVIDIA] Explicit sync on nested Wayland with gamescope upscaling crashes from vkImportSemaphoreFdKHR failed

4 participants