I'm trying to find a way to bind an OpenCL buffer into DirectX buffer.
I did manage to find the inverse way of doing so using eh OpenGL Api function: clCreateFromGLBuffer, but failed on finding the other way around.
Is there maybe a way to go through the 3rd party, meaning transfering from OpenCL into some other type of buffer which is capable to be bind into a DirectX buffer?
Update: Trying pmdj's solution (attached code snippet here), in a part of my solution what i'm doing is creating a DirectX 11 resource (ID3D11Texture2D to be precise) and giving that resource access from both OpenCL resource (boost::compute::image2d) and from DirectX 12 resource (ID3D12Resource).. Now about the OpenCL - i managed to perform. Though giving access to a DirectX 12 resource i didn't manage (it just leaves the com_ptr with NULL value, am i doing something wrong here?
std::tuple<com_ptr<ID3D11Texture2D>, com_ptr<ID3D12Resource>, boost::compute::image2d> CreateInteropTextureD12Support(
ID3D11Device* d3dDevice11,
ID3D12Device* d3dDevice12,
const boost::compute::context& clContext,
DXGI_FORMAT format,
UINT bindFlags,
unsigned width,
unsigned height
)
{
D3D11_TEXTURE2D_DESC desc{};
desc.Width = width;
desc.Height = height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = bindFlags;
desc.CPUAccessFlags = 0;
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;// shared with opencld
// create d11 resource (from which opencl and d12 will point to)
com_ptr<ID3D11Texture2D> texture11;
HR(d3dDevice11->CreateTexture2D(&desc, nullptr, texture11.GetAddressOf()));
auto image2d = GetCLImageFromD3D11Texture2D(texture11, clContext);
com_ptr<ID3D12Resource> texture12; // texture / resource?
HANDLE handle = NULL;
IDXGIResource1* pResource;
texture11->QueryInterface(__uuidof(IDXGIResource1), (void**)&pResource);
HR(pResource->CreateSharedHandle(
NULL,
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
NULL,
&handle
));
HR(d3dDevice12->OpenSharedHandle(handle, __uuidof(ID3D12Resource), (void**)&texture12));
return std::make_tuple(std::move(texture11), std::move(texture12), std::move(image2d));
}
cl_khr_d3d11_sharingextension? What about the OpenCL-on-DX12 implementation? Also, you want to create a buffer on OpenCL first and then bind this from DirectX, and you cannot modify your code to work the other way around?