1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/// Rust structure representing the Vulkan registry.
///
/// The registry contains all the information contained in a certain version
/// of the Vulkan specification, stored within a programmer-accessible format.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Registry(pub Vec<RegistryChild>);

/// An element of the Vulkan registry.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RegistryChild {
    /// Comments are human-readable strings which contain registry meta-data.
    Comment(String),
    /// IDs of all known Vulkan vendors.
    VendorIds(VendorIds),
    /// List of supported Vulkan platforms.
    Platforms(Platforms),
    /// Known extension tags.
    Tags(Tags),
    /// Type definitions.
    ///
    /// Unlike OpenGL, Vulkan is a strongly-typed API.
    Types(Types),
    /// Enum definitions.
    Enums(Enums),
    /// Commands are the Vulkan API's name for functions.
    Commands(Commands),
    /// Feature level of the API, such as Vulkan 1.0 or 1.1
    Feature(Feature),
    /// Container for all published Vulkan specification extensions.
    Extensions(Extensions),
}

pub type VendorIds = CommentedChildren<VendorId>;

/// Unique identifier for a Vulkan vendor.
///
/// Note: in newer versions of the Vulkan spec, this tag is not used,
/// instead it has been replaced by the `VKVendorId` enum.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VendorId {
    /// Name of the vendor.
    pub name: String,
    /// Human-readable description.
    pub comment: Option<String>,
    /// The unique ID.
    pub id: u32,
}

pub type Platforms = CommentedChildren<Platform>;

/// A platform refers to a windowing system which Vulkan can use.
///
/// Most operating systems will have only one corresponding platform,
/// but Linux has multiple (XCB, Wayland, etc.)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Platform {
    /// Short identifier.
    pub name: String,
    /// Human readable description of the platform.
    pub comment: Option<String>,
    /// C macro name which is used to guard platform-specific definitions.
    pub protect: String,
}

pub type Tags = CommentedChildren<Tag>;

/// Tags are the little suffixes attached to extension names or items, indicating the author.
///
/// Some examples:
/// - KHR for Khronos extensions
/// - EXT for multi-vendor extensions
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag {
    /// The name of the tag, e.g. "KHR".
    pub name: String,
    /// Author of the extensions associated with the tag, e.g. "Khronos".
    pub author: String,
    /// Contact information for the extension author(s).
    pub contact: String,
}

pub type Types = CommentedChildren<TypesChild>;

/// An item making up a type definition.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypesChild {
    Type(Type),
    Comment(String),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Type {
    pub name: Option<String>,
    pub alias: Option<String>,
    pub api: Option<String>,
    pub requires: Option<String>,
    pub category: Option<String>,
    pub comment: Option<String>,
    pub parent: Option<String>,
    pub returnedonly: Option<String>,
    pub structextends: Option<String>,
    pub spec: TypeSpec,
}

/// The contents of a type definition.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypeSpec {
    Code(TypeCode),
    Members(Vec<TypeMember>),
    None,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeCode {
    pub code: String,
    pub markup: Vec<TypeCodeMarkup>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypeCodeMarkup {
    Name(String),
    Type(String),
    ApiEntry(String),
}

/// A member of a type definition, i.e. a struct member.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypeMember {
    /// Human-readable comment.
    Comment(String),
    /// A structure field definition.
    Definition(TypeMemberDefinition),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeMemberDefinition {
    pub len: Option<String>,
    pub altlen: Option<String>,
    pub externsync: Option<String>,
    pub optional: Option<String>,
    pub noautovalidity: Option<String>,
    pub validextensionstructs: Option<String>,
    pub values: Option<String>,
    pub code: String,
    pub markup: Vec<TypeMemberMarkup>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TypeMemberMarkup {
    Name(String),
    Type(String),
    Enum(String),
    Comment(String),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Enums {
    pub name: Option<String>,
    pub kind: Option<String>,
    pub start: Option<i64>,
    pub end: Option<i64>,
    pub vendor: Option<String>,
    pub comment: Option<String>,
    pub children: Vec<EnumsChild>,
}

/// An item which forms an enum.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EnumsChild {
    /// Actual named enum.
    Enum(Enum),
    /// An unused range of enum values.
    Unused(Unused),
    /// Human-readable comment.
    Comment(String),
}

/// An unused range of enum values.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Unused {
    /// Beginning of the range.
    pub start: i64,
    /// Ending value of the range, if any.
    pub end: Option<i64>,
    /// Vendor who reserved this range.
    pub vendor: Option<String>,
    /// Human-readable description.
    pub comment: Option<String>,
}

/// An item of an enumeration type.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Enum {
    /// Name of this enum.
    pub name: String,
    /// Human-readable description.
    pub comment: Option<String>,
    pub type_suffix: Option<String>,
    pub api: Option<String>,
    pub spec: EnumSpec,
}

/// An enum specifier, which assigns a value to the enum.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EnumSpec {
    Alias {
        alias: String,
        extends: Option<String>,
    },
    Offset {
        offset: i64,
        extends: String,
        extnumber: Option<i64>,
        dir: bool,
    },
    /// Indicates an enum which is a bit flag.
    Bitpos {
        /// The bit to be set.
        bitpos: i64,
        /// Which structure this enum extends.
        extends: Option<String>,
    },
    /// An enum value.
    Value {
        /// Hard coded value for an enum.
        value: String, // rnc says this is an Integer, but validates it as text, and that's what it sometimes really is.
        /// Which structure this enum extends.
        extends: Option<String>,
    },
    None,
}

pub type Commands = CommentedChildren<Command>;

/// A command is just a Vulkan function.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Command {
    /// Indicates this function is an alias for another one.
    Alias { name: String, alias: String },
    /// Defines a new Vulkan function.
    Definition(CommandDefinition),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandDefinition {
    pub queues: Option<String>,
    pub successcodes: Option<String>,
    pub errorcodes: Option<String>,
    pub renderpass: Option<String>,
    pub cmdbufferlevel: Option<String>,
    pub pipeline: Option<String>,
    pub comment: Option<String>,
    pub proto: NameWithType,
    pub params: Vec<CommandParam>,
    pub alias: Option<String>,
    pub description: Option<String>,
    pub implicitexternsyncparams: Vec<String>,

    pub code: String,
}

/// Parameter for this Vulkan function.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommandParam {
    /// The expression which indicates the length of this array.
    pub len: Option<String>,
    /// Alternate description of the length of this parameter.
    pub altlen: Option<String>,
    /// Whether this parameter must be externally synchronised by the app.
    pub externsync: Option<String>,
    /// Whether this parameter must have a non-null value.
    pub optional: Option<String>,
    /// Disables automatic validity language being generated for this item.
    pub noautovalidity: Option<String>,

    /// The definition of this parameter.
    pub definition: NameWithType,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Feature {
    pub api: String,
    pub name: String,
    pub number: f32,
    pub protect: Option<String>,
    pub comment: Option<String>,
    pub children: Vec<FeatureChild>,
}

pub type FeatureChild = ExtensionChild;

pub type Extensions = CommentedChildren<Extension>;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Extension {
    /// Name of the extension.
    pub name: String,
    /// Human-readable description.
    pub comment: Option<String>,
    /// The unique index of this extension.
    pub number: Option<i64>,
    pub protect: Option<String>,
    /// Which platform it works with, if any.
    pub platform: Option<String>,
    /// Tag name of the author.
    pub author: Option<String>,
    /// Contact information for extension author(s).
    pub contact: Option<String>,
    /// The level at which the extension applies (instance / device).
    pub ext_type: Option<String>,
    pub requires: Option<String>,
    pub requires_core: Option<String>,
    pub supported: Option<String>, // mk:TODO StringGroup?
    pub deprecatedby: Option<String>,
    /// Whether this extension was promoted to core, and in which version.
    pub promotedto: Option<String>,
    pub obsoletedby: Option<String>,

    /// 'true' if this extension is released provisionally
    pub provisional: bool,
    /// The items which make up this extension.
    pub children: Vec<ExtensionChild>,
}

/// A part of an extension declaration.
///
/// Extensions either include functionality from the spec, or remove some functionality.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ExtensionChild {
    /// Indicates the items which this extension requires to work.
    Require {
        api: Option<String>,
        profile: Option<String>,
        /// The extension which provides these required items, if any.
        extension: Option<String>,
        feature: Option<String>,
        comment: Option<String>,
        /// The items which form this require block.
        items: Vec<InterfaceItem>,
    },
    /// Indicates the items this extension removes.
    Remove {
        api: Option<String>,
        profile: Option<String>,
        comment: Option<String>,
        items: Vec<InterfaceItem>,
    },
}

/// An interface item is a function or an enum which makes up a Vulkan interface.
///
/// This structure is used by extensions to express dependencies or include functionality.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum InterfaceItem {
    Comment(String),
    Type {
        name: String,
        comment: Option<String>,
    },
    Enum(Enum),
    Command {
        name: String,
        comment: Option<String>,
    },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NameWithType {
    pub type_name: Option<String>,
    pub name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommentedChildren<T> {
    pub comment: Option<String>,
    pub children: Vec<T>,
}