5 Replies Latest reply on Feb 7, 2017 9:15 AM by invertedantimatter

    Alignment problem in OpenGL compute shaders

    invertedantimatter

      I'm attempting to apply a matrix multiply to a batch of matrices by using a compute shader.  After troubleshooting various things, I found what was causing bad output.

       

      #version 430
      layout(local_size_x = 4, local_size_y = 4, local_size_z = 16) in;
      layout(binding = 0) uniform viewLayout { mat4 eye; };
      layout(std430, binding = 1) buffer inputLayout { mat4 src[]; };
      layout(std430, binding = 2) buffer outputLayout { mat4 dst[]; };
      void main(void)
      {  

        uint itm = (gl_WorkGroupID.z << 4) + gl_LocalInvocationID.z;
        uint col = gl_LocalInvocationID.y;
        uint row = gl_LocalInvocationID.x;
        dst[itm][col][row] = row;
      }

      The variable dst (in bold) produces the following output for the first 16 floats

      [0]0.000000000float
      [1]1.00000000float
      [2]2.00000000float
      [3]3.00000000float
      [4]0.000000000float
      [5]0.000000000float
      [6]1.00000000float
      [7]2.00000000float
      [8]3.00000000float
      [9]0.000000000float
      [10]0.000000000float
      [11]1.00000000float
      [12]2.00000000float
      [13]3.00000000float
      [14]0.000000000float
      [15]0.000000000float

      However, if I change it to vec4 dst[][4],

       

      [0]0.000000000float
      [1]1.00000000float
      [2]2.00000000float
      [3]3.00000000float
      [4]0.000000000float
      [5]1.00000000float
      [6]2.00000000float
      [7]3.00000000float
      [8]0.000000000float
      [9]1.00000000float
      [10]2.00000000float
      [11]3.00000000float
      [12]0.000000000float
      [13]1.00000000float
      [14]2.00000000float
      [15]3.00000000float

       

      Can anyone help me understand why mat4 is treated like it is 5 floats wide instead of 4?