C Specification

To create an OpenCL buffer object from a Direct3D 10 buffer, call the function

// Provided by cl_khr_d3d10_sharing
cl_mem clCreateFromD3D10BufferKHR(
    cl_context context,
    cl_mem_flags flags,
    ID3D10Buffer* resource,
    cl_int* errcode_ret);
clCreateFromD3D10BufferKHR is provided by the cl_khr_d3d10_sharing extension.

Parameters

  • context is a valid OpenCL context created from a Direct3D 10 device.

  • flags is a bit-field that is used to specify usage information. Refer to the List of supported memory flag values table for a description of flags. Only the CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY and CL_MEM_READ_WRITE flags specified in that table can be used.

  • resource is a pointer to the Direct3D 10 buffer to share.

  • errcode_ret will return an appropriate error code. If errcode_ret is NULL, no error code is returned.

Description

The size of the returned OpenCL buffer object is the same as the size of resource. This call will increment the internal Direct3D 10 reference count on resource. The internal Direct3D 10 reference count on resource will be decremented when the OpenCL reference count on the returned OpenCL memory object drops to zero.

clCreateFromD3D10BufferKHR returns a valid non-zero OpenCL buffer object and errcode_ret is set to CL_SUCCESS if the buffer object is created successfully. Otherwise, it returns a NULL value with one of the following error values returned in errcode_ret:

  • CL_INVALID_CONTEXT if context is not a valid context.

  • CL_INVALID_VALUE if values specified in flags are not valid.

  • CL_INVALID_D3D10_RESOURCE_KHR if resource is not a Direct3D 10 buffer resource, if resource was created with the D3D10_USAGE flag D3D10_USAGE_IMMUTABLE, if a cl_mem from resource has already been created using clCreateFromD3D10BufferKHR, or if context was not created against the same Direct3D 10 device from which resource was created.

  • CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

See Also

Document Notes

For more information, see the OpenCL Specification

This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.

Copyright 2014-2025 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0