dawn.json: Add the "chain roots" data for chained structs.

This helps output in the headers information about which structure can
be used to extend which. In the future it could also be used to generate
helpers that validate that the chain for a root structure contains only
allowed extension structs.

Fixed: dawn:1486
Change-Id: I6134332d477503e242b3bec9f8e9bedeeb352351
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96000
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2022-07-14 12:58:25 +00:00
committed by Dawn LUCI CQ
parent e1bcb0b416
commit a45561bb8c
5 changed files with 36 additions and 5 deletions

View File

@@ -237,12 +237,13 @@ class StructureType(Record, Type):
m for m in json_data['members'] if is_enabled(m)
]
Type.__init__(self, name, dict(json_data, **json_data_override))
self.chained = json_data.get("chained", None)
self.extensible = json_data.get("extensible", None)
self.chained = json_data.get('chained', None)
self.extensible = json_data.get('extensible', None)
if self.chained:
assert (self.chained == "in" or self.chained == "out")
assert self.chained == 'in' or self.chained == 'out'
assert 'chain roots' in json_data
if self.extensible:
assert (self.extensible == "in" or self.extensible == "out")
assert self.extensible == 'in' or self.extensible == 'out'
# Chained structs inherit from wgpu::ChainedStruct, which has
# nextInChain, so setting both extensible and chained would result in
# two nextInChain members.
@@ -348,6 +349,8 @@ def link_object(obj, types):
def link_structure(struct, types):
struct.members = linked_record_members(struct.json_data['members'], types)
struct.chain_roots = [types[root] for root in struct.json_data.get('chain roots', [])]
assert all((root.category == 'structure' for root in struct.chain_roots))
def link_function_pointer(function_pointer, types):

View File

@@ -89,6 +89,9 @@ typedef struct {{c_prefix}}ChainedStructOut {
} {{c_prefix}}ChainedStructOut;
{% for type in by_category["structure"] %}
{% for root in type.chain_roots %}
// Can be chained in {{as_cType(root.name)}}
{% endfor %}
typedef struct {{as_cType(type.name)}} {
{% set Out = "Out" if type.output else "" %}
{% set const = "const " if not type.output else "" %}

View File

@@ -225,6 +225,9 @@ namespace {{metadata.namespace}} {
{% set Out = "Out" if type.output else "" %}
{% set const = "const" if not type.output else "" %}
{% if type.chained %}
{% for root in type.chain_roots %}
// Can be chained in {{as_cppType(root.name)}}
{% endfor %}
struct {{as_cppType(type.name)}} : ChainedStruct{{Out}} {
{{as_cppType(type.name)}}() {
sType = SType::{{type.name.CamelCase()}};