diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index c2b36c61f8..e769858b1b 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -117,7 +117,6 @@ class ObjectType(Type): def __init__(self, name, json_data): Type.__init__(self, name, json_data) self.methods = [] - self.native_methods = [] self.built_type = None class Record: @@ -185,19 +184,13 @@ def linked_record_members(json_data, types): # PARSE ############################################################ -def is_native_method(method): - return method.return_type.category == "natively defined" or \ - any([arg.type.category == "natively defined" for arg in method.arguments]) - def link_object(obj, types): def make_method(json_data): arguments = linked_record_members(json_data.get('args', []), types) return Method(Name(json_data['name']), types[json_data.get('returns', 'void')], arguments) - methods = [make_method(m) for m in obj.json_data.get('methods', [])] - obj.methods = [method for method in methods if not is_native_method(method)] + obj.methods = [make_method(m) for m in obj.json_data.get('methods', [])] obj.methods.sort(key=lambda method: method.name.canonical_case()) - obj.native_methods = [method for method in methods if is_native_method(method)] def link_structure(struct, types): struct.members = linked_record_members(struct.json_data['members'], types) @@ -471,19 +464,16 @@ def as_wireType(typ): else: return as_cppType(typ.name) -def cpp_native_methods(types, typ): - return sorted(typ.methods + typ.native_methods, key=lambda method: method.name.canonical_case()) - -def c_native_methods(types, typ): - return cpp_native_methods(types, typ) + [ +def c_methods(types, typ): + return typ.methods + [ Method(Name('reference'), types['void'], []), Method(Name('release'), types['void'], []), ] -def get_methods_sorted_by_name(api_params): +def get_c_methods_sorted_by_name(api_params): unsorted = [(as_MethodSuffix(typ.name, method.name), typ, method) \ for typ in api_params['by_category']['object'] \ - for method in c_native_methods(api_params['types'], typ) ] + for method in c_methods(api_params['types'], typ) ] return [(typ, method) for (_, typ, method) in sorted(unsorted)] def has_callback_arguments(method): @@ -531,34 +521,31 @@ class MultiGeneratorFromDawnJSON(Generator): 'convert_cType_to_cppType': convert_cType_to_cppType, 'as_varName': as_varName, 'decorate': decorate, - 'methods_sorted_by_name': get_methods_sorted_by_name(api_params), + 'c_methods': lambda typ: c_methods(api_params['types'], typ), + 'c_methods_sorted_by_name': get_c_methods_sorted_by_name(api_params), } renders = [] - c_params = {'native_methods': lambda typ: c_native_methods(api_params['types'], typ)} - cpp_params = {'native_methods': lambda typ: cpp_native_methods(api_params['types'], typ)} - if 'dawn_headers' in targets: - renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params, c_params])) - renders.append(FileRender('dawn.h', 'src/include/dawn/dawn.h', [base_params, api_params, c_params])) - renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params, c_params])) + renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params])) + renders.append(FileRender('dawn.h', 'src/include/dawn/dawn.h', [base_params, api_params])) + renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params])) if 'dawncpp_headers' in targets: - renders.append(FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h', [base_params, api_params, cpp_params])) - renders.append(FileRender('dawncpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params, cpp_params])) + renders.append(FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.h', [base_params, api_params])) + renders.append(FileRender('dawncpp.h', 'src/include/dawn/dawncpp.h', [base_params, api_params])) if 'dawn_proc' in targets: - renders.append(FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params, c_params])) + renders.append(FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c', [base_params, api_params])) if 'dawncpp' in targets: - renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params, cpp_params])) + renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params])) if 'mock_webgpu' in targets: mock_params = [ base_params, api_params, - c_params, { 'has_callback_arguments': has_callback_arguments } @@ -570,7 +557,6 @@ class MultiGeneratorFromDawnJSON(Generator): frontend_params = [ base_params, api_params, - c_params, { 'as_frontendType': lambda typ: as_frontendType(typ), # TODO as_frontendType and friends take a Type and not a Name :( 'as_annotated_frontendType': lambda arg: annotated(as_frontendType(arg.type), arg) @@ -589,7 +575,6 @@ class MultiGeneratorFromDawnJSON(Generator): wire_params = [ base_params, api_params, - c_params, { 'as_wireType': as_wireType, 'as_annotated_wireType': lambda arg: annotated(as_wireType(arg.type), arg), diff --git a/generator/templates/dawn.h b/generator/templates/dawn.h index 7a68347775..bc78835006 100644 --- a/generator/templates/dawn.h +++ b/generator/templates/dawn.h @@ -25,7 +25,7 @@ {% for type in by_category["object"] %} typedef {{as_cType(type.name)}} {{as_cTypeDawn(type.name)}}; typedef {{as_cType(type.name)}}Impl {{as_cTypeDawn(type.name)}}Impl; - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} typedef {{as_cProc(type.name, method.name)}} {{as_cProcDawn(type.name, method.name)}}; #define {{as_cMethodDawn(type.name, method.name)}} {{as_cMethod(type.name, method.name)}} {% endfor %} diff --git a/generator/templates/dawn_native/ProcTable.cpp b/generator/templates/dawn_native/ProcTable.cpp index 3e1320542c..9088ce3279 100644 --- a/generator/templates/dawn_native/ProcTable.cpp +++ b/generator/templates/dawn_native/ProcTable.cpp @@ -37,7 +37,7 @@ namespace dawn_native { namespace { {% for type in by_category["object"] %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} {% set suffix = as_MethodSuffix(type.name, method.name) %} {{as_cType(method.return_type.name)}} Native{{suffix}}( @@ -85,7 +85,7 @@ namespace dawn_native { const char* name; }; static const ProcEntry sProcMap[] = { - {% for (type, method) in methods_sorted_by_name %} + {% for (type, method) in c_methods_sorted_by_name %} { reinterpret_cast(Native{{as_MethodSuffix(type.name, method.name)}}), "{{as_cMethod(type.name, method.name)}}" }, {% endfor %} }; @@ -127,7 +127,7 @@ namespace dawn_native { DawnProcTable table; table.getProcAddress = NativeGetProcAddress; {% for type in by_category["object"] %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} table.{{as_varName(type.name, method.name)}} = Native{{as_MethodSuffix(type.name, method.name)}}; {% endfor %} {% endfor %} diff --git a/generator/templates/dawn_proc.c b/generator/templates/dawn_proc.c index 2632124c13..fa0f1c94cf 100644 --- a/generator/templates/dawn_proc.c +++ b/generator/templates/dawn_proc.c @@ -31,7 +31,7 @@ WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName) { } {% for type in by_category["object"] %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}( {{-as_cType(type.name)}} {{as_varName(type.name)}} {%- for arg in method.arguments -%} diff --git a/generator/templates/dawn_proc_table.h b/generator/templates/dawn_proc_table.h index a6a9c88dcd..75304b87f3 100644 --- a/generator/templates/dawn_proc_table.h +++ b/generator/templates/dawn_proc_table.h @@ -21,7 +21,7 @@ typedef struct DawnProcTable { WGPUProcGetProcAddress getProcAddress; {% for type in by_category["object"] %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} {{as_cProc(type.name, method.name)}} {{as_varName(type.name, method.name)}}; {% endfor %} diff --git a/generator/templates/dawn_wire/client/ApiProcs.cpp b/generator/templates/dawn_wire/client/ApiProcs.cpp index 1b12552702..054d2af0f5 100644 --- a/generator/templates/dawn_wire/client/ApiProcs.cpp +++ b/generator/templates/dawn_wire/client/ApiProcs.cpp @@ -99,7 +99,7 @@ namespace dawn_wire { namespace client { const char* name; }; static const ProcEntry sProcMap[] = { - {% for (type, method) in methods_sorted_by_name %} + {% for (type, method) in c_methods_sorted_by_name %} { reinterpret_cast(Client{{as_MethodSuffix(type.name, method.name)}}), "{{as_cMethod(type.name, method.name)}}" }, {% endfor %} }; @@ -146,7 +146,7 @@ namespace dawn_wire { namespace client { DawnProcTable table; table.getProcAddress = ClientGetProcAddress; {% for type in by_category["object"] %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} {% set suffix = as_MethodSuffix(type.name, method.name) %} table.{{as_varName(type.name, method.name)}} = Client{{suffix}}; {% endfor %} diff --git a/generator/templates/dawn_wire/client/ApiProcs.h b/generator/templates/dawn_wire/client/ApiProcs.h index 69a183f729..8f301718e5 100644 --- a/generator/templates/dawn_wire/client/ApiProcs.h +++ b/generator/templates/dawn_wire/client/ApiProcs.h @@ -22,7 +22,7 @@ namespace dawn_wire { namespace client { //* Dawn API {% for type in by_category["object"] %} {% set cType = as_cType(type.name) %} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} {% set Suffix = as_MethodSuffix(type.name, method.name) %} {{as_cType(method.return_type.name)}} Client{{Suffix}}( {{-cType}} cSelf diff --git a/generator/templates/mock_webgpu.cpp b/generator/templates/mock_webgpu.cpp index fb92d70b19..788290b747 100644 --- a/generator/templates/mock_webgpu.cpp +++ b/generator/templates/mock_webgpu.cpp @@ -18,7 +18,7 @@ using namespace testing; namespace { {% for type in by_category["object"] %} - {% for method in native_methods(type) if len(method.arguments) < 10 %} + {% for method in c_methods(type) if len(method.arguments) < 10 %} {{as_cType(method.return_type.name)}} Forward{{as_MethodSuffix(type.name, method.name)}}( {{-as_cType(type.name)}} self {%- for arg in method.arguments -%} @@ -44,7 +44,7 @@ void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* d *device = GetNewDevice(); {% for type in by_category["object"] %} - {% for method in native_methods(type) if len(method.arguments) < 10 %} + {% for method in c_methods(type) if len(method.arguments) < 10 %} table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}}); {% endfor %} {% endfor %} diff --git a/generator/templates/webgpu.h b/generator/templates/webgpu.h index a1dbd9683a..39eb1bff05 100644 --- a/generator/templates/webgpu.h +++ b/generator/templates/webgpu.h @@ -103,9 +103,9 @@ typedef void (*WGPUProc)(); typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, const char* procName); -{% for type in by_category["object"] if len(native_methods(type)) > 0 %} +{% for type in by_category["object"] if len(c_methods(type)) > 0 %} // Procs of {{type.name.CamelCase()}} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})( {{-as_cType(type.name)}} {{as_varName(type.name)}} {%- for arg in method.arguments -%} @@ -121,9 +121,9 @@ typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, const char* procNa WGPU_EXPORT WGPUProc WGPUGetProcAddress(WGPUDevice device, const char* procName); -{% for type in by_category["object"] if len(native_methods(type)) > 0 %} +{% for type in by_category["object"] if len(c_methods(type)) > 0 %} // Methods of {{type.name.CamelCase()}} - {% for method in native_methods(type) %} + {% for method in c_methods(type) %} WGPU_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}( {{-as_cType(type.name)}} {{as_varName(type.name)}} {%- for arg in method.arguments -%} diff --git a/generator/templates/webgpu_cpp.cpp b/generator/templates/webgpu_cpp.cpp index f4fa053a70..400c8332b3 100644 --- a/generator/templates/webgpu_cpp.cpp +++ b/generator/templates/webgpu_cpp.cpp @@ -102,7 +102,7 @@ namespace wgpu { ) {%- endmacro %} - {% for method in native_methods(type) %} + {% for method in type.methods %} {{render_cpp_method_declaration(type, method)}} { {% if method.return_type.name.concatcase() == "void" %} {{render_cpp_to_c_method_call(type, method)}}; diff --git a/generator/templates/webgpu_cpp.h b/generator/templates/webgpu_cpp.h index 67f16438cf..911a16fafb 100644 --- a/generator/templates/webgpu_cpp.h +++ b/generator/templates/webgpu_cpp.h @@ -164,7 +164,7 @@ namespace wgpu { using ObjectBase::ObjectBase; using ObjectBase::operator=; - {% for method in native_methods(type) %} + {% for method in type.methods %} {{render_cpp_method_declaration(type, method)}}; {% endfor %}