• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //* Copyright 2017 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 #ifndef DAWNNATIVE_WGPU_STRUCTS_H_
16 #define DAWNNATIVE_WGPU_STRUCTS_H_
17 
18 #include "dawn/webgpu_cpp.h"
19 #include "dawn_native/Forward.h"
20 
21 namespace dawn_native {
22 
23 {% macro render_cpp_default_value(member) -%}
24     {%- if member.annotation in ["*", "const*"] and member.optional -%}
25         {{" "}}= nullptr
26     {%- elif member.type.category == "object" and member.optional -%}
27         {{" "}}= nullptr
28     {%- elif member.type.category in ["enum", "bitmask"] and member.default_value != None -%}
29         {{" "}}= wgpu::{{as_cppType(member.type.name)}}::{{as_cppEnum(Name(member.default_value))}}
30     {%- elif member.type.category == "native" and member.default_value != None -%}
31         {{" "}}= {{member.default_value}}
32     {%- else -%}
33         {{assert(member.default_value == None)}}
34     {%- endif -%}
35 {%- endmacro %}
36 
37     struct ChainedStruct {
38         ChainedStruct const * nextInChain = nullptr;
39         wgpu::SType sType = wgpu::SType::Invalid;
40     };
41 
42     {% for type in by_category["structure"] %}
43         {% if type.chained %}
44             struct {{as_cppType(type.name)}} : ChainedStruct {
45                 {{as_cppType(type.name)}}() {
46                     sType = wgpu::SType::{{type.name.CamelCase()}};
47                 }
48         {% else %}
49             struct {{as_cppType(type.name)}} {
50         {% endif %}
51             {% if type.extensible %}
52                 ChainedStruct const * nextInChain = nullptr;
53             {% endif %}
54             {% for member in type.members %}
55                 {% set member_declaration = as_annotated_frontendType(member) + render_cpp_default_value(member) %}
56                 {% if type.chained and loop.first %}
57                     //* Align the first member to ChainedStruct to match the C struct layout.
58                     alignas(ChainedStruct) {{member_declaration}};
59                 {% else %}
60                     {{member_declaration}};
61                 {% endif %}
62             {% endfor %}
63 
64             // Equality operators, mostly for testing. Note that this tests
65             // strict pointer-pointer equality if the struct contains member pointers.
66             bool operator==(const {{as_cppType(type.name)}}& rhs) const;
67         };
68 
69     {% endfor %}
70 
71     {% for typeDef in by_category["typedef"] if typeDef.type.category == "structure" %}
72         using {{as_cppType(typeDef.name)}} = {{as_cppType(typeDef.type.name)}};
73     {% endfor %}
74 
75 } // namespace dawn_native
76 
77 #endif  // DAWNNATIVE_WGPU_STRUCTS_H_
78