Results 1 to 3 of 3

Thread: shader storage buffer mat4x3[] array

  1. #1

    shader storage buffer mat4x3[] array

    Hi I would like to reduce my memory footprint for my rendering pipeline.
    A straightforward solution should be the use of 4x3 arrays to encode the modelmatrix, that is accessed indirectly.

    My question is: does that work or is it prevented by some alignment or packing requirement that I am not aware of.

    My problem is that as soon as I use 4x3 matrices, the transformation is wrong.

    Code :
    layout(std430, binding = 1) buffer TransformBuffer
    	mat4x3 transformBuffer[];
    mat4 M= mat4(transformBuffer[i]);

    On CPU, I create the array, using glm constuctors:

    Code :
    for (auto & t : transforms) // glm::mat4

    Interestingly, If I bind the mat4 array and declare with mat4x3 in glsl, all is fine. So it appears to be some alignment problem, that I have no clue of.

    GTX1070 btw.

    Alignment works,
    but the conversion is unexpected:

    Code :
    	mat4 M = mat4(	t.p[0], t.p[1], t.p[2], 0,
    					t.p[3], t.p[4], t.p[5], 0,
    					t.p[6], t.p[7], t.p[8], 0,
    					t.p[9],	t.p[10], t.p[11],	1);

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    mat4x3 has 4 columns and 3 rows (this is opposite to the usual mathematical convention, where a "4x3" or "four by three" matrix has 4 rows and 3 columns).

    A column-major matrix is treated as an array of vectors, one for each column, so a column-major mat4x3 is equivalent to vec3[4]. In both std140 and std430 layouts, a vec3 is always aligned as a vec4, so an array of column-major mat4x3 has the same layout as an array of mat4x4.

    If you want to save memory, you can declare the matrix as row-major. A row-major matrix is treated as an array of vectors, one for each row, so a row-major mat4x3 is equivalent to vec4[3], which doesn't require any padding. But then you'd need to explicitly transpose the matrices on the client side.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Take a look at:

    * Mat4x3 Uniform Registers?

    Also, it's useful to search the OpenGL forums when you have a question. Using Google for instance:
    "mat4x3 inurl:discussion_boards"

Similar Threads

  1. SPIR-V Storage Buffer Array problem?
    By efolkertsma in forum SPIR
    Replies: 1
    Last Post: 11-02-2018, 02:33 AM
  2. Get Shader Storage Buffer Object to work
    By FonzTech in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-09-2016, 02:35 PM
  3. shader storage buffer objects within geometry shader
    By minidrive in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-14-2014, 08:43 AM
  4. Shader storage buffer bug in Catalyst 13.4
    By jcabeleira in forum OpenGL: Drivers
    Replies: 6
    Last Post: 06-12-2013, 08:29 AM
  5. Replies: 3
    Last Post: 04-16-2013, 01:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean