Skip to content

Commit 36985c1

Browse files
authored
add ifdefs to support building the extension loader with older headers (#8)
* add ifdefs to support building the extension loader with older headers * updates for upstream headers
1 parent 3fa07b9 commit 36985c1

File tree

5 files changed

+565
-670
lines changed

5 files changed

+565
-670
lines changed

scripts/call_all.c.mako

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def getCallArgs(params):
115115
#define CL_USE_DEPRECATED_OPENCL_2_1_APIS
116116
#define CL_USE_DEPRECATED_OPENCL_2_2_APIS
117117
#define CL_USE_DEPRECATED_OPENCL_3_0_APIS
118-
#include "CL/cl.h"
118+
#include <CL/cl.h>
119119
#include <CL/cl_ext.h>
120120
#if defined(CLEXT_INCLUDE_GL)
121121
#include <CL/cl_gl.h>
@@ -138,6 +138,9 @@ def getCallArgs(params):
138138
#include <CL/cl_va_api_media_sharing_intel.h>
139139
#endif
140140

141+
// Some headers to not include function prototypes for the DX sharing extensions.
142+
#include "dx_sharing_prototypes.h"
143+
141144
void call_all(void)
142145
{
143146
%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey):

scripts/openclext.cpp.mako

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,42 @@ VA_API_Extensions = {
4747
}
4848
4949
# Extensions to include in this file:
50-
def shouldGenerate(extension):
51-
if extension in genExtensions:
50+
def shouldGenerate(name):
51+
if name in genExtensions:
5252
return True
53-
elif not genExtensions and not extension in skipExtensions:
53+
elif not genExtensions and not name in skipExtensions:
5454
return True
5555
return False
5656
5757
# ifdef condition for an extension:
58-
def getIfdefCondition(extension):
59-
if extension in GL_Extensions:
58+
def getIfdefCondition(name):
59+
if name in GL_Extensions:
6060
return 'CLEXT_INCLUDE_GL'
61-
elif extension in EGL_Extensions:
61+
elif name in EGL_Extensions:
6262
return 'CLEXT_INCLUDE_EGL'
63-
elif extension in DX9_Extensions:
63+
elif name in DX9_Extensions:
6464
return 'CLEXT_INCLUDE_DX9'
65-
elif extension in D3D10_Extensions:
65+
elif name in D3D10_Extensions:
6666
return 'CLEXT_INCLUDE_D3D10'
67-
elif extension in D3D11_Extensions:
67+
elif name in D3D11_Extensions:
6868
return 'CLEXT_INCLUDE_D3D11'
69-
elif extension in VA_API_Extensions:
69+
elif name in VA_API_Extensions:
7070
return 'CLEXT_INCLUDE_VA_API'
7171
return None
7272
73-
# XML blocks with functions to include:
73+
# XML blocks for extensions with functions to include:
7474
def shouldEmit(block):
7575
for func in block.findall('command'):
7676
return True
7777
return False
7878
79+
# Extensions with functions to include:
80+
def hasFunctions(extension):
81+
for block in extension.findall('require'):
82+
if shouldEmit(block):
83+
return True
84+
return False
85+
7986
# Order the extensions should be emitted in the headers.
8087
# KHR -> EXT -> Vendor Extensions
8188
def getExtensionSortKey(item):
@@ -145,6 +152,10 @@ def getCParameterStrings(params):
145152
#include <CL/cl_ext.h>
146153
#if defined(CLEXT_INCLUDE_GL)
147154
#include <CL/cl_gl.h>
155+
// Some versions of the headers to not define cl_khr_gl_event.
156+
#ifndef cl_khr_gl_event
157+
#define cl_khr_gl_event 1
158+
#endif
148159
#endif
149160
#if defined(CLEXT_INCLUDE_EGL)
150161
#include <CL/cl_egl.h>
@@ -303,14 +314,11 @@ static inline cl_platform_id _get_platform(cl_accelerator_intel accelerator)
303314
***************************************************************/
304315

305316
%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey):
306-
% if shouldGenerate(extension.get('name')):
317+
% if shouldGenerate(extension.get('name')) and hasFunctions(extension):
307318
% if getIfdefCondition(extension.get('name')):
308319
#if defined(${getIfdefCondition(extension.get('name'))})
309-
310320
% endif
311-
<%
312-
name = extension.get('name')
313-
%>/* ${name} */
321+
#if defined(${extension.get('name')})
314322
%for block in extension.findall('require'):
315323
% if shouldEmit(block):
316324
% if block.get('condition'):
@@ -337,10 +345,13 @@ typedef ${api.RetType} (CL_API_CALL* ${api.Name}_clextfn)(
337345
% endif
338346
%endfor
339347

348+
#else
349+
#pragma message("Define for ${extension.get('name')} was not found! Please update your headers.")
350+
#endif // defined(${extension.get('name')})
340351
% if getIfdefCondition(extension.get('name')):
341352
#endif // defined(${getIfdefCondition(extension.get('name'))})
342-
343353
% endif
354+
344355
% endif
345356
%endfor
346357

@@ -352,14 +363,11 @@ struct openclext_dispatch_table {
352363
cl_platform_id platform;
353364

354365
%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey):
355-
% if shouldGenerate(extension.get('name')):
366+
% if shouldGenerate(extension.get('name')) and hasFunctions(extension):
356367
% if getIfdefCondition(extension.get('name')):
357368
#if defined(${getIfdefCondition(extension.get('name'))})
358-
359369
% endif
360-
<%
361-
name = extension.get('name')
362-
%> /* ${name} */
370+
#if defined(${extension.get('name')})
363371
%for block in extension.findall('require'):
364372
% if shouldEmit(block):
365373
% if block.get('condition'):
@@ -375,11 +383,11 @@ struct openclext_dispatch_table {
375383
% endif
376384
% endif
377385
%endfor
378-
386+
#endif // defined(${extension.get('name')})
379387
% if getIfdefCondition(extension.get('name')):
380388
#endif // defined(${getIfdefCondition(extension.get('name'))})
381-
382389
% endif
390+
383391
% endif
384392
%endfor
385393
};
@@ -398,14 +406,11 @@ static void _init(cl_platform_id platform, openclext_dispatch_table* dispatch_pt
398406
platform, #_funcname);
399407

400408
%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey):
401-
% if shouldGenerate(extension.get('name')):
409+
% if shouldGenerate(extension.get('name')) and hasFunctions(extension):
402410
% if getIfdefCondition(extension.get('name')):
403411
#if defined(${getIfdefCondition(extension.get('name'))})
404-
405412
% endif
406-
<%
407-
name = extension.get('name')
408-
%> /* ${name} */
413+
#if defined(${extension.get('name')})
409414
%for block in extension.findall('require'):
410415
% if shouldEmit(block):
411416
% if block.get('condition'):
@@ -421,11 +426,11 @@ static void _init(cl_platform_id platform, openclext_dispatch_table* dispatch_pt
421426
% endif
422427
% endif
423428
%endfor
424-
429+
#endif // defined(${extension.get('name')})
425430
% if getIfdefCondition(extension.get('name')):
426431
#endif // defined(${getIfdefCondition(extension.get('name'))})
427-
428432
% endif
433+
429434
% endif
430435
%endfor
431436
#undef CLEXT_GET_EXTENSION
@@ -496,14 +501,11 @@ extern "C" {
496501
***************************************************************/
497502

498503
%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey):
499-
% if shouldGenerate(extension.get('name')):
504+
% if shouldGenerate(extension.get('name')) and hasFunctions(extension):
500505
% if getIfdefCondition(extension.get('name')):
501506
#if defined(${getIfdefCondition(extension.get('name'))})
502-
503507
% endif
504-
<%
505-
name = extension.get('name')
506-
%>/* ${name} */
508+
#if defined(${extension.get('name')})
507509
%for block in extension.findall('require'):
508510
% if shouldEmit(block):
509511
% if block.get('condition'):
@@ -559,10 +561,12 @@ ${api.RetType} CL_API_CALL ${api.Name}(
559561
% endif
560562
%endfor
561563

564+
#endif // defined(${extension.get('name')})
562565
% if getIfdefCondition(extension.get('name')):
563566
#endif // defined(${getIfdefCondition(extension.get('name'))})
564567

565568
% endif
569+
566570
% endif
567571
%endfor
568572
#ifdef __cplusplus

0 commit comments

Comments
 (0)