The difference between d8&d9's constants def in asm shaders
2013-05-10 00:12
323 查看
:::::Pick from dx9 sdk
The behavior of shader constants has changed between Direct3D 8 and Direct3D 9.
For Direct3D 9, constants set with defx assign values to the shader constant space. The lifetime of a constant declared with defx is confined to the execution of that shader only. Conversely, constants set using the APIs SetXXXShaderConstantX initialize constants in global space. Constants in global space are not copied to local space (visible to the shader) until SetxxxShaderConstants is called.
For Direct3D 8, constants set with defx or the APIs both assign values to the shader constant space. Each time the shader is executed, the constants are used by the current shader regardless of the technique used to set them.
Behavior of Constant Registers in Assembly Shaders
There are two ways to set constant registers in an assembly shader:Declare a shader constant in assembly code using one of the def* instructions.
Use one of the Set***ShaderConstant* API methods.
Direct3D 9 Shader Constants
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*.
Direct3D 8 Shader Constants
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.
Shader Driver Model Requirements
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.
Shader Binary Format
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).相关文章推荐
- the difference between request.getParameter()&request.getAttribute()
- What’s the Difference Between Sudo & Su?
- Q & A: The difference between hard and soft links
- The Differences Between POP3, IMAP & SMTP
- What is the difference between a = a * (2^3) and a = a << 3?
- The differences of Circuit Maintenance Messages between BICC &amp; ISUP
- The difference between 'typedef' and '#define'
- "Go to the Main Table Form" differences between Axapta 2.x and Dynamics AX 4
- The Difference between <resource-ref> and <resource-env-ref>,the title should be long...
- What's the difference between a URI and a URL?
- Oracle-The Main Difference Between DELETE & TRUNCATE
- The difference between Union & Union All in SQL Server/pOSTGRESQL
- The difference between "malloc" and "new"
- What is the difference between '/n' and '/r/n'? /n /r/n的区别是什么
- test the difference between "DEFAULT NULL" and "DEFAULT 0"
- The main difference between Java & C++(转载)
- Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
- What's the difference between @Component, @Repository & @Service annotations in Spring?
- The difference between "ModifyMenu" & "EnableMenuItem"
- CareerCup What is the difference between a computers heap and it's stack?