Sign in to follow this  
rogerdv

question about shaders

Recommended Posts

rogerdv    418
I have a few doubts about shader technology internals. As fas as I know we have GLSL, Cg and HLSL. Also Pixel shader 1.0, 2.0, etc. When a program executes a shader, it passes the high level program to the card or the driver compiles that high level program to some asm like code? What's the difference between the pixel shader (PS 2.0) version and high level language version (lets say GLSL 1.3)?

Share this post


Link to post
Share on other sites
Zipster    2365
Usually what happens is that the shader is compiled down to assembly on the CPU (such as ps_2_0), and that assembly is passed onto the GPU. This assembly is standardized across graphics cards so you only have to write it once (but of course nowadays you're actually writing the higher-level HLSL/GLSL/Cg/etc., which is also standard across graphics cards). The GPU then takes that assembly and converts it into its own special microcode which is specific to the hardware and executes that directly.

The pixel shader version basically determines what kind of functionality you have available to you, and what assembly your code gets compiled down to. You can write all sorts of high-level code, but if you compile against a version that doesn't support a feature you're trying to use (i.e. dependent texture reads, loops, dynamic branching), you'll get a compile error.

Hopefully that was along the lines of what you were looking for :)

Share this post


Link to post
Share on other sites
Ashkan    451
Nobody said the shader is compiled every single time it's used or passed onto the GPU. As a matter of fact, it's only compiled once and reused from there on, since there's no point in recompiling a code that's not changed. I was talking about WHAT is in charge of compiling the shaders under different APIs, not how often they're compiled. In Direct3D, you even have the option of pre-compiling all shaders offline and loading the pre-compiled assembly code during runtime.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this