mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
Add .clang-format files and format more files
The .clang-format files tell clang-format to ignore certain directories
(replacing code in lint_clang_format.sh which will be removed).
$ git ls-tree -r master --name-only | grep '\.\(c\|h\|cpp\|gn\|gni\|mm\|m\|py\)$' | xargs ./append-space-to-files
$ git checkout -- generator/templates third_party/khronos/{KHR,vulkan}
$ git cl format --full --python
Followed by manual reformatting of a few things in Python for
readability.
Bug: none
Change-Id: I4c9e472cc9a5cd80c07286e808f4e597cfef5428
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24785
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
5a1d39ad0b
commit
01aeca22a9
@@ -22,6 +22,7 @@ from generator_lib import Generator, run_generator, FileRender
|
||||
# OBJECT MODEL
|
||||
############################################################
|
||||
|
||||
|
||||
class Name:
|
||||
def __init__(self, name, native=False):
|
||||
self.native = native
|
||||
@@ -44,7 +45,8 @@ class Name:
|
||||
return ''.join(self.chunks)
|
||||
|
||||
def camelCase(self):
|
||||
return self.chunks[0] + ''.join([self.CamelChunk(chunk) for chunk in self.chunks[1:]])
|
||||
return self.chunks[0] + ''.join(
|
||||
[self.CamelChunk(chunk) for chunk in self.chunks[1:]])
|
||||
|
||||
def CamelCase(self):
|
||||
return ''.join([self.CamelChunk(chunk) for chunk in self.chunks])
|
||||
@@ -63,9 +65,11 @@ class Name:
|
||||
result += chunk.lower()
|
||||
return result
|
||||
|
||||
|
||||
def concat_names(*names):
|
||||
return ' '.join([name.canonical_case() for name in names])
|
||||
|
||||
|
||||
class Type:
|
||||
def __init__(self, name, json_data, native=False):
|
||||
self.json_data = json_data
|
||||
@@ -74,7 +78,10 @@ class Type:
|
||||
self.category = json_data['category']
|
||||
self.javascript = self.json_data.get('javascript', True)
|
||||
|
||||
|
||||
EnumValue = namedtuple('EnumValue', ['name', 'value', 'valid', 'jsrepr'])
|
||||
|
||||
|
||||
class EnumType(Type):
|
||||
def __init__(self, name, json_data):
|
||||
Type.__init__(self, name, json_data)
|
||||
@@ -87,42 +94,55 @@ class EnumType(Type):
|
||||
if value != lastValue + 1:
|
||||
self.contiguousFromZero = False
|
||||
lastValue = value
|
||||
self.values.append(EnumValue(
|
||||
Name(m['name']),
|
||||
value,
|
||||
m.get('valid', True),
|
||||
m.get('jsrepr', None)))
|
||||
self.values.append(
|
||||
EnumValue(Name(m['name']), value, m.get('valid', True),
|
||||
m.get('jsrepr', None)))
|
||||
|
||||
# Assert that all values are unique in enums
|
||||
all_values = set()
|
||||
for value in self.values:
|
||||
if value.value in all_values:
|
||||
raise Exception("Duplicate value {} in enum {}".format(value.value, name))
|
||||
raise Exception("Duplicate value {} in enum {}".format(
|
||||
value.value, name))
|
||||
all_values.add(value.value)
|
||||
|
||||
|
||||
BitmaskValue = namedtuple('BitmaskValue', ['name', 'value'])
|
||||
|
||||
|
||||
class BitmaskType(Type):
|
||||
def __init__(self, name, json_data):
|
||||
Type.__init__(self, name, json_data)
|
||||
self.values = [BitmaskValue(Name(m['name']), m['value']) for m in self.json_data['values']]
|
||||
self.values = [
|
||||
BitmaskValue(Name(m['name']), m['value'])
|
||||
for m in self.json_data['values']
|
||||
]
|
||||
self.full_mask = 0
|
||||
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)
|
||||
|
||||
|
||||
# Methods and structures are both "records", so record members correspond to
|
||||
# method arguments or structure members.
|
||||
class RecordMember:
|
||||
def __init__(self, name, typ, annotation, optional=False,
|
||||
is_return_value=False, default_value=None,
|
||||
def __init__(self,
|
||||
name,
|
||||
typ,
|
||||
annotation,
|
||||
optional=False,
|
||||
is_return_value=False,
|
||||
default_value=None,
|
||||
skip_serialize=False):
|
||||
self.name = name
|
||||
self.type = typ
|
||||
@@ -138,13 +158,17 @@ class RecordMember:
|
||||
assert self.type.dict_name == "ObjectHandle"
|
||||
self.handle_type = handle_type
|
||||
|
||||
|
||||
Method = namedtuple('Method', ['name', 'return_type', 'arguments'])
|
||||
|
||||
|
||||
class ObjectType(Type):
|
||||
def __init__(self, name, json_data):
|
||||
Type.__init__(self, name, json_data)
|
||||
self.methods = []
|
||||
self.built_type = None
|
||||
|
||||
|
||||
class Record:
|
||||
def __init__(self, name):
|
||||
self.name = Name(name)
|
||||
@@ -160,12 +184,15 @@ class Record:
|
||||
else:
|
||||
return False
|
||||
|
||||
self.may_have_dawn_object = any(may_have_dawn_object(member) for member in self.members)
|
||||
self.may_have_dawn_object = any(
|
||||
may_have_dawn_object(member) for member in self.members)
|
||||
|
||||
# set may_have_dawn_object to true if the type is chained or extensible. Chained structs
|
||||
# may contain a Dawn object.
|
||||
# Set may_have_dawn_object to true if the type is chained or
|
||||
# extensible. Chained structs may contain a Dawn object.
|
||||
if isinstance(self, StructureType):
|
||||
self.may_have_dawn_object = self.may_have_dawn_object or self.chained or self.extensible
|
||||
self.may_have_dawn_object = (self.may_have_dawn_object
|
||||
or self.chained or self.extensible)
|
||||
|
||||
|
||||
class StructureType(Record, Type):
|
||||
def __init__(self, name, json_data):
|
||||
@@ -173,9 +200,11 @@ class StructureType(Record, Type):
|
||||
Type.__init__(self, name, json_data)
|
||||
self.chained = json_data.get("chained", False)
|
||||
self.extensible = json_data.get("extensible", False)
|
||||
# Chained structs inherit from wgpu::ChainedStruct which has nextInChain so setting
|
||||
# both extensible and chained would result in two nextInChain members.
|
||||
assert(not (self.extensible and self.chained))
|
||||
# Chained structs inherit from wgpu::ChainedStruct, which has
|
||||
# nextInChain, so setting both extensible and chained would result in
|
||||
# two nextInChain members.
|
||||
assert not (self.extensible and self.chained)
|
||||
|
||||
|
||||
class Command(Record):
|
||||
def __init__(self, name, members=None):
|
||||
@@ -184,11 +213,13 @@ class Command(Record):
|
||||
self.derived_object = None
|
||||
self.derived_method = None
|
||||
|
||||
|
||||
def linked_record_members(json_data, types):
|
||||
members = []
|
||||
members_by_name = {}
|
||||
for m in json_data:
|
||||
member = RecordMember(Name(m['name']), types[m['type']],
|
||||
member = RecordMember(Name(m['name']),
|
||||
types[m['type']],
|
||||
m.get('annotation', 'value'),
|
||||
optional=m.get('optional', False),
|
||||
is_return_value=m.get('is_return_value', False),
|
||||
@@ -207,7 +238,7 @@ def linked_record_members(json_data, types):
|
||||
member.length = "constant"
|
||||
member.constant_length = 1
|
||||
else:
|
||||
assert(False)
|
||||
assert False
|
||||
elif m['length'] == 'strlen':
|
||||
member.length = 'strlen'
|
||||
else:
|
||||
@@ -215,31 +246,42 @@ def linked_record_members(json_data, types):
|
||||
|
||||
return members
|
||||
|
||||
|
||||
############################################################
|
||||
# PARSE
|
||||
############################################################
|
||||
|
||||
|
||||
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)
|
||||
return Method(Name(json_data['name']),
|
||||
types[json_data.get('returns', 'void')], arguments)
|
||||
|
||||
obj.methods = [make_method(m) for m in obj.json_data.get('methods', [])]
|
||||
obj.methods.sort(key=lambda method: method.name.canonical_case())
|
||||
|
||||
|
||||
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).
|
||||
# It works by computing for each struct type what is the depth of its DAG of dependents, then
|
||||
# resorting based on that depth using Python's stable sort. This makes a toposort because if
|
||||
# A depends on B then its depth will be bigger than B's. It is also nice because all nodes
|
||||
# with the same depth are kept in the input order.
|
||||
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 the sort isn't technically stable).
|
||||
#
|
||||
# It works by computing for each struct type what is the depth of its DAG of
|
||||
# dependents, then resorting based on that depth using Python's stable sort.
|
||||
# This makes a toposort because if A depends on B then its depth will be bigger
|
||||
# than B's. It is also nice because all nodes with the same depth are kept in
|
||||
# the input order.
|
||||
def topo_sort_structure(structs):
|
||||
for struct in structs:
|
||||
struct.visited = False
|
||||
@@ -252,7 +294,8 @@ def topo_sort_structure(structs):
|
||||
max_dependent_depth = 0
|
||||
for member in struct.members:
|
||||
if member.type.category == 'structure':
|
||||
max_dependent_depth = max(max_dependent_depth, compute_depth(member.type) + 1)
|
||||
max_dependent_depth = max(max_dependent_depth,
|
||||
compute_depth(member.type) + 1)
|
||||
|
||||
struct.subdag_depth = max_dependent_depth
|
||||
struct.visited = True
|
||||
@@ -269,6 +312,7 @@ def topo_sort_structure(structs):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def parse_json(json):
|
||||
category_to_parser = {
|
||||
'bitmask': BitmaskType,
|
||||
@@ -303,22 +347,22 @@ def parse_json(json):
|
||||
link_callback(callback, types)
|
||||
|
||||
for category in by_category.keys():
|
||||
by_category[category] = sorted(by_category[category], key=lambda typ: typ.name.canonical_case())
|
||||
by_category[category] = sorted(
|
||||
by_category[category], key=lambda typ: typ.name.canonical_case())
|
||||
|
||||
by_category['structure'] = topo_sort_structure(by_category['structure'])
|
||||
|
||||
for struct in by_category['structure']:
|
||||
struct.update_metadata()
|
||||
|
||||
return {
|
||||
'types': types,
|
||||
'by_category': by_category
|
||||
}
|
||||
return {'types': types, 'by_category': by_category}
|
||||
|
||||
|
||||
############################################################
|
||||
# WIRE STUFF
|
||||
############################################################
|
||||
|
||||
|
||||
# Create wire commands from api methods
|
||||
def compute_wire_params(api_params, wire_json):
|
||||
wire_params = api_params.copy()
|
||||
@@ -327,7 +371,8 @@ def compute_wire_params(api_params, wire_json):
|
||||
commands = []
|
||||
return_commands = []
|
||||
|
||||
wire_json['special items']['client_handwritten_commands'] += wire_json['special items']['client_side_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']:
|
||||
@@ -335,21 +380,33 @@ def compute_wire_params(api_params, wire_json):
|
||||
command_name = concat_names(api_object.name, method.name)
|
||||
command_suffix = Name(command_name).CamelCase()
|
||||
|
||||
# Only object return values or void are supported. Other methods must be handwritten.
|
||||
if method.return_type.category != 'object' and method.return_type.name.canonical_case() != 'void':
|
||||
assert(command_suffix in wire_json['special items']['client_handwritten_commands'])
|
||||
# Only object return values or void are supported.
|
||||
# Other methods must be handwritten.
|
||||
is_object = method.return_type.category == 'object'
|
||||
is_void = method.return_type.name.canonical_case() == 'void'
|
||||
if not (is_object or is_void):
|
||||
assert command_suffix in (
|
||||
wire_json['special items']['client_handwritten_commands'])
|
||||
continue
|
||||
|
||||
if command_suffix in wire_json['special items']['client_side_commands']:
|
||||
if command_suffix in (
|
||||
wire_json['special items']['client_side_commands']):
|
||||
continue
|
||||
|
||||
# Create object method commands by prepending "self"
|
||||
members = [RecordMember(Name('self'), types[api_object.dict_name], 'value')]
|
||||
members = [
|
||||
RecordMember(Name('self'), types[api_object.dict_name],
|
||||
'value')
|
||||
]
|
||||
members += method.arguments
|
||||
|
||||
# Client->Server commands that return an object return the result object handle
|
||||
# Client->Server commands that return an object return the
|
||||
# result object handle
|
||||
if method.return_type.category == 'object':
|
||||
result = RecordMember(Name('result'), types['ObjectHandle'], 'value', is_return_value=True)
|
||||
result = RecordMember(Name('result'),
|
||||
types['ObjectHandle'],
|
||||
'value',
|
||||
is_return_value=True)
|
||||
result.set_handle_type(method.return_type)
|
||||
members.append(result)
|
||||
|
||||
@@ -362,7 +419,8 @@ def compute_wire_params(api_params, wire_json):
|
||||
commands.append(Command(name, linked_record_members(json_data, types)))
|
||||
|
||||
for (name, json_data) in wire_json['return commands'].items():
|
||||
return_commands.append(Command(name, linked_record_members(json_data, types)))
|
||||
return_commands.append(
|
||||
Command(name, linked_record_members(json_data, types)))
|
||||
|
||||
wire_params['cmd_records'] = {
|
||||
'command': commands,
|
||||
@@ -378,12 +436,16 @@ def compute_wire_params(api_params, wire_json):
|
||||
|
||||
return wire_params
|
||||
|
||||
|
||||
#############################################################
|
||||
# Generator
|
||||
#############################################################
|
||||
|
||||
|
||||
def as_varName(*names):
|
||||
return names[0].camelCase() + ''.join([name.CamelCase() for name in names[1:]])
|
||||
return names[0].camelCase() + ''.join(
|
||||
[name.CamelCase() for name in names[1:]])
|
||||
|
||||
|
||||
def as_cType(name):
|
||||
if name.native:
|
||||
@@ -391,27 +453,32 @@ def as_cType(name):
|
||||
else:
|
||||
return 'WGPU' + name.CamelCase()
|
||||
|
||||
|
||||
def as_cTypeDawn(name):
|
||||
if name.native:
|
||||
return name.concatcase()
|
||||
else:
|
||||
return 'Dawn' + name.CamelCase()
|
||||
|
||||
|
||||
def as_cTypeEnumSpecialCase(typ):
|
||||
if typ.category == 'bitmask':
|
||||
return as_cType(typ.name) + 'Flags'
|
||||
return as_cType(typ.name)
|
||||
|
||||
|
||||
def as_cppType(name):
|
||||
if name.native:
|
||||
return name.concatcase()
|
||||
else:
|
||||
return name.CamelCase()
|
||||
|
||||
|
||||
def as_jsEnumValue(value):
|
||||
if value.jsrepr: return value.jsrepr
|
||||
return "'" + value.name.js_enum_case() + "'"
|
||||
|
||||
|
||||
def convert_cType_to_cppType(typ, annotation, arg, indent=0):
|
||||
if typ.category == 'native':
|
||||
return arg
|
||||
@@ -422,18 +489,20 @@ def convert_cType_to_cppType(typ, annotation, arg, indent=0):
|
||||
converted_members = [
|
||||
convert_cType_to_cppType(
|
||||
member.type, member.annotation,
|
||||
'{}.{}'.format(arg, as_varName(member.name)),
|
||||
indent + 1)
|
||||
for member in typ.members]
|
||||
'{}.{}'.format(arg, as_varName(member.name)), indent + 1)
|
||||
for member in typ.members
|
||||
]
|
||||
|
||||
converted_members = [(' ' * 4) + m for m in converted_members ]
|
||||
converted_members = [(' ' * 4) + m for m in converted_members]
|
||||
converted_members = ',\n'.join(converted_members)
|
||||
|
||||
return as_cppType(typ.name) + ' {\n' + converted_members + '\n}'
|
||||
else:
|
||||
return 'static_cast<{}>({})'.format(as_cppType(typ.name), arg)
|
||||
else:
|
||||
return 'reinterpret_cast<{} {}>({})'.format(as_cppType(typ.name), annotation, arg)
|
||||
return 'reinterpret_cast<{} {}>({})'.format(as_cppType(typ.name),
|
||||
annotation, arg)
|
||||
|
||||
|
||||
def decorate(name, typ, arg):
|
||||
if arg.annotation == 'value':
|
||||
@@ -445,46 +514,57 @@ def decorate(name, typ, arg):
|
||||
elif arg.annotation == 'const*const*':
|
||||
return 'const ' + typ + '* const * ' + name
|
||||
else:
|
||||
assert(False)
|
||||
assert False
|
||||
|
||||
|
||||
def annotated(typ, arg):
|
||||
name = as_varName(arg.name)
|
||||
return decorate(name, typ, arg)
|
||||
|
||||
|
||||
def as_cEnum(type_name, value_name):
|
||||
assert(not type_name.native and not value_name.native)
|
||||
assert not type_name.native and not value_name.native
|
||||
return 'WGPU' + type_name.CamelCase() + '_' + value_name.CamelCase()
|
||||
|
||||
|
||||
def as_cEnumDawn(type_name, value_name):
|
||||
assert(not type_name.native and not value_name.native)
|
||||
return 'DAWN' + '_' + type_name.SNAKE_CASE() + '_' + value_name.SNAKE_CASE()
|
||||
assert not type_name.native and not value_name.native
|
||||
return ('DAWN' + '_' + type_name.SNAKE_CASE() + '_' +
|
||||
value_name.SNAKE_CASE())
|
||||
|
||||
|
||||
def as_cppEnum(value_name):
|
||||
assert(not value_name.native)
|
||||
assert not value_name.native
|
||||
if value_name.concatcase()[0].isdigit():
|
||||
return "e" + value_name.CamelCase()
|
||||
return value_name.CamelCase()
|
||||
|
||||
|
||||
def as_cMethod(type_name, method_name):
|
||||
assert(not type_name.native and not method_name.native)
|
||||
assert not type_name.native and not method_name.native
|
||||
return 'wgpu' + type_name.CamelCase() + method_name.CamelCase()
|
||||
|
||||
|
||||
def as_cMethodDawn(type_name, method_name):
|
||||
assert(not type_name.native and not method_name.native)
|
||||
assert not type_name.native and not method_name.native
|
||||
return 'dawn' + type_name.CamelCase() + method_name.CamelCase()
|
||||
|
||||
|
||||
def as_MethodSuffix(type_name, method_name):
|
||||
assert(not type_name.native and not method_name.native)
|
||||
assert not type_name.native and not method_name.native
|
||||
return type_name.CamelCase() + method_name.CamelCase()
|
||||
|
||||
|
||||
def as_cProc(type_name, method_name):
|
||||
assert(not type_name.native and not method_name.native)
|
||||
assert not type_name.native and not method_name.native
|
||||
return 'WGPU' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
|
||||
|
||||
|
||||
def as_cProcDawn(type_name, method_name):
|
||||
assert(not type_name.native and not method_name.native)
|
||||
assert not type_name.native and not method_name.native
|
||||
return 'Dawn' + 'Proc' + type_name.CamelCase() + method_name.CamelCase()
|
||||
|
||||
|
||||
def as_frontendType(typ):
|
||||
if typ.category == 'object':
|
||||
return typ.name.CamelCase() + 'Base*'
|
||||
@@ -495,6 +575,7 @@ def as_frontendType(typ):
|
||||
else:
|
||||
return as_cType(typ.name)
|
||||
|
||||
|
||||
def as_wireType(typ):
|
||||
if typ.category == 'object':
|
||||
return typ.name.CamelCase() + '*'
|
||||
@@ -503,31 +584,50 @@ def as_wireType(typ):
|
||||
else:
|
||||
return as_cppType(typ.name)
|
||||
|
||||
|
||||
def c_methods(types, typ):
|
||||
return typ.methods + [
|
||||
Method(Name('reference'), types['void'], []),
|
||||
Method(Name('release'), types['void'], []),
|
||||
]
|
||||
|
||||
|
||||
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_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.'
|
||||
|
||||
def add_commandline_arguments(self, parser):
|
||||
allowed_targets = ['dawn_headers', 'dawncpp_headers', 'dawncpp', 'dawn_proc', 'mock_webgpu', 'dawn_wire', "dawn_native_utils"]
|
||||
allowed_targets = [
|
||||
'dawn_headers', 'dawncpp_headers', 'dawncpp', 'dawn_proc',
|
||||
'mock_webgpu', 'dawn_wire', "dawn_native_utils"
|
||||
]
|
||||
|
||||
parser.add_argument('--dawn-json', required=True, type=str, help ='The DAWN JSON definition to use.')
|
||||
parser.add_argument('--wire-json', default=None, type=str, help='The DAWN WIRE JSON definition to use.')
|
||||
parser.add_argument('--targets', required=True, type=str, help='Comma-separated subset of targets to output. Available targets: ' + ', '.join(allowed_targets))
|
||||
parser.add_argument('--dawn-json',
|
||||
required=True,
|
||||
type=str,
|
||||
help='The DAWN JSON definition to use.')
|
||||
parser.add_argument('--wire-json',
|
||||
default=None,
|
||||
type=str,
|
||||
help='The DAWN WIRE JSON definition to use.')
|
||||
parser.add_argument(
|
||||
'--targets',
|
||||
required=True,
|
||||
type=str,
|
||||
help=
|
||||
'Comma-separated subset of targets to output. Available targets: '
|
||||
+ ', '.join(allowed_targets))
|
||||
|
||||
def get_file_renders(self, args):
|
||||
with open(args.dawn_json) as f:
|
||||
@@ -543,9 +643,10 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||
|
||||
base_params = {
|
||||
'Name': lambda name: Name(name),
|
||||
|
||||
'as_annotated_cType': lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg),
|
||||
'as_annotated_cppType': lambda arg: annotated(as_cppType(arg.type.name), arg),
|
||||
'as_annotated_cType': \
|
||||
lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg),
|
||||
'as_annotated_cppType': \
|
||||
lambda arg: annotated(as_cppType(arg.type.name), arg),
|
||||
'as_cEnum': as_cEnum,
|
||||
'as_cEnumDawn': as_cEnumDawn,
|
||||
'as_cppEnum': as_cppEnum,
|
||||
@@ -562,78 +663,145 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||
'as_varName': as_varName,
|
||||
'decorate': decorate,
|
||||
'c_methods': lambda typ: c_methods(api_params['types'], typ),
|
||||
'c_methods_sorted_by_name': get_c_methods_sorted_by_name(api_params),
|
||||
'c_methods_sorted_by_name': \
|
||||
get_c_methods_sorted_by_name(api_params),
|
||||
}
|
||||
|
||||
renders = []
|
||||
|
||||
if 'dawn_headers' in targets:
|
||||
renders.append(FileRender('webgpu.h', 'src/include/dawn/webgpu.h', [base_params, api_params]))
|
||||
renders.append(FileRender('dawn_proc_table.h', 'src/include/dawn/dawn_proc_table.h', [base_params, api_params]))
|
||||
renders.append(
|
||||
FileRender('webgpu.h', 'src/include/dawn/webgpu.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]))
|
||||
renders.append(
|
||||
FileRender('webgpu_cpp.h', 'src/include/dawn/webgpu_cpp.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]))
|
||||
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]))
|
||||
renders.append(
|
||||
FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp',
|
||||
[base_params, api_params]))
|
||||
|
||||
if 'emscripten_bits' in targets:
|
||||
renders.append(FileRender('webgpu_struct_info.json', 'src/dawn/webgpu_struct_info.json', [base_params, api_params]))
|
||||
renders.append(FileRender('library_webgpu_enum_tables.js', 'src/dawn/library_webgpu_enum_tables.js', [base_params, api_params]))
|
||||
renders.append(
|
||||
FileRender('webgpu_struct_info.json',
|
||||
'src/dawn/webgpu_struct_info.json',
|
||||
[base_params, api_params]))
|
||||
renders.append(
|
||||
FileRender('library_webgpu_enum_tables.js',
|
||||
'src/dawn/library_webgpu_enum_tables.js',
|
||||
[base_params, api_params]))
|
||||
|
||||
if 'mock_webgpu' in targets:
|
||||
mock_params = [
|
||||
base_params,
|
||||
api_params,
|
||||
{
|
||||
base_params, api_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))
|
||||
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 = [
|
||||
base_params,
|
||||
api_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)
|
||||
# TODO: as_frontendType and co. take a Type, not a Name :(
|
||||
'as_frontendType': lambda typ: as_frontendType(typ),
|
||||
'as_annotated_frontendType': \
|
||||
lambda arg: annotated(as_frontendType(arg.type), arg),
|
||||
}
|
||||
]
|
||||
|
||||
renders.append(FileRender('dawn_native/ValidationUtils.h', 'src/dawn_native/ValidationUtils_autogen.h', frontend_params))
|
||||
renders.append(FileRender('dawn_native/ValidationUtils.cpp', 'src/dawn_native/ValidationUtils_autogen.cpp', frontend_params))
|
||||
renders.append(FileRender('dawn_native/wgpu_structs.h', 'src/dawn_native/wgpu_structs_autogen.h', frontend_params))
|
||||
renders.append(FileRender('dawn_native/wgpu_structs.cpp', 'src/dawn_native/wgpu_structs_autogen.cpp', frontend_params))
|
||||
renders.append(FileRender('dawn_native/ProcTable.cpp', 'src/dawn_native/ProcTable.cpp', frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/ValidationUtils.h',
|
||||
'src/dawn_native/ValidationUtils_autogen.h',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/ValidationUtils.cpp',
|
||||
'src/dawn_native/ValidationUtils_autogen.cpp',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/wgpu_structs.h',
|
||||
'src/dawn_native/wgpu_structs_autogen.h',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/wgpu_structs.cpp',
|
||||
'src/dawn_native/wgpu_structs_autogen.cpp',
|
||||
frontend_params))
|
||||
renders.append(
|
||||
FileRender('dawn_native/ProcTable.cpp',
|
||||
'src/dawn_native/ProcTable.cpp', frontend_params))
|
||||
|
||||
if 'dawn_wire' in targets:
|
||||
additional_params = compute_wire_params(api_params, wire_json)
|
||||
|
||||
wire_params = [
|
||||
base_params,
|
||||
api_params,
|
||||
{
|
||||
base_params, api_params, {
|
||||
'as_wireType': as_wireType,
|
||||
'as_annotated_wireType': lambda arg: annotated(as_wireType(arg.type), arg),
|
||||
},
|
||||
additional_params
|
||||
'as_annotated_wireType': \
|
||||
lambda arg: annotated(as_wireType(arg.type), arg),
|
||||
}, additional_params
|
||||
]
|
||||
renders.append(FileRender('dawn_wire/WireCmd.h', 'src/dawn_wire/WireCmd_autogen.h', wire_params))
|
||||
renders.append(FileRender('dawn_wire/WireCmd.cpp', 'src/dawn_wire/WireCmd_autogen.cpp', wire_params))
|
||||
renders.append(FileRender('dawn_wire/client/ApiObjects.h', 'src/dawn_wire/client/ApiObjects_autogen.h', wire_params))
|
||||
renders.append(FileRender('dawn_wire/client/ApiProcs.cpp', 'src/dawn_wire/client/ApiProcs_autogen.cpp', wire_params))
|
||||
renders.append(FileRender('dawn_wire/client/ClientBase.h', 'src/dawn_wire/client/ClientBase_autogen.h', wire_params))
|
||||
renders.append(FileRender('dawn_wire/client/ClientHandlers.cpp', 'src/dawn_wire/client/ClientHandlers_autogen.cpp', wire_params))
|
||||
renders.append(FileRender('dawn_wire/client/ClientPrototypes.inc', 'src/dawn_wire/client/ClientPrototypes_autogen.inc', wire_params))
|
||||
renders.append(FileRender('dawn_wire/server/ServerBase.h', 'src/dawn_wire/server/ServerBase_autogen.h', wire_params))
|
||||
renders.append(FileRender('dawn_wire/server/ServerDoers.cpp', 'src/dawn_wire/server/ServerDoers_autogen.cpp', wire_params))
|
||||
renders.append(FileRender('dawn_wire/server/ServerHandlers.cpp', 'src/dawn_wire/server/ServerHandlers_autogen.cpp', wire_params))
|
||||
renders.append(FileRender('dawn_wire/server/ServerPrototypes.inc', 'src/dawn_wire/server/ServerPrototypes_autogen.inc', wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/WireCmd.h',
|
||||
'src/dawn_wire/WireCmd_autogen.h', wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/WireCmd.cpp',
|
||||
'src/dawn_wire/WireCmd_autogen.cpp', wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/client/ApiObjects.h',
|
||||
'src/dawn_wire/client/ApiObjects_autogen.h',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/client/ApiProcs.cpp',
|
||||
'src/dawn_wire/client/ApiProcs_autogen.cpp',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/client/ClientBase.h',
|
||||
'src/dawn_wire/client/ClientBase_autogen.h',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/client/ClientHandlers.cpp',
|
||||
'src/dawn_wire/client/ClientHandlers_autogen.cpp',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender(
|
||||
'dawn_wire/client/ClientPrototypes.inc',
|
||||
'src/dawn_wire/client/ClientPrototypes_autogen.inc',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/server/ServerBase.h',
|
||||
'src/dawn_wire/server/ServerBase_autogen.h',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/server/ServerDoers.cpp',
|
||||
'src/dawn_wire/server/ServerDoers_autogen.cpp',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender('dawn_wire/server/ServerHandlers.cpp',
|
||||
'src/dawn_wire/server/ServerHandlers_autogen.cpp',
|
||||
wire_params))
|
||||
renders.append(
|
||||
FileRender(
|
||||
'dawn_wire/server/ServerPrototypes.inc',
|
||||
'src/dawn_wire/server/ServerPrototypes_autogen.inc',
|
||||
wire_params))
|
||||
|
||||
return renders
|
||||
|
||||
@@ -643,5 +811,6 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||
deps += [os.path.abspath(args.wire_json)]
|
||||
return deps
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(run_generator(MultiGeneratorFromDawnJSON()))
|
||||
|
||||
Reference in New Issue
Block a user