Counter Strike : Global Offensive Source Code
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.

1288 lines
52 KiB

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