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.

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