Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
8.0 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dsset.h
  8. *
  9. * Content: State set (block) management macros and structures
  10. *
  11. * Copyright (c) 1999-2003 Microsoft Corporation. All rights reserved.
  12. \*****************************************************************************/
  13. #if DX7_D3DSTATEBLOCKS
  14. //-----------------------------------------------------------------------------
  15. // State sets structure definitions
  16. //-----------------------------------------------------------------------------
  17. // How big is a FLAG field and how many bits can it accomodate
  18. #define FLAG DWORD
  19. #define FLAG_SIZE (8*sizeof(DWORD))
  20. // How many RS and TS stages are there (on this hw we only store 2 TSS)
  21. #define SB_MAX_STATE D3DSTATE_OVERRIDE_BIAS
  22. #define SB_MAX_STAGES 2
  23. // This value may change with the version of DX
  24. #define SB_MAX_TSS D3DTSS_MAX
  25. // FLAGS to indicate which state has been changed
  26. #define SB_VIEWPORT_CHANGED 1
  27. #define SB_ZRANGE_CHANGED 2
  28. #define SB_CUR_VS_CHANGED 4
  29. #define SB_INDICES_CHANGED 8
  30. #define SB_STREAMSRC_CHANGED (1 << 15)
  31. #define SB_TNL_MATERIAL_CHANGED 1
  32. #define SB_TNL_MATRIX_CHANGED 2
  33. #define SB_TNL_CUR_PS_CHANGED (1 << 31)
  34. // We store state blocks in two different formats: uncompressed and compressed.
  35. // The uncompressd format is much better while we're recording the state
  36. // block whereas the compressed format is much more compact and suitable for
  37. // state block execution. When a state block is ended (it's done recording)
  38. // the driver performs this transformation. Out records are defined as unions
  39. // in order to make the code easier to implement. The bCompressed field
  40. // indicates the current format used in the block.
  41. //
  42. // In between STATESETBEGIN and STATESETEND, no shader\light will be created\
  43. // destroyed.
  44. //
  45. // The compressed format will contain pointers to the commands to be executed,
  46. // so that no extra command parsing cost is involved.
  47. //
  48. typedef struct _UnCompStateSet {
  49. // Size of uncompressed state set
  50. DWORD dwSize;
  51. // Stored state block info (uncompressed)
  52. // Flags tell us which fields have been set
  53. DWORD RenderStates[SB_MAX_STATE];
  54. DWORD TssStates[SB_MAX_STAGES][SB_MAX_TSS];
  55. FLAG bStoredRS[(SB_MAX_STATE + FLAG_SIZE)/ FLAG_SIZE];
  56. FLAG bStoredTSS[SB_MAX_STAGES][(SB_MAX_TSS + FLAG_SIZE) / FLAG_SIZE];
  57. // Flag to indicate what information has been changed
  58. // Upper 16 bits are used for stream sources
  59. DWORD dwFlags;
  60. // Information for viewport
  61. D3DHAL_DP2VIEWPORTINFO viewport;
  62. // Information for z-range;
  63. D3DHAL_DP2ZRANGE zRange;
  64. #if DX8_DDI
  65. // Information for indices
  66. D3DHAL_DP2SETINDICES vertexIndex;
  67. // Information for stream source, only 1 for Permedia3
  68. D3DHAL_DP2SETSTREAMSOURCE streamSource[D3DVS_INPUTREG_MAX_V1_1];
  69. #endif //DX8_DDI
  70. #if DX7_SB_TNL
  71. // The least significant bit is used for material, others are used for matrices
  72. FLAG dwTnLFlags;
  73. // Information related to lights, size depends on the number of lights at
  74. // D3DHAL_STATESETBEGIN time
  75. DWORD dwNumLights;
  76. DWORD* pdwLightStateChanged;
  77. DWORD* pdwLightState;
  78. D3DLIGHT7* pLightData;
  79. // Information related to clip planes, size depends on the number of clip
  80. // planes at D3DHAL_STATESETBEGIN time
  81. DWORD dwNumClipPlanes;
  82. DWORD* pdwPlaneChanged;
  83. D3DVALUE* pPlaneCoff[4];
  84. // Information related to material
  85. D3DMATERIAL7 material;
  86. // Information related to transformation
  87. D3DMATRIX transMatrices[D3DTRANSFORMSTATE_TEXTURE7 + 1];
  88. #endif // DX7_SB_TNL
  89. #if DX8_SB_SHADERS
  90. // Number of vertex/pixel shaders, captured at D3DHAL_STATESETBEGIN time
  91. WORD wNumVertexShader;
  92. WORD wNumPixelShader;
  93. // Information for vertex/pixel shader constants
  94. FLAG* pdwVSConstChanged;
  95. D3DVALUE* pdvVSConsts[4];
  96. FLAG* pdwPSConstChanged;
  97. D3DVALUE* pdvPSConsts[4];
  98. // Offset from the beginning of uc to the shader info blocks
  99. // (flags + constant register values)
  100. DWORD dwOffsetVSInfo;
  101. DWORD dwOffsetPSInfo;
  102. // Information for current pixel shader
  103. DWORD dwCurPixelShader;
  104. #endif // DX8_SB_SHADERS
  105. #if DX8_DDI
  106. // Information for current vertex shader
  107. DWORD dwCurVertexShader;
  108. #endif // DX8_DDI
  109. } UnCompStateSet, *PUnCompStateSet;
  110. typedef struct _OffsetsCompSS {
  111. // Offset from the beginning of this structure
  112. DWORD dwOffDP2RenderState;
  113. DWORD dwOffDP2TextureStageState;
  114. DWORD dwOffDP2Viewport; // Single
  115. DWORD dwOffDP2ZRange; // Single
  116. #if DX8_DDI
  117. DWORD dwOffDP2SetIndices; // Single
  118. DWORD dwOffDP2SetStreamSources;
  119. #endif // DX8_DDI
  120. #if DX7_SB_TNL
  121. DWORD dwOffDP2SetLights;
  122. DWORD dwOffDP2SetClipPlanes;
  123. DWORD dwOffDP2SetMaterial; // Single
  124. #endif // DX7_SB_TNL
  125. #if DX8_SB_SHADERS
  126. // Number of vertex/pixel shader constant commands
  127. WORD wNumVSConstCmdPair;
  128. WORD wNumPSConstCmdPair;
  129. // Double indirection to the set current shader/set shader constant pairs
  130. DWORD *pdwOffDP2VSConstCmd;
  131. DWORD *pdwOffDP2PSConstCmd;
  132. DWORD dwOffDP2SetPixelShader;
  133. #endif // DX8_SB_SHADERS
  134. #if DX8_DDI
  135. DWORD dwOffDP2SetVertexShader;
  136. #endif // DX8_DDI
  137. } OffsetsCompSS;
  138. // After this fixed memory block, there is a size variable DP2 command stream
  139. // Correponding DP2 command pointer is not NULL, if that command is in the
  140. // state set. ppDP2{VS|PS}ConstCmd has to be double indirection, DP2 command
  141. // pointer pairs in it point to set current {V|P} shader and set {V|P} shader
  142. // constants DP2 command.
  143. typedef struct _CompressedStateSet {
  144. D3DHAL_DP2COMMAND* pDP2RenderState;
  145. D3DHAL_DP2COMMAND* pDP2TextureStageState;
  146. D3DHAL_DP2COMMAND* pDP2Viewport; // Single
  147. D3DHAL_DP2COMMAND* pDP2ZRange; // Single
  148. #if DX8_DDI
  149. D3DHAL_DP2COMMAND* pDP2SetIndices; // Single
  150. D3DHAL_DP2COMMAND* pDP2SetStreamSources;
  151. #endif // DX8_DDI
  152. #if DX7_SB_TNL
  153. D3DHAL_DP2COMMAND* pDP2SetLights;
  154. D3DHAL_DP2COMMAND* pDP2SetClipPlanes;
  155. D3DHAL_DP2COMMAND* pDP2SetMaterial; // Single
  156. D3DHAL_DP2COMMAND* pDP2SetTransform;
  157. #endif // DX7_SB_TNL
  158. #if DX8_SB_SHADERS
  159. // Number of vertex/pixel shader constant commands
  160. WORD wNumVSConstCmdPair;
  161. WORD wNumPSConstCmdPair;
  162. // Pairs of set vertex shader and set VS constants
  163. D3DHAL_DP2COMMAND** ppDP2VSConstCmd;
  164. // Pairs of set pixel shader and set PS constants
  165. D3DHAL_DP2COMMAND** ppDP2PSConstCmd;
  166. // These 2 command must be after the above 2 set shader const commands
  167. D3DHAL_DP2COMMAND* pDP2SetPixelShader;
  168. #endif // DX8_SB_SHADERS
  169. #if DX8_DDI
  170. D3DHAL_DP2COMMAND* pDP2SetVertexShader;
  171. #endif DX8_DDI
  172. } CompressedStateSet, *PCompressedStateSet;
  173. // The state set is compressed
  174. #define SB_COMPRESSED 0x1
  175. // Values in the state set were changed by the capturing
  176. #define SB_VAL_CAPTURED 0x2
  177. typedef struct _P3StateSetRec {
  178. DWORD dwHandle;
  179. DWORD dwSSFlags;
  180. union {
  181. UnCompStateSet uc;
  182. CompressedStateSet cc;
  183. };
  184. } P3StateSetRec , *PP3StateSetRec;
  185. // How many pointers can we store in a 4K page. Pools of pointers are allocated
  186. // in this chunks in order to optimize kernel pool usage (we use 4000 vs 4096
  187. // for any extra data the kernel allocator might put up along with the pool)
  188. #define SSPTRS_PERPAGE (4000/sizeof(P3StateSetRec *))
  189. #define FLAG_SET(flag, number) \
  190. flag[ (number) / FLAG_SIZE ] |= (1 << ((number) % FLAG_SIZE))
  191. #define IS_FLAG_SET(flag, number) \
  192. (flag[ (number) / FLAG_SIZE ] & (1 << ((number) % FLAG_SIZE) ))
  193. #endif //DX7_D3DSTATEBLOCKS