Team Fortress 2 Source Code as on 22/4/2020
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.

1289 lines
52 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. /*
  3. TODO: add option to null out drawprim calls.
  4. Also maybe hook the PIX_ENABLE stuff to Telemetry
  5. In imaterialsystem.h:
  6. #define PIX_ENABLE 1 // set this to 1 and build engine/studiorender to enable pix events in the engine
  7. And in shaderapidx8.h:
  8. #define PIX_ENABLE 1 // set this to 1 and build engine/studiorender to enable pix events in the engine
  9. Might be interesting to make it so dx9hook.h paid attention to the PIX_ENABLE names
  10. and allowed you to filter drawprim calls based on those?
  11. */
  12. #ifndef _DX9HOOK_H_
  13. #define _DX9HOOK_H_
  14. #if D3D_BATCH_PERF_ANALYSIS
  15. #include "../../thirdparty/miniz/miniz.c"
  16. #include "../../thirdparty/miniz/simple_bitmap.h"
  17. extern ConVar d3d_batch_vis, d3d_batch_vis_abs_scale, d3d_batch_vis_y_scale, d3d_present_vis_abs_scale;
  18. extern uint64 g_nTotalD3DCalls, g_nTotalD3DCycles;
  19. class CD3DCallTimer
  20. {
  21. public:
  22. inline CD3DCallTimer() { g_nTotalD3DCalls++; g_nTotalD3DCycles -= tmFastTime(); }
  23. inline ~CD3DCallTimer() { g_nTotalD3DCycles += tmFastTime(); }
  24. };
  25. #define D3D_BATCH_PERF(...) __VA_ARGS__
  26. #else
  27. #define D3D_BATCH_PERF(...)
  28. #endif
  29. #if D3D_BATCH_PERF_ANALYSIS
  30. #define XXX \
  31. tmZone( TELEMETRY_LEVEL3, TMZF_NONE, "D3D9: %s", __FUNCTION__ ); \
  32. CD3DCallTimer scopedCallTimer;
  33. #else
  34. #define XXX \
  35. if( ThreadInMainThread() ) \
  36. { \
  37. tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE | TMMF_SEVERITY_WARNING, "(source/d3d)%s", __FUNCTION__ ); \
  38. tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ ); \
  39. }
  40. #endif
  41. // Hooks for routines which return values.
  42. #define _DOCALL0( _member ) ( m_Data.pHWObj->_member )()
  43. #define _DOCALL( _member, ... ) ( m_Data.pHWObj->_member )( __VA_ARGS__ )
  44. // And hooks for routines which return squatola.
  45. #define _DOCALL0_NORET( _member ) ( m_Data.pHWObj->_member )()
  46. #define _DOCALL_NORET( _member, ... ) ( m_Data.pHWObj->_member )( __VA_ARGS__)
  47. #define DEF_HOOKCLASSES( X ) \
  48. template<> class CDx9HookBase< struct I ## X > \
  49. { \
  50. public: \
  51. typedef I ## X _D3DINTERFACE; \
  52. typedef class C ## X ## Hook _HOOKCLASS; \
  53. \
  54. public: \
  55. CDx9HookBase() { memset( &m_Data, 0, sizeof( m_Data ) ); } \
  56. virtual ~CDx9HookBase() {} \
  57. \
  58. public: \
  59. struct DATA \
  60. { \
  61. class CDirect3DDevice9Hook *pDevice; \
  62. _D3DINTERFACE *pHWObj; \
  63. }; \
  64. \
  65. DATA m_Data; \
  66. }
  67. template < class T > class CDx9HookBase;
  68. DEF_HOOKCLASSES( Direct3DVertexDeclaration9 );
  69. DEF_HOOKCLASSES( Direct3DPixelShader9 );
  70. DEF_HOOKCLASSES( Direct3DVertexShader9 );
  71. DEF_HOOKCLASSES( Direct3DVertexBuffer9 );
  72. DEF_HOOKCLASSES( Direct3DIndexBuffer9 );
  73. DEF_HOOKCLASSES( Direct3DQuery9 );
  74. DEF_HOOKCLASSES( Direct3DStateBlock9 );
  75. DEF_HOOKCLASSES( Direct3DSurface9 );
  76. DEF_HOOKCLASSES( Direct3DBaseTexture9 );
  77. DEF_HOOKCLASSES( Direct3DTexture9 );
  78. DEF_HOOKCLASSES( Direct3DCubeTexture9 );
  79. DEF_HOOKCLASSES( Direct3DVolume9 );
  80. DEF_HOOKCLASSES( Direct3DVolumeTexture9 );
  81. DEF_HOOKCLASSES( Direct3DSwapChain9 );
  82. DEF_HOOKCLASSES( Direct3D9 );
  83. DEF_HOOKCLASSES( Direct3DDevice9 );
  84. template < class _D3DINTERFACE > HRESULT AllocOverride( HRESULT *hr, class CDirect3DDevice9Hook *pDevice, _D3DINTERFACE **ppHWObj )
  85. {
  86. if( SUCCEEDED(*hr) && ppHWObj && *ppHWObj )
  87. {
  88. CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = new CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS;
  89. if(!pClass)
  90. {
  91. ( *ppHWObj )->Release();
  92. *hr = E_OUTOFMEMORY;
  93. return NULL;
  94. }
  95. pClass->m_Data.pDevice = pDevice;
  96. pClass->m_Data.pHWObj = *ppHWObj;
  97. *ppHWObj = pClass;
  98. return *hr;
  99. }
  100. return *hr;
  101. }
  102. template <class _D3DINTERFACE> _D3DINTERFACE *GetHWPtr( _D3DINTERFACE *pD3DInterface )
  103. {
  104. if( pD3DInterface )
  105. {
  106. CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = ( CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS * )pD3DInterface;
  107. return pClass->m_Data.pHWObj;
  108. }
  109. return NULL;
  110. }
  111. template <class _D3DINTERFACE> CDirect3DDevice9Hook *GetHookDevice( _D3DINTERFACE *pD3DInterface )
  112. {
  113. if( pD3DInterface )
  114. {
  115. CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = ( CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS * )pD3DInterface;
  116. return pClass->m_Data.pDevice;
  117. }
  118. return NULL;
  119. }
  120. //$ TODO: if(riid == IID_IDirect3DDevice9Ex, IID_IDirect3DDevice9, etc.
  121. #define IMPL_QUERYINTERFACE() \
  122. STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) \
  123. { \
  124. __debugbreak(); \
  125. XXX; return _DOCALL(QueryInterface, riid, ppvObj); \
  126. }
  127. #define IMPL_IUNKOWN() \
  128. IMPL_QUERYINTERFACE(); \
  129. STDMETHOD_(ULONG,AddRef)(THIS) \
  130. { XXX; return _DOCALL0(AddRef); } \
  131. STDMETHOD_(ULONG,Release)(THIS) \
  132. { \
  133. XXX; \
  134. ULONG retval = _DOCALL0(Release); \
  135. if(retval == 0) \
  136. delete this; \
  137. return retval; \
  138. }
  139. #define IMPL_GETDEVICE() \
  140. STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice) \
  141. { \
  142. XXX; \
  143. HRESULT hr = _DOCALL( GetDevice, ppDevice ); \
  144. return AllocOverride( &hr, m_Data.pDevice, ppDevice ); \
  145. }
  146. #define IMPL_SETPRIVATEDATA() \
  147. STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) \
  148. { XXX; return _DOCALL(SetPrivateData, refguid, pData, SizeOfData, Flags); }
  149. #define IMPL_GETPRIVATEDATA() \
  150. STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid,void* pData,DWORD* pSizeOfData) \
  151. { XXX; return _DOCALL(GetPrivateData, refguid, pData, pSizeOfData); }
  152. #define IMPL_FREEPRIVATEDATA() \
  153. STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid) \
  154. { XXX; return _DOCALL(FreePrivateData, refguid); }
  155. #define IMPL_IDIRECT3DRESOURCE9() \
  156. IMPL_GETDEVICE(); \
  157. IMPL_SETPRIVATEDATA(); \
  158. IMPL_GETPRIVATEDATA(); \
  159. IMPL_FREEPRIVATEDATA(); \
  160. STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew) \
  161. { XXX; return _DOCALL(SetPriority, PriorityNew); } \
  162. STDMETHOD_(DWORD, GetPriority)(THIS) \
  163. { XXX; return _DOCALL0(GetPriority); } \
  164. STDMETHOD_(void, PreLoad)(THIS) \
  165. { XXX; _DOCALL0_NORET(PreLoad); } \
  166. STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS) \
  167. { XXX; return _DOCALL0(GetType); }
  168. class CDirect3DSwapChain9Hook : public CDx9HookBase<IDirect3DSwapChain9>, public IDirect3DSwapChain9
  169. {
  170. public:
  171. /*** IUnknown methods ***/
  172. IMPL_IUNKOWN();
  173. /*** IDirect3DSwapChain9 methods ***/
  174. STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags)
  175. { XXX; return _DOCALL(Present, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); }
  176. STDMETHOD(GetFrontBufferData)(THIS_ IDirect3DSurface9* pDestSurface)
  177. {
  178. XXX; return _DOCALL(GetFrontBufferData, GetHWPtr(pDestSurface));
  179. }
  180. STDMETHOD(GetBackBuffer)(THIS_ UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer)
  181. {
  182. XXX;
  183. HRESULT hr = _DOCALL(GetBackBuffer, iBackBuffer, Type, ppBackBuffer);
  184. return AllocOverride( &hr, m_Data.pDevice, ppBackBuffer );
  185. }
  186. STDMETHOD(GetRasterStatus)(THIS_ D3DRASTER_STATUS* pRasterStatus)
  187. { XXX; return _DOCALL(GetRasterStatus, pRasterStatus); }
  188. STDMETHOD(GetDisplayMode)(THIS_ D3DDISPLAYMODE* pMode)
  189. { XXX; return _DOCALL(GetDisplayMode, pMode); }
  190. IMPL_GETDEVICE();
  191. STDMETHOD(GetPresentParameters)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters)
  192. { XXX; return _DOCALL(GetPresentParameters, pPresentationParameters); }
  193. };
  194. class CDirect3DVertexDeclaration9Hook : public CDx9HookBase<IDirect3DVertexDeclaration9>, public IDirect3DVertexDeclaration9
  195. {
  196. public:
  197. /*** IUnknown methods ***/
  198. IMPL_IUNKOWN();
  199. // IDirect3DVertexDeclaration9 methods
  200. IMPL_GETDEVICE();
  201. STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 *pVertElem, UINT* pNumElements)
  202. { XXX; return _DOCALL(GetDeclaration, pVertElem, pNumElements); }
  203. };
  204. class CDirect3DPixelShader9Hook : public CDx9HookBase<IDirect3DPixelShader9>, public IDirect3DPixelShader9
  205. {
  206. public:
  207. /*** IUnknown methods ***/
  208. IMPL_IUNKOWN();
  209. // IDirect3DPixelShader9 methods
  210. IMPL_GETDEVICE();
  211. STDMETHOD(GetFunction)(THIS_ void *pData,UINT* pSizeOfData)
  212. { XXX; return _DOCALL(GetFunction, pData, pSizeOfData); }
  213. };
  214. class CDirect3DVertexShader9Hook : public CDx9HookBase<IDirect3DVertexShader9>, public IDirect3DVertexShader9
  215. {
  216. public:
  217. /*** IUnknown methods ***/
  218. IMPL_IUNKOWN();
  219. // IDirect3DVertexDeclaration9 methods
  220. IMPL_GETDEVICE();
  221. STDMETHOD(GetFunction)(THIS_ void *pData,UINT* pSizeOfData)
  222. { XXX; return _DOCALL(GetFunction, pData, pSizeOfData); }
  223. };
  224. class CDirect3DVertexBuffer9Hook : public CDx9HookBase<IDirect3DVertexBuffer9>, public IDirect3DVertexBuffer9
  225. {
  226. public:
  227. /*** IUnknown methods ***/
  228. IMPL_IUNKOWN();
  229. // IDirect3DResource9 methods
  230. IMPL_IDIRECT3DRESOURCE9();
  231. // IDirect3DVertexBuffer9
  232. STDMETHOD(Lock)(THIS_ UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags)
  233. { XXX; return _DOCALL(Lock, OffsetToLock, SizeToLock, ppbData, Flags); }
  234. STDMETHOD(Unlock)(THIS)
  235. { XXX; return _DOCALL0(Unlock); }
  236. STDMETHOD(GetDesc)(THIS_ D3DVERTEXBUFFER_DESC *pDesc)
  237. { XXX; return _DOCALL(GetDesc, pDesc); }
  238. };
  239. class CDirect3DIndexBuffer9Hook : public CDx9HookBase<IDirect3DIndexBuffer9>, public IDirect3DIndexBuffer9
  240. {
  241. public:
  242. /*** IUnknown methods ***/
  243. IMPL_IUNKOWN();
  244. // IDirect3DResource9 methods
  245. IMPL_IDIRECT3DRESOURCE9();
  246. // IDirect3DIndexBuffer9
  247. STDMETHOD(Lock)(THIS_ UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags)
  248. { XXX; return _DOCALL(Lock, OffsetToLock, SizeToLock, ppbData, Flags); }
  249. STDMETHOD(Unlock)(THIS)
  250. { XXX; return _DOCALL0(Unlock); }
  251. STDMETHOD(GetDesc)(THIS_ D3DINDEXBUFFER_DESC *pDesc)
  252. { XXX; return _DOCALL(GetDesc, pDesc); }
  253. };
  254. class CDirect3DQuery9Hook : public CDx9HookBase<IDirect3DQuery9>, public IDirect3DQuery9
  255. {
  256. public:
  257. /*** IUnknown methods ***/
  258. IMPL_IUNKOWN();
  259. /*** IDirect3DQuery9 methods ***/
  260. IMPL_GETDEVICE();
  261. // IDirect3DQuery9
  262. STDMETHOD_(D3DQUERYTYPE, GetType)(THIS)
  263. { XXX; return _DOCALL0(GetType); }
  264. STDMETHOD_(DWORD, GetDataSize)(THIS)
  265. { XXX; return _DOCALL0(GetDataSize); }
  266. STDMETHOD(Issue)(THIS_ DWORD dwIssueFlags)
  267. { XXX; return _DOCALL(Issue, dwIssueFlags); }
  268. STDMETHOD(GetData)(THIS_ void* pData,DWORD dwSize,DWORD dwGetDataFlags)
  269. { XXX; return _DOCALL(GetData, pData, dwSize, dwGetDataFlags); }
  270. };
  271. class CDirect3DStateBlock9Hook : public CDx9HookBase<IDirect3DStateBlock9>, public IDirect3DStateBlock9
  272. {
  273. public:
  274. CDirect3DStateBlock9Hook() {}
  275. virtual ~CDirect3DStateBlock9Hook() {}
  276. /*** IUnknown methods ***/
  277. IMPL_IUNKOWN();
  278. // IDirect3DStateBlock9 methods
  279. IMPL_GETDEVICE();
  280. STDMETHOD(Capture)(THIS)
  281. { XXX; return _DOCALL0(Capture); }
  282. STDMETHOD(Apply)(THIS)
  283. { XXX; return _DOCALL0(Apply); }
  284. };
  285. class CDirect3DSurface9Hook : public CDx9HookBase<IDirect3DSurface9>, public IDirect3DSurface9
  286. {
  287. public:
  288. /*** IUnknown methods ***/
  289. IMPL_IUNKOWN();
  290. // IDirect3DResource9 methods
  291. IMPL_IDIRECT3DRESOURCE9();
  292. STDMETHOD(GetContainer)(THIS_ REFIID riid,void** ppContainer)
  293. {
  294. //$ TODO: do the call, check riid, and wrap the returned ppContainer
  295. __debugbreak();
  296. XXX; return _DOCALL(GetContainer, riid, ppContainer);
  297. }
  298. STDMETHOD(GetDesc)(THIS_ D3DSURFACE_DESC *pDesc)
  299. { XXX; return _DOCALL(GetDesc, pDesc); }
  300. STDMETHOD(LockRect)(THIS_ D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
  301. { XXX; return _DOCALL(LockRect, pLockedRect, pRect, Flags); }
  302. STDMETHOD(UnlockRect)(THIS)
  303. { XXX; return _DOCALL0(UnlockRect); }
  304. STDMETHOD(GetDC)(THIS_ HDC *phdc)
  305. { XXX; return _DOCALL(GetDC, phdc); }
  306. STDMETHOD(ReleaseDC)(THIS_ HDC hdc)
  307. { XXX; return _DOCALL(ReleaseDC, hdc); }
  308. };
  309. class CDirect3DBaseTexture9Hook : public CDx9HookBase<IDirect3DBaseTexture9>, public IDirect3DBaseTexture9
  310. {
  311. public:
  312. /*** IUnknown methods ***/
  313. IMPL_IUNKOWN();
  314. /*** IDirect3DBaseTexture9 methods ***/
  315. IMPL_IDIRECT3DRESOURCE9();
  316. STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew)
  317. { XXX; return _DOCALL(SetLOD, LODNew); }
  318. STDMETHOD_(DWORD, GetLOD)(THIS)
  319. { XXX; return _DOCALL0(GetLOD); }
  320. STDMETHOD_(DWORD, GetLevelCount)(THIS)
  321. { XXX; return _DOCALL0(GetLevelCount); }
  322. STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType)
  323. { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); }
  324. STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS)
  325. { XXX; return _DOCALL0(GetAutoGenFilterType); }
  326. STDMETHOD_(void, GenerateMipSubLevels)(THIS)
  327. { XXX; return _DOCALL0(GenerateMipSubLevels); }
  328. };
  329. class CDirect3DTexture9Hook : public CDx9HookBase<IDirect3DTexture9>, public IDirect3DTexture9
  330. {
  331. public:
  332. /*** IUnknown methods ***/
  333. IMPL_IUNKOWN();
  334. /*** IDirect3DBaseTexture9 methods ***/
  335. IMPL_IDIRECT3DRESOURCE9();
  336. STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew)
  337. { XXX; return _DOCALL(SetLOD, LODNew); }
  338. STDMETHOD_(DWORD, GetLOD)(THIS)
  339. { XXX; return _DOCALL0(GetLOD); }
  340. STDMETHOD_(DWORD, GetLevelCount)(THIS)
  341. { XXX; return _DOCALL0(GetLevelCount); }
  342. STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType)
  343. { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); }
  344. STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS)
  345. { XXX; return _DOCALL0(GetAutoGenFilterType); }
  346. STDMETHOD_(void, GenerateMipSubLevels)(THIS)
  347. { XXX; return _DOCALL0(GenerateMipSubLevels); }
  348. STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc)
  349. { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); }
  350. STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level,IDirect3DSurface9** ppSurfaceLevel)
  351. {
  352. XXX;
  353. HRESULT hr = _DOCALL(GetSurfaceLevel, Level, ppSurfaceLevel);
  354. return AllocOverride( &hr, m_Data.pDevice, ppSurfaceLevel );
  355. }
  356. STDMETHOD(LockRect)(THIS_ UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
  357. { XXX; return _DOCALL(LockRect, Level, pLockedRect, pRect, Flags); }
  358. STDMETHOD(UnlockRect)(THIS_ UINT Level)
  359. { XXX; return _DOCALL(UnlockRect, Level); }
  360. STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect)
  361. { XXX; return _DOCALL(AddDirtyRect, pDirtyRect); }
  362. };
  363. class CDirect3DCubeTexture9Hook : public CDx9HookBase<IDirect3DCubeTexture9>, public IDirect3DCubeTexture9
  364. {
  365. public:
  366. /*** IUnknown methods ***/
  367. IMPL_IUNKOWN();
  368. /*** IDirect3DBaseTexture9 methods ***/
  369. IMPL_IDIRECT3DRESOURCE9();
  370. STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew)
  371. { XXX; return _DOCALL(SetLOD, LODNew); }
  372. STDMETHOD_(DWORD, GetLOD)(THIS)
  373. { XXX; return _DOCALL0(GetLOD); }
  374. STDMETHOD_(DWORD, GetLevelCount)(THIS)
  375. { XXX; return _DOCALL0(GetLevelCount); }
  376. STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType)
  377. { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); }
  378. STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS)
  379. { XXX; return _DOCALL0(GetAutoGenFilterType); }
  380. STDMETHOD_(void, GenerateMipSubLevels)(THIS)
  381. { XXX; return _DOCALL0(GenerateMipSubLevels); }
  382. STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc)
  383. { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); }
  384. STDMETHOD(GetCubeMapSurface)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface9** ppCubeMapSurface)
  385. {
  386. XXX;
  387. HRESULT hr = _DOCALL(GetCubeMapSurface, FaceType, Level, ppCubeMapSurface);
  388. return AllocOverride(&hr, m_Data.pDevice, ppCubeMapSurface);
  389. }
  390. STDMETHOD(LockRect)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
  391. { XXX; return _DOCALL(LockRect, FaceType, Level, pLockedRect, pRect, Flags); }
  392. STDMETHOD(UnlockRect)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level)
  393. { XXX; return _DOCALL(UnlockRect, FaceType, Level); }
  394. STDMETHOD(AddDirtyRect)(THIS_ D3DCUBEMAP_FACES FaceType,CONST RECT* pDirtyRect)
  395. { XXX; return _DOCALL(AddDirtyRect, FaceType, pDirtyRect); }
  396. };
  397. class CDirect3DVolume9Hook : public CDx9HookBase<IDirect3DVolume9>, public IDirect3DVolume9
  398. {
  399. public:
  400. /*** IUnknown methods ***/
  401. IMPL_IUNKOWN();
  402. /*** IDirect3DVolume9 methods ***/
  403. IMPL_GETDEVICE();
  404. IMPL_SETPRIVATEDATA();
  405. IMPL_GETPRIVATEDATA();
  406. IMPL_FREEPRIVATEDATA()
  407. STDMETHOD(GetContainer)(THIS_ REFIID riid,void** ppContainer)
  408. {
  409. //$ TODO: do the call, check riid, and wrap the returned ppContainer
  410. __debugbreak();
  411. XXX; return _DOCALL(GetContainer, riid, ppContainer);
  412. }
  413. STDMETHOD(GetDesc)(THIS_ D3DVOLUME_DESC *pDesc)
  414. { XXX; return _DOCALL(GetDesc, pDesc); }
  415. STDMETHOD(LockBox)(THIS_ D3DLOCKED_BOX * pLockedVolume,CONST D3DBOX* pBox,DWORD Flags)
  416. { XXX; return _DOCALL(LockBox, pLockedVolume, pBox, Flags); }
  417. STDMETHOD(UnlockBox)(THIS)
  418. { XXX; return _DOCALL0(UnlockBox); }
  419. };
  420. class CDirect3DVolumeTexture9Hook : public CDx9HookBase<IDirect3DVolumeTexture9>, public IDirect3DVolumeTexture9
  421. {
  422. public:
  423. /*** IUnknown methods ***/
  424. IMPL_IUNKOWN();
  425. /*** IDirect3DBaseTexture9 methods ***/
  426. IMPL_IDIRECT3DRESOURCE9();
  427. STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew)
  428. { XXX; return _DOCALL(SetLOD, LODNew); }
  429. STDMETHOD_(DWORD, GetLOD)(THIS)
  430. { XXX; return _DOCALL0(GetLOD); }
  431. STDMETHOD_(DWORD, GetLevelCount)(THIS)
  432. { XXX; return _DOCALL0(GetLevelCount); }
  433. STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType)
  434. { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); }
  435. STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS)
  436. { XXX; return _DOCALL0(GetAutoGenFilterType); }
  437. STDMETHOD_(void, GenerateMipSubLevels)(THIS)
  438. { XXX; return _DOCALL0(GenerateMipSubLevels); }
  439. STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DVOLUME_DESC *pDesc)
  440. { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); }
  441. STDMETHOD(GetVolumeLevel)(THIS_ UINT Level,IDirect3DVolume9** ppVolumeLevel)
  442. {
  443. XXX;
  444. HRESULT hr = _DOCALL(GetVolumeLevel, Level, ppVolumeLevel);
  445. return AllocOverride( &hr, m_Data.pDevice, ppVolumeLevel );
  446. }
  447. STDMETHOD(LockBox)(THIS_ UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags)
  448. { XXX; return _DOCALL(LockBox, Level, pLockedVolume, pBox, Flags); }
  449. STDMETHOD(UnlockBox)(THIS_ UINT Level)
  450. { XXX; return _DOCALL(UnlockBox, Level); }
  451. STDMETHOD(AddDirtyBox)(THIS_ CONST D3DBOX* pDirtyBox)
  452. { XXX; return _DOCALL(AddDirtyBox, pDirtyBox); }
  453. };
  454. class CDirect3DDevice9Hook : public CDx9HookBase<IDirect3DDevice9>, public IDirect3DDevice9
  455. {
  456. public:
  457. /*** IUnknown methods ***/
  458. IMPL_IUNKOWN();
  459. CDirect3DDevice9Hook() : CDx9HookBase<IDirect3DDevice9>(), IDirect3DDevice9()
  460. {
  461. D3D_BATCH_PERF( g_nTotalD3DCycles = 0; g_nTotalD3DCalls = 0; m_batch_state.Clear(); m_nTotalDraws = 0; m_nTotalPrims = 0; m_nTotalD3DCalls = 0; m_flTotalD3DTime = 0; m_nOverallDraws = 0; m_nOverallPrims = 0; m_nOverallD3DCalls = 0; m_flOverallD3DTime = 0; m_nTotalFrames = 0; m_pPrevRenderTarget0 = NULL; )
  462. }
  463. // IDirect3DDevice9 methods
  464. STDMETHOD(TestCooperativeLevel)(THIS)
  465. { XXX; return _DOCALL0(TestCooperativeLevel); }
  466. STDMETHOD_(UINT, GetAvailableTextureMem)(THIS)
  467. { XXX; return _DOCALL0(GetAvailableTextureMem); }
  468. STDMETHOD(EvictManagedResources)(THIS)
  469. { XXX; return _DOCALL0(EvictManagedResources); }
  470. STDMETHOD(GetDirect3D)(THIS_ IDirect3D9** ppD3D9)
  471. {
  472. XXX;
  473. HRESULT hr = _DOCALL(GetDirect3D, ppD3D9);
  474. return AllocOverride(&hr, this, ppD3D9);
  475. }
  476. STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS9* pCaps)
  477. { XXX; return _DOCALL(GetDeviceCaps, pCaps); }
  478. STDMETHOD(GetDisplayMode)(THIS_ UINT iSwapChain,D3DDISPLAYMODE* pMode)
  479. { XXX; return _DOCALL(GetDisplayMode, iSwapChain, pMode); }
  480. STDMETHOD(GetCreationParameters)(THIS_ D3DDEVICE_CREATION_PARAMETERS *pParameters)
  481. { XXX; return _DOCALL(GetCreationParameters, pParameters); }
  482. STDMETHOD(SetCursorProperties)(THIS_ UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap)
  483. { XXX; return _DOCALL(SetCursorProperties, XHotSpot, YHotSpot, GetHWPtr(pCursorBitmap)); }
  484. STDMETHOD_(void, SetCursorPosition)(THIS_ int X,int Y,DWORD Flags)
  485. { XXX; _DOCALL_NORET(SetCursorPosition, X, Y, Flags); }
  486. STDMETHOD_(BOOL, ShowCursor)(THIS_ BOOL bShow)
  487. { XXX; return _DOCALL(ShowCursor, bShow); }
  488. STDMETHOD(CreateAdditionalSwapChain)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** ppSwapChain)
  489. {
  490. XXX;
  491. HRESULT hr = _DOCALL(CreateAdditionalSwapChain, pPresentationParameters, ppSwapChain);
  492. return AllocOverride(&hr, this, ppSwapChain);
  493. }
  494. STDMETHOD(GetSwapChain)(THIS_ UINT iSwapChain,IDirect3DSwapChain9** ppSwapChain)
  495. {
  496. XXX;
  497. HRESULT hr = _DOCALL(GetSwapChain, iSwapChain, ppSwapChain);
  498. return AllocOverride(&hr, this, ppSwapChain);
  499. }
  500. STDMETHOD_(UINT, GetNumberOfSwapChains)(THIS)
  501. { XXX; return _DOCALL0(GetNumberOfSwapChains); }
  502. STDMETHOD(Reset)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters)
  503. { XXX; return _DOCALL( Reset, pPresentationParameters ); }
  504. STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion)
  505. {
  506. HRESULT hres;
  507. #if D3D_BATCH_PERF_ANALYSIS
  508. uint64 nStartCycles = g_nTotalD3DCycles;
  509. CFastTimer tm;
  510. tm.Start();
  511. g_nTotalD3DCalls++;
  512. #endif
  513. {
  514. XXX;
  515. hres = _DOCALL(Present, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
  516. }
  517. #if D3D_BATCH_PERF_ANALYSIS
  518. const uint nFrameIndex = m_nTotalFrames;
  519. m_nTotalFrames++;
  520. if (nFrameIndex >= 5)
  521. {
  522. double flPresentTime = tm.GetDurationInProgress().GetMillisecondsF();
  523. uint64 nEndCycles = g_nTotalD3DCycles;
  524. double flTotalPresentTime = ( nEndCycles - nStartCycles ) * s_rdtsc_to_ms;
  525. m_nTotalD3DCalls += g_nTotalD3DCalls;
  526. m_flTotalD3DTime += g_nTotalD3DCycles * s_rdtsc_to_ms;
  527. static int bPrevBatchVis = -1;
  528. if ((bPrevBatchVis == 1) && m_batch_vis_bitmap.is_valid())
  529. {
  530. m_nOverallDraws += m_nTotalDraws;
  531. m_nOverallPrims += m_nTotalPrims;
  532. m_nOverallD3DCalls += m_nTotalD3DCalls;
  533. m_flOverallD3DTime += m_flTotalD3DTime;
  534. m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, (uint)(.5f + flPresentTime / d3d_present_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), 10, 255, 16, 128);
  535. m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, (uint)(.5f + flTotalPresentTime / d3d_present_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), 10, 0, 255, 128);
  536. m_nBatchVisY += 10;
  537. uint y = MAX( 600, m_nBatchVisY + 20 ), l = 0;
  538. m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Frame: %u, Batches: %u, Prims: %u", nFrameIndex, m_nTotalDraws, m_nTotalPrims );
  539. m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Frame: D3D Calls: %u, D3D Time: %3.3fms", m_nTotalD3DCalls, m_flTotalD3DTime);
  540. l++;
  541. m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Overall: Batches: %u, Prims: %u", m_nOverallDraws, m_nOverallPrims );
  542. m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Overall: D3D Calls: %u D3D Time: %4.3fms", m_nOverallD3DCalls, m_flOverallD3DTime );
  543. size_t png_size = 0;
  544. void *pPNG_data = tdefl_write_image_to_png_file_in_memory(m_batch_vis_bitmap.get_ptr(), m_batch_vis_bitmap.width(), m_batch_vis_bitmap.height(), 3, &png_size, true);
  545. if (pPNG_data)
  546. {
  547. char filename[256];
  548. V_snprintf(filename, sizeof(filename), "left4dead2/batchvis_%u_%u.png", m_nBatchVisFileIdx, m_nBatchVisFrameIndex);
  549. FILE* pFile = fopen(filename, "wb");
  550. if (pFile)
  551. {
  552. fwrite(pPNG_data, png_size, 1, pFile);
  553. fclose(pFile);
  554. }
  555. free(pPNG_data);
  556. }
  557. m_nBatchVisFrameIndex++;
  558. m_nBatchVisY = 0;
  559. m_batch_vis_bitmap.cls();
  560. }
  561. if (bPrevBatchVis != (int)d3d_batch_vis.GetBool())
  562. {
  563. bPrevBatchVis = d3d_batch_vis.GetBool();
  564. if (!bPrevBatchVis)
  565. {
  566. m_batch_vis_bitmap.clear();
  567. }
  568. else
  569. {
  570. m_batch_vis_bitmap.init(768, 1024);
  571. }
  572. m_nBatchVisY = 0;
  573. m_nBatchVisFrameIndex = 0;
  574. m_nBatchVisFileIdx = (uint)time(NULL); //rand();
  575. m_nOverallDraws = 0;
  576. m_nOverallPrims = 0;
  577. m_nOverallD3DCalls = 0;
  578. m_flOverallD3DTime = 0;
  579. }
  580. }
  581. m_nTotalD3DCalls = 0;
  582. m_nTotalPrims = 0;
  583. m_flTotalD3DTime = 0;
  584. g_nTotalD3DCycles = 0;
  585. g_nTotalD3DCalls = 0;
  586. m_nTotalDraws = 0;
  587. #else
  588. if ( d3d_batch_vis.GetBool() )
  589. {
  590. d3d_batch_vis.SetValue( false );
  591. ConMsg( "Must define D3D_BATCH_PERF_ANALYSIS to use this feature" );
  592. }
  593. #endif
  594. return hres;
  595. }
  596. STDMETHOD(GetBackBuffer)(THIS_ UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer)
  597. {
  598. XXX;
  599. HRESULT hr = _DOCALL(GetBackBuffer, iSwapChain, iBackBuffer, Type, ppBackBuffer);
  600. return AllocOverride(&hr, this, ppBackBuffer);
  601. }
  602. STDMETHOD(GetRasterStatus)(THIS_ UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus)
  603. { XXX; return _DOCALL(GetRasterStatus, iSwapChain, pRasterStatus); }
  604. STDMETHOD(SetDialogBoxMode)(THIS_ BOOL bEnableDialogs)
  605. { XXX; return _DOCALL(SetDialogBoxMode, bEnableDialogs); }
  606. STDMETHOD_(void, SetGammaRamp)(THIS_ UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp)
  607. { XXX; _DOCALL_NORET(SetGammaRamp, iSwapChain, Flags, pRamp); }
  608. STDMETHOD_(void, GetGammaRamp)(THIS_ UINT iSwapChain,D3DGAMMARAMP* pRamp)
  609. { XXX; _DOCALL_NORET(GetGammaRamp, iSwapChain, pRamp); }
  610. STDMETHOD(CreateTexture)(THIS_ UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle)
  611. {
  612. XXX;
  613. HRESULT hr = _DOCALL(CreateTexture, Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle);
  614. return AllocOverride(&hr, this, ppTexture);
  615. }
  616. STDMETHOD(CreateVolumeTexture)(THIS_ UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle)
  617. {
  618. XXX;
  619. HRESULT hr = _DOCALL(CreateVolumeTexture, Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
  620. return AllocOverride(&hr, this, ppVolumeTexture);
  621. }
  622. STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle)
  623. {
  624. XXX;
  625. HRESULT hr = _DOCALL(CreateCubeTexture, EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
  626. return AllocOverride(&hr, this, ppCubeTexture);
  627. }
  628. STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle)
  629. {
  630. XXX;
  631. HRESULT hr = _DOCALL(CreateVertexBuffer, Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle);
  632. return AllocOverride(&hr, this, ppVertexBuffer);
  633. }
  634. STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle)
  635. {
  636. XXX;
  637. HRESULT hr = _DOCALL(CreateIndexBuffer, Length, Usage, Format, Pool, ppIndexBuffer, pSharedHandle);
  638. return AllocOverride(&hr, this, ppIndexBuffer);
  639. }
  640. STDMETHOD(CreateRenderTarget)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultiSampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
  641. {
  642. XXX;
  643. HRESULT hr = _DOCALL(CreateRenderTarget, Width, Height, Format, MultiSample, MultiSampleQuality, Lockable, ppSurface, pSharedHandle);
  644. return AllocOverride(&hr, this, ppSurface);
  645. }
  646. STDMETHOD(CreateDepthStencilSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultiSampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
  647. {
  648. XXX;
  649. HRESULT hr = _DOCALL(CreateDepthStencilSurface, Width, Height, Format, MultiSample, MultiSampleQuality, Discard, ppSurface, pSharedHandle);
  650. return AllocOverride(&hr, this, ppSurface);
  651. }
  652. STDMETHOD(UpdateSurface)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint)
  653. { XXX; return _DOCALL(UpdateSurface, GetHWPtr(pSourceSurface), pSourceRect, GetHWPtr(pDestinationSurface), pDestPoint); }
  654. STDMETHOD(UpdateTexture)(THIS_ IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture)
  655. { XXX; return _DOCALL(UpdateTexture, GetHWPtr(pSourceTexture), GetHWPtr(pDestinationTexture)); }
  656. STDMETHOD(GetRenderTargetData)(THIS_ IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface)
  657. { XXX; return _DOCALL(GetRenderTargetData, GetHWPtr(pRenderTarget), GetHWPtr(pDestSurface)); }
  658. STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain,IDirect3DSurface9* pDestSurface)
  659. { XXX; return _DOCALL(GetFrontBufferData, iSwapChain, GetHWPtr(pDestSurface)); }
  660. STDMETHOD(StretchRect)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter)
  661. { XXX; return _DOCALL(StretchRect, GetHWPtr(pSourceSurface), pSourceRect, GetHWPtr(pDestSurface), pDestRect, Filter); }
  662. STDMETHOD(ColorFill)(THIS_ IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color)
  663. { XXX; return _DOCALL(ColorFill, GetHWPtr(pSurface), pRect, color); }
  664. STDMETHOD(CreateOffscreenPlainSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle)
  665. {
  666. XXX;
  667. HRESULT hr = _DOCALL(CreateOffscreenPlainSurface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
  668. return AllocOverride(&hr, this, ppSurface);
  669. }
  670. STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget)
  671. {
  672. HRESULT hres;
  673. {
  674. XXX;
  675. hres = _DOCALL(SetRenderTarget, RenderTargetIndex, GetHWPtr(pRenderTarget));
  676. }
  677. #if D3D_BATCH_PERF_ANALYSIS
  678. if ( m_batch_vis_bitmap.is_valid() && !RenderTargetIndex )
  679. {
  680. if ( pRenderTarget != m_pPrevRenderTarget0 )
  681. {
  682. m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, m_batch_vis_bitmap.width(), 1, 30, 20, 20);
  683. m_nBatchVisY += 1;
  684. }
  685. }
  686. if ( !RenderTargetIndex )
  687. {
  688. m_pPrevRenderTarget0 = pRenderTarget;
  689. }
  690. #endif
  691. return hres;
  692. }
  693. STDMETHOD(GetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget)
  694. {
  695. XXX;
  696. HRESULT hr = _DOCALL(GetRenderTarget, RenderTargetIndex, ppRenderTarget);
  697. return AllocOverride(&hr, this, ppRenderTarget);
  698. }
  699. STDMETHOD(SetDepthStencilSurface)(THIS_ IDirect3DSurface9* pNewZStencil)
  700. { XXX; return _DOCALL(SetDepthStencilSurface, GetHWPtr(pNewZStencil)); }
  701. STDMETHOD(GetDepthStencilSurface)(THIS_ IDirect3DSurface9** ppZStencilSurface)
  702. {
  703. XXX;
  704. HRESULT hr = _DOCALL(GetDepthStencilSurface, ppZStencilSurface);
  705. return AllocOverride(&hr, this, ppZStencilSurface);
  706. }
  707. STDMETHOD(BeginScene)(THIS)
  708. { XXX; return _DOCALL0(BeginScene); }
  709. STDMETHOD(EndScene)(THIS)
  710. { XXX; return _DOCALL0(EndScene); }
  711. STDMETHOD(Clear)(THIS_ DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil)
  712. { XXX; return _DOCALL(Clear, Count, pRects, Flags, Color, Z, Stencil); }
  713. STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix)
  714. { XXX; return _DOCALL(SetTransform, State, pMatrix); }
  715. STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix)
  716. { XXX; return _DOCALL(GetTransform, State, pMatrix); }
  717. STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX *pMatrix)
  718. { XXX; return _DOCALL(MultiplyTransform, State, pMatrix); }
  719. STDMETHOD(SetViewport)(THIS_ CONST D3DVIEWPORT9* pViewport)
  720. { XXX; return _DOCALL(SetViewport, pViewport); }
  721. STDMETHOD(GetViewport)(THIS_ D3DVIEWPORT9* pViewport)
  722. { XXX; return _DOCALL(GetViewport, pViewport); }
  723. STDMETHOD(SetMaterial)(THIS_ CONST D3DMATERIAL9* pMaterial)
  724. { XXX; return _DOCALL(SetMaterial, pMaterial); }
  725. STDMETHOD(GetMaterial)(THIS_ D3DMATERIAL9* pMaterial)
  726. { XXX; return _DOCALL(GetMaterial, pMaterial); }
  727. STDMETHOD(SetLight)(THIS_ DWORD Index,CONST D3DLIGHT9* pLight)
  728. { XXX; return _DOCALL(SetLight, Index, pLight); }
  729. STDMETHOD(GetLight)(THIS_ DWORD Index,D3DLIGHT9* pLight)
  730. { XXX; return _DOCALL(GetLight, Index, pLight); }
  731. STDMETHOD(LightEnable)(THIS_ DWORD Index,BOOL Enable)
  732. { XXX; return _DOCALL(LightEnable, Index, Enable); }
  733. STDMETHOD(GetLightEnable)(THIS_ DWORD Index,BOOL* pEnable)
  734. { XXX; return _DOCALL(GetLightEnable, Index, pEnable); }
  735. STDMETHOD(SetClipPlane)(THIS_ DWORD Index,CONST float* pPlane)
  736. { XXX; return _DOCALL(SetClipPlane, Index, pPlane);}
  737. STDMETHOD(GetClipPlane)(THIS_ DWORD Index,float* pPlane)
  738. { XXX; return _DOCALL(GetClipPlane, Index, pPlane); }
  739. STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD Value)
  740. { XXX; return _DOCALL(SetRenderState, State, Value); }
  741. STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD* pValue)
  742. { XXX; return _DOCALL(GetRenderState, State, pValue); }
  743. STDMETHOD(CreateStateBlock)(THIS_ D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB)
  744. {
  745. XXX;
  746. HRESULT hr = _DOCALL(CreateStateBlock, Type, ppSB);
  747. return AllocOverride(&hr, this, ppSB);
  748. }
  749. STDMETHOD(BeginStateBlock)(THIS)
  750. { XXX; return _DOCALL0(BeginStateBlock); }
  751. STDMETHOD(EndStateBlock)(THIS_ IDirect3DStateBlock9** ppSB)
  752. {
  753. XXX;
  754. HRESULT hr = _DOCALL(EndStateBlock, ppSB);
  755. return AllocOverride(&hr, this, ppSB);
  756. }
  757. STDMETHOD(SetClipStatus)(THIS_ CONST D3DCLIPSTATUS9* pClipStatus)
  758. { XXX; return _DOCALL(SetClipStatus, pClipStatus);}
  759. STDMETHOD(GetClipStatus)(THIS_ D3DCLIPSTATUS9* pClipStatus)
  760. { XXX; return _DOCALL(GetClipStatus, pClipStatus);}
  761. STDMETHOD(GetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9** ppTexture)
  762. {
  763. XXX;
  764. HRESULT hr = _DOCALL(GetTexture, Stage, ppTexture);
  765. return AllocOverride(&hr, this, ppTexture);
  766. }
  767. STDMETHOD(SetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9* pTexture)
  768. {
  769. HRESULT hres;
  770. {
  771. XXX;
  772. hres = _DOCALL(SetTexture, Stage, GetHWPtr(pTexture));
  773. }
  774. D3D_BATCH_PERF( m_batch_state.m_nNumSamplersChanged++; )
  775. return hres;
  776. }
  777. STDMETHOD(GetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue)
  778. { XXX; return _DOCALL(GetTextureStageState, Stage, Type, pValue); }
  779. STDMETHOD(SetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value)
  780. { XXX; return _DOCALL(SetTextureStageState, Stage, Type, Value); }
  781. STDMETHOD(GetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue)
  782. { XXX; return _DOCALL(GetSamplerState, Sampler, Type, pValue); }
  783. STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value)
  784. {
  785. HRESULT hres;
  786. {
  787. XXX;
  788. hres = _DOCALL(SetSamplerState, Sampler, Type, Value);
  789. }
  790. D3D_BATCH_PERF( m_batch_state.m_nNumSamplerStatesChanged++; )
  791. return hres;
  792. }
  793. STDMETHOD(ValidateDevice)(THIS_ DWORD* pNumPasses)
  794. { XXX; return _DOCALL(ValidateDevice, pNumPasses); }
  795. STDMETHOD(SetPaletteEntries)(THIS_ UINT PaletteNumber,CONST PALETTEENTRY* pEntries)
  796. { XXX; return _DOCALL(SetPaletteEntries, PaletteNumber, pEntries); }
  797. STDMETHOD(GetPaletteEntries)(THIS_ UINT PaletteNumber,PALETTEENTRY* pEntries)
  798. { XXX; return _DOCALL(GetPaletteEntries, PaletteNumber, pEntries); }
  799. STDMETHOD(SetCurrentTexturePalette)(THIS_ UINT PaletteNumber)
  800. { XXX; return _DOCALL(SetCurrentTexturePalette, PaletteNumber);}
  801. STDMETHOD(GetCurrentTexturePalette)(THIS_ UINT *PaletteNumber)
  802. { XXX; return _DOCALL(GetCurrentTexturePalette, PaletteNumber); }
  803. STDMETHOD(SetScissorRect)(THIS_ CONST RECT* pRect)
  804. { XXX; return _DOCALL(SetScissorRect, pRect); }
  805. STDMETHOD(GetScissorRect)(THIS_ RECT* pRect)
  806. { XXX; return _DOCALL(GetScissorRect, pRect); }
  807. STDMETHOD(SetSoftwareVertexProcessing)(THIS_ BOOL bSoftware)
  808. { XXX; return _DOCALL(SetSoftwareVertexProcessing, bSoftware); }
  809. STDMETHOD_(BOOL, GetSoftwareVertexProcessing)(THIS)
  810. { XXX; return _DOCALL0(GetSoftwareVertexProcessing); }
  811. STDMETHOD(SetNPatchMode)(THIS_ float nSegments)
  812. { XXX; return _DOCALL(SetNPatchMode, nSegments); }
  813. STDMETHOD_(float, GetNPatchMode)(THIS)
  814. { XXX; return _DOCALL0(GetNPatchMode);}
  815. STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount)
  816. { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawPrimitive, PrimitiveType, StartVertex, PrimitiveCount); }
  817. STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount)
  818. {
  819. m_nTotalDraws++;
  820. m_nTotalPrims += primCount;
  821. #if D3D_BATCH_PERF_ANALYSIS
  822. CFastTimer tm;
  823. if ( m_batch_vis_bitmap.is_valid() )
  824. {
  825. tm.Start();
  826. }
  827. #endif
  828. HRESULT hres;
  829. {
  830. XXX;
  831. hres = _DOCALL(DrawIndexedPrimitive, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount);
  832. }
  833. #if D3D_BATCH_PERF_ANALYSIS
  834. if ( m_batch_vis_bitmap.is_valid() )
  835. {
  836. double t = tm.GetDurationInProgress().GetMillisecondsF();
  837. uint h = 1;
  838. if ( d3d_batch_vis_y_scale.GetFloat() > 0.0f)
  839. {
  840. h = ceil( t / d3d_batch_vis_y_scale.GetFloat() );
  841. h = MAX(h, 1);
  842. }
  843. m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, (uint)(.5f + t / d3d_batch_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), h, 64, 64, 64);
  844. if ( s_rdtsc_to_ms == 0.0f )
  845. {
  846. TmU64 t0 = tmFastTime();
  847. double d0 = Plat_FloatTime();
  848. ThreadSleep( 1 );
  849. TmU64 t1 = tmFastTime();
  850. double d1 = Plat_FloatTime();
  851. s_rdtsc_to_ms = ( 1000.0f * ( d1 - d0 ) ) / ( t1 - t0 );
  852. }
  853. double flTotalD3DCallMS = g_nTotalD3DCycles * s_rdtsc_to_ms;
  854. m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, (uint)(.5f + flTotalD3DCallMS / d3d_batch_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), h, 96, 96, 128);
  855. if (m_batch_state.m_bVertexShaderChanged) m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, 8, h, 0, 0, 64);
  856. if (m_batch_state.m_bPixelShaderChanged) m_batch_vis_bitmap.additive_fill_box(32, m_nBatchVisY, 8, h, 64, 0, 64);
  857. int lm = 80;
  858. m_batch_vis_bitmap.fill_box(lm+0+0, m_nBatchVisY, m_batch_state.m_nNumVSConstants, h, 64, 255, 255);
  859. m_batch_vis_bitmap.fill_box(lm+64+256+0, m_nBatchVisY, m_batch_state.m_nNumPSConstants, h, 64, 64, 255);
  860. m_batch_vis_bitmap.fill_box(lm+64+256+32, m_nBatchVisY, m_batch_state.m_nNumSamplersChanged, h, 255, 255, 255);
  861. m_batch_vis_bitmap.fill_box(lm+64+256+32+16, m_nBatchVisY, m_batch_state.m_nNumSamplerStatesChanged, h, 92, 128, 255);
  862. if ( m_batch_state.m_bStreamSourceChanged) m_batch_vis_bitmap.fill_box(lm+64+256+32+16+64, m_nBatchVisY, 16, h, 128, 128, 128);
  863. if ( m_batch_state.m_bIndicesChanged ) m_batch_vis_bitmap.fill_box(lm+64+256+32+16+64+16, m_nBatchVisY, 16, h, 128, 128, 255);
  864. m_nBatchVisY += h;
  865. m_nTotalD3DCalls += g_nTotalD3DCalls;
  866. m_flTotalD3DTime += flTotalD3DCallMS;
  867. g_nTotalD3DCycles = 0;
  868. g_nTotalD3DCalls = 0;
  869. m_batch_state.Clear();
  870. }
  871. #endif
  872. return hres;
  873. }
  874. STDMETHOD(DrawPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
  875. { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawPrimitiveUP, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); }
  876. STDMETHOD(DrawIndexedPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride)
  877. { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawIndexedPrimitiveUP, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); }
  878. STDMETHOD(ProcessVertices)(THIS_ UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags)
  879. { XXX; return _DOCALL(ProcessVertices, SrcStartIndex, DestIndex, VertexCount, GetHWPtr(pDestBuffer), GetHWPtr(pVertexDecl), Flags); }
  880. STDMETHOD(CreateVertexDeclaration)(THIS_ CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl)
  881. {
  882. XXX;
  883. HRESULT hr = _DOCALL(CreateVertexDeclaration, pVertexElements, ppDecl);
  884. return AllocOverride(&hr, this, ppDecl);
  885. }
  886. STDMETHOD(SetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9* pDecl)
  887. { XXX; return _DOCALL(SetVertexDeclaration, GetHWPtr(pDecl)); }
  888. STDMETHOD(GetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9** ppDecl)
  889. {
  890. XXX;
  891. HRESULT hr = _DOCALL(GetVertexDeclaration, ppDecl);
  892. return AllocOverride(&hr, this, ppDecl);
  893. }
  894. STDMETHOD(SetFVF)(THIS_ DWORD FVF)
  895. { XXX; return _DOCALL(SetFVF, FVF); }
  896. STDMETHOD(GetFVF)(THIS_ DWORD* pFVF)
  897. { XXX; return _DOCALL(GetFVF, pFVF); }
  898. STDMETHOD(CreateVertexShader)(THIS_ CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader)
  899. {
  900. XXX;
  901. HRESULT hr = _DOCALL(CreateVertexShader, pFunction, ppShader);
  902. return AllocOverride(&hr, this, ppShader);
  903. }
  904. STDMETHOD(SetVertexShader)(THIS_ IDirect3DVertexShader9* pShader)
  905. {
  906. HRESULT hres;
  907. {
  908. XXX;
  909. hres = _DOCALL(SetVertexShader, GetHWPtr(pShader));
  910. }
  911. D3D_BATCH_PERF( m_batch_state.m_bVertexShaderChanged = true; )
  912. return hres;
  913. }
  914. STDMETHOD(GetVertexShader)(THIS_ IDirect3DVertexShader9** ppShader)
  915. {
  916. XXX;
  917. HRESULT hr = _DOCALL(GetVertexShader, ppShader);
  918. return AllocOverride(&hr, this, ppShader);
  919. }
  920. STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount)
  921. {
  922. HRESULT hres;
  923. {
  924. XXX;
  925. hres = _DOCALL(SetVertexShaderConstantF, StartRegister, pConstantData, Vector4fCount);
  926. }
  927. D3D_BATCH_PERF( m_batch_state.m_nNumVSConstants += Vector4fCount; )
  928. return hres;
  929. }
  930. STDMETHOD(GetVertexShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount)
  931. { XXX; return _DOCALL(GetVertexShaderConstantF, StartRegister, pConstantData, Vector4fCount);}
  932. STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount)
  933. { XXX; return _DOCALL(SetVertexShaderConstantI, StartRegister, pConstantData, Vector4iCount); }
  934. STDMETHOD(GetVertexShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount)
  935. { XXX; return _DOCALL(GetVertexShaderConstantI, StartRegister, pConstantData, Vector4iCount); }
  936. STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount)
  937. { XXX; return _DOCALL(SetVertexShaderConstantB, StartRegister, pConstantData, BoolCount); }
  938. STDMETHOD(GetVertexShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount)
  939. { XXX; return _DOCALL(GetVertexShaderConstantB, StartRegister, pConstantData, BoolCount); }
  940. STDMETHOD(SetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride)
  941. {
  942. HRESULT hres;
  943. {
  944. XXX;
  945. hres = _DOCALL(SetStreamSource, StreamNumber, GetHWPtr(pStreamData), OffsetInBytes, Stride);
  946. }
  947. D3D_BATCH_PERF( m_batch_state.m_bStreamSourceChanged = true; )
  948. return hres;
  949. }
  950. STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride)
  951. {
  952. XXX;
  953. HRESULT hr = _DOCALL(GetStreamSource, StreamNumber, ppStreamData, OffsetInBytes, pStride);
  954. return AllocOverride(&hr, this, ppStreamData);
  955. }
  956. STDMETHOD(SetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT Divider)
  957. { XXX; return _DOCALL(SetStreamSourceFreq, StreamNumber, Divider); }
  958. STDMETHOD(GetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT* Divider)
  959. { XXX; return _DOCALL(GetStreamSourceFreq, StreamNumber, Divider); }
  960. STDMETHOD(SetIndices)(THIS_ IDirect3DIndexBuffer9* pIndexData)
  961. {
  962. HRESULT hres;
  963. {
  964. XXX;
  965. hres = _DOCALL(SetIndices, GetHWPtr(pIndexData));
  966. }
  967. D3D_BATCH_PERF( m_batch_state.m_bIndicesChanged = true; )
  968. return hres;
  969. }
  970. STDMETHOD(GetIndices)(THIS_ IDirect3DIndexBuffer9** ppIndexData)
  971. {
  972. XXX;
  973. HRESULT hr = _DOCALL(GetIndices, ppIndexData);
  974. return AllocOverride(&hr, this, ppIndexData);
  975. }
  976. STDMETHOD(CreatePixelShader)(THIS_ CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader)
  977. {
  978. XXX;
  979. HRESULT hr = _DOCALL(CreatePixelShader, pFunction, ppShader);
  980. return AllocOverride(&hr, this, ppShader);
  981. }
  982. STDMETHOD(SetPixelShader)(THIS_ IDirect3DPixelShader9* pShader)
  983. {
  984. HRESULT hres;
  985. {
  986. XXX;
  987. hres = _DOCALL(SetPixelShader, GetHWPtr(pShader));
  988. }
  989. D3D_BATCH_PERF( m_batch_state.m_bPixelShaderChanged = true; )
  990. return hres;
  991. }
  992. STDMETHOD(GetPixelShader)(THIS_ IDirect3DPixelShader9** ppShader)
  993. {
  994. XXX;
  995. HRESULT hr = _DOCALL(GetPixelShader, ppShader);
  996. return AllocOverride(&hr, this, ppShader);
  997. }
  998. STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount)
  999. {
  1000. HRESULT hres;
  1001. {
  1002. XXX;
  1003. hres = _DOCALL(SetPixelShaderConstantF, StartRegister, pConstantData, Vector4fCount);
  1004. }
  1005. D3D_BATCH_PERF( m_batch_state.m_nNumPSConstants += Vector4fCount; )
  1006. return hres;
  1007. }
  1008. STDMETHOD(GetPixelShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount)
  1009. { XXX; return _DOCALL(GetPixelShaderConstantF, StartRegister, pConstantData, Vector4fCount); }
  1010. STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount)
  1011. { XXX; return _DOCALL(SetPixelShaderConstantI, StartRegister, pConstantData, Vector4iCount); }
  1012. STDMETHOD(GetPixelShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount)
  1013. { XXX; return _DOCALL(GetPixelShaderConstantI, StartRegister, pConstantData, Vector4iCount); }
  1014. STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount)
  1015. { XXX; return _DOCALL(SetPixelShaderConstantB, StartRegister, pConstantData, BoolCount); }
  1016. STDMETHOD(GetPixelShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount)
  1017. { XXX; return _DOCALL(GetPixelShaderConstantB, StartRegister, pConstantData, BoolCount); }
  1018. STDMETHOD(DrawRectPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo)
  1019. { XXX; return _DOCALL(DrawRectPatch, Handle, pNumSegs, pRectPatchInfo);}
  1020. STDMETHOD(DrawTriPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo)
  1021. { XXX; return _DOCALL(DrawTriPatch, Handle, pNumSegs, pTriPatchInfo); }
  1022. STDMETHOD(DeletePatch)(THIS_ UINT Handle)
  1023. { XXX; return _DOCALL(DeletePatch, Handle);}
  1024. STDMETHOD(CreateQuery)(THIS_ D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery)
  1025. {
  1026. XXX;
  1027. HRESULT hr = _DOCALL(CreateQuery, Type, ppQuery);
  1028. return AllocOverride(&hr, this, ppQuery);
  1029. }
  1030. private:
  1031. #if D3D_BATCH_PERF_ANALYSIS
  1032. IDirect3DSurface9* m_pPrevRenderTarget0;
  1033. simple_bitmap m_batch_vis_bitmap;
  1034. uint m_nBatchVisY;
  1035. uint m_nBatchVisFrameIndex, m_nBatchVisFileIdx;
  1036. struct BatchState_t
  1037. {
  1038. void Clear() { memset(this, 0, sizeof(*this)); }
  1039. bool m_bStreamSourceChanged;
  1040. bool m_bIndicesChanged;
  1041. bool m_bPixelShaderChanged;
  1042. bool m_bVertexShaderChanged;
  1043. uint m_nNumPSConstants;
  1044. uint m_nNumVSConstants;
  1045. uint m_nNumSamplersChanged;
  1046. uint m_nNumSamplerStatesChanged;
  1047. };
  1048. BatchState_t m_batch_state;
  1049. uint m_nTotalFrames;
  1050. uint m_nTotalDraws;
  1051. uint m_nTotalPrims;
  1052. uint m_nTotalD3DCalls;
  1053. double m_flTotalD3DTime;
  1054. uint m_nOverallDraws;
  1055. uint m_nOverallPrims;
  1056. uint m_nOverallD3DCalls;
  1057. double m_flOverallD3DTime;
  1058. #endif
  1059. };
  1060. class CDirect3D9Hook : public CDx9HookBase<IDirect3D9>, public IDirect3D9
  1061. {
  1062. public:
  1063. /*** IUnknown methods ***/
  1064. IMPL_IUNKOWN();
  1065. // IDirect3D9 methods
  1066. STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction)
  1067. { XXX; return _DOCALL(RegisterSoftwareDevice, pInitializeFunction); }
  1068. STDMETHOD_(UINT, GetAdapterCount)(THIS)
  1069. { XXX; return _DOCALL0(GetAdapterCount); }
  1070. STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier)
  1071. { XXX; return _DOCALL(GetAdapterIdentifier, Adapter, Flags, pIdentifier);}
  1072. STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter,D3DFORMAT Format)
  1073. { XXX; return _DOCALL(GetAdapterModeCount, Adapter, Format);}
  1074. STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode)
  1075. { XXX; return _DOCALL(EnumAdapterModes, Adapter, Format, Mode, pMode); }
  1076. STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode)
  1077. { XXX; return _DOCALL(GetAdapterDisplayMode, Adapter, pMode); }
  1078. STDMETHOD(CheckDeviceType)(THIS_ UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed)
  1079. { XXX; return _DOCALL(CheckDeviceType, iAdapter, DevType, DisplayFormat, BackBufferFormat, bWindowed); }
  1080. STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat)
  1081. { XXX; return _DOCALL(CheckDeviceFormat, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); }
  1082. STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels)
  1083. { XXX; return _DOCALL(CheckDeviceMultiSampleType, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); }
  1084. STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat)
  1085. { XXX; return _DOCALL(CheckDepthStencilMatch, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); }
  1086. STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat)
  1087. { XXX; return _DOCALL(CheckDeviceFormatConversion, Adapter, DeviceType, SourceFormat, TargetFormat); }
  1088. STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps)
  1089. { XXX; return _DOCALL(GetDeviceCaps, Adapter, DeviceType, pCaps); }
  1090. STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter)
  1091. { XXX; return _DOCALL(GetAdapterMonitor, Adapter); }
  1092. STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface)
  1093. {
  1094. XXX;
  1095. HRESULT hr = _DOCALL(CreateDevice, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
  1096. if( SUCCEEDED( hr ) && ppReturnedDeviceInterface && *ppReturnedDeviceInterface )
  1097. {
  1098. CDirect3DDevice9Hook *pDevice = new CDirect3DDevice9Hook;
  1099. if(!pDevice)
  1100. {
  1101. ( *ppReturnedDeviceInterface )->Release();
  1102. hr = E_OUTOFMEMORY;
  1103. return NULL;
  1104. }
  1105. pDevice->m_Data.pDevice = pDevice;
  1106. pDevice->m_Data.pHWObj = *ppReturnedDeviceInterface;
  1107. *ppReturnedDeviceInterface = pDevice;
  1108. }
  1109. return hr;
  1110. }
  1111. };
  1112. inline IDirect3D9 *Direct3DCreate9Hook( UINT SDKVersion )
  1113. {
  1114. HRESULT hr = S_OK;
  1115. IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION );
  1116. AllocOverride( &hr, NULL, &pD3D );
  1117. return pD3D;
  1118. }
  1119. #endif // _DX9HOOK_H_