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>
This commit is contained in:
Brandon Jones 2021-02-08 19:48:06 +00:00 committed by Commit Bot service account
parent 734e88b2e7
commit 58a471ae25
5 changed files with 44 additions and 4 deletions

View File

@ -954,7 +954,7 @@
"extensible": true, "extensible": true,
"members": [] "members": []
}, },
"vertex attribute descriptor": { "vertex attribute": {
"category": "structure", "category": "structure",
"extensible": false, "extensible": false,
"members": [ "members": [
@ -963,23 +963,31 @@
{"name": "shader location", "type": "uint32_t"} {"name": "shader location", "type": "uint32_t"}
] ]
}, },
"vertex buffer layout descriptor": { "vertex attribute descriptor": {
"category": "typedef",
"type": "vertex attribute"
},
"vertex buffer layout": {
"category": "structure", "category": "structure",
"extensible": false, "extensible": false,
"members": [ "members": [
{"name": "array stride", "type": "uint64_t"}, {"name": "array stride", "type": "uint64_t"},
{"name": "step mode", "type": "input step mode", "default": "vertex"}, {"name": "step mode", "type": "input step mode", "default": "vertex"},
{"name": "attribute count", "type": "uint32_t"}, {"name": "attribute count", "type": "uint32_t"},
{"name": "attributes", "type": "vertex attribute descriptor", "annotation": "const*", "length": "attribute count"} {"name": "attributes", "type": "vertex attribute", "annotation": "const*", "length": "attribute count"}
] ]
}, },
"vertex buffer layout descriptor": {
"category": "typedef",
"type": "vertex buffer layout"
},
"vertex state descriptor": { "vertex state descriptor": {
"category": "structure", "category": "structure",
"extensible": true, "extensible": true,
"members": [ "members": [
{"name": "index format", "type": "index format", "default": "undefined"}, {"name": "index format", "type": "index format", "default": "undefined"},
{"name": "vertex buffer count", "type": "uint32_t", "default": 0}, {"name": "vertex buffer count", "type": "uint32_t", "default": 0},
{"name": "vertex buffers", "type": "vertex buffer layout descriptor", "annotation": "const*", "length": "vertex buffer count"} {"name": "vertex buffers", "type": "vertex buffer layout", "annotation": "const*", "length": "vertex buffer count"}
] ]
}, },
"input step mode": { "input step mode": {

View File

@ -128,6 +128,12 @@ class CallbackType(Type):
self.arguments = [] self.arguments = []
class TypedefType(Type):
def __init__(self, name, json_data):
Type.__init__(self, name, json_data)
self.type = None
class NativeType(Type): class NativeType(Type):
def __init__(self, name, json_data): def __init__(self, name, json_data):
Type.__init__(self, name, json_data, native=True) Type.__init__(self, name, json_data, native=True)
@ -271,6 +277,10 @@ def link_callback(callback, types):
types) 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 # Sort structures so that if struct A has struct B as a member, then B is
# listed before A. # listed before A.
# #
@ -321,6 +331,7 @@ def parse_json(json):
'callback': CallbackType, 'callback': CallbackType,
'object': ObjectType, 'object': ObjectType,
'structure': StructureType, 'structure': StructureType,
'typedef': TypedefType,
} }
types = {} types = {}
@ -346,6 +357,9 @@ def parse_json(json):
for callback in by_category['callback']: for callback in by_category['callback']:
link_callback(callback, types) link_callback(callback, types)
for typedef in by_category['typedef']:
link_typedef(typedef, types)
for category in by_category.keys(): for category in by_category.keys():
by_category[category] = sorted( by_category[category] = sorted(
by_category[category], key=lambda typ: typ.name.canonical_case()) by_category[category], key=lambda typ: typ.name.canonical_case())

View File

@ -64,6 +64,10 @@ namespace dawn_native {
{% endfor %} {% endfor %}
{% for typeDef in by_category["typedef"] %}
using {{as_cppType(typeDef.name)}} = {{as_cppType(typeDef.type.name)}};
{% endfor %}
} // namespace dawn_native } // namespace dawn_native
#endif // DAWNNATIVE_WGPU_STRUCTS_H_ #endif // DAWNNATIVE_WGPU_STRUCTS_H_

View File

@ -117,6 +117,13 @@ typedef struct WGPUChainedStruct {
{% endfor %} {% 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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -63,6 +63,13 @@ namespace wgpu {
struct {{as_cppType(type.name)}}; struct {{as_cppType(type.name)}};
{% endfor %} {% 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> template<typename Derived, typename CType>
class ObjectBase { class ObjectBase {
public: public: