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[[fundamentals]] 6= Fundamentals 7 8This chapter introduces fundamental concepts including the Vulkan 9architecture and execution model, API syntax, queues, pipeline 10configurations, numeric representation, state and state queries, and the 11different types of objects and shaders. 12It provides a framework for interpreting more specific descriptions of 13commands and behavior in the remainder of the Specification. 14 15 16[[fundamentals-host-environment]] 17== Host and Device Environment 18 19The Vulkan Specification assumes and requires: the following properties of 20the host environment with respect to Vulkan implementations: 21 22 * The host must: have runtime support for 8, 16, 32 and 64-bit signed and 23 unsigned twos-complement integers, all addressable at the granularity of 24 their size in bytes. 25 * The host must: have runtime support for 32- and 64-bit floating-point 26 types satisfying the range and precision constraints in the 27 <<fundamentals-floatingpoint,Floating Point Computation>> section. 28 * The representation and endianness of these types on the host must: match 29 the representation and endianness of the same types on every physical 30 device supported. 31 32[NOTE] 33.Note 34==== 35Since a variety of data types and structures in Vulkan may: be accessible by 36both host and physical device operations, the implementation should: be able 37to access such data efficiently in both paths in order to facilitate writing 38portable and performant applications. 39==== 40 41[[fundamentals-execmodel]] 42== Execution Model 43 44This section outlines the execution model of a Vulkan system. 45 46Vulkan exposes one or more _devices_, each of which exposes one or more 47_queues_ which may: process work asynchronously to one another. 48The set of queues supported by a device is partitioned into _families_. 49Each family supports one or more types of functionality and may: contain 50multiple queues with similar characteristics. 51Queues within a single family are considered _compatible_ with one another, 52and work produced for a family of queues can: be executed on any queue 53within that family. 54This Specification defines four types of functionality that queues may: 55support: graphics, compute, transfer, and sparse memory management. 56 57[NOTE] 58.Note 59==== 60A single device may: report multiple similar queue families rather than, or 61as well as, reporting multiple members of one or more of those families. 62This indicates that while members of those families have similar 63capabilities, they are _not_ directly compatible with one another. 64==== 65 66Device memory is explicitly managed by the application. 67Each device may: advertise one or more heaps, representing different areas 68of memory. 69Memory heaps are either device local or host local, but are always visible 70to the device. 71Further detail about memory heaps is exposed via memory types available on 72that heap. 73Examples of memory areas that may: be available on an implementation 74include: 75 76 * _device local_ is memory that is physically connected to the device. 77 * _device local, host visible_ is device local memory that is visible to 78 the host. 79 * _host local, host visible_ is memory that is local to the host and 80 visible to the device and host. 81 82On other architectures, there may: only be a single heap that can: be used 83for any purpose. 84 85A Vulkan application controls a set of devices through the submission of 86command buffers which have recorded device commands issued via Vulkan 87library calls. 88The content of command buffers is specific to the underlying implementation 89and is opaque to the application. 90Once constructed, a command buffer can: be submitted once or many times to a 91queue for execution. 92Multiple command buffers can: be built in parallel by employing multiple 93threads within the application. 94 95Command buffers submitted to different queues may: execute in parallel or 96even out of order with respect to one another. 97Command buffers submitted to a single queue respect 98<<synchronization-submission-order, submission order>>, as described further 99in <<synchronization, synchronization chapter>>. 100Command buffer execution by the device is also asynchronous to host 101execution. 102Once a command buffer is submitted to a queue, control may: return to the 103application immediately. 104Synchronization between the device and host, and between different queues is 105the responsibility of the application. 106 107 108[[fundamentals-queueoperation]] 109=== Queue Operation 110 111Vulkan queues provide an interface to the execution engines of a device. 112Commands for these execution engines are recorded into command buffers ahead 113of execution time. 114These command buffers are then submitted to queues with a _queue submission_ 115command for execution in a number of _batches_. 116Once submitted to a queue, these commands will begin and complete execution 117without further application intervention, though the order of this execution 118is dependent on a number of <<synchronization, implicit and explicit 119ordering constraints>>. 120 121Work is submitted to queues using queue submission commands that typically 122take the form ftext:vkQueue* (e.g. flink:vkQueueSubmit, 123flink:vkQueueBindSparse), and optionally take a list of semaphores upon 124which to wait before work begins and a list of semaphores to signal once 125work has completed. 126The work itself, as well as signaling and waiting on the semaphores are all 127_queue operations_. 128 129Queue operations on different queues have no implicit ordering constraints, 130and may: execute in any order. 131Explicit ordering constraints between queues can: be expressed with 132<<synchronization-semaphores,semaphores>> and 133<<synchronization-fences,fences>>. 134 135Command buffer submissions to a single queue respect 136<<synchronization-submission-order, submission order>> and other 137<<synchronization-implicit, implicit ordering guarantees>>, but otherwise 138may: overlap or execute out of order. 139Other types of batches and queue submissions against a single queue (e.g. 140<<sparsemem-memory-binding, sparse memory binding>>) have no implicit 141ordering constraints with any other queue submission or batch. 142Additional explicit ordering constraints between queue submissions and 143individual batches can be expressed with 144<<synchronization-semaphores,semaphores>> and 145<<synchronization-fences,fences>>. 146 147Before a fence or semaphore is signaled, it is guaranteed that any 148previously submitted queue operations have completed execution, and that 149memory writes from those queue operations are 150<<synchronization-dependencies-available-and-visible,available>> to future 151queue operations. 152Waiting on a signaled semaphore or fence guarantees that previous writes 153that are available are also 154<<synchronization-dependencies-available-and-visible,visible>> to subsequent 155commands. 156 157Command buffer boundaries, both between primary command buffers of the same 158or different batches or submissions as well as between primary and secondary 159command buffers, do not introduce any additional ordering constraints. 160In other words, submitting the set of command buffers (which can: include 161executing secondary command buffers) between any semaphore or fence 162operations execute the recorded commands as if they had all been recorded 163into a single primary command buffer, except that the current state is 164<<commandbuffers-statereset,reset>> on each boundary. 165Explicit ordering constraints can: be expressed with <<synchronization, 166explicit synchronization primitives>>. 167 168There are a few <<synchronization-implicit, implicit ordering guarantees>> 169between commands within a command buffer, but only covering a subset of 170execution. 171Additional explicit ordering constraints can be expressed with the various 172<<synchronization, explicit synchronization primitives>>. 173 174[NOTE] 175.Note 176==== 177Implementations have significant freedom to overlap execution of work 178submitted to a queue, and this is common due to deep pipelining and 179parallelism in Vulkan devices. 180==== 181 182[[fundamentals-queueoperation-command-types]] 183Commands recorded in command buffers either perform actions (draw, dispatch, 184clear, copy, query/timestamp operations, begin/end subpass operations), set 185state (bind pipelines, descriptor sets, and buffers, set dynamic state, push 186constants, set render pass/subpass state), or perform synchronization 187(set/wait events, pipeline barrier, render pass/subpass dependencies). 188Some commands perform more than one of these tasks. 189State setting commands update the _current state_ of the command buffer. 190Some commands that perform actions (e.g. draw/dispatch) do so based on the 191current state set cumulatively since the start of the command buffer. 192The work involved in performing action commands is often allowed to overlap 193or to be reordered, but doing so must: not alter the state to be used by 194each action command. 195In general, action commands are those commands that alter framebuffer 196attachments, read/write buffer or image memory, or write to query pools. 197 198Synchronization commands introduce explicit 199<<synchronization-dependencies,execution and memory dependencies>> between 200two sets of action commands, where the second set of commands depends on the 201first set of commands. 202These dependencies enforce that both the execution of certain 203<<synchronization-pipeline-stages, pipeline stages>> in the later set occur 204after the execution of certain stages in the source set, and that the 205effects of <<synchronization-global-memory-barriers,memory accesses>> 206performed by certain pipeline stages occur in order and are visible to each 207other. 208When not enforced by an explicit dependency or <<synchronization-implicit, 209implicit ordering guarantees>>, action commands may: overlap execution or 210execute out of order, and may: not see the side effects of each other's 211memory accesses. 212 213The device executes queue operations asynchronously with respect to the 214host. 215Control is returned to an application immediately following command buffer 216submission to a queue. 217The application must: synchronize work between the host and device as 218needed. 219 220 221[[fundamentals-objectmodel-overview]] 222== Object Model 223 224The devices, queues, and other entities in Vulkan are represented by Vulkan 225objects. 226At the API level, all objects are referred to by handles. 227There are two classes of handles, dispatchable and non-dispatchable. 228_Dispatchable_ handle types are a pointer to an opaque type. 229This pointer may: be used by layers as part of intercepting API commands, 230and thus each API command takes a dispatchable type as its first parameter. 231Each object of a dispatchable type must: have a unique handle value during 232its lifetime. 233 234_Non-dispatchable_ handle types are a 64-bit integer type whose meaning is 235implementation-dependent, and may: encode object information directly in the 236handle rather than acting as a reference to an underlying object. 237Objects of a non-dispatchable type may: not have unique handle values within 238a type or across types. 239If handle values are not unique, then destroying one such handle must: not 240cause identical handles of other types to become invalid, and must: not 241cause identical handles of the same type to become invalid if that handle 242value has been created more times than it has been destroyed. 243 244All objects created or allocated from a sname:VkDevice (i.e. with a 245sname:VkDevice as the first parameter) are private to that device, and must: 246not be used on other devices. 247 248 249[[fundamentals-objectmodel-lifetime]] 250=== Object Lifetime 251 252Objects are created or allocated by ftext:vkCreate* and ftext:vkAllocate* 253commands, respectively. 254Once an object is created or allocated, its "`structure`" is considered to 255be immutable, though the contents of certain object types is still free to 256change. 257Objects are destroyed or freed by ftext:vkDestroy* and ftext:vkFree* 258commands, respectively. 259 260Objects that are allocated (rather than created) take resources from an 261existing pool object or memory heap, and when freed return resources to that 262pool or heap. 263While object creation and destruction are generally expected to be 264low-frequency occurrences during runtime, allocating and freeing objects 265can: occur at high frequency. 266Pool objects help accommodate improved performance of the allocations and 267frees. 268 269It is an application's responsibility to track the lifetime of Vulkan 270objects, and not to destroy them while they are still in use. 271 272[[fundamentals-objectmodel-lifetime-acquire]] 273The ownership of application-owned memory is immediately acquired by any 274Vulkan command it is passed into. 275Ownership of such memory must: be released back to the application at the 276end of the duration of the command, so that the application can: alter or 277free this memory as soon as all the commands that acquired it have returned. 278 279The following object types are consumed when they are passed into a Vulkan 280command and not further accessed by the objects they are used to create. 281They must: not be destroyed in the duration of any API command they are 282passed into: 283 284 * sname:VkShaderModule 285 * sname:VkPipelineCache 286ifdef::VK_EXT_validation_cache[] 287 * sname:VkValidationCacheEXT 288endif::VK_EXT_validation_cache[] 289 290A sname:VkRenderPass object passed as a parameter to create another object 291is not further accessed by that object after the duration of the command it 292is passed into. 293A sname:VkRenderPass used in a command buffer follows the rules described 294below. 295 296A sname:VkPipelineLayout object must: not be destroyed while any command 297buffer that uses it is in the recording state. 298 299sname:VkDescriptorSetLayout objects may: be accessed by commands that 300operate on descriptor sets allocated using that layout, and those descriptor 301sets must: not be updated with flink:vkUpdateDescriptorSets after the 302descriptor set layout has been destroyed. 303Otherwise, a sname:VkDescriptorSetLayout object passed as a parameter to 304create another object is not further accessed by that object after the 305duration of the command it is passed into. 306 307The application must: not destroy any other type of Vulkan object until all 308uses of that object by the device (such as via command buffer execution) 309have completed. 310 311[[fundamentals-objectmodel-lifetime-cmdbuffers]] 312The following Vulkan objects must: not be destroyed while any command 313buffers using the object are in the <<commandbuffers-lifecycle, pending 314state>>: 315 316 * sname:VkEvent 317 * sname:VkQueryPool 318 * sname:VkBuffer 319 * sname:VkBufferView 320 * sname:VkImage 321 * sname:VkImageView 322 * sname:VkPipeline 323 * sname:VkSampler 324ifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 325 * basetype:VkSamplerYcbcrConversion 326endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 327 * sname:VkDescriptorPool 328 * sname:VkFramebuffer 329 * sname:VkRenderPass 330 * sname:VkCommandBuffer 331 * sname:VkCommandPool 332 * sname:VkDeviceMemory 333 * sname:VkDescriptorSet 334ifdef::VK_NVX_device_generated_commands[] 335 * sname:VkObjectTableNVX 336 * sname:VkIndirectCommandsLayout 337endif::VK_NVX_device_generated_commands[] 338 339Destroying these objects will move any command buffers that are in the 340<<commandbuffers-lifecycle, recording or executable state>>, and are using 341those objects, to the <<commandbuffers-lifecycle, invalid state>>. 342 343The following Vulkan objects must: not be destroyed while any queue is 344executing commands that use the object: 345 346 * sname:VkFence 347 * sname:VkSemaphore 348 * sname:VkCommandBuffer 349 * sname:VkCommandPool 350 351In general, objects can: be destroyed or freed in any order, even if the 352object being freed is involved in the use of another object (e.g. use of a 353resource in a view, use of a view in a descriptor set, use of an object in a 354command buffer, binding of a memory allocation to a resource), as long as 355any object that uses the freed object is not further used in any way except 356to be destroyed or to be reset in such a way that it no longer uses the 357other object (such as resetting a command buffer). 358If the object has been reset, then it can: be used as if it never used the 359freed object. 360An exception to this is when there is a parent/child relationship between 361objects. 362In this case, the application must: not destroy a parent object before its 363children, except when the parent is explicitly defined to free its children 364when it is destroyed (e.g. for pool objects, as defined below). 365 366sname:VkCommandPool objects are parents of sname:VkCommandBuffer objects. 367sname:VkDescriptorPool objects are parents of sname:VkDescriptorSet objects. 368sname:VkDevice objects are parents of many object types (all that take a 369sname:VkDevice as a parameter to their creation). 370 371The following Vulkan objects have specific restrictions for when they can: 372be destroyed: 373 374 * sname:VkQueue objects cannot: be explicitly destroyed. 375 Instead, they are implicitly destroyed when the sname:VkDevice object 376 they are retrieved from is destroyed. 377 * Destroying a pool object implicitly frees all objects allocated from 378 that pool. 379 Specifically, destroying sname:VkCommandPool frees all 380 sname:VkCommandBuffer objects that were allocated from it, and 381 destroying sname:VkDescriptorPool frees all sname:VkDescriptorSet 382 objects that were allocated from it. 383 * sname:VkDevice objects can: be destroyed when all sname:VkQueue objects 384 retrieved from them are idle, and all objects created from them have 385 been destroyed. 386 This includes the following objects: 387 ** sname:VkFence 388 ** sname:VkSemaphore 389 ** sname:VkEvent 390 ** sname:VkQueryPool 391 ** sname:VkBuffer 392 ** sname:VkBufferView 393 ** sname:VkImage 394 ** sname:VkImageView 395 ** sname:VkShaderModule 396 ** sname:VkPipelineCache 397 ** sname:VkPipeline 398 ** sname:VkPipelineLayout 399 ** sname:VkSampler 400ifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 401 ** basetype:VkSamplerYcbcrConversion 402endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[] 403 ** sname:VkDescriptorSetLayout 404 ** sname:VkDescriptorPool 405 ** sname:VkFramebuffer 406 ** sname:VkRenderPass 407 ** sname:VkCommandPool 408 ** sname:VkCommandBuffer 409 ** sname:VkDeviceMemory 410ifdef::VK_EXT_validation_cache[] 411 * sname:VkValidationCacheEXT 412endif::VK_EXT_validation_cache[] 413 * sname:VkPhysicalDevice objects cannot: be explicitly destroyed. 414 Instead, they are implicitly destroyed when the sname:VkInstance object 415 they are retrieved from is destroyed. 416 * sname:VkInstance objects can: be destroyed once all sname:VkDevice 417 objects created from any of its sname:VkPhysicalDevice objects have been 418 destroyed. 419 420 421ifdef::VK_VERSION_1_1,VK_KHR_external_memory_capabilities,VK_KHR_external_semaphore_capabilities,VK_KHR_external_fence_capabilities[] 422[[fundamentals-objectmodel-external]] 423=== External Object Handles 424 425As defined above, the scope of object handles created or allocated from a 426sname:VkDevice is limited to that logical device. 427Objects which are not in scope are said to be external. 428To bring an external object into scope, an external handle must: be exported 429from the object in the source scope and imported into the destination scope. 430 431[NOTE] 432.Note 433==== 434The scope of external handles and their associated resources may: vary 435according to their type, but they can: generally be shared across process 436and API boundaries. 437==== 438endif::VK_VERSION_1_1,VK_KHR_external_memory_capabilities,VK_KHR_external_semaphore_capabilities,VK_KHR_external_fence_capabilities[] 439 440 441[[fundamentals-abi]] 442== Application Binary Interface 443 444The mechanism by which Vulkan is made available to applications is platform- 445or implementation- defined. 446On many platforms the C interface described in this Specification is 447provided by a shared library. 448Since shared libraries can be changed independently of the applications that 449use them, they present particular compatibility challenges, and this 450Specification places some requirements on them. 451 452Shared library implementations must: use the default Application Binary 453Interface (ABI) of the standard C compiler for the platform, or provide 454customized API headers that cause application code to use the 455implementation's non-default ABI. 456An ABI in this context means the size, alignment, and layout of C data 457types; the procedure calling convention; and the naming convention for 458shared library symbols corresponding to C functions. 459Customizing the calling convention for a platform is usually accomplished by 460defining <<boilerplate-platform-specific-calling-conventions,calling 461convention macros>> appropriately in `vk_platform.h`. 462 463On platforms where Vulkan is provided as a shared library, library symbols 464beginning with "`vk`" and followed by a digit or uppercase letter are 465reserved for use by the implementation. 466Applications which use Vulkan must: not provide definitions of these 467symbols. 468This allows the Vulkan shared library to be updated with additional symbols 469for new API versions or extensions without causing symbol conflicts with 470existing applications. 471 472Shared library implementations should: provide library symbols for commands 473in the highest version of this Specification they support, and for 474ifdef::VK_KHR_surface[] 475<<wsi,Window System Integration>> 476endif::VK_KHR_surface[] 477ifndef::VK_KHR_surface[] 478Window System Integration 479endif::VK_KHR_surface[] 480extensions relevant to the platform. 481They may: also provide library symbols for commands defined by additional 482extensions. 483 484[NOTE] 485.Note 486==== 487These requirements and recommendations are intended to allow implementors to 488take advantage of platform-specific conventions for SDKs, ABIs, library 489versioning mechanisms, etc. 490while still minimizing the code changes necessary to port applications or 491libraries between platforms. 492Platform vendors, or providers of the _de facto_ standard Vulkan shared 493library for a platform, are encouraged to document what symbols the shared 494library provides and how it will be versioned when new symbols are added. 495 496Applications should: only rely on shared library symbols for commands in the 497minimum core version required by the application. 498flink:vkGetInstanceProcAddr and flink:vkGetDeviceProcAddr should: be used to 499obtain function pointers for commands in core versions beyond the 500application's minimum required version. 501==== 502 503 504[[fundamentals-commandsyntax]] 505== Command Syntax and Duration 506 507The Specification describes Vulkan commands as functions or procedures using 508C99 syntax. 509Language bindings for other languages such as C++ and JavaScript may: allow 510for stricter parameter passing, or object-oriented interfaces. 511 512Vulkan uses the standard C types for the base type of scalar parameters 513(e.g. types from `<stdint.h>`), with exceptions described below, or 514elsewhere in the text when appropriate: 515 516[open,refpage='VkBool32',desc='Vulkan boolean type',type='basetypes'] 517-- 518 519basetype:VkBool32 represents boolean `True` and `False` values, since C does 520not have a sufficiently portable built-in boolean type: 521 522include::../api/basetypes/VkBool32.txt[] 523 524ename:VK_TRUE represents a boolean *True* (integer 1) value, and 525ename:VK_FALSE a boolean *False* (integer 0) value. 526 527All values returned from a Vulkan implementation in a basetype:VkBool32 will 528be either ename:VK_TRUE or ename:VK_FALSE. 529 530Applications must: not pass any other values than ename:VK_TRUE or 531ename:VK_FALSE into a Vulkan implementation where a basetype:VkBool32 is 532expected. 533 534-- 535 536[open,refpage='VkDeviceSize',desc='Vulkan device memory size and offsets',type='basetypes'] 537-- 538 539basetype:VkDeviceSize represents device memory size and offset values: 540 541include::../api/basetypes/VkDeviceSize.txt[] 542 543-- 544 545Commands that create Vulkan objects are of the form ftext:vkCreate* and take 546stext:Vk*CreateInfo structures with the parameters needed to create the 547object. 548These Vulkan objects are destroyed with commands of the form 549ftext:vkDestroy*. 550 551The last in-parameter to each command that creates or destroys a Vulkan 552object is pname:pAllocator. 553The pname:pAllocator parameter can: be set to a non-`NULL` value such that 554allocations for the given object are delegated to an application provided 555callback; refer to the <<memory-allocation,Memory Allocation>> chapter for 556further details. 557 558Commands that allocate Vulkan objects owned by pool objects are of the form 559ftext:vkAllocate*, and take stext:Vk*AllocateInfo structures. 560These Vulkan objects are freed with commands of the form ftext:vkFree*. 561These objects do not take allocators; if host memory is needed, they will 562use the allocator that was specified when their parent pool was created. 563 564Commands are recorded into a command buffer by calling API commands of the 565form ftext:vkCmd*. 566Each such command may: have different restrictions on where it can: be used: 567in a primary and/or secondary command buffer, inside and/or outside a render 568pass, and in one or more of the supported queue types. 569These restrictions are documented together with the definition of each such 570command. 571 572The _duration_ of a Vulkan command refers to the interval between calling 573the command and its return to the caller. 574 575 576[[fundamentals-commandsyntax-results-lifetime]] 577=== Lifetime of Retrieved Results 578 579Information is retrieved from the implementation with commands of the form 580ftext:vkGet* and ftext:vkEnumerate*. 581 582Unless otherwise specified for an individual command, the results are 583_invariant_; that is, they will remain unchanged when retrieved again by 584calling the same command with the same parameters, so long as those 585parameters themselves all remain valid. 586 587 588[[fundamentals-threadingbehavior]] 589== Threading Behavior 590 591Vulkan is intended to provide scalable performance when used on multiple 592host threads. 593All commands support being called concurrently from multiple threads, but 594certain parameters, or components of parameters are defined to be 595_externally synchronized_. 596This means that the caller must: guarantee that no more than one thread is 597using such a parameter at a given time. 598 599More precisely, Vulkan commands use simple stores to update the state of 600Vulkan objects. 601A parameter declared as externally synchronized may: have its contents 602updated at any time during the host execution of the command. 603If two commands operate on the same object and at least one of the commands 604declares the object to be externally synchronized, then the caller must: 605guarantee not only that the commands do not execute simultaneously, but also 606that the two commands are separated by an appropriate memory barrier (if 607needed). 608 609[NOTE] 610.Note 611==== 612Memory barriers are particularly relevant for hosts based on the ARM CPU 613architecture, which is more weakly ordered than many developers are 614accustomed to from x86/x64 programming. 615Fortunately, most higher-level synchronization primitives (like the pthread 616library) perform memory barriers as a part of mutual exclusion, so mutexing 617Vulkan objects via these primitives will have the desired effect. 618==== 619 620Similarly the application must: avoid any potential data hazard of 621application-owned memory that has its 622<<fundamentals-objectmodel-lifetime-acquire,ownership temporarily acquired>> 623by a Vulkan command. 624While the ownership of application-owned memory remains acquired by a 625command the implementation may: read the memory at any point, and it may: 626write non-code:const qualified memory at any point. 627Parameters referring to non-code:const qualified application-owned memory 628are not marked explicitly as _externally synchronized_ in the Specification. 629 630Many object types are _immutable_, meaning the objects cannot: change once 631they have been created. 632These types of objects never need external synchronization, except that they 633must: not be destroyed while they are in use on another thread. 634In certain special cases mutable object parameters are internally 635synchronized, making external synchronization unnecessary. 636One example of this is the use of a sname:VkPipelineCache in 637fname:vkCreateGraphicsPipelines and fname:vkCreateComputePipelines, where 638external synchronization around such a heavyweight command would be 639impractical. 640The implementation must: internally synchronize the cache in this example, 641and may: be able to do so in the form of a much finer-grained mutex around 642the command. 643Any command parameters that are not labeled as externally synchronized are 644either not mutated by the command or are internally synchronized. 645Additionally, certain objects related to a command's parameters (e.g. 646command pools and descriptor pools) may: be affected by a command, and must: 647also be externally synchronized. 648These implicit parameters are documented as described below. 649 650Parameters of commands that are externally synchronized are listed below. 651 652include::../hostsynctable/parameters.txt[] 653 654There are also a few instances where a command can: take in a user allocated 655list whose contents are externally synchronized parameters. 656In these cases, the caller must: guarantee that at most one thread is using 657a given element within the list at a given time. 658These parameters are listed below. 659 660include::../hostsynctable/parameterlists.txt[] 661 662In addition, there are some implicit parameters that need to be externally 663synchronized. 664For example, all pname:commandBuffer parameters that need to be externally 665synchronized imply that the pname:commandPool that was passed in when 666creating that command buffer also needs to be externally synchronized. 667The implicit parameters and their associated object are listed below. 668 669include::../hostsynctable/implicit.txt[] 670 671 672[[fundamentals-errors]] 673== Errors 674 675Vulkan is a layered API. 676The lowest layer is the core Vulkan layer, as defined by this Specification. 677The application can: use additional layers above the core for debugging, 678validation, and other purposes. 679 680One of the core principles of Vulkan is that building and submitting command 681buffers should: be highly efficient. 682Thus error checking and validation of state in the core layer is minimal, 683although more rigorous validation can: be enabled through the use of layers. 684 685The core layer assumes applications are using the API correctly. 686Except as documented elsewhere in the Specification, the behavior of the 687core layer to an application using the API incorrectly is undefined, and 688may: include program termination. 689However, implementations must: ensure that incorrect usage by an application 690does not affect the integrity of the operating system, the Vulkan 691implementation, or other Vulkan client applications in the system. 692In particular, any guarantees made by an operating system about whether 693memory from one process can: be visible to another process or not must: not 694be violated by a Vulkan implementation for *any memory allocation*. 695Vulkan implementations are not required: to make additional security or 696integrity guarantees beyond those provided by the OS unless explicitly 697directed by the application's use of a particular feature or extension (e.g. 698via <<features-features-robustBufferAccess, robust buffer access>>). 699 700[NOTE] 701.Note 702==== 703For instance, if an operating system guarantees that data in all its memory 704allocations are set to zero when newly allocated, the Vulkan implementation 705must: make the same guarantees for any allocations it controls (e.g. 706slink:VkDeviceMemory). 707==== 708 709Applications can: request stronger robustness guarantees by enabling the 710pname:robustBufferAccess feature as described in <<features>>. 711 712Validation of correct API usage is left to validation layers. 713Applications should: be developed with validation layers enabled, to help 714catch and eliminate errors. 715Once validated, released applications should: not enable validation layers 716by default. 717 718 719[[fundamentals-validusage]] 720=== Valid Usage 721 722Valid usage defines a set of conditions which must: be met in order to 723achieve well-defined run-time behavior in an application. 724These conditions depend only on Vulkan state, and the parameters or objects 725whose usage is constrained by the condition. 726 727Some valid usage conditions have dependencies on run-time limits or feature 728availability. 729It is possible to validate these conditions against Vulkan's minimum 730supported values for these limits and features, or some subset of other 731known values. 732 733Valid usage conditions do not cover conditions where well-defined behavior 734(including returning an error code) exists. 735 736Valid usage conditions should: apply to the command or structure where 737complete information about the condition would be known during execution of 738an application. 739This is such that a validation layer or linter can: be written directly 740against these statements at the point they are specified. 741 742[NOTE] 743.Note 744==== 745This does lead to some non-obvious places for valid usage statements. 746For instance, the valid values for a structure might depend on a separate 747value in the calling command. 748In this case, the structure itself will not reference this valid usage as it 749is impossible to determine validity from the structure that it is invalid - 750instead this valid usage would be attached to the calling command. 751 752Another example is draw state - the state setters are independent, and can 753cause a legitimately invalid state configuration between draw calls; so the 754valid usage statements are attached to the place where all state needs to be 755valid - at the draw command. 756==== 757 758Valid usage conditions are described in a block labelled "`Valid Usage`" 759following each command or structure they apply to. 760 761 762[[fundamentals-implicit-validity]] 763=== Implicit Valid Usage 764 765Some valid usage conditions apply to all commands and structures in the API, 766unless explicitly denoted otherwise for a specific command or structure. 767These conditions are considered _implicit_, and are described in a block 768labelled "`Valid Usage (Implicit)`" following each command or structure they 769apply to. 770Implicit valid usage conditions are described in detail below. 771 772 773[[fundamentals-validusage-handles]] 774==== Valid Usage for Object Handles 775 776Any input parameter to a command that is an object handle must: be a valid 777object handle, unless otherwise specified. 778An object handle is valid if: 779 780 * It has been created or allocated by a previous, successful call to the 781 API. 782 Such calls are noted in the Specification. 783 * It has not been deleted or freed by a previous call to the API. 784 Such calls are noted in the Specification. 785 * Any objects used by that object, either as part of creation or 786 execution, must: also be valid. 787 788The reserved values dlink:VK_NULL_HANDLE and `NULL` can: be used in place of 789valid non-dispatchable handles and dispatchable handles, respectively, when 790_explicitly called out in the Specification_. 791Any command that creates an object successfully must: not return these 792values. 793It is valid to pass these values to ftext:vkDestroy* or ftext:vkFree* 794commands, which will silently ignore these values. 795 796 797[[fundamentals-validusage-pointers]] 798==== Valid Usage for Pointers 799 800Any parameter that is a pointer must: be a _valid pointer_ only if it is 801explicitly called out by a Valid Usage statement. 802 803A pointer is "`valid`" if it points at memory containing values of the 804number and type(s) expected by the command, and all fundamental types 805accessed through the pointer (e.g. as elements of an array or as members of 806a structure) satisfy the alignment requirements of the host processor. 807 808[[fundamentals-validusage-strings]] 809==== Valid Usage for Strings 810 811Any parameter that is a pointer to `char` must: be a finite sequence of 812values terminated by a null character, or if _explicitly called out in the 813Specification_, can: be `NULL`. 814 815 816[[fundamentals-validusage-enums]] 817==== Valid Usage for Enumerated Types 818 819Any parameter of an enumerated type must: be a valid enumerant for that 820type. 821A enumerant is valid if: 822 823 * The enumerant is defined as part of the enumerated type. 824 * The enumerant is not one of the special values defined for the 825 enumerated type, which are suffixed with etext:_BEGIN_RANGE, 826 etext:_END_RANGE, etext:_RANGE_SIZE or etext:_MAX_ENUM^1^. 827 8281:: 829 The meaning of these special tokens is not exposed in the Vulkan 830 Specification. 831 They are not part of the API, and they should: not be used by 832 applications. 833 Their original intended use was for internal consumption by Vulkan 834 implementations. 835 Even that use will no longer be supported in the future, but they will 836 be retained for backwards compatibility reasons. 837 838Any enumerated type returned from a query command or otherwise output from 839Vulkan to the application must: not have a reserved value. 840Reserved values are values not defined by any extension for that enumerated 841type. 842 843[NOTE] 844.Note 845==== 846This language is intended to accomodate cases such as "`hidden`" extensions 847known only to driver internals, or layers enabling extensions without 848knowledge of the application, without allowing return of values not defined 849by any extension. 850==== 851 852 853[[fundamentals-validusage-flags]] 854==== Valid Usage for Flags 855 856[open,refpage='VkFlags',desc='Vulkan bitmasks',type='basetypes',xrefs='VkColorComponentFlags'] 857-- 858 859A collection of flags is represented by a bitmask using the type 860basetype:VkFlags: 861 862include::../api/basetypes/VkFlags.txt[] 863 864Bitmasks are passed to many commands and structures to compactly represent 865options, but basetype:VkFlags is not used directly in the API. 866Instead, a etext:Vk*Flags type which is an alias of basetype:VkFlags, and 867whose name matches the corresponding etext:Vk*FlagBits that are valid for 868that type, is used. 869 870-- 871 872Any etext:Vk*Flags member or parameter used in the API as an input must: be 873a valid combination of bit flags. 874A valid combination is either zero or the bitwise OR of valid bit flags. 875A bit flag is valid if: 876 877 * The bit flag is defined as part of the etext:Vk*FlagBits type, where the 878 bits type is obtained by taking the flag type and replacing the trailing 879 etext:Flags with etext:FlagBits. 880 For example, a flag value of type elink:VkColorComponentFlags must: 881 contain only bit flags defined by elink:VkColorComponentFlagBits. 882 * The flag is allowed in the context in which it is being used. 883 For example, in some cases, certain bit flags or combinations of bit 884 flags are mutually exclusive. 885 886Any etext:Vk*Flags member or parameter returned from a query command or 887otherwise output from Vulkan to the application may: contain bit flags 888undefined in its corresponding etext:Vk*FlagBits type. 889An application cannot: rely on the state of these unspecified bits. 890 891 892[[fundamentals-validusage-sType]] 893==== Valid Usage for Structure Types 894 895Any parameter that is a structure containing a pname:sType member must: have 896a value of ptext:sType which is a valid elink:VkStructureType value matching 897the type of the structure. 898 899[open,refpage='VkStructureType',desc='Vulkan structure types (pname:stype)',type='enums'] 900-- 901Structure types supported by the Vulkan API include: 902 903include::../api/enums/VkStructureType.txt[] 904 905Each value corresponds to a particular structure with a pname:sType member 906with a matching name. 907As a general rule, the name of each ename:VkStructureType value is obtained 908by taking the name of the structure, stripping the leading etext:Vk, 909prefixing each capital letter with etext:_, converting the entire resulting 910string to upper case, and prefixing it with etext:VK_STRUCTURE_TYPE_. 911For example, structures of type sname:VkImageCreateInfo correspond to a 912ename:VkStructureType of ename:VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, and thus 913its pname:sType member must: equal that when it is passed to the API. 914 915The values ename:VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO and 916ename:VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO are reserved for internal 917use by the loader, and do not have corresponding Vulkan structures in this 918Specification. 919-- 920 921 922[[fundamentals-validusage-pNext]] 923==== Valid Usage for Structure Pointer Chains 924 925Any parameter that is a structure containing a `void*` ptext:pNext member 926must: have a value of pname:pNext that is either `NULL`, or points to a 927valid structure defined by an extension, containing ptext:sType and 928ptext:pNext members as described in the <<vulkan-styleguide,Vulkan 929Documentation and Extensions>> document in the section "`Extension 930Interactions`". 931The set of structures connected by ptext:pNext pointers is referred to as a 932_pname:pNext chain_. 933If that extension is supported by the implementation, then it must: be 934enabled. 935 936Each type of valid structure must: not appear more than once in a 937ptext:pNext chain. 938 939Any component of the implementation (the loader, any enabled layers, and 940drivers) must: skip over, without processing (other than reading the 941pname:sType and pname:pNext members) any structures in the chain with 942pname:sType values not defined by extensions supported by that component. 943 944Extension structures are not described in the base Vulkan Specification, but 945either in layered Specifications incorporating those extensions, or in 946separate vendor-provided documents. 947 948As a convenience to implementations and layers needing to iterate through a 949structure pointer chain, the Vulkan API provides the following base 950structures: 951 952include::../api/structs/VkBaseInStructure.txt[] 953 954include::../api/structs/VkBaseOutStructure.txt[] 955 956sname:VkBaseInStructure can be used to facilitate iterating through a 957read-only structure pointer chain. 958sname:VkBaseOutStructure can be used to facilitate iterating through a 959structure pointer chain that returns data back to the application. 960These structures allow for some type safety and can be used by Vulkan API 961functions that operate on generic inputs and outputs. 962 963[[fundamentals-validusage-nested-structs]] 964==== Valid Usage for Nested Structures 965 966The above conditions also apply recursively to members of structures 967provided as input to a command, either as a direct argument to the command, 968or themselves a member of another structure. 969 970Specifics on valid usage of each command are covered in their individual 971sections. 972 973 974[[fundamentals-validusage-extensions]] 975==== Valid Usage for Extensions 976 977Instance-level functionality or behavior added by an <<extensions, instance 978extension>> to the API must: not be used unless that extension is supported 979by the instance as determined by 980flink:vkEnumerateInstanceExtensionProperties, and that extension is enabled 981in slink:VkInstanceCreateInfo. 982 983Physical-device-level functionality or behavior added by an <<extensions, 984instance extension>> to the API must: not be used unless that extension is 985supported by the instance as determined by 986flink:vkEnumerateInstanceExtensionProperties, and that extension is enabled 987in slink:VkInstanceCreateInfo. 988 989Physical-device-level functionality or behavior added by a <<extensions, 990device extension>> to the API must: not be used unless the conditions 991described in <<initialization-phys-dev-extensions, Extending Physical Device 992Core Functionality>> are met. 993 994Device functionality or behavior added by a <<extensions, device extension>> 995to the API must: not be used unless that extension is supported by the 996device as determined by flink:vkEnumerateDeviceExtensionProperties, and that 997extension is enabled in slink:VkDeviceCreateInfo. 998 999 1000[[fundamentals-validusage-versions]] 1001==== Valid Usage for Newer Core Versions 1002 1003Instance-level functionality or behavior added by a <<versions, new core 1004version>> of the API must: not be used unless it is supported by the 1005instance as determined by flink:vkEnumerateInstanceVersion. 1006 1007Physical-device-level functionality or behavior added by a <<versions, new 1008core version>> of the API must: not be used unless it is supported by the 1009physical device as determined by flink:vkGetPhysicalDeviceProperties. 1010 1011Device-level functionality or behavior added by a <<versions, new core 1012version>> of the API must: not be used unless it is supported by the device 1013as determined by flink:vkGetPhysicalDeviceProperties. 1014 1015 1016[[fundamentals-returncodes]] 1017=== Return Codes 1018 1019[open,refpage='VkResult',desc='Vulkan command return codes',type='enums',xrefs='TBD'] 1020-- 1021 1022While the core Vulkan API is not designed to capture incorrect usage, some 1023circumstances still require return codes. 1024Commands in Vulkan return their status via return codes that are in one of 1025two categories: 1026 1027 * Successful completion codes are returned when a command needs to 1028 communicate success or status information. 1029 All successful completion codes are non-negative values. 1030 * Run time error codes are returned when a command needs to communicate a 1031 failure that could only be detected at run time. 1032 All run time error codes are negative values. 1033 1034All return codes in Vulkan are reported via elink:VkResult return values. 1035The possible codes are: 1036 1037include::../api/enums/VkResult.txt[] 1038 1039[[fundamentals-successcodes]] 1040.Success Codes 1041 * ename:VK_SUCCESS Command successfully completed 1042 * ename:VK_NOT_READY A fence or query has not yet completed 1043 * ename:VK_TIMEOUT A wait operation has not completed in the specified 1044 time 1045 * ename:VK_EVENT_SET An event is signaled 1046 * ename:VK_EVENT_RESET An event is unsignaled 1047 * ename:VK_INCOMPLETE A return array was too small for the result 1048ifdef::VK_KHR_swapchain[] 1049 * ename:VK_SUBOPTIMAL_KHR A swapchain no longer matches the surface 1050 properties exactly, but can: still be used to present to the surface 1051 successfully. 1052endif::VK_KHR_swapchain[] 1053 1054[[fundamentals-errorcodes]] 1055.Error codes 1056 * ename:VK_ERROR_OUT_OF_HOST_MEMORY A host memory allocation has failed. 1057 * ename:VK_ERROR_OUT_OF_DEVICE_MEMORY A device memory allocation has 1058 failed. 1059 * ename:VK_ERROR_INITIALIZATION_FAILED Initialization of an object could 1060 not be completed for implementation-specific reasons. 1061 * ename:VK_ERROR_DEVICE_LOST The logical or physical device has been lost. 1062 See <<devsandqueues-lost-device,Lost Device>> 1063 * ename:VK_ERROR_MEMORY_MAP_FAILED Mapping of a memory object has failed. 1064 * ename:VK_ERROR_LAYER_NOT_PRESENT A requested layer is not present or 1065 could not be loaded. 1066 * ename:VK_ERROR_EXTENSION_NOT_PRESENT A requested extension is not 1067 supported. 1068 * ename:VK_ERROR_FEATURE_NOT_PRESENT A requested feature is not supported. 1069 * ename:VK_ERROR_INCOMPATIBLE_DRIVER The requested version of Vulkan is 1070 not supported by the driver or is otherwise incompatible for 1071 implementation-specific reasons. 1072 * ename:VK_ERROR_TOO_MANY_OBJECTS Too many objects of the type have 1073 already been created. 1074 * ename:VK_ERROR_FORMAT_NOT_SUPPORTED A requested format is not supported 1075 on this device. 1076 * ename:VK_ERROR_FRAGMENTED_POOL A pool allocation has failed due to 1077 fragmentation of the pool's memory. 1078 This must: only be returned if no attempt to allocate host or device 1079 memory was made to accomodate the new allocation. 1080ifdef::VK_VERSION_1_1,VK_KHR_maintenance1[] 1081 This should: be returned in preference to 1082 ename:VK_ERROR_OUT_OF_POOL_MEMORY, but only if the implementation is 1083 certain that the pool allocation failure was due to fragmentation. 1084endif::VK_VERSION_1_1,VK_KHR_maintenance1[] 1085ifdef::VK_KHR_surface[] 1086 * ename:VK_ERROR_SURFACE_LOST_KHR A surface is no longer available. 1087 * ename:VK_ERROR_NATIVE_WINDOW_IN_USE_KHR The requested window is already 1088 in use by Vulkan or another API in a manner which prevents it from being 1089 used again. 1090endif::VK_KHR_surface[] 1091ifdef::VK_KHR_swapchain[] 1092 * ename:VK_ERROR_OUT_OF_DATE_KHR A surface has changed in such a way that 1093 it is no longer compatible with the swapchain, and further presentation 1094 requests using the swapchain will fail. 1095 Applications must: query the new surface properties and recreate their 1096 swapchain if they wish to continue presenting to the surface. 1097endif::VK_KHR_swapchain[] 1098ifdef::VK_KHR_display_swapchain[] 1099 * ename:VK_ERROR_INCOMPATIBLE_DISPLAY_KHR The display used by a swapchain 1100 does not use the same presentable image layout, or is incompatible in a 1101 way that prevents sharing an image. 1102endif::VK_KHR_display_swapchain[] 1103ifdef::VK_NV_glsl_shader[] 1104 * ename:VK_ERROR_INVALID_SHADER_NV One or more shaders failed to compile 1105 or link. 1106 More details are reported back to the application via 1107 `<<VK_EXT_debug_report>>` if enabled. 1108endif::VK_NV_glsl_shader[] 1109ifdef::VK_VERSION_1_1,VK_KHR_maintenance1[] 1110 * ename:VK_ERROR_OUT_OF_POOL_MEMORY A pool memory allocation has failed. 1111 This must: only be returned if no attempt to allocate host or device 1112 memory was made to accomodate the new allocation. 1113 If the failure was definitely due to fragmentation of the pool, 1114 ename:VK_ERROR_FRAGMENTED_POOL should: be returned instead. 1115endif::VK_VERSION_1_1,VK_KHR_maintenance1[] 1116ifdef::VK_VERSION_1_1,VK_KHR_external_memory,VK_KHR_external_semaphore,VK_KHR_external_fence[] 1117 * ename:VK_ERROR_INVALID_EXTERNAL_HANDLE An external handle is not a valid 1118 handle of the specified type. 1119endif::VK_VERSION_1_1,VK_KHR_external_memory,VK_KHR_external_semaphore,VK_KHR_external_fence[] 1120ifdef::VK_EXT_descriptor_indexing[] 1121 * ename:VK_ERROR_FRAGMENTATION_EXT A descriptor pool creation has failed 1122 due to fragmentation. 1123endif::VK_EXT_descriptor_indexing[] 1124 1125If a command returns a run time error, unless otherwise specified any output 1126parameters will have undefined contents, except that if the output parameter 1127is a structure with pname:sType and pname:pNext fields, those fields will be 1128unmodified. 1129Any structures chained from pname:pNext will also have undefined contents, 1130except that pname:sType and pname:pNext will be unmodified. 1131 1132Out of memory errors do not damage any currently existing Vulkan objects. 1133Objects that have already been successfully created can: still be used by 1134the application. 1135 1136Performance-critical commands generally do not have return codes. 1137If a run time error occurs in such commands, the implementation will defer 1138reporting the error until a specified point. 1139For commands that record into command buffers (ftext:vkCmd*) run time errors 1140are reported by fname:vkEndCommandBuffer. 1141 1142-- 1143 1144 1145[[fundamentals-numerics]] 1146== Numeric Representation and Computation 1147 1148Implementations normally perform computations in floating-point, and must: 1149meet the range and precision requirements defined under "`Floating-Point 1150Computation`" below. 1151 1152These requirements only apply to computations performed in Vulkan operations 1153outside of shader execution, such as texture image specification and 1154sampling, and per-fragment operations. 1155Range and precision requirements during shader execution differ and are 1156specified by the <<spirvenv-precision-operation, Precision and Operation of 1157SPIR-V Instructions>> section. 1158 1159In some cases, the representation and/or precision of operations is 1160implicitly limited by the specified format of vertex or texel data consumed 1161by Vulkan. 1162Specific floating-point formats are described later in this section. 1163 1164 1165[[fundamentals-floatingpoint]] 1166=== Floating-Point Computation 1167 1168Most floating-point computation is performed in SPIR-V shader modules. 1169The properties of computation within shaders are constrained as defined by 1170the <<spirvenv-precision-operation, Precision and Operation of SPIR-V 1171Instructions>> section. 1172 1173Some floating-point computation is performed outside of shaders, such as 1174viewport and depth range calculations. 1175For these computations, we do not specify how floating-point numbers are to 1176be represented, or the details of how operations on them are performed, but 1177only place minimal requirements on representation and precision as described 1178in the remainder of this section. 1179 1180ifdef::editing-notes[] 1181[NOTE] 1182.editing-note 1183==== 1184(Jon, Bug 14966) This is a rat's nest of complexity, both in terms of 1185describing/enumerating places such computation may: take place (other than 1186"`not shader code`") and in how implementations may: do it. 1187We have consciously deferred the resolution of this issue to post-1.0, and 1188in the meantime, the following language inherited from the OpenGL 1189Specification is inserted as a placeholder. 1190Hopefully it can: be tightened up considerably. 1191==== 1192endif::editing-notes[] 1193 1194We require simply that numbers`' floating-point parts contain enough bits 1195and that their exponent fields are large enough so that individual results 1196of floating-point operations are accurate to about 1 part in 10^5^. 1197The maximum representable magnitude for all floating-point values must: be 1198at least 2^32^. 1199 1200 :: [eq]#x {times} 0 = 0 {times} x = 0# for any non-infinite and 1201 non-[eq]#NaN# [eq]#x#. 1202 :: [eq]#1 {times} x = x {times} 1 = x#. 1203 :: [eq]#x {plus} 0 = 0 {plus} x = x#. 1204 :: [eq]#0^0^ = 1#. 1205 1206Occasionally, further requirements will be specified. 1207Most single-precision floating-point formats meet these requirements. 1208 1209The special values [eq]#Inf# and [eq]#-Inf# encode values with magnitudes 1210too large to be represented; the special value [eq]#NaN# encodes {ldquo}Not 1211A Number{rdquo} values resulting from undefined arithmetic operations such 1212as [eq]#0 / 0#. 1213Implementations may: support [eq]#Inf# and [eq]#NaN# in their floating-point 1214computations. 1215 1216 1217[[fundamentals-fp-conversion]] 1218=== Floating-Point Format Conversions 1219 1220When a value is converted to a defined floating-point representation, finite 1221values falling between two representable finite values are rounded to one or 1222the other. 1223The rounding mode is not defined. 1224Finite values whose magnitude is larger than that of any representable 1225finite value may be rounded either to the closest representable finite value 1226or to the appropriately signed infinity. 1227For unsigned destination formats any negative values are converted to zero. 1228Positive infinity is converted to positive infinity; negative infinity is 1229converted to negative infinity in signed formats and to zero in unsigned 1230formats; and any [eq]#NaN# is converted to a [eq]#NaN#. 1231 1232 1233[[fundamentals-fp16]] 1234=== 16-Bit Floating-Point Numbers 1235 123616-bit floating point numbers are defined in the "`16-bit floating point 1237numbers`" section of the <<data-format,Khronos Data Format Specification>>. 1238 1239 1240[[fundamentals-fp11]] 1241=== Unsigned 11-Bit Floating-Point Numbers 1242 1243Unsigned 11-bit floating point numbers are defined in the "`Unsigned 11-bit 1244floating point numbers`" section of the <<data-format,Khronos Data Format 1245Specification>>. 1246 1247 1248[[fundamentals-fp10]] 1249=== Unsigned 10-Bit Floating-Point Numbers 1250 1251Unsigned 10-bit floating point numbers are defined in the "`Unsigned 10-bit 1252floating point numbers`" section of the <<data-format,Khronos Data Format 1253Specification>>. 1254 1255 1256[[fundamentals-general]] 1257=== General Requirements 1258 1259Any representable floating-point value in the appropriate format is legal as 1260input to a Vulkan command that requires floating-point data. 1261The result of providing a value that is not a floating-point number to such 1262a command is unspecified, but must: not lead to Vulkan interruption or 1263termination. 1264For example, providing a negative zero (where applicable) or a denormalized 1265number to an Vulkan command must: yield deterministic results, while 1266providing a [eq]#NaN# or [eq]#Inf# yields unspecified results. 1267 1268Some calculations require division. 1269In such cases (including implied divisions performed by vector 1270normalization), division by zero produces an unspecified result but must: 1271not lead to Vulkan interruption or termination. 1272 1273 1274[[fundamentals-fixedconv]] 1275== Fixed-Point Data Conversions 1276 1277When generic vertex attributes and pixel color or depth _components_ are 1278represented as integers, they are often (but not always) considered to be 1279_normalized_. 1280Normalized integer values are treated specially when being converted to and 1281from floating-point values, and are usually referred to as _normalized 1282fixed-point_. 1283 1284In the remainder of this section, [eq]#b# denotes the bit width of the 1285fixed-point integer representation. 1286When the integer is one of the types defined by the API, [eq]#b# is the bit 1287width of that type. 1288When the integer comes from an <<resources-images,image>> containing color 1289or depth component texels, [eq]#b# is the number of bits allocated to that 1290component in its <<features-formats,specified image format>>. 1291 1292The signed and unsigned fixed-point representations are assumed to be 1293[eq]#b#-bit binary two's-complement integers and binary unsigned integers, 1294respectively. 1295 1296 1297[[fundamentals-fixedfpconv]] 1298=== Conversion from Normalized Fixed-Point to Floating-Point 1299 1300Unsigned normalized fixed-point integers represent numbers in the range 1301[eq]#[0,1]#. 1302The conversion from an unsigned normalized fixed-point value [eq]#c# to the 1303corresponding floating-point value [eq]#f# is defined as 1304 1305[latexmath] 1306++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1307f = { c \over { 2^b - 1 } } 1308++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1309 1310Signed normalized fixed-point integers represent numbers in the range 1311[eq]#[-1,1]#. 1312The conversion from a signed normalized fixed-point value [eq]#c# to the 1313corresponding floating-point value [eq]#f# is performed using 1314 1315[latexmath] 1316++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1317f = \max\left( {c \over {2^{b-1} - 1}}, -1.0 \right) 1318++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1319 1320Only the range [eq]#[-2^b-1^ {plus} 1, 2^b-1^ - 1]# is used to represent 1321signed fixed-point values in the range [eq]#[-1,1]#. 1322For example, if [eq]#b = 8#, then the integer value [eq]#-127# corresponds 1323to [eq]#-1.0# and the value 127 corresponds to [eq]#1.0#. 1324Note that while zero is exactly expressible in this representation, one 1325value ([eq]#-128# in the example) is outside the representable range, and 1326must: be clamped before use. 1327This equation is used everywhere that signed normalized fixed-point values 1328are converted to floating-point. 1329 1330 1331[[fundamentals-fpfixedconv]] 1332=== Conversion from Floating-Point to Normalized Fixed-Point 1333 1334The conversion from a floating-point value [eq]#f# to the corresponding 1335unsigned normalized fixed-point value [eq]#c# is defined by first clamping 1336[eq]#f# to the range [eq]#[0,1]#, then computing 1337 1338 :: [eq]#c = convertFloatToUint(f {times} (2^b^ - 1), b)# 1339 1340where [eq]#convertFloatToUint}(r,b)# returns one of the two unsigned binary 1341integer values with exactly [eq]#b# bits which are closest to the 1342floating-point value [eq]#r#. 1343Implementations should: round to nearest. 1344If [eq]#r# is equal to an integer, then that integer value must: be 1345returned. 1346In particular, if [eq]#f# is equal to 0.0 or 1.0, then [eq]#c# must: be 1347assigned 0 or [eq]#2^b^ - 1#, respectively. 1348 1349The conversion from a floating-point value [eq]#f# to the corresponding 1350signed normalized fixed-point value [eq]#c# is performed by clamping [eq]#f# 1351to the range [eq]#[-1,1]#, then computing 1352 1353 :: [eq]#c = convertFloatToInt(f {times} (2^b-1^ - 1), b)# 1354 1355where [eq]#convertFloatToInt(r,b)# returns one of the two signed 1356two's-complement binary integer values with exactly [eq]#b# bits which are 1357closest to the floating-point value [eq]#r#. 1358Implementations should: round to nearest. 1359If [eq]#r# is equal to an integer, then that integer value must: be 1360returned. 1361In particular, if [eq]#f# is equal to -1.0, 0.0, or 1.0, then [eq]#c# must: 1362be assigned [eq]#-(2^b-1^ - 1)#, 0, or [eq]#2^b-1^ - 1#, respectively. 1363 1364This equation is used everywhere that floating-point values are converted to 1365signed normalized fixed-point. 1366 1367 1368[[fundamentals-versionnum]] 1369== API Version Numbers and Semantics 1370 1371The Vulkan version number is used in several places in the API. 1372In each such use, the API _major version number_, _minor version number_, 1373and _patch version number_ are packed into a 32-bit integer as follows: 1374 1375 * The major version number is a 10-bit integer packed into bits 31-22. 1376 * The minor version number is a 10-bit integer packed into bits 21-12. 1377 * The patch version number is a 12-bit integer packed into bits 11-0. 1378 1379Differences in any of the Vulkan version numbers indicates a change to the 1380API in some way, with each part of the version number indicating a different 1381scope of changes. 1382 1383A difference in patch version numbers indicates that some usually small part 1384of the Specification or header has been modified, typically to fix a bug, 1385and may: have an impact on the behavior of existing functionality. 1386Differences in this version number should: not affect either _full 1387compatibility_ or _backwards compatibility_ between two versions, or add 1388additional interfaces to the API. 1389 1390A difference in minor version numbers indicates that some amount of new 1391functionality has been added. 1392This will usually include new interfaces in the header, and may: also 1393include behavior changes and bug fixes. 1394Functionality may: be deprecated in a minor revision, but will not be 1395removed. 1396The patch version will continue to increment through minor version number 1397changes since all minor versions are generated from the same source files, 1398and changes to the source files may affect all minor versions within a major 1399version. 1400Differences in the patch version should: not affect backwards compatibility, 1401but will affect full compatibility. 1402The patch version of the Specification is taken from 1403dlink:VK_HEADER_VERSION. 1404 1405A difference in major version numbers indicates a large set of changes to 1406the API, potentially including new functionality and header interfaces, 1407behavioral changes, removal of deprecated features, modification or outright 1408replacement of any feature, and is thus very likely to break any and all 1409compatibility. 1410Differences in this version will typically require significant modification 1411to an application in order for it to function. 1412 1413C language macros for manipulating version numbers are defined in the 1414<<boilerplate-versions,Version Number Macros>> appendix. 1415 1416 1417[[fundamentals-common-objects]] 1418== Common Object Types 1419 1420Some types of Vulkan objects are used in many different structures and 1421command parameters, and are described here. 1422These types include _offsets_, _extents_, and _rectangles_. 1423 1424 1425=== Offsets 1426 1427Offsets are used to describe a pixel location within an image or 1428framebuffer, as an (x,y) location for two-dimensional images, or an (x,y,z) 1429location for three-dimensional images. 1430 1431[open,refpage='VkOffset2D',desc='Structure specifying a two-dimensional offset',type='structs'] 1432-- 1433 1434A two-dimensional offsets is defined by the structure: 1435 1436include::../api/structs/VkOffset2D.txt[] 1437 1438 * pname:x is the x offset. 1439 * pname:y is the y offset. 1440 1441include::../validity/structs/VkOffset2D.txt[] 1442-- 1443 1444[open,refpage='VkOffset3D',desc='Structure specifying a three-dimensional offset',type='structs'] 1445-- 1446 1447A three-dimensional offset is defined by the structure: 1448 1449include::../api/structs/VkOffset3D.txt[] 1450 1451 * pname:x is the x offset. 1452 * pname:y is the y offset. 1453 * pname:z is the z offset. 1454 1455include::../validity/structs/VkOffset3D.txt[] 1456-- 1457 1458 1459=== Extents 1460 1461Extents are used to describe the size of a rectangular region of pixels 1462within an image or framebuffer, as (width,height) for two-dimensional 1463images, or as (width,height,depth) for three-dimensional images. 1464 1465[open,refpage='VkExtent2D',desc='Structure specifying a two-dimensional extent',type='structs'] 1466-- 1467 1468A two-dimensional extent is defined by the structure: 1469 1470include::../api/structs/VkExtent2D.txt[] 1471 1472 * pname:width is the width of the extent. 1473 * pname:height is the height of the extent. 1474 1475include::../validity/structs/VkExtent2D.txt[] 1476-- 1477 1478[open,refpage='VkExtent3D',desc='Structure specifying a three-dimensional extent',type='structs'] 1479-- 1480 1481A three-dimensional extent is defined by the structure: 1482 1483include::../api/structs/VkExtent3D.txt[] 1484 1485 * pname:width is the width of the extent. 1486 * pname:height is the height of the extent. 1487 * pname:depth is the depth of the extent. 1488 1489include::../validity/structs/VkExtent3D.txt[] 1490-- 1491 1492 1493=== Rectangles 1494 1495[open,refpage='VkRect2D',desc='Structure specifying a two-dimensional subregion',type='structs'] 1496-- 1497 1498Rectangles are used to describe a specified rectangular region of pixels 1499within an image or framebuffer. 1500Rectangles include both an offset and an extent of the same dimensionality, 1501as described above. 1502Two-dimensional rectangles are defined by the structure 1503 1504include::../api/structs/VkRect2D.txt[] 1505 1506 * pname:offset is a slink:VkOffset2D specifying the rectangle offset. 1507 * pname:extent is a slink:VkExtent2D specifying the rectangle extent. 1508 1509include::../validity/structs/VkRect2D.txt[] 1510-- 1511