Source code of Windows XP (NT5)
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.

294 lines
10 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: vstream.h
  6. * Content: Direct3D Vertex Streams header
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef _VSTREAM_H
  11. #define _VSTREAM_H
  12. //---------------------------------------------------------------------
  13. // Constants
  14. //---------------------------------------------------------------------
  15. const DWORD RD_MAX_NUMELEMENTS = 16;
  16. const DWORD RD_MAX_NUMSTREAMS = RD_MAX_NUMELEMENTS;
  17. const DWORD RDVSD_STREAMTESS = RD_MAX_NUMSTREAMS;
  18. const DWORD RD_MAX_SHADERINSTSTRING = 128;
  19. const DWORD RD_MAX_SHADERTOKENSPERINST = 32;
  20. //---------------------------------------------------------------------
  21. // macros for parsing Declaration Token Array
  22. // TRUE, if shader handle is DX7 FVF code
  23. //---------------------------------------------------------------------
  24. #define RDVSD_ISLEGACY(ShaderHandle) !(ShaderHandle & D3DFVF_RESERVED0)
  25. enum RDVSD_DATALOAD
  26. {
  27. RDVSD_LOADREGISTER = 0,
  28. RDVSD_SKIP
  29. };
  30. #define RDVSD_GETTOKENTYPE(token) \
  31. ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT)
  32. #define RDVSD_ISSTREAMTESS(token) \
  33. ((token & D3DVSD_STREAMTESSMASK) >> D3DVSD_STREAMTESSSHIFT)
  34. #define RDVSD_GETDATALOADTYPE(token) \
  35. ((token & D3DVSD_DATALOADTYPEMASK) >> D3DVSD_DATALOADTYPESHIFT)
  36. #define RDVSD_GETDATATYPE(token) \
  37. ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT)
  38. #define RDVSD_GETSKIPCOUNT(token) \
  39. ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT)
  40. #define RDVSD_GETSTREAMNUMBER(token) \
  41. ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT)
  42. #define RDVSD_GETVERTEXREG(token) \
  43. ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT)
  44. #define RDVSD_GETVERTEXREGIN(token) \
  45. ((token & D3DVSD_VERTEXREGINMASK) >> D3DVSD_VERTEXREGINSHIFT)
  46. #define RDVSD_GETCONSTCOUNT(token) \
  47. ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT)
  48. #define RDVSD_GETCONSTADDRESS(token) \
  49. ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT)
  50. #define RDVSD_GETCONSTRS(token) \
  51. ((token & D3DVSD_CONSTRSMASK) >> D3DVSD_CONSTRSSHIFT)
  52. #define RDVSD_GETEXTCOUNT(token) \
  53. ((token & D3DVSD_EXTCOUNTMASK) >> D3DVSD_EXTCOUNTSHIFT)
  54. #define RDVSD_GETEXTINFO(token) \
  55. ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT)
  56. //---------------------------------------------------------------------
  57. //
  58. // RDVElement: Describes a vertex element
  59. //
  60. //---------------------------------------------------------------------
  61. // Function pointer that copies a vertex element into the 4-float vector.
  62. typedef void (*PFN_RDCOPYELEMENT)(LPVOID pInputStream,
  63. RDVECTOR4* pVertexRegister);
  64. class RDVElement
  65. {
  66. public:
  67. RDVElement()
  68. {
  69. memset( this, 0, sizeof( RDVElement ) );
  70. }
  71. // Pointer to a function to convert input vertex element data type to
  72. // the RDVECTOR4
  73. PFN_RDCOPYELEMENT m_pfnCopy;
  74. DWORD m_dwToken; // The token that described this vertex element.
  75. DWORD m_dwRegister; // Input register index
  76. DWORD m_dwDataType; // Data type and dimension
  77. DWORD m_dwStreamIndex; // API stream index
  78. DWORD m_dwOffset; // Offset in the input stream in bytes
  79. //
  80. // Tesselator support
  81. //
  82. BOOL m_bIsTessGen; // Is this vertex element generated by
  83. // tesselator
  84. DWORD m_dwRegisterIn; // Tesselator Input register index
  85. DWORD m_dwStreamIndexIn;// API stream index for m_dwRegisterIn
  86. DWORD m_dwOffsetIn; // Offset for m_dwRegisterIn in bytes
  87. };
  88. //---------------------------------------------------------------------
  89. //
  90. // RDVConstantData: Constant data that is used by a shader
  91. //
  92. //---------------------------------------------------------------------
  93. class RDVConstantData: public RDListEntry
  94. {
  95. public:
  96. RDVConstantData() {m_pData = NULL; m_dwCount = 0;}
  97. ~RDVConstantData() {delete m_pData;}
  98. DWORD m_dwCount; // Number of 4*DWORDs to load
  99. DWORD m_dwAddress; // Start constant register
  100. DWORD* m_pData; // Data. Multiple of 4*DWORD
  101. };
  102. //-----------------------------------------------------------------------------
  103. //
  104. // RDVStream: Class representing the vertex stream.
  105. //
  106. //-----------------------------------------------------------------------------
  107. class RDVStream
  108. {
  109. public:
  110. RDVStream()
  111. {
  112. m_pData = NULL;
  113. m_pSavedData = NULL;
  114. m_dwHandle = 0;
  115. m_dwNumVertices = 0;
  116. m_dwSize = 0;
  117. }
  118. // Stream memory.
  119. LPBYTE m_pData;
  120. // Temporary pointer
  121. LPBYTE m_pSavedData;
  122. // Vertex buffer handle
  123. DWORD m_dwHandle;
  124. // Vertex (or index) stride in bytes
  125. DWORD m_dwStride;
  126. // Max number of vertices (or indices in case of index buffer) the buffer
  127. // can store
  128. DWORD m_dwNumVertices;
  129. // Buffer size in bytes
  130. DWORD m_dwSize;
  131. // Output array for a tessellator
  132. GArrayT<BYTE> m_TessOut;
  133. };
  134. //-----------------------------------------------------------------------------
  135. //
  136. // RDIStream: Class representing the current Index stream
  137. //
  138. //-----------------------------------------------------------------------------
  139. class RDIStream: public RDVStream
  140. {
  141. public:
  142. RDIStream()
  143. {
  144. m_dwFlags = 0;
  145. }
  146. DWORD m_dwFlags; // User passed flags
  147. };
  148. //---------------------------------------------------------------------
  149. //
  150. // RDVStreamDecl:
  151. //
  152. // Describes a stream, used by a declaration
  153. //
  154. //---------------------------------------------------------------------
  155. class RDVStreamDecl
  156. {
  157. public:
  158. RDVStreamDecl();
  159. // Parses declaration.
  160. // For fixed-function pipeline computes FVF and FVF2 (used to record
  161. // texture presence)
  162. HRESULT Parse(DWORD ** ppToken, BOOL bFixedFunction, BOOL bStreamTess,
  163. UINT64* pqwFVF, UINT64* pqwFVF2, DWORD* pdwNumBetas);
  164. HRESULT MakeVElementArray( UINT64 qwFVF );
  165. RDVElement m_Elements[RD_MAX_NUMELEMENTS]; // Vertex elements in the
  166. // stream.
  167. DWORD m_dwNumElements; // Number of elements to use
  168. DWORD m_dwStride; // Vertex size in bytes
  169. DWORD m_dwStreamIndex; // Index to device streams
  170. BOOL m_bIsStreamTess; // Is it a tesselator stream ?
  171. };
  172. //---------------------------------------------------------------------
  173. //
  174. // RDVShaderInst:
  175. // The object representing each shader instruction. Used for
  176. // debugging, since the reference implementation directly interprets
  177. // the raw token stream during vshader execution.
  178. //-----------------------------------------------------------------------------
  179. class RDVShaderInst
  180. {
  181. public:
  182. char m_String[RD_MAX_SHADERINSTSTRING];
  183. DWORD m_Tokens[RD_MAX_SHADERTOKENSPERINST];
  184. DWORD* m_pComment;
  185. DWORD m_CommentSize;
  186. };
  187. //---------------------------------------------------------------------
  188. //
  189. // RDVShaderCode:
  190. // The object representing the compiled shader code.
  191. // In the reference implementation, there is really no compiling
  192. // happening. The compile phase consists of:
  193. // 1) Validating the the code.
  194. // 2) Computing the output FVF.
  195. // 3) Saving the original bits for later interpretation.
  196. // In the execution phase (in the RefVM) these saved bits are
  197. // interpreted.
  198. //-----------------------------------------------------------------------------
  199. class RDVShaderCode
  200. {
  201. public:
  202. RDVShaderCode() { memset( this, 0, sizeof( this ) ); }
  203. ~RDVShaderCode(){ delete m_pRawBits; if (m_pInst) delete m_pInst; }
  204. inline UINT GetInstructionCount( void ) { return m_InstCount; }
  205. LPDWORD m_pRawBits; // Raw code bits
  206. DWORD m_dwSize; // Number of DWORDs
  207. UINT m_InstCount; // Instruction count (for debug monitor)
  208. RDVShaderInst* m_pInst; // Instruction array (for debug monitor)
  209. // Output FVF for this shaders
  210. UINT64 m_qwFVFOut;
  211. };
  212. //---------------------------------------------------------------------
  213. //
  214. // RDVDeclaration:
  215. // The object representing the parsed and compiled declaration.
  216. //-----------------------------------------------------------------------------
  217. class RDVDeclaration
  218. {
  219. public:
  220. RDVDeclaration()
  221. {
  222. memset( this, 0, sizeof( RDVDeclaration ) );
  223. }
  224. ~RDVDeclaration();
  225. HRESULT Parse( DWORD * decl, BOOL bFixedFunction );
  226. HRESULT MakeVElementArray( UINT64 qwFVF );
  227. // List of streams, which are used by the declaration
  228. // The additional one is used for the Tesselator stream.
  229. RDVStreamDecl m_StreamArray[RD_MAX_NUMSTREAMS + 1];
  230. // Number of active streams
  231. DWORD m_dwNumActiveStreams;
  232. // Corresponding FVF for fixed-function pipeline
  233. // This is OR of all streams input FVF
  234. UINT64 m_qwInputFVF;
  235. // Constant data that should be loaded when shader becomes active
  236. RDVConstantData* m_pConstants;
  237. // The description of all vertex elements to be loaded into input
  238. // registers. The array is built by going through active streams and
  239. // elements inside each stream
  240. RDVElement m_VertexElements[RD_MAX_NUMELEMENTS];
  241. // Number of used members of m_VertexElements
  242. DWORD m_dwNumElements;
  243. // Stride computed for the implicit tesselator stream
  244. DWORD m_dwStreamTessStride;
  245. };
  246. //-----------------------------------------------------------------------------
  247. //
  248. // RDVShader: Vertex Shader Class
  249. //
  250. //-----------------------------------------------------------------------------
  251. class RDVShader
  252. {
  253. public:
  254. RDVShader();
  255. ~RDVShader();
  256. HRESULT Initialize(DWORD* lpdwDeclaration, DWORD* lpdwFunction);
  257. RDVDeclaration m_Declaration;
  258. RDVShaderCode* m_pCode;
  259. inline BOOL IsFixedFunction()
  260. {
  261. return (m_pCode == NULL);
  262. }
  263. };
  264. typedef RDVShader *PRDVSHADER;
  265. #endif _VSTREAM_H