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.

565 lines
21 KiB

  1. //================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
  2. //
  3. // LibGcm implementation of DX
  4. //
  5. //==================================================================================================
  6. #ifndef DXABSTRACT_H
  7. #define DXABSTRACT_H
  8. #include "tier0/platform.h"
  9. #include "tier0/memalloc.h"
  10. #include "utlvector.h"
  11. #include <cell/gcm.h>
  12. #include <cell/gcm/gcm_method_data.h>
  13. #include <cell/gcm/gcm_methods.h>
  14. #include <sysutil/sysutil_sysparam.h>
  15. #include "gcmconfig.h"
  16. #include "dxabstract_def.h"
  17. #include "gcmtexture.h"
  18. #include "gcmlabels.h"
  19. #define GCM_ALLOW_TIMESTAMPS 1
  20. #ifdef _CERT
  21. #define Debugger() ((void)0)
  22. #else
  23. #define Debugger() DebuggerBreak()
  24. #endif
  25. #define PS3GCM_ARTIFICIAL_TEXTURE_HANDLE_INDEX_BACKBUFFER 0
  26. #define PS3GCM_ARTIFICIAL_TEXTURE_HANDLE_INDEX_DEPTHBUFFER 1
  27. //--------------------------------------------------------------------------------------------------
  28. // Interfaces
  29. //--------------------------------------------------------------------------------------------------
  30. struct IDirect3DResource9 : public IUnknown
  31. {
  32. IDirect3DDevice9 *m_device; // parent device
  33. D3DRESOURCETYPE m_restype;
  34. DWORD SetPriority(DWORD PriorityNew);
  35. };
  36. // for the moment, a "D3D surface" is modeled as a GLM tex, a face, and a mip.
  37. struct IDirect3DSurface9 : public IDirect3DResource9
  38. {
  39. // no Create method, these are filled in by the various create surface methods.
  40. HRESULT LockRect(D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  41. HRESULT UnlockRect();
  42. HRESULT GetDesc(D3DSURFACE_DESC *pDesc);
  43. // only invoke this on depth/stencil surfaces please...
  44. // axed HRESULT ResetDepthStencilSurfaceSize( int Width, int Height );
  45. D3DSURFACE_DESC m_desc; // Layout must be the same as IDirect3DBaseTexture9!
  46. CPs3gcmTexture *m_tex;
  47. int m_face;
  48. int m_mip;
  49. bool m_bOwnsTexture;
  50. ~IDirect3DSurface9() { if ( m_bOwnsTexture && m_tex ) m_tex->Release(); }
  51. };
  52. struct IDirect3DBaseTexture9 : public IDirect3DResource9 // "A Texture.."
  53. {
  54. D3DSURFACE_DESC m_descZero; // desc of top level.
  55. CPs3gcmTexture *m_tex; // this object owns data
  56. D3DRESOURCETYPE GetType();
  57. DWORD GetLevelCount();
  58. HRESULT GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  59. ~IDirect3DBaseTexture9() { if ( m_tex ) m_tex->Release(); }
  60. };
  61. struct IDirect3DTexture9 : public IDirect3DBaseTexture9 // "Texture 2D"
  62. {
  63. //CUtlVector< IDirect3DSurface9* > m_surfs;
  64. IDirect3DSurface9 *m_surfZero; // surf of top level. YUK!!
  65. HRESULT LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
  66. HRESULT UnlockRect(UINT Level);
  67. HRESULT GetSurfaceLevel(UINT Level,IDirect3DSurface9** ppSurfaceLevel);
  68. ~IDirect3DTexture9() { if ( m_surfZero ) m_surfZero->Release(); }
  69. };
  70. struct IDirect3DCubeTexture9 : public IDirect3DBaseTexture9 // "Texture Cube Map"
  71. {
  72. IDirect3DSurface9 *m_surfZero[6]; // surfs of top level. YUK!!
  73. HRESULT GetCubeMapSurface(D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface9** ppCubeMapSurface);
  74. HRESULT GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc);
  75. ~IDirect3DCubeTexture9() { for ( int j = 0; j < 6; ++ j ) if ( m_surfZero[j] ) m_surfZero[j]->Release(); }
  76. };
  77. struct IDirect3DVolumeTexture9 : public IDirect3DBaseTexture9 // "Texture 3D"
  78. {
  79. IDirect3DSurface9 *m_surfZero; // surf of top level. YUK!!
  80. D3DVOLUME_DESC m_volDescZero; // volume desc top level
  81. HRESULT LockBox(UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags);
  82. HRESULT UnlockBox(UINT Level);
  83. HRESULT GetLevelDesc( UINT level, D3DVOLUME_DESC *pDesc );
  84. ~IDirect3DVolumeTexture9() { if ( m_surfZero ) m_surfZero->Release(); }
  85. };
  86. struct IDirect3D9 : public IUnknown
  87. {
  88. public:
  89. UINT GetAdapterCount(); //cheese: returns 1
  90. HRESULT GetDeviceCaps (UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps);
  91. HRESULT GetAdapterIdentifier (UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier);
  92. HRESULT CheckDeviceFormat (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat);
  93. UINT GetAdapterModeCount (UINT Adapter,D3DFORMAT Format);
  94. HRESULT EnumAdapterModes (UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode);
  95. HRESULT CheckDeviceType (UINT Adapter,D3DDEVTYPE DevType,D3DFORMAT AdapterFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed);
  96. HRESULT GetAdapterDisplayMode (UINT Adapter,D3DDISPLAYMODE* pMode);
  97. HRESULT CheckDepthStencilMatch (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat);
  98. HRESULT CheckDeviceMultiSampleType (UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels);
  99. HRESULT CreateDevice (UINT Adapter,D3DDEVTYPE DeviceType,VD3DHWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface);
  100. };
  101. struct IDirect3DSwapChain9 : public IUnknown
  102. {
  103. };
  104. struct IDirect3DQuery9 : public IUnknown
  105. {
  106. public:
  107. D3DQUERYTYPE m_type; // D3DQUERYTYPE_OCCLUSION or D3DQUERYTYPE_EVENT
  108. uint32 m_queryIdx;
  109. enum Flags_t
  110. {
  111. kQueryValueMask = 0x0000FFFF, // Mask for query value index
  112. kQueryFinished = 0x80000000, // Query is completed
  113. kQueryUninitialized = 0xFFFFFFFF, // Query hasn't started
  114. };
  115. struct QueryGlobalStateOcclusion_t
  116. {
  117. enum { kMaxQueries = GCM_REPORT_QUERY_LAST + 1 - GCM_REPORT_QUERY_FIRST, kGcmQueryBase = GCM_REPORT_QUERY_FIRST };
  118. CellGcmReportData volatile *m_Values[kMaxQueries];
  119. uint32 m_queryIdx;
  120. uint32 PrepareForQuery();
  121. };
  122. static QueryGlobalStateOcclusion_t s_GlobalStateOcclusion;
  123. struct QueryGlobalStateFence_t
  124. {
  125. enum { kMaxQueries = GCM_LABEL_QUERY_LAST + 1 - GCM_LABEL_QUERY_FIRST, kGcmLabelBase = GCM_LABEL_QUERY_FIRST };
  126. uint32 volatile *m_Values[kMaxQueries];
  127. uint32 m_queryIdx;
  128. uint32 PrepareForQuery();
  129. };
  130. static QueryGlobalStateFence_t s_GlobalStateFence;
  131. HRESULT Issue(DWORD dwIssueFlags);
  132. HRESULT GetData(void* pData,DWORD dwSize,DWORD dwGetDataFlags);
  133. };
  134. struct IDirect3DGcmBufferBase : public IUnknown
  135. {
  136. public:
  137. CPs3gcmBuffer *m_pBuffer;
  138. HRESULT Lock(UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags);
  139. HRESULT Unlock();
  140. ~IDirect3DGcmBufferBase() { if ( m_pBuffer ) m_pBuffer->Release(); }
  141. };
  142. struct IDirect3DVertexBuffer9 : public IDirect3DGcmBufferBase
  143. {
  144. public:
  145. D3DVERTEXBUFFER_DESC m_vtxDesc; // to satisfy GetDesc
  146. };
  147. struct IDirect3DIndexBuffer9 : public IDirect3DGcmBufferBase
  148. {
  149. public:
  150. D3DINDEXBUFFER_DESC m_idxDesc; // to satisfy GetDesc
  151. HRESULT GetDesc(D3DINDEXBUFFER_DESC *pDesc);
  152. };
  153. struct IDirect3DGcmProgramBase : public IUnknown
  154. {
  155. public:
  156. CgBinaryProgram *m_pProgram;
  157. inline CGprogram GetCgProgram() const { return reinterpret_cast< CGprogram >( m_pProgram ); }
  158. inline void * GetProgramUCode() const { return (((char*)m_pProgram) + m_pProgram->ucode); }
  159. ~IDirect3DGcmProgramBase() { if ( m_pProgram ) free( m_pProgram ); }
  160. };
  161. // define this to find out how many times we reuse the same shader during a frame
  162. //#define DEBUG_GCM_VERTEX_SHADER_USAGE
  163. struct IDirect3DVertexShader9 : public IDirect3DGcmProgramBase
  164. {
  165. public:
  166. VertexShader9Data_t m_data;
  167. //uint32 m_nIoOffsetStart; // the start of subroutine (IO Offset on RSX) that sets this vertex program
  168. ~IDirect3DVertexShader9();
  169. };
  170. struct IDirect3DPixelShader9 : public CAlignedNewDelete< 16, IUnknown >
  171. {
  172. public:
  173. PixelShader9Data_t m_data;
  174. public:
  175. //inline CgBinaryFragmentProgram *GetFragmentProgram() const { return (CgBinaryFragmentProgram *)(((char*)m_pProgram) + m_pProgram->program); }
  176. //void ValidateAssumptions( const char * pShaderName );
  177. IDirect3DPixelShader9( CgBinaryProgram* prog );
  178. ~IDirect3DPixelShader9();
  179. #ifdef _DEBUG
  180. CgBinaryProgram *m_pCgProg;
  181. #endif
  182. };
  183. struct ID3DXMatrixStack : public IUnknown
  184. {
  185. public:
  186. CUtlVector<D3DMATRIX> m_stack;
  187. int m_stackTop; // top of stack is at the highest index, this is that index. push increases, pop decreases.
  188. HRESULT Create( void );
  189. D3DXMATRIX* GetTop();
  190. void Push();
  191. void Pop();
  192. void LoadIdentity();
  193. void LoadMatrix( const D3DXMATRIX *pMat );
  194. void MultMatrix( const D3DXMATRIX *pMat );
  195. void MultMatrixLocal( const D3DXMATRIX *pMat );
  196. HRESULT ScaleLocal(FLOAT x, FLOAT y, FLOAT z);
  197. // Left multiply the current matrix with the computed rotation
  198. // matrix, counterclockwise about the given axis with the given angle.
  199. // (rotation is about the local origin of the object)
  200. HRESULT RotateAxisLocal(CONST D3DXVECTOR3* pV, FLOAT Angle);
  201. // Left multiply the current matrix with the computed translation
  202. // matrix. (transformation is about the local origin of the object)
  203. HRESULT TranslateLocal(FLOAT x, FLOAT y, FLOAT z);
  204. };
  205. typedef ID3DXMatrixStack* LPD3DXMATRIXSTACK;
  206. struct IDirect3DDevice9Params
  207. {
  208. UINT m_adapter;
  209. D3DDEVTYPE m_deviceType;
  210. VD3DHWND m_focusWindow;
  211. DWORD m_behaviorFlags;
  212. D3DPRESENT_PARAMETERS m_presentationParameters;
  213. };
  214. struct D3DIndexDesc
  215. {
  216. IDirect3DIndexBuffer9 *m_idxBuffer;
  217. };
  218. struct IDirect3DDevice9 : public IUnknown
  219. {
  220. // members
  221. IDirect3DDevice9Params m_params; // mirror of the creation inputs
  222. // D3D flavor stuff
  223. IDirect3DSurface9 *m_rtSurfaces[16]; // current color RT (Render Target) surfaces. [0] is initially == m_defaultColorSurface
  224. IDirect3DSurface9 *m_dsSurface; // current Depth Stencil Render Target surface. can be changed!
  225. IDirect3DSurface9 *m_defaultColorSurface; // default color surface.
  226. IDirect3DSurface9 *m_defaultDepthStencilSurface; // queried by GetDepthStencilSurface.
  227. IDirect3DVertexDeclaration9 *m_vertDecl; // Set by SetVertexDeclaration...
  228. //D3DStreamDesc *m_pVertexStreamSources; // Set by SetStreamSource..
  229. D3DIndexDesc m_indices; // Set by SetIndices..
  230. IDirect3DVertexShader9 *m_vertexShader; // Set by SetVertexShader...
  231. IDirect3DPixelShader9 *m_pixelShader; // Set by SetPixelShader...
  232. #ifdef _DEBUG
  233. uint m_nDrawIndexedPrimitives;
  234. #endif
  235. enum AntiAliasingStatusEnum_t
  236. {
  237. AA_STATUS_NORMAL,
  238. AA_STATUS_PREV_FRAME, // drawing into previous frame, aliased
  239. AA_STATUS_DEFERRED // drawing into deferred queue
  240. };
  241. // this is used to draw UI into already-mlaa'd-surface (to avoid AA'ing the UI)
  242. // when this is on, the default surface to draw should be previous flip surface
  243. AntiAliasingStatusEnum_t m_nAntiAliasingStatus;
  244. // is in logical zpass? logical zpass may have wider scope than spuGcm.zPass, because logical zpass does not abort for any reason. It begins and ends with API calls. Used to balance Perf Marker Push/Pop
  245. bool m_isZPass; //
  246. bool m_isDeferredDrawQueueSurfaceSet;
  247. // methods
  248. // Create call invoked from IDirect3D9
  249. HRESULT Create( IDirect3DDevice9Params *params );
  250. //
  251. // Basics
  252. //
  253. HRESULT Reset(D3DPRESENT_PARAMETERS* pPresentationParameters);
  254. HRESULT SetViewport(CONST D3DVIEWPORT9* pViewport);
  255. HRESULT BeginScene();
  256. HRESULT Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
  257. HRESULT EndScene();
  258. HRESULT Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,VD3DHWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
  259. // textures
  260. HRESULT CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,VD3DHANDLE* pSharedHandle);
  261. HRESULT CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,VD3DHANDLE* pSharedHandle);
  262. HRESULT CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,VD3DHANDLE* pSharedHandle);
  263. HRESULT SetTexture(DWORD Stage,IDirect3DBaseTexture9* pTexture);
  264. HRESULT GetTexture(DWORD Stage,IDirect3DBaseTexture9** ppTexture);
  265. // render targets, color and depthstencil, surfaces, blit
  266. HRESULT CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  267. HRESULT SetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget);
  268. HRESULT GetRenderTarget(DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget);
  269. HRESULT CreateOffscreenPlainSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  270. HRESULT CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultisampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,VD3DHANDLE* pSharedHandle);
  271. HRESULT SetDepthStencilSurface(IDirect3DSurface9* pNewZStencil);
  272. HRESULT GetDepthStencilSurface(IDirect3DSurface9** ppZStencilSurface);
  273. HRESULT GetRenderTargetData(IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface); // ? is anyone using this ?
  274. HRESULT GetFrontBufferData(UINT iSwapChain,IDirect3DSurface9* pDestSurface);
  275. HRESULT StretchRect(IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter);
  276. // pixel shaders
  277. HRESULT CreatePixelShader(CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader, const char *pShaderName = NULL, char *debugLabel = NULL);
  278. HRESULT SetPixelShader(IDirect3DPixelShader9* pShader);
  279. HRESULT SetPixelShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  280. HRESULT SetPixelShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  281. HRESULT SetPixelShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  282. // vertex shaders
  283. HRESULT CreateVertexShader(CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader, char *debugLabel = NULL);
  284. HRESULT SetVertexShader(IDirect3DVertexShader9* pShader);
  285. HRESULT SetVertexShaderConstantF(UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount);
  286. HRESULT SetVertexShaderConstantB(UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount);
  287. HRESULT SetVertexShaderConstantI(UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount);
  288. // vertex buffers
  289. HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl);
  290. HRESULT SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl);
  291. HRESULT SetFVF(DWORD FVF); // we might not be using these ?
  292. HRESULT GetFVF(DWORD* pFVF);
  293. HRESULT CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,VD3DHANDLE* pSharedHandle);
  294. HRESULT SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride);
  295. HRESULT SetRawHardwareDataStreams( IDirect3DVertexBuffer9** ppRawHardwareDataStreams );
  296. // index buffers
  297. HRESULT CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,VD3DHANDLE* pSharedHandle);
  298. HRESULT SetIndices(IDirect3DIndexBuffer9* pIndexData);
  299. // State management.
  300. HRESULT SetRenderState(D3DRENDERSTATETYPE State,DWORD Value);
  301. HRESULT SetSamplerState(DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value);
  302. // Draw.
  303. HRESULT ValidateDrawPrimitiveStreams( D3DPRIMITIVETYPE Type, UINT baseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount ); // validate streams
  304. HRESULT DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
  305. void DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void *pVertexStreamZeroData,UINT VertexStreamZeroStride);
  306. HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount);
  307. HRESULT DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
  308. // misc
  309. BOOL ShowCursor(BOOL bShow);
  310. HRESULT ValidateDevice(DWORD* pNumPasses);
  311. HRESULT SetMaterial(CONST D3DMATERIAL9* pMaterial);
  312. HRESULT LightEnable(DWORD Index,BOOL Enable);
  313. HRESULT SetScissorRect(CONST RECT* pRect);
  314. HRESULT CreateQuery(D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery);
  315. HRESULT GetDeviceCaps(D3DCAPS9* pCaps);
  316. HRESULT TestCooperativeLevel();
  317. HRESULT EvictManagedResources();
  318. HRESULT SetLight(DWORD Index,CONST D3DLIGHT9*);
  319. void SetGammaRamp(UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp);
  320. // Talk to JasonM about this one. It's tricky in GL.
  321. HRESULT SetClipPlane(DWORD Index,CONST float* pPlane);
  322. ULONG __stdcall Release();
  323. // Xbox ZPass analogue
  324. void BeginZPass( DWORD Flags );
  325. void SetPredication( DWORD PredicationMask );
  326. HRESULT EndZPass();
  327. // void ReloadZcullMemory( int nStencilRef );
  328. void StartRenderingIntoPreviousFramebuffer();
  329. void AntiAliasingHint( int nHint );
  330. //
  331. //
  332. // **** FIXED FUNCTION STUFF - None of this stuff needs support in GL.
  333. //
  334. //
  335. HRESULT SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
  336. HRESULT SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
  337. #ifdef _PS3
  338. void GetGPUMemoryStats( GPUMemoryStats &stats ) { return ::GetGPUMemoryStats( stats ); }
  339. void FlushVertexCache();
  340. void FlushTextureCache();
  341. // Allocate storage for a texture's bits (if D3DUSAGE_TEXTURE_NOD3DMEMORY was used to defer allocation on creation)
  342. bool AllocateTextureStorage( IDirect3DBaseTexture9 *pTexture );
  343. protected:
  344. // Flushing changes to GL
  345. void SetVertexStreamSource( uint i, IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride );
  346. void Ps3Helper_ResetSurfaceToKnownDefaultState();
  347. void Ps3Helper_UpdateSurface( int idx );
  348. friend void DxDeviceForceUpdateRenderTarget( );
  349. #endif
  350. };
  351. struct ID3DXInclude
  352. {
  353. virtual HRESULT Open(D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) = 0;
  354. virtual HRESULT Close(LPCVOID pData) = 0;
  355. };
  356. typedef ID3DXInclude* LPD3DXINCLUDE;
  357. struct ID3DXBuffer : public IUnknown
  358. {
  359. void* GetBufferPointer();
  360. DWORD GetBufferSize();
  361. };
  362. typedef ID3DXBuffer* LPD3DXBUFFER;
  363. class ID3DXConstantTable : public IUnknown
  364. {
  365. };
  366. typedef ID3DXConstantTable* LPD3DXCONSTANTTABLE;
  367. // ------------------------------------------------------------------------------------------------------------------------------ //
  368. // D3DX stuff.
  369. // ------------------------------------------------------------------------------------------------------------------------------ //
  370. const char* D3DXGetPixelShaderProfile( IDirect3DDevice9 *pDevice );
  371. D3DXMATRIX* D3DXMatrixMultiply( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM1, CONST D3DXMATRIX *pM2 );
  372. D3DXVECTOR3* D3DXVec3TransformCoord( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV, CONST D3DXMATRIX *pM );
  373. HRESULT D3DXCreateMatrixStack( DWORD Flags, LPD3DXMATRIXSTACK* ppStack);
  374. void D3DXMatrixIdentity( D3DXMATRIX * );
  375. D3DXINLINE D3DXVECTOR3* D3DXVec3Subtract( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  376. {
  377. pOut->x = pV1->x - pV2->x;
  378. pOut->y = pV1->y - pV2->y;
  379. pOut->z = pV1->z - pV2->z;
  380. return pOut;
  381. }
  382. D3DXINLINE D3DXVECTOR3* D3DXVec3Cross( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  383. {
  384. D3DXVECTOR3 v;
  385. v.x = pV1->y * pV2->z - pV1->z * pV2->y;
  386. v.y = pV1->z * pV2->x - pV1->x * pV2->z;
  387. v.z = pV1->x * pV2->y - pV1->y * pV2->x;
  388. *pOut = v;
  389. return pOut;
  390. }
  391. D3DXINLINE FLOAT D3DXVec3Dot( CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
  392. {
  393. return pV1->x * pV2->x + pV1->y * pV2->y + pV1->z * pV2->z;
  394. }
  395. D3DXMATRIX* D3DXMatrixInverse( D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM );
  396. D3DXMATRIX* D3DXMatrixTranspose( D3DXMATRIX *pOut, CONST D3DXMATRIX *pM );
  397. D3DXPLANE* D3DXPlaneNormalize( D3DXPLANE *pOut, CONST D3DXPLANE *pP);
  398. D3DXVECTOR4* D3DXVec4Transform( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV, CONST D3DXMATRIX *pM );
  399. D3DXVECTOR4* D3DXVec4Normalize( D3DXVECTOR4 *pOut, CONST D3DXVECTOR4 *pV );
  400. D3DXMATRIX* D3DXMatrixTranslation( D3DXMATRIX *pOut, FLOAT x, FLOAT y, FLOAT z );
  401. // Build an ortho projection matrix. (right-handed)
  402. D3DXMATRIX* D3DXMatrixOrthoOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn,FLOAT zf );
  403. D3DXMATRIX* D3DXMatrixPerspectiveRH( D3DXMATRIX *pOut, FLOAT w, FLOAT h, FLOAT zn, FLOAT zf );
  404. D3DXMATRIX* D3DXMatrixPerspectiveOffCenterRH( D3DXMATRIX *pOut, FLOAT l, FLOAT r, FLOAT b, FLOAT t, FLOAT zn, FLOAT zf );
  405. // Transform a plane by a matrix. The vector (a,b,c) must be normal.
  406. // M should be the inverse transpose of the transformation desired.
  407. D3DXPLANE* D3DXPlaneTransform( D3DXPLANE *pOut, CONST D3DXPLANE *pP, CONST D3DXMATRIX *pM );
  408. IDirect3D9 *Direct3DCreate9(UINT SDKVersion);
  409. void D3DPERF_SetOptions( DWORD dwOptions );
  410. HRESULT D3DXCompileShader(
  411. LPCSTR pSrcData,
  412. UINT SrcDataLen,
  413. CONST D3DXMACRO* pDefines,
  414. LPD3DXINCLUDE pInclude,
  415. LPCSTR pFunctionName,
  416. LPCSTR pProfile,
  417. DWORD Flags,
  418. LPD3DXBUFFER* ppShader,
  419. LPD3DXBUFFER* ppErrorMsgs,
  420. LPD3DXCONSTANTTABLE* ppConstantTable);
  421. // fake D3D usage constant for SRGB tex creation
  422. #define D3DUSAGE_TEXTURE_SRGB (0x80000000L)
  423. // fake D3D usage constant for deferred tex bits allocation
  424. #define D3DUSAGE_TEXTURE_NOD3DMEMORY (0x40000000L)
  425. extern bool g_bDxMicroProfile;
  426. #endif // DXABSTRACT_H