ฉันใช้คอมพิวเตอร์เชเดอร์เพื่อรับค่าผลรวม (ประเภทคือลอย) เช่นนี้
#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 เป็น int ได้หรือมีวิธีง่ายๆ ในการแก้ปัญหาของฉันบ้างไหม?