4
我有我的體素化場景的顏色,法線和其他數據的3D紋理,並且由於這些數據的某些數據不能進行平均計算,因此需要我自己計算mip級別。 3D紋理大小爲(128 + 64)x 128 x 128,額外的64 x 128 x 128用於mip級別。因此,當我第一個mip水平,這是在(0,0,0)與128 x 128 x 128的大小,只是複製體素到第二級,這是在(128,0,0 )數據出現在那裏,但只要我複製(128,0,0)的第二級到(128,0,64)的第三級,數據不會出現在第三級。使用計算着色器進行Mipmapping
shader代碼:
#version 450 core
layout (local_size_x = 1,
local_size_y = 1,
local_size_z = 1) in;
layout (location = 0) uniform unsigned int resolution;
layout (binding = 0, rgba32f) uniform image3D voxel_texture;
void main()
{
ivec3 index = ivec3(gl_WorkGroupID);
ivec3 spread_index = index * 2;
vec4 voxel = imageLoad(voxel_texture, spread_index);
imageStore(voxel_texture, index + ivec3(resolution, 0, 0), voxel);
// This isn't working
voxel = imageLoad(voxel_texture, spread_index +
ivec3(resolution, 0, 0));
imageStore(voxel_texture, index + ivec3(resolution, 0, 64), voxel);
}
着色器程序與
glUniform1ui(0, OCTREE_RES);
glBindImageTexture(0, voxel_textures[0], 0, GL_TRUE, 0, GL_READ_WRITE,
GL_RGBA32F);
glDispatchCompute(64, 64, 64);
派出我不知道如果我錯過了一些基本的東西,這是我第一次計算着色器。我也試圖使用記憶障礙,但它並沒有改變一件事情。
對,我認爲障礙在全球範圍內工作......你知道如果使用一個單一的「全球」工作組與128x128x128本地工作組,那麼你的2個選項效率會降低嗎? – FamZ
我的意思是1個本地工作組,大小爲128x128x128 – FamZ
@FamZ:你認爲128x128x128的工作組大小是可能的。 [任何硬件支持的組中最大數量的工作項目是1536](http://opengl.gpuinfo.org/gl_stats_caps_single.php?listreportsbycap=GL_MAX_COMPUTE_WORK_GROUP_SIZE)。這很像128^3。你想要的只是不可能的。最好重構你的算法和數據,以適應合理的工作組大小。 –