Shaders drive the programmable graphics pipeline.
Vertex Shader Differences summarizes the differences between vertex shader versions.
Pixel Shader Differences summarizes the differences between pixel shader versions.
There are two ways to set constant registers in an assembly shader:
In Direct3D 9 the lifetime of defined constants in a given shader is confined to the execution of that shader only (and is non-overridable). Defined constants in Direct3D 9 have no side effects outside of the shader.
Here's an example using Direct3D 9:
Given: Create shader1 which references c4 and defines it with the def instruction Scenario 1: Call Set***Shader shader1 Call Set***ShaderConstant* to set c4 Call Draw Result: The shader will see the def'd value in c4 Given: Scenario 1 has just completed Create shader2 (which references c4 but does not use the def instruction to define it) Scenario 2: Call Set***Shader shader2 Call Draw Result: The shader will see the value last set in c4 by Set***ShaderConstant* in scenario 1. This is because shader 2 didn't def c4.
In Direct3D 9, calling Get***ShaderConstant* will only retrieve constant values set via Set***ShaderConstant*.
This behavior is different in Direct3D 8.x.
Given: Create shader1 which references c4 and defines it with the def instruction Scenario 1 (repeated with Direct3D 8): Call Set***Shader with shader1 Call Set***ShaderConstant to set c4 Call Draw Result: The shader will see the value in c4 from Set***ShaderConstant
In Direct3D 8.x Set***ShaderConstant takes effect immediately. Consider this scenario:
Given: Create shader1 which references c4 and defines it with the def instruction Scenario 3: Call Set***Shader with shader1 Call Draw Result: The shader will see the def'd value in c4 Given: Scenario 3 has just completed Create shader2 (which references c4 but does not use the def instruction to define it) Scenario 4 : Call Set***Shader with shader2 Call Draw Result: The shader will see the def'd value in c4 (set by def in shader 1)
The undesirable result is that the order in which the shaders are set could affect the observed behavior of individual shaders.
Direct3D 9 interfaces are restricted to device driver interface (DDI) drivers that are DirectX 7-level and above. To check the DDI level, run the DirectX Diagnostic Tool and examine the saved text file.
For reference, Direct3D 8 interfaces work only on DDI drivers that are DirectX 6-level and above.
The bitwise layout of the shader instruction stream is defined in D3d9types.h. If you want to design your own shader compiler or construction tools and you want more information about the shader token stream, refer to the Direct3D 9 Driver Development Kit (DDK).
See HLSL Shader Reference to experience a C-like shader language.