Vulkan-Docs/doc/specs/vulkan/style/naming.txt

425 lines
12 KiB
Plaintext
Raw Normal View History

Change log for July 15, 2016 Vulkan 1.0.21 spec update: * Bump API patch number and header version number to 21 for this update. Github Issues: * Clarify how <<features-supported-sample-counts,sample count queries>> relate to the limits in slink:VkPhysicalDeviceLimits. (public issue 185). * Clarify in the <<interfaces-iointerfaces,Shader Input and Output Interfaces>> section that shader output variables have undefined values until the shader writes to them (public issue 240). * Specify the implicit value of image parameters that cannot be set in slink:VkSwapchainCreateInfo::pname:flags, pname:imageType, pname:mipLevels, pname:samples, pname:tiling, and pname:initialLayout (public issue 243). * Make use of code:NULL and code:VK_NULL_HANDLE consistent in the VK_KHR_swapchain extension (public issue 276). Internal Issues: * Clarify that presenting an image to a display surface swapchain applies the display surface's mode, and that destroying a display surface swapchain may reset the display's mode, in the VK_KHR_display_swapchain extension (internal issue 247). * Better describe what a slink:VkSurfaceKHR is, and that creating one does not set a mode, in the VK_KHR_display extension. This is a round-about way of pointing out that mode setting is not covered by the extension, but rather is performed as a side effect of presentation (internal issue 247). * Add more valid usage statements to flink:vkQueuePresentKHR command when the VK_KHR_display_swapchain extension is present (internal issue 247). * Add more includes to the VK_KHR_swapchain extension to better document interactions with VK_KHR_display_swapchain (internal issue 247). * Clarify restrictions on location aliasing in the <<fxvertex,Fixed-Function Vertex Processing>> section (internal issue 370). * Add mathematical description of blitting to flink:vkCmdBlitImage, and link it to the <<textures,Image Operations>> chapter. Use mathematical notation for ranges of texel coordinates in the <<textures,Image Operations>> chapter. Fixed miscellaneous validity statements for flink:vkCmdBlit and slink:VkImageBlit (internal issue 382). Other Commits: * Added a valid usage rule to flink:VkGraphicsPipelineCreateInfo that the ename:VK_PRIMITIVE_TOPOLOGY_PATCH_LIST topology must only be used when tessellation shaders are used. * Expand the style guide into a formal "Procedures and Conventions" document. Add a API Naming Conventions section, move most of the API Specification Appendix C (Layers and Extensions) content into the new document, and define the resulting procedures as mandatory (where relevant). This more clearly separates use vs. specification of Vulkan APIs. * Update vk_platform.h to handle 32-bit ARMv8 binaries. * Various minor cleanups to the Makefile and build process.
2016-07-16 02:05:43 +00:00
// Copyright (c) 2016 The Khronos Group Inc.
// Copyright notice at https://www.khronos.org/registry/speccopyright.html
[[naming]]
= API Naming Conventions
Identifiers in the Vulkan API (e.g. types, parameters, constants, etc.) all
follow a set of naming rules, providing a consistent scheme for developers.
The Vulkan C API uses prefixes as an implicit namespace control mechanism.
Bindings to other languages can choose not to use these prefixes if the
language provides an explicit namespace mechanism.
== General Naming Rules
Names of identifiers should generally be written with full words, avoiding
abbreviations, as a concise description of what that identifier is. For
example, the type of a structure containing information about how to create
an instance is stext:VkInstanceCreateInfo.
Abbreviations and prefixes are sometimes used in the API when they are in
common use. All abbreviations and prefixes used in the API must be approved
by the Vulkan working group, and be added to the
<<naming-abbreviations,Common Abbreviations>> and <<naming-prefixes,Standard
Prefixes>> sections, respectively.
Whenever an abbreviation exists for a particular word, it should be used in
place of the full word unless there is good reason not to.
[[naming-preprocessor]]
== Preprocessor Defines
Preprocessor definitions include an underscore `_` as a delimiter between
words, with every character in upper case.
Each definition is prefixed with `VK_`, followed by the name.
This rule applies to most declarations with the C Preprocessor's `#define`
token, including macros and constants. There are however a few exceptions:
* The header guard for each header includes an additional underscore `_` at
the end of the identifier.
** Example: `VULKAN_H_`
* Definitions that denote the presence of an extension follow the
<<extensions-naming-conventions-name-strings,extension name string
convention>>.
** Example: `VK_KHR_sampler_mirror_clamp_to_edge`
* Three `VKAPI_*` definitions are defined by the platform header to alias
certain platform-specific identifiers related to calling conventions.
** Examples: `VKAPI_ATTR`, `VKAPI_CALL` and `VKAPI_PTR`
* Preprocessor defines are occasionally used to create aliases between
other Vulkan identifiers, which usually happens when something was
originally misnamed. In these cases, the fixed name is added to the API,
and the old name is made into an alias of that. In these cases, the name
will be whatever the original misnamed identifier was.
[source, c]
.Example
----
// VK_VERSION_MAJOR (Macro)
#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22)
// VK_HEADER_VERSION (Base type)
#define VK_HEADER_VERSION 10
----
== Type Names
Type names are declared with no separator between words. Each word starts
with a capital letter, and every other character in each word is lower case.
Each type name is prefixed with `Vk`.
This rule applies to all type definitions except <<naming-funcpointers,
function pointer types>>, including struct and union types, handles,
base typedefs, and enumerant types.
[source, c]
.Example
----
// VkImage (Handle)
VK_NONDISP_HANDLE(VkImage)
// VkFlags (Base type)
typedef uint32_t VkFlags;
// VkResult (Enum type)
typedef enum VkResult {
...
};
// VkApplicationInfo (Struct)
typedef struct VkApplicationInfo {
...
} VkApplicationInfo;
// VkClearColorValue (Union)
typedef union VkClearColorValue {
...
} VkClearColorValue;
----
== Enumerant Names
Enumerants include an underscore `_` as a delimiter between words, with
every character in upper case.
Each enumerant name is prefixed with `VK_`.
Enumerants are prefixed with the exact name of the type it belongs to,
converted to the correct case (e.g. `VkStructureType` ->
`VK_STRUCTURE_TYPE_APPLICATION_INFO`).
This rule applies to all enumerants, with one exception.
* The "VkResult" enumerants are split into two sub types: error and success
codes.
** Success codes are not prefixed with anything other than `VK_`.
** Error codes are prefixed with `VK_ERROR_`.
[source, c]
.Example
----
// VK_FORMAT_UNDEFINED, VK_FORMAT_R4G4_UNORM_PACK8 (Enumerants)
typedef enum VkFormat {
VK_FORMAT_UNDEFINED = 0,
VK_FORMAT_R4G4_UNORM_PACK8 = 1,
...
};
// VkResult codes (Exception)
typedef enum VkResult {
VK_SUCCESS = 0,
...
VK_ERROR_OUT_OF_HOST_MEMORY = -1,
...
} VkResult;
----
== Function Names
Function names are declared with no separator between words. Each word
starts with a capital letter, and every other character in each word is
lower case.
Function names are prefixed with `vk`, with the exception of functions that
record commands into a command buffer and are instead prefixed with
`vkCmd`.
This rule applies to all function declarations.
[source, c]
.Example
----
// Function call
VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( ... );
// Command buffer function
VKAPI_ATTR VkResult VKAPI_CALL vkCmdBindPipeline( ... );
----
[[naming-funcpointers]]
=== Function Pointer Type Names
Function pointer names are declared exactly as the equivalent statically
declared function would be declared, but prefixed with `PFN_`, standing for
"Pointer to FunctioN".
[source, c]
.Example
----
// PFN_vkCreateInstance (Function Pointer)
typedef VkResult (VKAPI_PTR *PFN_vkCreateInstance)( ... );
----
== Function Parameter and Struct/Union Member Names
Function parameter names are declared with no separator between words. Each
new word, *except* for the first, starts with a capital letter. All other
characters in the parameter name are in lower case.
Members/parameters of a type that is not a base type should generally be
named in a similar way to the type itself, with additional context added for
clarity when necessary.
Pointer members/parameters are prefixed with a number of `p` characters,
with one `p` for each level of indirection.
Function pointer members/parameters are prefixed with `pfn`.
Any member that describes the size of a memory allocation should be suffixed
with `Size`. If the context is self-evident from the structure name, then it
may simply be named `size`.
Any member that describes the number of something, such as an array length
or number of internal allocations, should be suffixed with `Count`. If the
context is self-evident from the structure name, then it may simply be named
`count`. The `size` rule overrides this rule, though it is possible to have
multiple sizes (e.g. `sizeCount`).
These rules apply to all function parameters and struct/union members, with a
single exception:
* The 'sType' member of structures is abbreviated as it is used in almost
every structure.
** The slightly odd naming prevents it clashing with any future variables.
** The s stands for "structure", referring to its enumerant type.
[source, c]
.Example
----
// Function parameters, including a twice indirected pointer.
VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
VkDevice device,
VkDeviceMemory memory,
VkDeviceSize offset,
VkDeviceSize size,
VkMemoryMapFlags flags,
void** ppData);
// Structure members, including the sType exception and a single indirected
// pointer.
typedef struct VkMemoryBarrier {
VkStructureType sType;
const void* pNext;
VkAccessFlags srcAccessMask;
VkAccessFlags dstAccessMask;
} VkMemoryBarrier;
// Function pointer members
typedef struct VkAllocationCallbacks {
void* pUserData;
PFN_vkAllocationFunction pfnAllocation;
PFN_vkReallocationFunction pfnReallocation;
PFN_vkFreeFunction pfnFree;
PFN_vkInternalAllocationNotification pfnInternalAllocation;
PFN_vkInternalFreeNotification pfnInternalFree;
} VkAllocationCallbacks;
// Size member (pCode is not a specific array of anything, it is just a
// pointer to memory)
typedef struct VkShaderModuleCreateInfo {
VkStructureType sType;
const void* pNext;
VkShaderModuleCreateFlags flags;
size_t codeSize;
const uint32_t* pCode;
} VkShaderModuleCreateInfo;
// Count member
typedef struct VkSparseImageMemoryBindInfo {
VkImage image;
uint32_t bindCount;
const VkSparseImageMemoryBind* pBinds;
} VkSparseImageMemoryBindInfo;
----
[[naming-extension-identifiers]]
== Extension Identifier Naming Conventions
Identifiers defined by an extension are modified by appending the
extension's author ID to the end of the identifier, as described below.
Author IDs are obtained as described in the
<<extensions-naming-conventions,Extension and Layer Naming Conventions>>
section.
=== Extension Type Names
Types defined by extensions have the author ID appended to the end of
the type name.
[source, c]
.Example
----
// VkSurfaceFormatKHR (structure type with KHR appended)
typedef struct VkSurfaceFormatKHR {
VkFormat format;
VkColorSpaceKHR colorSpace;
} VkSurfaceFormatKHR;
----
=== Extension Enumerant Names
Enumerants defined by extensions have the author ID appended to the end
of the enumerant name, separated by an underscore. This includes the begin,
end, range and max values added to enumeranted type definitions by the
generator scripts.
[NOTE]
====
There is one exception to this rule in the
VK_KHR_sampler_mirror_clamp_to_edge extension. This functionality was
included in the original spec, but quickly separated out at release. Due to
this late change, the single enum exposed has retained its original
identifier to avoid compatibility issues:
ename:VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
====
[source, c]
.Example
----
// VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR (enumerant with _KHR appended)
typedef enum VkCompositeAlphaFlagBitsKHR {
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR = 0x00000001,
...
} VkCompositeAlphaFlagBitsKHR;
----
=== Extension Function Names
Function and function pointer type names defined by extensions have the
author ID appended to the end of the name.
[source, c]
.Example
----
// vkDestroySurfaceKHR (function with KHR appended)
VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
VkInstance instance,
VkSurfaceKHR surface,
const VkAllocationCallbacks* pAllocator);
typedef void (VKAPI_PTR *PFN_vkDestroySurfaceKHR)(
VkInstance instance,
VkSurfaceKHR surface,
const VkAllocationCallbacks* pAllocator);
----
[[naming-abbreviations]]
== Common Abbreviations
Abbreviations and acronyms are sometimes used in the
<<Vulkan API Specification>> and the Vulkan
API where they are considered clear and commonplace. All such abbrevations
used in the core API are defined here. Extensions should also use these
abbreviations where appropriate.
Src::
Source
Dst::
Destination
Min::
Minimum
Max::
Maximum
Rect::
Rectangle
Info::
Information
Lod::
Level of Detail
ID::
Identifier
UUID::
Universally Unique Identifier
Op::
Operation
R::
Red color component
G::
Green color component
B::
Blue color component
A::
Alpha color component
[[naming-prefixes]]
== Standard Prefixes
Prefixes are used in the API to denote specific semantic meaning of
{apiname} names, or as a label to avoid name clashes, and are explained
here:
VK/Vk/vk::
Vulkan namespace +
All types, commands, enumerants and C macro definitions in the Vulkan
specification are prefixed with these two characters, according to the
rules defined above.
PFN/pfn::
Function Pointer +
Denotes that a type is a function pointer, or that a variable is of a
pointer type.
p::
Pointer +
Variable is a pointer.
vkCmd::
Commands that record commands in command buffers +
These API commands do not result in immediate processing on the device.
Instead, they record the requested action in a command buffer for
execution when the command buffer is submitted to a queue.
s::
Structure +
Used to denote the etext:VK_STRUCTURE_TYPE* member of each structure in
pname:sType.