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:
parent
734e88b2e7
commit
58a471ae25
16
dawn.json
16
dawn.json
|
@ -954,7 +954,7 @@
|
|||
"extensible": true,
|
||||
"members": []
|
||||
},
|
||||
"vertex attribute descriptor": {
|
||||
"vertex attribute": {
|
||||
"category": "structure",
|
||||
"extensible": false,
|
||||
"members": [
|
||||
|
@ -963,23 +963,31 @@
|
|||
{"name": "shader location", "type": "uint32_t"}
|
||||
]
|
||||
},
|
||||
"vertex buffer layout descriptor": {
|
||||
"vertex attribute descriptor": {
|
||||
"category": "typedef",
|
||||
"type": "vertex attribute"
|
||||
},
|
||||
"vertex buffer layout": {
|
||||
"category": "structure",
|
||||
"extensible": false,
|
||||
"members": [
|
||||
{"name": "array stride", "type": "uint64_t"},
|
||||
{"name": "step mode", "type": "input step mode", "default": "vertex"},
|
||||
{"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": {
|
||||
"category": "structure",
|
||||
"extensible": true,
|
||||
"members": [
|
||||
{"name": "index format", "type": "index format", "default": "undefined"},
|
||||
{"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": {
|
||||
|
|
|
@ -128,6 +128,12 @@ class CallbackType(Type):
|
|||
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 @@ def link_callback(callback, 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
|
||||
# listed before A.
|
||||
#
|
||||
|
@ -321,6 +331,7 @@ def parse_json(json):
|
|||
'callback': CallbackType,
|
||||
'object': ObjectType,
|
||||
'structure': StructureType,
|
||||
'typedef': TypedefType,
|
||||
}
|
||||
|
||||
types = {}
|
||||
|
@ -346,6 +357,9 @@ def parse_json(json):
|
|||
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())
|
||||
|
|
|
@ -64,6 +64,10 @@ namespace dawn_native {
|
|||
|
||||
{% 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_
|
||||
|
|
|
@ -117,6 +117,13 @@ typedef struct WGPUChainedStruct {
|
|||
|
||||
{% 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
|
||||
|
|
|
@ -63,6 +63,13 @@ namespace wgpu {
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue