nvpro-samples / vk_denoise

Denoising a Vulkan ray traced image using OptiX denoiser
Apache License 2.0
89 stars 7 forks source link

Synchronization problems between Vulkan and CUDA #2

Open antaalt opened 4 years ago

antaalt commented 4 years ago

I think there might be synchronization issues with the denoiser between CUDA and Vulkan. The denoiser is run once per frame after raytracing the image, and before tonemapping it.

But the command buffer is being built then submitted to the graphics queue while the optix denoiser is run immediatly while building command buffer and it waits for completion with cudaStreamSynchronize. Which means that each frame, the denoiser will denoise the previous frame instead of the one that was just processed, as the command buffer is not submitted yet. The first frame will then be an undefined output.

Is this an intended features ?

wumo commented 4 years ago

Yeah. also interested in how optix syncs with vulkan.

antaalt commented 4 years ago

I managed to fix this by using external semaphore to sync vulkan command buffers with cuda streams used by the optix 7 denoiser. There is a good example in the CUDA SDK for synchronization between Cuda and Vulkan here vulkanCUDASinewave.cu. This way, you can wait for a semaphore to be signaled by a vulkan command buffer before running the Cuda stream.