当前位置:网站首页>Vulkan specification notes (I) Chapter 1 to Chapter 6

Vulkan specification notes (I) Chapter 1 to Chapter 6

2022-06-09 17:53:00 VII Du ° C

Preface

   Study Vulkan It's been more than a year , It's the beginning . But if you want to know Vulkan More features of , Simply developing a rendering engine is not an in-depth understanding . After all, engines only use mainstream graphics API Universal interface . such “backend” It makes sense . But people like me who are seriously partial to science , I prefer to specialize in one kind of graphics API. So read Vulkan Normative documentation is a required course ! Finally, I found some time to read some , First, sort out your notes . Maybe it will stop for nearly three months , Take time to make up C++ The foundation of parallel programming . This helps to understand Vulkan Command The underlying logic of .

Vulkan standard :https://www.khronos.org/registry/vulkan/specs/1.3-extensions/pdf/vkspec.pdf
Be careful : The specification is now available in Chinese (http://spec.vulkan.org.cn/), However, it is recommended to see the latest version of the specification in the official address !

  


Chapter one

  • Vulkan yes c99 API

The third chapter Fundamentals

Host and device environments

  • Must support 8 position 、16 position 、32 position 、64 Bit signed and unsigned bit integers
  • Must support 16 Bit and 32 Bit floating point

Execution mode

  • Vulkan One or more... Can be turned on device
  • Every device One or more... Can be turned on queue
  • Every queue Can be executed asynchronously ( Different device Of queue Independent 、 Asynchronous execution )
  • device Supported by queue To classify ---- Divided into families
  • Every family Support one or more types of functions .
    • Contains multiple... With similar characteristics queue
  • Single family Medium queues It's compatible with each other 、queue The generated work can be done in this family Execute in any queue within
  • queue The following types of functions can be supported
    • Video decoding
    • Video coding
    • Graph drawing
    • Calculation
    • transfer
    • sparse memory management
  • A single device Sure report Multiple similar queue family. Although the same family Different queue Have similar abilities . But they are incompatible
  • device memory Is explicitly managed by the application
  • Every device One or more heaps can be published 、 Each heap represents a different memory region
  • A heap can be device-local or host-local、 Yes device so
  • Heap commonly used are
    • device-local Is physically connected to device Of memory
    • device-local、 host visible Is the host visible memory
    • host-local、 host visible It is local to the host 、 For the host and device Visible memory

Queue Operation

  • queue It's driving device The interface of . The command is recorded in the command buffer before execution , And then write queue In the implementation of . Once the command is submitted to queue, The command is executed , No need to intervene .
  • The order in which commands are executed depends on implicit and explicit sort constraints
  • After submitting the command, you can obtain a semaphore list 、 Used to wait and signal after completion
  • Commands in different queues are independent of each other 、 Explicit sorting between different queues or between hosts and queues can use semaphores and fences
  • There are several commands
    • Perform the operation
      • draw
      • dispatch Dispatch
      • clear
      • copy
      • query /timestamp operations
      • begin /end
      • subpass operations
    • Set the state of
      • bind pipelines
      • descriptor sets and buffers
      • set dynamic state
      • push constants
      • set render
      • pass /subpass state
    • Perform synchronization
      • set/wait event
      • pipeline barrier
      • render pass /subpass rely on

object model

  • There are two types of Handel
    • Schedulable
      • Is an opaque type pointer , It is a API Part of the order . And as the API The first parameter of
      • A schedulable object can only have one in its life cycle Handel
    • Not schedulable
      • Handel Is an implementation dependent 64 Bit integer type
      • If VkDevice Turn on privateData characteristic
        • Each in this device An object of non schedulable type created on is in the life cycle of the object , There has to be only one Handel
      • If Handel Is not the only , Other similar types of Handel Invalid
  • VkDevice All objects created are private , Cannot be used for other device

object lifetime

  • adopt vkCreate… and vkAllocate… Command to create or assign objects
    • After creation or assignment , Although the contents of some objects can be changed freely , But the structure of objects is mostly considered immutable
    • vkDestroy… and vkFree… The commands are to destroy or release the object
  • The following object Type in any API The command cannot be destroyed during use
    • VkShaderModule
    • VkPipelineCache
    • VkValidationCacheEXT
  • In command VkRenderPass Rules of use
    • You can use the assigned descriptor sets The operation command on gets VkDescriptorSetLayout objects
    • When descriptor set layout Be destroyed when the , these descriptor sets Out of commission vkUpdateDescriptorSets updated
    • Use VkDescriptorSetLayout objec When you create another object as a parameter , At the end of the command , The object cannot be further accessed
  • In all use object Before the execution is complete , The application must not destroy any other type of Vulkan object
  • When anything command buffer Cannot be destroyed while in use Vulkan object
    • VkEvent
    • VkQueryPool
    • VkBuffer
    • VkBufferView
    • VkImage
    • VkImageView
    • VkPipeline
    • VkSampler
    • VkSamplerYcbcrConversion
    • VkDescriptorPool
    • VkFramebuffer
    • VkRenderPass
    • VkCommandBuffer
    • VkCommandPool
    • VkDeviceMemory
    • VkDescriptorSet
    • VkIndirectCommandsLayoutNV
    • VkAccelerationStructureNV
    • VkAccelerationStructureKHR
  • When queue Objects that cannot be destroyed during execution
    • VkFence
    • VkSemaphore
    • VkCommandBuffer
    • VkCommandPool
  • Objects that can be destroyed at any time (page 11)
  • VkPhysicalDevice Will be implicitly destroyed
  • VkInstance Will be in VkDevice It can only be destroyed after being destroyed

External Object Handle

  • external handle How to import

Application Binary Interface

  • Common library interface definitions , I don't care about

Command Syntax and Durati

  • Parametric theory , It's all basic content

ThreadingBehavior

  • External synchronization command : although Vulkan Multithreading support , But some commands must be executed in a single thread
    • These orders are in (page 16)

Valid Usage

  • Defines a set of conditions that must be met , To implement well-defined runtime behavior in the application
  • These conditions only depend on Vulkan state , The state of parameters and objects is limited by these conditions

Usage Validation

  • Vulkan It is a hierarchical structure API、 The lowest level is the core of this specification API
  • Applications can be used at the core API Debug at the level above 、 verification , Or other uses
  • Use... Correctly API Approach is to : Enable the validation layer during development , Close the validation layer when publishing

Implicit Valid Usage

  • Not paying attention for the time being

VkResult Return Code

*  The return value type can be found here 

Numeric Representation and Computa

*  Value types and conversions can be found in this section 

Floating-Point Computation

Floating-Point Format Conversion

16-Bit Floating-Point Numbers

Unsigned 11-Bit Floating-Point Number

Unsigned 10-Bit Floating-Point Numbers

General Requirement

Fixed-Point Data Conversions

Conversion from Normalized Fixed-Point to Floating-Point

  • Here are the specific formulas for type conversion

Conversion from Floating-Point to Normalized Fixed-Point

  • Here are the specific formulas for type conversion

Common Object Types

Offsets

  • Used to represent images and framebuffer The pixel position of
    • VkOffset2D
    • VkOffset3D

Extents

  • Used to represent an image or framebuffer The size of the rectangular region of the inner pixel
    • VkExtent2D
    • VkExtent3D

Rectangles

  • Used to describe an image or framebuffer The specified rectangular area of the inner pixel
    • VkRect2D
    • There's one in there offsets and extents

Structure Types

  • Correspondence between type and structure
    • Type name to mourn vk, The rest of the names are capitalized with _ Separate , Finally, add... To the front VK_STRUCTURE_TYPE_
    • VkImageCreateInfo->VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
  • The structure type can be found in (page 47) Inquire about

API Name Aliases

  • Aliases don't care

Chapter four Initialization

  • Use Vulkan You must load the command and create VkInstance object

Command Function Pointers

  • Vulkan The command does not need to use static links 、Vulkan The function pointer of the command can be obtained by using the following function
    • vkGetInstanceProcAddr
      • It will load the function pointer of the corresponding platform
      • Platform specific API Dynamically load function pointers
  • In order to support multiple Vulkan Realization 、vkGetInstanceProcAddr The returned function pointer may point to a different VkDevice Object or its child object implementation
  • By using VkDevice or VkDevice Child object as its schedulable object , Get device specific function pointers , You can avoid VkDevice Object's internal scheduling overhead .
  • You can use the following command to get such a function pointer :
    • vkGetDeviceProcAddr

Extending Physical Device Core Functionality

  • When physical-device The version is greater than or equal to that of adding new functions Vulkan version , You can use the new physical-device-level function .physical dev Supported by Vulkan Version can be accessed by calling vkGetPhysicalDeviceProperties To get .

Extending Physical Device From Device Extensions

  • When VK_KHR_get_physical_device_properties2 Extensions are enabled , or instance and physical-device The version of is greater than or equal to 1.1 when ,device Of physical-device-level Functions can be used
  • If it is from device extension In order to get physical-device-level Function pointer to the command , have access to vkGetInstanceProcAddr. The obtained function pointer can point to different VkPhysicalDevice Object to call the scheduling code of different implementations
  • The application must not be used in this physical device The extension or core version of is not supported by VkPhysicalDevice Any commands added
  • Device extensions You can define a structure and add it to physical-device-level Ordered pNext in

Instances

  • Vulkan There is no global state in , all per-application The states of are stored in One VkInstance In the object .
  • establish VkInstance Object will be initialized Vulkan library , And allow the application to pass information about itself to the implementation .
  • Instances from VkInstance The handle represents :
    • VK_DEFINE_HANDLE(VkInstance)
  • To query the supported instance-level Version of function , Please call :
    • vkEnumerateInstanceVersion
  • To create a Instances object
    • vkCreateInstance
  • If you need to capture create or destroy Instances What happened when , Can be in VkInstanceCreateInfo Of pNext Fill in VkDebugReportCallbackCreateInfoEXT or VkDebugUtilsMessengerCreateInfoEXT
  • VkInstanceCreateFlagBits
    • VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR Appoint instance Enumerations will match Vulkan Available physical devices and groups for portability , And enumerated by default Vulkan Physical devices and groups .
  • The verification check needs to be disabled. You can VkInstanceCreateInfo Of pNext Add VkValidationFlagsEXT
  • To enable or disable a specific authentication function Vulkan When an instance , take VkValidationFeaturesEXT Add to VkInstanceCreateInfo Of pNext in
  • because Vulkan 1.0 Implementation may result from VK_ERROR_INCOMPATIBLE_DRIVER Failure , So the application should call vkCreateInstance Determine available before Vulkan edition . If vkGetInstanceProcAddr by vkEnumerateInstanceVersion return NULL, Then it is Vulkan 1.0 Realization . otherwise , The application can call vkEnumerateInstanceVersion To make sure Vulkan Version of .
  • as long as instance At least support Vulkan 1.1, The application can be used to instance Use different versions of Vulkan, Not right. device or physical device Use different versions .
  • instance Supported versions and physical device The logic that supports different versions can be accessed from (page 99) see
  • Host Synchronizatio
    • The host is right instance Access to must be synchronized externally
    • Master to slave instance Enumerate all VkPhysicalDevice Object access must be synchronized externally

The fifth chapter Devices and Queue

  • once Vulkan Initialized ,device and queue It is used to communicate with Vulkan The main object of the interaction .
  • Vulkan Yes physical and logical device Points 、physical device Express GPU、 and logical device It means that we should GPU One of them is independent of the others logical device Status of and instances of resources
  • VkPhysicalDevice handles
    • VK_DEFINE_HANDLE(VkPhysicalDevice)

Physical Devices

  • List the installed in the system GPU list , call :
    • vkEnumeratePhysicalDevices
  • To query the enumerated GPU Properties of , call :
    • vkGetPhysicalDeviceProperties
    • vkGetPhysicalDeviceProperties2
    • vkGetPhysicalDeviceProperties2KHR
    • In the query results vendorID and deviceID Is to allow the application to adapt by other Vulkan Query for device features that are not fully disclosed .
      • These may include performance profiles , Hardware errata or other features .
    • GPU The specific information that can be queried is in (page 105) Inquire about
  • VkPhysicalDeviceVulkan13Properties
    • This series of functions will be based on Vulkan New functions are added in the version upgrade
    • VkPhysicalDeviceVulkan**Properties
  • Applications can span instance Compare with the process driverUUID Value , It can be outside API For similar queries , To determine if they can be compared with device Shared memory objects and resources .
  • If you want to know driverUUID You can read this section for related matters , I don't need to know for the time being
  • VkPhysicalDevicePCIBusInfoPropertiesEXT You can query PCI Bus information
  • VkPhysicalDeviceDrmPropertiesEXT You can query DRM Information
    • DRM Is a kernel level device driver
  • VkPhysicalDeviceShaderIntegerDotProductProperties Query calculation support
    • Optimize dot multiplication
  • vkGetPhysicalDeviceQueueFamilyProperties Inquire about query attribute
  • If the implementation exposes any that supports graphical operations queue family, Then the implementation exposes at least one physical device One of the queue family Both graphical and computational operations must be supported .
  • If the support protected memory physical device feature, Then the implementation exposes at least one physical device One of the queue family Must support at the same time graphics operations, compute operations, and protected memory operations
  • To query physical device Available on the queue Properties of , call :
    • vkGetPhysicalDeviceQueueFamilyProperties2
    • vkGetPhysicalDeviceQueueFamilyProperties2
  • queues family Related attributes can be found in (page 141) Inquire about

Devices

  • Device Object representation and physical device Logical connection of .
  • Created logical device yes physical device The interface of .
  • If more than one physical device Belong to the same device group, This group multiple physical device Create a single logical device
  • device group
    • A group of physical device, Support mutual access to each other's memory and single command buffer Can be in all physical device On the implementation
    • call vkEnumeratePhysicalDeviceGroups enumeration device group,
    • adopt VkDeviceGroupDeviceCreateInfo Set up physical device, from device group in physical device Create a subset of logical device
    • To make two physical device In the same device group , They must support the same extensions , Functions and properties .
  • Retrieve the list of device groups that exist in the system , call :
    • vkEnumeratePhysicalDeviceGroups
    • vkEnumeratePhysicalDeviceGroupsKHR

Device Creation

  • Logical device The handle represents :
    • VK_DEFINE_HANDLE(VkDevice)
  • To create a logical device , call :
    • vkCreateDevice
    • Want to set up Logical device The supported extensions can be found in this section
  • From the same physical device Create multiple Logical device.
  • To specify whether device memory allocation is allowed to exceed VkPhysicalDeviceMemoryProperties The size of the report , Please put VkDeviceMemoryOverallocationCreateInfoAMD Structure added to VkDeviceCreateInfo Structure of the pNext In the chain .
  • Use NsightTM Aftermath SDK when , To configure how device crash dumps are created , Please put VkDeviceDiagnosticsConfigCreateInfoNV Structure added to VkDeviceCreateInfo Structure of the pNext In the chain
  • Callbacks can be called from multiple threads at the same time .
    • When VkDeviceMemoryReportEventTypeEXT Event time , The implementation can only call the callback once .
    • Callbacks can be called from Vulkan A background thread other than the thread of the command calls .
    • The callback must not call any Vulkan command .
  • Memory event callbacks can be made in (page 165) Inquire about
  • If you want to use private data storage slots add to VkDevicePrivateDataCreateInfo

Device Use

  • Here are VkDevice Advanced list used
    • establish queue
    • Create and track various synchronization structures
    • Distribute 、 Free and manage memory
    • Create and destroy command buffer and command buffer pool
    • establish 、 Destruction and management graphics state

Lost Device

  • logical device May be lost due to some specific implementation , It is possible to make the command that is properly prepared for execution fail , And causes resources and allocated memory to become undefined .
  • logical device The reason for the loss
    • Run timeout
    • Power management events
    • Platform resource management
    • Implementation error
  • logical device The loss of will not affect VkPhysicalDevice
  • physical device It can also be lost , There may be a problem with the basic implementation or the connection to the host
  • When device When lost , Its children are not implicitly destroyed , Destroying objects or device These objects must be destroyed
  • When device When lost , And use vkMapMemory The host address space corresponding to the mapped device memory is still valid . And the host memory access to these mapped areas is still valid , But the content is not defined . And in device It is still legal to invoke any access command on and its child objects
  • device Execute the command without waiting for a long time, such as vkDeviceWaitIdle、vkQueueWaitIdle、vkWaitForFences or vkAcquireNextImageKHR You need to set the timeout , also vkGetQueryPoolResults Of flags Must contain VK_QUERY_RESULT_WAIT_BIT
  • device The command executed without waiting for a long time is device In case of loss, it must be returned within a limited time VK_SUCCESS or VK_ERROR_DEVICE_LOST
  • Any command can return VK_ERROR_DEVICE_LOST, To identify a command buffer Whether to suspend the status or think that the resource is in use

Device Destruction

  • The destruction Device
    • vkDestroyDevice
  • To ensure device No work is active on , have access to vkDeviceWaitIdle To stop device Destruction of .
  • The lifetime of each object is affected by VkDevice Object lifetime constraints . therefore , To avoid resource leakage , The application is calling vkDestroyDevice Explicitly release all these resources before

Queues

Queue Family Properties

  • You can use the command to get Queue Family and Queue Support related information
  • physical device in queue familie The group depends on the implementation .
  • Once the application chooses what it wants to use queue Marked physical device,physical device Will work with logical device Create these together queue

Queue Creation

  • establish logical device You will also create a connection to the device The associated queue . To be created queue from VkDeviceQueueCreateInfo describe , Set in the vkCreateDevice Of pQueueCreateInfos in
  • VkQueue handles
    • VK_DEFINE_HANDLE(VkQueue)
  • queue priority
    • Priority values are sorted in ascending order
    • Priority can be set
      • VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR
      • VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR
      • VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR
      • VK_QUEUE_GLOBAL_PRIORITY_REALTIME_KHR
    • With lower priority queue comparison , Higher system priority queue More processing time may be allocated
    • Implementation may allow higher priority queue Make lower priority queue Blocking , Until higher priority queue There is no command to execute .
    • Global priority queue Prior to the per-process Priority queue (VkDeviceQueueCreateInfo::pQueuePriorities)
    • obtain vkqueue Object handle
      • vkGetDeviceQueue
    • To obtain a VkDeviceQueueCreateFlags The information of vkqueue Object handle
      • vkGetDeviceQueue2

Queue Family Index

  • The queue family index stay Vulkan Multiple locations of are used . To bind an action to a specific family Of queue On
  • When using vkGetDeviceQueue Query a queue handle when ,Queue Family Index Used to select which to query queue family Of VkQueue handle
  • When creating a VkCommandPool Object time ,Queue Family Index Add VkCommandPoolCreateInfo in . Command buffers in this pool can only be queue family Corresponding queue Submit on .
  • When creating a VkImage and VkBuffer Resource time , A group of queue family Included in VkImageCreateInfo and VkBufferCreateInfo in . Used to specify which... Can access these resources queue families.
  • Insert VkBufferMemoryBarrier or VkImageMemoryBarrier when , The source and destination will be specified Queue Family Index, To allow ownership of the buffer or image to be transferred from one queue family Move to another queue family On .

Queue Priority

  • Every queue Are assigned a priority , Such as creating device when VkDeviceQueueCreateInfo As set in the structure . The priority of each queue is between 0.0 and 1.0 The floating point number between
  • 0.0 Represents the lowest priority 、1.0 Represents the highest priority
  • In the same device in , Higher priority queue May be lower priority than queue Allocate more processing time . This implementation does not guarantee sorting or scheduling between queues with the same priority ,
  • explicit synchronization primitives The priority scheduling order can be explicitly defined
  • Implementation does not guarantee difference device On queue The execution priority of
  • Implementations may allow higher priority queue In the same VkDevice To lower the priority of queue Blocking , Until the higher priority queue There are no other commands to execute .queue The priority relationship must not lead to a VkDevice Upper queue Make another VkDevice Of queue Blocking .
  • Implementation does not guarantee higher priority queue Lower than the priority level queue Get more processing time or better quality of service

Queue Submission

  • By using queue submission commands Submit the task to be executed to the queue
    • Such as vkQueueSubmit and vkQueueSubmit2
  • queue submission commands ( Queue submit command ) Define a set of physical device Queue operations performed
    • Including those used synchronously semaphores and fences
  • When the command is submitted, the target queue 、 Zero or more batches Work 、 Optional fence As a parameter , So as to signal when it is finished
  • Every batch It consists of three different parts
    • Before executing the rest of the batch , Wait for zero or more semaphores.
    • Zero or more work items to execute .
    • Zero or more semaphores , Used to signal when a work item is completed .
  • If... Exists in the queue submission fence, Then it describes fence Signal operation .
  • Before the command returns , All work described by the queue submit command must be submitted to the queue
  • Sparse Memory Binding
    • stay Vulkan in , Memory can be sparsely associated with buffers and images Binding
    • Sparse Memory Binding It is a queue operation
    • contain VK_QUEUE_SPARSE_BINDING_BIT The queue must be able to support mapping virtual addresses to physical addresses on the device .
    • This operation will update device Page table mapping on . The update must be synchronized on the queue , To avoid damaging the page table mapping during the execution of graphic commands .

Queue Destruction

  • The line is in vkCreateDevice During the period and logical device Created together . stay logical device On the call . vkDestroyDevice when , With this logical device All associated queues will be destroyed .

Chapter six Command Buffers

  • Command buffers Is the object used to record commands 、 These commands can then be submitted to device queue In the implementation of
  • Command buffers There are two levels
    • primary command buffers
      • It can be executed secondary command buffers, And can be submitted to queue in ,
    • secondary command buffers
      • May by primary command buffers perform , And cannot be submitted directly to queue in
  • Command buffers from VkCommandBuffer The handle represents :
    • VK_DEFINE_HANDLE(VkCommandBuffer)
  • The recorded commands include
    • take pipelines and descriptor sets Bound to the command buffer The order of
    • Used to modify the dynamic state (dynamic state) The order of
    • Draw command ( For rendering )
    • Scheduling commands (dispatch)、 Used to calculate
    • Used to perform secondary command buffers The order of ( Only applicable to primary command buffer)
    • Used to copy buffers and images The order of
    • Other commands
  • Every command buffer Independent of others command buffer Management status of
    • stay primary command buffers and secondary command buffers Between , Or in the secondary command buffers Between , No state inheritance
  • exception
    • If primary command buffer be located render pass In case , be secondary command buffers Will not interfere with render pass and subpass state .
  • When command buffers Start recording、command buffer All States in are undefined
    • For state related commands ( Such as drawing and scheduling ), Any state used by these commands must not be undefined
  • VkCommandBufferInheritanceViewportScissorInfoNV Defines an exception (exception、 I think it should be translated into an exception ), Allow dynamic viewport and scissor Limited inheritance of States .

Command Buffer Lifecycle

  • Every command buffer Always in one of the following states :
    • Initial
      • Distribute command buffer when , It's in its initial state . Some commands can put command buffer( Or a group command buffer)Executable、Recording or Invalid Reset back to this state .
      • stay Initial In state command buffer The status can only be changed to recording Or release
    • Recording
      • vkBeginCommandBuffer take command buffer The state of is changed from the initial state to the recording state .command buffer After recording , have access to vkCmd* Command record the command to command buffer
    • Executable
      • vkEndCommandBuffer end command buffer The record of , And move it from the recording state to the executable state . The executable command buffer You can submit 、 Reset or record to another command buffer.
    • Pending
      • command buffer The queue submission of will command buffer The state of is changed from executable state to pending state . When suspended , The application must not attempt to modify... In any way command buffer
      • command buffer After execution , The command buffer will revert to the executable state
      • If you use VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT Record ,command buffer Move to invalid state . You should use synchronization Command to detect when this happens .
    • Invalid
      • Some operations ( For example, the modification or deletion is recorded in command buffer Resources used in the command of ) Will be the command buffer The state of changes to an invalid state . In an invalid state command buffer Only reset or release .
    • Reset command buffer
      • vkResetCommandBuffer
      • vkResetCommandPool
  • Secondary command buffers Can pass vkCmdExecuteCommands It was recorded that primary command buffer
    • Secondary command buffers The execution status of will follow primary command buffer change
    • If primary command buffer Submit to queue , be primary command buffer And any... Recorded in the queue Secondary command buffers Will enter the suspended state .
    • once primary command buffer Execution completed , Any... Recorded therein Secondary command buffers It is also executed .
    • If Secondary command buffers Set to invalid state or initial state , Then all primary command buffer Will change to invalid state .(??? It is not possible to determine whether the translation is correct )
    • primary command buffer Setting to any other state does not affect the Secondary command buffers state .
  • Reset or release primary command buffer Will delete and record all Secondary command buffers Life cycle links for .

Command Pools

  • Command pools yes command buffer memory Allocate opaque objects in memory , It allows implementation in multiple command buffer Apportion the cost of resource creation between
  • Command pools Is external synchronization (externally synchronized) Of , This means that you must not use... In multiple threads at the same time command pool
    • This includes through the command pool Any assigned command buffer Record operation 、 And distribution , Destroy and reset command buffer or command pool Its own operation
  • Command Pools from VkCommandPool The handle represents :
    • VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)
  • To create a Command Pools
    • vkCreateCommandPool
  • To trim (trim) CommandPool,call:
    • vkTrimCommandPool
    • vkTrimCommandPoolKHR
  • trim CommandPool It's from Command Pools Reclaim unused memory into the system
    • from Pool The distribution of Command buffers Not affected by this command .
    • This command provides the application with access to Command Pool Some degree of control over the use of internal memory allocation .
    • command buffers Unused memory ( Include recorded、 later reset) stay reset when ,command buffer The memory used will be returned to Command Pool
    • To put Command Pool The memory returned to the operating system must be used VKResetCommandPool
      • When Command Pool There is command buffer Cannot execute while in use
    • command buffer Operation reuse Command Pool Memory in , Therefore, memory fragmentation will occur
    • under these circumstances , tailoring (trimming)Command Pool Memory fragments can be returned to the operating system . take pool The total memory allocated is reset to a more average size to reduce fragmentation
    • Vulkan The implementation uses many internal allocation strategies . This makes it impossible to ensure that all unused memory is released back to the system
      • for example Command Pool Of sub-allocating It is possible to allocate memory from the operating system , Even if only a small portion of the memory is in use , It will also prevent memory from being freed
    • in the majority of cases , Pruning results in less allocated but unused memory , But there is no guarantee “ Ideal ” Behavior
    • Pruning is an expensive operation , Should not be called frequently . When there is enough unused memory , Pruning should be used as a way to reduce memory pressure . Pay attention to the balance
  • To reset Command Pool
    • vkResetCommandPool
  • Reset Command Pool Will recycle all resources . from Command Pool All assigned command buffer All return to the original state .
  • From the other VkCommandPool recording or executable Status assigned primary command buffer and Have from commandPool To obtain the recording State of secondary command buffer, Reset invalid
  • Destroy command pool
    • vkDestroyCommandPool
    • When pool Be destroyed when the , All from pool Allocated in command buffer Will release .
    • From the other VkCommandPool recording or executable Status assigned primary command buffer and Have from commandPool To obtain the recording State of secondary command buffer, The destroy command is invalid

Command Buffer Allocation and Management

  • Distribute command buffers
    • vkAllocateCommandBuffers
    • VkallocateCommandBuffers Can be used to allocate multiple command buffers. If any one command buffer Allocation of failed , The implementation must release all successfully allocated from this command command buffer object , take PCommandBuffers All elements of the collection are set to null And return error .
    • Distribute command buffer after , Its initialization status is initial state
  • Reset command buffer,
    • vkResetCommandBuffer
    • stay recording or executable Status and has entered commandBuffer Any of them primary command buffer, The reset command will be invalid .
  • Release command buffer
    • vkFreeCommandBuffers

Command Buffer Recording

  • Start recording command buffer
    • vkBeginCommandBuffer
    • After the recording started , The application records a sequence of commands (vkCmd*), In the command buffer 、 draw 、 Set status in scheduling and other commands .
    • Or indirectly from vkbuffer Content records some commands
  • Complete recording of command buffer
    • vkEndCommandBuffer
  • If there is an error during recording , Will be passed vkEndCommandBuffer Return unsuccessful , To notify the application . If the application wants to use the command buffer further , The command buffer must be reset .
  • When the command buffer is in an executable state , It can be submitted to the queue for execution .

Command Buffer Submission

  • Submission is expensive (high overhead) operation , Applications should be submitted in batches , To minimize the use of vkQueueSubmit or vkQueueSubmit2.
  • Commit the command buffer to the queue
    • vkQueueSubmit2
    • vkQueueSubmit2KHR
  • Compared with other submit commands , Use vkQueueSubmit2 The semaphore operation submitted has additional constraints , Its dependencies involve previous and subsequent queue operations .
  • If any command buffer submitted to this queue is in an executable state , Then it will be moved to the pending state . After executing all commit of all command buffers , It will be taken from pending State moves to executable state . If you use VK_Command_Buffer_USAGE_ONE_TIME_SUBMIT_BIT FLAG Record command buffer , Will be moved back to the invalid state .
  • To commit the command buffer to a queue
    • vkQueueSubmit
    • The submission starts in the order of submission , However, there is no guarantee that the required sequence will be completed
  • The command buffer appears in PCommandBuffers The order in is used to determine the order of submission ,
  • Specifies the semaphore when waiting
    • VkTimelineSemaphoreSubmitInfo

Queue Forward Progress

  • The command buffer in the commit can include vkCmdWaitEvents command , This command will not wait in the queue for events issued by earlier commands . Such events must use VKSetEvent Applications that send signals , And wait for their vkCmdWaitEvents The order must not be in render pass In the example . Must be executed at vkCmdWaitEvents Set this event before the command .

Secondary Command Buffer Execution

  • secondary command buffer Do not submit directly to the queue . contrary , take secondary command buffer As primary command buffer Partial execution
  • vkCmdExecuteCommands

Command Buffer Device Mask

  • Every command buffe There is a current device mask for the state store command buffer . This mask controls logical device Which of the physical device All subsequent commands will execute , Including status setting commands , Operation command and synchronization command .
  • To update command buffe Current device mask for
    • vkCmdSetDeviceMask
    • vkCmdSetDeviceMaskKHR
原网站

版权声明
本文为[VII Du ° C]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091746059082.html