diff --git a/README.OpenSource b/README.OpenSource index 3c54814d54cca4039ff53f7adbde29c32fc87ad0..ff5c4f772262f91b0e39b9bb24ad0784733783b2 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -5,7 +5,7 @@ "License File": "LICENSE", "Version Number": "v2024.05.08", "Owner": "sunsuodong@huawei.com", - "Upstream URL": "https://github.com/KhronosGroup/OpenCL-Headers/archive/v2022.05.18.tar.gz", + "Upstream URL": "https://github.com/KhronosGroup/OpenCL-Headers", "Description": "OpenCLTM API Headers" } ] diff --git a/scripts/.gitignore b/scripts/.gitignore deleted file mode 100644 index b971803c4a60094efb1e0d32d656c05b45d154c9..0000000000000000000000000000000000000000 --- a/scripts/.gitignore +++ /dev/null @@ -1 +0,0 @@ -gen/__pycache__/* diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index 6597642eaa9e2b669e80cf1db988238b92f8cf06..0000000000000000000000000000000000000000 --- a/scripts/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# OpenCL Header Code Generation - -## Introduction - -In order to ease maintenance and enable faster development in the OpenCL headers, the OpenCL headers for extensions are generated from the OpenCL XML machine readable grammar. -Currently, header generation is only enabled for the OpenCL headers for extensions, and the OpenCL headers for core APIs are still authored manually. - -## Dependencies - -The OpenCL headers are generated using Python [Mako Templates](https://www.makotemplates.org/). - -In most cases, after installing Python for your platform, Mako may be installed using: - -```sh -$ pip install Mako -``` - -## Making Changes - -Most changes only require modifications to the Mako templates. -Small changes modifying syntax or layout are simple and straightforward. -Occasionally, more complicated changes will be required, say when a new API is added that is unlike any previous API or when a new extension header file is needed, but this should be rare. - -The Python script should only need to be modified if additional information needs to be propagated from the XML file into the Mako template itself. - -## Generating Headers - -The script to generate headers requires the `cl.xml` machine readable grammar. -The latest version of `cl.xml` may be found in the Khronos OpenCL-Docs repo [here](https://github.com/KhronosGroup/OpenCL-Docs/blob/main/xml/cl.xml). - -The easiest way to generate new headers is by using the `headers_generate` target. -For example, from a directory used to build the headers, simply execute: - -```sh -$ cmake --build . --target headers_generate -``` - -The `cl.xml` file used to generate headers with the header generation target may be provided by setting the CMake variable `OPENCL_HEADERS_XML_PATH` to the full path to `cl.xml`. diff --git a/scripts/cl_ext.h.mako b/scripts/cl_ext.h.mako deleted file mode 100644 index c1f89260422c53a3093845a75344d3c7b3078718..0000000000000000000000000000000000000000 --- a/scripts/cl_ext.h.mako +++ /dev/null @@ -1,431 +0,0 @@ -<% -# Extensions to skip by default because they are in dedicated headers: -skipExtensions = { - 'cl_khr_d3d10_sharing', - 'cl_khr_d3d11_sharing', - 'cl_khr_dx9_media_sharing', - 'cl_khr_egl_event', - 'cl_khr_egl_image', - 'cl_khr_gl_depth_images', - 'cl_khr_gl_event', - 'cl_khr_gl_msaa_sharing', - 'cl_khr_gl_sharing', - 'cl_loader_layers', - 'cl_intel_dx9_media_sharing', - 'cl_intel_va_api_media_sharing', - 'cl_intel_sharing_format_query_d3d10', - 'cl_intel_sharing_format_query_d3d11', - 'cl_intel_sharing_format_query_dx9', - 'cl_intel_sharing_format_query_gl', - 'cl_intel_sharing_format_query_va_api', - } - -# Extensions to include in this header: -def shouldGenerate(extension): - if extension in genExtensions: - return True - elif not genExtensions and not extension in skipExtensions: - return True - return False - -# XML blocks to include in the headers: -def shouldEmit(block): - for type in block.findall('type'): - if type.get('name') in typedefs: - return True - elif type.get('name') in macros: - return True - elif type.get('name') in structs: - return True - for enum in block.findall('enum'): - #if enum.get('name') in enums: - return True - for func in block.findall('command'): - return True - return False - -# Initially, keep the same extension order as the original headers: -orderedExtensions = [ - # cl_ext.h: - 'cl_khr_command_buffer', - 'cl_khr_command_buffer_multi_device', - 'cl_khr_command_buffer_mutable_dispatch', - 'cl_khr_fp64', - 'cl_khr_fp16', - 'cl_APPLE_SetMemObjectDestructor', - 'cl_APPLE_ContextLoggingFunctions', - 'cl_khr_icd', - 'cl_khr_il_program', - 'cl_khr_image2D_from_buffer', # incorrect name - 'cl_khr_image2d_from_buffer', - 'cl_khr_initialize_memory', - 'cl_khr_terminate_context', - 'cl_khr_spir', - 'cl_khr_create_command_queue', - 'cl_nv_device_attribute_query', - 'cl_amd_device_attribute_query', - 'cl_arm_printf', - 'cl_ext_device_fission', - 'cl_ext_migrate_memobject', - 'cl_ext_cxx_for_opencl', - 'cl_qcom_ext_host_ptr', - 'cl_qcom_ext_host_ptr_iocoherent', - 'cl_qcom_ion_host_ptr', - 'cl_qcom_android_native_buffer_host_ptr', - 'cl_img_yuv_image', - 'cl_img_cached_allocations', - 'cl_img_use_gralloc_ptr', - 'cl_img_generate_mipmap', - 'cl_img_mem_properties', - 'cl_khr_subgroups', - 'cl_khr_mipmap_image', - 'cl_khr_priority_hints', - 'cl_khr_throttle_hints', - 'cl_khr_subgroup_named_barrier', - 'cl_khr_extended_versioning', - 'cl_khr_device_uuid', - 'cl_khr_pci_bus_info', - 'cl_khr_suggested_local_work_size', - 'cl_khr_integer_dot_product', - 'cl_khr_external_memory', - 'cl_khr_external_memory_dma_buf', - 'cl_khr_external_memory_dx', - 'cl_khr_external_memory_opaque_fd', - 'cl_khr_external_memory_win32', - 'cl_khr_external_semaphore', - 'cl_khr_external_semaphore_dx_fence', - 'cl_khr_external_semaphore_opaque_fd', - 'cl_khr_external_semaphore_sync_fd', - 'cl_khr_external_semaphore_win32', - 'cl_khr_semaphore', - 'cl_arm_import_memory', - 'cl_arm_shared_virtual_memory', - 'cl_arm_get_core_id', - 'cl_arm_job_slot_selection', - 'cl_arm_scheduling_controls', - 'cl_arm_controlled_kernel_termination', - 'cl_arm_protected_memory_allocation', - 'cl_intel_exec_by_local_thread', - 'cl_intel_device_attribute_query', - 'cl_intel_device_partition_by_names', - 'cl_intel_accelerator', - 'cl_intel_motion_estimation', - 'cl_intel_advanced_motion_estimation', - 'cl_intel_simultaneous_sharing', - 'cl_intel_egl_image_yuv', - 'cl_intel_packed_yuv', - 'cl_intel_required_subgroup_size', - 'cl_intel_driver_diagnostics', - 'cl_intel_planar_yuv', - 'cl_intel_device_side_avc_motion_estimation', - 'cl_intel_unified_shared_memory', - 'cl_intel_mem_alloc_buffer_location', - 'cl_intel_create_buffer_with_properties', - 'cl_intel_program_scope_host_pipe', - 'cl_intel_mem_channel_property', - 'cl_intel_mem_force_host_memory', - 'cl_intel_command_queue_families', - 'cl_intel_queue_no_sync_operations', - 'cl_intel_sharing_format_query', - 'cl_ext_image_requirements_info', - 'cl_ext_image_from_buffer', - 'cl_loader_info', - 'cl_khr_depth_images', - 'cl_ext_float_atomics', - 'cl_intel_create_mem_object_properties', - 'cl_pocl_content_size', - 'cl_ext_image_raw10_raw12', - # cl_d3d10.h - 'cl_khr_d3d10_sharing', - 'cl_intel_sharing_format_query_d3d10', - # cl_d3d11.h - 'cl_khr_d3d11_sharing', - 'cl_intel_sharing_format_query_d3d11', - # cl_dx9_media_sharing.h - 'cl_khr_dx9_media_sharing', - 'cl_intel_dx9_media_sharing', - 'cl_intel_sharing_format_query_dx9', - # cl_egl.h - 'cl_khr_egl_image', - 'cl_khr_egl_event', - # cl_gl.h - 'cl_khr_gl_sharing', - 'cl_khr_gl_event', - 'cl_khr_gl_depth_images', - 'cl_khr_gl_msaa_sharing', - 'cl_intel_sharing_format_query_gl', - # cl_layer.h - 'cl_loader_layers', - # cl_va_api_media_sharing_intel.h - 'cl_intel_sharing_format_query_va_api', - 'cl_intel_va_api_media_sharing', - ] - -def getExtensionSortKey(item): - name = item.get('name') - try: - index = orderedExtensions.index(name) - except ValueError: - if name.startswith('cl_khr'): - index = 10000 - elif name.startswith('cl_ext'): - index = 10001 - else: - index = 10002 - return index, name - -# Order the extensions should be emitted in the headers. -# KHR -> EXT -> Vendor Extensions -def getExtensionSortKey_ideal(item): - name = item.get('name') - if name.startswith('cl_khr'): - return 0, name - if name.startswith('cl_ext'): - return 1, name - return 99, name - -# Order enums should be emitted in the headers. -# Enums Without Bits -> Ordered Bit Enums -def getEnumSortKey(item): - name = item.get('name') - if name in enums: - if enums[name].Value: - return -1 - if enums[name].Bitpos: - return int(enums[name].Bitpos) - return 99 - -# Gets C function parameter strings for the specified API params: -def getCParameterStrings(params): - strings = [] - if len(params) == 0: - strings.append("void") - else: - for param in params: - paramstr = param.Type + ' ' + param.Name + param.TypeEnd - strings.append(paramstr) - return strings - -# Gets a bit string for the specified bit position: -def getBitPosString(bitpos): - ret = '(' - ret += '(cl_bitfield)' if int(bitpos) >= 31 else '' - ret += '1 << ' - ret += bitpos - ret += ')' - return ret - -# Extensions that are included in the ICD dispatch table for historical reasons. -# This should not be required for new extensions! -loaderExtensions = { - 'cl_ext_device_fission', - 'cl_khr_d3d10_sharing', - 'cl_khr_d3d11_sharing', - 'cl_khr_dx9_media_sharing', - 'cl_khr_egl_event', - 'cl_khr_egl_image', - 'cl_khr_gl_event', - 'cl_khr_gl_sharing', - 'cl_khr_subgroups' - } - -# Gets the preprocessor guard for the given extension: -def getPrototypeIfGuard(name): - if name in loaderExtensions: - guard = '!defined(CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES)' - else: - guard = '!defined(CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES)' - return guard - -# Names that have been generated already, since some may be shared by multiple -# extensions: -generatedNames = set() - -def isDuplicateName(name): - if name in generatedNames: - return True - generatedNames.add(name) - return False - -%>/******************************************************************************* - * Copyright (c) 2008-2023 The Khronos Group Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -#ifndef ${guard} -#define ${guard} - -/* -** This header is generated from the Khronos OpenCL XML API Registry. -*/ - -%if includes: -${includes} - -%endif -#include - -/* CL_NO_PROTOTYPES implies CL_NO_EXTENSION_PROTOTYPES: */ -#if defined(CL_NO_PROTOTYPES) && !defined(CL_NO_EXTENSION_PROTOTYPES) -#define CL_NO_EXTENSION_PROTOTYPES -#endif - -/* CL_NO_EXTENSION_PROTOTYPES implies - CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES and - CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES: */ -#if defined(CL_NO_EXTENSION_PROTOTYPES) && ${"\\"} - !defined(CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES) -#define CL_NO_ICD_DISPATCH_EXTENSION_PROTOTYPES -#endif -#if defined(CL_NO_EXTENSION_PROTOTYPES) && ${"\\"} - !defined(CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES) -#define CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -%for extension in sorted(spec.findall('extensions/extension'), key=getExtensionSortKey): -% if shouldGenerate(extension.get('name')): -<% - name = extension.get('name') -%>/*************************************************************** -* ${name} -***************************************************************/ -%if extension.get('condition'): -#if ${extension.get('condition')} - -%endif -#define ${name} 1 -#define ${name.upper()}_EXTENSION_NAME ${"\\"} - "${name}" - -%for block in extension.findall('require'): -% if shouldEmit(block): -% if block.get('condition'): -#if ${block.get('condition')} -% endif -% if block.get('comment'): -/* ${block.get('comment')} */ -% endif -% for type in block.findall('type'): -% if isDuplicateName(type.get('name')): -/* type ${type.get('name')} */ -% else: -% if type.get('name') in typedefs: -${typedefs[type.get('name')].Typedef.ljust(27)} ${type.get('name')}; -% elif type.get('name') in macros: -#define ${type.get('name')}${macros[type.get('name')].Macro} -% elif type.get('name') in structs: -<% - struct = structs[type.get('name')] -%>typedef struct _${struct.Name} { -% for i, member in enumerate(struct.Members): - ${member.Type} ${member.Name}${member.TypeEnd}; -% endfor -} ${struct.Name}; -% else: -// type ${type.get('name')} not found! -% endif -% endif -% endfor -% for enum in sorted(block.findall('enum'), key=getEnumSortKey): -% if isDuplicateName(enum.get('name')): -/* enum ${enum.get('name')} */ -% else: -% if enum.get('name') in enums: -% if enums[enum.get('name')].Value: -#define ${enum.get('name').ljust(51)} ${enums[enum.get('name')].Value} -% elif enums[enum.get('name')].Bitpos: -#define ${enum.get('name').ljust(51)} ${getBitPosString(enums[enum.get('name')].Bitpos)} -% else: -// enum ${enum.get('name')} is unassigned! -% endif -% else: -// enum ${enum.get('name')} not found! -% endif -% endif -% endfor -% if block.findall('command'): -% for func in block.findall('command'): -<% - api = apisigs[func.get('name')] -%> -typedef ${api.RetType} CL_API_CALL -${api.Name}_t( -% for i, paramStr in enumerate(getCParameterStrings(api.Params)): -% if i < len(api.Params)-1: - ${paramStr}, -% else: - ${paramStr}); -% endif -% endfor - -typedef ${api.Name}_t * -${api.Name}_fn ${api.Suffix}; -% endfor -% if generate_pfn_typedefs: - -/* -** The function pointer typedefs prefixed with "pfn_" are provided for -** compatibility with earlier versions of the headers. New code is -** encouraged to use the function pointer typedefs that are suffixed with -** "_fn" instead, for consistency. -*/ -% for func in block.findall('command'): -<% - api = apisigs[func.get('name')] -%> -typedef ${api.Name}_t * -pfn_${api.Name} ${api.Suffix}; -% endfor -% endif - -#if ${getPrototypeIfGuard(name)} -% for func in block.findall('command'): -<% - api = apisigs[func.get('name')] -%> -extern CL_API_ENTRY ${api.RetType} CL_API_CALL -${api.Name}( -% for i, paramStr in enumerate(getCParameterStrings(api.Params)): -% if i < len(api.Params)-1: - ${paramStr}, -% else: - ${paramStr}) ${api.Suffix}; -% endif -% endfor -% endfor - -#endif /* ${getPrototypeIfGuard(name)} */ -% endif -% if block.get('condition'): - -#endif /* ${block.get('condition')} */ -% endif - -% endif -%endfor -%if extension.get('condition'): -#endif /* ${extension.get('condition')} */ - -%endif -% endif -%endfor -#ifdef __cplusplus -} -#endif - -#endif /* ${guard} */ diff --git a/scripts/cl_function_types.h.mako b/scripts/cl_function_types.h.mako deleted file mode 100644 index 7888e148cff7d32bd0412ffb9742e5be867f535a..0000000000000000000000000000000000000000 --- a/scripts/cl_function_types.h.mako +++ /dev/null @@ -1,62 +0,0 @@ -<% -# Gets C function parameter strings for the specified API params: -import sys -import json -def getCParameterStrings(params): - strings = [] - if len(params) == 0: - strings.append("void") - else: - for param in params: - paramstr = param.Type + ' ' + param.Name + param.TypeEnd - strings.append(paramstr) - return strings - -%>/* - * Copyright (c) 2023 The Khronos Group Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * OpenCL is a trademark of Apple Inc. used under license by Khronos. - */ - -#ifndef OPENCL_CL_FUNCTION_TYPES_H_ -#define OPENCL_CL_FUNCTION_TYPES_H_ - -#include - -%for version, apis in coreapis.items(): -% if version != "CL_VERSION_1_0": -#ifdef ${version} - -% endif -% for api in apis: -typedef ${api.RetType} CL_API_CALL ${api.Name}_t( -% for i, paramStr in enumerate(getCParameterStrings(api.Params)): -% if i < len(api.Params)-1: - ${paramStr}, -% else: - ${paramStr}); -% endif -% endfor - -typedef ${api.Name}_t * -${api.Name}_fn ${api.Suffix}; - -% endfor -% if version != "CL_VERSION_1_0": -#endif /* ${version} */ - -% endif -%endfor -#endif /* OPENCL_CL_FUNCTION_TYPES_H_ */ diff --git a/scripts/gen/__init__.py b/scripts/gen/__init__.py deleted file mode 100644 index dbdf858bfafffa903ff9a437ddde10a339e51fb4..0000000000000000000000000000000000000000 --- a/scripts/gen/__init__.py +++ /dev/null @@ -1,210 +0,0 @@ -# Copyright (c) 2021 The Khronos Group Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from collections import OrderedDict -from collections import namedtuple - -import argparse -import sys -import urllib -import xml.etree.ElementTree as etree -import urllib.request - -# parse_xml - Helper function to parse the XML file from a URL or local file. -def parse_xml(path): - file = urllib.request.urlopen(path) if path.startswith("http") else open(path, 'r') - with file: - tree = etree.parse(file) - return tree - -# noneStr - returns string argument, or "" if argument is None. -def noneStr(s): - if s: - return s - return "" - -def parse_args(): - parser = argparse.ArgumentParser() - - # To pull the latest registry file from GitHub, pass: - # -registry "https://raw.githubusercontent.com/KhronosGroup/OpenCL-Registry/master/xml/cl.xml" - - parser.add_argument('-registry', action='store', - default='cl.xml', - help='Use specified registry file instead of cl.xml') - parser.add_argument('-o', action='store', dest='directory', - default='.', - help='Create target and related files in specified directory') - - args = parser.parse_args() - return args - -def load_spec(args): - specpath = args.registry - - print('Parsing XML file from: ' + specpath) - spec = parse_xml(specpath) - return spec - -def get_apitypedefs(spec): - typedefs = OrderedDict() - Typedef = namedtuple('Typedef', 'Typedef Name') - print('Generating API typedef dictionary...') - for type in spec.findall('types/type'): - if type.get('category') == 'define': - if noneStr(type.text).startswith("typedef"): - typedef = noneStr(type.text) - name = "" - for elem in type: - if elem.tag == 'name': - name = noneStr(elem.text) - else: - typedef = typedef + noneStr(elem.text) + noneStr(elem.tail) - typedef = typedef.strip() - name = name.strip() - typedefs[name] = Typedef(typedef, name) - return typedefs - -def get_apimacros(spec): - macros = OrderedDict() - Macro = namedtuple('Macro', 'Define Name Macro') - print('Generating API macro dictionary...') - for type in spec.findall('types/type'): - if type.get('category') == 'define': - if noneStr(type.text).startswith("#define"): - define = noneStr(type.text) - name = "" - macro = "" - for elem in type: - if elem.tag == 'name': - name = noneStr(elem.text) - macro = macro + noneStr(elem.tail) - define = define.strip() - name = name.strip() - macro = macro.rstrip() # keep spaces on the left! - macros[name] = Macro(define, name, macro) - return macros - -def get_apistructs(spec): - structs = OrderedDict() - Struct = namedtuple('Struct', 'Name Members') - StructMember = namedtuple('StructMember', 'Type TypeEnd Name') - print('Generating API struct dictionary...') - for type in spec.findall('types/type'): - if type.get('category') == 'struct': - name = type.get('name') - mlist = [] - for member in type.findall('member'): - mtype = noneStr(member.text) - mtypeend = "" - mname = "" - for elem in member: - if elem.tag == 'name': - mname = noneStr(elem.text) - mtypeend = noneStr(elem.tail) - elif elem.tag == 'enum': - # Assumes any additional enums are for array limits, e.g.: - # charname[CL_NAME_VERSION_MAX_NAME_SIZE] - mtypeend = mtypeend + noneStr(elem.text) + noneStr(elem.tail) - else: - mtype = mtype + noneStr(elem.text) + noneStr(elem.tail) - mtype = mtype.strip() - mtypeend = mtypeend.strip() - mname = mname.strip() - mlist.append(StructMember(mtype, mtypeend, mname)) - structs[name] = Struct(name, mlist) - return structs - -def get_apienums(spec): - enums = OrderedDict() - Enum = namedtuple('Enum', 'Value Bitpos Name') - print('Generating API enum dictionary...') - for enum in spec.findall('enums/enum'): - value = enum.get('value') - bitpos = enum.get('bitpos') - name = enum.get('name') - enums[name] = Enum(value, bitpos, name) - return enums - -def get_apisigs(spec): - apisigs = OrderedDict() - ApiSignature = namedtuple('ApiSignature', 'Name RetType Params Suffix') - ApiParam = namedtuple('ApiParam', 'Type TypeEnd Name') - print('Generating API signatures dictionary...') - for command in spec.findall('commands/command'): - suffix = noneStr(command.get('suffix')) - proto = command.find('proto') - ret = noneStr(proto.text) - name = "" - params = "" - for elem in proto: - if elem.tag == 'name': - name = noneStr(elem.text) + noneStr(elem.tail) - else: - ret = ret + noneStr(elem.text) + noneStr(elem.tail) - ret = ret.strip() - name = name.strip() - - plist = [] - for param in command.findall('param'): - ptype = noneStr(param.text) - ptypeend = "" - pname = "" - for elem in param: - if elem.tag == 'name': - pname = noneStr(elem.text) - ptypeend = noneStr(elem.tail) - else: - ptype = ptype + noneStr(elem.text) + noneStr(elem.tail) - ptype = ptype.strip() - ptypeend = ptypeend.strip() - pname = pname.strip() - plist.append(ApiParam(ptype, ptypeend, pname)) - - # For an empty parameter list (for e.g. clUnloadCompiler), add a single - # unnamed void parameter to make generation easier. - if len(plist) == 0: - plist.append(ApiParam("void", "", "")) - - apisigs[name] = ApiSignature(name, ret, plist, suffix) - return apisigs - -def get_coreapis(spec, apisigs): - coreapis = OrderedDict() - print('Generating core API dictionary...') - for feature in spec.findall('feature'): - version = noneStr(feature.get('name')) - - alist = [] - for function in feature.findall('require/command'): - name = function.get('name') - alist.append(apisigs[name]) - coreapis[version] = alist - return coreapis - -def get_extapis(spec, apisigs): - extapis = OrderedDict() - print('Generating API extensions dictionary...') - for feature in spec.findall('extensions/extension'): - extension = noneStr(feature.get('name')) - - alist = [] - for function in feature.findall('require/command'): - name = function.get('name') - alist.append(apisigs[name]) - extapis[extension] = alist - return extapis - -def get_apis(spec, apisigs): - return (get_coreapis(spec, apisigs), get_extapis(spec, apisigs)) diff --git a/scripts/gen_headers.py b/scripts/gen_headers.py deleted file mode 100644 index 4bfaa0e40d374dc69ee24367b399ac63a9f6a45a..0000000000000000000000000000000000000000 --- a/scripts/gen_headers.py +++ /dev/null @@ -1,240 +0,0 @@ -#!/usr/bin/python3 - -# Copyright (c) 2021 The Khronos Group Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import gen -import re - -from mako.template import Template -from mako.exceptions import RichTraceback - -from collections import OrderedDict -from collections import namedtuple - -def getDisableWarningIncludeString(include): - warningPush = """#if defined(_MSC_VER) -#if _MSC_VER >=1500 -#pragma warning( push ) -#pragma warning( disable : 4201 ) -#pragma warning( disable : 5105 ) -#endif -#endif -""" - warningPop = """ -#if defined(_MSC_VER) -#if _MSC_VER >=1500 -#pragma warning( pop ) -#endif -#endif""" - return warningPush + include + warningPop - -def getWin32OnlyIncludeString(include): - return """#if defined(_WIN32) -""" + include + """ -#endif""" - -if __name__ == "__main__": - args = gen.parse_args() - spec = gen.load_spec(args) - - typedefs = gen.get_apitypedefs(spec) - macros = gen.get_apimacros(spec) - structs = gen.get_apistructs(spec) - enums = gen.get_apienums(spec) - apisigs = gen.get_apisigs(spec) - - coreapis = gen.get_coreapis(spec, apisigs) - extapis = gen.get_extapis(spec, apisigs) - - try: - cl_ext_h_template = Template(filename='cl_ext.h.mako', input_encoding='utf-8') - cl_function_types_h_template = Template(filename='cl_function_types.h.mako', input_encoding='utf-8') - - print('Generating cl_dx9_media_sharing.h...') - text = cl_ext_h_template.render( - genExtensions={ - 'cl_khr_dx9_media_sharing', - 'cl_intel_dx9_media_sharing', - 'cl_intel_sharing_format_query_dx9', - }, - guard="OPENCL_CL_DX9_MEDIA_SHARING_H_", - includes=getWin32OnlyIncludeString(getDisableWarningIncludeString("#include ")), - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_dx9_media_sharing.h', 'w') as gen: - gen.write(text) - - print('Generating cl_d3d10.h...') - text = cl_ext_h_template.render( - genExtensions={ - 'cl_khr_d3d10_sharing', - 'cl_intel_sharing_format_query_d3d10', - }, - guard="OPENCL_CL_D3D10_H_", - includes=getDisableWarningIncludeString("#include "), - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_d3d10.h', 'w') as gen: - gen.write(text) - - print('Generating cl_d3d11.h...') - text = cl_ext_h_template.render( - genExtensions={ - 'cl_khr_d3d11_sharing', - 'cl_intel_sharing_format_query_d3d11' - }, - guard="OPENCL_CL_D3D11_H_", - includes=getDisableWarningIncludeString("#include "), - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_d3d11.h', 'w') as gen: - gen.write(text) - - print('Generating cl_egl.h...') - text = cl_ext_h_template.render( - genExtensions={'cl_khr_egl_event', 'cl_khr_egl_image'}, - guard="OPENCL_CL_EGL_H_", - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_egl.h', 'w') as gen: - gen.write(text) - - print('Generating cl_gl.h...') - text = cl_ext_h_template.render( - genExtensions={ - 'cl_khr_gl_depth_images', - 'cl_khr_gl_event', - 'cl_khr_gl_msaa_sharing', - 'cl_khr_gl_sharing', - 'cl_intel_sharing_format_query_gl', - }, - guard="OPENCL_CL_GL_H_", - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_gl.h', 'w') as gen: - gen.write(text) - - print('Generating cl_layer.h...') - text = cl_ext_h_template.render( - genExtensions={'cl_loader_layers'}, - guard="OPENCL_CL_LAYER_H_", - includes='#include ', - generate_pfn_typedefs=True, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_layer.h', 'w') as gen: - gen.write(text) - - print('Generating cl_va_api_media_sharing_intel.h...') - text = cl_ext_h_template.render( - genExtensions={ - 'cl_intel_va_api_media_sharing', - 'cl_intel_sharing_format_query_va_api', - }, - guard="OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H_", - includes='#include ', - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_va_api_media_sharing_intel.h', 'w') as gen: - gen.write(text) - - print('Generating cl_ext.h...') - text = cl_ext_h_template.render( - genExtensions={}, - guard="OPENCL_CL_EXT_H_", - generate_pfn_typedefs=False, - spec=spec, - typedefs=typedefs, - macros=macros, - structs=structs, - enums=enums, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_ext.h', 'w') as gen: - gen.write(text) - - print('Generating cl_function_types.h...') - text = cl_function_types_h_template.render( - spec=spec, - apisigs=apisigs, - coreapis=coreapis, - extapis=extapis) - text = re.sub(r'\r\n', r'\n', text) - with open(args.directory + '/cl_function_types.h', 'w') as gen: - gen.write(text) - - except: - traceback = RichTraceback() - for (filename, lineno, function, line) in traceback.traceback: - print('%s(%s) : error in %s' % (filename, lineno, function)) - print(' ', line) - print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error)) diff --git a/scripts/requirements.txt b/scripts/requirements.txt deleted file mode 100644 index 650c29a4d9c2760cbd497e41676e246cb314c1ee..0000000000000000000000000000000000000000 --- a/scripts/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Mako>=1.2.2