From 919812ed1c25b9aba8fcf182de96b91181e4cfb0 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 17 Oct 2019 08:46:07 +0000 Subject: [PATCH] Use webgpu.h's bitmask type definitions. BUG=dawn:22 Change-Id: Ib7cf75a1411a6ed86cc5abb1218beb924dbb9001 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12260 Reviewed-by: Kai Ninomiya Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- generator/dawn_json_generator.py | 7 ++++++- generator/templates/api.h | 5 +++++ generator/templates/apicpp.cpp | 15 ++++++++++++++- generator/templates/dawn_wire/WireCmd.cpp | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 0d37a3365e..9f52d9526c 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -354,6 +354,11 @@ def as_cType(name): else: return 'Dawn' + name.CamelCase() +def as_cTypeEnumSpecialCase(typ): + if typ.category == 'bitmask': + return as_cType(typ.name) + 'Flags' + return as_cType(typ.name) + def as_cppType(name): if name.native: return name.concatcase() @@ -480,7 +485,7 @@ class MultiGeneratorFromDawnJSON(Generator): base_params = { 'Name': lambda name: Name(name), - 'as_annotated_cType': lambda arg: annotated(as_cType(arg.type.name), arg), + 'as_annotated_cType': lambda arg: annotated(as_cTypeEnumSpecialCase(arg.type), arg), 'as_annotated_cppType': lambda arg: annotated(as_cppType(arg.type.name), arg), 'as_cEnum': as_cEnum, 'as_cppEnum': as_cppEnum, diff --git a/generator/templates/api.h b/generator/templates/api.h index bb71141c23..3782fa7eb2 100644 --- a/generator/templates/api.h +++ b/generator/templates/api.h @@ -23,6 +23,8 @@ const uint64_t DAWN_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX +typedef uint32_t WGPUFlags; + {% for type in by_category["object"] %} typedef struct {{as_cType(type.name)}}Impl* {{as_cType(type.name)}}; {% endfor %} @@ -34,6 +36,9 @@ const uint64_t DAWN_WHOLE_SIZE = 0xffffffffffffffffULL; // UINT64_MAX {% endfor %} {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF } {{as_cType(type.name)}}; + {% if type.category == "bitmask" %} + typedef WGPUFlags {{as_cType(type.name)}}Flags; + {% endif %} {% endfor %} diff --git a/generator/templates/apicpp.cpp b/generator/templates/apicpp.cpp index b43fb4fe8e..ca2724c632 100644 --- a/generator/templates/apicpp.cpp +++ b/generator/templates/apicpp.cpp @@ -16,7 +16,7 @@ namespace dawn { - {% for type in by_category["enum"] + by_category["bitmask"] %} + {% for type in by_category["enum"] %} {% set CppType = as_cppType(type.name) %} {% set CType = as_cType(type.name) %} @@ -29,6 +29,19 @@ namespace dawn { {% endfor %} + {% for type in by_category["bitmask"] %} + {% set CppType = as_cppType(type.name) %} + {% set CType = as_cType(type.name) + "Flags" %} + + static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}"); + static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}"); + + {% for value in type.values %} + static_assert(static_cast({{CppType}}::{{as_cppEnum(value.name)}}) == {{as_cEnum(type.name, value.name)}}, "value mismatch for {{CppType}}::{{as_cppEnum(value.name)}}"); + {% endfor %} + + {% endfor %} + {% for type in by_category["structure"] %} {% set CppType = as_cppType(type.name) %} {% set CType = as_cType(type.name) %} diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index 731751f502..e693349e30 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -37,6 +37,8 @@ ObjectId {%- elif member.type.category == "structure" -%} {{as_cType(member.type.name)}}Transfer + {%- elif member.type.category == "bitmask" -%} + {{as_cType(member.type.name)}}Flags {%- else -%} {{as_cType(member.type.name)}} {%- endif -%}