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.

288 lines
11 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: vshader.hpp
  6. * Content: Direct3D vertex shader internal include file
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef _VSHADER_HPP
  11. #define _VSHADER_HPP
  12. #include "d3dfe.hpp"
  13. #include "vvm.h"
  14. #include "hmgr.hpp"
  15. #include "vbuffer.hpp"
  16. #include "ibuffer.hpp"
  17. void CheckForNull(LPVOID p, DWORD line, char* file);
  18. class CD3DBase;
  19. //---------------------------------------------------------------------
  20. // macros for parsing Declaration Token Array
  21. // TRUE, if shader handle is DX7 FVF code
  22. //
  23. #define D3DVSD_ISLEGACY(ShaderHandle) !(ShaderHandle & D3DFVF_RESERVED0)
  24. enum D3DVSD_DATALOAD
  25. {
  26. D3DVSD_LOADREGISTER = 0,
  27. D3DVSD_SKIP
  28. };
  29. #define D3DVSD_GETTOKENTYPE(token) ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT)
  30. #define D3DVSD_ISSTREAMTESS(token) ((token & D3DVSD_STREAMTESSMASK) >> (D3DVSD_TOKENTYPESHIFT - 1))
  31. #define D3DVSD_GETDATALOADTYPE(token) ((token & D3DVSD_DATALOADTYPEMASK) >> D3DVSD_DATALOADTYPESHIFT)
  32. #define D3DVSD_GETDATATYPE(token) ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT)
  33. #define D3DVSD_GETSKIPCOUNT(token) ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT)
  34. #define D3DVSD_GETSTREAMNUMBER(token) ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT)
  35. #define D3DVSD_GETVERTEXREG(token) ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT)
  36. #define D3DVSD_GETCONSTCOUNT(token) ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT)
  37. #define D3DVSD_GETCONSTADDRESS(token) ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT)
  38. #define D3DVSD_GETCONSTRS(token) ((token & D3DVSD_CONSTRSMASK) >> D3DVSD_CONSTRSSHIFT)
  39. #define D3DVSD_GETEXTCOUNT(token) ((token & D3DVSD_EXTCOUNTMASK) >> D3DVSD_EXTCOUNTSHIFT)
  40. #define D3DVSD_GETEXTINFO(token) ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT)
  41. //---------------------------------------------------------------------
  42. //
  43. // CVConstantData: Constant data that is used by a shader
  44. //
  45. //---------------------------------------------------------------------
  46. struct CVConstantData: public CListEntry
  47. {
  48. CVConstantData() {m_pData = NULL; m_dwCount = 0;}
  49. ~CVConstantData() {delete m_pData;}
  50. DWORD m_dwCount; // Number of 4*DWORDs to load
  51. DWORD m_dwAddress; // Start constant register
  52. DWORD* m_pData; // Data. Multiple of 4*DWORD
  53. };
  54. //---------------------------------------------------------------------
  55. //
  56. // CVStreamDecl:
  57. //
  58. // Describes a stream, used by a declaration
  59. //
  60. //---------------------------------------------------------------------
  61. class CVStreamDecl: public CListEntry
  62. {
  63. public:
  64. CVStreamDecl()
  65. {
  66. m_dwNumElements = 0;
  67. m_dwStride = 0;
  68. m_dwStreamIndex = 0xFFFFFFFF;
  69. #if DBG
  70. m_dwFVF = 0;
  71. #endif // DBG
  72. }
  73. // Parses declaration.
  74. // For fixed-function pipeline computes FVF, FVF2 (used to record
  75. // texture presense) and number of floats after position
  76. void Parse(CD3DBase* pDevice, DWORD CONST ** ppToken, BOOL bFixedFunction,
  77. DWORD* pdwFVF, DWORD* pdwFVF2, DWORD* pnFloats,
  78. BOOL* pbLegacyFVF, UINT Usage, BOOL bTessStream = FALSE);
  79. CVElement m_Elements[__NUMELEMENTS]; // Vertex elements in the stream
  80. DWORD m_dwNumElements; // Number of elements to use
  81. DWORD m_dwStride; // Vertex size in bytes
  82. DWORD m_dwStreamIndex; // Index to device streams
  83. #if DBG
  84. // FVF, computed from declaration. Used for fixed function pipeline only
  85. DWORD m_dwFVF;
  86. #endif //DBG
  87. };
  88. //---------------------------------------------------------------------
  89. //
  90. // CVDeclaration:
  91. //
  92. // D3D parses declaration byte-codes and creates this data structure.
  93. //
  94. //-----------------------------------------------------------------------------
  95. class CVDeclaration
  96. {
  97. public:
  98. CVDeclaration(DWORD dwNumStreams);
  99. ~CVDeclaration();
  100. //------------- Used during declaration parsing -----------
  101. // pDeclSize will have size of the declaration in bytes if not NULL
  102. void Parse(CD3DBase* pDevice, CONST DWORD * decl, BOOL bFixedFunction,
  103. DWORD* pDeclSize, UINT Usage);
  104. // List of streams, which are used by the declaration
  105. CVStreamDecl* m_pActiveStreams;
  106. CVStreamDecl* m_pActiveStreamsTail;
  107. // Corresponding FVF for fixed-function pipeline
  108. // This is OR of all streams input FVF
  109. DWORD m_dwInputFVF;
  110. // This is computed for legacy TL capable hardware.
  111. // If this is NULL, that means that the declaration is too complex
  112. // for these devices.
  113. BOOL m_bLegacyFVF;
  114. // TRUE when a tesselator stream is present in the declaration.
  115. // We need this to validate that the stream is not passed to DrawPrimitive
  116. // API.
  117. BOOL m_bStreamTessPresent;
  118. // Max number of available streams
  119. DWORD m_dwNumStreams;
  120. // Constant data that should be loaded when shader becomes active
  121. CVConstantData* m_pConstants;
  122. CVConstantData* m_pConstantsTail;
  123. //------------- Used by PSGP ---------------
  124. // The description of all vertex elements to be loaded into input registers.
  125. // The array is built by going through active streams and elements inside
  126. // each stream
  127. CVElement m_VertexElements[__NUMELEMENTS];
  128. // Number of used members of m_VertexElements
  129. DWORD m_dwNumElements;
  130. friend class CD3DHal;
  131. };
  132. //-----------------------------------------------------------------------------
  133. //
  134. // CVStreamBase: Class representing the digested information for vertex
  135. // stream in the MS implementation.
  136. //
  137. //-----------------------------------------------------------------------------
  138. struct CVStreamBase
  139. {
  140. CVStreamBase()
  141. {
  142. m_pData = NULL;
  143. m_dwStride = 0;
  144. #if DBG
  145. m_dwSize = 0;
  146. #endif
  147. m_dwNumVertices = 0;
  148. m_dwIndex = 0;
  149. }
  150. // Stream memory. In case of vertex buffers (m_pVB != NULL), we lock the
  151. // vertex buffer and assign its memory pointer to the m_pData
  152. LPBYTE m_pData;
  153. // Vertex (or index) stride in bytes
  154. DWORD m_dwStride;
  155. #if DBG
  156. // Buffer size in bytes
  157. DWORD m_dwSize;
  158. #endif // DBG
  159. // Index of the stream. Needed when we access streams through pointers
  160. // m_dwIndex == __NUMSTREAMS is a flag when CIndexBuffer is used
  161. DWORD m_dwIndex;
  162. // Max number of vertices (or indices in case of index buffer) the buffer
  163. // can store (valid in DBG only !!!).
  164. // For internal TL buffers this is used as number of vertices, currently
  165. // written to the buffer.
  166. DWORD m_dwNumVertices;
  167. };
  168. //-----------------------------------------------------------------------------
  169. //
  170. // CVStream: Class representing the digested information for vertex
  171. // stream in the MS implementation.
  172. //
  173. //-----------------------------------------------------------------------------
  174. struct CVStream: public CVStreamBase
  175. {
  176. CVStream() {m_pVB = NULL;}
  177. BYTE* Data()
  178. {
  179. if (m_pVB)
  180. return m_pVB->Data();
  181. else
  182. return m_pData;
  183. }
  184. ~CVStream();
  185. virtual BOOL IsUserMemStream() {return FALSE;}
  186. CVertexBuffer *m_pVB; // User passed VB
  187. };
  188. //-----------------------------------------------------------------------------
  189. //
  190. // CVStream: Class representing the digested information for vertex
  191. // stream in the MS implementation.
  192. //
  193. //-----------------------------------------------------------------------------
  194. struct CVIndexStream: public CVStreamBase
  195. {
  196. CVIndexStream()
  197. {
  198. m_dwBaseIndex = 0;
  199. m_dwIndex = __NUMSTREAMS; // Mark the stream as index stream
  200. m_pVBI = NULL;
  201. }
  202. BYTE* Data()
  203. {
  204. if (m_pVBI)
  205. return m_pVBI->Data();
  206. else
  207. return m_pData;
  208. }
  209. ~CVIndexStream();
  210. DWORD m_dwBaseIndex; // Vertex index, that corresponds to the index 0
  211. CIndexBuffer *m_pVBI; // User passed VB
  212. };
  213. //-----------------------------------------------------------------------------
  214. //
  215. // CVShader: Vertex Shader Class
  216. //
  217. //-----------------------------------------------------------------------------
  218. class CVShader : public CD3DBaseObj
  219. {
  220. public:
  221. CVShader(DWORD dwNumStreams): m_Declaration(dwNumStreams)
  222. {
  223. m_dwFlags = 0;
  224. m_pCode = NULL;
  225. m_pOrgDeclaration = NULL;
  226. m_OrgDeclSize = 0;
  227. m_pOrgFuncCode = NULL;
  228. m_OrgFuncCodeSize = 0;
  229. m_pStrippedFuncCode = NULL;
  230. m_StrippedFuncCodeSize = 0;
  231. }
  232. ~CVShader()
  233. {
  234. delete m_pCode;
  235. delete m_pOrgDeclaration;
  236. delete m_pOrgFuncCode;
  237. delete m_pStrippedFuncCode;
  238. }
  239. HRESULT Initialize(DWORD* lpdwDeclaration, DWORD* lpdwFunction);
  240. // Bits for m_dwFlags
  241. static const DWORD FIXEDFUNCTION; // This is fixed-function shader
  242. static const DWORD SOFTWARE; // Shader is used with software pipeline
  243. CVDeclaration m_Declaration;
  244. CVShaderCode* m_pCode; // PSGP vertex shader object
  245. // Used to process point sprites.
  246. DWORD m_dwFlags;
  247. DWORD m_dwInputFVF; // Input FVF for fixed-function pipeline
  248. DWORD* m_pOrgDeclaration; // Original declaration
  249. UINT m_OrgDeclSize; // Size in bytes
  250. DWORD* m_pOrgFuncCode; // Original function code
  251. UINT m_OrgFuncCodeSize; // Size in bytes
  252. DWORD* m_pStrippedFuncCode; // Comment-stripped function code
  253. UINT m_StrippedFuncCodeSize; // Size in bytes
  254. };
  255. typedef CVShader *LPVSHADER;
  256. //-----------------------------------------------------------------------------
  257. //
  258. // CVShaderHandleFactory: Vertex Shader Handle Factory
  259. //
  260. //-----------------------------------------------------------------------------
  261. class CVShaderHandleFactory : public CHandleFactory
  262. {
  263. public:
  264. DWORD CreateNewHandle( LPVSHADER pVShader );
  265. LPD3DBASEOBJ GetObject( DWORD dwHandle ) const;
  266. void ReleaseHandle(DWORD handle, BOOL);
  267. BOOL SetObject( DWORD dwHandle, LPD3DBASEOBJ );
  268. virtual UINT HandleFromIndex( DWORD index) const {return (index << 1) + 1;}
  269. CVShader* GetObjectFast(DWORD dwHandle) const
  270. {
  271. return (CVShader*)((reinterpret_cast<CHandle*>(m_Handles.GetArrayPointer())[dwHandle >> 1]).m_pObj);
  272. }
  273. };
  274. #endif _VSHADER_HPP