How many different shaders are possible?

Started by
5 comments, last by zedz 16 years, 6 months ago
Hi there, I am working on a program which will have many different versions of the same shader (to avoid branching, ...). I wonder whether there's a limit how many shaders (or shader-instructions, or whatever) can be uploaded to the card simultaneously? Does anybody know where the programs are storen on the GPU-Board, are they stored in VRAM? Thank you in advance, lg Clemens
Advertisement
Shader programs are very small in size, you can store hundreds of them in VRAM and not even notice. I don't know of any built-in limit, other than the amount of memory available. Internally, shaders are stored in main RAM (microcode and GLSL headers) and parts are typically copied into VRAM, probably just the microcode, although this depends on the card and the OpenGL driver.

There is a hard limit of how many instructions a shader can have. This entirely depends on the amount of microcode memory the card has and the profile (Shader Model 2, Shader Model 3, etc)

I know in D3D there is D3DCAPS9.MaxPixelShader30InstructionSlots, I'm not sure what the equivalent in OpenGL is.

[Edited by - deathkrush on October 10, 2007 1:00:03 AM]
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
i know of instances where ppl are using 1000s (though perhaps not all simultaneously), personally ive had ~200 loaded + used in a frame
This has a list of cards, driver versions, different GL info
http://delphi3d.net/hardware/index.php

For example, the 8800 supports 32 texture units in the vertex shader. NV_vertex_program3 was used to query that feature.

ARB_vertex_program and ARB_fragment_program can be used to get some details.
The GLSL functions don't offer much in terms of quering the card's capabilities.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thats really good news for me :)

Oh, a last question ... how expensive is it to attach/detach a shader from a program (is this thre preferred way if disabling a shader?)? Of course this depends heavily on driver and GPU but I read that in general it can be quite expensive.
What I have to do is to render many small quads (maybe between 20x20 and 100x100) maybe with other shaders, and well it would be cool to know when using a faster shader would be benefitial and when the switch would eat up all benefits.

Thanks, lg Clemens
Well ive read switching between shaders is very slow but rather let someone more educated than me give you a proper answer
yes there is someoverhead with shader switching, if youre only gonna draw a few fragments than changing uniforms etc is perhaps a better way to go (benchmark to see)
though one thing ive seen is with fullscreen effects eg blurring
ive seen ppl use the same shader for horizontal as well as vertical + just change the uniforms so its either blurring horizontally + then vertically. in such a case its better to have 2 different shaders

This topic is closed to new replies.

Advertisement