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