• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2015-2018 Khronos Group. This work is licensed under a
2// Creative Commons Attribution 4.0 International License; see
3// http://creativecommons.org/licenses/by/4.0/
4
5[[naming]]
6= API Naming Conventions
7
8Identifiers in the Vulkan API (e.g. types, parameters, constants, etc.) all
9follow a set of naming rules, providing a consistent scheme for developers.
10
11The Vulkan C API uses prefixes as an implicit namespace control mechanism.
12Bindings to other languages can choose not to use these prefixes if the
13language provides an explicit namespace mechanism.
14
15
16== General Naming Rules
17
18Names of identifiers should generally be written with full words, avoiding
19abbreviations, as a concise description of what that identifier is.
20For example, the type of a structure containing information about how to
21create an instance is stext:VkInstanceCreateInfo.
22
23Abbreviations and prefixes are sometimes used in the API when they are in
24common use.
25All abbreviations and prefixes used in the API must be approved by the
26Vulkan working group, and be added to the <<naming-abbreviations,Common
27Abbreviations>> and <<naming-prefixes,Standard Prefixes>> sections,
28respectively.
29
30Whenever an abbreviation exists for a particular word, it should be used in
31place of the full word unless there is good reason not to.
32
33When a number is part of an identifier, it is treated as a word if it is a
34standalone number, such as the extension name token
35ename:VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME for the
36+VK_KHR_get_memory_requirements2+ extension.
37For uses where the number is part of a common abbreviation such as etext:2D
38or etext:R8B8`, the entire abbreviation is treated as a word.
39
40ifdef::editing-notes[]
41[NOTE]
42.editing-note
43====
44Unfortunately, there's an internal inconsistency here between extension name
45strings, such as VK_KHR_get_memory_requirements2, and tokens encoding those
46names, such as ename:VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME.
47====
48endif::editing-notes[]
49
50
51[[naming-preprocessor]]
52== Preprocessor Defines
53
54Preprocessor definitions include an underscore `_` as a delimiter between
55words, with every character in upper case.
56
57Each definition is prefixed with `VK_`, followed by the name.
58
59This rule applies to most declarations with the C Preprocessor's `#define`
60token, including macros and constants.
61There are however a few exceptions:
62
63  * The header guard for each header includes an additional underscore `_`
64    at the end of the identifier.
65  ** Example: `VULKAN_H_`
66  * Definitions that denote the presence of an extension follow the
67    <<extensions-naming-conventions-name-strings,extension name string
68    convention>>.
69  ** Example: `VK_KHR_sampler_mirror_clamp_to_edge`
70  * Three `VKAPI_*` definitions are defined by the platform header to alias
71    certain platform-specific identifiers related to calling conventions.
72  ** Examples: `VKAPI_ATTR`, `VKAPI_CALL` and `VKAPI_PTR`
73  * Preprocessor defines are occasionally used to create aliases between
74    other Vulkan identifiers, which usually happens when something was
75    originally misnamed.
76    In these cases, the fixed name is added to the API, and the old name is
77    made into an alias of that.
78    In these cases, the name will be whatever the original misnamed
79    identifier was.
80
81[source, c]
82.Example
83----
84// VK_VERSION_MAJOR (Macro)
85#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22)
86
87// VK_HEADER_VERSION (Base type)
88#define VK_HEADER_VERSION 10
89----
90
91
92== Type Names
93
94Type names are declared with no separator between words.
95Each word starts with a capital letter, and every other character in each
96word is lower case.
97
98Each type name is prefixed with `Vk`.
99
100This rule applies to all type definitions except <<naming-funcpointers,
101function pointer types>>, including struct and union types, handles, base
102typedefs, and enumerant types.
103
104[source, c]
105.Example
106----
107// VkImage (Handle)
108VK_NONDISP_HANDLE(VkImage)
109
110// VkFlags (Base type)
111typedef uint32_t VkFlags;
112
113// VkResult (Enum type)
114typedef enum VkResult {
115    ...
116};
117
118// VkApplicationInfo (Struct)
119typedef struct VkApplicationInfo {
120    ...
121} VkApplicationInfo;
122
123// VkClearColorValue (Union)
124typedef union VkClearColorValue {
125    ...
126} VkClearColorValue;
127----
128
129
130[[naming-extension-structures]]
131=== Extension Structure Names
132
133Structures which extend other structures through the pname:pNext chain
134should reflect the name of the base structure they extend.
135Currently there are two examples of such naming schemes.
136
137New structures which add extended object creation parameters to a base
138structure should use this naming scheme:
139
140.Extended Object Information Structures
141[width="60%",options="header"]
142|====
143| Base Structure Name | Extension Structure Name
144| `Vk__Object__CreateInfo`
145    | `Vk__ObjectName__CreateInfo__Author__`
146|====
147
148`_Object_` is the name of the object being created.
149`_Name_` is a short name for the extension or the new information added by
150that extension.
151`_Author_` is the author ID of the extension.
152
153New structures which extend API queries, such as the
154`vkGetPhysicalDeviceFeatures2KHR` and `vkGetPhysicalDeviceProperties2KHR`
155commands defined by the `VK_KHR_get_physical_device_properties2` extension,
156should use this naming scheme:
157
158.Extended Query Structures
159[width="60%",options="header"]
160|====
161| Base Structure Name | Extension Structure Name
162| `vkGetPhysicalDeviceFeatures2KHR`
163    | `VkPhysicalDevice__Name__Features__Author__`
164| `vkGetPhysicalDeviceProperties2KHR`
165    | `VkPhysicalDevice__Name__Properties__Author__`
166|====
167
168`_Name_` is a short name for the extension, or for the new feature or
169property being queried, such as `Multiview` or `DiscardRectangle`.
170`_Author_` is the author ID of the extension.
171
172
173== Enumerant Names
174
175Enumerants include an underscore `_` as a delimiter between words, with
176every character in upper case.
177
178Each enumerant name is prefixed with `VK_`.
179
180Enumerants are prefixed with the exact name of the type it belongs to,
181converted to the correct case (e.g. `VkStructureType` ->
182`VK_STRUCTURE_TYPE_*`).
183
184This rule applies to all enumerants, with one exception.
185
186  * The `VkResult` enumerants are split into two sub types: error and
187    success codes.
188  ** Success codes are not prefixed with anything other than `VK_`.
189  ** Error codes are prefixed with `VK_ERROR_`.
190
191[source, c]
192.Example
193----
194// VK_FORMAT_UNDEFINED, VK_FORMAT_R4G4_UNORM_PACK8 (Enumerants)
195typedef enum VkFormat {
196    VK_FORMAT_UNDEFINED = 0,
197    VK_FORMAT_R4G4_UNORM_PACK8 = 1,
198    ...
199};
200
201// VkResult codes (Exception)
202typedef enum VkResult {
203    VK_SUCCESS = 0,
204    ...
205    VK_ERROR_OUT_OF_HOST_MEMORY = -1,
206    ...
207} VkResult;
208----
209
210
211== Command Names
212
213Command names are declared with no separator between words.
214Each word starts with a capital letter, and every other character in each
215word is lower case.
216
217The structure of a command name should be as follows:
218
219`__prefix Verb Object Property__`
220
221`_prefix_`::
222    This is usually "vk", but will be "vkCmd" if it is a command used to
223    record into a command buffer, or "vkQueue" if it directly affects a
224    queue.
225
226`_Verb_`::
227    The verb that describes the action being performed.
228    A list of most verbs used in Vulkan is available <<command-names-verbs,
229    here>>.
230
231`_Object_`::
232    The name of the object being acted upon by the command.
233
234`_Property_`::
235    The property of the object which is being acted upon by the command, and
236    is omitted in cases where the whole object is being acted upon (e.g.
237    creation commands).
238
239These rules apply to all command declarations.
240
241[source, c]
242.Example
243----
244// Creation command
245VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( ... );
246
247// Command buffer recording command
248VKAPI_ATTR VkResult VKAPI_CALL vkCmdBindPipeline( ... );
249
250// Get command
251VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults( ... );
252----
253
254.Note
255[NOTE]
256====
257There are three exceptions to the above rule in the core Vulkan API:
258
259  * vkDeviceWaitIdle
260  * vkCmdNextSubpass
261  * vkCmdPipelineBarrier
262
263These names are left as-is to maintain compatibility.
264
265There are additionally a number of exceptions in a few existing extensions.
266====
267
268
269=== Query Commands
270
271A number of commands in the API are used to determine the properties of some
272object in the implementation.
273
274The queried properties may either be invariant, or they may: change based on
275application behaviour.
276If the results are not invariant, the lifetime of the results should be
277clearly described in the command description.
278See <<fundamentals-commandsyntax-results-lifetime,Lifetime of Retrieved
279Results>> in the specification for more information.
280
281These commands fall into two categories from a naming perspective:
282
283Capability Queries::
284
285These are commands which query capabilities of objects that an
286implementation can provide.
287Such commands use the verb "Enumerate" to identify themselves.
288+
289e.g. `vkEnumeratePhysicalDeviceProperties`
290+
291Whilst these commands describe properties of the named object, they do not
292accept a parameter of that object type - though they usually have a
293parameter for the parent type.
294
295Object State Queries::
296
297These commands are used to query the current properties of an object that
298has been created.
299Such commands use the verb "Get" to identify themselves.
300+
301e.g. `vkGetPhysicalDeviceQueueFamilyProperties`
302+
303These commands always have a parameter of the object type.
304
305
306[[command-names-verbs]]
307=== Command Verbs
308
309Below is a list of many of the verbs currently in use in core Vulkan and KHR
310extensions, along with their meanings.
311The list is not guaranteed to be up to date, but covers all core and KHR
312verbs at the time of writing.
313
314[%autowidth,options="header"]
315|===
316| Verb       | Meaning
317| Acquire    | Acquire ownership of an object from an external source
318| Allocate   | Allocates memory in a pool or memory heap and creates object - paired with "Free"
319| Begin      | Start of a range of command buffer commands with different behaviour than those outside the range - "End" marks the end of the range
320| Bind       | Binds an object to another object
321| Blit       | Performs a filtered and scaled copy of pixels from one image to another
322| Clear      | Sets all pixels in an image to the same value
323| Copy       | A raw copy of data from one object to another with no transformation of the data
324| Create     | Creates an object - paired with "Destroy"
325| Destroy    | Destroys an object - paired with "Create"
326| Dispatch   | Kicks off a set of compute tasks
327| Draw       | Kicks off a set of rasterization tasks
328| End        | End of a range of command buffer commands with different behaviour than those outside the range - "Begin" marks the start of the range
329| Enumerate  | Queries the capabilities of objects that could be created, before creating them
330| Execute    | Executes commands recorded in another command buffer
331| Fill       | Sets all data units in a buffer to the same value
332| Flush      | Flushes data from the host to the device
333| Free       | Destroys an object and then frees memory back to a pool or memory heap - paired with "Allocate"
334| Get        | Queries the state of an existing object
335| Import     | Imports the payload from an external object into a Vulkan object
336| Invalidate | Invalidates data on the host, forcing newer data on the device to be read
337| Map        | Maps an allocation into host memory - paired with "Unmap"
338| Merge      | Merges two objects
339| Present    | Presents an image to a surface
340| Push       | Pushes data to the device as part of a command stream
341| Release    | Releases ownership of an object to an external source
342| Reset      | Resets the state of an object to an initial state
343| Resolve    | Resolves multiple samples in a multisampled image to an image with one sample per pixel
344| Set        | Sets the state of an object
345| Submit     | Submits a set of commands to a queue
346| Unmap      | Unmaps an allocation from host memory - paired with "Map"
347| Update     | Updates entries in a descriptor set
348| Wait       | Waits for some signal
349| Write      | Writes values to an object
350|===
351
352
353[[naming-funcpointers]]
354=== Function Pointer Type Names
355
356Function pointer names are declared exactly as the equivalent statically
357declared command would be declared, but prefixed with `PFN_`, standing for
358"Pointer to FunctioN".
359
360[source, c]
361.Example
362----
363// PFN_vkCreateInstance (Function Pointer)
364typedef VkResult (VKAPI_PTR *PFN_vkCreateInstance)( ... );
365----
366
367
368== Function Parameter and Struct/Union Member Names
369
370Function parameter names are declared with no separator between words.
371Each new word, *except* for the first, starts with a capital letter.
372All other characters in the parameter name are in lower case.
373
374Members/parameters of a type that is not a base type should generally be
375named in a similar way to the type itself, with additional context added for
376clarity when necessary.
377
378Pointer members/parameters are prefixed with a number of `p` characters,
379with one `p` for each level of indirection.
380
381Function pointer members/parameters are prefixed with `pfn`.
382
383Any member that describes the size of a memory allocation should be suffixed
384with `Size`.
385If the context is self-evident from the structure name, then it may simply
386be named `size`.
387
388Any member that describes the number of something, such as an array length
389or number of internal allocations, should be suffixed with `Count`.
390The `size` rule overrides this rule, though it is possible to have multiple
391sizes (e.g. `sizeCount`).
392If the member is an array length, then the name of length should correspond
393to the name of the array member, usually `XYZCount` for an array named
394`pXYZs`.
395If a member of a chained extension structure is an array whose length must
396match the length of an array of the base structure, then the chained
397extension structure should include an array length member with the same name
398as the length in the base structure.
399
400These rules apply to all function parameters and struct/union members, with
401a single exception:
402
403  * The `sType` member of structures is abbreviated as it is used in almost
404    every structure.
405  ** The slightly odd naming prevents it clashing with any future variables.
406  ** The `s` stands for "`structure`", referring to its enumerant type.
407
408[source, c]
409.Example
410----
411// Function parameters, including a twice indirected pointer.
412VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
413    VkDevice                                    device,
414    VkDeviceMemory                              memory,
415    VkDeviceSize                                offset,
416    VkDeviceSize                                size,
417    VkMemoryMapFlags                            flags,
418    void**                                      ppData);
419
420// Structure members, including the sType exception and a single indirected
421// pointer.
422typedef struct VkMemoryBarrier {
423    VkStructureType    sType;
424    const void*        pNext;
425    VkAccessFlags      srcAccessMask;
426    VkAccessFlags      dstAccessMask;
427} VkMemoryBarrier;
428
429// Function pointer members
430typedef struct VkAllocationCallbacks {
431    void*                                   pUserData;
432    PFN_vkAllocationFunction                pfnAllocation;
433    PFN_vkReallocationFunction              pfnReallocation;
434    PFN_vkFreeFunction                      pfnFree;
435    PFN_vkInternalAllocationNotification    pfnInternalAllocation;
436    PFN_vkInternalFreeNotification          pfnInternalFree;
437} VkAllocationCallbacks;
438
439// Size member (pCode is not a specific array of anything, it is just a
440// pointer to memory)
441typedef struct VkShaderModuleCreateInfo {
442    VkStructureType              sType;
443    const void*                  pNext;
444    VkShaderModuleCreateFlags    flags;
445    size_t                       codeSize;
446    const uint32_t*              pCode;
447} VkShaderModuleCreateInfo;
448
449// Count member
450typedef struct VkSparseImageMemoryBindInfo {
451    VkImage                           image;
452    uint32_t                          bindCount;
453    const VkSparseImageMemoryBind*    pBinds;
454} VkSparseImageMemoryBindInfo;
455----
456
457
458[[naming-extension-identifiers]]
459== Extension Identifier Naming Conventions
460
461Identifiers defined by an extension are modified by appending the
462extension's author ID to the end of the identifier, as described below.
463Author IDs are obtained as described in the
464<<extensions-naming-conventions,Extension and Layer Naming Conventions>>
465section.
466
467If an extension becomes part of core, a new version of the extension's
468identifiers should be created, that do not contain the author ID at the end
469of the identifier.
470The original identifiers should be kept in order to maintain source-level
471compatibility with existing applications making use of the earlier
472extension's identifiers.
473
474
475=== Extension Type Names
476
477Types defined by extensions have the author ID appended to the end of the
478type name.
479
480[source, c]
481.Example
482----
483// VkSurfaceFormatKHR (structure type with KHR appended)
484typedef struct VkSurfaceFormatKHR {
485    VkFormat           format;
486    VkColorSpaceKHR    colorSpace;
487} VkSurfaceFormatKHR;
488----
489
490
491=== Extension Enumerant Names
492
493Enumerants defined by extensions have the author ID appended to the end of
494the enumerant name, separated by an underscore.
495This includes the begin, end, range and max values added to enumeranted type
496definitions by the generator scripts.
497
498[NOTE]
499====
500There is one exception to this rule in the
501`VK_KHR_sampler_mirror_clamp_to_edge` extension.
502This functionality was included in the original spec, but quickly separated
503out at release.
504Due to this late change, the single enum exposed has retained its original
505identifier to avoid compatibility issues:
506ename:VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
507====
508
509[source, c]
510.Example
511----
512// VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR (enumerant with _KHR appended)
513typedef enum VkCompositeAlphaFlagBitsKHR {
514    VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR = 0x00000001,
515    ...
516} VkCompositeAlphaFlagBitsKHR;
517----
518
519
520=== Extension Function Names
521
522Function and function pointer type names defined by extensions have the
523author ID appended to the end of the name.
524
525[source, c]
526.Example
527----
528// vkDestroySurfaceKHR (function with KHR appended)
529VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
530    VkInstance                                  instance,
531    VkSurfaceKHR                                surface,
532    const VkAllocationCallbacks*                pAllocator);
533
534typedef void (VKAPI_PTR *PFN_vkDestroySurfaceKHR)(
535    VkInstance                                  instance,
536    VkSurfaceKHR                                surface,
537    const VkAllocationCallbacks*                pAllocator);
538----
539
540
541[[naming-abbreviations]]
542== Common Abbreviations
543
544Abbreviations and acronyms are sometimes used in the <<vulkan-spec,Vulkan
545API Specification>> and the Vulkan API where they are considered clear and
546commonplace.
547All such abbrevations used in the core API are defined here.
548Extensions should also use these abbreviations where appropriate.
549
550Src::
551    Source
552
553Dst::
554    Destination
555
556Min::
557    Minimum
558
559Max::
560    Maximum
561
562Rect::
563    Rectangle
564
565Info::
566    Information
567
568Lod::
569    Level of Detail
570
571Mip::
572    Related to a mipmap.
573    Use "`mipmap`" in full only when it is a standalone term.
574    If referred to some associating with a mipmap, such as levels, sampling
575    mode, size, tail images, etc., use "`mip`" as a standalone prefix word,
576    e.g. pname:maxMipLevels, ename:VK_MIP_MODE, etc.
577    This is analogous to the <<writing-compount-words,spelling conventions
578    for mip-related terms>>
579
580[NOTE]
581====
582The names pname:mipmapMode, pname:mipmapPrecisionBits,
583sname:VkSamplerMipmapMode, and
584ename:VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT are exceptions to this
585general usage guideline, for historical reasons.
586====
587
588ID::
589    Identifier
590
591UUID::
592    Universally Unique Identifier
593
594Op::
595    Operation
596
597R::
598    Red color component
599
600G::
601    Green color component
602
603B::
604    Blue color component
605
606A::
607    Alpha color component
608
609
610[[naming-prefixes]]
611== Standard Prefixes
612
613Prefixes are used in the API to denote specific semantic meaning of Vulkan
614names, or as a label to avoid name clashes, and are explained here:
615
616VK/Vk/vk::
617    Vulkan namespace +
618    All types, commands, enumerants and C macro definitions in the Vulkan
619    specification are prefixed with these two characters, according to the
620    rules defined above.
621
622PFN/pfn::
623    Function Pointer +
624    Denotes that a type is a function pointer, or that a variable is of a
625    pointer type.
626
627p::
628    Pointer +
629    Variable is a pointer.
630
631vkCmd::
632    Commands that record commands in command buffers +
633    These API commands do not result in immediate processing on the device.
634    Instead, they record the requested action in a command buffer for
635    execution when the command buffer is submitted to a queue.
636
637s::
638    Structure +
639    Used to denote the etext:VK_STRUCTURE_TYPE* member of each structure in
640    pname:sType.
641