Descriptor Heaps
When the descriptorHeap feature is
enabled, applications can use descriptor heaps to specify the descriptors
that they will be accessing from shaders.
Descriptor heaps are not objects, rather they are state that is bound to a
command buffer indicating the device address of descriptors that can be
accessed from a shader.
There are two heaps available to the application - the sampler heap and the
resource heap.
The sampler heap contains sampler descriptors, the resource heap contains
image,
acceleration structure,
tensor,
and buffer descriptors.
Writing Descriptors
Descriptors can be obtained for the different heaps with commands that write sampler descriptors to host memory, with the application responsible for transferring those descriptors into device memory for access via heaps.
To write sampler descriptors to memory, call:
// Provided by VK_EXT_descriptor_heap
VkResult vkWriteSamplerDescriptorsEXT(
VkDevice device,
uint32_t samplerCount,
const VkSamplerCreateInfo* pSamplers,
const VkHostAddressRangeEXT* pDescriptors);
-
deviceis the logical device that the descriptors are for. -
samplerCountis the number of elements inpSamplersandpDescriptors. -
pSamplersis a pointer to an array of VkSamplerCreateInfo structures defining properties of the sampler descriptors that will be written. -
pDescriptorsis a pointer to an array of VkHostAddressRangeEXT structures defining the host address ranges that will be written to for each descriptor.
Each descriptor will be written to pDescriptors[i]→address where
i is the index of its create info in pSamplers.
Descriptors written using a fully identical VkSamplerCreateInfo structure on the same VkDevice will always return the same bit pattern. If the descriptorHeapCaptureReplay feature is enabled, descriptors written using a fully identical VkSamplerCreateInfo structure on a VkDevice created from the same VkPhysicalDevice with identical parameters will always return the same bit pattern.
|
YCBCR samplers must be embedded in a shader by using VkShaderDescriptorSetAndBindingMappingInfoEXT, they cannot be specified here. |
To write resource descriptors to memory, call:
// Provided by VK_EXT_descriptor_heap
VkResult vkWriteResourceDescriptorsEXT(
VkDevice device,
uint32_t resourceCount,
const VkResourceDescriptorInfoEXT* pResources,
const VkHostAddressRangeEXT* pDescriptors);
-
deviceis the logical device that the descriptors are for. -
resourceCountis the number of elements inpResourcesandpDescriptors. -
pResourcesis a pointer to an array of VkResourceDescriptorInfoEXT structures defining properties of the resource descriptors that will be written. -
pDescriptorsis a pointer to an array of VkHostAddressRangeEXT structures defining the host address ranges that will be written to for each descriptor.
Each descriptor will be written to pDescriptors[i]→address where
i is the index of its create info in pResources.
If any image descriptor written by this command includes a VkSamplerYcbcrConversion, multiple descriptors will be written adjacent to each other for that descriptor, equal to VkSamplerYcbcrConversionImageFormatProperties::combinedImageSamplerDescriptorCount for the image.
If any image descriptor written by this command is for an image created with
flags containing VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT, multiple
descriptors will be written adjacent to each other for that descriptor,
equal to
VkSubsampledImageFormatPropertiesEXT::subsampledImageDescriptorCount
for the image.
Descriptors using the same type and written using a fully identical
VkTexelBufferDescriptorInfoEXT or VkDeviceAddressRangeEXT
structure on the same VkDevice will always return the same bit
pattern.
If the descriptorHeapCaptureReplay
feature is enabled, this applies to any VkDevice created with
identical parameters from the same VkPhysicalDevice.
|
Recreating the same buffer descriptor during replay of a prior capture requires that the device address is the same, which requires additional data to be captured and provided during replay when creating a buffer and allocating memory for it. |
Image descriptors using the same type and written using a fully
identical VkImageDescriptorInfoEXT other than
VkImageDescriptorInfoEXT::pView->image, where image was
successfully created with
VK_IMAGE_CREATE_DESCRIPTOR_HEAP_CAPTURE_REPLAY_BIT_EXT and a
VkOpaqueCaptureDataCreateInfoEXT with data captured via
vkGetImageOpaqueCaptureDataEXT from an image used previously, will
write a descriptor with the same bit pattern if possible; if the same bit
pattern cannot be generated, VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS
will be returned instead.
Tensor descriptors using the same type and written using a fully
identical VkTensorViewCreateInfoARM other than
VkTensorViewCreateInfoARM::tensor, where tensor was successfully
created with VkOpaqueCaptureDataCreateInfoEXT with
VK_TENSOR_CREATE_DESCRIPTOR_HEAP_CAPTURE_REPLAY_BIT_ARM and a
VkOpaqueCaptureDataCreateInfoEXT with data captured via
vkGetTensorOpaqueCaptureDataARM from a tensor used previously, will
write a descriptor with the same bit pattern if possible; if the same bit
pattern cannot be generated, VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS
will be returned instead.
|
Image creation is sufficiently complex that it may not be possible to recreate all possible descriptors from an image during replay, even if the image itself was successfully recreated. The conditions for this happening will be largely the same as those which could cause allocating a buffer with the same device address during replay to fail. Replay tools are advised to recreate captured descriptors for an image immediately after recreating the image itself wherever possible. The same is true for tensors. |
VkResourceDescriptorInfoEXT is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkResourceDescriptorInfoEXT {
VkStructureType sType;
const void* pNext;
VkDescriptorType type;
VkResourceDescriptorDataEXT data;
} VkResourceDescriptorInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
typeis the type of descriptor to get. -
datais a VkResourceDescriptorDataEXT union defining the properties of a resource descriptor according totype
If type is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or
VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, data->pTexelBuffer is
used to construct the descriptor.
If type is
VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV,
VK_DESCRIPTOR_TYPE_PARTITIONED_ACCELERATION_STRUCTURE_NV,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, or
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, data->pAddressRange is used
to construct the descriptor.
For acceleration structures, the size of the range is not used by the
descriptor, and can be set to 0.
If a non-zero size is provided though, it must be a valid range.
|
Applications may wish to provide a valid range as a way to check their own assumptions about the range they are binding; but it has no bearing on anything except validation. Implementations cannot make any assumptions based on the size of the provided range. |
If type is VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
VK_DESCRIPTOR_TYPE_BLOCK_MATCH_IMAGE_QCOM,
VK_DESCRIPTOR_TYPE_SAMPLE_WEIGHT_IMAGE_QCOM,
VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, or
VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, data->pImage is used to
construct the descriptor.
If type is VK_DESCRIPTOR_TYPE_TENSOR_ARM, data->pTensorARM
is used to construct the descriptor.
If the nullDescriptor feature is enabled,
the corresponding element of data may be NULL to generate a null
descriptor.
Applications can give resource descriptors a debug name in a similar way to
naming an object, via the VkDebugUtilsObjectNameInfoEXT structure.
However, as there is no actual object, this structure must be passed via
the pNext chain of this structure, with a objectType of
VK_OBJECT_TYPE_UNKNOWN and a objectHandle of
VK_NULL_HANDLE.
The name is attached to the unique set of descriptor bits written by the
implementation, and writing the same bits again with new debug info may
rename the original descriptor.
|
Implementations are not prevented from returning the same bits for different descriptors. This can result in multiple different resources mapping to the same name. A common case for this might be something like a uniform buffer and storage buffer with the same device address range. |
If a descriptor becomes invalid due to the underlying resource becoming invalid, implementations may remove the name association.
The VkResourceDescriptorDataEXT union is defined as:
// Provided by VK_EXT_descriptor_heap
typedef union VkResourceDescriptorDataEXT {
const VkImageDescriptorInfoEXT* pImage;
const VkTexelBufferDescriptorInfoEXT* pTexelBuffer;
const VkDeviceAddressRangeEXT* pAddressRange;
const VkTensorViewCreateInfoARM* pTensorARM;
} VkResourceDescriptorDataEXT;
-
pImageis a pointer to a VkImageDescriptorInfoEXT structure. -
pTexelBufferis a pointer to a VkTexelBufferDescriptorInfoEXT structure. -
pAddressRangeis a pointer to a VkDeviceAddressRangeEXT structure. -
pTensorARMis a pointer to a VkTensorViewCreateInfoARM structure.
VkTexelBufferDescriptorInfoEXT is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkTexelBufferDescriptorInfoEXT {
VkStructureType sType;
const void* pNext;
VkFormat format;
VkDeviceAddressRangeEXT addressRange;
} VkTexelBufferDescriptorInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
formatis the VkFormat of the descriptor. -
addressRangeis a VkDeviceAddressRangeEXT defining the range of data backing the descriptor.
VkImageDescriptorInfoEXT is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkImageDescriptorInfoEXT {
VkStructureType sType;
const void* pNext;
const VkImageViewCreateInfo* pView;
VkImageLayout layout;
} VkImageDescriptorInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
pViewis an VkImageViewCreateInfo describing the descriptor. -
layoutis the VkImageLayout that the image view will be in when accessed as a descriptor.
Using Heaps
One descriptor heap of each type can be bound to a command buffer for use with shaders. When using descriptor heaps, pipelines must be created with VK_PIPELINE_CREATE_2_DESCRIPTOR_HEAP_BIT_EXT and shaders created with VK_SHADER_CREATE_DESCRIPTOR_HEAP_BIT_EXT in order to make use of the heaps.
When any heap state command is recorded to a command buffer, it immediately invalidates all descriptor set and descriptor buffer state set by vkCmdBindDescriptorSets2, vkCmdPushDescriptorSet2, vkCmdPushDescriptorSetWithTemplate2, vkCmdSetDescriptorBufferOffsets2EXT, vkCmdBindDescriptorBufferEmbeddedSamplers2EXT, vkCmdPushConstants2, vkCmdBindDescriptorSets, vkCmdPushDescriptorSet, vkCmdPushDescriptorSetWithTemplate, vkCmdBindDescriptorBuffersEXT, vkCmdSetDescriptorBufferOffsetsEXT, vkCmdBindDescriptorBufferEmbeddedSamplersEXT, or vkCmdPushConstants. Similarly, recording any of these commands immediately invalidates all state set by commands in this chapter.
Implementations may require storage in descriptor heaps for their own
internal descriptors.
Storage for these extra descriptors must be allocated by the application as
part of each descriptor heap address range, and must not be accessed by the
application while it is bound as a reserved range, in any command buffer,
until all such command buffers are freed or reset.
The amount of storage required by an implementation is advertised by
minResourceHeapReservedRange
for the resource heap, and minSamplerHeapReservedRange or
minSamplerHeapReservedRangeWithEmbedded for the sampler heap (the
latter being required when using embedded samplers).
Applications can set different heaps to use the same address ranges, but must take care to ensure that the reserved ranges for each heap do not overlap with each other or with user ranges.
To bind a sampler heap to a command buffer, call:
// Provided by VK_EXT_descriptor_heap
void vkCmdBindSamplerHeapEXT(
VkCommandBuffer commandBuffer,
const VkBindHeapInfoEXT* pBindInfo);
-
commandBufferis the command buffer that the sampler heap will be bound to. -
pBindInfois a VkBindHeapInfoEXT specifying the device address range used for the heap and any implementation reservations.
Addresses in the range defined by pBindInfo->heapRange are bound as
the sampler heap.
The application can access samplers and data through this heap anywhere
except for the reserved range specified by
pBindInfo->reservedRangeOffset.
Addresses in the range [pBindInfo->reservedRangeOffset,
pBindInfo->reservedRangeOffset +
minSamplerHeapReservedRange),
or in the range [pBindInfo->reservedRangeOffset,
pBindInfo->reservedRangeOffset +
minSamplerHeapReservedRangeWithEmbedded) if embedded samplers will
be used, are reserved for the implementation and must not be accessed by
the application at any time from when this command is recorded until all
command buffers with that range bound (even invalid ones) have been reset or
freed.
|
Implementations may require a larger sampler heap reservation to store
embedded sampler descriptors when used in a mapping, as advertised by
|
Shaders executed by commands recorded after this command can use the
specified sampler heap to access resources.
pBindInfo->heapRange.address will be available to shaders to access
samplers and data through the SamplerHeapEXT BuiltIn or via
shader bindings.
When vkCmdBindSamplerHeapEXT is recorded, it
immediately invalidates all non-heap descriptor state.
Similarly, recording any non-heap descriptor state commands immediately
invalidates state set by this command.
To bind a resource heap to a command buffer, call:
// Provided by VK_EXT_descriptor_heap
void vkCmdBindResourceHeapEXT(
VkCommandBuffer commandBuffer,
const VkBindHeapInfoEXT* pBindInfo);
-
commandBufferis the command buffer that the resource heap will be bound to. -
pBindInfois a VkBindHeapInfoEXT specifying the device address range used for the heap and any implementation reservations.
Addresses in the range defined by pBindInfo->heapRange are bound as
the resource heap.
The application can access resources and data through this heap anywhere
except for the reserved range specified by
pBindInfo->reservedRangeOffset.
Addresses in the range [pBindInfo->reservedRangeOffset,
pBindInfo->reservedRangeOffset +
minResourceHeapReservedRange)
are reserved for the implementation and must not be accessed by the
application at any time from when this command is recorded until there are
no command buffers with that range bound.
Shaders executed by commands recorded after this command can use the
specified resource heap to access resources.
pBindInfo->heapRange.address will be available to shaders to access
resources through the ResourceHeapEXT BuiltIn or via
shader bindings.
When vkCmdBindResourceHeapEXT is recorded, it
immediately invalidates all non-heap descriptor state.
Similarly, recording any non-heap descriptor state commands immediately
invalidates state set by this command.
VkBindHeapInfoEXT is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkBindHeapInfoEXT {
VkStructureType sType;
const void* pNext;
VkDeviceAddressRangeEXT heapRange;
VkDeviceSize reservedRangeOffset;
VkDeviceSize reservedRangeSize;
} VkBindHeapInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
heapRangeis a VkDeviceAddressRangeEXT defining the device address range used for the heap, inclusive of the implementation reserved range. -
reservedRangeOffsetis the offset withinheapRangeto the start of the reserved range for the implementation. -
reservedRangeSizeis the size of the reserved range for the implementation withinheapRange.
SamplerHeapEXT-
Decorating a variable with the
SamplerHeapEXTbuilt-in decoration will back it with the contents of the sampler heap bound by vkCmdBindSamplerHeapEXT.
ResourceHeapEXT-
Decorating a variable with the
ResourceHeapEXTbuilt-in decoration will back it with the contents of the resource heap bound by vkCmdBindResourceHeapEXT.
Push Data
Push constants specified by vkCmdPushConstants or vkCmdPushConstants2KHR rely on descriptor set layout state, and are not compatible with descriptor heaps. A new push interface is provided for use with descriptor heaps:
To update push data when using descriptor heaps, call:
// Provided by VK_EXT_descriptor_heap
void vkCmdPushDataEXT(
VkCommandBuffer commandBuffer,
const VkPushDataInfoEXT* pPushDataInfo);
-
commandBufferis the command buffer in which the push data update will be recorded. -
pPushDataInfois a pointer to a VkPushDataInfoEXT structure.
When vkCmdPushDataEXT is recorded, it
immediately invalidates all non-heap descriptor state.
Similarly, recording any non-heap descriptor state commands immediately
invalidates state set by this command.
All push data is available to all shaders using the existing
PushConstant Storage Class.
|
Device addresses in push data are intended as the fast path for
shader-constant data that does not fit into push data directly.
In order to maximize performance of constant data inputs, addresses should
be aligned to |
The VkPushDataInfoEXT structure is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkPushDataInfoEXT {
VkStructureType sType;
const void* pNext;
uint32_t offset;
VkHostAddressRangeConstEXT data;
} VkPushDataInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
offsetis the start offset of the push data range to update, in units of bytes. -
datais the host address range containing the push data to update.
Push Data Banks
When the pushConstantBank feature is enabled,
applications can specify the hardware bank into which data is pushed using
the VkPushConstantBankInfoNV structure.
The VkPushConstantBankInfoNV structure is defined as:
// Provided by VK_NV_push_constant_bank
typedef struct VkPushConstantBankInfoNV {
VkStructureType sType;
const void* pNext;
uint32_t bank;
} VkPushConstantBankInfoNV;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
bankis the index of the hardware bank into which the data is pushed.
This structure can be chained to VkPushDataInfoEXT,
VkPushConstantsInfo, VkDescriptorSetAndBindingMappingEXT, and
VkIndirectCommandsLayoutTokenEXT via the pNext chain to specify
push constant bank placement:
-
When chained to VkPushDataInfoEXT, it specifies the hardware bank into which vkCmdPushDataEXT pushes the data.
-
When chained to VkPushConstantsInfo, it specifies the hardware bank into which vkCmdPushConstants2 pushes the constants.
-
When chained to VkDescriptorSetAndBindingMappingEXT, it specifies the hardware push data bank from which the push data is read.
-
When chained to VkIndirectCommandsLayoutTokenEXT with VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_DATA_EXT, it specifies the hardware bank into which indirect push data is placed.
This allows for more flexible push constant management in descriptor heap scenarios where shaders access different root descriptors with specific bank requirements.
Shader Bindings
While descriptor heaps can be accessed directly through the
SamplerHeapEXT and ResourceHeapEXT built-ins, shaders using the
existing DescriptorSet and Binding decorations can map these to
heap offsets.
In place of descriptor set layouts and pipeline layouts, information can be
provided at pipeline
or shader
creation time to indicate how these bindings are mapped, through a
combination of constants, push data, and indirections through device
addresses.
This interface provides significantly more flexibility than descriptor set
layouts, enabling applications to specify precisely where they expect each
descriptor to be.
The VkShaderDescriptorSetAndBindingMappingInfoEXT structure is defined
as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkShaderDescriptorSetAndBindingMappingInfoEXT {
VkStructureType sType;
const void* pNext;
uint32_t mappingCount;
const VkDescriptorSetAndBindingMappingEXT* pMappings;
} VkShaderDescriptorSetAndBindingMappingInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
mappingCountis the number of elements inpMappings. -
pMappingsis a pointer to an array of VkDescriptorSetAndBindingMappingEXT structures specifying mappings for a set of descriptors
Including this structure in the pNext chain of
VkPipelineShaderStageCreateInfo will set mappings for the shader
defined by that structure.
Similarly, including this structure in the pNext chain of a
VkShaderCreateInfoEXT with a codeType of
VK_SHADER_CODE_TYPE_SPIRV_EXT, will set mappings for that shader.
If this structure is not present, it is equivalent to setting
mappingCount to 0.
The VkDescriptorSetAndBindingMappingEXT structure is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorSetAndBindingMappingEXT {
VkStructureType sType;
const void* pNext;
uint32_t descriptorSet;
uint32_t firstBinding;
uint32_t bindingCount;
VkSpirvResourceTypeFlagsEXT resourceMask;
VkDescriptorMappingSourceEXT source;
VkDescriptorMappingSourceDataEXT sourceData;
} VkDescriptorSetAndBindingMappingEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
descriptorSetis the value ofDescriptorSetfor resources that this mapping affects. -
firstBindingis the first value ofBindingof resources that this mapping affects. -
bindingCountis the number of consecutiveBindingvalues of resources that this mapping affects. -
resourceMaskis a mask of VkSpirvResourceTypeFlagBitsEXT values indicating which resource types are specified by this mapping. -
sourceis a VkDescriptorMappingSourceEXT value specifying the method of mapping specified for the affected resources. -
sourceDatais a VkDescriptorMappingSourceDataEXT that provides the details of how each mapping is specified according tosource.
Resources specified in a shader with a DescriptorSet decoration set to
descriptorSet, a Binding decoration greater than or equal to
firstBinding and less than the sum of firstBinding and
bindingCount, and a resource type matching one of the bits in
resourceMask will be mapped according to source and
sourceData.
|
Applications are free to overspecify bindings that are not present; allowing
reuse of the same mapping structures with multiple shaders, even when those
shaders only partially reuse those mappings.
This includes things like setting binding counts higher than the number used
in the shader, specifying bindings that are not present in the shader, and
setting |
If source selects an element of sourceData defined by a
structure, the description of that structure defines how resources are
mapped.
Source mappings using a single base type are defined here.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_CONSTANT_OFFSET_EXT, the
resource will be backed by heap data as specified by
constantOffset.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT, the resource
will be backed by heap data as specified by
pushIndex.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_EXT, the
resource will be backed by heap data as specified by
indirectIndex.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_ARRAY_EXT, the
resource will be backed by heap data as specified by
indirectIndexArray.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_RESOURCE_HEAP_DATA_EXT, the resource will
be backed by heap data as specified by
heapData.
If source is VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_DATA_EXT, the
resource will be backed by push data at a range from pushDataOffset to
the size of the resource, allowing a uniform buffer to be backed by push
data access push data.
Accessing data in the uniform buffer at an offset of shaderOffset in
the shader will access push data at an offset equal to
-
offset = shaderOffset + pushDataOffset.
If source is VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_ADDRESS_EXT, the
resource will be backed by data pointed to by a device address in push data
at an offset of pushAddressOffset.
Accessing data via the mapped resource in the shader will access data
backing the address specified in push data:
-
address = ((VkDeviceAddress*)pPushData)[pushAddressOffset/8]
where pPushData is the total set of push data specified by vkCmdPushDataEXT. If the shader resource is an acceleration structure, the address must be a valid acceleration structure address.
If source is VK_DESCRIPTOR_MAPPING_SOURCE_INDIRECT_ADDRESS_EXT,
the resource will be backed by heap data as specified by
indirectAddress.
|
Accesses to resources using mappings to anything that is not a descriptor in a heap are not subject to robustness guarantees; resources for such mappings must not be accessed out of bounds. |
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_SHADER_RECORD_INDEX_EXT, the
resource will be backed by heap data as specified by
shaderRecordIndex.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_DATA_EXT, the resource will
be backed by shader record data at a range from shaderRecordDataOffset
to the size of the resource, allowing a uniform buffer to be used as a way
to access shader record data.
Accessing data in the uniform buffer at an offset shaderOffset in the
shader will access shader record data at an offset equal to
-
offset = shaderOffset + shaderRecordDataOffset.
If source is
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_ADDRESS_EXT, the resource
will be backed by data pointed to by a device address in the shader record
at shaderRecordAddressOffset.
Accessing data via the mapped resource in the shader will access data
backing the address specified in shader record data:
-
address = ((VkDeviceAddress*)pShaderRecordData)[shaderRecordAddressOffset/8]
where pShaderRecord is the memory associated with a given shader as its shader record. If the shader resource is an acceleration structure, the address must be a valid acceleration structure address.
|
Accesses to resources using VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_ADDRESS_EXT mappings are not subject to robustness guarantees; data must not be accessed outside of the allocated memory range. |
Mappings must be declared for all variables with a DescriptorSet and
Binding in the shader resource interface.
Bits which can be set in
VkDescriptorSetAndBindingMappingEXT::resourceMask, are:
// Provided by VK_EXT_descriptor_heap
typedef enum VkSpirvResourceTypeFlagBitsEXT {
VK_SPIRV_RESOURCE_TYPE_ALL_EXT = 0x7FFFFFFF,
VK_SPIRV_RESOURCE_TYPE_SAMPLER_BIT_EXT = 0x00000001,
VK_SPIRV_RESOURCE_TYPE_SAMPLED_IMAGE_BIT_EXT = 0x00000002,
VK_SPIRV_RESOURCE_TYPE_READ_ONLY_IMAGE_BIT_EXT = 0x00000004,
VK_SPIRV_RESOURCE_TYPE_READ_WRITE_IMAGE_BIT_EXT = 0x00000008,
VK_SPIRV_RESOURCE_TYPE_COMBINED_SAMPLED_IMAGE_BIT_EXT = 0x00000010,
VK_SPIRV_RESOURCE_TYPE_UNIFORM_BUFFER_BIT_EXT = 0x00000020,
VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT = 0x00000040,
VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT = 0x00000080,
// Provided by VK_EXT_descriptor_heap with VK_KHR_ray_tracing_pipeline or VK_NV_ray_tracing
VK_SPIRV_RESOURCE_TYPE_ACCELERATION_STRUCTURE_BIT_EXT = 0x00000100,
// Provided by VK_EXT_descriptor_heap with VK_ARM_tensors
VK_SPIRV_RESOURCE_TYPE_TENSOR_BIT_ARM = 0x00000200,
} VkSpirvResourceTypeFlagBitsEXT;
-
VK_SPIRV_RESOURCE_TYPE_ALL_EXT specifies that all resource declarations are included.
-
VK_SPIRV_RESOURCE_TYPE_SAMPLER_BIT_EXT specifies
OpTypeSamplervariables. -
VK_SPIRV_RESOURCE_TYPE_SAMPLED_IMAGE_BIT_EXT specifies
OpTypeImagevariables with aSampledparameter of 1. -
VK_SPIRV_RESOURCE_TYPE_READ_ONLY_IMAGE_BIT_EXT specifies
OpTypeImagevariables with aSampledparameter of 2 and decorated withNonWritable. -
VK_SPIRV_RESOURCE_TYPE_READ_WRITE_IMAGE_BIT_EXT specifies
OpTypeImagevariables with aSampledparameter of 2 and not decorated withNonWritable. -
VK_SPIRV_RESOURCE_TYPE_COMBINED_SAMPLED_IMAGE_BIT_EXT specifies
OpTypeSampledImagevariables. -
VK_SPIRV_RESOURCE_TYPE_UNIFORM_BUFFER_BIT_EXT specifies
OpTypeStructvariables in theUniformstorage class decorated withBlock -
VK_SPIRV_RESOURCE_TYPE_READ_ONLY_STORAGE_BUFFER_BIT_EXT specifies
OpTypeStructvariables either in theStorageBufferstorage class decorated withBlockor in theUniformstorage class decorated withBufferBlock, and decorated withNonWritable -
VK_SPIRV_RESOURCE_TYPE_READ_WRITE_STORAGE_BUFFER_BIT_EXT specifies
OpTypeStructvariables either in theStorageBufferstorage class decorated withBlockor in theUniformstorage class decorated withBufferBlock, but not decorated withNonWritable -
VK_SPIRV_RESOURCE_TYPE_ACCELERATION_STRUCTURE_BIT_EXT specifies
OpTypeAccelerationStructureKHRvariables -
VK_SPIRV_RESOURCE_TYPE_TENSOR_BIT_ARM specifies
OpTypeTensorARMvariables
// Provided by VK_EXT_descriptor_heap
typedef VkFlags VkSpirvResourceTypeFlagsEXT;
VkSpirvResourceTypeFlagsEXT is a bitmask type for setting a mask of
zero or more VkSpirvResourceTypeFlagBitsEXT.
The possible mapping sources for a shader binding are:
// Provided by VK_EXT_descriptor_heap
typedef enum VkDescriptorMappingSourceEXT {
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_CONSTANT_OFFSET_EXT = 0,
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT = 1,
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_EXT = 2,
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_ARRAY_EXT = 3,
VK_DESCRIPTOR_MAPPING_SOURCE_RESOURCE_HEAP_DATA_EXT = 4,
VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_DATA_EXT = 5,
VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_ADDRESS_EXT = 6,
VK_DESCRIPTOR_MAPPING_SOURCE_INDIRECT_ADDRESS_EXT = 7,
// Provided by VK_EXT_descriptor_heap with VK_KHR_ray_tracing_pipeline or VK_NV_ray_tracing
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_SHADER_RECORD_INDEX_EXT = 8,
// Provided by VK_EXT_descriptor_heap with VK_KHR_ray_tracing_pipeline or VK_NV_ray_tracing
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_DATA_EXT = 9,
// Provided by VK_EXT_descriptor_heap with VK_KHR_ray_tracing_pipeline or VK_NV_ray_tracing
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_ADDRESS_EXT = 10,
} VkDescriptorMappingSourceEXT;
-
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_CONSTANT_OFFSET_EXT specifies that the resource will be backed by a descriptor from the heap at a constant index.
-
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_PUSH_INDEX_EXT specifies that the resource will be backed by a descriptor from the heap at an index sourced from push data, added to a constant index.
-
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_EXT specifies that the resource will be backed by a descriptor from the heap at an index sourced from an address in push data, added to a constant index. If the mapping is an array, the array will be mapped to a base offset in indirect memory, and subsequent elements are mapped as offsets to that base.
-
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_INDIRECT_INDEX_ARRAY_EXT specifies that the resource will be backed by a descriptor from the heap at an index sourced from an address in push data, added to a constant index. If the mapping is an array, each array element will be mapped to a separate index in indirect memory.
-
VK_DESCRIPTOR_MAPPING_SOURCE_RESOURCE_HEAP_DATA_EXT specifies that the resource will be backed by heap data directly.
-
VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_DATA_EXT specifies that the resource will be backed by push data directly.
-
VK_DESCRIPTOR_MAPPING_SOURCE_PUSH_ADDRESS_EXT specifies that the resource will be backed by an address in push data.
-
VK_DESCRIPTOR_MAPPING_SOURCE_INDIRECT_ADDRESS_EXT specifies that the resource will be backed by an address sourced via another address in push data.
-
VK_DESCRIPTOR_MAPPING_SOURCE_HEAP_WITH_SHADER_RECORD_INDEX_EXT specifies that the resource will be backed by a descriptor from the heap at an index sourced from shader record data, added to a constant index.
-
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_DATA_EXT specifies that the resource will be backed by shader record data directly.
-
VK_DESCRIPTOR_MAPPING_SOURCE_SHADER_RECORD_ADDRESS_EXT specifies that the resource will be backed by an address in shader record data.
The VkDescriptorMappingSourceDataEXT union is defined as:
// Provided by VK_EXT_descriptor_heap
typedef union VkDescriptorMappingSourceDataEXT {
VkDescriptorMappingSourceConstantOffsetEXT constantOffset;
VkDescriptorMappingSourcePushIndexEXT pushIndex;
VkDescriptorMappingSourceIndirectIndexEXT indirectIndex;
VkDescriptorMappingSourceIndirectIndexArrayEXT indirectIndexArray;
VkDescriptorMappingSourceHeapDataEXT heapData;
uint32_t pushDataOffset;
uint32_t pushAddressOffset;
VkDescriptorMappingSourceIndirectAddressEXT indirectAddress;
VkDescriptorMappingSourceShaderRecordIndexEXT shaderRecordIndex;
uint32_t shaderRecordDataOffset;
uint32_t shaderRecordAddressOffset;
} VkDescriptorMappingSourceDataEXT;
-
constantOffsetis a VkDescriptorMappingSourceConstantOffsetEXT structure specifying the mapping for resources at a constant byte offset into a heap. -
pushIndexis a VkDescriptorMappingSourcePushIndexEXT structure specifying the mapping for resources at an index into a heap source from push data. -
indirectIndexis a VkDescriptorMappingSourceIndirectIndexEXT structure specifying the mapping for resources at an index into a heap source from an address in push data. -
indirectIndexArrayis a VkDescriptorMappingSourceIndirectIndexArrayEXT structure specifying the mapping for resources to an array of indices into a heap source from an address in push data. -
heapDatais a VkDescriptorMappingSourceHeapDataEXT structure specifying an offset into heap data for a uniform buffer to map to. -
pushDataOffsetan offset into push data for a uniform buffer to map to. -
pushAddressOffsetan offset into push data storing an address for a resource to map to. -
indirectAddressis a VkDescriptorMappingSourceIndirectAddressEXT structure specifying an address in push data containing another address for a resource to map to. -
shaderRecordIndexis a VkDescriptorMappingSourceShaderRecordIndexEXT structure specifying the mapping for resources at an index into a heap source from shader record data. -
shaderRecordDataOffsetan offset into shader record data for a uniform buffer to map to. -
shaderRecordAddressOffsetan offset into shader record data storing an address for a resource to map to.
The VkDescriptorMappingSourceConstantOffsetEXT structure is defined
as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceConstantOffsetEXT {
uint32_t heapOffset;
uint32_t heapArrayStride;
const VkSamplerCreateInfo* pEmbeddedSampler;
uint32_t samplerHeapOffset;
uint32_t samplerHeapArrayStride;
} VkDescriptorMappingSourceConstantOffsetEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped resource or sampler. -
heapArrayStrideis a constant byte stride that multiplies the shader binding and array index. -
pEmbeddedSampleris an optional VkSamplerCreateInfo structure specifying a sampler to embed into the shader, in place of looking the sampler up in a heap. -
samplerHeapOffsetis used only when mapping a combined image sampler, used in place ofheapOffsetto retrieve the sampler. -
samplerHeapArrayStrideis used only when mapping a combined image sampler, used in place ofheapArrayStrideto retrieve the sampler.
Resources using this mapping will be backed by a descriptor in the heap, at an offset calculated as
-
shaderIndex = (Binding -
firstBinding) + arrayIndex -
offset = heapOffset + (shaderIndex * heapArrayStride)
where Binding is the binding value in the shader, arrayIndex is the index into the array if the shader binding is declared as an array.
If the mapped resource is a OpTypeSampledImage, offset is instead
calculated for the sampler as
-
offset = samplerHeapOffset + (shaderIndex * samplerHeapArrayStride)
If the mapped resource is a OpTypeSampler or OpTypeSampledImage,
and pEmbeddedSampler is not NULL, the specified embedded sampler
will be used rather than accessing the sampler heap.
The VkDescriptorMappingSourcePushIndexEXT structure is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourcePushIndexEXT {
uint32_t heapOffset;
uint32_t pushOffset;
uint32_t heapIndexStride;
uint32_t heapArrayStride;
const VkSamplerCreateInfo* pEmbeddedSampler;
VkBool32 useCombinedImageSamplerIndex;
uint32_t samplerHeapOffset;
uint32_t samplerPushOffset;
uint32_t samplerHeapIndexStride;
uint32_t samplerHeapArrayStride;
} VkDescriptorMappingSourcePushIndexEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped resource or sampler. -
pushOffsetis an index into push data where an index into the heap for the mapped resource will be retrieved. -
heapIndexStrideis a constant byte stride that multiplies the index in push data. -
heapArrayStrideis a constant byte stride that multiplies the shader binding and array index. -
pEmbeddedSampleris an optional VkSamplerCreateInfo structure specifying a sampler to embed into the shader, in place of looking the sampler up in a heap. -
useCombinedImageSamplerIndexspecifies whether the generated index value will be decoded as two packed indices if the mapped resource is anOpTypeSampledImage. -
samplerHeapOffsetis used only when mapping a combined image sampler, used in place ofheapOffsetto retrieve the sampler. -
samplerPushOffsetis used only when mapping a combined image sampler, used in place ofpushOffsetto retrieve the sampler. -
samplerHeapIndexStrideis used only when mapping a combined image sampler, used in place ofheapIndexStrideto retrieve the sampler. -
samplerHeapArrayStrideis used only when mapping a combined image sampler, used in place ofheapArrayStrideto retrieve the sampler.
Resources using this mapping will be backed by a descriptor in the heap, at an offset calculated as
-
pushIndex = ((uint32_t*)pPushData)[pushOffset/4]
-
shaderIndex = (Binding - firstBinding) + arrayIndex
-
offset = heapOffset + (pushIndex × heapIndexStride) + (shaderIndex × heapArrayStride)
where Binding is the binding value in the shader, arrayIndex is the index into the array if the shader binding is declared as an array, and pPushData is the total set of push data specified by vkCmdPushDataEXT.
If the mapped resource is a OpTypeSampledImage, offset is instead
calculated for the sampler as
-
samplerPushIndex = ((uint32_t*)pPushData)[samplerPushOffset/4]
-
offset = samplerHeapOffset + (samplerPushIndex × samplerHeapIndexStride) + (shaderIndex × samplerHeapArrayStride)
If useCombinedImageSamplerIndex is VK_TRUE, and the mapped
resource is a OpTypeSampledImage, pushIndex and
samplerPushIndex in the above equations are instead calculated as
-
pushIndex = ((uint32_t*)pPushData)[pushOffset/4] & 0xFFFFF
-
samplerPushIndex = (((uint32_t*)pPushData)[pushOffset/4] >> 20) & 0xFFF
If the mapped resource is a OpTypeSampler or OpTypeSampledImage,
and pEmbeddedSampler is not NULL, the specified embedded sampler
will be used rather than accessing the sampler heap.
The VkDescriptorMappingSourceIndirectIndexEXT structure is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceIndirectIndexEXT {
uint32_t heapOffset;
uint32_t pushOffset;
uint32_t addressOffset;
uint32_t heapIndexStride;
uint32_t heapArrayStride;
const VkSamplerCreateInfo* pEmbeddedSampler;
VkBool32 useCombinedImageSamplerIndex;
uint32_t samplerHeapOffset;
uint32_t samplerPushOffset;
uint32_t samplerAddressOffset;
uint32_t samplerHeapIndexStride;
uint32_t samplerHeapArrayStride;
} VkDescriptorMappingSourceIndirectIndexEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped resource or sampler. -
pushOffsetis an offset into push data where an the indirect address will be. -
addressOffsetis an index into the address in push data where an index into the heap for the mapped resource will be retrieved. -
heapIndexStrideis a constant byte stride that multiplies the index in indirect data. -
heapArrayStrideis a constant byte stride that multiplies the shader binding and array index. -
pEmbeddedSampleris an optional VkSamplerCreateInfo structure specifying a sampler to embed into the shader, in place of looking the sampler up in a heap. -
useCombinedImageSamplerIndexspecifies whether the generated index value will be decoded as two packed indices if the mapped resource is anOpTypeSampledImage. -
samplerHeapOffsetis used only when mapping a combined image sampler, used in place ofheapOffsetto retrieve the sampler. -
samplerPushOffsetis used only when mapping a combined image sampler, used in place ofpushOffsetto retrieve the sampler. -
samplerAddressOffsetis used only when mapping a combined image sampler, used in place ofaddressOffsetto retrieve the sampler. -
samplerHeapIndexStrideis used only when mapping a combined image sampler, used in place ofheapIndexStrideto retrieve the sampler. -
samplerHeapArrayStrideis used only when mapping a combined image sampler, used in place ofheapArrayStrideto retrieve the sampler.
Resources using this mapping will be backed by a descriptor in the heap, at an offset calculated as
-
uint32_t *indirectAddress = ((VkDeviceAddress*)pPushData)[pushOffset/8]
-
indirectIndex = indirectAddress[(addressOffset / 4)]
-
shaderIndex = (Binding - firstBinding) + arrayIndex
-
offset = heapOffset + (indirectIndex × heapIndexStride) + (shaderIndex × heapArrayStride)
where Binding is the binding value in the shader, arrayIndex is the index into the array if the shader binding is declared as an array, and pPushData is the total set of push data specified by vkCmdPushDataEXT. The value of the address in push data must be a multiple of 4. Index reads through indirectAddress are performed as non-volatile uniform buffer reads, and can be synchronized using VK_ACCESS_2_UNIFORM_READ_BIT. The value in memory must remain static while any shader invocation using this mapping is in flight to avoid a data race.
If the mapped resource is a OpTypeSampledImage, offset is instead
calculated for the sampler as
-
uint32_t *samplerIndirectAddress = ((VkDeviceAddress*)pPushData)[samplerPushOffset/8]
-
samplerIndirectIndex = samplerIndirectAddress[(samplerAddressOffset / 4)]
-
offset = samplerHeapOffset + (samplerIndirectIndex × samplerHeapIndexStride) + (shaderIndex × samplerHeapArrayStride)
If useCombinedImageSamplerIndex is VK_TRUE, and the mapped
resource is a OpTypeSampledImage, indirectIndex and
samplerIndirectIndex in the above equations are instead calculated as
-
indirectIndex = indirectAddress[addressOffset/4] & 0xFFFFF
-
samplerIndirectIndex = indirectAddress[addressOffset/4] >> 20) & 0xFFF
If the mapped resource is a OpTypeSampler or OpTypeSampledImage,
and pEmbeddedSampler is not NULL, the specified embedded sampler
will be used rather than accessing the sampler heap.
The VkDescriptorMappingSourceIndirectIndexArrayEXT structure is
defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceIndirectIndexArrayEXT {
uint32_t heapOffset;
uint32_t pushOffset;
uint32_t addressOffset;
uint32_t heapIndexStride;
const VkSamplerCreateInfo* pEmbeddedSampler;
VkBool32 useCombinedImageSamplerIndex;
uint32_t samplerHeapOffset;
uint32_t samplerPushOffset;
uint32_t samplerAddressOffset;
uint32_t samplerHeapIndexStride;
} VkDescriptorMappingSourceIndirectIndexArrayEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped resource or sampler. -
pushOffsetis an offset into push data where an the indirect address will be. -
addressOffsetis an index into the address in push data where an index into the heap for the mapped resource will be retrieved. -
heapIndexStrideis a constant byte stride that multiplies the index in indirect data. -
pEmbeddedSampleris an optional VkSamplerCreateInfo structure specifying a sampler to embed into the shader, in place of looking the sampler up in a heap. -
useCombinedImageSamplerIndexspecifies whether the generated index value will be decoded as two packed indices if the mapped resource is anOpTypeSampledImage. -
samplerHeapOffsetis used only when mapping a combined image sampler, used in place ofheapOffsetto retrieve the sampler. -
samplerPushOffsetis used only when mapping a combined image sampler, used in place ofpushOffsetto retrieve the sampler. -
samplerAddressOffsetis used only when mapping a combined image sampler, used in place ofaddressOffsetto retrieve the sampler. -
samplerHeapIndexStrideis used only when mapping a combined image sampler, used in place ofheapIndexStrideto retrieve the sampler.
Resources using this mapping will be backed by a descriptor in the heap, at an offset calculated as
-
uint32_t *indirectAddress = ((VkDeviceAddress*)pPushData)[pushOffset/8]
-
shaderIndex = (Binding - firstBinding) + arrayIndex
-
indirectIndex = indirectAddress[(addressOffset / 4) + shaderIndex]
-
offset = heapOffset + (indirectIndex × heapIndexStride)
where Binding is the binding value in the shader, arrayIndex is the index into the array if the shader binding is declared as an array, and pPushData is the total set of push data specified by vkCmdPushDataEXT. The value of the address in push data must be a multiple of 4. Index reads through indirectAddress are performed as non-volatile uniform buffer reads, and can be synchronized using VK_ACCESS_2_UNIFORM_READ_BIT. The value in memory must remain static while any shader invocation using this mapping is in flight to avoid a data race.
If the mapped resource is a OpTypeSampledImage, offset is instead
calculated for the sampler as
-
uint32_t *samplerIndirectAddress = ((VkDeviceAddress*)pPushData)[samplerPushOffset/8]
-
samplerIndirectIndex = samplerAddr[(samplerAddressOffset / 4) + shaderIndex]
-
offset = samplerHeapOffset + (samplerIndirectIndex × samplerHeapIndexStride)
If useCombinedImageSamplerIndex is VK_TRUE, and the mapped
resource is a OpTypeSampledImage, indirectIndex and
samplerIndirectIndex in the above equations are instead calculated as
-
indirectIndex = indirectAddress[addressOffset/4 + shaderIndex] & 0xFFFFF
-
samplerIndirectIndex = indirectAddress[addressOffset/4 + shaderIndex] >> 20) & 0xFFF
If the mapped resource is a OpTypeSampler or OpTypeSampledImage,
and pEmbeddedSampler is not NULL, the specified embedded sampler
will be used rather than accessing the sampler heap.
The VkDescriptorMappingSourceHeapDataEXT structure is defined as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceHeapDataEXT {
uint32_t heapOffset;
uint32_t pushOffset;
} VkDescriptorMappingSourceHeapDataEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped buffer. -
pushOffsetis an index into push data where an additional offset into the heap for the mapped resource will be retrieved.
Uniform buffers using this mapping will be backed directly by data in the heap. Accessing data in the uniform buffer at an offset of shaderOffset in the shader will access heap data at an offset equal to
-
offset = shaderOffset + heapOffset + ((uint32_t*)pPushData)[pushOffset/4]
where pPushData is the total set of push data specified by vkCmdPushDataEXT. Shader reads through the heap mapped in this way are performed according to the mapped resource.
The VkDescriptorMappingSourceIndirectAddressEXT structure is defined
as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceIndirectAddressEXT {
uint32_t pushOffset;
uint32_t addressOffset;
} VkDescriptorMappingSourceIndirectAddressEXT;
-
pushOffsetis a byte offset into push data where an indirect address containing the address for the mapped resource will be retrieved. -
addressOffsetis a byte offset into the indirect address where the address for the mapped resource will be retrieved.
Accessing data via the mapped resource in the shader will access data backing the address specified in the indirect address at the supplied offset:
-
indirectAddress = ((VkDeviceAddress*)pPushData)[pushOffset/8]
-
resourceAddress = ((VkDeviceAddress*)indirectAddress)[addressOffset/8]
where pPushData is the total set of push data specified by vkCmdPushDataEXT. Reads through indirectAddress are performed as non-volatile uniform buffer reads, and can be synchronized using VK_ACCESS_2_UNIFORM_READ_BIT. Shader reads through resourceAddress are performed according to the mapped resource. If the shader resource is an acceleration structure, the address must be a valid acceleration structure address.
The VkDescriptorMappingSourceShaderRecordIndexEXT structure is defined
as:
// Provided by VK_EXT_descriptor_heap
typedef struct VkDescriptorMappingSourceShaderRecordIndexEXT {
uint32_t heapOffset;
uint32_t shaderRecordOffset;
uint32_t heapIndexStride;
uint32_t heapArrayStride;
const VkSamplerCreateInfo* pEmbeddedSampler;
VkBool32 useCombinedImageSamplerIndex;
uint32_t samplerHeapOffset;
uint32_t samplerShaderRecordOffset;
uint32_t samplerHeapIndexStride;
uint32_t samplerHeapArrayStride;
} VkDescriptorMappingSourceShaderRecordIndexEXT;
-
heapOffsetis a constant byte offset added to the heap address for the mapped resource or sampler. -
shaderRecordOffsetis an index into shader record data where an index into the heap for the mapped resource will be retrieved. -
heapIndexStrideis a constant byte stride that multiplies the index in shader record data. -
heapArrayStrideis a constant byte stride that multiplies the shader binding and array index. -
pEmbeddedSampleris an optional VkSamplerCreateInfo structure specifying a sampler to embed into the shader, in place of looking the sampler up in a heap. -
useCombinedImageSamplerIndexspecifies whether the generated index value will be decoded as two packed indices if the mapped resource is anOpTypeSampledImage. -
samplerHeapOffsetis used only when mapping a combined image sampler, used in place ofheapOffsetto retrieve the sampler. -
samplerShaderRecordOffsetis used only when mapping a combined image sampler, used in place ofshaderRecordOffsetto retrieve the sampler. -
samplerHeapIndexStrideis used only when mapping a combined image sampler, used in place ofheapIndexStrideto retrieve the sampler. -
samplerHeapArrayStrideis used only when mapping a combined image sampler, used in place ofheapArrayStrideto retrieve the sampler.
Resources using this mapping will be backed by a descriptor in the heap, at an offset calculated as
-
shaderRecordIndex = ((uint32_t*)pShaderRecordData)[shaderRecordOffset/4]
-
shaderIndex = (Binding - firstBinding) + arrayIndex
-
offset = heapOffset + (shaderRecordIndex × heapIndexStride) + (shaderIndex × heapArrayStride)
where Binding is the binding value in the shader, arrayIndex is the index into the array if the shader binding is declared as an array, and pShaderRecordData is the set of shader record data accessible to the shader.
If the mapped resource is a OpTypeSampledImage, offset is instead
calculated for the sampler as
-
samplerShaderRecordIndex = ((uint32_t*)pShaderRecordData)[samplerShaderRecordOffset/4]
-
offset = samplerHeapOffset + (samplerShaderRecordIndex × samplerHeapIndexStride) + (shaderIndex × samplerHeapArrayStride)
If useCombinedImageSamplerIndex is VK_TRUE, and the mapped
resource is a OpTypeSampledImage, shaderRecordIndex and
samplerShaderRecordIndex in the above equations are instead calculated
as
-
shaderRecordIndex = ((uint32_t*)pShaderRecordData)[shaderRecordOffset/4] & 0xFFFFF
-
samplerShaderRecordIndex = (((uint32_t*)pShaderRecordData)[shaderRecordOffset/4] >> 20) & 0xFFF
If the mapped resource is a OpTypeSampler or OpTypeSampledImage,
and pEmbeddedSampler is not NULL, the specified embedded sampler
will be used rather than accessing the sampler heap.
Packing descriptors more tightly
For simplicity, descriptor sizes are advertised and treated by default as equal to the advertised descriptor size limits:
However, for some specific use cases it is useful to be able to pack specific descriptors into memory more tightly than this when the implementation allows for this.
To query the size of heap descriptor for a specific VkDescriptorType, call:
// Provided by VK_EXT_descriptor_heap
VkDeviceSize vkGetPhysicalDeviceDescriptorSizeEXT(
VkPhysicalDevice physicalDevice,
VkDescriptorType descriptorType);
-
physicalDeviceis the physical device from which to query the descriptor sizes. -
descriptorTypeis a VkDescriptorType specifying the type of heap descriptor to query the size for.
The return value of this function will be a VkDeviceSize indicating
the size in bytes (N) of a heap descriptor with a type equal to
descriptorType.
When a descriptor of this type is written by
vkWriteResourceDescriptorsEXT or vkWriteSamplerDescriptorsEXT,
only the first N bytes are written; the rest will not be accessed and
can be safely discarded when copying descriptors around.
Additionally, those first N bytes are the only bytes that will be
accessed when the descriptor is accessed in the shader.
N will never be larger than the applicable limits in
VkPhysicalDeviceDescriptorHeapTensorPropertiesARM or
VkPhysicalDeviceDescriptorHeapPropertiesEXT.
|
Values returned by this function have other requirements, so for example may not be power-of-two values. |
|
This command is not intended for general use, and is for tools that already
take advantage of tighter packing with other similar features
(e.g. |