简体   繁体   English

2 计算着色器,1 glMemoryBarrier = OK?

[英]2 Compute shaders, 1 glMemoryBarrier = OK?

Setup(OpenGL ES 3.1 on android device):设置(Android 设备上的 OpenGL ES 3.1):

Compute_shader_clear (in PROGRAM_A): Compute_shader_clear(在 PROGRAM_A 中):

layout (local_size_x = 8, local_size_y = 8) in;
layout(rgba32f, binding=0) writeonly uniform mediump image2D write00;
void main() {
 ...
 imageStore(write00, pixel, vec4(0.0));
}

Compute_shader_main (in PROGRAM_B): Compute_shader_main(在 PROGRAM_B 中):

layout (local_size_x = 8, local_size_y = 8) in;
layout(rgba32f, binding=0) writeonly uniform mediump image2D write00;
void main() {
 ...
 imageStore(write00, pixel, final_color);
}

Both compute shaders are pointing at the same texture (Binding zero = image unit zero)两个计算着色器都指向同一个纹理(绑定零 = 图像单元零)

App calling code:应用调用代码:

glUseProgram(PROGRAM_A);
glDispatchCompute(90, 160, 1);
glUseProgram(PROGRAM_B);
GLES31.glMemoryBarrier(GLES31.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
glDispatchCompute(3, 160, 1);
...

This setup seems to work without a problem, but is this interpretation correct?这种设置似乎没有问题,但这种解释是否正确? :

  1. The barrier is necessary because it is possible that both dispatch commands could be running at the same time.屏障是必要的,因为两个调度命令可能同时运行。

  2. The barrier means that no imageStore will be executed in the second dispatch until ALL imageStore calls in the first dispatch are finished.屏障意味着在第一次分派中的所有 imageStore 调用完成之前,不会在第二次分派中执行任何 imageStore。

The barrier is necessary because it is possible that both dispatch commands could be running at the same time.屏障是必要的,因为两个调度命令可能同时运行。

Technically yes, but the more proper reason is "because the OpenGL ES specification says it is necessary."从技术上讲是的,但更恰当的理由是“因为 OpenGL ES 规范说这是必要的”。

The barrier means that no imageStore will be executed in the second dispatch until ALL imageStore calls in the first dispatch are finished.屏障意味着在第一次分派中的所有 imageStore 调用完成之前,不会在第二次分派中执行任何 imageStore。

What the barrier means is that, if there are read/write operations later that attempt to access data written previously, those read/write operations will read/overwrite data written by commands before the barrier.屏障的意思是,如果以后有读/写操作尝试访问先前写入的数据,这些读/写操作将读取/覆盖屏障之前命令写入的数据。

How that gets implemented is an implementation detail.如何实现是一个实现细节。 There could be hardware that could concurrently execute such commands, through the use of some ordering operation somehow.通过以某种方式使用某种排序操作,可能存在可以并发执行此类命令的硬件。 Granted, odds are good that most implementations will do what you said: wait until prior commands are executed and clear caches before executing subsequent commands.诚然,大多数实现都会按照您说的做的可能性很大:等到执行先前的命令并在执行后续命令之前清除缓存。

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

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