You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
update Vulkan sample with external memory and semaphore sharing (#59)
* started to add interop functions but still crashes
* slightly working version
* successfully create an image from external memory
* revert a few other testing changes
* basic memory sharing is working
* fix dummy object codepath with host copy
* fix validation errors
* start to add external semaphore support
* add support for synchronization via semaphores
* reduce verbosity by default, start to add Linux support
* fix Linux builds
* fix dependency on OpenCL extension loader
* fix Linux function name typo
* remove nvidia workarounds, dependency on extension loader
* tidy up command line options, update readme
* remove unused vector of wait semaphores
* update readme to recommend installing the latest drivers
* fix incorrect handle type for external semaphore
* fix incorrect app name
* add a command-line option for VK_PRESENT_MODE_IMMEDIATE_KHR
* try to add support for dma_buf sharing on Linux
* fix whitespace
* add a command line option to disable device local images
Copy file name to clipboardExpand all lines: samples/vulkan/00_juliavk/README.md
+46-3Lines changed: 46 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,51 @@ This is a modified version of the earlier Julia set sample.
6
6
Similar to the earlier Julia Set sample, an OpenCL kernel is used to generate a Julia set image.
7
7
The main difference between this sample and the earlier sample is that in this sample the Julia set image is used as an Vulkan texture and rendered to the screen instead of writing it to a BMP file.
8
8
9
-
This sample currently copies the result of the OpenCL kernel to the Vulkan texture on the host, however several new extensions were recently provisionally released to enable [interop between OpenCL and Vulkan devices](https://www.khronos.org/blog/khronos-releases-opencl-3.0-extensions-for-neural-network-inferencing-and-opencl-vulkan-interop).
10
-
When drivers are available that support these extensions, this sample will be updated to use them!
9
+
This sample can create an OpenCL image directly from the Vulkan texture when supported.
10
+
In order to share the Vulkan texture with OpenCL, the OpenCL device must support [cl_khr_external_memory](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_external_memory).
11
+
Additionally, the Vulkan device must support exporting the Vulkan texture as an OS-specific external memory handle, and the OpenCL device must support importing external memory handles of that type.
12
+
Creating the OpenCL image directly from the Vulkan texture avoids a memory copy and can improve performance.
13
+
14
+
For Windows, the external memory handle types that are currently supported are:
15
+
16
+
*`CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR`
17
+
18
+
For Linux, the external memory handle types that are currently supported are:
19
+
20
+
*`CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR`
21
+
*`CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR`
22
+
23
+
This sample can also share semaphores between Vulkan and OpenCL when supported.
24
+
In order to share a Vulkan semaphore with OpenCL, the OpenCL device must support [cl_khr_external_semaphore](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_external_semaphore).
25
+
Additionally, the Vulkan device must support exporting the Vulkan semaphore as an OS-specific external semaphore handle, and the OpenCL device must support importing external semaphore handles of that type.
26
+
Sharing a semaphore object between Vulkan and OpenCL avoids synchronization on the host and can also improve performance.
27
+
28
+
For Windows, the external semaphore handle types that are currently supported are:
29
+
30
+
*`CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR`
31
+
32
+
For Linux, the external semaphore handle types that are currently supported are:
33
+
34
+
*`CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR`
35
+
36
+
For more information about these extensions, please see [this blog post](https://www.khronos.org/blog/khronos-releases-opencl-3.0-extensions-for-neural-network-inferencing-and-opencl-vulkan-interop).
37
+
When the extensions are not supported the sample will still run, although perhaps with lower performance.
38
+
39
+
Important note: The OpenCL extensions used in this sample are very new!
40
+
If the sample does not run correctly please ensure you are using the latest OpenCL drivers for your device, or use the command line option to force copying on the host.
11
41
12
42
## Key APIs and Concepts
13
43
14
-
This example shows how to share an Vulkan texture with OpenCL.
44
+
This example shows how to share an Vulkan texture and semaphore with OpenCL.
45
+
46
+
```c
47
+
clEnqueueAcquireExternalMemObjectsKHR
48
+
clEnqueueReleaseExternalMemObjectsKHR
49
+
50
+
clCreateSemaphoreWithPropertiesKHR
51
+
clEnqueueSignalSemaphoresKHR
52
+
clReleaseSemaphoreKHR
53
+
```
15
54
16
55
## Command Line Options
17
56
@@ -21,10 +60,14 @@ Note: Many of these command line arguments are identical to the earlier Julia se
21
60
|:--|:-:|:--|
22
61
| `-d <index>` | 0 | Specify the index of the OpenCL device in the platform to execute on the sample on.
23
62
| `-p <index>` | 0 | Specify the index of the OpenCL platform to execute the sample on.
63
+
| `--hostcopy` | n/a | Do not use the `cl_khr_external_memory` extension and unconditionally copy on the host.
64
+
| `--hostsync` | n/a | Do not use the `cl_khr_external_semaphore` extension and exclusively synchronize on the host.
65
+
| `--nodevicelocal` | n/a | Do not use device local images (`VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT`). May be useful for debugging.
24
66
| `--gwx <number>` | 512 | Specify the global work size to execute, in the X direction. This also determines the width of the generated image.
25
67
| `--gwy <number>` | 512 | Specify the global work size to execute, in the Y direction. This also determines the height of the generated image.
26
68
| `--lwx <number>` | 0 | Specify the local work size in the X direction. If either local works size dimension is zero a `NULL` local work size is used.
27
69
| `--lwy <number>` | 0 | Specify the local work size in the Y direction. If either local works size dimension is zero a `NULL` local work size is used.
70
+
| `--immediate` | n/a | Prefer `VK_PRESENT_MODE_IMMEDIATE_KHR` (no vsync). May result in faster framerates at the cost of visible tearing.
0 commit comments