I'm writing a program that uses libev to wait on many file descriptors. When data comes in, a vulkan compute shader gets run to process the data. The completion of that shader is signalled with a fence. I'd rather not block my event loop to wait for completion to return results.
I originally tried getting a file descriptor using VkGetFenceFdKHR
, with the VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT
set on the fence to get a sync file, but one of the computers that i'm targetting doesn't support that feature.
For the time being, i'm just polling the fences with a timer and vkGetFenceStatus
, but that feels really inefficient. is there a better way to wake up my event loop?
I don't know if this is a better way, as I have no real experience with file-descriptor based synchronization. But here's an alternative.
You can create a thread whose sole purpose is to block on the fence, after which it will signal an FD. That's probably better in some respects than your timer&polling API, as it's not wasting CPU cycles. But it does require an extra thread wake-up before the thread that's waiting on the FD can see it, so that may delay responsiveness.