N0xus
N0xus

Reputation: 2724

setting up OpenCL with DirectX 9

I'm completely new to OpenCL and GPU programming in general. Right now I am working on a project where I'm trying to see the performance saves that making use of the GPU in a game has. With this, however, I have ran into a snag; how do I set up my Directx project to speak to the OpenCL code base?

I've been googling this for about a week and haven't been able to find anything. If someone could point me in the right direction, I would be greatful.

Upvotes: 1

Views: 1351

Answers (3)

reirab
reirab

Reputation: 1599

OpenCL has extensions for sharing memory between DirectX and OpenCL (and also between OpenGL and OpenCL.) This allows you to read or write DirectX buffers, including textures from within OpenCL. Ani's answer mentioned the extension for DirectX 10, but since the question is about DirectX 9, the extension you'll actually be using is cl_khr_dx9_media_sharing.

This extension has just 4 functions:

clGetDeviceIDsFromDX9MediaAdapterKHR

This function allows you to get the OpenCL device IDs of the OpenCL device(s) that can share memory with a given Direct3D 9 device.

clCreateFromDX9MediaSurfaceKHR

This function gets an OpenCL cl_mem memory object for a given Direct3D 9 memory object.

clEnqueueAcquireDX9MediaSurfacesKHR

This function locks the specified shared memory object so that you can read and/or write to it from OpenCL.

clEnqueueReleaseDX9MediaSurfacesKHR

This function unlocks the specified memory object from OpenCL, so that Direct3D can read/write it again.


Once you've used the above functions to share and synchronize access to the memory buffers, everything else on both the Direct3D 9 side and the OpenCL side works as it would otherwise with those particular APIs.

Note that your GPU will need to support the cl_khr_dx9_media_sharing extension in order for this to work. You can check the extensions property of the OpenCL platform and device in order to confirm that this extension is supported.

Some NVidia GPUs support a different extension instead, called cl_nv_d3d9_sharing. The basic idea of how it works is the same as with the cl_khr_dx9_media_sharing extension, but the exact details are a bit different. The biggest difference is just that it has different functions for getting cl_mem objects for different types of Direct3D 9 buffers, rather than just one function to cover all of them.

Upvotes: -1

Ani
Ani

Reputation: 10906

The specific OpenCL extension that allows sharing of OpenCL buffers as textures and vice versa is cl_khr_d3d10_sharing.txt. http://www.khronos.org/registry/cl/extensions/khr/cl_khr_d3d10_sharing.txt

Upvotes: 1

pezcode
pezcode

Reputation: 5769

OpenCL does not have anything to do with DirectX, it's simply another library.

For OpenCL you'll need an implementation ('SDK'), as Khronos don't provide those (they only provide the specifications). Intel, AMD and Nvidia all provide one, but they have different requirements and limitations. See here for some of the existing implementations

After installing one of these, you'll have the necessary headers and libraries to code against the OpenCL API and link with OpenCL.dll

There are lots of sample sources in the SDKs or online, you have to write the kernel, the rest is mostly boilerplate code for initialization and kernel compilation.

Upvotes: 1

Related Questions