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.

409 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. //
  5. // File: D3DX11GPGPU.h
  6. // Content: D3DX11 General Purpose GPU computing algorithms
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #include "d3dx11.h"
  10. #ifndef __D3DX11GPGPU_H__
  11. #define __D3DX11GPGPU_H__
  12. // Current name of the DLL shipped in the same SDK as this header.
  13. #define D3DCSX_DLL_W L"d3dcsx_43.dll"
  14. #define D3DCSX_DLL_A "d3dcsx_43.dll"
  15. #ifdef UNICODE
  16. #define D3DCSX_DLL D3DCSX_DLL_W
  17. #else
  18. #define D3DCSX_DLL D3DCSX_DLL_A
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif //__cplusplus
  23. //////////////////////////////////////////////////////////////////////////////
  24. typedef enum D3DX11_SCAN_DATA_TYPE
  25. {
  26. D3DX11_SCAN_DATA_TYPE_FLOAT = 1,
  27. D3DX11_SCAN_DATA_TYPE_INT,
  28. D3DX11_SCAN_DATA_TYPE_UINT,
  29. } D3DX11_SCAN_DATA_TYPE;
  30. typedef enum D3DX11_SCAN_OPCODE
  31. {
  32. D3DX11_SCAN_OPCODE_ADD = 1,
  33. D3DX11_SCAN_OPCODE_MIN,
  34. D3DX11_SCAN_OPCODE_MAX,
  35. D3DX11_SCAN_OPCODE_MUL,
  36. D3DX11_SCAN_OPCODE_AND,
  37. D3DX11_SCAN_OPCODE_OR,
  38. D3DX11_SCAN_OPCODE_XOR,
  39. } D3DX11_SCAN_OPCODE;
  40. typedef enum D3DX11_SCAN_DIRECTION
  41. {
  42. D3DX11_SCAN_DIRECTION_FORWARD = 1,
  43. D3DX11_SCAN_DIRECTION_BACKWARD,
  44. } D3DX11_SCAN_DIRECTION;
  45. //////////////////////////////////////////////////////////////////////////////
  46. // ID3DX11Scan:
  47. //////////////////////////////////////////////////////////////////////////////
  48. // {5089b68f-e71d-4d38-be8e-f363b95a9405}
  49. DEFINE_GUID(IID_ID3DX11Scan, 0x5089b68f, 0xe71d, 0x4d38, 0xbe, 0x8e, 0xf3, 0x63, 0xb9, 0x5a, 0x94, 0x05);
  50. #undef INTERFACE
  51. #define INTERFACE ID3DX11Scan
  52. DECLARE_INTERFACE_(ID3DX11Scan, IUnknown)
  53. {
  54. // IUnknown
  55. STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  56. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  57. STDMETHOD_(ULONG, Release)(THIS) PURE;
  58. // ID3DX11Scan
  59. STDMETHOD(SetScanDirection)(THIS_ D3DX11_SCAN_DIRECTION Direction) PURE;
  60. //=============================================================================
  61. // Performs an unsegmented scan of a sequence in-place or out-of-place
  62. // ElementType element type
  63. // OpCode binary operation
  64. // Direction scan direction
  65. // ElementScanSize size of scan, in elements
  66. // pSrc input sequence on the device. pSrc==pDst for in-place scans
  67. // pDst output sequence on the device
  68. //=============================================================================
  69. STDMETHOD(Scan)( THIS_
  70. D3DX11_SCAN_DATA_TYPE ElementType,
  71. D3DX11_SCAN_OPCODE OpCode,
  72. UINT ElementScanSize,
  73. __in ID3D11UnorderedAccessView* pSrc,
  74. __in ID3D11UnorderedAccessView* pDst
  75. ) PURE;
  76. //=============================================================================
  77. // Performs a multiscan of a sequence in-place or out-of-place
  78. // ElementType element type
  79. // OpCode binary operation
  80. // Direction scan direction
  81. // ElementScanSize size of scan, in elements
  82. // ElementScanPitch pitch of the next scan, in elements
  83. // ScanCount number of scans in a multiscan
  84. // pSrc input sequence on the device. pSrc==pDst for in-place scans
  85. // pDst output sequence on the device
  86. //=============================================================================
  87. STDMETHOD(Multiscan)( THIS_
  88. D3DX11_SCAN_DATA_TYPE ElementType,
  89. D3DX11_SCAN_OPCODE OpCode,
  90. UINT ElementScanSize,
  91. UINT ElementScanPitch,
  92. UINT ScanCount,
  93. __in ID3D11UnorderedAccessView* pSrc,
  94. __in ID3D11UnorderedAccessView* pDst
  95. ) PURE;
  96. };
  97. //=============================================================================
  98. // Creates a scan context
  99. // pDevice the device context
  100. // MaxElementScanSize maximum single scan size, in elements (FLOAT, UINT, or INT)
  101. // MaxScanCount maximum number of scans in multiscan
  102. // ppScanContext new scan context
  103. //=============================================================================
  104. HRESULT WINAPI D3DX11CreateScan(
  105. __in ID3D11DeviceContext* pDeviceContext,
  106. UINT MaxElementScanSize,
  107. UINT MaxScanCount,
  108. __out ID3DX11Scan** ppScan );
  109. //////////////////////////////////////////////////////////////////////////////
  110. // ID3DX11SegmentedScan:
  111. //////////////////////////////////////////////////////////////////////////////
  112. // {a915128c-d954-4c79-bfe1-64db923194d6}
  113. DEFINE_GUID(IID_ID3DX11SegmentedScan, 0xa915128c, 0xd954, 0x4c79, 0xbf, 0xe1, 0x64, 0xdb, 0x92, 0x31, 0x94, 0xd6);
  114. #undef INTERFACE
  115. #define INTERFACE ID3DX11SegmentedScan
  116. DECLARE_INTERFACE_(ID3DX11SegmentedScan, IUnknown)
  117. {
  118. // IUnknown
  119. STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  120. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  121. STDMETHOD_(ULONG, Release)(THIS) PURE;
  122. // ID3DX11SegmentedScan
  123. STDMETHOD(SetScanDirection)(THIS_ D3DX11_SCAN_DIRECTION Direction) PURE;
  124. //=============================================================================
  125. // Performs a segscan of a sequence in-place or out-of-place
  126. // ElementType element type
  127. // OpCode binary operation
  128. // Direction scan direction
  129. // pSrcElementFlags compact array of bits, one per element of pSrc. A set value
  130. // indicates the start of a new segment.
  131. // ElementScanSize size of scan, in elements
  132. // pSrc input sequence on the device. pSrc==pDst for in-place scans
  133. // pDst output sequence on the device
  134. //=============================================================================
  135. STDMETHOD(SegScan)( THIS_
  136. D3DX11_SCAN_DATA_TYPE ElementType,
  137. D3DX11_SCAN_OPCODE OpCode,
  138. UINT ElementScanSize,
  139. __in_opt ID3D11UnorderedAccessView* pSrc,
  140. __in ID3D11UnorderedAccessView* pSrcElementFlags,
  141. __in ID3D11UnorderedAccessView* pDst
  142. ) PURE;
  143. };
  144. //=============================================================================
  145. // Creates a segmented scan context
  146. // pDevice the device context
  147. // MaxElementScanSize maximum single scan size, in elements (FLOAT, UINT, or INT)
  148. // ppScanContext new scan context
  149. //=============================================================================
  150. HRESULT WINAPI D3DX11CreateSegmentedScan(
  151. __in ID3D11DeviceContext* pDeviceContext,
  152. UINT MaxElementScanSize,
  153. __out ID3DX11SegmentedScan** ppScan );
  154. //////////////////////////////////////////////////////////////////////////////
  155. #define D3DX11_FFT_MAX_PRECOMPUTE_BUFFERS 4
  156. #define D3DX11_FFT_MAX_TEMP_BUFFERS 4
  157. #define D3DX11_FFT_MAX_DIMENSIONS 32
  158. //////////////////////////////////////////////////////////////////////////////
  159. // ID3DX11FFT:
  160. //////////////////////////////////////////////////////////////////////////////
  161. // {b3f7a938-4c93-4310-a675-b30d6de50553}
  162. DEFINE_GUID(IID_ID3DX11FFT, 0xb3f7a938, 0x4c93, 0x4310, 0xa6, 0x75, 0xb3, 0x0d, 0x6d, 0xe5, 0x05, 0x53);
  163. #undef INTERFACE
  164. #define INTERFACE ID3DX11FFT
  165. DECLARE_INTERFACE_(ID3DX11FFT, IUnknown)
  166. {
  167. // IUnknown
  168. STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  169. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  170. STDMETHOD_(ULONG, Release)(THIS) PURE;
  171. // ID3DX11FFT
  172. // scale for forward transform (defaults to 1 if set to 0)
  173. STDMETHOD(SetForwardScale)(THIS_ FLOAT ForwardScale) PURE;
  174. STDMETHOD_(FLOAT, GetForwardScale)(THIS) PURE;
  175. // scale for inverse transform (defaults to 1/N if set to 0, where N is
  176. // the product of the transformed dimension lengths
  177. STDMETHOD(SetInverseScale)(THIS_ FLOAT InverseScale) PURE;
  178. STDMETHOD_(FLOAT, GetInverseScale)(THIS) PURE;
  179. //------------------------------------------------------------------------------
  180. // Attaches buffers to the context and performs any required precomputation.
  181. // The buffers must be no smaller than the corresponding buffer sizes returned
  182. // by D3DX11CreateFFT*(). Temp buffers may beshared between multiple contexts,
  183. // though care should be taken to concurrently execute multiple FFTs which share
  184. // temp buffers.
  185. //
  186. // NumTempBuffers number of buffers in ppTempBuffers
  187. // ppTempBuffers temp buffers to attach
  188. // NumPrecomputeBuffers number of buffers in ppPrecomputeBufferSizes
  189. // ppPrecomputeBufferSizes buffers to hold precomputed data
  190. STDMETHOD(AttachBuffersAndPrecompute)( THIS_
  191. __in_range(0,D3DX11_FFT_MAX_TEMP_BUFFERS) UINT NumTempBuffers,
  192. __in_ecount(NumTempBuffers) ID3D11UnorderedAccessView*const* ppTempBuffers,
  193. __in_range(0,D3DX11_FFT_MAX_PRECOMPUTE_BUFFERS) UINT NumPrecomputeBuffers,
  194. __in_ecount(NumPrecomputeBuffers) ID3D11UnorderedAccessView*const* ppPrecomputeBufferSizes ) PURE;
  195. //------------------------------------------------------------------------------
  196. // Call after buffers have been attached to the context, pInput and *ppOuput can
  197. // be one of the temp buffers. If *ppOutput == NULL, then the computation will ping-pong
  198. // between temp buffers and the last buffer written to is stored at *ppOutput.
  199. // Otherwise, *ppOutput is used as the output buffer (which may incur an extra copy).
  200. //
  201. // The format of complex data is interleaved components, e.g. (Real0, Imag0),
  202. // (Real1, Imag1) ... etc. Data is stored in row major order
  203. //
  204. // pInputBuffer view onto input buffer
  205. // ppOutpuBuffert pointer to view of output buffer
  206. STDMETHOD(ForwardTransform)( THIS_
  207. __in const ID3D11UnorderedAccessView* pInputBuffer,
  208. __inout ID3D11UnorderedAccessView** ppOutputBuffer ) PURE;
  209. STDMETHOD(InverseTransform)( THIS_
  210. __in const ID3D11UnorderedAccessView* pInputBuffer,
  211. __inout ID3D11UnorderedAccessView** ppOutputBuffer ) PURE;
  212. };
  213. //////////////////////////////////////////////////////////////////////////////
  214. // ID3DX11FFT Creation Routines
  215. //////////////////////////////////////////////////////////////////////////////
  216. typedef enum D3DX11_FFT_DATA_TYPE
  217. {
  218. D3DX11_FFT_DATA_TYPE_REAL,
  219. D3DX11_FFT_DATA_TYPE_COMPLEX,
  220. } D3DX11_FFT_DATA_TYPE;
  221. typedef enum D3DX11_FFT_DIM_MASK
  222. {
  223. D3DX11_FFT_DIM_MASK_1D = 0x1,
  224. D3DX11_FFT_DIM_MASK_2D = 0x3,
  225. D3DX11_FFT_DIM_MASK_3D = 0x7,
  226. } D3DX11_FFT_DIM_MASK;
  227. typedef struct D3DX11_FFT_DESC
  228. {
  229. UINT NumDimensions; // number of dimensions
  230. UINT ElementLengths[D3DX11_FFT_MAX_DIMENSIONS]; // length of each dimension
  231. UINT DimensionMask; // a bit set for each dimensions to transform
  232. // (see D3DX11_FFT_DIM_MASK for common masks)
  233. D3DX11_FFT_DATA_TYPE Type; // type of the elements in spatial domain
  234. } D3DX11_FFT_DESC;
  235. //------------------------------------------------------------------------------
  236. // NumTempBufferSizes Number of temporary buffers needed
  237. // pTempBufferSizes Minimum sizes (in FLOATs) of temporary buffers
  238. // NumPrecomputeBufferSizes Number of precompute buffers needed
  239. // pPrecomputeBufferSizes minimum sizes (in FLOATs) for precompute buffers
  240. //------------------------------------------------------------------------------
  241. typedef struct D3DX11_FFT_BUFFER_INFO
  242. {
  243. __range(0,D3DX11_FFT_MAX_TEMP_BUFFERS) UINT NumTempBufferSizes;
  244. UINT TempBufferFloatSizes[D3DX11_FFT_MAX_TEMP_BUFFERS];
  245. __range(0,D3DX11_FFT_MAX_PRECOMPUTE_BUFFERS) UINT NumPrecomputeBufferSizes;
  246. UINT PrecomputeBufferFloatSizes[D3DX11_FFT_MAX_PRECOMPUTE_BUFFERS];
  247. } D3DX11_FFT_BUFFER_INFO;
  248. typedef enum D3DX11_FFT_CREATE_FLAG
  249. {
  250. D3DX11_FFT_CREATE_FLAG_NO_PRECOMPUTE_BUFFERS = 0x01L, // do not precompute values and store into buffers
  251. } D3DX11_FFT_CREATE_FLAG;
  252. //------------------------------------------------------------------------------
  253. // Creates an ID3DX11FFT COM interface object and returns a pointer to it at *ppFFT.
  254. // The descriptor describes the shape of the data as well as the scaling factors
  255. // that should be used for forward and inverse transforms.
  256. // The FFT computation may require temporaries that act as ping-pong buffers
  257. // and for other purposes. aTempSizes is a list of the sizes required for
  258. // temporaries. Likewise, some data may need to be precomputed and the sizes
  259. // of those sizes are returned in aPrecomputedBufferSizes.
  260. //
  261. // To perform a computation, follow these steps:
  262. // 1) Create the FFT context object
  263. // 2) Precompute (and Attach temp working buffers of at least the required size)
  264. // 3) Call Compute() on some input data
  265. //
  266. // Compute() may be called repeatedly with different inputs and transform
  267. // directions. When finished with the FFT work, release the FFT interface()
  268. //
  269. // Device Direct3DDeviceContext to use in
  270. // pDesc Descriptor for FFT transform in
  271. // Count the number of 1D FFTs to perform in
  272. // Flags See D3DX11_FFT_CREATE_FLAG in
  273. // pBufferInfo Pointer to BUFFER_INFO struct, filled by funciton out
  274. // ppFFT Pointer to returned context pointer out
  275. //------------------------------------------------------------------------------
  276. HRESULT WINAPI D3DX11CreateFFT(
  277. ID3D11DeviceContext* pDeviceContext,
  278. __in const D3DX11_FFT_DESC* pDesc,
  279. UINT Flags,
  280. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  281. __out ID3DX11FFT** ppFFT
  282. );
  283. HRESULT WINAPI D3DX11CreateFFT1DReal(
  284. ID3D11DeviceContext* pDeviceContext,
  285. UINT X,
  286. UINT Flags,
  287. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  288. __out ID3DX11FFT** ppFFT
  289. );
  290. HRESULT WINAPI D3DX11CreateFFT1DComplex(
  291. ID3D11DeviceContext* pDeviceContext,
  292. UINT X,
  293. UINT Flags,
  294. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  295. __out ID3DX11FFT** ppFFT
  296. );
  297. HRESULT WINAPI D3DX11CreateFFT2DReal(
  298. ID3D11DeviceContext* pDeviceContext,
  299. UINT X,
  300. UINT Y,
  301. UINT Flags,
  302. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  303. __out ID3DX11FFT** ppFFT
  304. );
  305. HRESULT WINAPI D3DX11CreateFFT2DComplex(
  306. ID3D11DeviceContext* pDeviceContext,
  307. UINT X,
  308. UINT Y,
  309. UINT Flags,
  310. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  311. __out ID3DX11FFT** ppFFT
  312. );
  313. HRESULT WINAPI D3DX11CreateFFT3DReal(
  314. ID3D11DeviceContext* pDeviceContext,
  315. UINT X,
  316. UINT Y,
  317. UINT Z,
  318. UINT Flags,
  319. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  320. __out ID3DX11FFT** ppFFT
  321. );
  322. HRESULT WINAPI D3DX11CreateFFT3DComplex(
  323. ID3D11DeviceContext* pDeviceContext,
  324. UINT X,
  325. UINT Y,
  326. UINT Z,
  327. UINT Flags,
  328. __out D3DX11_FFT_BUFFER_INFO* pBufferInfo,
  329. __out ID3DX11FFT** ppFFT
  330. );
  331. #ifdef __cplusplus
  332. }
  333. #endif //__cplusplus
  334. #endif //__D3DX11GPGPU_H__