Shader performance: attribute vec3 vs vec4

This topic contains 3 replies, has 3 voices, and was last updated by  marco 5 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30743

    Hi,

    I am sending 3 floats in the position attribute. And I was wondering which are the benefits of using a attribute vec3 vs vec4 on the vertex shader.

    eg:

    attribute vec3 a_position; /// <— Vec 3

    uniform     mat4 u_MVPMatrix;

    void main()

    {

        gl_Position = u_MVPMatrix * vec4( a_position, 1.0 );

    }

    [/CODE]

    [CODE]

    attribute vec4 a_position; // <— vec 4

    uniform     mat4 u_MVPMatrix;

    void main()

    {

        gl_Position = u_MVPMatrix * a_position;

    }

    [/CODE]

    According to PVRUniSCoEditor emulator, “attribute vec4” takes 1 less cycle than the “attribute vec3”. But, does it consume more memory ? or does it have any other advantage / disadvantage ?

    Thank you,

    ricardoquesada2012-02-01 01:44:03[CODE]

    attribute vec3 a_position; /// <— Vec 3

    uniform     mat4 u_MVPMatrix;

    void main()

    {

        gl_Position = u_MVPMatrix * vec4( a_position, 1.0 );

    }

    [/CODE]

    attribute vec4 a_position; // <— vec 4

    uniform     mat4 u_MVPMatrix;

    void main()

    {

        gl_Position = u_MVPMatrix * a_position;

    }

    [/CODE]

    According to PVRUniSCoEditor emulator, “attribute vec4” takes 1 less cycle than the “attribute vec3”. But, does it consume more memory ? or does it have any other advantage / disadvantage ?

    Thank you,

    ricardoquesada2012-02-01 01:44:03[CODE]

    attribute vec4 a_position; // <— vec 4

    uniform     mat4 u_MVPMatrix;

    void main()

    {

        gl_Position = u_MVPMatrix * a_position;

    }

    [/CODE]

    According to PVRUniSCoEditor emulator, “attribute vec4” takes 1 less cycle than the “attribute vec3”. But, does it consume more memory ? or does it have any other advantage / disadvantage ?

    Thank you,

    ricardoquesada2012-02-01 01:44:03

    #35413

    maximd33
    Member

    unless we can see full assembly produced ( which is not possible, AFAIK )
    these pieces are the same and editor/compiler just show a side effect…

    would be happy to see assembly as GPU ShaderAnalyzer etc tools do…

    #35414

    Thanks. I made some tests, and the performance was the same on both cases.

    #35415

    marco
    Member

    Hi,
    there are small differences in the assembly code, hence the different cycle count estimates.
    The vec3 example on the other hand uses less memory bandwidth as the w-component doesn’t need to be transferred over the memory bus.

    Regards,
    Marco

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.