Skip to content

Commit

Permalink
Add mechanism to specify named win32 NT handles.
Browse files Browse the repository at this point in the history
Currently, cl_khr_external_semaphore and cl_khr_external_memory
define properties to specify external win32 NT handle via pointer.
Win32 NT handles can also be specified via named strings.
Add properties to specify external Win32 NT handles via named strings too.

Fixes #943
  • Loading branch information
nikhiljnv committed Nov 21, 2023
1 parent 325f801 commit a4575e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ext/cl_khr_external_memory.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ External memory handle types added by `cl_khr_external_memory_win32`:
----
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR 0x2061
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR 0x2062
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR 0x2069
----

=== Modifications to existing APIs added by this spec
Expand Down Expand Up @@ -395,6 +396,7 @@ The `cl_khr_external_memory_win32` extension extends {cl_external_memory_handle_
--
* {CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR} specifies an NT handle that has only limited valid usage outside of OpenCL and other compatible APIs. It must be compatible with the functions DuplicateHandle, CloseHandle, CompareObjectHandles, GetHandleInformation, and SetHandleInformation. It owns a reference to the underlying memory resource represented by its memory object.
* {CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR} specifies a global share handle that has only limited valid usage outside of OpenCL and other compatible APIs. It is not compatible with any native APIs. It does not own a reference to the underlying memory resource represented by its memory object, and will therefore become invalid when all memory objects associated with it are destroyed.
* {CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR} specifies an NT handle name that has only limited valid usage outside of OpenCL and other compatible APIs. It must be compatible with the functions DuplicateHandle, CloseHandle, CompareObjectHandles, GetHandleInformation, and SetHandleInformation. It owns a reference to the underlying memory resource represented by its memory object.
--

For these extensions, importing memory object payloads from Windows handles does not transfer ownership of the handle to the OpenCL implementation. For handle types defined as NT handles, the application must release handle ownership using the CloseHandle system call when the handle is no longer needed. For handle types defined as NT handles, the imported memory object holds a reference to its payload.
Expand Down
5 changes: 5 additions & 0 deletions ext/cl_khr_external_semaphore.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ External semaphore handle types added by `cl_khr_external_semaphore_win32`:
----
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR 0x2056
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR 0x2057
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR 0x2068
----

=== Modifications to existing APIs added by this spec
Expand Down Expand Up @@ -404,6 +405,7 @@ The `cl_khr_external_semaphore_win32` extension extends {cl_external_semaphore_h
--
* {CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR} specifies an NT handle that has only limited valid usage outside of OpenCL and other compatible APIs. It must be compatible with the functions DuplicateHandle, CloseHandle, CompareObjectHandles, GetHandleInformation, and SetHandleInformation. It owns a reference to the underlying synchronization primitive represented by its semaphore object.
* {CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR} specifies a global share handle that has only limited valid usage outside of OpenCL and other compatible APIs. It is not compatible with any native APIs. It does not own a reference to the underlying synchronization primitive represented by its semaphore object, and will therefore become invalid when all semaphore objects associated with it are destroyed.
* {CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR} specifies an NT handle name that has only limited valid usage outside of OpenCL and other compatible APIs. It must be compatible with the functions DuplicateHandle, CloseHandle, CompareObjectHandles, GetHandleInformation, and SetHandleInformation. It owns a reference to the underlying synchronization primitive represented by its semaphore object.
--

Transference and permanence properties for handle types added by `cl_khr_external_semaphore_win32`:
Expand All @@ -418,6 +420,9 @@ Transference and permanence properties for handle types added by `cl_khr_externa
| {CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR}
| Reference
| Temporary, Permanent
| {CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR}
| Reference
| Temporary, Permanent
|====

For these extensions, importing a semaphore payload from Windows handles does not transfer ownership of the handle to the OpenCL implementation. For handle types defined as NT handles, the application must release ownership using the CloseHandle system call when the handle is no longer needed.
Expand Down
4 changes: 3 additions & 1 deletion xml/cl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,9 @@ server's OpenCL/api-docs repository.
<enum value="0x2065" name="CL_EXTERNAL_MEMORY_HANDLE_D3D12_HEAP_KHR"/>
<enum value="0x2066" name="CL_EXTERNAL_MEMORY_HANDLE_D3D12_RESOURCE_KHR"/>
<enum value="0x2067" name="CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR"/>
<unused start="0x2068" end="0x2FFF" comment="Reserved to Khronos for interop"/>
<enum value="0x2068" name="CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR"/>
<enum value="0x2069" name="CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR"/>
<unused start="0x206A" end="0x2FFF" comment="Reserved to Khronos for interop"/>
</enums>

<enums start="0x3000" end="0x3FFF" name="enums.3000" vendor="Khronos" comment="Platform IDs. Allocate individually.">
Expand Down

0 comments on commit a4575e1

Please sign in to comment.