How is the shader file compiled into machine code?

991060

Regular
Acoording to my limited knowledge,if I was using HLSL or Cg,the text file has to be first compiled to the assembly shaders,than the compiled shaders need to be compiled again to the form of binary machine code,is that right?

If I was right,who's in charge of the 2 compilation?

I think the first compilation is done using the HLSL compiler or the Cg compiler which come from MS and Nvidia,respectively.

And what about the 2nd compilation? Is the compiler in charge of this step residing in the driver or the DirectX runtime?
 
There are three (logical) stages:
1. HLL -> Assembly language
2. Assembly language -> bytecode
3. bytecode -> hardware specific code.

Alternatively the HLL could be compiled directly to bytecode. I don't know exactly how DirectX does it. The bytecode is not a 'machine code' as traditionally defined - it sits conceptually as a similar class citizen to JVM code.

3 will always be in the drivers, as the hardware shader code is proprietary.
 
Dio said:
There are three (logical) stages:
1. HLL -> Assembly language
2. Assembly language -> bytecode
3. bytecode -> hardware specific code.

Alternatively the HLL could be compiled directly to bytecode.
This (HLL-> bytecode) is what GLSL does, but the bytecode is implementation specific and private to the driver. I think there was discussion above having a standard bytecode representation that could be saved off / loaded up, but it was decided to leave it for the first version of the specs.

So to answer the original question from a GL perspective, all the compilers are the responsibilty of the driver writer.
 
Just minor additions:

Dio said:
There are three (logical) stages:
1. HLL -> Assembly language
2. Assembly language -> bytecode
3. bytecode -> hardware specific code.

1 and 2 are in D3DX (a utility library) or in external tools.
The D3D runtime accepts bytecode and passes it unchanged to the driver.
In other words the runtime does NONE of the compilations.

Alternatively the HLL could be compiled directly to bytecode. I don't know exactly how DirectX does it. The bytecode is not a 'machine code' as traditionally defined - it sits conceptually as a similar class citizen to JVM code.

Yes, HLL -> bytecode is possible, unsurprisingly as both compilation steps are done in the same library anyway.
 
Back
Top