Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion layers/10_cmdbufemu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It works by intercepting calls to `clGetExtensionFunctionAddressForPlatform` to
If a query succeeds by default then the layer does nothing and simply returns the queried function pointer as-is.
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.

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.
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.
The functionality in this emulation layer is sufficient to run the command buffer samples in this repository.

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.
Expand Down Expand Up @@ -40,4 +40,5 @@ The following environment variables can modify the behavior of the command buffe
This section describes some of the limitations of the emulated `cl_khr_command_buffer` functionality:

* Some error conditions are not properly checked for and returned.
* Deferred kernel arguments are supported, but `CL_COMMAND_BUFFER_STATE_FINALIZED_KHR` is not properly handled.
* Many functions are not thread safe.
18 changes: 15 additions & 3 deletions layers/10_cmdbufemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "emulate.h"

static constexpr cl_version version_cl_khr_command_buffer =
CL_MAKE_VERSION(0, 9, 7);
CL_MAKE_VERSION(0, 9, 8);
static constexpr cl_version version_cl_khr_command_buffer_mutable_dispatch =
CL_MAKE_VERSION(0, 9, 3);
CL_MAKE_VERSION(0, 9, 5);

SLayerContext& getLayerContext(void)
{
Expand Down Expand Up @@ -2113,6 +2113,13 @@ cl_int CL_API_CALL clEnqueueCommandBufferKHR_EMU(
}
}

// If the error code is CL_INVALID_KERNEL_ARGS, then there are probably
// deferred kernel arguments and the command buffer is not yet in the
// executable state, therefore we should return CL_INVALID_OPERATION.
if( errorCode == CL_INVALID_KERNEL_ARGS )
{
errorCode = CL_INVALID_OPERATION;
}
return errorCode;
}

Expand Down Expand Up @@ -2821,7 +2828,12 @@ cl_int CL_API_CALL clCommandNDRangeKernelKHR_EMU(
nullptr,
nullptr ) )
{
return errorCode;
// Ignore CL_INVALID_KERNEL_ARGS errors if this is a mutable
// command in order to handle deferred kernel arguments.
if( !( errorCode == CL_INVALID_KERNEL_ARGS && mutable_handle ) )
{
return errorCode;
}
}
}

Expand Down