Skip to content

Commit 4a90872

Browse files
committed
update command buffer emulation layer to latest spec version
The command buffer emulation layer will support setting deferred kernel arguments, but will not properly handle the new FINALIZED state.
1 parent d79c921 commit 4a90872

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

layers/10_cmdbufemu/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It works by intercepting calls to `clGetExtensionFunctionAddressForPlatform` to
77
If a query succeeds by default then the layer does nothing and simply returns the queried function pointer as-is.
88
If the query is unsuccessful however, then the layer returns its own function pointer, which will record the contents of the command buffer for later playback.
99

10-
This command buffer emulation layer currently implements v0.9.4 of the `cl_khr_command_buffer` extension and v0.9.0 of the `cl_khr_command_buffer_mutable_dispatch` extension.
10+
This command buffer emulation layer currently implements v0.9.8 of the `cl_khr_command_buffer` extension and v0.9.5 of the `cl_khr_command_buffer_mutable_dispatch` extension.
1111
The functionality in this emulation layer is sufficient to run the command buffer samples in this repository.
1212

1313
Please note that the emulated command buffers are intended to be functional, but unlike a native implementation, they may not provide any performance benefit over similar code without using command buffers.
@@ -40,4 +40,5 @@ The following environment variables can modify the behavior of the command buffe
4040
This section describes some of the limitations of the emulated `cl_khr_command_buffer` functionality:
4141

4242
* Some error conditions are not properly checked for and returned.
43+
* Deferred kernel arguments are supported, but the `CL_COMMAND_BUFFER_STATE_FINALIZED` is not properly handled.
4344
* Many functions are not thread safe.

layers/10_cmdbufemu/emulate.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include "emulate.h"
2121

2222
static constexpr cl_version version_cl_khr_command_buffer =
23-
CL_MAKE_VERSION(0, 9, 7);
23+
CL_MAKE_VERSION(0, 9, 8);
2424
static constexpr cl_version version_cl_khr_command_buffer_mutable_dispatch =
25-
CL_MAKE_VERSION(0, 9, 3);
25+
CL_MAKE_VERSION(0, 9, 5);
2626

2727
SLayerContext& getLayerContext(void)
2828
{
@@ -2113,6 +2113,13 @@ cl_int CL_API_CALL clEnqueueCommandBufferKHR_EMU(
21132113
}
21142114
}
21152115

2116+
// If the error code is CL_INVALID_KERNEL_ARGS, then there are probably
2117+
// deferred kernel arguments and the command buffer is not yet in the
2118+
// executable state, therefore we should return CL_INVALID_OPERATION.
2119+
if( errorCode == CL_INVALID_KERNEL_ARGS )
2120+
{
2121+
errorCode = CL_INVALID_OPERATION;
2122+
}
21162123
return errorCode;
21172124
}
21182125

@@ -2821,7 +2828,12 @@ cl_int CL_API_CALL clCommandNDRangeKernelKHR_EMU(
28212828
nullptr,
28222829
nullptr ) )
28232830
{
2824-
return errorCode;
2831+
// Ignore CL_INVALID_KERNEL_ARGS errors if this is a mutable
2832+
// command in order to handle deferred kernel arguments.
2833+
if( !( errorCode == CL_INVALID_KERNEL_ARGS && mutable_handle ) )
2834+
{
2835+
return errorCode;
2836+
}
28252837
}
28262838
}
28272839

0 commit comments

Comments
 (0)