Compute.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // Notice Regarding Standards. AMD does not provide a license or sublicense to
  3. // any Intellectual Property Rights relating to any standards, including but not
  4. // limited to any audio and/or video codec technologies such as MPEG-2, MPEG-4;
  5. // AVC/H.264; HEVC/H.265; AAC decode/FFMPEG; AAC encode/FFMPEG; VC-1; and MP3
  6. // (collectively, the "Media Technologies"). For clarity, you will pay any
  7. // royalties due for such third party technologies, which may include the Media
  8. // Technologies that are owed as a result of AMD providing the Software to you.
  9. //
  10. // MIT license
  11. //
  12. // Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the "Software"), to deal
  16. // in the Software without restriction, including without limitation the rights
  17. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. // copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. // THE SOFTWARE.
  31. //
  32. /**
  33. ***************************************************************************************************
  34. * @file Compute.h
  35. * @brief AMFCompute interface declaration
  36. ***************************************************************************************************
  37. */
  38. #ifndef AMF_Compute_h
  39. #define AMF_Compute_h
  40. #pragma once
  41. #include "Buffer.h"
  42. #include "Surface.h"
  43. #if defined(__cplusplus)
  44. namespace amf
  45. {
  46. #endif
  47. typedef amf_uint64 AMF_KERNEL_ID;
  48. //----------------------------------------------------------------------------------------------
  49. // enumerations for plane conversion
  50. //----------------------------------------------------------------------------------------------
  51. typedef enum AMF_CHANNEL_ORDER
  52. {
  53. AMF_CHANNEL_ORDER_INVALID = 0,
  54. AMF_CHANNEL_ORDER_R = 1,
  55. AMF_CHANNEL_ORDER_RG = 2,
  56. AMF_CHANNEL_ORDER_BGRA = 3,
  57. AMF_CHANNEL_ORDER_RGBA = 4,
  58. AMF_CHANNEL_ORDER_ARGB = 5,
  59. AMF_CHANNEL_ORDER_YUY2 = 6,
  60. } AMF_CHANNEL_ORDER;
  61. //----------------------------------------------------------------------------------------------
  62. typedef enum AMF_CHANNEL_TYPE
  63. {
  64. AMF_CHANNEL_INVALID = 0,
  65. AMF_CHANNEL_UNSIGNED_INT8 = 1,
  66. AMF_CHANNEL_UNSIGNED_INT32 = 2,
  67. AMF_CHANNEL_UNORM_INT8 = 3,
  68. AMF_CHANNEL_UNORM_INT16 = 4,
  69. AMF_CHANNEL_SNORM_INT16 = 5,
  70. AMF_CHANNEL_FLOAT = 6,
  71. AMF_CHANNEL_FLOAT16 = 7,
  72. AMF_CHANNEL_UNSIGNED_INT16 = 8,
  73. AMF_CHANNEL_UNORM_INT_101010 = 9,
  74. } AMF_CHANNEL_TYPE;
  75. //----------------------------------------------------------------------------------------------
  76. #define AMF_STRUCTURED_BUFFER_FORMAT L"StructuredBufferFormat" // amf_int64(AMF_CHANNEL_TYPE), default - AMF_CHANNEL_UNSIGNED_INT32; to be set on AMFBuffer objects
  77. #if defined(_WIN32)
  78. AMF_WEAK GUID AMFStructuredBufferFormatGUID = { 0x90c5d674, 0xe90, 0x4181, {0xbd, 0xef, 0x26, 0x13, 0xc1, 0xdf, 0xa3, 0xbd} }; // UINT(DXGI_FORMAT), default - DXGI_FORMAT_R32_UINT; to be set on ID3D11Buffer or ID3D11Texture2D objects when used natively
  79. #endif
  80. //----------------------------------------------------------------------------------------------
  81. // enumeration argument type
  82. //----------------------------------------------------------------------------------------------
  83. typedef enum AMF_ARGUMENT_ACCESS_TYPE
  84. {
  85. AMF_ARGUMENT_ACCESS_READ = 0,
  86. AMF_ARGUMENT_ACCESS_WRITE = 1,
  87. AMF_ARGUMENT_ACCESS_READWRITE = 2,
  88. AMF_ARGUMENT_ACCESS_READWRITE_MASK = 0xFFFF,
  89. //Sampler parameters
  90. AMF_ARGUMENT_SAMPLER_LINEAR = 0x10000000,
  91. AMF_ARGUMENT_SAMPLER_NORM_COORD = 0x20000000,
  92. AMF_ARGUMENT_SAMPLER_POINT = 0x40000000,
  93. AMF_ARGUMENT_SAMPLER_MASK = 0xFFFF0000,
  94. } AMF_ARGUMENT_ACCESS_TYPE;
  95. //----------------------------------------------------------------------------------------------
  96. // AMFComputeKernel interface
  97. //----------------------------------------------------------------------------------------------
  98. #if defined(__cplusplus)
  99. class AMF_NO_VTABLE AMFComputeKernel : public AMFInterface
  100. {
  101. public:
  102. AMF_DECLARE_IID(0x94815701, 0x6c84, 0x4ba6, 0xa9, 0xfe, 0xe9, 0xad, 0x40, 0xf8, 0x8, 0x8)
  103. virtual void* AMF_STD_CALL GetNative() = 0;
  104. virtual const wchar_t* AMF_STD_CALL GetIDName() = 0;
  105. virtual AMF_RESULT AMF_STD_CALL SetArgPlaneNative(amf_size index, void* pPlane, AMF_ARGUMENT_ACCESS_TYPE eAccess) = 0;
  106. virtual AMF_RESULT AMF_STD_CALL SetArgBufferNative(amf_size index, void* pBuffer, AMF_ARGUMENT_ACCESS_TYPE eAccess) = 0;
  107. virtual AMF_RESULT AMF_STD_CALL SetArgPlane(amf_size index, AMFPlane* pPlane, AMF_ARGUMENT_ACCESS_TYPE eAccess) = 0;
  108. virtual AMF_RESULT AMF_STD_CALL SetArgBuffer(amf_size index, AMFBuffer* pBuffer, AMF_ARGUMENT_ACCESS_TYPE eAccess) = 0;
  109. virtual AMF_RESULT AMF_STD_CALL SetArgInt32(amf_size index, amf_int32 data) = 0;
  110. virtual AMF_RESULT AMF_STD_CALL SetArgInt64(amf_size index, amf_int64 data) = 0;
  111. virtual AMF_RESULT AMF_STD_CALL SetArgFloat(amf_size index, amf_float data) = 0;
  112. virtual AMF_RESULT AMF_STD_CALL SetArgBlob(amf_size index, amf_size dataSize, const void* pData) = 0;
  113. virtual AMF_RESULT AMF_STD_CALL GetCompileWorkgroupSize(amf_size workgroupSize[3]) = 0;
  114. virtual AMF_RESULT AMF_STD_CALL Enqueue(amf_size dimension, amf_size globalOffset[3], amf_size globalSize[3], amf_size localSize[3]) = 0;
  115. };
  116. //----------------------------------------------------------------------------------------------
  117. // smart pointer
  118. //----------------------------------------------------------------------------------------------
  119. typedef AMFInterfacePtr_T<AMFComputeKernel> AMFComputeKernelPtr;
  120. #else // #if defined(__cplusplus)
  121. AMF_DECLARE_IID(AMFComputeKernel, 0x94815701, 0x6c84, 0x4ba6, 0xa9, 0xfe, 0xe9, 0xad, 0x40, 0xf8, 0x8, 0x8)
  122. typedef struct AMFComputeKernel AMFComputeKernel;
  123. typedef struct AMFComputeKernelVtbl
  124. {
  125. // AMFInterface interface
  126. amf_long (AMF_STD_CALL *Acquire)(AMFComputeKernel* pThis);
  127. amf_long (AMF_STD_CALL *Release)(AMFComputeKernel* pThis);
  128. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFComputeKernel* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  129. // AMFComputeKernel interface
  130. } AMFComputeKernelVtbl;
  131. struct AMFComputeKernel
  132. {
  133. const AMFComputeKernelVtbl *pVtbl;
  134. };
  135. #endif //#if defined(__cplusplus)
  136. //----------------------------------------------------------------------------------------------
  137. // AMFComputeSyncPoint interface
  138. //----------------------------------------------------------------------------------------------
  139. #if defined(__cplusplus)
  140. class AMF_NO_VTABLE AMFComputeSyncPoint : public AMFInterface
  141. {
  142. public:
  143. AMF_DECLARE_IID(0x66f33fe6, 0xaae, 0x4e65, 0xba, 0x3, 0xea, 0x8b, 0xa3, 0x60, 0x11, 0x2)
  144. virtual amf_bool AMF_STD_CALL IsCompleted() = 0;
  145. virtual void AMF_STD_CALL Wait() = 0;
  146. };
  147. typedef AMFInterfacePtr_T<AMFComputeSyncPoint> AMFComputeSyncPointPtr;
  148. #else // #if defined(__cplusplus)
  149. AMF_DECLARE_IID(AMFComputeSyncPoint, 0x66f33fe6, 0xaae, 0x4e65, 0xba, 0x3, 0xea, 0x8b, 0xa3, 0x60, 0x11, 0x2)
  150. typedef struct AMFComputeSyncPoint AMFComputeSyncPoint;
  151. typedef struct AMFComputeSyncPointVtbl
  152. {
  153. // AMFInterface interface
  154. amf_long (AMF_STD_CALL *Acquire)(AMFComputeSyncPoint* pThis);
  155. amf_long (AMF_STD_CALL *Release)(AMFComputeSyncPoint* pThis);
  156. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFComputeSyncPoint* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  157. // AMFComputeSyncPoint interface
  158. amf_bool (AMF_STD_CALL *IsCompleted)(AMFComputeSyncPoint* pThis);
  159. void (AMF_STD_CALL *Wait)(AMFComputeSyncPoint* pThis);
  160. } AMFComputeSyncPointVtbl;
  161. struct AMFComputeSyncPoint
  162. {
  163. const AMFComputeSyncPointVtbl *pVtbl;
  164. };
  165. #endif // #if defined(__cplusplus)
  166. //----------------------------------------------------------------------------------------------
  167. // AMFCompute interface
  168. //----------------------------------------------------------------------------------------------
  169. #if defined(__cplusplus)
  170. class AMF_NO_VTABLE AMFCompute : public AMFInterface
  171. {
  172. public:
  173. AMF_DECLARE_IID(0x3846233a, 0x3f43, 0x443f, 0x8a, 0x45, 0x75, 0x22, 0x11, 0xa9, 0xfb, 0xd5)
  174. virtual AMF_MEMORY_TYPE AMF_STD_CALL GetMemoryType() = 0;
  175. virtual void* AMF_STD_CALL GetNativeContext() = 0;
  176. virtual void* AMF_STD_CALL GetNativeDeviceID() = 0;
  177. virtual void* AMF_STD_CALL GetNativeCommandQueue() = 0;
  178. virtual AMF_RESULT AMF_STD_CALL GetKernel(AMF_KERNEL_ID kernelID, AMFComputeKernel** kernel) = 0;
  179. virtual AMF_RESULT AMF_STD_CALL PutSyncPoint(AMFComputeSyncPoint** ppSyncPoint) = 0;
  180. virtual AMF_RESULT AMF_STD_CALL FinishQueue() = 0;
  181. virtual AMF_RESULT AMF_STD_CALL FlushQueue() = 0;
  182. virtual AMF_RESULT AMF_STD_CALL FillPlane(AMFPlane *pPlane, const amf_size origin[3], const amf_size region[3], const void* pColor) = 0;
  183. virtual AMF_RESULT AMF_STD_CALL FillBuffer(AMFBuffer* pBuffer, amf_size dstOffset, amf_size dstSize, const void* pSourcePattern, amf_size patternSize) = 0;
  184. virtual AMF_RESULT AMF_STD_CALL ConvertPlaneToBuffer(AMFPlane *pSrcPlane, AMFBuffer** ppDstBuffer) = 0;
  185. virtual AMF_RESULT AMF_STD_CALL CopyBuffer(AMFBuffer* pSrcBuffer, amf_size srcOffset, amf_size size, AMFBuffer* pDstBuffer, amf_size dstOffset) = 0;
  186. virtual AMF_RESULT AMF_STD_CALL CopyPlane(AMFPlane *pSrcPlane, const amf_size srcOrigin[3], const amf_size region[3], AMFPlane *pDstPlane, const amf_size dstOrigin[3]) = 0;
  187. virtual AMF_RESULT AMF_STD_CALL CopyBufferToHost(AMFBuffer* pSrcBuffer, amf_size srcOffset, amf_size size, void* pDest, amf_bool blocking) = 0;
  188. virtual AMF_RESULT AMF_STD_CALL CopyBufferFromHost(const void* pSource, amf_size size, AMFBuffer* pDstBuffer, amf_size dstOffsetInBytes, amf_bool blocking) = 0;
  189. virtual AMF_RESULT AMF_STD_CALL CopyPlaneToHost(AMFPlane *pSrcPlane, const amf_size origin[3], const amf_size region[3], void* pDest, amf_size dstPitch, amf_bool blocking) = 0;
  190. virtual AMF_RESULT AMF_STD_CALL CopyPlaneFromHost(void* pSource, const amf_size origin[3], const amf_size region[3], amf_size srcPitch, AMFPlane *pDstPlane, amf_bool blocking) = 0;
  191. virtual AMF_RESULT AMF_STD_CALL ConvertPlaneToPlane(AMFPlane* pSrcPlane, AMFPlane** ppDstPlane, AMF_CHANNEL_ORDER order, AMF_CHANNEL_TYPE type) = 0;
  192. };
  193. //----------------------------------------------------------------------------------------------
  194. // smart pointer
  195. //----------------------------------------------------------------------------------------------
  196. typedef AMFInterfacePtr_T<AMFCompute> AMFComputePtr;
  197. #else // #if defined(__cplusplus)
  198. AMF_DECLARE_IID(AMFCompute, 0x3846233a, 0x3f43, 0x443f, 0x8a, 0x45, 0x75, 0x22, 0x11, 0xa9, 0xfb, 0xd5)
  199. typedef struct AMFCompute AMFCompute;
  200. typedef struct AMFComputeVtbl
  201. {
  202. // AMFInterface interface
  203. amf_long (AMF_STD_CALL *Acquire)(AMFCompute* pThis);
  204. amf_long (AMF_STD_CALL *Release)(AMFCompute* pThis);
  205. enum AMF_RESULT (AMF_STD_CALL *QueryInterface)(AMFCompute* pThis, const struct AMFGuid *interfaceID, void** ppInterface);
  206. // AMFCompute interface
  207. AMF_MEMORY_TYPE (AMF_STD_CALL *GetMemoryType)(AMFCompute* pThis);
  208. void* (AMF_STD_CALL *GetNativeContext)(AMFCompute* pThis);
  209. void* (AMF_STD_CALL *GetNativeDeviceID)(AMFCompute* pThis);
  210. void* (AMF_STD_CALL *GetNativeCommandQueue)(AMFCompute* pThis);
  211. AMF_RESULT (AMF_STD_CALL *GetKernel)(AMFCompute* pThis, AMF_KERNEL_ID kernelID, AMFComputeKernel** kernel);
  212. AMF_RESULT (AMF_STD_CALL *PutSyncPoint)(AMFCompute* pThis, AMFComputeSyncPoint** ppSyncPoint);
  213. AMF_RESULT (AMF_STD_CALL *FinishQueue)(AMFCompute* pThis);
  214. AMF_RESULT (AMF_STD_CALL *FlushQueue)(AMFCompute* pThis);
  215. AMF_RESULT (AMF_STD_CALL *FillPlane)(AMFCompute* pThis, AMFPlane *pPlane, const amf_size origin[3], const amf_size region[3], const void* pColor);
  216. AMF_RESULT (AMF_STD_CALL *FillBuffer)(AMFCompute* pThis, AMFBuffer* pBuffer, amf_size dstOffset, amf_size dstSize, const void* pSourcePattern, amf_size patternSize);
  217. AMF_RESULT (AMF_STD_CALL *ConvertPlaneToBuffer)(AMFCompute* pThis, AMFPlane *pSrcPlane, AMFBuffer** ppDstBuffer);
  218. AMF_RESULT (AMF_STD_CALL *CopyBuffer)(AMFCompute* pThis, AMFBuffer* pSrcBuffer, amf_size srcOffset, amf_size size, AMFBuffer* pDstBuffer, amf_size dstOffset);
  219. AMF_RESULT (AMF_STD_CALL *CopyPlane)(AMFCompute* pThis, AMFPlane *pSrcPlane, const amf_size srcOrigin[3], const amf_size region[3], AMFPlane *pDstPlane, const amf_size dstOrigin[3]);
  220. AMF_RESULT (AMF_STD_CALL *CopyBufferToHost)(AMFCompute* pThis, AMFBuffer* pSrcBuffer, amf_size srcOffset, amf_size size, void* pDest, amf_bool blocking);
  221. AMF_RESULT (AMF_STD_CALL *CopyBufferFromHost)(AMFCompute* pThis, const void* pSource, amf_size size, AMFBuffer* pDstBuffer, amf_size dstOffsetInBytes, amf_bool blocking);
  222. AMF_RESULT (AMF_STD_CALL *CopyPlaneToHost)(AMFCompute* pThis, AMFPlane *pSrcPlane, const amf_size origin[3], const amf_size region[3], void* pDest, amf_size dstPitch, amf_bool blocking);
  223. AMF_RESULT (AMF_STD_CALL *CopyPlaneFromHost)(AMFCompute* pThis, void* pSource, const amf_size origin[3], const amf_size region[3], amf_size srcPitch, AMFPlane *pDstPlane, amf_bool blocking);
  224. AMF_RESULT (AMF_STD_CALL *ConvertPlaneToPlane)(AMFCompute* pThis, AMFPlane* pSrcPlane, AMFPlane** ppDstPlane, AMF_CHANNEL_ORDER order, AMF_CHANNEL_TYPE type);
  225. } AMFComputeVtbl;
  226. struct AMFCompute
  227. {
  228. const AMFComputeVtbl *pVtbl;
  229. };
  230. #endif // #if defined(__cplusplus)
  231. //----------------------------------------------------------------------------------------------
  232. // AMFPrograms interface - singleton
  233. //----------------------------------------------------------------------------------------------
  234. #if defined(__cplusplus)
  235. class AMF_NO_VTABLE AMFPrograms
  236. {
  237. public:
  238. virtual AMF_RESULT AMF_STD_CALL RegisterKernelSourceFile(AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, const wchar_t* filepath, const char* options) = 0;
  239. virtual AMF_RESULT AMF_STD_CALL RegisterKernelSource(AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options) = 0;
  240. virtual AMF_RESULT AMF_STD_CALL RegisterKernelBinary(AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options) = 0;
  241. virtual AMF_RESULT AMF_STD_CALL RegisterKernelSource1(AMF_MEMORY_TYPE eMemoryType, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options) = 0;
  242. virtual AMF_RESULT AMF_STD_CALL RegisterKernelBinary1(AMF_MEMORY_TYPE eMemoryType, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options) = 0;
  243. };
  244. #else // #if defined(__cplusplus)
  245. typedef struct AMFPrograms AMFPrograms;
  246. typedef struct AMFProgramsVtbl
  247. {
  248. AMF_RESULT (AMF_STD_CALL *RegisterKernelSourceFile)(AMFPrograms* pThis, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, const wchar_t* filepath, const char* options);
  249. AMF_RESULT (AMF_STD_CALL *RegisterKernelSource)(AMFPrograms* pThis, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options);
  250. AMF_RESULT (AMF_STD_CALL *RegisterKernelBinary)(AMFPrograms* pThis, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options);
  251. AMF_RESULT (AMF_STD_CALL *RegisterKernelSource1)(AMFPrograms* pThis, AMF_MEMORY_TYPE eMemoryType, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options);
  252. AMF_RESULT (AMF_STD_CALL *RegisterKernelBinary1)(AMFPrograms* pThis, AMF_MEMORY_TYPE eMemoryType, AMF_KERNEL_ID* pKernelID, const wchar_t* kernelid_name, const char* kernelName, amf_size dataSize, const amf_uint8* data, const char* options);
  253. } AMFProgramsVtbl;
  254. struct AMFPrograms
  255. {
  256. const AMFProgramsVtbl *pVtbl;
  257. };
  258. #endif // #if defined(__cplusplus)
  259. #if defined(__cplusplus)
  260. } // namespace amf
  261. #endif
  262. #endif // AMF_Compute_h