简体   繁体   English

如何让OpenGL ES 2.0中的vertex shader进行GPGPU计算?

[英]How to let a vertex shader in OpenGL ES 2.0 perform GPGPU computing?

I'm doing a project using OpenCL and thought it can work on Mali 400 GPU.我正在做一个使用 OpenCL 的项目,我认为它可以在 Mali 400 GPU 上运行。 But I recently found that Mali 400 GPU only support OpenGL ES 2.0 standard.但是我最近发现Mali 400 GPU只支持OpenGL ES 2.0标准。

I still have to use this GPU, So is there any way to let a shader act nearly the same as OpenCL kernel or CUDA kernel?我仍然必须使用这个 GPU,那么有什么方法可以让着色器的行为与 OpenCL 内核或 CUDA 内核几乎相同?

There are some main features I expect but not sure glsl will support:我期望有一些主要功能,但不确定 glsl 是否支持:

  • For example, I created a global memory for GPU, and I want to read/write the global memory in shader, how should I pass the variable from host to vertex shader, can I expect that data be both 'in and out' like this?例如,我为 GPU 创建了一个全局内存,我想在着色器中读取/写入全局内存,我应该如何将变量从主机传递到顶点着色器,我是否可以期望数据像这样“进出” ?
layout (location = 0) inout vec3 a_Data;
  • I want to fetch a_Data as 64 float values, is there a easy way to declare it like vec64 or float[64] , or I have to use multiple vec4 to assemble it?我想获取a_Data作为 64 个浮点值,是否有一种简单的方法来声明它,如vec64float[64] ,或者我必须使用多个vec4来组装它?

So is there any way to let a vertex shader act nearly the same as OpenCL kernel or CUDA kernel?那么有什么方法可以让顶点着色器的行为与 OpenCL 内核或 CUDA 内核几乎相同?

No.不。

In ES 2.0, vertex shaders have no mechanism to write to memory.在 ES 2.0 中,顶点着色器没有写入内存的机制。 At all.完全没有。 All of their output variables go to the rasterizer to generate fragments to be processed by the fragment shader.它们的所有输出变量都进入光栅化器以生成要由片段着色器处理的片段。

The only way to do GPGPU processing on such hardware is to use the fragment shader to write data.在这种硬件上进行GPGPU处理的唯一方法是使用片段着色器写入数据。 That means you have to manipulate your data to look like a rendering operation.这意味着您必须操纵您的数据,使其看起来像渲染操作。 Your vertex positions needs to set up your fragment shader to be able to write values to the appropriate places.您的顶点位置需要设置片段着色器才能将值写入适当的位置。 And your fragment shader needs to be able to acquire whatever information it needs based on what the VS provides (which is at a per-vertex granularity and interpolated for each fragment).并且您的片段着色器需要能够根据 VS 提供的内容(以每个顶点为粒度并为每个片段进行插值)获取所需的任何信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM