Imagination PowerVR SDK Blog

Shader performance: attribute vec3 vs vec4


#1

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]



<br />attribute vec4 a_position; // &lt;--- vec 4 <br />uniform&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mat4 u_MVPMatrix; <br /> <br />void main() <br />{ <br />&nbsp;&nbsp;&nbsp;&nbsp;gl_Position = u_MVPMatrix * a_position; <br />} <br />



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<br /> <br />attribute vec3 a_position; /// &lt;--- Vec 3<br /> <br />uniform&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mat4 u_MVPMatrix;<br /> <br /><br /> <br />void main()<br /> <br />{<br /> <br />&nbsp;&nbsp;&nbsp;&nbsp;gl_Position = u_MVPMatrix * vec4( a_position, 1.0 );<br /> <br />}<br /> <br />







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<br /> <br />attribute vec4 a_position; // &lt;--- vec 4<br /> <br />uniform&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mat4 u_MVPMatrix;<br /> <br /><br /> <br />void main()<br /> <br />{<br /> <br />&nbsp;&nbsp;&nbsp;&nbsp;gl_Position = u_MVPMatrix * a_position;<br /> <br />}<br /> <br />





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


#2

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…


#3

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


#4

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