• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //* Copyright 2018 The Dawn Authors
2 //*
3 //* Licensed under the Apache License, Version 2.0 (the "License");
4 //* you may not use this file except in compliance with the License.
5 //* You may obtain a copy of the License at
6 //*
7 //*     http://www.apache.org/licenses/LICENSE-2.0
8 //*
9 //* Unless required by applicable law or agreed to in writing, software
10 //* distributed under the License is distributed on an "AS IS" BASIS,
11 //* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //* See the License for the specific language governing permissions and
13 //* limitations under the License.
14 
15 #include "dawn_native/wgpu_structs_autogen.h"
16 
17 #include <tuple>
18 
19 #ifdef __GNUC__
20 // error: 'offsetof' within non-standard-layout type 'wgpu::XXX' is conditionally-supported
21 #pragma GCC diagnostic ignored "-Winvalid-offsetof"
22 #endif
23 
24 namespace dawn_native {
25 
26     static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct),
27             "sizeof mismatch for ChainedStruct");
28     static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct),
29             "alignof mismatch for ChainedStruct");
30     static_assert(offsetof(ChainedStruct, nextInChain) == offsetof(WGPUChainedStruct, next),
31             "offsetof mismatch for ChainedStruct::nextInChain");
32     static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType),
33             "offsetof mismatch for ChainedStruct::sType");
34 
35     {% for type in by_category["structure"] %}
36         {% set CppType = as_cppType(type.name) %}
37         {% set CType = as_cType(type.name) %}
38 
39         static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
40         static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
41 
42         {% if type.extensible %}
43             static_assert(offsetof({{CppType}}, nextInChain) == offsetof({{CType}}, nextInChain),
44                     "offsetof mismatch for {{CppType}}::nextInChain");
45         {% endif %}
46         {% for member in type.members %}
47             {% set memberName = member.name.camelCase() %}
48             static_assert(offsetof({{CppType}}, {{memberName}}) == offsetof({{CType}}, {{memberName}}),
49                     "offsetof mismatch for {{CppType}}::{{memberName}}");
50         {% endfor %}
51 
52         bool {{CppType}}::operator==(const {{as_cppType(type.name)}}& rhs) const {
53             return {% if type.extensible or type.chained -%}
54                 (nextInChain == rhs.nextInChain) &&
55             {%- endif %} std::tie(
56                 {% for member in type.members %}
57                     {{member.name.camelCase()-}}
58                     {{ "," if not loop.last else "" }}
59                 {% endfor %}
60             ) == std::tie(
61                 {% for member in type.members %}
62                     rhs.{{member.name.camelCase()-}}
63                     {{ "," if not loop.last else "" }}
64                 {% endfor %}
65             );
66         }
67 
68     {% endfor %}
69 }
70