PDA

View Full Version : Instruction count in GLSL



Hekus
02-16-2006, 09:33 AM
Sorry for my english =).

I have CG shader and when i compile it with ABR_VP1 profile there is about 124 instructions.
When i use same shader in glsl, linker return " available number of ALU instructions exceeded"

How can i know number of instructions in glsl shader.
Where i can look max number of instructon or other max parameter than i can use in glsl

GPU: ATI Raderon 9800

_def
02-16-2006, 09:44 AM
Originally posted by Hekus:
Sorry for my english =).

I have CG shader and when i compile it with ABR_VP1 profile there is about 124 instructions.
When i use same shader in glsl, linker return " available number of ALU instructions exceeded"

How can i know number of instructions in glsl shader.
Where i can look max number of instructon or other max parameter than i can use in glsl

GPU: ATI Raderon 9800every card has its own max number of instruction, texture indications etc.
check out the sgi opengl specifications for more information on how to look up the cards limits:

void GetProgramivARB(enum target, enum pname, int *params);

obtains program state for the program target <target>, writing the
state into the array given by <params>. GetProgramivARB can be used
to determine the properties of the currently bound program object or
implementation limits for <target>.

If <pname> is PROGRAM_LENGTH_ARB, PROGRAM_FORMAT_ARB, or
PROGRAM_BINDING_ARB, GetProgramivARB returns one integer holding the
program string length (in bytes), program string format, and program
name, respectively, for the program object currently bound to
<target>.

If <pname> is MAX_PROGRAM_LOCAL_PARAMETERS_ARB or
MAX_PROGRAM_ENV_PARAMETERS_ARB, GetProgramivARB returns one integer
holding the maximum number of program local parameters or program
environment parameters, respectively, supported for the program
target <target>.

If <pname> is MAX_PROGRAM_INSTRUCTIONS_ARB,
MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, MAX_PROGRAM_TEX_INSTRUCTIONS_ARB,
MAX_PROGRAM_TEX_INDIRECTIONS_ARB, MAX_PROGRAM_TEMPORARIES_ARB,
MAX_PROGRAM_PARAMETERS_ARB, or MAX_PROGRAM_ATTRIBS_ARB,
GetProgramivARB returns a single integer giving the maximum number
of total instructions, ALU instructions, texture instructions,
texture indirections, temporaries, parameters, and attributes that
can be used by a program of type <target>. If <pname> is
PROGRAM_INSTRUCTIONS_ARB, PROGRAM_ALU_INSTRUCTIONS_ARB,
PROGRAM_TEX_INSTRUCTIONS_ARB, PROGRAM_TEX_INDIRECTIONS_ARB,
PROGRAM_TEMPORARIES_ARB, PROGRAM_PARAMETERS_ARB, or
PROGRAM_ATTRIBS_ARB, GetProgramivARB returns a single integer giving
the number of total instructions, ALU instructions, texture
instructions, texture indirections, temporaries, parameters, and
attributes used by the current program for <target>.

If <pname> is MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,
MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB,
MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB,
MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB,
MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,
MAX_PROGRAM_NATIVE_PARAMETERS_ARB, or
MAX_PROGRAM_NATIVE_ATTRIBS_ARB, GetProgramivARB returns a single
integer giving the maximum number of native instruction, ALU
instruction, texture instruction, texture indirection, temporary,
parameter, and attribute resources available to a program of type
<target>. If <pname> is PROGRAM_NATIVE_INSTRUCTIONS_ARB,
PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB,
PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB,
PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB,
PROGRAM_NATIVE_TEMPORARIES_ARB, PROGRAM_NATIVE_PARAMETERS_ARB, or
PROGRAM_NATIVE_ATTRIBS_ARB, GetProgramivARB returns a single integer
giving the number of native instruction, ALU instruction, texture
instruction, texture indirection, temporary, parameter, and
attribute resources consumed by the program currently bound to
<target>. Native resource counts will reflect the results of
implementation-dependent scheduling and optimization algorithms
applied by the GL, as well as emulation of non-native features. If
<pname> is PROGRAM_UNDER_NATIVE_LIMITS_ARB, GetProgramivARB returns
0 if the native resource consumption of the program currently bound
to <target> exceeds the number of available resources for any
resource type, and 1 otherwise. http://oss.sgi.com/projects/ogl-sample/registry/ARB/fragment_program.txt

V-man
02-17-2006, 11:23 AM
You can use ARB_vp and fp to collect the "max" numbers. The other way is visit www.delphi3d.net, (http://www.delphi3d.net,) go to hardware section. Example, for 9800 :
http://www.delphi3d.net/hardware/viewreport.php?report=1473


How can i know number of instructions in glsl shader.On ATI, you can't

Unfortunatly, the reason you get
"available number of ALU instructions exceeded"
is that the ATI GLSL compiler has issues.
Can you post the shader?

Hekus
02-19-2006, 12:19 PM
hm i install Catalyst 6.2 driver and now it compiled it, but fps is about 2 times slower

But when i attach fragment shader fps is good

Why when i use only vertex shader fps drop down and when i use in pair with fragment shader it rather good?

V-man

attribute vec4 Position;
attribute vec4 PositionNext;
attribute vec3 Normal;
attribute vec3 NormalNext;
attribute vec2 TexCoord0;

varying vec2 Tex0;
varying vec2 Tex1;
varying vec2 Tex2;
varying vec3 Tex3;
varying vec4 Color0;


vec2 texgen_sphere(vec4 epos,
vec3 norm)
{
vec3 vdir = normalize(epos.xyz);
vec3 ref = reflect(vdir, norm);
vec3 em = ref + vec3(0.0,0.0,1);
em.x = 2.0 * sqrt(dot(em, em));
vec2 tcoord = vec2(0.0,0.0);
tcoord.xy = ref.xy/em.x + 0.5;
return tcoord;
}

#define FogDepth FogParam[2].x
#define FogNearPlane FogParam[2].y
#define FogFarPlane FogParam[2].z
#define FogPos FogParam[0]
#define FogDir FogParam[1]


#define DetailRatio LocalParam.x
#define Lerp LocalParam.y
#define Refl LocalParam.z

uniform vec4 LocalParam;
uniform vec3 StaticLight[6];
uniform mat3 mCam;
uniform vec4 dLights_pos[3];
uniform vec3 dLights_col[3];
uniform vec3 FogParam[3];


void main()
{


mat3 ModelView3x3;
ModelView3x3[0] = gl_ModelViewMatrix[0].xyz;
ModelView3x3[1] = gl_ModelViewMatrix[1].xyz;
ModelView3x3[2] = gl_ModelViewMatrix[2].xyz;

// Make some animation
vec4 Pos = (1.0 - Lerp) * Position + Lerp * PositionNext;

gl_Position = gl_ModelViewProjectionMatrix * Pos;

Pos = gl_ModelViewMatrix * Pos;

vec3 Normal1;
Normal1=(1.0 - Lerp) * Normal + Lerp * NormalNext;
vec3 norm2;
vec3 norm = normalize( ModelView3x3 * Normal1 ) ;
norm2=mCam * Normal;

// calculate reflection texcoords
vec3 NormalRefl;
NormalRefl=(1.0 - Refl)*Normal1 + Refl*norm2;
Tex2 = texgen_sphere(Pos, NormalRefl);

// pass texture coord through the shader
Tex0 = TexCoord0;
Tex1 = TexCoord0*DetailRatio;

// calc total lights color

// ambient lighting


vec3 a=norm2.x>0.0 ? StaticLight[0] : StaticLight[3];
vec3 b=norm2.y>0.0 ? StaticLight[1] : StaticLight[4];
vec3 c=norm2.z>0.0 ? StaticLight[2] : StaticLight[5];

vec3 col=clamp((a*norm2.xxx + b*norm2.yyy + c*norm2.zzz), 0.0, 1.0);

// dinamic point light

for (int i=0; i<3; i++)
{
vec3 lvec=dLights_pos[i].xyz-Pos.xyz;
float len = sqrt( dot(lvec,lvec) );
float diffuse = clamp(dot( norm, lvec/len ), 0.0, 1.0);

col+= diffuse * dLights_col[i] * clamp( 1.0 - len/dLights_pos[i].w, 0.0, 1.0 );
}
/**/
// res_color.xyz=clamp(col, 0.0, 1).xyz;

Color0 = vec4(col, 1) * gl_Color;


// extract camera position and direction from modelvew matrix

float vert_cam_dist = Pos.z;
float vert_fog_dist = dot(FogDir, Pos.xyz) - dot(FogDir, FogPos);
float cam_fog_dist = - dot(FogDir, FogPos);

vec3 fog_tex;

fog_tex.x = -vert_fog_dist/FogDepth/4.0 + 0.5;
fog_tex.y = 0.5 + cam_fog_dist/FogDepth/4.0;
fog_tex.z = (-vert_cam_dist - FogNearPlane)/(FogFarPlane-FogNearPlane);

Tex3=fog_tex;

} //main

V-man
02-20-2006, 06:14 PM
I compiled with Cat 6.1 on a R9500 (similar to your GPU). It compiled and linked except I converted the attribs to the fixed func names.
I wanted to see if something new was amiss :)


Why when i use only vertex shader fps drop down and when i use in pair with fragment shader it rather good?Only an internal employee, perhaps humus, can answer that with sharp shooter precision.

All I can say is that the spec wants you to output to standard varyings, like gl_TexCoord[0], if you don't have a frag shader.

You can optimize your code.

vec4 Pos = (1.0 - Lerp) * Position + Lerp * PositionNext;

becomes

vec4 Pos = mix(Position, PositionNext, Lerp);