dawn_wire: use memcpy on structures when possible

This patch sets 'is_wire_transparent' on the structures whose members
are all wire transparent and are not pointers, so that we can use
memcpy when serializing and deserializing these structures:
- GPUBlendComponent
- GPUColor
- GPUExtent3D
- GPULimits
- GPUOrigin3D
- GPUStencilFaceState
- GPUVertexAttribute
- GPUBlendState

In the next patch we will support memcpy on the qualified structures
whose members contain pointers (e.g. GPUVertexBufferLayout).

BUG=chromium:1266727

Change-Id: If46289f2d10cc7b17e6f5330cd2c2d4dc481f8b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/73000
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2021-12-21 04:04:51 +00:00 committed by Dawn LUCI CQ
parent b9467591a4
commit 1fa386cc87
2 changed files with 33 additions and 8 deletions

View File

@ -242,6 +242,21 @@ class StructureType(Record, Type):
# two nextInChain members. # two nextInChain members.
assert not (self.extensible and self.chained) 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 @property
def output(self): def output(self):
return self.chained == "out" or self.extensible == "out" return self.chained == "out" or self.extensible == "out"

View File

@ -63,9 +63,14 @@
{%- if member.type.category == "object" -%} {%- if member.type.category == "object" -%}
{%- set Optional = "Optional" if member.optional else "" -%} {%- set Optional = "Optional" if member.optional else "" -%}
WIRE_TRY(provider.Get{{Optional}}Id({{in}}, &{{out}})); WIRE_TRY(provider.Get{{Optional}}Id({{in}}, &{{out}}));
{% elif member.type.category == "structure"%} {%- 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 "" -%} {%- set Provider = ", provider" if member.type.may_have_dawn_object else "" -%}
WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}})); WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}}));
{%- endif -%}
{%- else -%} {%- else -%}
{{out}} = {{in}}; {{out}} = {{in}};
{%- endif -%} {%- endif -%}
@ -77,11 +82,16 @@
{%- set Optional = "Optional" if member.optional else "" -%} {%- set Optional = "Optional" if member.optional else "" -%}
WIRE_TRY(resolver.Get{{Optional}}FromId({{in}}, &{{out}})); WIRE_TRY(resolver.Get{{Optional}}FromId({{in}}, &{{out}}));
{%- elif member.type.category == "structure" -%} {%- elif member.type.category == "structure" -%}
{%- if member.type.is_wire_transparent -%}
static_assert(sizeof({{out}}) == sizeof({{in}}), "Deserialize memcpy size must match.");
memcpy(&{{out}}, const_cast<const {{member_transfer_type(member)}}*>(&{{in}}), {{member_transfer_sizeof(member)}});
{%- else -%}
WIRE_TRY({{as_cType(member.type.name)}}Deserialize(&{{out}}, &{{in}}, deserializeBuffer, allocator WIRE_TRY({{as_cType(member.type.name)}}Deserialize(&{{out}}, &{{in}}, deserializeBuffer, allocator
{%- if member.type.may_have_dawn_object -%} {%- if member.type.may_have_dawn_object -%}
, resolver , resolver
{%- endif -%} {%- endif -%}
)); ));
{%- endif -%}
{%- else -%} {%- else -%}
static_assert(sizeof({{out}}) >= sizeof({{in}}), "Deserialize assignment may not narrow."); static_assert(sizeof({{out}}) >= sizeof({{in}}), "Deserialize assignment may not narrow.");
{{out}} = {{in}}; {{out}} = {{in}};