【发布时间】:2020-01-13 12:59:38
【问题描述】:
我正在使用计算机着色器来获取总和值(类型为浮点数),如下所示:
#version 320 es
layout(local_size_x = 640,local_size_y=480,local_size_z=1)
layout(binding = 0) buffer OutputData{
float sum[];
}output;
uniform sampler2D texture_1;
void main()
{
vec2 texcoord(float(gl_LocalInvocationIndex.x)/640.0f,float(gl_LocalInvocationIndex.y)/480.0f);
float val = textureLod(texture_1,texcoord,0.0).r;
//where need synchronize
sum[0] = sum[0]+val;
//Here i want to get the sum of all val in texture_1 first channal
}
我知道有 atomicAdd() 之类的原子操作,但不支持 float 参数,并且 barrier() 似乎无法解决我的问题。 也许我可以将浮点数编码为 int,或者有什么简单的方法可以解决我的问题?
【问题讨论】:
标签: android opengl-es synchronization compute-shader glsles