Introduce a "callback" type in dawn.json
This replaces all instances of "natively defined" with callbacks and
adds information about the callbacks arguments so that their typedefs
can be autogenerated in dawn.json.
Also adds all the methods using callbacks to the list of handwritten
client commands so that the wire templates don't try to generate code
for them.
BUG=dawn:22
Change-Id: I30ce01e3e688a16b31efa74d0c94ebafdca00985
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13901
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index f957f01..c2b36c6 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -83,14 +83,15 @@
for value in self.values:
self.full_mask = self.full_mask | value.value
+class CallbackType(Type):
+ def __init__(self, name, json_data):
+ Type.__init__(self, name, json_data)
+ self.arguments = []
+
class NativeType(Type):
def __init__(self, name, json_data):
Type.__init__(self, name, json_data, native=True)
-class NativelyDefined(Type):
- def __init__(self, name, json_data):
- Type.__init__(self, name, json_data)
-
# Methods and structures are both "records", so record members correspond to
# method arguments or structure members.
class RecordMember:
@@ -201,6 +202,9 @@
def link_structure(struct, types):
struct.members = linked_record_members(struct.json_data['members'], types)
+def link_callback(callback, types):
+ callback.arguments = linked_record_members(callback.json_data['args'], types)
+
# Sort structures so that if struct A has struct B as a member, then B is listed before A
# This is a form of topological sort where we try to keep the order reasonably similar to the
# original order (though th sort isn't technically stable).
@@ -242,7 +246,7 @@
'bitmask': BitmaskType,
'enum': EnumType,
'native': NativeType,
- 'natively defined': NativelyDefined,
+ 'callback': CallbackType,
'object': ObjectType,
'structure': StructureType,
}
@@ -267,6 +271,9 @@
for struct in by_category['structure']:
link_structure(struct, types)
+ for callback in by_category['callback']:
+ link_callback(callback, types)
+
for category in by_category.keys():
by_category[category] = sorted(by_category[category], key=lambda typ: typ.name.canonical_case())
@@ -292,6 +299,8 @@
commands = []
return_commands = []
+ wire_json['special items']['client_handwritten_commands'] += wire_json['special items']['client_side_commands']
+
# Generate commands from object methods
for api_object in wire_params['by_category']['object']:
for method in api_object.methods:
@@ -477,6 +486,9 @@
for method in c_native_methods(api_params['types'], typ) ]
return [(typ, method) for (_, typ, method) in sorted(unsorted)]
+def has_callback_arguments(method):
+ return any(arg.type.category == 'callback' for arg in method.arguments)
+
class MultiGeneratorFromDawnJSON(Generator):
def get_description(self):
return 'Generates code for various target from Dawn.json.'
@@ -543,8 +555,16 @@
renders.append(FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', [base_params, api_params, cpp_params]))
if 'mock_webgpu' in targets:
- renders.append(FileRender('mock_webgpu.h', 'src/dawn/mock_webgpu.h', [base_params, api_params, c_params]))
- renders.append(FileRender('mock_webgpu.cpp', 'src/dawn/mock_webgpu.cpp', [base_params, api_params, c_params]))
+ mock_params = [
+ base_params,
+ api_params,
+ c_params,
+ {
+ 'has_callback_arguments': has_callback_arguments
+ }
+ ]
+ renders.append(FileRender('mock_webgpu.h', 'src/dawn/mock_webgpu.h', mock_params))
+ renders.append(FileRender('mock_webgpu.cpp', 'src/dawn/mock_webgpu.cpp', mock_params))
if 'dawn_native_utils' in targets:
frontend_params = [