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.

1354 lines
60 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3di.hpp
  6. * Content: Direct3D internal include file
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef _D3DI_HPP
  11. #define _D3DI_HPP
  12. // Allow fast path
  13. #define FAST_PATH
  14. #include "ddrawp.h"
  15. #include "d3d8p.h"
  16. #include "d3dmem.h"
  17. #if !defined(BUILD_DDDDK)
  18. extern "C" {
  19. #include "ddrawi.h"
  20. };
  21. #include "lists.hpp"
  22. #include <d3ditype.h>
  23. #include <d3dutil.h>
  24. #include <d3dfe.hpp>
  25. #include <vshader.hpp>
  26. #include <pshader.hpp>
  27. #include "ddi.h"
  28. //--------------------------------------------------------------------
  29. const DWORD __INIT_VERTEX_NUMBER = 1024;// Initial number of vertices in TL and
  30. // clip flag buffers
  31. //--------------------------------------------------------------------
  32. /*
  33. * Registry defines
  34. */
  35. #define RESPATH "Software\\Microsoft\\Direct3D\\Drivers"
  36. #define RESPATH_D3D "Software\\Microsoft\\Direct3D"
  37. #define STATS_FONT_FACE "Terminal"
  38. #define STATS_FONT_SIZE 9
  39. extern HINSTANCE hGeometryDLL;
  40. /*
  41. * CPU family and features flags
  42. */
  43. extern DWORD dwCPUFamily, dwCPUFeatures;
  44. extern char szCPUString[];
  45. // MMX available
  46. #define D3DCPU_MMX 0x00000001L
  47. // FCOMI and CMOV are both supported
  48. #define D3DCPU_FCOMICMOV 0x00000002L
  49. // Reads block until satisfied
  50. #define D3DCPU_BLOCKINGREAD 0x00000004L
  51. // Extended 3D support available
  52. #define D3DCPU_X3D 0x00000008L
  53. // Pentium II CPU
  54. #define D3DCPU_PII 0x000000010L
  55. // Streaming SIMD Extensions (aka Katmai) CPU
  56. #define D3DCPU_SSE 0x000000020L
  57. // Streaming SIMD2 Extensions (aka Willamete) CPU
  58. #define D3DCPU_WLMT 0x000000040L
  59. #define DEFAULT_GAMMA DTOVAL(1.4)
  60. /*
  61. INDEX_BATCH_SCALE is the constant which is used by DrawIndexedPrim
  62. to deterimine if the number of primitives being drawn is small
  63. relative to the number of vertices being passed. If it is then
  64. the prims are dereferenced in batches and sent to DrawPrim.
  65. */
  66. #define INDEX_BATCH_SCALE 2
  67. #endif // BUILD_DDDDK
  68. #if !defined(BUILD_DDDDK)
  69. class CD3DHal;
  70. class CStateSets;
  71. class CVertexVM;
  72. class CBaseTexture;
  73. class CD3DDDI;
  74. typedef CD3DDDI* LPD3DDDI;
  75. typedef class CD3DHal *LPD3DHAL;
  76. typedef class DIRECT3DLIGHTI *LPDIRECT3DLIGHTI;
  77. BOOL ValidatePixelShaderInternal( const DWORD* pCode, const D3DCAPS8* pCaps );
  78. BOOL ValidateVertexShaderInternal( const DWORD* pCode, const DWORD* pDecl,
  79. const D3DCAPS8* pCaps );
  80. #include "d3dhalp.h"
  81. //-----------------------------------------------------------------------------
  82. // Helper class to hold vertex element pointers and strides
  83. //
  84. class CVertexPointer
  85. {
  86. public:
  87. BYTE* pData[__NUMELEMENTS];
  88. static UINT Stride[__NUMELEMENTS];
  89. static UINT NumUsedElements;
  90. static UINT DataType[__NUMELEMENTS];
  91. CVertexPointer() {}
  92. // Copy constructor
  93. CVertexPointer(CVertexPointer& vp)
  94. {
  95. for (UINT i=0; i < NumUsedElements; i++)
  96. {
  97. pData[i] = vp.pData[i];
  98. }
  99. }
  100. // Copy constructor
  101. void operator=(CVertexPointer& vp)
  102. {
  103. for (UINT i=0; i < NumUsedElements; i++)
  104. {
  105. pData[i] = vp.pData[i];
  106. }
  107. }
  108. void SetVertex(CVertexPointer& base, UINT index)
  109. {
  110. for (UINT i=0; i < NumUsedElements; i++)
  111. pData[i] = base.pData[i] + index * Stride[i];
  112. }
  113. CVertexPointer& operator++(int)
  114. {
  115. for (UINT i=0; i < NumUsedElements; i++)
  116. pData[i] += Stride[i];
  117. return *this;
  118. }
  119. };
  120. //-----------------------------------------------------------------------------
  121. // Class to convert NPatches to RTPatches
  122. //
  123. class CNPatch2TriPatch
  124. {
  125. public:
  126. CNPatch2TriPatch();
  127. ~CNPatch2TriPatch();
  128. void MakeRectPatch(const CVertexPointer& pV0,
  129. const CVertexPointer& pV1,
  130. const CVertexPointer& pV2);
  131. CVStream m_InpStream[__NUMELEMENTS]; // Original vertex streams
  132. CTLStream* m_pOutStream[__NUMELEMENTS]; // Computed output vertex streams
  133. BYTE* m_pInpStreamMem[__NUMELEMENTS]; // Input stream memory
  134. BYTE* m_pOutStreamMem[__NUMELEMENTS]; // Output stream memory
  135. CVertexPointer m_InpVertex; // Pointers to elements of the first input vertex
  136. CVertexPointer m_OutVertex; // Pointers to elements of the first output vertex
  137. UINT m_PositionIndex; // Index in vertex element array
  138. UINT m_NormalIndex; // Index in vertex element array
  139. D3DORDERTYPE m_PositionOrder;
  140. D3DORDERTYPE m_NormalOrder;
  141. UINT m_FirstVertex; // Index of the first vertex in the
  142. // output buffer
  143. DWORD m_bNormalizeNormals;
  144. };
  145. //-----------------------------------------------------------------------------
  146. // Function to compute lighting
  147. //
  148. typedef struct _LIGHT_VERTEX_FUNC_TABLE
  149. {
  150. LIGHT_VERTEX_FUNC pfnDirectional;
  151. LIGHT_VERTEX_FUNC pfnPointSpot;
  152. // Used in multi-loop pipeline
  153. PFN_LIGHTLOOP pfnDirectionalFirst;
  154. PFN_LIGHTLOOP pfnDirectionalNext;
  155. PFN_LIGHTLOOP pfnPointSpotFirst;
  156. PFN_LIGHTLOOP pfnPointSpotNext;
  157. } LIGHT_VERTEX_FUNC_TABLE;
  158. //---------------------------------------------------------------------
  159. class DIRECT3DLIGHTI : public CD3DBaseObj
  160. {
  161. public:
  162. DIRECT3DLIGHTI() {m_LightI.flags = 0;} // VALID bit is not set
  163. HRESULT SetInternalData();
  164. BOOL Enabled() {return (m_LightI.flags & D3DLIGHTI_ENABLED);}
  165. // TRUE is we need to send the light to the driver when switching
  166. // to the hardware vertex processing mode
  167. BOOL DirtyForDDI() {return (m_LightI.flags & D3DLIGHTI_UPDATEDDI);}
  168. void SetDirtyForDDI() {m_LightI.flags |= D3DLIGHTI_UPDATEDDI;}
  169. void ClearDirtyForDDI() {m_LightI.flags &= ~D3DLIGHTI_UPDATEDDI;}
  170. // TRUE is we need to send the "enable" state of the light to the driver
  171. // when switching to the hardware vertex processing mode
  172. BOOL EnableDirtyForDDI() {return (m_LightI.flags & D3DLIGHTI_UPDATE_ENABLE_DDI);}
  173. void SetEnableDirtyForDDI() {m_LightI.flags |= D3DLIGHTI_UPDATE_ENABLE_DDI;}
  174. void ClearEnableDirtyForDDI() {m_LightI.flags &= ~D3DLIGHTI_UPDATE_ENABLE_DDI;}
  175. LIST_MEMBER(DIRECT3DLIGHTI) m_List; // Active light list member
  176. D3DLIGHT8 m_Light;
  177. D3DI_LIGHT m_LightI;
  178. };
  179. //---------------------------------------------------------------------
  180. struct CPalette : public CD3DBaseObj
  181. {
  182. CPalette()
  183. {
  184. m_dirty = TRUE;
  185. }
  186. BOOL m_dirty;
  187. PALETTEENTRY m_pEntries[256];
  188. };
  189. #if DBG
  190. //---------------------------------------------------------------------
  191. struct CRTPatchValidationInfo : public CD3DBaseObj
  192. {
  193. CRTPatchValidationInfo()
  194. {
  195. m_ShaderHandle = __INVALIDHANDLE;
  196. }
  197. DWORD m_ShaderHandle;
  198. };
  199. #endif // DBG
  200. //---------------------------------------------------------------------
  201. //
  202. // Bits for Runtime state flags (m_dwRuntimeFlags in CD3DBase)
  203. //
  204. // This bit set if UpdateManagedTextures() needs to be called
  205. const DWORD D3DRT_NEED_TEXTURE_UPDATE = 1 << 1;
  206. // We are in recording state set mode
  207. const DWORD D3DRT_RECORDSTATEMODE = 1 << 2;
  208. // We are in execution state set mode
  209. // In this mode the front-and executes recorded states but does not pass
  210. // them to the driver (the states will be passed using a set state handle)
  211. const DWORD D3DRT_EXECUTESTATEMODE = 1 << 3;
  212. //
  213. const DWORD D3DRT_LOSTSURFACES = 1 << 4;
  214. // Set when D3DRS_SOFTWAREVERTEXPROCESSING is TRUE
  215. const DWORD D3DRT_RSSOFTWAREPROCESSING = 1 << 5;
  216. // Set when device does not support point sprites
  217. const DWORD D3DRT_DOPOINTSPRITEEMULATION = 1 << 6;
  218. // Set when input stream has point size. It is computed in the SetVertexShaderI
  219. const DWORD D3DRT_POINTSIZEINVERTEX = 1 << 7;
  220. // Set when D3DRS_POINTSIZE != 1.0
  221. const DWORD D3DRT_POINTSIZEINRS = 1 << 8;
  222. // Set when
  223. // - shader has been changed.
  224. // - when ForceFVFRecompute has been called
  225. const DWORD D3DRT_SHADERDIRTY = 1 << 9;
  226. // This bit set if UpdateDirtyStreams() needs to be called
  227. const DWORD D3DRT_NEED_VB_UPDATE = 1 << 11;
  228. // This bit set if we need to update vertex shader constants in the driver
  229. const DWORD D3DRT_NEED_VSCONST_UPDATE = 1 << 12;
  230. // Set if device can handle only 2 floats per texture coord set
  231. const DWORD D3DRT_ONLY2FLOATSPERTEXTURE = 1 << 13;
  232. // Set if device cannot handle projected textures, so we need to emulate them
  233. const DWORD D3DRT_EMULATEPROJECTEDTEXTURE = 1 << 14;
  234. // Set if a directional light is present in the active light list
  235. const DWORD D3DRT_DIRECTIONALIGHTPRESENT = 1 << 15;
  236. // Set if a point/spot light is present in the active light list
  237. const DWORD D3DRT_POINTLIGHTPRESENT = 1 << 16;
  238. // Set if current primitive is user memory primitive
  239. const DWORD D3DRT_USERMEMPRIMITIVE = 1 << 17;
  240. // Set if reg key to disallow Non-Versioned (FF.FF) pixel shaders was set on device create
  241. const DWORD D3DRT_DISALLOWNVPSHADERS = 1 << 18;
  242. // Set when MaxPointSize in the device is greater than 1.0
  243. const DWORD D3DRT_SUPPORTSPOINTSPRITES = 1 << 19;
  244. // Set when we need to do NPatch to RTPatch conversion
  245. const DWORD D3DRT_DONPATCHCONVERSION = 1 << 20;
  246. const DWORD D3DRT_POINTSIZEPRESENT = D3DRT_POINTSIZEINRS |
  247. D3DRT_POINTSIZEINVERTEX;
  248. //---------------------------------------------------------------------
  249. //
  250. // Bits for D3DFRONTEND flags (dwFEFlags in CD3DHal)
  251. //
  252. const DWORD D3DFE_WORLDMATRIX_DIRTY = 1 << 0; // World matrix dirty bits
  253. const DWORD D3DFE_TLVERTEX = 1 << 5;
  254. const DWORD D3DFE_PROJMATRIX_DIRTY = 1 << 8;
  255. const DWORD D3DFE_VIEWMATRIX_DIRTY = 1 << 9;
  256. // Set when we need to check world-view matrix for orthogonality
  257. const DWORD D3DFE_NEEDCHECKWORLDVIEWVMATRIX = 1 << 10;
  258. // Set when some state has been changed and we have to go through the slow path
  259. // to update state.
  260. // Currently the bit is set when one of the following bits is set:
  261. // D3DFE_PROJMATRIX_DIRTY
  262. // D3DFE_VIEWMATRIX_DIRTY
  263. // D3DFE_WORLDMATRIX_DIRTY
  264. // D3DFE_VERTEXBLEND_DIRTY
  265. // D3DFE_LIGHTS_DIRTY
  266. // D3DFE_MATERIAL_DIRTY
  267. // D3DFE_FVF_DIRTY
  268. // D3DFE_CLIPPLANES_DIRTY
  269. // OutputFVF has been changed
  270. //
  271. const DWORD D3DFE_FRONTEND_DIRTY = 1 << 11;
  272. const DWORD D3DFE_NEED_TRANSFORM_LIGHTS = 1 << 14;
  273. const DWORD D3DFE_MATERIAL_DIRTY = 1 << 15;
  274. const DWORD D3DFE_CLIPPLANES_DIRTY = 1 << 16;
  275. const DWORD D3DFE_LIGHTS_DIRTY = 1 << 18;
  276. // This bit is set when vertex blending state is dirty
  277. const DWORD D3DFE_VERTEXBLEND_DIRTY = 1 << 19;
  278. // Set if the Current Transformation Matrix has been changed
  279. // Reset when frustum planes in the model space have been computed
  280. const DWORD D3DFE_FRUSTUMPLANES_DIRTY = 1 << 20;
  281. const DWORD D3DFE_WORLDVIEWMATRIX_DIRTY = 1 << 21;
  282. const DWORD D3DFE_FVF_DIRTY = 1 << 22;
  283. // This bit set if mapping DX6 texture blend modes to renderstates is desired
  284. const DWORD D3DFE_MAP_TSS_TO_RS = 1 << 24;
  285. const DWORD D3DFE_INVWORLDVIEWMATRIX_DIRTY = 1 << 25;
  286. // This bit set if texturing is disabled
  287. const DWORD D3DFE_DISABLE_TEXTURES = 1 << 28;
  288. // Clip matrix is used to transform user clipping planes
  289. // to the clipping space
  290. const DWORD D3DFE_CLIPMATRIX_DIRTY = 1 << 29;
  291. // HAL supports Transformation and Lighting
  292. const DWORD D3DFE_TLHAL = 1 << 30;
  293. const DWORD D3DFE_TRANSFORM_DIRTY = D3DFE_PROJMATRIX_DIRTY |
  294. D3DFE_VIEWMATRIX_DIRTY |
  295. D3DFE_WORLDMATRIX_DIRTY |
  296. D3DFE_VERTEXBLEND_DIRTY;
  297. // Are we in a scene?
  298. const DWORD D3DDEVBOOL_HINTFLAGS_INSCENE = 1 << 0;
  299. // Means the FPU is already in preferred state.
  300. const DWORD D3DDEVBOOL_HINTFLAGS_FPUSETUP = 1 << 3;
  301. //---------------------------------------------------------------------
  302. // Bits for transform.dwFlags
  303. //
  304. //---------------------------------------------------------------------
  305. typedef struct _D3DFE_TRANSFORM
  306. {
  307. D3DMATRIXI proj;
  308. D3DMATRIXI mPC; // Mproj * Mclip
  309. D3DMATRIXI mVPCI; // Inverse Mview * PC, used to transform clipping planes
  310. D3DVECTORH userClipPlane[D3DMAXUSERCLIPPLANES];
  311. } D3DFE_TRANSFORM;
  312. typedef void (*D3DFEDestroyProc)(LPD3DHAL lpD3DDevI);
  313. //---------------------------------------------------------------------
  314. #ifdef _IA64_ // Removes IA64 compiler alignment warnings
  315. #pragma pack(16)
  316. #endif
  317. #ifdef _AXP64_ // Removes AXP64 compiler alignment warnings
  318. #pragma pack(16)
  319. #endif
  320. // We modify the compiler generated VTable for CD3DHal object. To make
  321. // life easy, all virtual functions are defined in CD3DHal. Also since
  322. // DEVICEI has multiple inheritance, there are more than 1 VTable.
  323. // Currently we assume that it only inherits from IDirect3DDevice7 and
  324. // D3DFE_PROCESSVERTICES and, in that order! Thus IDirect3DDevice7 and
  325. // CD3DHal share the same vtable. This is the VTable we copy and
  326. // modify. The define below is the total entries in this vtable. It is the
  327. // sum of the methods in IDirect3DDevice7 (incl. IUnknown) (49) and all the
  328. // virtual methods in CD3DHal ()
  329. #define D3D_NUM_API_FUNCTIONS (49)
  330. #define D3D_NUM_VIRTUAL_FUNCTIONS (D3D_NUM_API_FUNCTIONS+38)
  331. // These constants are based on the assumption that rsVec array is an array
  332. // of 32-bit intergers
  333. const D3D_RSVEC_SHIFT = 5; // log2(sizeof(DWORD)*8);
  334. const D3D_RSVEC_MASK = sizeof(DWORD) * 8 - 1;
  335. //-----------------------------------------------------------------------------
  336. // The class is used to maintain a packed array of bits
  337. //
  338. class CPackedBitArray
  339. {
  340. public:
  341. CPackedBitArray() {m_pArray = NULL;}
  342. ~CPackedBitArray() {delete m_pArray;}
  343. // This function could be called to re-allocate the array. All data from the
  344. // previous array is copied into new array
  345. HRESULT Init(UINT size)
  346. {
  347. // Size in bytes
  348. UINT allocsize = ((size + D3D_RSVEC_MASK) >> D3D_RSVEC_SHIFT) << 2;
  349. DWORD* pNew = (DWORD*)new BYTE[allocsize];
  350. if (pNew == NULL)
  351. return E_OUTOFMEMORY;
  352. memset(pNew, 0, allocsize);
  353. if (m_pArray)
  354. {
  355. // User asks to re-allocate the array
  356. memcpy(pNew, m_pArray, m_sizeInBytes);
  357. delete m_pArray;
  358. }
  359. m_pArray = pNew;
  360. m_size = size;
  361. m_sizeInBytes = allocsize;
  362. return S_OK;
  363. }
  364. UINT GetSize() {return m_size;}
  365. void ClearBit(DWORD index)
  366. {
  367. #if DBG
  368. CheckIndex(index);
  369. #endif
  370. m_pArray[index >> D3D_RSVEC_SHIFT] &= ~(1 << (index & D3D_RSVEC_MASK));
  371. }
  372. void SetBit(DWORD index)
  373. {
  374. #if DBG
  375. CheckIndex(index);
  376. #endif
  377. m_pArray[index >> D3D_RSVEC_SHIFT] |= 1 << (index & D3D_RSVEC_MASK);
  378. }
  379. BOOL IsBitSet(DWORD index)
  380. {
  381. #if DBG
  382. CheckIndex(index);
  383. #endif
  384. return (m_pArray[index >> D3D_RSVEC_SHIFT] &
  385. (1ul << (index & D3D_RSVEC_MASK))) != 0;
  386. }
  387. private:
  388. DWORD* m_pArray;
  389. UINT m_sizeInBytes;
  390. UINT m_size; // Number of elements (bits) in the array
  391. #if DBG
  392. void CheckIndex(UINT index);
  393. #endif // DBG
  394. };
  395. //-----------------------------------------------------------------------------
  396. // Map DX8 texture filter enum to D3DTEXTUREMAGFILTER
  397. const texf2texfg[] = {
  398. D3DTFG_POINT, // D3DTEXF_NONE = 0,
  399. D3DTFG_POINT, // D3DTEXF_POINT = 1,
  400. D3DTFG_LINEAR, // D3DTEXF_LINEAR = 2,
  401. D3DTFG_ANISOTROPIC, // D3DTEXF_ANISOTROPIC = 3,
  402. D3DTFG_FLATCUBIC, // D3DTEXF_FLATCUBIC = 4,
  403. D3DTFG_GAUSSIANCUBIC, // D3DTEXF_GAUSSIANCUBIC = 5,
  404. };
  405. // Map DX8 texture filter enum to D3DTEXTUREMINFILTER
  406. const texf2texfn[] = {
  407. D3DTFN_POINT, // D3DTEXF_NONE = 0,
  408. D3DTFN_POINT, // D3DTEXF_POINT = 1,
  409. D3DTFN_LINEAR, // D3DTEXF_LINEAR = 2,
  410. D3DTFN_ANISOTROPIC, // D3DTEXF_ANISOTROPIC = 3,
  411. D3DTFN_LINEAR, // D3DTEXF_FLATCUBIC = 4,
  412. D3DTFN_LINEAR, // D3DTEXF_GAUSSIANCUBIC = 5,
  413. };
  414. // Map DX8 texture filter enum to D3DTEXTUREMIPFILTER
  415. const texf2texfp[] = {
  416. D3DTFP_NONE, // D3DTEXF_NONE = 0,
  417. D3DTFP_POINT, // D3DTEXF_POINT = 1,
  418. D3DTFP_LINEAR, // D3DTEXF_LINEAR = 2,
  419. D3DTFP_LINEAR, // D3DTEXF_ANISOTROPIC = 3,
  420. D3DTFP_LINEAR, // D3DTEXF_FLATCUBIC = 4,
  421. D3DTFP_LINEAR, // D3DTEXF_GAUSSIANCUBIC = 5,
  422. };
  423. /////////////////////////////////////////////////////////////////////////////
  424. // //
  425. // CD3DBase //
  426. // //
  427. /////////////////////////////////////////////////////////////////////////////
  428. class CD3DBase : public CBaseDevice
  429. {
  430. public:
  431. // IDirect3DDevice8 Methods
  432. HRESULT D3DAPI ResourceManagerDiscardBytes(DWORD cbBytes); // 5
  433. HRESULT D3DAPI SetRenderTarget(IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pZStencil); // 31
  434. HRESULT D3DAPI GetRenderTarget(IDirect3DSurface8 **ppRenderTarget); // 32
  435. HRESULT D3DAPI GetDepthStencilSurface(IDirect3DSurface8 **ppZStencil); // 33
  436. HRESULT D3DAPI BeginScene(); // 34
  437. HRESULT D3DAPI EndScene(); // 35
  438. HRESULT D3DAPI Clear( DWORD dwCount, CONST D3DRECT* rects, DWORD dwFlags,
  439. D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil); // 36
  440. HRESULT D3DAPI SetTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 37
  441. HRESULT D3DAPI GetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX); // 38
  442. HRESULT D3DAPI MultiplyTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 39
  443. HRESULT D3DAPI SetViewport(CONST D3DVIEWPORT8*); // 40
  444. HRESULT D3DAPI GetViewport(D3DVIEWPORT8*); // 41
  445. HRESULT D3DAPI SetMaterial(CONST D3DMATERIAL8*); // 42
  446. HRESULT D3DAPI GetMaterial(D3DMATERIAL8*); // 43
  447. HRESULT D3DAPI SetLight(DWORD, CONST D3DLIGHT8*); // 44
  448. HRESULT D3DAPI GetLight(DWORD, D3DLIGHT8*); // 45
  449. HRESULT D3DAPI LightEnable(DWORD dwLightIndex, BOOL); // 46
  450. HRESULT D3DAPI GetLightEnable(DWORD dwLightIndex, BOOL*); // 47
  451. HRESULT D3DAPI SetClipPlane(DWORD dwPlaneIndex, CONST D3DVALUE* pPlaneEquation); // 48
  452. HRESULT D3DAPI GetClipPlane(DWORD dwPlaneIndex, D3DVALUE* pPlaneEquation); // 49
  453. HRESULT D3DAPI SetRenderState(D3DRENDERSTATETYPE, DWORD); // 50
  454. HRESULT D3DAPI GetRenderState(D3DRENDERSTATETYPE, LPDWORD); // 51
  455. HRESULT D3DAPI BeginStateBlock(); // 52
  456. HRESULT D3DAPI EndStateBlock(LPDWORD); // 53
  457. HRESULT D3DAPI ApplyStateBlock(DWORD); // 54
  458. HRESULT D3DAPI CaptureStateBlock(DWORD Handle); // 55
  459. HRESULT D3DAPI DeleteStateBlock(DWORD); // 56
  460. HRESULT D3DAPI CreateStateBlock(D3DSTATEBLOCKTYPE sbt, LPDWORD pdwHandle); // 57
  461. HRESULT D3DAPI SetClipStatus(CONST D3DCLIPSTATUS8*); // 58
  462. HRESULT D3DAPI GetClipStatus(D3DCLIPSTATUS8*); // 59
  463. HRESULT D3DAPI GetTexture(DWORD, IDirect3DBaseTexture8**); // 60
  464. HRESULT D3DAPI SetTexture(DWORD, IDirect3DBaseTexture8*); // 61
  465. HRESULT D3DAPI GetTextureStageState(DWORD, D3DTEXTURESTAGESTATETYPE, LPDWORD); // 62
  466. HRESULT D3DAPI SetTextureStageState(DWORD dwStage,
  467. D3DTEXTURESTAGESTATETYPE dwState,
  468. DWORD dwValue); // 63
  469. HRESULT D3DAPI ValidateDevice(LPDWORD lpdwNumPasses); // 64
  470. HRESULT D3DAPI GetInfo(DWORD dwDevInfoID, LPVOID pDevInfoStruct,
  471. DWORD dwSize); // 65
  472. HRESULT D3DAPI SetPaletteEntries(UINT PaletteNumber, CONST PALETTEENTRY *pEntries); // 66
  473. HRESULT D3DAPI GetPaletteEntries(UINT PaletteNumber, PALETTEENTRY *pEntries); // 67
  474. HRESULT D3DAPI SetCurrentTexturePalette(UINT PaletteNumber); // 68
  475. HRESULT D3DAPI GetCurrentTexturePalette(UINT *PaletteNumber); // 69
  476. HRESULT D3DAPI DrawPrimitive(D3DPRIMITIVETYPE PrimType,
  477. UINT StartVertex, UINT VertexCount); // 70
  478. HRESULT D3DAPI DrawIndexedPrimitive(D3DPRIMITIVETYPE, UINT minIndex,
  479. UINT maxIndex, UINT startIndex,
  480. UINT count); // 71
  481. HRESULT D3DAPI DrawPrimitiveUP(
  482. D3DPRIMITIVETYPE PrimitiveType,
  483. UINT PrimitiveCount,
  484. CONST VOID *pVertexStreamZeroData,
  485. UINT VertexStreamZeroStride); // 72
  486. HRESULT D3DAPI DrawIndexedPrimitiveUP(
  487. D3DPRIMITIVETYPE PrimitiveType,
  488. UINT MinVertexIndex, UINT NumVertexIndices,
  489. UINT PrimitiveCount,
  490. CONST VOID *pIndexData, D3DFORMAT IndexDataFormat,
  491. CONST VOID *pVertexStreamZeroData, UINT VertexStreamZeroStride); // 73
  492. HRESULT D3DAPI ProcessVertices(UINT SrcStartIndex, UINT DestIndex,
  493. UINT VertexCount,
  494. IDirect3DVertexBuffer8 *pDestBuffer,
  495. DWORD Flags); // 74
  496. HRESULT D3DAPI CreateVertexShader(CONST DWORD* pdwDeclaration,
  497. CONST DWORD* pdwFunction,
  498. DWORD* pdwHandle, DWORD dwUsage); // 75
  499. HRESULT D3DAPI SetVertexShader(DWORD dwHandle); // 76
  500. HRESULT D3DAPI GetVertexShader(LPDWORD pdwHandle); // 77
  501. HRESULT D3DAPI DeleteVertexShader(DWORD dwHandle); // 78
  502. HRESULT D3DAPI SetVertexShaderConstant(DWORD dwRegisterAddress,
  503. CONST VOID* lpvConstantData,
  504. DWORD dwConstantCount); // 79
  505. HRESULT D3DAPI GetVertexShaderConstant(DWORD dwRegisterAddress,
  506. LPVOID lpvConstantData,
  507. DWORD dwConstantCount); // 80
  508. HRESULT D3DAPI GetVertexShaderDeclaration(DWORD dwHandle, void *pData,
  509. DWORD *pSizeOfData); // 81
  510. HRESULT D3DAPI GetVertexShaderFunction(DWORD dwHandle, void *pData,
  511. DWORD *pSizeOfData); // 82
  512. HRESULT D3DAPI SetStreamSource(UINT StreamNumber,
  513. IDirect3DVertexBuffer8 *pStreamData,
  514. UINT Stride); // 83
  515. HRESULT D3DAPI GetStreamSource(UINT StreamNumber,
  516. IDirect3DVertexBuffer8 **ppStreamData,
  517. UINT* pStride); // 84
  518. HRESULT D3DAPI SetIndices(IDirect3DIndexBuffer8 *pIndexData,
  519. UINT BaseVertexIndex); // 85
  520. HRESULT D3DAPI GetIndices(IDirect3DIndexBuffer8 **ppIndexData,
  521. UINT* pBaseVertexIndex); // 86
  522. HRESULT D3DAPI CreatePixelShader(CONST DWORD* pdwFunction,
  523. LPDWORD pdwHandle); // 87
  524. HRESULT D3DAPI SetPixelShader(DWORD dwHandle); // 88
  525. HRESULT D3DAPI GetPixelShader(LPDWORD pdwHandle); // 89
  526. HRESULT D3DAPI DeletePixelShader(DWORD dwHandle); // 90
  527. HRESULT D3DAPI SetPixelShaderConstant(DWORD dwRegisterAddress,
  528. CONST VOID* lpvConstantData,
  529. DWORD dwConstantCount); // 91
  530. HRESULT D3DAPI GetPixelShaderConstant(DWORD dwRegisterAddress,
  531. LPVOID lpvConstantData,
  532. DWORD dwConstantCount); // 92
  533. HRESULT D3DAPI GetPixelShaderFunction(DWORD dwHandle, void *pData,
  534. DWORD *pSizeOfData); // 93
  535. HRESULT D3DAPI DrawRectPatch(UINT Handle, CONST FLOAT *pNumSegs,
  536. CONST D3DRECTPATCH_INFO *pSurf); // 94
  537. HRESULT D3DAPI DrawTriPatch(UINT Handle, CONST FLOAT *pNumSegs,
  538. CONST D3DTRIPATCH_INFO *pSurf); // 95
  539. HRESULT D3DAPI DeletePatch(UINT Handle); // 96
  540. public:
  541. // Flags to indicate runtime state
  542. DWORD m_dwRuntimeFlags;
  543. // D3DDEVBOOL flags
  544. DWORD m_dwHintFlags;
  545. // This should only be accessed through
  546. // CurrentBatch and IncrementBatchCount
  547. ULONGLONG m_qwBatch;
  548. // The object encapsulating the DDI styles
  549. // At the minimum this is a DX6 driver.
  550. LPD3DDDIDX6 m_pDDI;
  551. // Pointer to texture objects for currently installed textures.
  552. // NULL indicates that the texture is either not set (rstate NULL) or that
  553. // the handle to tex3 pointer mapping is not done. This mapping is
  554. // expensive, so it is deferred until needed. This is needed for finding
  555. // the WRAPU,V mode for texture index clipping (since the WRAPU,V state is
  556. // part of the device).
  557. CBaseTexture* m_lpD3DMappedTexI[D3DHAL_TSS_MAXSTAGES];
  558. DWORD m_dwDDITexHandle[D3DHAL_TSS_MAXSTAGES];
  559. // Max number of blend stages supported by a driver
  560. DWORD m_dwMaxTextureBlendStages;
  561. DWORD m_dwStageDirty, m_dwStreamDirty;
  562. // Object to record state sets
  563. CStateSets* m_pStateSets;
  564. //
  565. // The following is for validation only
  566. //
  567. // Max TSS that can be passed to the driver
  568. D3DTEXTURESTAGESTATETYPE m_tssMax;
  569. // Max RS that can be passed to the driver, used for CanHandleRenderState
  570. D3DRENDERSTATETYPE m_rsMax;
  571. #if defined(PROFILE4) || defined(PROFILE)
  572. DWORD m_dwProfStart, m_dwProfStop;
  573. #endif
  574. // This bit array is used to tell if a light has been created or not
  575. CPackedBitArray* m_pCreatedLights;
  576. // DX8 related stuff from here -------------------------------------
  577. // The current shader handle. It is initialized to Zero.
  578. // Zero means that there is no current shader. User always has to
  579. // initialize the shader.
  580. // It is used only by non-pure device
  581. DWORD m_dwCurrentShaderHandle;
  582. // The current pixel shader handle. It is initialized to zero, and
  583. // is set to zero for legacy pixel processing
  584. // It is used only by non-pure device
  585. DWORD m_dwCurrentPixelShaderHandle;
  586. // This object gives us pixel shader handles
  587. CHandleFactory* m_pPShaderArray;
  588. // This object gives us vertex shader handles
  589. CVShaderHandleFactory* m_pVShaderArray;
  590. // Vertex sctreams
  591. CVStream* m_pStream;
  592. // Index stream
  593. CVIndexStream* m_pIndexStream;
  594. // Max number of streams allowed. For D3D software it is __NUMSTREAMS
  595. // For hardware T&L it could be smaller
  596. DWORD m_dwNumStreams;
  597. // Max number of user clipping streams supported
  598. DWORD m_dwMaxUserClipPlanes;
  599. // Currently set palette
  600. DWORD m_dwPalette;
  601. // Palette array
  602. CHandleArray *m_pPaletteArray;
  603. #if DBG
  604. // Needed for RT-Patch validation
  605. CHandleArray *m_pRTPatchValidationInfo;
  606. // Needed for VB warnings
  607. DWORD m_SceneStamp;
  608. #endif // DBG
  609. // Function pointers for DrawPrimitive processing
  610. PFN_DRAWPRIMFAST m_pfnDrawPrim;
  611. PFN_DRAWINDEXEDPRIMFAST m_pfnDrawIndexedPrim;
  612. // Function pointers for DrawPrimitive processing from NPatch
  613. // conversion function in case of point or line primitives
  614. PFN_DRAWPRIMFAST m_pfnDrawPrimFromNPatch;
  615. PFN_DRAWINDEXEDPRIMFAST m_pfnDrawIndexedPrimFromNPatch;
  616. // Number of constant register. This could be different for software and
  617. // hardware vertex processing
  618. UINT m_MaxVertexShaderConst;
  619. #ifdef FAST_PATH
  620. #define NUMVTBLENTRIES 135
  621. VOID **m_pOrigVtbl;
  622. VOID *m_pVtbl[NUMVTBLENTRIES];
  623. void FastPathSetRenderStateExecute()
  624. {
  625. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  626. {
  627. m_pVtbl[50] = m_pVtbl[98];
  628. }
  629. else
  630. {
  631. DXGASSERT(m_pVtbl[50] == m_pOrigVtbl[50]);
  632. }
  633. }
  634. void FastPathSetRenderStateRecord()
  635. {
  636. m_pVtbl[50] = m_pOrigVtbl[50];
  637. }
  638. void FastPathSetTextureStageStateExecute()
  639. {
  640. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  641. {
  642. m_pVtbl[63] = m_pVtbl[99];
  643. }
  644. else
  645. {
  646. DXGASSERT(m_pVtbl[63] == m_pOrigVtbl[63]);
  647. }
  648. }
  649. void FastPathSetTextureStageStateRecord()
  650. {
  651. m_pVtbl[63] = m_pOrigVtbl[63];
  652. }
  653. void FastPathSetTextureExecute()
  654. {
  655. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  656. {
  657. m_pVtbl[61] = m_pVtbl[100];
  658. }
  659. else
  660. {
  661. DXGASSERT(m_pVtbl[61] == m_pOrigVtbl[61]);
  662. }
  663. }
  664. void FastPathSetTextureRecord()
  665. {
  666. m_pVtbl[61] = m_pOrigVtbl[61];
  667. }
  668. void FastPathApplyStateBlockExecute()
  669. {
  670. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  671. {
  672. m_pVtbl[54] = m_pVtbl[101];
  673. }
  674. else
  675. {
  676. DXGASSERT(m_pVtbl[54] == m_pOrigVtbl[54]);
  677. }
  678. }
  679. void FastPathApplyStateBlockRecord()
  680. {
  681. m_pVtbl[54] = m_pOrigVtbl[54];
  682. }
  683. void FastPathSetVertexShaderFast()
  684. {
  685. if((m_dwRuntimeFlags & (D3DRT_RECORDSTATEMODE | D3DRT_RSSOFTWAREPROCESSING)) == 0 &&
  686. (BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  687. {
  688. m_pVtbl[76] = m_pVtbl[102];
  689. }
  690. else
  691. {
  692. DXGASSERT(m_pVtbl[76] == m_pOrigVtbl[76]);
  693. }
  694. }
  695. void FastPathSetVertexShaderSlow()
  696. {
  697. m_pVtbl[76] = m_pOrigVtbl[76];
  698. }
  699. void FastPathSetStreamSourceFast()
  700. {
  701. if((m_dwRuntimeFlags & (D3DRT_RECORDSTATEMODE | D3DRT_RSSOFTWAREPROCESSING)) == 0 &&
  702. (BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  703. {
  704. m_pVtbl[83] = m_pVtbl[103];
  705. }
  706. else
  707. {
  708. DXGASSERT(m_pVtbl[83] == m_pOrigVtbl[83]);
  709. }
  710. }
  711. void FastPathSetStreamSourceSlow()
  712. {
  713. m_pVtbl[83] = m_pOrigVtbl[83];
  714. }
  715. void FastPathSetIndicesFast()
  716. {
  717. if((m_dwRuntimeFlags & (D3DRT_RECORDSTATEMODE | D3DRT_RSSOFTWAREPROCESSING)) == 0 &&
  718. (BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  719. {
  720. m_pVtbl[85] = m_pVtbl[104];
  721. }
  722. else
  723. {
  724. DXGASSERT(m_pVtbl[85] == m_pOrigVtbl[85]);
  725. }
  726. }
  727. void FastPathSetIndicesSlow()
  728. {
  729. m_pVtbl[85] = m_pOrigVtbl[85];
  730. }
  731. void FastPathSetTransformExecute()
  732. {
  733. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0 &&
  734. (BehaviorFlags() & D3DCREATE_PUREDEVICE) != 0)
  735. {
  736. m_pVtbl[37] = m_pVtbl[105];
  737. }
  738. else
  739. {
  740. DXGASSERT(m_pVtbl[37] == m_pOrigVtbl[37]);
  741. }
  742. }
  743. void FastPathSetTransformRecord()
  744. {
  745. m_pVtbl[37] = m_pOrigVtbl[37];
  746. }
  747. void FastPathMultiplyTransformExecute()
  748. {
  749. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0 &&
  750. (BehaviorFlags() & D3DCREATE_PUREDEVICE) != 0)
  751. {
  752. m_pVtbl[39] = m_pVtbl[106];
  753. }
  754. else
  755. {
  756. DXGASSERT(m_pVtbl[39] == m_pOrigVtbl[39]);
  757. }
  758. }
  759. void FastPathMultiplyTransformRecord()
  760. {
  761. m_pVtbl[39] = m_pOrigVtbl[39];
  762. }
  763. void FastPathSetMaterialExecute()
  764. {
  765. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  766. {
  767. m_pVtbl[42] = m_pVtbl[107];
  768. }
  769. else
  770. {
  771. DXGASSERT(m_pVtbl[42] == m_pOrigVtbl[42]);
  772. }
  773. }
  774. void FastPathSetMaterialRecord()
  775. {
  776. m_pVtbl[42] = m_pOrigVtbl[42];
  777. }
  778. void FastPathSetPixelShaderExecute()
  779. {
  780. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  781. {
  782. m_pVtbl[88] = m_pVtbl[108];
  783. }
  784. else
  785. {
  786. DXGASSERT(m_pVtbl[88] == m_pOrigVtbl[88]);
  787. }
  788. }
  789. void FastPathSetPixelShaderRecord()
  790. {
  791. m_pVtbl[88] = m_pOrigVtbl[88];
  792. }
  793. void FastPathSetPixelShaderConstantExecute()
  794. {
  795. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0)
  796. {
  797. m_pVtbl[91] = m_pVtbl[109];
  798. }
  799. else
  800. {
  801. DXGASSERT(m_pVtbl[91] == m_pOrigVtbl[91]);
  802. }
  803. }
  804. void FastPathSetPixelShaderConstantRecord()
  805. {
  806. m_pVtbl[91] = m_pOrigVtbl[91];
  807. }
  808. void FastPathSetVertexShaderConstantExecute()
  809. {
  810. if((BehaviorFlags() & D3DCREATE_MULTITHREADED) == 0 &&
  811. (BehaviorFlags() & D3DCREATE_PUREDEVICE) != 0)
  812. {
  813. m_pVtbl[79] = m_pVtbl[110];
  814. }
  815. else
  816. {
  817. DXGASSERT(m_pVtbl[79] == m_pOrigVtbl[79]);
  818. }
  819. }
  820. void FastPathSetVertexShaderConstantRecord()
  821. {
  822. m_pVtbl[79] = m_pOrigVtbl[79];
  823. }
  824. #endif // FAST_PATH
  825. public:
  826. CD3DBase();
  827. virtual ~CD3DBase(); // 97
  828. virtual HRESULT D3DAPI SetRenderStateFast(D3DRENDERSTATETYPE dwState, DWORD value); // 98
  829. virtual HRESULT D3DAPI SetTextureStageStateFast(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue); // 99
  830. virtual HRESULT D3DAPI SetTextureFast(DWORD, IDirect3DBaseTexture8 *lpTex); // 100
  831. virtual HRESULT D3DAPI ApplyStateBlockFast(DWORD); // 101
  832. #ifdef FAST_PATH
  833. virtual HRESULT D3DAPI SetVertexShaderFast(DWORD); // 102
  834. virtual HRESULT D3DAPI SetStreamSourceFast(UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride); // 103
  835. virtual HRESULT D3DAPI SetIndicesFast(IDirect3DIndexBuffer8 *pIndexData, UINT BaseVertexIndex); // 104
  836. virtual HRESULT D3DAPI SetTransformFast(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 105
  837. virtual HRESULT D3DAPI MultiplyTransformFast(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 106
  838. #endif // FAST_PATH
  839. virtual HRESULT D3DAPI SetMaterialFast(CONST D3DMATERIAL8*); // 107
  840. virtual HRESULT D3DAPI SetPixelShaderFast(DWORD dwHandle); // 108
  841. virtual HRESULT D3DAPI SetPixelShaderConstantFast(DWORD dwRegisterAddress, // 109
  842. CONST VOID* lpvConstantData,
  843. DWORD dwConstantCount);
  844. virtual HRESULT D3DAPI SetVertexShaderConstantFast(DWORD dwRegisterAddress, // 110
  845. CONST VOID* lpvConstantData,
  846. DWORD dwConstantCount);
  847. virtual void Destroy(); // 111
  848. // Virtual methods for CBaseDevice
  849. virtual HRESULT InitDevice(); // 112
  850. virtual void StateInitialize(BOOL bZEnable); // 113
  851. virtual void UpdateRenderState(DWORD dwStateType, DWORD value) {} // 114
  852. virtual void SetTransformI(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 115
  853. virtual void MultiplyTransformI(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*); // 116
  854. virtual void SetClipPlaneI(DWORD dwPlaneIndex, // 117
  855. CONST D3DVALUE* pPlaneEquation);
  856. virtual void UpdateDriverStates(){ DDASSERT( FALSE ); } // 118
  857. virtual void SetViewportI(CONST D3DVIEWPORT8*); // 119
  858. virtual void SetStreamSourceI(CVStream*); // 120
  859. virtual void SetIndicesI(CVIndexStream*); // 121
  860. virtual void CreateVertexShaderI(CONST DWORD* pdwDeclaration, // 122
  861. DWORD dwDeclSize,
  862. CONST DWORD* pdwFunction,
  863. DWORD dwCodeSize,
  864. DWORD dwHandle);
  865. virtual void SetVertexShaderI(DWORD dwHandle); // 123
  866. virtual void DeleteVertexShaderI(DWORD dwHandle); // 124
  867. virtual void SetVertexShaderConstantI(DWORD dwRegisterAddress, // 125
  868. CONST VOID* lpvConstantData,
  869. DWORD dwConstantCount);
  870. virtual void DrawPointsI(D3DPRIMITIVETYPE PrimitiveType, // 126
  871. UINT StartVertex,
  872. UINT PrimitiveCount);
  873. virtual void SetLightI(DWORD dwLightIndex, CONST D3DLIGHT8*); // 127
  874. virtual void LightEnableI(DWORD dwLightIndex, BOOL); // 128
  875. virtual void SetRenderStateInternal(D3DRENDERSTATETYPE, DWORD); // 129
  876. virtual void DrawPrimitiveUPI(D3DPRIMITIVETYPE PrimitiveType, // 130
  877. UINT PrimitiveCount);
  878. virtual void DrawIndexedPrimitiveUPI(D3DPRIMITIVETYPE PrimitiveType, // 131
  879. UINT MinVertexIndex,
  880. UINT NumVertexIndices,
  881. UINT PrimitiveCount);
  882. virtual void GetPixelShaderConstantI(DWORD Register, DWORD count, // 132
  883. LPVOID pData );
  884. virtual void ClearI( DWORD dwCount, CONST D3DRECT* rects, DWORD dwFlags, // 133
  885. D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  886. // Picks the right DrawPrimitive and DrawIndexedPrimitive function to
  887. // execute
  888. // Call this function when
  889. // - vertex shader is changed
  890. // - stream source is changed
  891. // - D3DRS_CLIPPING is changed
  892. // - resource has been changed
  893. //
  894. // Base device implementation is empty, because the function pointers are
  895. // initialized in the constructor and do not change
  896. virtual void __declspec(nothrow) PickDrawPrimFn() {}; // 134
  897. protected:
  898. void ValidateDraw(D3DPRIMITIVETYPE primType, UINT StartVertex,
  899. UINT PrimitiveCount, UINT NumVertices,
  900. BOOL bIndexPrimitive, BOOL bUsedMemPrimitive);
  901. void CheckIndices(CONST BYTE* pIndices, UINT NumIndices, UINT StartIndex,
  902. UINT MinIndex, UINT NumVertices, UINT IndexStride);
  903. void CheckViewport(CONST D3DVIEWPORT8* lpData);
  904. void CheckVertexShaderHandle(DWORD dwHandle);
  905. void CheckPixelShaderHandle(DWORD dwHandle);
  906. inline void ClearVertexShaderHandle()
  907. {
  908. m_dwCurrentShaderHandle = 0;
  909. }
  910. public:
  911. // non virtual methods
  912. HRESULT __declspec(nothrow) Init();
  913. HRESULT VerifyTexture(DWORD dwStage, IDirect3DBaseTexture8 *lpTex);
  914. HRESULT CalcDDSurfInfo(BOOL bUpdateZBufferFields);
  915. // Re-creates hardware pixel and vertex shaders after device is reset
  916. HRESULT ResetShaders();
  917. void __declspec(nothrow) NeedResourceStateUpdate()
  918. {
  919. this->m_dwRuntimeFlags |= (D3DRT_NEED_TEXTURE_UPDATE | D3DRT_NEED_VB_UPDATE);
  920. // We shouldn't call PickDrawPrimFn when the device is being destroyed
  921. if (m_pDDI)
  922. PickDrawPrimFn();
  923. }
  924. HRESULT __declspec(nothrow) SetRenderTargetI(CBaseSurface* pTarget,
  925. CBaseSurface* pZ);
  926. // Checks if we can pass the render state to the driver
  927. BOOL CanHandleRenderState(D3DRENDERSTATETYPE type)
  928. {
  929. if (type >= m_rsMax)
  930. {
  931. // not an error condition because we don't send front-end stuff to
  932. // non-TL Hal devices, for example, but don't send to HAL anyway
  933. return FALSE;
  934. }
  935. return TRUE;
  936. };
  937. void UpdateTextures();
  938. void UpdatePalette(CBaseTexture *pTex, DWORD Palette, DWORD dwStage, BOOL bSavedWithinPrimitive);
  939. HRESULT __declspec(nothrow) TexBlt(CBaseTexture *lpDst,
  940. CBaseTexture* lpSrc,
  941. POINT *pPoint,
  942. RECTL *pRect);
  943. HRESULT __declspec(nothrow) CubeTexBlt(CBaseTexture *lpDstParent,
  944. CBaseTexture* lpSrcParent,
  945. DWORD dwDestFaceHandle,
  946. DWORD dwSrcFaceHandle,
  947. POINT *pPoint,
  948. RECTL *pRect);
  949. HRESULT __declspec(nothrow) VolBlt(CBaseTexture *lpDst, CBaseTexture* lpSrc, DWORD dwDestX,
  950. DWORD dwDestY, DWORD dwDestZ, D3DBOX *pBox);
  951. HRESULT __declspec(nothrow) BufBlt(CBuffer *lpDst, CBuffer* lpSrc, DWORD dwOffset,
  952. D3DRANGE* pRange);
  953. HRESULT __declspec(nothrow) SetPriority(CResource *pRes, DWORD dwPriority);
  954. HRESULT __declspec(nothrow) SetTexLOD(CBaseTexture *pTex, DWORD dwLOD);
  955. HRESULT __declspec(nothrow) AddDirtyRect(CBaseTexture *pTex, CONST RECTL *pRect);
  956. HRESULT __declspec(nothrow) AddCubeDirtyRect(CBaseTexture *pTex, DWORD dwFaceHandle, CONST RECTL *pRect);
  957. HRESULT __declspec(nothrow) AddDirtyBox(CBaseTexture *pTex, CONST D3DBOX *pBox);
  958. void __declspec(nothrow) CleanupTextures();
  959. void __declspec(nothrow) OnTextureDestroy(CBaseTexture*);
  960. ULONGLONG __declspec(nothrow) CurrentBatch()
  961. {
  962. DDASSERT(m_qwBatch > 0);
  963. return m_qwBatch;
  964. }
  965. void IncrementBatchCount();
  966. void __declspec(nothrow) Sync(ULONGLONG batch)
  967. {
  968. if (m_qwBatch <= batch)
  969. {
  970. FlushStatesNoThrow();
  971. }
  972. }
  973. HRESULT __declspec(nothrow) ValidateFVF(DWORD dwFVF);
  974. void __declspec(nothrow) FlushStatesNoThrow();
  975. #if DBG
  976. #define PROF_DRAWPRIMITIVEDEVICE2 0x0003
  977. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE2 0x0004
  978. #define PROF_DRAWPRIMITIVESTRIDED 0x0005
  979. #define PROF_DRAWINDEXEDPRIMITIVESTRIDED 0x0006
  980. #define PROF_DRAWPRIMITIVEDEVICE3 0x0007
  981. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE3 0x0008
  982. #define PROF_DRAWPRIMITIVEVB 0x0009
  983. #define PROF_DRAWINDEXEDPRIMITIVEVB 0x000a
  984. DWORD dwCaller;
  985. DWORD dwPrimitiveType[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  986. DWORD dwVertexType1[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  987. DWORD dwVertexType2[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  988. void Profile(DWORD, D3DPRIMITIVETYPE, DWORD);
  989. #else
  990. #define Profile(a,b,c)
  991. #endif
  992. friend class CD3DDDIDX6;
  993. };
  994. typedef CD3DBase *LPD3DBASE;
  995. /////////////////////////////////////////////////////////////////////////////
  996. // //
  997. // CD3DHal //
  998. // //
  999. /////////////////////////////////////////////////////////////////////////////
  1000. typedef void (CD3DHal::* PFN_PREPARETODRAW)(UINT StartVertex);
  1001. class CD3DHal : public CD3DBase
  1002. {
  1003. public: // Private Data
  1004. // buffer for H vertices
  1005. CAlignedBuffer32 HVbuf;
  1006. // Front end data
  1007. D3DFE_TRANSFORM transform; // Transformation state
  1008. D3DCLIPSTATUS8 m_ClipStatus;
  1009. // Pipeline state info
  1010. D3DFE_PROCESSVERTICES* m_pv; // common data for D3D and PSGP
  1011. DWORD dwFEFlags; // Front-end flags
  1012. //--------------- Lights start -----------------------
  1013. // List of currently enabled lights
  1014. LIST_ROOT(_dlights, DIRECT3DLIGHTI) m_ActiveLights;
  1015. LIST_ROOT(name10,_SpecularTable) specular_tables;
  1016. SpecularTable* specular_table;
  1017. LIGHT_VERTEX_FUNC_TABLE *lightVertexFuncTable;
  1018. // Light management support
  1019. CHandleArray* m_pLightArray;
  1020. //--------------- Lights end -----------------------
  1021. // Viewports
  1022. D3DVIEWPORT8 m_Viewport;
  1023. DWORD m_clrCount; // Number of rects allocated
  1024. LPD3DRECT m_clrRects; // Rects used for clearing
  1025. // Runtime copy of the renderstates
  1026. LPDWORD rstates;
  1027. // Runtime copy of texture stage states
  1028. DWORD tsstates[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  1029. // Bit set for a render state means that we have to update internal front-end state
  1030. // Otherwise we can go through a fast path
  1031. CPackedBitArray rsVec;
  1032. // Bit set for a render state means that the render state is retired
  1033. CPackedBitArray rsVecRetired;
  1034. // Bit set for a render state means that the render state is for vertex
  1035. // processing only
  1036. CPackedBitArray rsVertexProcessingOnly;
  1037. // For every transformation matrix there is a bit, which is set if we need
  1038. // to update driver state
  1039. CPackedBitArray* pMatrixDirtyForDDI;
  1040. // Pointer to a specific PrepareToDraw function
  1041. PFN_PREPARETODRAW m_pfnPrepareToDraw;
  1042. // Current vertex shader, corresponding to the dwCurrentShaderHandle
  1043. // NULL for the fixed-function pipeline
  1044. CVShader* m_pCurrentShader;
  1045. // The instance of the class providing a guaranteed implementation
  1046. D3DFE_PVFUNCSI* GeometryFuncsGuaranteed;
  1047. // Pixel Shader constant registers cached for Hal device
  1048. PVM_WORD m_PShaderConstReg[D3DPS_CONSTREG_MAX_DX8];
  1049. // Object, used to convert NPatches to TriPatches
  1050. CNPatch2TriPatch* m_pConvObj;
  1051. // Texture stages, which we need to remap, when number of output texture
  1052. // coordinates is greater than number of input texture coordinates
  1053. D3DFE_TEXTURESTAGE textureStageToRemap[D3DDP_MAXTEXCOORD];
  1054. // Number of texture stages to remap
  1055. DWORD dwNumTextureStagesToRemap;
  1056. virtual HRESULT D3DAPI SetRenderStateFast(D3DRENDERSTATETYPE dwState, DWORD value);
  1057. virtual HRESULT D3DAPI SetTextureStageStateFast(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue);
  1058. #ifdef FAST_PATH
  1059. virtual HRESULT D3DAPI SetVertexShaderFast(DWORD);
  1060. #endif // FAST_PATH
  1061. virtual HRESULT D3DAPI SetMaterialFast(CONST D3DMATERIAL8*);
  1062. virtual HRESULT D3DAPI SetPixelShaderFast(DWORD dwHandle);
  1063. virtual HRESULT D3DAPI SetPixelShaderConstantFast(DWORD dwRegisterAddress,
  1064. CONST VOID* lpvConstantData,
  1065. DWORD dwConstantCount);
  1066. public:
  1067. CD3DHal();
  1068. virtual ~CD3DHal();
  1069. virtual void Destroy();
  1070. //
  1071. // Pure Methods from CD3DBase implemented here
  1072. //
  1073. virtual HRESULT InitDevice();
  1074. virtual void StateInitialize(BOOL bZEnable);
  1075. virtual void SetTransformI(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*);
  1076. virtual void MultiplyTransformI(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*);
  1077. virtual void SetViewportI(CONST D3DVIEWPORT8*);
  1078. virtual void SetLightI(DWORD dwLightIndex, CONST D3DLIGHT8*);
  1079. virtual void LightEnableI(DWORD dwLightIndex, BOOL);
  1080. virtual void SetClipPlaneI(DWORD dwPlaneIndex,
  1081. CONST D3DVALUE* pPlaneEquation);
  1082. virtual void SetStreamSourceI(CVStream*);
  1083. virtual void SetIndicesI(CVIndexStream*);
  1084. virtual void CreateVertexShaderI(CONST DWORD* pdwDeclaration,
  1085. DWORD dwDeclSize,
  1086. CONST DWORD* pdwFunction,
  1087. DWORD dwCodeSize,
  1088. DWORD dwHandle);
  1089. virtual void SetVertexShaderI(DWORD dwHandle);
  1090. virtual void DeleteVertexShaderI(DWORD dwHandle);
  1091. virtual void SetVertexShaderConstantI(DWORD dwRegisterAddress,
  1092. CONST VOID* lpvConstantData,
  1093. DWORD dwConstantCount);
  1094. virtual void DrawPointsI(D3DPRIMITIVETYPE PrimitiveType,
  1095. UINT StartVertex,
  1096. UINT PrimitiveCount);
  1097. virtual void DrawPrimitiveUPI(D3DPRIMITIVETYPE PrimitiveType,
  1098. UINT PrimitiveCount);
  1099. virtual void DrawIndexedPrimitiveUPI(D3DPRIMITIVETYPE PrimitiveType,
  1100. UINT MinVertexIndex,
  1101. UINT NumVertexIndices,
  1102. UINT PrimitiveCount);
  1103. virtual void ClearI( DWORD dwCount, CONST D3DRECT* rects, DWORD dwFlags,
  1104. D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  1105. // This function is used when in SetRenderTarget the driver context is
  1106. // recreated
  1107. virtual void UpdateDriverStates(); // 10
  1108. virtual void UpdateRenderState(DWORD dwStateType, DWORD value)
  1109. {rstates[dwStateType] = value;}
  1110. virtual void __declspec(nothrow) PickDrawPrimFn();
  1111. public: // non virtual methods
  1112. // Called by drawing functions to prepare vertex stream pointers for
  1113. // legacy vertex shaders
  1114. void PrepareToDrawLegacy(UINT dwStartVertex);
  1115. // Called by drawing functions to prepare vertex stream pointers for
  1116. // programmable pipeline
  1117. void PrepareToDrawVVM(UINT dwStartVertex);
  1118. // Called by drawing functions to prepare vertex stream pointers for
  1119. // fixed-function pipeline with declarations
  1120. void PrepareToDraw(UINT dwStartVertex);
  1121. // dwValue could be changed by the function, when we need to filter
  1122. // PROJECTED bit.
  1123. BOOL UpdateInternalTextureStageState(DWORD dwStage,
  1124. D3DTEXTURESTAGESTATETYPE dwState,
  1125. DWORD* dwValue);
  1126. HRESULT checkDeviceSurface(LPDDRAWI_DDRAWSURFACE_LCL lpDDS, LPDDRAWI_DDRAWSURFACE_LCL lpZbuffer, LPGUID pGuid);
  1127. void SetupFVFDataCommon();
  1128. void SetupFVFData();
  1129. void SwitchVertexProcessingMode(DWORD SoftwareMode);
  1130. void DrawPoints(UINT StartVertex);
  1131. void GetPixelShaderConstantI(DWORD Register, DWORD count, LPVOID pData );
  1132. void PrepareNPatchConversion(UINT PrimitiveCount, UINT StartVertex);
  1133. BOOL NeedInternalTSSUpdate(DWORD dwState)
  1134. {
  1135. return dwState == D3DTSS_TEXCOORDINDEX || dwState >= D3DTSS_TEXTURETRANSFORMFLAGS ||
  1136. dwState == D3DTSS_COLOROP;
  1137. }
  1138. // Always use this function to update "rstates", because we have to
  1139. // set some internal flags when "rstats" is changed.
  1140. void UpdateInternalState(D3DRENDERSTATETYPE type, DWORD value);
  1141. // Checks for 'retired' render state - returns TRUE if not retired
  1142. BOOL CheckForRetiredRenderState(D3DRENDERSTATETYPE type)
  1143. {
  1144. if (!rsVecRetired.IsBitSet(type))
  1145. {
  1146. // not retired
  1147. return TRUE;
  1148. }
  1149. return FALSE;
  1150. }
  1151. // Update internal state
  1152. inline void SetFogFlags(void);
  1153. void ForceFVFRecompute(void)
  1154. {
  1155. dwFEFlags |= D3DFE_FVF_DIRTY | D3DFE_FRONTEND_DIRTY;
  1156. m_pv->dwDeviceFlags &= ~(D3DDEV_POSITIONINCAMERASPACE |
  1157. D3DDEV_NORMALINCAMERASPACE);
  1158. m_dwRuntimeFlags |= D3DRT_SHADERDIRTY;
  1159. };
  1160. void DisplayStats();
  1161. void SetRenderStateInternal(D3DRENDERSTATETYPE, DWORD);
  1162. HRESULT Initialize(IUnknown* pUnkOuter, LPDDRAWI_DIRECTDRAW_INT pDDrawInt);
  1163. HRESULT D3DFE_Create();
  1164. void D3DFE_Destroy();
  1165. void ValidateDraw2(D3DPRIMITIVETYPE primType, UINT StartVertex,
  1166. UINT PrimitiveCount, UINT NumVertices,
  1167. BOOL bIndexPrimitive, UINT StartIndex = 0);
  1168. #if DBG
  1169. void ValidateRTPatch();
  1170. #endif // DBG
  1171. #if DBG
  1172. #define PROF_DRAWPRIMITIVEDEVICE2 0x0003
  1173. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE2 0x0004
  1174. #define PROF_DRAWPRIMITIVESTRIDED 0x0005
  1175. #define PROF_DRAWINDEXEDPRIMITIVESTRIDED 0x0006
  1176. #define PROF_DRAWPRIMITIVEDEVICE3 0x0007
  1177. #define PROF_DRAWINDEXEDPRIMITIVEDEVICE3 0x0008
  1178. #define PROF_DRAWPRIMITIVEVB 0x0009
  1179. #define PROF_DRAWINDEXEDPRIMITIVEVB 0x000a
  1180. DWORD dwCaller;
  1181. DWORD dwPrimitiveType[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  1182. DWORD dwVertexType1[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  1183. DWORD dwVertexType2[PROF_DRAWINDEXEDPRIMITIVEVB+1];
  1184. void Profile(DWORD, D3DPRIMITIVETYPE, DWORD);
  1185. #else
  1186. #define Profile(a,b,c)
  1187. #endif
  1188. public:
  1189. // IDirect3DDevice8 Methods
  1190. HRESULT D3DAPI GetViewport(D3DVIEWPORT8*);
  1191. HRESULT D3DAPI GetMaterial(D3DMATERIAL8*);
  1192. HRESULT D3DAPI GetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX);
  1193. HRESULT D3DAPI GetLight(DWORD, D3DLIGHT8*);
  1194. HRESULT D3DAPI GetLightEnable(DWORD dwLightIndex, BOOL*);
  1195. HRESULT D3DAPI GetClipPlane(DWORD dwPlaneIndex, D3DVALUE* pPlaneEquation);
  1196. HRESULT D3DAPI GetTextureStageState(DWORD, D3DTEXTURESTAGESTATETYPE,
  1197. LPDWORD);
  1198. HRESULT D3DAPI SetTextureStageState(DWORD dwStage,
  1199. D3DTEXTURESTAGESTATETYPE dwState,
  1200. DWORD dwValue);
  1201. HRESULT D3DAPI GetRenderState(D3DRENDERSTATETYPE, LPDWORD);
  1202. HRESULT D3DAPI SetRenderState(D3DRENDERSTATETYPE, DWORD);
  1203. HRESULT D3DAPI SetClipStatus(CONST D3DCLIPSTATUS8*);
  1204. HRESULT D3DAPI GetClipStatus(D3DCLIPSTATUS8*);
  1205. HRESULT D3DAPI ProcessVertices(UINT SrcStartIndex, UINT DestIndex,
  1206. UINT VertexCount,
  1207. IDirect3DVertexBuffer8 *DestBuffer,
  1208. DWORD Flags);
  1209. HRESULT D3DAPI GetVertexShaderConstant(DWORD dwRegisterAddress,
  1210. LPVOID lpvConstantData,
  1211. DWORD dwConstantCount);
  1212. HRESULT D3DAPI GetPixelShaderConstant(DWORD dwRegisterAddress,
  1213. LPVOID lpvConstantData,
  1214. DWORD dwConstantCount);
  1215. HRESULT D3DAPI GetVertexShader(LPDWORD pdwHandle);
  1216. HRESULT D3DAPI GetPixelShader(LPDWORD pdwHandle);
  1217. };
  1218. //---------------------------------------------------------------------
  1219. // macros to characterize device
  1220. //
  1221. #define IS_DX7HAL_DEVICE(lpDevI) ((lpDevI)->GetDDIType() >= D3DDDITYPE_DX7)
  1222. #define IS_DX8HAL_DEVICE(lpDevI) ((lpDevI)->GetDDIType() >= D3DDDITYPE_DX8)
  1223. #define IS_FPU_SETUP(lpDevI) ((lpDevI)->m_dwHintFlags & D3DDEVBOOL_HINTFLAGS_FPUSETUP )
  1224. #define IS_HAL_DEVICE(lpDevI) ((lpDevI)->GetDeviceType() == D3DDEVTYPE_HAL)
  1225. #define IS_HEL_DEVICE(lpDevI) ((lpDevI)->GetDeviceType() == D3DDEVTYPE_EMULATION)
  1226. #define IS_REF_DEVICE(lpDevI) ((lpDevI)->GetDeviceType() == D3DDEVTYPE_REF)
  1227. #endif
  1228. // @@END_MSINTERNAL
  1229. #endif /* _D3DI_H */