Skip to content

Commit b7a527a

Browse files
authored
add command buffer emulation layer support for mutable dispatch (#63)
* start to add support for mutable command buffers mutable command buffers are working improve reporting and checks for extension support add support for CL_MUTABLE_DISPATCH_UPDATABLE_FIELDS_KHR fix bug with multiple mutable dispatch configs add missing include * minor fixes, update README
1 parent 29f861d commit b7a527a

10 files changed

Lines changed: 1006 additions & 5 deletions

File tree

layers/10_cmdbufemu/emulate.cpp

Lines changed: 526 additions & 2 deletions
Large diffs are not rendered by default.

layers/10_cmdbufemu/emulate.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ cl_int CL_API_CALL clGetCommandBufferInfoKHR_EMU(
156156
void* param_value,
157157
size_t* param_value_size_ret);
158158

159+
#if defined(cl_khr_command_buffer_mutable_dispatch)
160+
161+
cl_int CL_API_CALL clUpdateMutableCommandsKHR_EMU(
162+
cl_command_buffer_khr command_buffer,
163+
const cl_mutable_base_config_khr* mutable_config);
164+
165+
cl_int CL_API_CALL clGetMutableCommandInfoKHR_EMU(
166+
cl_mutable_command_khr command,
167+
cl_mutable_command_info_khr param_name,
168+
size_t param_value_size,
169+
void* param_value,
170+
size_t* param_value_size_ret);
171+
172+
#endif // defined(cl_khr_command_buffer_mutable_dispatch)
173+
159174
///////////////////////////////////////////////////////////////////////////////
160175
// Override Functions
161176

layers/10_cmdbufemu/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ clGetExtensionFunctionAddressForPlatform_layer(
9090
CHECK_RETURN_EXTENSION_FUNCTION( clCommandNDRangeKernelKHR );
9191
CHECK_RETURN_EXTENSION_FUNCTION( clGetCommandBufferInfoKHR );
9292

93+
#if defined(cl_khr_command_buffer_mutable_dispatch)
94+
CHECK_RETURN_EXTENSION_FUNCTION( clUpdateMutableCommandsKHR );
95+
CHECK_RETURN_EXTENSION_FUNCTION( clGetMutableCommandInfoKHR );
96+
#endif // defined(cl_khr_command_buffer_mutable_dispatch)
97+
9398
return nullptr;
9499
}
95100

samples/12_commandbuffers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This sample requires the OpenCL Extension Loader to get the extension APIs for c
1414

1515
This sample demonstrates how to query the command buffer properties supported by a device, and the properties of a command buffer.
1616

17-
This sample also demostrates how to create, finalize, and execute a command buffer.
17+
This sample also demonstrates how to create, finalize, and execute a command buffer.
1818

1919
```c
2020
clCreateCommandBufferKHR

samples/12_commandbuffers/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(
8585

8686
if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) {
8787
fprintf(stderr,
88-
"Usage: copybufferkernel [options]\n"
88+
"Usage: commandbuffers [options]\n"
8989
"%s", op.help().c_str());
9090
return -1;
9191
}

samples/12_commandbufferspp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(
8585

8686
if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) {
8787
fprintf(stderr,
88-
"Usage: copybufferkernel [options]\n"
88+
"Usage: commandbufferspp [options]\n"
8989
"%s", op.help().c_str());
9090
return -1;
9191
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2022 Ben Ashbaugh
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
add_opencl_sample(
6+
TEST
7+
NUMBER 12
8+
TARGET mutablecommandbuffers
9+
VERSION 120
10+
SOURCES main.cpp
11+
LIBS OpenCLExt)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# mutablecommandbuffers
2+
3+
## Sample Purpose
4+
5+
This is an intermediate-level sample that demonstrates how to use the OpenCL extension [cl_khr_command_buffer_mutable_dispatch](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#cl_khr_command_buffer_mutable_dispatch) to modify a command buffer after it has been finalized.
6+
As of this writing, `cl_khr_command_buffer_mutable_dispatch` is a provisional extension.
7+
This sample uses the functionality described in v0.9.0 of the extension.
8+
9+
This is an optional extension and some devices may not support `cl_khr_command_buffer_mutable_dispatch`, but the sample may still run using the [cl_khr_command_buffer emulation layer](../../layers/10_cmdbufemu).
10+
11+
This sample requires the OpenCL Extension Loader to get the extension APIs for command buffers.
12+
13+
## Key APIs and Concepts
14+
15+
This sample demonstrates how to query the mutable dispatch capabilities supported by a device, how to create a mutable command buffer, and how to query the properties of a mutable command.
16+
17+
This sample also demonstrates how to mutate (modify) a command buffer after it has been finalized.
18+
19+
```c
20+
clGetMutableCommandInfoKHR
21+
clUpdateMutableCommandsKHR
22+
```
23+
24+
## Command Line Options
25+
26+
| Option | Default Value | Description |
27+
|:--|:-:|:--|
28+
| `-d <index>` | 0 | Specify the index of the OpenCL device in the platform to execute on the sample on.
29+
| `-p <index>` | 0 | Specify the index of the OpenCL platform to execute the sample on.

0 commit comments

Comments
 (0)