Only first Compute Shader array element appears updated

后端 未结 2 2085
耶瑟儿~
耶瑟儿~ 2020-12-21 19:33

Trying to send an array of integer to a compute shader, sets an arbitrary value to each integer and then reads back on CPU/HOST. The problem is that only the first element o

相关标签:
2条回答
  • 2020-12-21 20:01

    Ok i had this problem as well i changed:

    layout(binding = 0) buffer SSBO{
    

    to:

    layout(binding = 0, std430) buffer SSBO{
    
    0 讨论(0)
  • 2020-12-21 20:04
    glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);
    
    //Gets a pointer to the returned data
    int* returnArray = (int *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_WRITE);
    

    The bit you use for glMemoryBarrier represents the way you want to read the data written by the shader. GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT says "I'm going to read this written data by using the buffer for vertex attribute arrays". In reality, you are going to read the buffer by mapping it.

    So you should use the proper barrier bit:

    glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
    
    0 讨论(0)
提交回复
热议问题