diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 60dfbe7f10..6a89240467 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -242,6 +242,21 @@ class StructureType(Record, Type): # two nextInChain members. assert not (self.extensible and self.chained) + def update_metadata(self): + Record.update_metadata(self) + + if self.may_have_dawn_object: + self.is_wire_transparent = False + return + + assert not (self.chained or self.extensible) + + def get_is_wire_transparent(member): + return member.type.is_wire_transparent and member.annotation == 'value' + + self.is_wire_transparent = all( + get_is_wire_transparent(m) for m in self.members) + @property def output(self): return self.chained == "out" or self.extensible == "out" diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index 0eb1bd1aa3..7bc148f6df 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -63,9 +63,14 @@ {%- if member.type.category == "object" -%} {%- set Optional = "Optional" if member.optional else "" -%} WIRE_TRY(provider.Get{{Optional}}Id({{in}}, &{{out}})); - {% elif member.type.category == "structure"%} - {%- set Provider = ", provider" if member.type.may_have_dawn_object else "" -%} - WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}})); + {%- elif member.type.category == "structure" -%} + {%- if member.type.is_wire_transparent -%} + static_assert(sizeof({{out}}) == sizeof({{in}}), "Serialize memcpy size must match."); + memcpy(&{{out}}, &{{in}}, {{member_transfer_sizeof(member)}}); + {%- else -%} + {%- set Provider = ", provider" if member.type.may_have_dawn_object else "" -%} + WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}})); + {%- endif -%} {%- else -%} {{out}} = {{in}}; {%- endif -%} @@ -77,11 +82,16 @@ {%- set Optional = "Optional" if member.optional else "" -%} WIRE_TRY(resolver.Get{{Optional}}FromId({{in}}, &{{out}})); {%- elif member.type.category == "structure" -%} - WIRE_TRY({{as_cType(member.type.name)}}Deserialize(&{{out}}, &{{in}}, deserializeBuffer, allocator - {%- if member.type.may_have_dawn_object -%} - , resolver - {%- endif -%} - )); + {%- if member.type.is_wire_transparent -%} + static_assert(sizeof({{out}}) == sizeof({{in}}), "Deserialize memcpy size must match."); + memcpy(&{{out}}, const_cast(&{{in}}), {{member_transfer_sizeof(member)}}); + {%- else -%} + WIRE_TRY({{as_cType(member.type.name)}}Deserialize(&{{out}}, &{{in}}, deserializeBuffer, allocator + {%- if member.type.may_have_dawn_object -%} + , resolver + {%- endif -%} + )); + {%- endif -%} {%- else -%} static_assert(sizeof({{out}}) >= sizeof({{in}}), "Deserialize assignment may not narrow."); {{out}} = {{in}};