opencl.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. /*****************************************************************************
  2. * opencl.h: OpenCL structures and defines
  3. *****************************************************************************
  4. * Copyright (C) 2012-2018 x264 project
  5. *
  6. * Authors: Steve Borho <sborho@multicorewareinc.com>
  7. * Anton Mitrofanov <BugMaster@narod.ru>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  22. *
  23. * This program is also available under a commercial proprietary license.
  24. * For more information, contact us at licensing@x264.com.
  25. *****************************************************************************/
  26. #ifndef X264_OPENCL_H
  27. #define X264_OPENCL_H
  28. #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
  29. #include "extras/cl.h"
  30. #define OCL_API(ret, attr, name) typedef ret (attr *name##_func)
  31. /* Platform API */
  32. OCL_API(cl_int, CL_API_CALL, clGetPlatformIDs)
  33. ( cl_uint /* num_entries */,
  34. cl_platform_id * /* platforms */,
  35. cl_uint * /* num_platforms */);
  36. OCL_API(cl_int, CL_API_CALL, clGetPlatformInfo)
  37. ( cl_platform_id /* platform */,
  38. cl_platform_info /* param_name */,
  39. size_t /* param_value_size */,
  40. void * /* param_value */,
  41. size_t * /* param_value_size_ret */);
  42. /* Device APIs */
  43. OCL_API(cl_int, CL_API_CALL, clGetDeviceIDs)
  44. ( cl_platform_id /* platform */,
  45. cl_device_type /* device_type */,
  46. cl_uint /* num_entries */,
  47. cl_device_id * /* devices */,
  48. cl_uint * /* num_devices */);
  49. OCL_API(cl_int, CL_API_CALL, clGetDeviceInfo)
  50. ( cl_device_id /* device */,
  51. cl_device_info /* param_name */,
  52. size_t /* param_value_size */,
  53. void * /* param_value */,
  54. size_t * /* param_value_size_ret */);
  55. OCL_API(cl_int, CL_API_CALL, clCreateSubDevices)
  56. ( cl_device_id /* in_device */,
  57. const cl_device_partition_property * /* properties */,
  58. cl_uint /* num_devices */,
  59. cl_device_id * /* out_devices */,
  60. cl_uint * /* num_devices_ret */);
  61. OCL_API(cl_int, CL_API_CALL, clRetainDevice)
  62. ( cl_device_id /* device */);
  63. OCL_API(cl_int, CL_API_CALL, clReleaseDevice)
  64. ( cl_device_id /* device */);
  65. /* Context APIs */
  66. OCL_API(cl_context, CL_API_CALL, clCreateContext)
  67. ( const cl_context_properties * /* properties */,
  68. cl_uint /* num_devices */,
  69. const cl_device_id * /* devices */,
  70. void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *),
  71. void * /* user_data */,
  72. cl_int * /* errcode_ret */);
  73. OCL_API(cl_context, CL_API_CALL, clCreateContextFromType)
  74. ( const cl_context_properties * /* properties */,
  75. cl_device_type /* device_type */,
  76. void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *),
  77. void * /* user_data */,
  78. cl_int * /* errcode_ret */);
  79. OCL_API(cl_int, CL_API_CALL, clRetainContext)
  80. ( cl_context /* context */);
  81. OCL_API(cl_int, CL_API_CALL, clReleaseContext)
  82. ( cl_context /* context */);
  83. OCL_API(cl_int, CL_API_CALL, clGetContextInfo)
  84. ( cl_context /* context */,
  85. cl_context_info /* param_name */,
  86. size_t /* param_value_size */,
  87. void * /* param_value */,
  88. size_t * /* param_value_size_ret */);
  89. /* Command Queue APIs */
  90. OCL_API(cl_command_queue, CL_API_CALL, clCreateCommandQueue)
  91. ( cl_context /* context */,
  92. cl_device_id /* device */,
  93. cl_command_queue_properties /* properties */,
  94. cl_int * /* errcode_ret */);
  95. OCL_API(cl_int, CL_API_CALL, clRetainCommandQueue)
  96. ( cl_command_queue /* command_queue */);
  97. OCL_API(cl_int, CL_API_CALL, clReleaseCommandQueue)
  98. ( cl_command_queue /* command_queue */);
  99. OCL_API(cl_int, CL_API_CALL, clGetCommandQueueInfo)
  100. ( cl_command_queue /* command_queue */,
  101. cl_command_queue_info /* param_name */,
  102. size_t /* param_value_size */,
  103. void * /* param_value */,
  104. size_t * /* param_value_size_ret */);
  105. /* Memory Object APIs */
  106. OCL_API(cl_mem, CL_API_CALL, clCreateBuffer)
  107. ( cl_context /* context */,
  108. cl_mem_flags /* flags */,
  109. size_t /* size */,
  110. void * /* host_ptr */,
  111. cl_int * /* errcode_ret */);
  112. OCL_API(cl_mem, CL_API_CALL, clCreateSubBuffer)
  113. ( cl_mem /* buffer */,
  114. cl_mem_flags /* flags */,
  115. cl_buffer_create_type /* buffer_create_type */,
  116. const void * /* buffer_create_info */,
  117. cl_int * /* errcode_ret */);
  118. OCL_API(cl_mem, CL_API_CALL, clCreateImage)
  119. ( cl_context /* context */,
  120. cl_mem_flags /* flags */,
  121. const cl_image_format * /* image_format */,
  122. const cl_image_desc * /* image_desc */,
  123. void * /* host_ptr */,
  124. cl_int * /* errcode_ret */);
  125. OCL_API(cl_int, CL_API_CALL, clRetainMemObject)
  126. ( cl_mem /* memobj */);
  127. OCL_API(cl_int, CL_API_CALL, clReleaseMemObject)
  128. ( cl_mem /* memobj */);
  129. OCL_API(cl_int, CL_API_CALL, clGetSupportedImageFormats)
  130. ( cl_context /* context */,
  131. cl_mem_flags /* flags */,
  132. cl_mem_object_type /* image_type */,
  133. cl_uint /* num_entries */,
  134. cl_image_format * /* image_formats */,
  135. cl_uint * /* num_image_formats */);
  136. OCL_API(cl_int, CL_API_CALL, clGetMemObjectInfo)
  137. ( cl_mem /* memobj */,
  138. cl_mem_info /* param_name */,
  139. size_t /* param_value_size */,
  140. void * /* param_value */,
  141. size_t * /* param_value_size_ret */);
  142. OCL_API(cl_int, CL_API_CALL, clGetImageInfo)
  143. ( cl_mem /* image */,
  144. cl_image_info /* param_name */,
  145. size_t /* param_value_size */,
  146. void * /* param_value */,
  147. size_t * /* param_value_size_ret */);
  148. OCL_API(cl_int, CL_API_CALL, clSetMemObjectDestructorCallback)
  149. ( cl_mem /* memobj */,
  150. void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/),
  151. void * /*user_data */ );
  152. /* Sampler APIs */
  153. OCL_API(cl_sampler, CL_API_CALL, clCreateSampler)
  154. ( cl_context /* context */,
  155. cl_bool /* normalized_coords */,
  156. cl_addressing_mode /* addressing_mode */,
  157. cl_filter_mode /* filter_mode */,
  158. cl_int * /* errcode_ret */);
  159. OCL_API(cl_int, CL_API_CALL, clRetainSampler)
  160. ( cl_sampler /* sampler */);
  161. OCL_API(cl_int, CL_API_CALL, clReleaseSampler)
  162. ( cl_sampler /* sampler */);
  163. OCL_API(cl_int, CL_API_CALL, clGetSamplerInfo)
  164. ( cl_sampler /* sampler */,
  165. cl_sampler_info /* param_name */,
  166. size_t /* param_value_size */,
  167. void * /* param_value */,
  168. size_t * /* param_value_size_ret */);
  169. /* Program Object APIs */
  170. OCL_API(cl_program, CL_API_CALL, clCreateProgramWithSource)
  171. ( cl_context /* context */,
  172. cl_uint /* count */,
  173. const char ** /* strings */,
  174. const size_t * /* lengths */,
  175. cl_int * /* errcode_ret */);
  176. OCL_API(cl_program, CL_API_CALL, clCreateProgramWithBinary)
  177. ( cl_context /* context */,
  178. cl_uint /* num_devices */,
  179. const cl_device_id * /* device_list */,
  180. const size_t * /* lengths */,
  181. const unsigned char ** /* binaries */,
  182. cl_int * /* binary_status */,
  183. cl_int * /* errcode_ret */);
  184. OCL_API(cl_program, CL_API_CALL, clCreateProgramWithBuiltInKernels)
  185. ( cl_context /* context */,
  186. cl_uint /* num_devices */,
  187. const cl_device_id * /* device_list */,
  188. const char * /* kernel_names */,
  189. cl_int * /* errcode_ret */);
  190. OCL_API(cl_int, CL_API_CALL, clRetainProgram)
  191. ( cl_program /* program */);
  192. OCL_API(cl_int, CL_API_CALL, clReleaseProgram)
  193. ( cl_program /* program */);
  194. OCL_API(cl_int, CL_API_CALL, clBuildProgram)
  195. ( cl_program /* program */,
  196. cl_uint /* num_devices */,
  197. const cl_device_id * /* device_list */,
  198. const char * /* options */,
  199. void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
  200. void * /* user_data */);
  201. OCL_API(cl_int, CL_API_CALL, clCompileProgram)
  202. ( cl_program /* program */,
  203. cl_uint /* num_devices */,
  204. const cl_device_id * /* device_list */,
  205. const char * /* options */,
  206. cl_uint /* num_input_headers */,
  207. const cl_program * /* input_headers */,
  208. const char ** /* header_include_names */,
  209. void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
  210. void * /* user_data */);
  211. OCL_API(cl_program, CL_API_CALL, clLinkProgram)
  212. ( cl_context /* context */,
  213. cl_uint /* num_devices */,
  214. const cl_device_id * /* device_list */,
  215. const char * /* options */,
  216. cl_uint /* num_input_programs */,
  217. const cl_program * /* input_programs */,
  218. void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
  219. void * /* user_data */,
  220. cl_int * /* errcode_ret */ );
  221. OCL_API(cl_int, CL_API_CALL, clUnloadPlatformCompiler)
  222. ( cl_platform_id /* platform */);
  223. OCL_API(cl_int, CL_API_CALL, clGetProgramInfo)
  224. ( cl_program /* program */,
  225. cl_program_info /* param_name */,
  226. size_t /* param_value_size */,
  227. void * /* param_value */,
  228. size_t * /* param_value_size_ret */);
  229. OCL_API(cl_int, CL_API_CALL, clGetProgramBuildInfo)
  230. ( cl_program /* program */,
  231. cl_device_id /* device */,
  232. cl_program_build_info /* param_name */,
  233. size_t /* param_value_size */,
  234. void * /* param_value */,
  235. size_t * /* param_value_size_ret */);
  236. /* Kernel Object APIs */
  237. OCL_API(cl_kernel, CL_API_CALL, clCreateKernel)
  238. ( cl_program /* program */,
  239. const char * /* kernel_name */,
  240. cl_int * /* errcode_ret */);
  241. OCL_API(cl_int, CL_API_CALL, clCreateKernelsInProgram)
  242. ( cl_program /* program */,
  243. cl_uint /* num_kernels */,
  244. cl_kernel * /* kernels */,
  245. cl_uint * /* num_kernels_ret */);
  246. OCL_API(cl_int, CL_API_CALL, clRetainKernel)
  247. ( cl_kernel /* kernel */);
  248. OCL_API(cl_int, CL_API_CALL, clReleaseKernel)
  249. ( cl_kernel /* kernel */);
  250. OCL_API(cl_int, CL_API_CALL, clSetKernelArg)
  251. ( cl_kernel /* kernel */,
  252. cl_uint /* arg_index */,
  253. size_t /* arg_size */,
  254. const void * /* arg_value */);
  255. OCL_API(cl_int, CL_API_CALL, clGetKernelInfo)
  256. ( cl_kernel /* kernel */,
  257. cl_kernel_info /* param_name */,
  258. size_t /* param_value_size */,
  259. void * /* param_value */,
  260. size_t * /* param_value_size_ret */);
  261. OCL_API(cl_int, CL_API_CALL, clGetKernelArgInfo)
  262. ( cl_kernel /* kernel */,
  263. cl_uint /* arg_indx */,
  264. cl_kernel_arg_info /* param_name */,
  265. size_t /* param_value_size */,
  266. void * /* param_value */,
  267. size_t * /* param_value_size_ret */);
  268. OCL_API(cl_int, CL_API_CALL, clGetKernelWorkGroupInfo)
  269. ( cl_kernel /* kernel */,
  270. cl_device_id /* device */,
  271. cl_kernel_work_group_info /* param_name */,
  272. size_t /* param_value_size */,
  273. void * /* param_value */,
  274. size_t * /* param_value_size_ret */);
  275. /* Event Object APIs */
  276. OCL_API(cl_int, CL_API_CALL, clWaitForEvents)
  277. ( cl_uint /* num_events */,
  278. const cl_event * /* event_list */);
  279. OCL_API(cl_int, CL_API_CALL, clGetEventInfo)
  280. ( cl_event /* event */,
  281. cl_event_info /* param_name */,
  282. size_t /* param_value_size */,
  283. void * /* param_value */,
  284. size_t * /* param_value_size_ret */);
  285. OCL_API(cl_event, CL_API_CALL, clCreateUserEvent)
  286. ( cl_context /* context */,
  287. cl_int * /* errcode_ret */);
  288. OCL_API(cl_int, CL_API_CALL, clRetainEvent)
  289. ( cl_event /* event */);
  290. OCL_API(cl_int, CL_API_CALL, clReleaseEvent)
  291. ( cl_event /* event */);
  292. OCL_API(cl_int, CL_API_CALL, clSetUserEventStatus)
  293. ( cl_event /* event */,
  294. cl_int /* execution_status */);
  295. OCL_API(cl_int, CL_API_CALL, clSetEventCallback)
  296. ( cl_event /* event */,
  297. cl_int /* command_exec_callback_type */,
  298. void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *),
  299. void * /* user_data */);
  300. /* Profiling APIs */
  301. OCL_API(cl_int, CL_API_CALL, clGetEventProfilingInfo)
  302. ( cl_event /* event */,
  303. cl_profiling_info /* param_name */,
  304. size_t /* param_value_size */,
  305. void * /* param_value */,
  306. size_t * /* param_value_size_ret */);
  307. /* Flush and Finish APIs */
  308. OCL_API(cl_int, CL_API_CALL, clFlush)
  309. ( cl_command_queue /* command_queue */);
  310. OCL_API(cl_int, CL_API_CALL, clFinish)
  311. ( cl_command_queue /* command_queue */);
  312. /* Enqueued Commands APIs */
  313. OCL_API(cl_int, CL_API_CALL, clEnqueueReadBuffer)
  314. ( cl_command_queue /* command_queue */,
  315. cl_mem /* buffer */,
  316. cl_bool /* blocking_read */,
  317. size_t /* offset */,
  318. size_t /* size */,
  319. void * /* ptr */,
  320. cl_uint /* num_events_in_wait_list */,
  321. const cl_event * /* event_wait_list */,
  322. cl_event * /* event */);
  323. OCL_API(cl_int, CL_API_CALL, clEnqueueReadBufferRect)
  324. ( cl_command_queue /* command_queue */,
  325. cl_mem /* buffer */,
  326. cl_bool /* blocking_read */,
  327. const size_t * /* buffer_offset */,
  328. const size_t * /* host_offset */,
  329. const size_t * /* region */,
  330. size_t /* buffer_row_pitch */,
  331. size_t /* buffer_slice_pitch */,
  332. size_t /* host_row_pitch */,
  333. size_t /* host_slice_pitch */,
  334. void * /* ptr */,
  335. cl_uint /* num_events_in_wait_list */,
  336. const cl_event * /* event_wait_list */,
  337. cl_event * /* event */);
  338. OCL_API(cl_int, CL_API_CALL, clEnqueueWriteBuffer)
  339. ( cl_command_queue /* command_queue */,
  340. cl_mem /* buffer */,
  341. cl_bool /* blocking_write */,
  342. size_t /* offset */,
  343. size_t /* size */,
  344. const void * /* ptr */,
  345. cl_uint /* num_events_in_wait_list */,
  346. const cl_event * /* event_wait_list */,
  347. cl_event * /* event */);
  348. OCL_API(cl_int, CL_API_CALL, clEnqueueWriteBufferRect)
  349. ( cl_command_queue /* command_queue */,
  350. cl_mem /* buffer */,
  351. cl_bool /* blocking_write */,
  352. const size_t * /* buffer_offset */,
  353. const size_t * /* host_offset */,
  354. const size_t * /* region */,
  355. size_t /* buffer_row_pitch */,
  356. size_t /* buffer_slice_pitch */,
  357. size_t /* host_row_pitch */,
  358. size_t /* host_slice_pitch */,
  359. const void * /* ptr */,
  360. cl_uint /* num_events_in_wait_list */,
  361. const cl_event * /* event_wait_list */,
  362. cl_event * /* event */);
  363. OCL_API(cl_int, CL_API_CALL, clEnqueueFillBuffer)
  364. ( cl_command_queue /* command_queue */,
  365. cl_mem /* buffer */,
  366. const void * /* pattern */,
  367. size_t /* pattern_size */,
  368. size_t /* offset */,
  369. size_t /* size */,
  370. cl_uint /* num_events_in_wait_list */,
  371. const cl_event * /* event_wait_list */,
  372. cl_event * /* event */);
  373. OCL_API(cl_int, CL_API_CALL, clEnqueueCopyBuffer)
  374. ( cl_command_queue /* command_queue */,
  375. cl_mem /* src_buffer */,
  376. cl_mem /* dst_buffer */,
  377. size_t /* src_offset */,
  378. size_t /* dst_offset */,
  379. size_t /* size */,
  380. cl_uint /* num_events_in_wait_list */,
  381. const cl_event * /* event_wait_list */,
  382. cl_event * /* event */);
  383. OCL_API(cl_int, CL_API_CALL, clEnqueueCopyBufferRect)
  384. ( cl_command_queue /* command_queue */,
  385. cl_mem /* src_buffer */,
  386. cl_mem /* dst_buffer */,
  387. const size_t * /* src_origin */,
  388. const size_t * /* dst_origin */,
  389. const size_t * /* region */,
  390. size_t /* src_row_pitch */,
  391. size_t /* src_slice_pitch */,
  392. size_t /* dst_row_pitch */,
  393. size_t /* dst_slice_pitch */,
  394. cl_uint /* num_events_in_wait_list */,
  395. const cl_event * /* event_wait_list */,
  396. cl_event * /* event */);
  397. OCL_API(cl_int, CL_API_CALL, clEnqueueReadImage)
  398. ( cl_command_queue /* command_queue */,
  399. cl_mem /* image */,
  400. cl_bool /* blocking_read */,
  401. const size_t * /* origin[3] */,
  402. const size_t * /* region[3] */,
  403. size_t /* row_pitch */,
  404. size_t /* slice_pitch */,
  405. void * /* ptr */,
  406. cl_uint /* num_events_in_wait_list */,
  407. const cl_event * /* event_wait_list */,
  408. cl_event * /* event */);
  409. OCL_API(cl_int, CL_API_CALL, clEnqueueWriteImage)
  410. ( cl_command_queue /* command_queue */,
  411. cl_mem /* image */,
  412. cl_bool /* blocking_write */,
  413. const size_t * /* origin[3] */,
  414. const size_t * /* region[3] */,
  415. size_t /* input_row_pitch */,
  416. size_t /* input_slice_pitch */,
  417. const void * /* ptr */,
  418. cl_uint /* num_events_in_wait_list */,
  419. const cl_event * /* event_wait_list */,
  420. cl_event * /* event */);
  421. OCL_API(cl_int, CL_API_CALL, clEnqueueFillImage)
  422. ( cl_command_queue /* command_queue */,
  423. cl_mem /* image */,
  424. const void * /* fill_color */,
  425. const size_t * /* origin[3] */,
  426. const size_t * /* region[3] */,
  427. cl_uint /* num_events_in_wait_list */,
  428. const cl_event * /* event_wait_list */,
  429. cl_event * /* event */);
  430. OCL_API(cl_int, CL_API_CALL, clEnqueueCopyImage)
  431. ( cl_command_queue /* command_queue */,
  432. cl_mem /* src_image */,
  433. cl_mem /* dst_image */,
  434. const size_t * /* src_origin[3] */,
  435. const size_t * /* dst_origin[3] */,
  436. const size_t * /* region[3] */,
  437. cl_uint /* num_events_in_wait_list */,
  438. const cl_event * /* event_wait_list */,
  439. cl_event * /* event */);
  440. OCL_API(cl_int, CL_API_CALL, clEnqueueCopyImageToBuffer)
  441. ( cl_command_queue /* command_queue */,
  442. cl_mem /* src_image */,
  443. cl_mem /* dst_buffer */,
  444. const size_t * /* src_origin[3] */,
  445. const size_t * /* region[3] */,
  446. size_t /* dst_offset */,
  447. cl_uint /* num_events_in_wait_list */,
  448. const cl_event * /* event_wait_list */,
  449. cl_event * /* event */);
  450. OCL_API(cl_int, CL_API_CALL, clEnqueueCopyBufferToImage)
  451. ( cl_command_queue /* command_queue */,
  452. cl_mem /* src_buffer */,
  453. cl_mem /* dst_image */,
  454. size_t /* src_offset */,
  455. const size_t * /* dst_origin[3] */,
  456. const size_t * /* region[3] */,
  457. cl_uint /* num_events_in_wait_list */,
  458. const cl_event * /* event_wait_list */,
  459. cl_event * /* event */);
  460. OCL_API(void *, CL_API_CALL, clEnqueueMapBuffer)
  461. ( cl_command_queue /* command_queue */,
  462. cl_mem /* buffer */,
  463. cl_bool /* blocking_map */,
  464. cl_map_flags /* map_flags */,
  465. size_t /* offset */,
  466. size_t /* size */,
  467. cl_uint /* num_events_in_wait_list */,
  468. const cl_event * /* event_wait_list */,
  469. cl_event * /* event */,
  470. cl_int * /* errcode_ret */);
  471. OCL_API(void *, CL_API_CALL, clEnqueueMapImage)
  472. ( cl_command_queue /* command_queue */,
  473. cl_mem /* image */,
  474. cl_bool /* blocking_map */,
  475. cl_map_flags /* map_flags */,
  476. const size_t * /* origin[3] */,
  477. const size_t * /* region[3] */,
  478. size_t * /* image_row_pitch */,
  479. size_t * /* image_slice_pitch */,
  480. cl_uint /* num_events_in_wait_list */,
  481. const cl_event * /* event_wait_list */,
  482. cl_event * /* event */,
  483. cl_int * /* errcode_ret */);
  484. OCL_API(cl_int, CL_API_CALL, clEnqueueUnmapMemObject)
  485. ( cl_command_queue /* command_queue */,
  486. cl_mem /* memobj */,
  487. void * /* mapped_ptr */,
  488. cl_uint /* num_events_in_wait_list */,
  489. const cl_event * /* event_wait_list */,
  490. cl_event * /* event */);
  491. OCL_API(cl_int, CL_API_CALL, clEnqueueMigrateMemObjects)
  492. ( cl_command_queue /* command_queue */,
  493. cl_uint /* num_mem_objects */,
  494. const cl_mem * /* mem_objects */,
  495. cl_mem_migration_flags /* flags */,
  496. cl_uint /* num_events_in_wait_list */,
  497. const cl_event * /* event_wait_list */,
  498. cl_event * /* event */);
  499. OCL_API(cl_int, CL_API_CALL, clEnqueueNDRangeKernel)
  500. ( cl_command_queue /* command_queue */,
  501. cl_kernel /* kernel */,
  502. cl_uint /* work_dim */,
  503. const size_t * /* global_work_offset */,
  504. const size_t * /* global_work_size */,
  505. const size_t * /* local_work_size */,
  506. cl_uint /* num_events_in_wait_list */,
  507. const cl_event * /* event_wait_list */,
  508. cl_event * /* event */);
  509. OCL_API(cl_int, CL_API_CALL, clEnqueueTask)
  510. ( cl_command_queue /* command_queue */,
  511. cl_kernel /* kernel */,
  512. cl_uint /* num_events_in_wait_list */,
  513. const cl_event * /* event_wait_list */,
  514. cl_event * /* event */);
  515. OCL_API(cl_int, CL_API_CALL, clEnqueueNativeKernel)
  516. ( cl_command_queue /* command_queue */,
  517. void (CL_CALLBACK * /*user_func*/)(void *),
  518. void * /* args */,
  519. size_t /* cb_args */,
  520. cl_uint /* num_mem_objects */,
  521. const cl_mem * /* mem_list */,
  522. const void ** /* args_mem_loc */,
  523. cl_uint /* num_events_in_wait_list */,
  524. const cl_event * /* event_wait_list */,
  525. cl_event * /* event */);
  526. OCL_API(cl_int, CL_API_CALL, clEnqueueMarkerWithWaitList)
  527. ( cl_command_queue /* command_queue */,
  528. cl_uint /* num_events_in_wait_list */,
  529. const cl_event * /* event_wait_list */,
  530. cl_event * /* event */);
  531. OCL_API(cl_int, CL_API_CALL, clEnqueueBarrierWithWaitList)
  532. ( cl_command_queue /* command_queue */,
  533. cl_uint /* num_events_in_wait_list */,
  534. const cl_event * /* event_wait_list */,
  535. cl_event * /* event */);
  536. /* Extension function access
  537. *
  538. * Returns the extension function address for the given function name,
  539. * or NULL if a valid function can not be found. The client must
  540. * check to make sure the address is not NULL, before using or
  541. * calling the returned function address.
  542. */
  543. OCL_API(void *, CL_API_CALL, clGetExtensionFunctionAddressForPlatform)
  544. ( cl_platform_id /* platform */,
  545. const char * /* func_name */);
  546. // Deprecated OpenCL 1.1 APIs
  547. OCL_API(cl_mem, CL_API_CALL, clCreateImage2D)
  548. ( cl_context /* context */,
  549. cl_mem_flags /* flags */,
  550. const cl_image_format * /* image_format */,
  551. size_t /* image_width */,
  552. size_t /* image_height */,
  553. size_t /* image_row_pitch */,
  554. void * /* host_ptr */,
  555. cl_int * /* errcode_ret */);
  556. OCL_API(cl_mem, CL_API_CALL, clCreateImage3D)
  557. ( cl_context /* context */,
  558. cl_mem_flags /* flags */,
  559. const cl_image_format * /* image_format */,
  560. size_t /* image_width */,
  561. size_t /* image_height */,
  562. size_t /* image_depth */,
  563. size_t /* image_row_pitch */,
  564. size_t /* image_slice_pitch */,
  565. void * /* host_ptr */,
  566. cl_int * /* errcode_ret */);
  567. OCL_API(cl_int, CL_API_CALL, clEnqueueMarker)
  568. ( cl_command_queue /* command_queue */,
  569. cl_event * /* event */);
  570. OCL_API(cl_int, CL_API_CALL, clEnqueueWaitForEvents)
  571. ( cl_command_queue /* command_queue */,
  572. cl_uint /* num_events */,
  573. const cl_event * /* event_list */);
  574. OCL_API(cl_int, CL_API_CALL, clEnqueueBarrier)
  575. ( cl_command_queue /* command_queue */);
  576. OCL_API(cl_int, CL_API_CALL, clUnloadCompiler)
  577. ( void);
  578. OCL_API(void *, CL_API_CALL, clGetExtensionFunctionAddress)
  579. ( const char * /* func_name */);
  580. #define OCL_DECLARE_FUNC(name) name##_func name
  581. typedef struct
  582. {
  583. void *library;
  584. OCL_DECLARE_FUNC( clBuildProgram );
  585. OCL_DECLARE_FUNC( clCreateBuffer );
  586. OCL_DECLARE_FUNC( clCreateCommandQueue );
  587. OCL_DECLARE_FUNC( clCreateContext );
  588. OCL_DECLARE_FUNC( clCreateImage2D );
  589. OCL_DECLARE_FUNC( clCreateKernel );
  590. OCL_DECLARE_FUNC( clCreateProgramWithBinary );
  591. OCL_DECLARE_FUNC( clCreateProgramWithSource );
  592. OCL_DECLARE_FUNC( clEnqueueCopyBuffer );
  593. OCL_DECLARE_FUNC( clEnqueueMapBuffer );
  594. OCL_DECLARE_FUNC( clEnqueueNDRangeKernel );
  595. OCL_DECLARE_FUNC( clEnqueueReadBuffer );
  596. OCL_DECLARE_FUNC( clEnqueueWriteBuffer );
  597. OCL_DECLARE_FUNC( clFinish );
  598. OCL_DECLARE_FUNC( clGetCommandQueueInfo );
  599. OCL_DECLARE_FUNC( clGetDeviceIDs );
  600. OCL_DECLARE_FUNC( clGetDeviceInfo );
  601. OCL_DECLARE_FUNC( clGetKernelWorkGroupInfo );
  602. OCL_DECLARE_FUNC( clGetPlatformIDs );
  603. OCL_DECLARE_FUNC( clGetProgramBuildInfo );
  604. OCL_DECLARE_FUNC( clGetProgramInfo );
  605. OCL_DECLARE_FUNC( clGetSupportedImageFormats );
  606. OCL_DECLARE_FUNC( clReleaseCommandQueue );
  607. OCL_DECLARE_FUNC( clReleaseContext );
  608. OCL_DECLARE_FUNC( clReleaseKernel );
  609. OCL_DECLARE_FUNC( clReleaseMemObject );
  610. OCL_DECLARE_FUNC( clReleaseProgram );
  611. OCL_DECLARE_FUNC( clSetKernelArg );
  612. } x264_opencl_function_t;
  613. /* Number of downscale resolutions to use for motion search */
  614. #define NUM_IMAGE_SCALES 4
  615. /* Number of PCIe copies that can be queued before requiring a flush */
  616. #define MAX_FINISH_COPIES 1024
  617. /* Size (in bytes) of the page-locked buffer used for PCIe xfers */
  618. #define PAGE_LOCKED_BUF_SIZE 32 * 1024 * 1024
  619. typedef struct
  620. {
  621. x264_opencl_function_t *ocl;
  622. cl_context context;
  623. cl_device_id device;
  624. cl_command_queue queue;
  625. cl_program lookahead_program;
  626. cl_int last_buf;
  627. cl_mem page_locked_buffer;
  628. char *page_locked_ptr;
  629. int pl_occupancy;
  630. struct
  631. {
  632. void *src;
  633. void *dest;
  634. int bytes;
  635. } copies[MAX_FINISH_COPIES];
  636. int num_copies;
  637. int b_device_AMD_SI;
  638. int b_fatal_error;
  639. int lookahead_thread_pri;
  640. int opencl_thread_pri;
  641. /* downscale lowres luma */
  642. cl_kernel downscale_hpel_kernel;
  643. cl_kernel downscale_kernel1;
  644. cl_kernel downscale_kernel2;
  645. cl_mem luma_16x16_image[2];
  646. /* weightp filtering */
  647. cl_kernel weightp_hpel_kernel;
  648. cl_kernel weightp_scaled_images_kernel;
  649. cl_mem weighted_scaled_images[NUM_IMAGE_SCALES];
  650. cl_mem weighted_luma_hpel;
  651. /* intra */
  652. cl_kernel memset_kernel;
  653. cl_kernel intra_kernel;
  654. cl_kernel rowsum_intra_kernel;
  655. cl_mem row_satds[2];
  656. /* hierarchical motion estimation */
  657. cl_kernel hme_kernel;
  658. cl_kernel subpel_refine_kernel;
  659. cl_mem mv_buffers[2];
  660. cl_mem lowres_mv_costs;
  661. cl_mem mvp_buffer;
  662. /* bidir */
  663. cl_kernel mode_select_kernel;
  664. cl_kernel rowsum_inter_kernel;
  665. cl_mem lowres_costs[2];
  666. cl_mem frame_stats[2]; /* cost_est, cost_est_aq, intra_mbs */
  667. } x264_opencl_t;
  668. typedef struct
  669. {
  670. x264_opencl_function_t *ocl;
  671. cl_mem scaled_image2Ds[NUM_IMAGE_SCALES];
  672. cl_mem luma_hpel;
  673. cl_mem inv_qscale_factor;
  674. cl_mem intra_cost;
  675. cl_mem lowres_mvs0;
  676. cl_mem lowres_mvs1;
  677. cl_mem lowres_mv_costs0;
  678. cl_mem lowres_mv_costs1;
  679. } x264_frame_opencl_t;
  680. typedef struct x264_frame x264_frame;
  681. #define x264_opencl_load_library x264_template(opencl_load_library)
  682. x264_opencl_function_t *x264_opencl_load_library( void );
  683. #define x264_opencl_close_library x264_template(opencl_close_library)
  684. void x264_opencl_close_library( x264_opencl_function_t *ocl );
  685. #define x264_opencl_lookahead_init x264_template(opencl_lookahead_init)
  686. int x264_opencl_lookahead_init( x264_t *h );
  687. #define x264_opencl_lookahead_delete x264_template(opencl_lookahead_delete)
  688. void x264_opencl_lookahead_delete( x264_t *h );
  689. #define x264_opencl_frame_delete x264_template(opencl_frame_delete)
  690. void x264_opencl_frame_delete( x264_frame *frame );
  691. #endif