OpenCL和OpenGL的计算着色器之间有什么区别? [英] What is the difference between OpenCL and OpenGL's compute shader?

查看:143
本文介绍了OpenCL和OpenGL的计算着色器之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道OpenCL可以控制GPU的内存架构,因此可以实现更好的优化,但是,撇开这一点,我们可以使用Compute Shaders进行矢量运算(加法,乘法,求逆等)吗?

I know OpenCL gives control of the GPU's memory architecture and thus allows better optimization, but, leaving this aside, can we use Compute Shaders for vector operations (addition, multiplication, inversion, etc.)?

推荐答案

与其他OpenGL着色器类型相比,计算着色器与计算机图形不直接相关,并且提供了与CUDA类似的更直接的底层硬件抽象和OpenCL.它提供可自定义的工作组大小,共享内存,组内同步以及CUDA和OpenCL已知和喜爱的所有功能.

In contrast to the other OpenGL shader types, compute shaders are not directly related to computer graphics and provide a much more direct abstraction of the underlying hardware, similar to CUDA and OpenCL. It provides customizable work group size, shared memory, intra-group synchronization and all those things known and loved from CUDA and OpenCL.

主要区别在于:

  • 它使用GLSL而不是OpenCLC.尽管这些编程语言之间没有太大的区别,但是您可以使用OpenCL不可用的所有与图形相关的GLSL函数,例如高级纹理类型(例如,立方体贴图数组)),高级过滤(例如mipmapping,好吧,您可能需要自己计算mip级别),以及诸如4x4矩阵或几何函数之类的便利工具.
  • 这是与其他GLSL着色器一样的OpenGL着色器程序.这意味着访问OpenGL数据(例如缓冲区,纹理,图像)只是微不足道的,而OpenGL和OpenCL/CUDA之间的接口可能会很繁琐,并且可能需要您手动进行同步.以同样的方式将其集成到现有的OpenGL工作流程中也是微不足道的,而设置OpenCL本身就是一本书,更不用说将其集成到现有的图形管线中了.

因此,实际上是,计算着色器实际上是要在现有OpenGL应用程序中使用的,尽管与GPU的图形方法相比,它对GPU编程表现出通常的(类似于OpenCL/CUDA的)计算方法.其他着色器阶段不具有OpenCL/CUDA的计算灵活性(当然还具有其他优势).因此,执行计算任务比将它们压缩到其他不用于通用计算的着色器阶段或引入必须与之同步的其他计算框架相比,更加灵活,直接和容易.

So what this comes down to is, that compute shaders are really intended for use within existing OpenGL applications, though exhibiting the usual (OpenCL/CUDA-like) compute-approach to GPU programming, in contrast to the graphics-approach of the other shader stages, which didn't have the compute-flexibility of OpenCL/CUDA (while offering other advantages, of course). So doing compute tasks is more flexible, direct and easy than either squeezing them into other shader stages not intended for general computing or introducing an additional computing framework you have to synchronize with.

计算着色器应该能够以相同的灵活性和对硬件资源的控制以及相同的编程方法,使用OpenCL几乎可以完成任何事情.因此,如果您对要执行的任务具有适用于GPU的良好算法(可以与CUDA或OpenCL很好地兼容),那么可以,您也可以使用计算着色器来实现.但是仅仅由于计算着色器的原因,使用OpenGL并没有多大意义(使用OpenGL仍然是并且现在将始终是实时计算机图形的框架).为此,您可以仅使用OpenCL或CUDA.在混合图形和计算功能时,计算着色器的真正优势就发挥了作用.

Compute shaders should be able to do nearly anything achievable with OpenCL with the same flexibility and control over hardware resources and with the same programming approach. So if you have a good GPU-suitable algorithm (that would work well with CUDA or OpenCL) for the task you want to do, then yes, you can also do it with compute shaders, too. But it wouldn't make that much sense to use OpenGL (which still is and will probably always be a framework for real-time computer graphics in the first place) only because of compute shaders. For this you can just use OpenCL or CUDA. The real strength of compute shaders comes into play when mixing graphics and compute capabilities.

这篇关于OpenCL和OpenGL的计算着色器之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆