Vulkan GPU particle simulation where the rendering is done with Vulkan graphics, and the simulation with a SYCL kernel sharing data and synchronization with it. Based on the Khronos Vulkan Compute Shader Tutorial.
Modifications from tutorial include:
- The compute shader that updates the particles is replaced with a SYCL kernel run through the Vulkan backend of AdaptiveCpp, see SYCL interop.
AdaptiveCpp creates and owns its own VkInstance and VkDevice, which this
application cannot influence. Rather than sharing them, which would restrict
the layers, extensions, features and queues the renderer is able to ask for,
the two sides keep separate logical devices and share the Vulkan objects they
need to have in common through
external memory
and
external semaphore
opaque file descriptors.
- Device selection (
src/device.cpp) — aVkPhysicalDevicehandle is only meaningful within the instance it came from, so the physical device of this application and that of the SYCL device are matched on theirVkPhysicalDeviceIDProperties::deviceUUID. Sharing memory by file descriptor requires both logical devices to originate from the same physical device. - Particle buffers (
src/buffer.cpp) — the particles of each frame in flight are allocated as SYCL device USM with thesycl::property::usm::AdaptiveCpp_exportableproperty, exported withsycl::AdaptiveCpp_vk_interop::export_memory, and the resulting file descriptor imported into theVkDeviceof this application and bound to a vertex buffer. The buffer created here chooses its own usage flags, so the buffer AdaptiveCpp creates for the same memory does not constrain the renderer. - Synchronization (
src/draw.cpp,src/interop.cpp) — two timeline semaphores are shared in opposite directions. The semaphore AdaptiveCpp signals on kernel completion is imported here, and waited on by the graphics submission at the vertex input stage. The semaphore this application signals on completion of its graphics work is imported into the SYCL context, and waited on by the kernel of a later frame before it overwrites a buffer that is still being read. - Ownership transfers (
src/command_buffer.cpp) — the shared buffers are created withVK_SHARING_MODE_EXCLUSIVE, so the graphics command-buffer acquires each buffer fromVK_QUEUE_FAMILY_EXTERNALbefore reading it and releases it afterwards. Semaphores alone do not make the writes of the other device visible.
This relies on the Vulkan backend interop of AdaptiveCpp, which is only available on Linux, as the opaque file descriptor handle type is POSIX only.
Tested on Ubuntu 24.04 and 26.04. Requires an AdaptiveCpp SYCL compiler, the Vulkan-SDK, and AdaptiveCpp built with its Vulkan backend and the Vulkan backend interop API. See Development Environment for more details on the Vulkan build setup.
Sample command line for building and running the application, the validation layer is enabled in Debug builds:
$ mkdir build && cd build
$ cmake ../ -GNinja -DCMAKE_CXX_COMPILER=acpp -DACPP_TARGETS=generic
$ ninja
$ ACPP_VISIBILITY_MASK=vk ./vkSyclParticleACPP_VISIBILITY_MASK=vk restricts AdaptiveCpp to its Vulkan backend. Without
it a device of another backend may be chosen, which cannot share memory with
the Vulkan objects of this application.
Press Escape key to exit, or close window in GUI.
