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.

836 lines
36 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: ddi.h
  6. * Content: Direct3D DDI encapsulation implementations
  7. *
  8. *
  9. ***************************************************************************/
  10. #ifndef _DDI_H
  11. #define _DDI_H
  12. #include "ddibase.h"
  13. class CVertexBuffer;
  14. class CCommandBuffer;
  15. class CTLStreamRO;
  16. class CTLIndexStreamRO;
  17. class CD3DDDIDX6;
  18. // Number of point sprites in a point sprite batch
  19. const UINT NUM_SPRITES_IN_BATCH = 500;
  20. extern void CD3DDDIDX6_DrawPrimitive(CD3DBase* pDevice,
  21. D3DPRIMITIVETYPE primType,
  22. UINT StartVertex,
  23. UINT PrimitiveCount);
  24. extern void
  25. CD3DDDIDX8_DrawPrimitive(CD3DBase* pDevice, D3DPRIMITIVETYPE PrimitiveType,
  26. UINT StartVertex, UINT PrimitiveCount);
  27. extern void
  28. CD3DDDIDX8_DrawIndexedPrimitive(CD3DBase* pDevice,
  29. D3DPRIMITIVETYPE PrimitiveType,
  30. UINT BaseVertexIndex,
  31. UINT MinIndex, UINT NumVertices,
  32. UINT StartIndex, UINT PrimitiveCount);
  33. extern void
  34. CD3DDDITL_DrawIndexedPrimitive(CD3DBase* pDevice,
  35. D3DPRIMITIVETYPE PrimitiveType,
  36. UINT BaseVertexIndex,
  37. UINT MinIndex,
  38. UINT NumVertices, UINT StartIndex,
  39. UINT PrimitiveCount);
  40. extern void
  41. CD3DDDIDX6_DrawIndexedPrimitive(CD3DBase* pDevice,
  42. D3DPRIMITIVETYPE PrimitiveType,
  43. UINT BaseVertexIndex,
  44. UINT MinIndex,
  45. UINT NumVertices, UINT StartIndex,
  46. UINT PrimitiveCount);
  47. typedef void (*PFN_DRAWPRIMFAST)(CD3DBase* pDevice, D3DPRIMITIVETYPE primType,
  48. UINT StartVertex, UINT PrimitiveCount);
  49. typedef void (*PFN_DRAWINDEXEDPRIMFAST)(CD3DBase* pDevice,
  50. D3DPRIMITIVETYPE PrimitiveType,
  51. UINT BaseVertexIndex,
  52. UINT MinIndex, UINT NumVertices,
  53. UINT StartIndex, UINT PrimitiveCount);
  54. //-----------------------------------------------------------------------------
  55. class CTLStream: public CVStream
  56. {
  57. public:
  58. CTLStream(BOOL bWriteOnly);
  59. CTLStream(BOOL bWriteOnly, UINT Usage);
  60. UINT GetSize() {return m_dwSize - m_dwUsedSize;}
  61. void Grow(UINT RequiredSize, CD3DDDIDX6* pDDI);
  62. void Reset() {m_dwPrimitiveBase = 0; m_dwUsedSize = 0;}
  63. DWORD GetVertexSize() {return m_dwStride;}
  64. void SetVertexSize(DWORD dwVertexSize) {m_dwStride = dwVertexSize;}
  65. DWORD GetPrimitiveBase() {return m_dwPrimitiveBase;}
  66. virtual BYTE* Lock(UINT NeededSize, CD3DDDIDX6* pDDI);
  67. virtual void Unlock();
  68. virtual void AddVertices(UINT NumVertices)
  69. {
  70. m_dwUsedSize = m_dwPrimitiveBase + NumVertices * m_dwStride;
  71. DXGASSERT(m_dwSize >= m_dwUsedSize);
  72. }
  73. virtual void SubVertices(UINT NumVertices)
  74. {
  75. DXGASSERT(m_dwUsedSize >= NumVertices * m_dwStride);
  76. m_dwUsedSize -= NumVertices * m_dwStride;
  77. DXGASSERT(m_dwSize >= m_dwUsedSize);
  78. }
  79. virtual void MovePrimitiveBase(int NumVertices)
  80. {
  81. m_dwPrimitiveBase += NumVertices * m_dwStride;
  82. }
  83. virtual void SkipVertices(DWORD NumVertices)
  84. {
  85. const UINT size = NumVertices * m_dwStride;
  86. m_dwPrimitiveBase += size;
  87. m_dwUsedSize = m_dwPrimitiveBase;
  88. DXGASSERT(m_dwSize >= m_dwUsedSize);
  89. }
  90. BOOL CheckFreeSpace(UINT size) {return (m_dwSize - m_dwUsedSize) >= size;}
  91. protected:
  92. // Number of bytes used in the buffer
  93. // It is not used by CTLStreamRO
  94. DWORD m_dwUsedSize;
  95. // Offset in bytes from where the current primitive starts
  96. DWORD m_dwPrimitiveBase;
  97. UINT m_Usage;
  98. // TRUE, if buffer is used only for writing
  99. BOOL m_bWriteOnly;
  100. #if !DBG
  101. DWORD m_dwSize;
  102. #endif
  103. };
  104. //-----------------------------------------------------------------------------
  105. class CTLIndexStream: public CVIndexStream
  106. {
  107. public:
  108. CTLIndexStream();
  109. UINT GetSize() {return m_dwSize - m_dwUsedSize;}
  110. void Grow(UINT RequiredSize, CD3DDDIDX6* pDDI);
  111. void Reset() {m_dwPrimitiveBase = 0; m_dwUsedSize = 0;}
  112. DWORD GetVertexSize() {return m_dwStride;}
  113. void SetVertexSize(DWORD dwVertexSize) {m_dwStride = dwVertexSize;}
  114. DWORD GetPrimitiveBase() {return m_dwPrimitiveBase;}
  115. virtual BYTE* Lock(UINT NeededSize, CD3DDDIDX6* pDDI);
  116. BYTE* LockDiscard(UINT NeededSize, CD3DDDIDX6* pDDI);
  117. virtual void Unlock();
  118. virtual void AddVertices(UINT NumVertices)
  119. {
  120. m_dwUsedSize = m_dwPrimitiveBase + NumVertices * m_dwStride;
  121. DXGASSERT(m_dwSize >= m_dwUsedSize);
  122. }
  123. virtual void SubVertices(UINT NumVertices)
  124. {
  125. DXGASSERT(m_dwUsedSize >= NumVertices * m_dwStride);
  126. m_dwUsedSize -= NumVertices * m_dwStride;
  127. DXGASSERT(m_dwSize >= m_dwUsedSize);
  128. }
  129. virtual void MovePrimitiveBase(int NumVertices)
  130. {
  131. m_dwPrimitiveBase += NumVertices * m_dwStride;
  132. }
  133. virtual void SkipVertices(DWORD NumVertices)
  134. {
  135. const UINT size = NumVertices * m_dwStride;
  136. m_dwPrimitiveBase += size;
  137. m_dwUsedSize = m_dwPrimitiveBase;
  138. DXGASSERT(m_dwSize >= m_dwUsedSize);
  139. }
  140. protected:
  141. // Number of bytes used in the buffer
  142. // It is not used by CTLStreamRO
  143. DWORD m_dwUsedSize;
  144. // Index of a index, which is the start of the current primitive
  145. DWORD m_dwPrimitiveBase;
  146. #if !DBG
  147. DWORD m_dwSize;
  148. #endif
  149. };
  150. // This class is used to keep track of what set to a DDI stream
  151. struct CDDIStream
  152. {
  153. CDDIStream()
  154. {
  155. m_pStream = NULL;
  156. m_dwStride = 0;
  157. m_pBuf = NULL;
  158. }
  159. // Pointer to a stream object
  160. CVStreamBase* m_pStream;
  161. // Stride of the currently set stream
  162. DWORD m_dwStride;
  163. // VB pointer of the currently set stream
  164. CBuffer *m_pBuf;
  165. };
  166. /////////////////////////////////////////////////////////////////////////////
  167. // //
  168. // CD3DDDIDX6 //
  169. // //
  170. /////////////////////////////////////////////////////////////////////////////
  171. //--------------------------------------------------------------------
  172. // Flags for dwDP2Flags
  173. //
  174. // This flag is set if the current TLVbuf is write only
  175. const DWORD D3DDDI_TLVBUFWRITEONLY = 1 << 0;
  176. // This flag is set we pass user memory to the DDI
  177. const DWORD D3DDDI_USERMEMVERTICES = 1 << 1;
  178. // Set when DrawIndexPrim is called. It is used to check if vertices
  179. // of an indexed primitive were used at all. They could not be used because
  180. // of clipping.
  181. const DWORD D3DDDI_INDEXEDPRIMDRAWN = 1 << 2;
  182. typedef void (CD3DDDIDX6::* PFN_PROCESSPRIM)(D3DFE_PROCESSVERTICES*,
  183. UINT StartVertex);
  184. class CD3DDDIDX6 : public CD3DDDI
  185. {
  186. public:
  187. CD3DDDIDX6();
  188. ~CD3DDDIDX6();
  189. // Virtual functions -----------------------------------------------
  190. virtual void Init(CD3DBase* pDevice );
  191. virtual void SetRenderTarget(CBaseSurface*, CBaseSurface*);
  192. virtual void FlushStates(BOOL bReturnDriverError=FALSE, BOOL bWithinPrimitive = FALSE);
  193. virtual void ValidateDevice(LPDWORD lpdwNumPasses);
  194. virtual void Clear(DWORD dwFlags, DWORD clrCount, LPD3DRECT clrRects,
  195. D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  196. virtual HRESULT __declspec(nothrow) LockVB(CDriverVertexBuffer*, DWORD dwFlags);
  197. virtual HRESULT __declspec(nothrow) UnlockVB(CDriverVertexBuffer*);
  198. virtual void ClearBatch( BOOL bWithinPrimitive );
  199. virtual void SceneCapture(BOOL bState);
  200. // This function is called whe software vertex processing is used
  201. // Handle should be always legacy
  202. virtual void SetVertexShader(DWORD dwHandle);
  203. // This function is called whe hardware vertex processing is used
  204. virtual void SetVertexShaderHW(DWORD dwHandle);
  205. virtual void UpdatePalette(DWORD,DWORD,DWORD,PALETTEENTRY*);
  206. virtual void SetPalette(DWORD,DWORD,CBaseTexture*);
  207. // Used to pick a function to process (indexed) primitive
  208. // The picking is based on
  209. // D3DDEV_DONOTCLIP
  210. // FVF_TRANSFORMED(m_pDevice->m_dwCurrentShaderHandle)
  211. // D3DDEV_DOPOINTSPRITEEMULATION
  212. virtual void PickProcessPrimitive();
  213. virtual void SetTSS(DWORD, D3DTEXTURESTAGESTATETYPE, DWORD);
  214. virtual void DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,
  215. UINT PrimitiveCount);
  216. virtual void DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,
  217. UINT MinVertexIndex,
  218. UINT NumVertices,
  219. UINT PrimitiveCount);
  220. // Returns max number of renderstates, handled by the DDI
  221. virtual D3DRENDERSTATETYPE GetMaxRenderState()
  222. {return D3DRENDERSTATE_CLIPPING;}
  223. // Returns max number of texture stage states, handled by the DDI
  224. virtual D3DTEXTURESTAGESTATETYPE GetMaxTSS()
  225. {return D3DTSS_TEXTURETRANSFORMFLAGS;}
  226. // Returns TRUE if the device supports T&L
  227. virtual BOOL CanDoTL() {return FALSE;}
  228. // DDI can directly accept index buffer
  229. virtual BOOL AcceptIndexBuffer() {return FALSE;}
  230. virtual BOOL CanDoTLVertexClipping() {return FALSE;}
  231. // Process primitive with untransformed vertices and with no clipping
  232. virtual void ProcessPrimitive(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  233. virtual void ProcessIndexedPrimitive(D3DFE_PROCESSVERTICES* pv,
  234. UINT StartVertex);
  235. // Process primitive with untransformed vertices and with clipping
  236. virtual void ProcessPrimitiveC(D3DFE_PROCESSVERTICES* pv,
  237. UINT StartVertex);
  238. virtual void ProcessIndexedPrimitiveC(D3DFE_PROCESSVERTICES* pv,
  239. UINT StartVertex);
  240. virtual void SetViewport(CONST D3DVIEWPORT8*);
  241. virtual void StartPrimVB(D3DFE_PROCESSVERTICES * pv, CVStream* pStream,
  242. DWORD dwStartVertex);
  243. virtual LPVOID StartPrimTL(D3DFE_PROCESSVERTICES*, DWORD dwVertexPoolSize,
  244. BOOL bWriteOnly);
  245. virtual void StartPointSprites();
  246. virtual void EndPointSprites();
  247. // Virtual functions: Empty implementations ------------------------
  248. virtual void SetTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*){}
  249. virtual void MultiplyTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*){}
  250. virtual void SetMaterial(CONST D3DMATERIAL8*){}
  251. virtual void CreateLight(DWORD dwLightIndex) {}
  252. virtual void SetLight(DWORD dwLightIndex, CONST D3DLIGHT8*){}
  253. virtual void LightEnable(DWORD dwLightIndex, BOOL){}
  254. virtual void SetClipPlane(DWORD dwPlaneIndex,
  255. CONST D3DVALUE* pPlaneEquation){}
  256. virtual void WriteStateSetToDevice(D3DSTATEBLOCKTYPE sbt) {}
  257. // Used to notify DDI that a vertex buffer was released. If the DDI keeps a
  258. // pointer to the VB it should be zeroed
  259. virtual void VBReleased(CBuffer *pBuf) {}
  260. // Used to notify DDI that amn index buffer was released. If the DDI keeps
  261. // a pointer to the IB it should be zeroed
  262. virtual void VBIReleased(CBuffer *pBuf) {}
  263. virtual void ResetVertexShader() {}
  264. virtual void SetVertexShaderConstant(DWORD dwRegisterAddress,
  265. CONST VOID* lpvConstantData,
  266. DWORD dwConstantCount){}
  267. virtual void SetPixelShaderConstant(DWORD dwRegisterAddress,
  268. CONST VOID* lpvConstantData,
  269. DWORD dwConstantCount){}
  270. // Virtual functions: Unsupported implementations ------------------
  271. virtual void SetPriority(CResource*, DWORD dwPriority)
  272. { NotSupported("SetPriority");}
  273. virtual void SetTexLOD(CBaseTexture*, DWORD dwLOD)
  274. { NotSupported("SetTexLOD");}
  275. virtual void TexBlt(DWORD dwDst, DWORD dwSrc,
  276. LPPOINT p, RECTL *r)
  277. { NotSupported("TexBlt");}
  278. virtual void VolBlt(CBaseTexture *lpDst, CBaseTexture* lpSrc,
  279. DWORD dwDestX, DWORD dwDestY, DWORD dwDestZ,
  280. D3DBOX *pBox)
  281. { NotSupported("VolBlt");}
  282. virtual void BufBlt(CBuffer *lpDst, CBuffer* lpSrc,
  283. DWORD dwOffset, D3DRANGE* pRange)
  284. { NotSupported("BufBlt");}
  285. virtual void AddDirtyRect(DWORD dwHandle,
  286. CONST RECTL *pRect)
  287. { NotSupported("AddDirtyRect");}
  288. virtual void AddDirtyBox(DWORD dwHandle,
  289. CONST D3DBOX *pBox)
  290. { NotSupported("AddDirtyRect");}
  291. virtual void InsertStateSetOp(DWORD dwOperation, DWORD dwParam,
  292. D3DSTATEBLOCKTYPE sbt)
  293. { NotSupported("InsertStateSetOp");}
  294. virtual void CreateVertexShader(CONST DWORD* pdwDeclaration,
  295. DWORD dwDeclarationSize,
  296. CONST DWORD* pdwFunction,
  297. DWORD dwFunctionSize,
  298. DWORD dwHandle,
  299. BOOL bLegacyFVF)
  300. { NotSupported("CreateVertexShader");}
  301. virtual void DeleteVertexShader(DWORD dwHandle)
  302. { NotSupported("DeleteVertexShader");}
  303. virtual void CreatePixelShader(CONST DWORD* pdwFunction,
  304. DWORD dwFunctionSize,
  305. DWORD dwHandle)
  306. { NotSupported("CreatePixelShader");}
  307. virtual void SetPixelShader(DWORD dwHandle) {}
  308. virtual void DeletePixelShader(DWORD dwHandle)
  309. { NotSupported("DeletePixelShader");}
  310. virtual void GetInfo(DWORD dwDevInfoID, LPVOID pDevInfoStruct,
  311. DWORD dwSize)
  312. { NotSupported("GetInfo");}
  313. virtual void DrawRectPatch(UINT Handle, CONST D3DRECTPATCH_INFO *pSurf,
  314. CONST FLOAT *pNumSegs)
  315. { NotSupported("DrawRectPatch");}
  316. virtual void DrawTriPatch(UINT Handle, CONST D3DTRIPATCH_INFO *pSurf,
  317. CONST FLOAT *pNumSegs)
  318. { NotSupported("DrawTriPatch");}
  319. // Non Virtual functions -------------------------------------------
  320. void CreateContext();
  321. void DestroyContext();
  322. void SetRenderState(D3DRENDERSTATETYPE, DWORD);
  323. void FlushStatesReq(DWORD dwReqSize);
  324. void FlushStatesCmdBufReq(DWORD dwReqSize);
  325. void SetStreamSource(UINT StreamIndex, CVStream*);
  326. void SetIndices(CVIndexStream*);
  327. // Update W range in device. Projection matrix is passed as parameter
  328. void UpdateWInfo(CONST D3DMATRIX* lpMat);
  329. // Process points with point sprite expansion
  330. void ProcessPointSprites(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  331. // Process primitive with transformed vertices and with clipping
  332. void ProcessPrimitiveTC(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  333. void ProcessIndexedPrimitiveTC(D3DFE_PROCESSVERTICES* pv,
  334. UINT StartVertex);
  335. void NotSupported(char* msg);
  336. void BeginScene()
  337. {
  338. SceneCapture(TRUE);
  339. }
  340. void EndScene();
  341. void EndPrim(UINT vertexSize);
  342. void NextSprite(float x, float y, float z, float w, DWORD diffuse,
  343. DWORD specular, float* pTexture, UINT TextureSize,
  344. float PointSize);
  345. void AddVertices(UINT NumVertices)
  346. {
  347. if (dwDP2VertexCountMask)
  348. {
  349. dwDP2VertexCount = max(dwVertexBase + NumVertices, dwDP2VertexCount);
  350. }
  351. }
  352. void SubVertices(UINT NumVertices)
  353. {
  354. if (dwDP2VertexCountMask)
  355. {
  356. DXGASSERT(dwDP2VertexCount >= NumVertices);
  357. dwDP2VertexCount -= NumVertices;
  358. }
  359. }
  360. void MovePrimitiveBase(int NumVertices)
  361. {
  362. dwVertexBase += NumVertices;
  363. }
  364. void SkipVertices(DWORD NumVertices)
  365. {
  366. dwVertexBase += NumVertices;
  367. if (dwDP2VertexCountMask)
  368. dwDP2VertexCount = max(dwVertexBase, dwDP2VertexCount);
  369. }
  370. void SetWithinPrimitive( BOOL bWP ){ m_bWithinPrimitive = bWP; }
  371. BOOL GetWithinPrimitive(){ return m_bWithinPrimitive; }
  372. D3DDDITYPE GetDDIType() {return m_ddiType;}
  373. CD3DBase* GetDevice() {return m_pDevice;}
  374. ULONG_PTR GetDeviceContext() {return m_dwhContext;}
  375. virtual PFN_DRAWPRIMFAST __declspec(nothrow) GetDrawPrimFunction()
  376. {
  377. return CD3DDDIDX6_DrawPrimitive;
  378. }
  379. virtual PFN_DRAWINDEXEDPRIMFAST __declspec(nothrow) GetDrawIndexedPrimFunction()
  380. {
  381. return CD3DDDIDX6_DrawIndexedPrimitive;
  382. }
  383. // Implementation of base functions ---------------------------------
  384. // Draw non-indexed primitive
  385. void DrawPrim(D3DFE_PROCESSVERTICES* pv);
  386. // Draw point sprites with emulation
  387. void DrawPrimPS(D3DFE_PROCESSVERTICES* pv);
  388. // Draw primitive, generated by the clipper
  389. void DrawClippedPrim(D3DFE_PROCESSVERTICES* pv);
  390. // Draw indexed primitive
  391. void DrawIndexPrim(D3DFE_PROCESSVERTICES* pv);
  392. protected:
  393. // DDI Type
  394. D3DDDITYPE m_ddiType;
  395. CD3DBase* m_pDevice;
  396. DWORD m_dwInterfaceNumber;
  397. // Driver context
  398. ULONG_PTR m_dwhContext;
  399. // Is it within primitive
  400. BOOL m_bWithinPrimitive;
  401. PFN_PROCESSPRIM m_pfnProcessPrimitive;
  402. PFN_PROCESSPRIM m_pfnProcessIndexedPrimitive;
  403. // Reserve space in the command buffer. Flush and grow if needed.
  404. // Returns pointer to where new commands could be inserted
  405. LPVOID ReserveSpaceInCommandBuffer(UINT ByteCount);
  406. // Reserve space for a new command in the command buffer. Flush if needed
  407. // New command is initialized.
  408. // Returns pointer to where the command data could be inserted
  409. LPVOID GetHalBufferPointer(D3DHAL_DP2OPERATION op, DWORD dwDataSize);
  410. DWORD GetTLVbufSize() { return TLVbuf_size - TLVbuf_base; }
  411. DWORD& TLVbuf_Base() { return TLVbuf_base; }
  412. LPVOID TLVbuf_GetAddress() {return (LPBYTE)alignedBuf + TLVbuf_base;}
  413. void GrowCommandBuffer(DWORD dwSize);
  414. void GrowTLVbuf(DWORD growSize, BOOL bWriteOnly);
  415. void PrepareForClipping(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  416. void StartPrimUserMem(D3DFE_PROCESSVERTICES*, UINT VertexPoolSize);
  417. inline CVertexBuffer* TLVbuf_GetVBI() { return allocatedBuf; }
  418. #if DBG
  419. void ValidateVertex(LPDWORD lpdwVertex);
  420. virtual void ValidateCommand(LPD3DHAL_DP2COMMAND lpCmd);
  421. #endif
  422. static const DWORD dwD3DDefaultCommandBatchSize;
  423. // Index (relative to the TLVbuf start) of the first vertex of
  424. // the current primitive
  425. DWORD dwVertexBase;
  426. // Number of vertices in the DP2 vertex buffer
  427. DWORD dwDP2VertexCount;
  428. // Mask used to prevent modification of dwDP2VertexCount. This is needed
  429. // when user calls SetStreamSource with TL vertices and uses multiple
  430. // DrawPrimitive calls with different StartVertex. dwDP2VertexCount should
  431. // be always set to the number of vertices in the user vertex buffer.
  432. DWORD dwDP2VertexCountMask;
  433. // This is the VB interface corresponding to the dp2data.lpDDVertex
  434. // This is kept so that the VB can be released when done
  435. // which cannot be done from just the LCL pointer which is lpDDVertex
  436. CVertexBuffer* lpDP2CurrBatchVBI;
  437. DWORD TLVbuf_size;
  438. DWORD TLVbuf_base;
  439. #ifdef VTABLE_HACK
  440. // Cached dwFlags for fast path
  441. DWORD dwLastFlags;
  442. // Last VB used in a call that involved D3D's FE.
  443. CVertexBuffer* lpDP2LastVBI;
  444. #endif
  445. DWORD dwDP2CommandBufSize;
  446. DWORD dwDP2CommandLength;
  447. // Cache line should start here
  448. // Pointer to the actual data in CB1
  449. LPVOID lpvDP2Commands;
  450. //Pointer to the current position the CB1 buffer
  451. LPD3DHAL_DP2COMMAND lpDP2CurrCommand;
  452. // Perf issue: replace the below 3 fields by a 32 bit D3DHAL_DP2COMMAND struct
  453. WORD wDP2CurrCmdCnt; // Mirror of Count field if the current command
  454. BYTE bDP2CurrCmdOP; // Mirror of Opcode of the current command
  455. BYTE bDummy; // Force DWORD alignment of next member
  456. D3D8_DRAWPRIMITIVES2DATA dp2data;
  457. // The buffer we currently batch into
  458. CCommandBuffer *lpDDSCB1;
  459. CVertexBuffer *allocatedBuf;
  460. LPVOID alignedBuf;
  461. CVertexBuffer *m_pNullVB;
  462. // Count read/write <-> write-only transistions
  463. DWORD dwTLVbufChanges;
  464. // Flags specific to DP2 device
  465. DWORD dwDP2Flags;
  466. // This stuff is allocated by the NT Kernel. Need to keep
  467. // it around to pass it to all the DP2 calls. Kernel validates
  468. // this pointer.
  469. WORD *lpwDPBuffer;
  470. // Used to offset indices in DrawIndexPrim
  471. DWORD m_dwIndexOffset;
  472. // Data to draw point sprites
  473. // Pointer where to insert the next point sprite vertex
  474. BYTE* m_pCurSpriteVertex;
  475. // Pointer where to insert the next point sprite index
  476. WORD* m_pCurPointSpriteIndex;
  477. // Number of sprites in the current point sprite batch
  478. UINT m_CurNumberOfSprites;
  479. // When we need to expand points to quads, we use this stream to process
  480. // vertices into
  481. CTLStream* m_pPointStream;
  482. // These is used to keep the original dwVertexBase and dwDP2VertexCount,
  483. // when processing point sprites
  484. DWORD m_dwVertexBasePS;
  485. DWORD m_dwVertexCountPS;
  486. // Output vertex FVF for point sprite emulation
  487. DWORD m_dwVIDOutPS;
  488. // Output vertex size for point sprites emulation
  489. DWORD m_dwOutputSizePS;
  490. DWORD dwDPBufferSize;
  491. // Vertex shader handle currently set to the device driver
  492. DWORD m_CurrentVertexShader;
  493. // Currently used stream 0
  494. CVStream* m_pStream0;
  495. // Currently used index stream
  496. CVIndexStream* m_pIStream;
  497. #if DBG
  498. // Vertex size, computed from the vertex shader
  499. DWORD m_VertexSizeFromShader;
  500. // Switches on/off command and vertices validation
  501. BOOL m_bValidateCommands;
  502. #endif
  503. friend class CD3DHal;
  504. friend void CD3DDDIDX6_DrawPrimitive(CD3DBase* pDevice,
  505. D3DPRIMITIVETYPE primType,
  506. UINT StartVertex,
  507. UINT PrimitiveCount);
  508. friend void CD3DDDIDX6_DrawPrimitiveFast(CD3DBase* pDevice,
  509. D3DPRIMITIVETYPE primType,
  510. UINT StartVertex,
  511. UINT PrimitiveCount);
  512. friend void CD3DDDIDX6_DrawIndexedPrimitive(CD3DBase* pDevice,
  513. D3DPRIMITIVETYPE PrimitiveType,
  514. UINT BaseVertexIndex,
  515. UINT MinIndex, UINT NumVertices,
  516. UINT StartIndex, UINT PrimitiveCount);
  517. friend void CD3DDDIDX6_DrawIndexedPrimitiveFast(CD3DBase* pDevice,
  518. D3DPRIMITIVETYPE primType,
  519. UINT BaseVertexIndex,
  520. UINT MinIndex, UINT NumVertices,
  521. UINT StartIndex, UINT PrimitiveCount);
  522. friend void CD3DHal_DrawPrimitive(CD3DBase* pBaseDevice,
  523. D3DPRIMITIVETYPE PrimitiveType,
  524. UINT StartVertex, UINT PrimitiveCount);
  525. friend void CD3DHal_DrawIndexedPrimitive(CD3DBase* pBaseDevice,
  526. D3DPRIMITIVETYPE PrimitiveType,
  527. UINT BaseIndex,
  528. UINT MinIndex, UINT NumVertices,
  529. UINT StartIndex,
  530. UINT PrimitiveCount);
  531. };
  532. typedef CD3DDDIDX6 *LPD3DDDIDX6;
  533. /////////////////////////////////////////////////////////////////////////////
  534. // //
  535. // CD3DDDIDX7 //
  536. // //
  537. /////////////////////////////////////////////////////////////////////////////
  538. class CD3DDDIDX7 : public CD3DDDIDX6
  539. {
  540. public:
  541. CD3DDDIDX7();
  542. ~CD3DDDIDX7();
  543. void SetRenderTarget(CBaseSurface*, CBaseSurface*);
  544. void InsertStateSetOp(DWORD dwOperation, DWORD dwParam,
  545. D3DSTATEBLOCKTYPE sbt);
  546. void Clear(DWORD dwFlags, DWORD clrCount, LPD3DRECT clrRects,
  547. D3DCOLOR dwColor, D3DVALUE dvZ, DWORD dwStencil);
  548. void TexBlt(DWORD dwDst, DWORD dwSrc, LPPOINT p, RECTL *r);
  549. void SetPriority(CResource*, DWORD dwPriority);
  550. void SetTexLOD(CBaseTexture*, DWORD dwLOD);
  551. void AddDirtyRect(DWORD dwHandle, CONST RECTL *pRect);
  552. void AddDirtyBox(DWORD dwHandle, CONST D3DBOX *pBox);
  553. void UpdatePalette(DWORD,DWORD,DWORD,PALETTEENTRY*);
  554. void SetPalette(DWORD,DWORD,CBaseTexture*);
  555. void WriteStateSetToDevice(D3DSTATEBLOCKTYPE sbt);
  556. virtual void SceneCapture(BOOL bState);
  557. virtual D3DTEXTURESTAGESTATETYPE GetMaxTSS()
  558. {return (D3DTEXTURESTAGESTATETYPE)(D3DTSS_TEXTURETRANSFORMFLAGS+1);}
  559. };
  560. typedef CD3DDDIDX7 *LPD3DDDIDX7;
  561. /////////////////////////////////////////////////////////////////////////////
  562. // //
  563. // CD3DDDITL //
  564. // //
  565. /////////////////////////////////////////////////////////////////////////////
  566. class CD3DDDITL : public CD3DDDIDX7
  567. {
  568. public:
  569. CD3DDDITL();
  570. ~CD3DDDITL();
  571. void SetTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*);
  572. void SetVertexShader(DWORD dwHandle);
  573. void SetVertexShaderHW(DWORD dwHandle);
  574. void SetViewport(CONST D3DVIEWPORT8*);
  575. void SetMaterial(CONST D3DMATERIAL8*);
  576. void SetLight(DWORD dwLightIndex, CONST D3DLIGHT8*);
  577. void LightEnable(DWORD dwLightIndex, BOOL);
  578. void CreateLight(DWORD dwLightIndex);
  579. void SetClipPlane(DWORD dwPlaneIndex, CONST D3DVALUE* pPlaneEquation);
  580. D3DRENDERSTATETYPE GetMaxRenderState()
  581. {return (D3DRENDERSTATETYPE)(D3DRENDERSTATE_CLIPPLANEENABLE + 1);}
  582. BOOL CanDoTL() {return TRUE;}
  583. BOOL CanDoTLVertexClipping() {return TRUE;}
  584. void CreateVertexShader(CONST DWORD* pdwDeclaration,
  585. DWORD dwDeclarationSize,
  586. CONST DWORD* pdwFunction,
  587. DWORD dwFunctionSize,
  588. DWORD dwHandle,
  589. BOOL bLegacyFVF);
  590. };
  591. typedef CD3DDDITL *LPD3DDDITL;
  592. /////////////////////////////////////////////////////////////////////////////
  593. // //
  594. // CD3DDDIDX8 //
  595. // //
  596. /////////////////////////////////////////////////////////////////////////////
  597. class CD3DDDIDX8 : public CD3DDDIDX7
  598. {
  599. public:
  600. CD3DDDIDX8();
  601. ~CD3DDDIDX8();
  602. void Init(CD3DBase* pDevice );
  603. void SetDummyData();
  604. void FlushStates(BOOL bReturnDriverError=FALSE, BOOL bWithinPrimitive = FALSE);
  605. void ClearBatch( BOOL bWithinPrimitive );
  606. HRESULT __declspec(nothrow) LockVB(CDriverVertexBuffer*, DWORD dwFlags);
  607. HRESULT __declspec(nothrow) UnlockVB(CDriverVertexBuffer*);
  608. D3DRENDERSTATETYPE GetMaxRenderState();
  609. D3DTEXTURESTAGESTATETYPE GetMaxTSS()
  610. {return (D3DTEXTURESTAGESTATETYPE)(D3DTSS_RESULTARG+1);}
  611. void SetTSS(DWORD, D3DTEXTURESTAGESTATETYPE, DWORD);
  612. void SetVertexShader(DWORD dwHandle);
  613. void SetVertexShaderHW(DWORD dwHandle);
  614. void ValidateDevice(LPDWORD lpdwNumPasses);
  615. void VolBlt(CBaseTexture *lpDst, CBaseTexture* lpSrc, DWORD dwDestX,
  616. DWORD dwDestY, DWORD dwDestZ, D3DBOX *pBox);
  617. void BufBlt(CBuffer *lpDst, CBuffer* lpSrc, DWORD dwOffset,
  618. D3DRANGE* pRange);
  619. void CreatePixelShader(CONST DWORD* pdwFunction,
  620. DWORD dwFunctionSize,
  621. DWORD dwHandle);
  622. void SetPixelShader(DWORD dwHandle);
  623. void DeletePixelShader(DWORD dwHandle);
  624. void SetPixelShaderConstant(DWORD dwRegisterAddress,
  625. CONST VOID* lpvConstantData,
  626. DWORD dwConstantCount);
  627. void DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount);
  628. void DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,
  629. UINT MinVertexIndex,
  630. UINT NumVertices,
  631. UINT PrimitiveCount);
  632. BOOL AcceptIndexBuffer() {return TRUE;}
  633. BOOL CanDoTLVertexClipping() {return TRUE;}
  634. void DrawRectPatch(UINT Handle, CONST D3DRECTPATCH_INFO *pSurf,
  635. CONST FLOAT *pNumSegs);
  636. void DrawTriPatch(UINT Handle, CONST D3DTRIPATCH_INFO *pSurf,
  637. CONST FLOAT *pNumSegs);
  638. void PickProcessPrimitive();
  639. // Process primitive with untransformed vertices and with no clipping
  640. void ProcessPrimitive(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  641. void ProcessIndexedPrimitive(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  642. // Process primitive with untransformed vertices and with clipping
  643. void ProcessPrimitiveC(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  644. void ProcessIndexedPrimitiveC(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  645. // Process primitive with transformed vertices
  646. void ProcessPrimitiveT(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  647. void ProcessIndexedPrimitiveT(D3DFE_PROCESSVERTICES* pv, UINT StartVertex);
  648. void StartPrimVB(D3DFE_PROCESSVERTICES * pv, CVStream* pStream,
  649. DWORD dwStartVertex);
  650. LPVOID StartPrimTL(D3DFE_PROCESSVERTICES*, DWORD dwVertexPoolSize,
  651. BOOL bWriteOnly);
  652. void DrawPrim(D3DFE_PROCESSVERTICES* pv);
  653. void DrawIndexPrim(D3DFE_PROCESSVERTICES* pv);
  654. void DrawClippedPrim(D3DFE_PROCESSVERTICES* pv);
  655. void VBReleased(CBuffer *pBuf)
  656. {
  657. if (m_pDDIStream[0].m_pBuf == pBuf)
  658. m_pDDIStream[0].m_pBuf = NULL;
  659. }
  660. void VBIReleased(CBuffer *pBuf)
  661. {
  662. if (m_pDDIStream[__NUMSTREAMS].m_pBuf == pBuf)
  663. m_pDDIStream[__NUMSTREAMS].m_pBuf = NULL;
  664. }
  665. void AddVertices(UINT NumVertices)
  666. {
  667. m_pCurrentTLStream->AddVertices(NumVertices);
  668. }
  669. void MovePrimitiveBase(int NumVertices)
  670. {
  671. m_pCurrentTLStream->MovePrimitiveBase(NumVertices);
  672. }
  673. void SkipVertices(DWORD NumVertices)
  674. {
  675. m_pCurrentTLStream->SkipVertices(NumVertices);
  676. }
  677. // Returns offset in bytes of the start vertex of the current primitive in
  678. // the current TL stream
  679. DWORD GetCurrentPrimBase()
  680. {
  681. return m_pCurrentTLStream->GetPrimitiveBase();
  682. }
  683. void ResetVertexShader()
  684. {
  685. m_CurrentVertexShader = 0;
  686. #if DBG
  687. m_VertexSizeFromShader = 0;
  688. #endif
  689. }
  690. PFN_DRAWPRIMFAST __declspec(nothrow) GetDrawPrimFunction() {return CD3DDDIDX8_DrawPrimitive;}
  691. PFN_DRAWINDEXEDPRIMFAST __declspec(nothrow) GetDrawIndexedPrimFunction()
  692. {
  693. return CD3DDDIDX8_DrawIndexedPrimitive;
  694. }
  695. protected:
  696. void StartPointSprites();
  697. void EndPointSprites();
  698. void StartIndexPrimVB(CVIndexStream* pStream, UINT StartIndex, UINT IndexSize);
  699. void UpdateDirtyStreams();
  700. void InsertStreamSource(CVStream*);
  701. void InsertStreamSourceUP(DWORD);
  702. void InsertIndices(CVIndexStream*);
  703. #if DBG
  704. void ValidateCommand(LPD3DHAL_DP2COMMAND lpCmd);
  705. #endif
  706. // This array is used to keep track of what stream is set to a DDI stream.
  707. // __NUMSTREAMS element is used for the indexed DDI stream
  708. CDDIStream m_pDDIStream[__NUMSTREAMS+1];
  709. // Stream for TL vertices, which are the result of the front-end pipeline
  710. CTLStream* m_pTLStream;
  711. // Stream for TL vertices, which are the result of the front-end pipeline
  712. // This is write-only stream
  713. CTLStream* m_pTLStreamW;
  714. // Stream for TL vertices, generated by the clipper. Write-only stream
  715. CTLStream* m_pTLStreamClip;
  716. // Read-only stream. Used with user provided VBs
  717. CTLStreamRO* m_pTLStreamRO;
  718. // Points to the current TL stream. This could be NULL.
  719. CTLStream* m_pCurrentTLStream;
  720. // Points to the current index stream. This could be NULL.
  721. CTLIndexStream* m_pCurrentIndexStream;
  722. // Internal index stream. Used to store indices during clipping
  723. CTLIndexStream* m_pIndexStream;
  724. // Read-only index stream. Used with user provided VBs
  725. CTLIndexStreamRO* m_pTLIndexStreamRO;
  726. // This is a dummy buffer allocated for DP2 call to pass through
  727. // the kernel.
  728. VOID* m_pvDummyArray;
  729. static const DWORD m_dwDummyVertexLength;
  730. static const DWORD m_dwDummyVertexSize;
  731. friend void CD3DDDIDX8_DrawPrimitive(CD3DBase* pDevice,
  732. D3DPRIMITIVETYPE PrimitiveType,
  733. UINT StartVertex, UINT PrimitiveCount);
  734. friend void CD3DDDIDX8_DrawIndexedPrimitive(CD3DBase* pDevice,
  735. D3DPRIMITIVETYPE PrimitiveType,
  736. UINT BaseVertexIndex,
  737. UINT MinIndex, UINT NumVertices,
  738. UINT StartIndex, UINT PrimitiveCount);
  739. };
  740. typedef CD3DDDIDX8 *LPD3DDDIDX8;
  741. /////////////////////////////////////////////////////////////////////////////
  742. // //
  743. // CD3DDDIDX8TL //
  744. // //
  745. /////////////////////////////////////////////////////////////////////////////
  746. class CD3DDDIDX8TL : public CD3DDDIDX8
  747. {
  748. public:
  749. CD3DDDIDX8TL();
  750. ~CD3DDDIDX8TL();
  751. void SetTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*);
  752. void MultiplyTransform(D3DTRANSFORMSTATETYPE, CONST D3DMATRIX*);
  753. void SetViewport(CONST D3DVIEWPORT8*);
  754. void SetMaterial(CONST D3DMATERIAL8*);
  755. void SetLight(DWORD dwLightIndex, CONST D3DLIGHT8*);
  756. void LightEnable(DWORD dwLightIndex, BOOL);
  757. void CreateLight(DWORD dwLightIndex);
  758. void SetClipPlane(DWORD dwPlaneIndex, CONST D3DVALUE* pPlaneEquation);
  759. void CreateVertexShader(CONST DWORD* pdwDeclaration,
  760. DWORD dwDeclarationSize,
  761. CONST DWORD* pdwFunction,
  762. DWORD dwFunctionSize,
  763. DWORD dwHandle,
  764. BOOL bLegacyFVF);
  765. void DeleteVertexShader(DWORD dwHandle);
  766. void SetVertexShaderConstant(DWORD dwRegisterAddress,
  767. CONST VOID* lpvConstantData,
  768. DWORD dwConstantCount);
  769. BOOL CanDoTL() {return TRUE;}
  770. BOOL AcceptIndexBuffer() {return TRUE;}
  771. };
  772. typedef CD3DDDIDX8TL *LPD3DDDIDX8TL;
  773. #endif /* _D3DI_H */