关闭

计算着色器

139人阅读 评论(0) 收藏 举报
分类:
struct col{
uint x;
uint y;
uint z;
uint w;
};


layout ( binding = 0 ) buffer bmp{
uvec4 color[];
};


layout(local_size_x = 1) in;


void main(void)
{

uint ID = gl_WorkGroupID.y * gl_NumWorkGroups.x + gl_WorkGroupID.x;

//color[ID] = col(ID * 3,ID * 3 + 1,ID * 3 + 2);


//color[ID] = col(ID * 4,ID * 4 + 1,ID * 4 + 2,ID * 4 + 3);


color[ID] = uvec4(gl_WorkGroupID.x, gl_WorkGroupID.y, gl_NumWorkGroups.x, ID);

}


以上计算着色器当color类型为uvec3或者自定义类型col时,无法正确执行,有没有谁知道怎么回事?谢谢!


对应以下C++代码:

#define EC (4)
const unsigned char * bc = (const unsigned char *)bmp;
ShaderStorageBufferObject ssbo( bmp.W() * bmp.H() * EC * sizeof(int), 0, Buffer::USAGE::DYNAMIC_DRAW);
ssbo.Bind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
unsigned int (*bia)[4288][2848][EC] = (unsigned int (*)[4288][2848][EC])ssbo.MapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER,Buffer::MAP_FLAG::READ_WRITE);
unsigned int *bi = (unsigned int *)bia;
for(int i = 0; i < bmp.W() * bmp.H() * EC; ++i)
{
//bi[i] = *bc;
bi[i] = i/EC + i%EC;
}
ssbo.UnmapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.UnBind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.BindBase(0);
std::string cstr;
ShaderM::ReadShaderSourceFromFile("shaders/computer.glsl/bmp.glsl", cstr);
CMPProg cmpp(cstr.data());
cmpp.UseProgram();

//cmpp.Dispatch(1,1,16);
cmpp.Dispatch(bmp.W() ,bmp.H() ,1);
//glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
ssbo.Bind(Buffer::BIND_TARGET::COPY_READ_BUFFER);
bia = (unsigned int (*)[4288][2848][EC])ssbo.MapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER,Buffer::MAP_FLAG::READ_WRITE);

ssbo.UnmapBuffer(Buffer::BIND_TARGET::COPY_READ_BUFFER);
ssbo.UnBind(Buffer::BIND_TARGET::COPY_READ_BUFFER);


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:607次
    • 积分:24
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档