Add ability to generate typedefs from dawn.json
Can be used to help with deprecation during simple struct renames.
Includes typedefs for VertexAttributeDescriptor -> VertexAttribute and
VertexBufferLayoutDescriptor -> VertexBufferLayout as specified by the
latest RenderPipelineDescriptor changes.
Bug: dawn:642
Change-Id: Iab3d74d179884499540e813b0e66859713031ccb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/40581
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 01d7040..8af2272 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -128,6 +128,12 @@
self.arguments = []
+class TypedefType(Type):
+ def __init__(self, name, json_data):
+ Type.__init__(self, name, json_data)
+ self.type = None
+
+
class NativeType(Type):
def __init__(self, name, json_data):
Type.__init__(self, name, json_data, native=True)
@@ -271,6 +277,10 @@
types)
+def link_typedef(typedef, types):
+ typedef.type = types[typedef.json_data['type']]
+
+
# Sort structures so that if struct A has struct B as a member, then B is
# listed before A.
#
@@ -321,6 +331,7 @@
'callback': CallbackType,
'object': ObjectType,
'structure': StructureType,
+ 'typedef': TypedefType,
}
types = {}
@@ -346,6 +357,9 @@
for callback in by_category['callback']:
link_callback(callback, types)
+ for typedef in by_category['typedef']:
+ link_typedef(typedef, types)
+
for category in by_category.keys():
by_category[category] = sorted(
by_category[category], key=lambda typ: typ.name.canonical_case())
diff --git a/generator/templates/dawn_native/wgpu_structs.h b/generator/templates/dawn_native/wgpu_structs.h
index 3e267cb..0bffebb 100644
--- a/generator/templates/dawn_native/wgpu_structs.h
+++ b/generator/templates/dawn_native/wgpu_structs.h
@@ -64,6 +64,10 @@
{% endfor %}
+ {% for typeDef in by_category["typedef"] %}
+ using {{as_cppType(typeDef.name)}} = {{as_cppType(typeDef.type.name)}};
+ {% endfor %}
+
} // namespace dawn_native
#endif // DAWNNATIVE_WGPU_STRUCTS_H_
diff --git a/generator/templates/webgpu.h b/generator/templates/webgpu.h
index 7704707..c44fa39 100644
--- a/generator/templates/webgpu.h
+++ b/generator/templates/webgpu.h
@@ -117,6 +117,13 @@
{% endfor %}
+{% for typeDef in by_category["typedef"] %}
+ // {{as_cType(typeDef.name)}} is deprecated.
+ // Use {{as_cType(typeDef.type.name)}} instead.
+ typedef {{as_cType(typeDef.type.name)}} {{as_cType(typeDef.name)}};
+
+{% endfor %}
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/generator/templates/webgpu_cpp.h b/generator/templates/webgpu_cpp.h
index 3e6b80c..40b804f 100644
--- a/generator/templates/webgpu_cpp.h
+++ b/generator/templates/webgpu_cpp.h
@@ -63,6 +63,13 @@
struct {{as_cppType(type.name)}};
{% endfor %}
+ {% for typeDef in by_category["typedef"] %}
+ // {{as_cppType(typeDef.name)}} is deprecated.
+ // Use {{as_cppType(typeDef.type.name)}} instead.
+ using {{as_cppType(typeDef.name)}} = {{as_cppType(typeDef.type.name)}};
+
+ {% endfor %}
+
template<typename Derived, typename CType>
class ObjectBase {
public: