使用 DirectX 9 设置 OpenCL

发布于 2025-01-05 03:43:22 字数 172 浏览 0 评论 0原文

总的来说,我对 OpenCL 和 GPU 编程完全陌生。目前,我正在开展一个项目,试图了解在游戏中使用 GPU 所带来的性能节省。然而,我遇到了一个障碍;如何设置我的 Directx 项目来与 OpenCL 代码库对话?

我已经在谷歌上搜索了大约一周,但没有找到任何东西。如果有人能指出我正确的方向,我将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

反差帅 2025-01-12 03:43:22

OpenCL 与 DirectX 没有任何关系,它只是另一个库。

对于 OpenCL,您需要一个实现(“SDK”),因为 Khronos 不提供这些(他们只提供规范)。
Intel、AMD 和 Nvidia 都提供了一种,但它们有不同的要求和限制。 请参阅此处了解一些现有实现

安装其中之一后,您将拥有针对 OpenCL API 进行编码并与 OpenCL.dll 链接所需的头文件和库

在 SDK 或在线中有很多示例源,您必须编写内核,其余的大部分是用于初始化和内核编译的样板代码。

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.

忘你却要生生世世 2025-01-12 03:43:22

允许将 OpenCL 缓冲区共享为纹理(反之亦然)的特定 OpenCL 扩展是 cl_khr_d3d10_sharing.txt。 http://www.khronos.org/registry/cl/extensions/khr /cl_khr_d3d10_sharing.txt

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

十年九夏 2025-01-12 03:43:22

OpenCL 具有在 DirectX 和 OpenCL 之间(以及 OpenGL 和 OpenCL 之间)共享内存的扩展。这允许您读取或写入 DirectX 缓冲区,包括 OpenCL 中的纹理。 Ani 的回答提到了 DirectX 10 的扩展,但由于问题是关于 DirectX 9 的,因此您实际使用的扩展是 cl_khr_dx9_media_sharing

该扩展只有 4 个函数:

clGetDeviceIDsFromDX9MediaAdapterKHR

此函数允许您获取可与给定 Direct3D 共享内存的 OpenCL 设备的 OpenCL 设备 ID 9 装置。

clCreateFromDX9MediaSurfaceKHR

此函数获取 OpenCL给定 Direct3D 9 内存对象的 cl_mem 内存对象。

clEnqueueAcquireDX9MediaSurfacesKHR

该函数锁定指定的共享内存对象,以便您可以从 OpenCL 读取和/或写入它。

clEnqueueReleaseDX9MediaSurfacesKHR

此函数解锁指定的来自 OpenCL 的内存对象,以便 Direct3D 可以再次读取/写入它。


使用上述函数来共享和同步对内存缓冲区的访问后,Direct3D 9 端和 OpenCL 端的所有其他内容都将像使用这些特定 API 一样工作。

请注意,您的 GPU 需要支持 cl_khr_dx9_media_sharing 扩展才能使其正常工作。您可以检查 OpenCL 平台和设备的扩展属性,以确认是否支持此扩展。

某些 NVidia GPU 支持不同的扩展,称为 cl_nv_d3d9_sharing。其工作原理的基本思想与 cl_khr_dx9_media_sharing 扩展相同,但具体细节略有不同。最大的区别在于它具有不同的函数来获取不同类型的 Direct3D 9 缓冲区的 cl_mem 对象,而不是仅用一个函数来涵盖所有这些对象。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文