38. Micromap
38.1. Micromaps
Acceleration structures store and organize geometry for ray tracing, but in some cases it is beneficial to include some information within the geometry, particularly for triangles. A micromap organizes this data around a map of values corresponding to subdivided microtriangles which can be added to a triangle geometry when building a bottom level acceleration structure.
An opacity micromap is a type of micromap which stores information to control intersection opacity as described in Ray Opacity Micromap.
A displacement micromap is a type of micromap which stores information to displace sub-triangle vertices as described in Displacement Micromap.
A micromap is considered to be constructed if a micromap build command or copy command has been executed with the given acceleration structure as the destination.
38.1.1. Building Micromaps
To build micromaps call:
// Provided by VK_EXT_opacity_micromap
void vkCmdBuildMicromapsEXT(
VkCommandBuffer commandBuffer,
uint32_t infoCount,
const VkMicromapBuildInfoEXT* pInfos);
-
commandBufferis the command buffer into which the command will be recorded. -
infoCountis the number of micromaps to build. It specifies the number of thepInfosstructures that must be provided. -
pInfosis a pointer to an array ofinfoCountVkMicromapBuildInfoEXT structures defining the data used to build each micromap.
The vkCmdBuildMicromapsEXT command provides the ability to initiate
multiple micromaps builds, however there is no ordering or synchronization
implied between any of the individual micromap builds.
|
Note
|
This means that there cannot be any memory aliasing between any micromap memories or scratch memories being used by any of the builds. |
Accesses to the micromap scratch buffers as identified by the
VkMicromapBuildInfoEXT::scratchData buffer device addresses
must be synchronized with the
VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
(VK_ACCESS_2_MICROMAP_READ_BIT_EXT |
VK_ACCESS_2_MICROMAP_WRITE_BIT_EXT).
Accesses to VkMicromapBuildInfoEXT::dstMicromap must be
synchronized with the
VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_2_MICROMAP_WRITE_BIT_EXT.
Accesses to other input buffers as identified by any used values of
VkMicromapBuildInfoEXT::data or
VkMicromapBuildInfoEXT::triangleArray must be
synchronized with the
VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_SHADER_READ_BIT.
Formats which can be set in VkMicromapUsageEXT::format and
VkMicromapTriangleEXT::format for micromap builds, are:
// Provided by VK_EXT_opacity_micromap
typedef enum VkOpacityMicromapFormatEXT {
VK_OPACITY_MICROMAP_FORMAT_2_STATE_EXT = 1,
VK_OPACITY_MICROMAP_FORMAT_4_STATE_EXT = 2,
} VkOpacityMicromapFormatEXT;
-
VK_OPACITY_MICROMAP_FORMAT_2_STATE_EXTspecifies that the given micromap format has one bit per subtriangle encoding either fully opaque or fully transparent. -
VK_OPACITY_MICROMAP_FORMAT_4_STATE_EXTspecifies that the given micromap format has two bits per subtriangle encoding four modes which can be interpreted as described in ray traversal.
|
Note
|
For compactness, these values are stored as 16-bit in some structures. |
Formats which can be set in VkMicromapUsageEXT::format and
VkMicromapTriangleEXT::format for micromap builds, are:
// Provided by VK_NV_displacement_micromap
typedef enum VkDisplacementMicromapFormatNV {
VK_DISPLACEMENT_MICROMAP_FORMAT_64_TRIANGLES_64_BYTES_NV = 1,
VK_DISPLACEMENT_MICROMAP_FORMAT_256_TRIANGLES_128_BYTES_NV = 2,
VK_DISPLACEMENT_MICROMAP_FORMAT_1024_TRIANGLES_128_BYTES_NV = 3,
} VkDisplacementMicromapFormatNV;
-
VK_DISPLACEMENT_MICROMAP_FORMAT_64_TRIANGLES_64_BYTES_NVspecifies that the given micromap format encodes 64 micro-triangles worth of displacements in 64 bytes as described in Displacement Micromap Encoding. -
VK_DISPLACEMENT_MICROMAP_FORMAT_256_TRIANGLES_128_BYTES_NVspecifies that the given micromap format encodes 256 micro-triangles worth of displacements in 128 bytes as described in Displacement Micromap Encoding. -
VK_DISPLACEMENT_MICROMAP_FORMAT_1024_TRIANGLES_128_BYTES_NVspecifies that the given micromap format encodes 1024 micro-triangles worth of displacements in 128 bytes as described in Displacement Micromap Encoding.
|
Note
|
For compactness, these values are stored as 16-bit in some structures. |
The VkMicromapBuildInfoEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkMicromapBuildInfoEXT {
VkStructureType sType;
const void* pNext;
VkMicromapTypeEXT type;
VkBuildMicromapFlagsEXT flags;
VkBuildMicromapModeEXT mode;
VkMicromapEXT dstMicromap;
uint32_t usageCountsCount;
const VkMicromapUsageEXT* pUsageCounts;
const VkMicromapUsageEXT* const* ppUsageCounts;
VkDeviceOrHostAddressConstKHR data;
VkDeviceOrHostAddressKHR scratchData;
VkDeviceOrHostAddressConstKHR triangleArray;
VkDeviceSize triangleArrayStride;
} VkMicromapBuildInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
typeis a VkMicromapTypeEXT value specifying the type of micromap being built. -
flagsis a bitmask of VkBuildMicromapFlagBitsEXT specifying additional parameters of the micromap. -
modeis a VkBuildMicromapModeEXT value specifying the type of operation to perform. -
dstMicromapis a pointer to the target micromap for the build. -
usageCountsCountspecifies the number of usage counts structures that will be used to determine the size of this micromap. -
pUsageCountsis a pointer to an array of VkMicromapUsageEXT structures. -
ppUsageCountsis a pointer to an array of pointers to VkMicromapUsageEXT structures. -
datais the device or host address to memory which contains the data for the micromap. -
scratchDatais the device or host address to memory that will be used as scratch memory for the build. -
triangleArrayis the device or host address to memory containing the VkMicromapTriangleEXT data -
triangleArrayStrideis the stride in bytes between each element oftriangleArray
Only one of pUsageCounts or ppUsageCounts can be a valid
pointer, the other must be NULL.
The elements of the non-NULL array describe the total counts used to build
each micromap.
Each element contains a count which is the number of micromap
triangles of that format and subdivisionLevel contained in the
micromap.
Multiple elements with the same format and subdivisionLevel are
allowed and the total count for that format and subdivisionLevel
is the sum of the count for each element.
Each micromap triangle refers to one element in triangleArray which
contains the format and subdivisionLevel for that particular
triangle as well as a dataOffset in bytes which is the location
relative to data where that triangle’s micromap data begins.
The data at triangleArray is laid out as a 4 byte unsigned integer for
the dataOffset followed by a 2 byte unsigned integer for the
subdivision level then a 2 byte unsigned integer for the format.
In practice, compilers compile VkMicromapTriangleEXT to match this
pattern.
For opacity micromaps, the data at data is packed as either one bit
per element for VK_OPACITY_MICROMAP_FORMAT_2_STATE_EXT or two bits per
element for VK_OPACITY_MICROMAP_FORMAT_4_STATE_EXT and is packed from
LSB to MSB in each byte.
The data at each index in those bytes is interpreted as discussed in
Ray Opacity Micromap.
For displacement micromaps, the data at data is interpreted as
discussed in Displacement Micromap
Encoding.
The VkBuildMicromapModeEXT enumeration is defined as:
// Provided by VK_EXT_opacity_micromap
typedef enum VkBuildMicromapModeEXT {
VK_BUILD_MICROMAP_MODE_BUILD_EXT = 0,
} VkBuildMicromapModeEXT;
-
VK_BUILD_MICROMAP_MODE_BUILD_EXTspecifies that the destination micromap will be built using the specified data.
The VkMicromapUsageEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkMicromapUsageEXT {
uint32_t count;
uint32_t subdivisionLevel;
uint32_t format;
} VkMicromapUsageEXT;
-
countis the number of triangles in the usage format defined by thesubdivisionLevelandformatbelow in the micromap -
subdivisionLevelis the subdivision level of this usage format -
formatis the format of this usage format
The format is interpreted based on the type of the micromap
using it.
The VkMicromapTriangleEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkMicromapTriangleEXT {
uint32_t dataOffset;
uint16_t subdivisionLevel;
uint16_t format;
} VkMicromapTriangleEXT;
-
dataOffsetis the offset in bytes of the start of the data for this triangle. This is a byte aligned value. -
subdivisionLevelis the subdivision level of this triangle -
formatis the format of this triangle
The format is interpreted based on the type of the micromap
using it.
38.1.2. Copying Micromaps
An additional command exists for copying micromaps without updating their contents. Before copying, an application must query the size of the resulting micromap.
To query micromap size parameters call:
// Provided by VK_EXT_opacity_micromap
void vkCmdWriteMicromapsPropertiesEXT(
VkCommandBuffer commandBuffer,
uint32_t micromapCount,
const VkMicromapEXT* pMicromaps,
VkQueryType queryType,
VkQueryPool queryPool,
uint32_t firstQuery);
-
commandBufferis the command buffer into which the command will be recorded. -
micromapCountis the count of micromaps for which to query the property. -
pMicromapsis a pointer to an array of existing previously built micromaps. -
queryTypeis a VkQueryType value specifying the type of queries managed by the pool. -
queryPoolis the query pool that will manage the results of the query. -
firstQueryis the first query index within the query pool that will contain themicromapCountnumber of results.
Accesses to any of the micromaps listed in pMicromaps must be
synchronized with the
VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_2_MICROMAP_READ_BIT_EXT.
-
If
queryTypeisVK_QUERY_TYPE_MICROMAP_SERIALIZATION_SIZE_EXT, then the value written out is the number of bytes required by a serialized micromap. -
If
queryTypeisVK_QUERY_TYPE_MICROMAP_COMPACTED_SIZE_EXT, then the value written out is the number of bytes required by a compacted micromap.
To copy a micromap call:
// Provided by VK_EXT_opacity_micromap
void vkCmdCopyMicromapEXT(
VkCommandBuffer commandBuffer,
const VkCopyMicromapInfoEXT* pInfo);
-
commandBufferis the command buffer into which the command will be recorded. -
pInfois a pointer to a VkCopyMicromapInfoEXT structure defining the copy operation.
This command copies the pInfo->src micromap to the pInfo->dst
micromap in the manner specified by pInfo->mode.
Accesses to pInfo->src and pInfo->dst must be
synchronized with the
VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_2_MICROMAP_READ_BIT_EXT or
VK_ACCESS_2_MICROMAP_WRITE_BIT_EXT as appropriate.
The VkCopyMicromapInfoEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkCopyMicromapInfoEXT {
VkStructureType sType;
const void* pNext;
VkMicromapEXT src;
VkMicromapEXT dst;
VkCopyMicromapModeEXT mode;
} VkCopyMicromapInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
srcis the source micromap for the copy. -
dstis the target micromap for the copy. -
modeis a VkCopyMicromapModeEXT value specifying additional operations to perform during the copy.
Possible values of mode specifying additional operations to perform
during the copy, are:
// Provided by VK_EXT_opacity_micromap
typedef enum VkCopyMicromapModeEXT {
VK_COPY_MICROMAP_MODE_CLONE_EXT = 0,
VK_COPY_MICROMAP_MODE_SERIALIZE_EXT = 1,
VK_COPY_MICROMAP_MODE_DESERIALIZE_EXT = 2,
VK_COPY_MICROMAP_MODE_COMPACT_EXT = 3,
} VkCopyMicromapModeEXT;
-
VK_COPY_MICROMAP_MODE_CLONE_EXTcreates a direct copy of the micromap specified insrcinto the one specified bydst. Thedstmicromap must have been created with the same parameters assrc. -
VK_COPY_MICROMAP_MODE_SERIALIZE_EXTserializes the micromap to a semi-opaque format which can be reloaded on a compatible implementation. -
VK_COPY_MICROMAP_MODE_DESERIALIZE_EXTdeserializes the semi-opaque serialization format in the buffer to the micromap. -
VK_COPY_MICROMAP_MODE_COMPACT_EXTcreates a more compact version of a micromapsrcintodst. The micromapdstmust have been created with a size at least as large as that returned by vkCmdWriteMicromapsPropertiesEXT after the build of the micromap specified bysrc.
To copy a micromap to device memory call:
// Provided by VK_EXT_opacity_micromap
void vkCmdCopyMicromapToMemoryEXT(
VkCommandBuffer commandBuffer,
const VkCopyMicromapToMemoryInfoEXT* pInfo);
-
commandBufferis the command buffer into which the command will be recorded. -
pInfois an a pointer to a VkCopyMicromapToMemoryInfoEXT structure defining the copy operation.
Accesses to pInfo->src must be synchronized with the VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_2_MICROMAP_READ_BIT_EXT.
Accesses to the buffer indicated by pInfo->dst.deviceAddress must be
synchronized with the VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an access type of VK_ACCESS_TRANSFER_WRITE_BIT.
This command produces the same results as vkCopyMicromapToMemoryEXT, but writes its result to a device address, and is executed on the device rather than the host. The output may not necessarily be bit-for-bit identical, but it can be equally used by either vkCmdCopyMemoryToMicromapEXT or vkCopyMemoryToMicromapEXT.
The defined header structure for the serialized data consists of:
-
VK_UUID_SIZEbytes of data matchingVkPhysicalDeviceIDProperties::driverUUID -
VK_UUID_SIZEbytes of data identifying the compatibility for comparison using vkGetDeviceMicromapCompatibilityEXT The serialized data is written to the buffer (or read from the buffer) according to the host endianness.
// Provided by VK_EXT_opacity_micromap
typedef struct VkCopyMicromapToMemoryInfoEXT {
VkStructureType sType;
const void* pNext;
VkMicromapEXT src;
VkDeviceOrHostAddressKHR dst;
VkCopyMicromapModeEXT mode;
} VkCopyMicromapToMemoryInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
srcis the source micromap for the copy -
dstis the device or host address to memory which is the target for the copy -
modeis a VkCopyMicromapModeEXT value specifying additional operations to perform during the copy.
To copy device memory to a micromap call:
// Provided by VK_EXT_opacity_micromap
void vkCmdCopyMemoryToMicromapEXT(
VkCommandBuffer commandBuffer,
const VkCopyMemoryToMicromapInfoEXT* pInfo);
-
commandBufferis the command buffer into which the command will be recorded. -
pInfois a pointer to a VkCopyMemoryToMicromapInfoEXT structure defining the copy operation.
Accesses to pInfo->dst must be synchronized with the VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an
access type of
VK_ACCESS_2_MICROMAP_READ_BIT_EXT.
Accesses to the buffer indicated by pInfo->src.deviceAddress must be
synchronized with the VK_PIPELINE_STAGE_2_MICROMAP_BUILD_BIT_EXT
pipeline stage and an access type of VK_ACCESS_TRANSFER_READ_BIT.
This command can accept micromaps produced by either vkCmdCopyMicromapToMemoryEXT or vkCopyMicromapToMemoryEXT.
The VkCopyMemoryToMicromapInfoEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkCopyMemoryToMicromapInfoEXT {
VkStructureType sType;
const void* pNext;
VkDeviceOrHostAddressConstKHR src;
VkMicromapEXT dst;
VkCopyMicromapModeEXT mode;
} VkCopyMemoryToMicromapInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
srcis the device or host address to memory containing the source data for the copy. -
dstis the target micromap for the copy. -
modeis a VkCopyMicromapModeEXT value specifying additional operations to perform during the copy.
To check if a serialized micromap is compatible with the current device call:
// Provided by VK_EXT_opacity_micromap
void vkGetDeviceMicromapCompatibilityEXT(
VkDevice device,
const VkMicromapVersionInfoEXT* pVersionInfo,
VkAccelerationStructureCompatibilityKHR* pCompatibility);
-
deviceis the device to check the version against. -
pVersionInfois a pointer to a VkMicromapVersionInfoEXT structure specifying version information to check against the device. -
pCompatibilityis a pointer to a VkAccelerationStructureCompatibilityKHR value in which compatibility information is returned.
The VkMicromapVersionInfoEXT structure is defined as:
// Provided by VK_EXT_opacity_micromap
typedef struct VkMicromapVersionInfoEXT {
VkStructureType sType;
const void* pNext;
const uint8_t* pVersionData;
} VkMicromapVersionInfoEXT;
-
sTypeis a VkStructureType value identifying this structure. -
pNextisNULLor a pointer to a structure extending this structure. -
pVersionDatais a pointer to the version header of a micromap as defined in vkCmdCopyMicromapToMemoryEXT
|
Note
|
|
38.2. Host Micromap Operations
Implementations are also required to provide host implementations of the
micromap operations if the micromapHostCommands feature is enabled:
-
vkBuildMicromapsEXT corresponding to vkCmdBuildMicromapsEXT
-
vkCopyMicromapEXT corresponding to vkCmdCopyMicromapEXT
-
vkCopyMicromapToMemoryEXT corresponding to vkCmdCopyMicromapToMemoryEXT
-
vkCopyMemoryToMicromapEXT corresponding to vkCmdCopyMemoryToMicromapEXT
-
vkWriteMicromapsPropertiesEXT corresponding to vkCmdWriteMicromapsPropertiesEXT
These commands are functionally equivalent to their device counterparts, except that they are executed on the host timeline, rather than being enqueued into command buffers.
All micromaps used by the host commands must be bound to host-visible memory, and all input data for micromap builds must be referenced using host addresses instead of device addresses. Applications are not required to map micromap memory when using the host commands.
|
Note
|
The vkBuildMicromapsEXT and vkCmdBuildMicromapsEXT may use different algorithms, and thus are not required to produce identical structures. Apart from these details, the host and device operations are interchangeable. |
|
Note
|
For efficient execution, micromaps manipulated using these commands should always be bound to host cached memory, as the implementation may need to repeatedly read and write this memory during the execution of the command. |
To build micromaps on the host, call:
// Provided by VK_EXT_opacity_micromap
VkResult vkBuildMicromapsEXT(
VkDevice device,
VkDeferredOperationKHR deferredOperation,
uint32_t infoCount,
const VkMicromapBuildInfoEXT* pInfos);
-
deviceis theVkDevicefor which the micromaps are being built. -
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command. -
infoCountis the number of micromaps to build. It specifies the number of thepInfosthat must be provided. -
pInfosis a pointer to an array ofinfoCountVkMicromapBuildInfoEXT structures defining the geometry used to build each micromap.
This command fulfills the same task as vkCmdBuildMicromapsEXT but is executed by the host.
The vkBuildMicromapsEXT command provides the ability to initiate
multiple micromaps builds, however there is no ordering or synchronization
implied between any of the individual micromap builds.
|
Note
|
This means that there cannot be any memory aliasing between any micromap memories or scratch memories being used by any of the builds. |
To copy or compact a micromap on the host, call:
// Provided by VK_EXT_opacity_micromap
VkResult vkCopyMicromapEXT(
VkDevice device,
VkDeferredOperationKHR deferredOperation,
const VkCopyMicromapInfoEXT* pInfo);
-
deviceis the device which owns the micromaps. -
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command. -
pInfois a pointer to a VkCopyMicromapInfoEXT structure defining the copy operation.
This command fulfills the same task as vkCmdCopyMicromapEXT but is executed by the host.
To copy host accessible memory to a micromap, call:
// Provided by VK_EXT_opacity_micromap
VkResult vkCopyMemoryToMicromapEXT(
VkDevice device,
VkDeferredOperationKHR deferredOperation,
const VkCopyMemoryToMicromapInfoEXT* pInfo);
-
deviceis the device which ownspInfo->dst. -
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command. -
pInfois a pointer to a VkCopyMemoryToMicromapInfoEXT structure defining the copy operation.
This command fulfills the same task as vkCmdCopyMemoryToMicromapEXT but is executed by the host.
This command can accept micromaps produced by either vkCmdCopyMicromapToMemoryEXT or vkCopyMicromapToMemoryEXT.
To copy a micromap to host accessible memory, call:
// Provided by VK_EXT_opacity_micromap
VkResult vkCopyMicromapToMemoryEXT(
VkDevice device,
VkDeferredOperationKHR deferredOperation,
const VkCopyMicromapToMemoryInfoEXT* pInfo);
-
deviceis the device which ownspInfo->src. -
deferredOperationis an optional VkDeferredOperationKHR to request deferral for this command. -
pInfois a pointer to a VkCopyMicromapToMemoryInfoEXT structure defining the copy operation.
This command fulfills the same task as vkCmdCopyMicromapToMemoryEXT but is executed by the host.
This command produces the same results as vkCmdCopyMicromapToMemoryEXT, but writes its result directly to a host pointer, and is executed on the host rather than the device. The output may not necessarily be bit-for-bit identical, but it can be equally used by either vkCmdCopyMemoryToMicromapEXT or vkCopyMemoryToMicromapEXT.
To query micromap size parameters on the host, call:
// Provided by VK_EXT_opacity_micromap
VkResult vkWriteMicromapsPropertiesEXT(
VkDevice device,
uint32_t micromapCount,
const VkMicromapEXT* pMicromaps,
VkQueryType queryType,
size_t dataSize,
void* pData,
size_t stride);
-
deviceis the device which owns the micromaps inpMicromaps. -
micromapCountis the count of micromaps for which to query the property. -
pMicromapsis a pointer to an array of existing previously built micromaps. -
queryTypeis a VkQueryType value specifying the property to be queried. -
dataSizeis the size in bytes of the buffer pointed to bypData. -
pDatais a pointer to an application-allocated buffer where the results will be written. -
strideis the stride in bytes between results for individual queries withinpData.
This command fulfills the same task as vkCmdWriteMicromapsPropertiesEXT but is executed by the host.
38.2.1. Displacement Micromap
A displacement micromap in an acceleration structure includes information in the VkAccelerationStructureTrianglesDisplacementMicromapNV to define a base triangle and displacement directions then uses displacement information encoded in the micromap to apply to those values to generate the final position.
Displacement Base Triangle
If displacementBiasAndScaleBuffer is provided the bias and scale are
fetched from that buffer.
If displacementBiasAndScaleBuffer is zero the bias and scale are
assumed to be 0.0 and 1.0, respectively.
Given an input position from the geometry, the base position and displacement vector used by the displacement are computed by:
basePosition = inputPosition + displacementVector × bias
baseDisplacementVector = displacementVector × scale
The parameters of each micro-vertex are derived from a combination of the base triangle parameters extracted from the bottom-level acceleration structure, the barycentrics of that micro-vertex, and the displacement value fetched from the displacement micromap corresponding to that micro-vertex.
microVertexBasePosition = lerp(basePositions, microVertexBarycentrics)
microVertexDisplacementVector = lerp(displacementVectors, microVertexBarycentrics)
microVertexDisplacedPosition = microVertexBasePosition + microVertexDisplacementVector × micromapDisplacementValue
Displacement Micromap Encoding
Displacement amounts are stored in displacement blocks, each covering a triangular region of microvertices. Depending on the subdivision level and encoding format, one or more displacement blocks combine to store all displacement values for a given displacement micromap.
Displacement blocks are organized along a space filling curve within a displacement micromap if more than one block is required, then micro-vertices are organized along the same space filling curve within a displacement micromap.
The space-filling curve is purely hierarchical with recursive splitting, similar to that for opacity micromaps but operating on vertices instead of triangles. To maintain that the hierarchical ordering is contiguous while keeping continuous winding, some triangles are flipped and wound differently.
The VK_DISPLACEMENT_MICROMAP_FORMAT_64_TRIANGLES_64_BYTES_NV format is
an uncompressed, packed format which covers 64 microtriangles (subdivision
level 3) in a block.
The block contains 45 displacement values encoded as 11 bit unorm values and
stored tightly packed in the vertex order described above, occupying 495
bits.
This is followed by 15 unused bits then 2 reserved bits which must be 0.
If this block is used to store displacement for a subdivision level below 3
the later unused values are ignored.
| Section | Field | Entries | Bits per entry | Starting bit offset |
|---|---|---|---|---|
Displacement amounts |
Vertex 0 - 44 |
45 |
11 |
0 |
Unused |
1 |
15 |
495 |
|
Reserved |
Must be 0 |
1 |
2 |
510 |
The VK_DISPLACEMENT_MICROMAP_FORMAT_256_TRIANGLES_128_BYTES_NV and
VK_DISPLACEMENT_MICROMAP_FORMAT_1024_TRIANGLES_128_BYTES_NV formats
store displacements in a compressed form to save space.
Both formats use the same compression algorithm, differing in the number of
bits used in the different fields.
The compression algorithm works by starting with fully specified anchor vertices, then for each level, predicting the value for the displacement and encoding the correction for that value, using fewer bits for each level of subdivision.
When adding a vertex in the recursive subdivision process between two adjacent displacement values, the predicted value is given by the rounded average of the two adjacent values as integers:
prediction = (A + B + 1) / 2
The decoded value after applying the correction is given by:
decoded = prediction + ( SignExtend(correction) << shift )
where correction is given by the corrections field for a given level and micro vertex and shift is given by the shifts field indexed from the level then by 4 values, selected from interior or the 3 edges in vertex order in that order.
The bit encoding for
VK_DISPLACEMENT_MICROMAP_FORMAT_256_TRIANGLES_128_BYTES_NV
| Section | Field | Entries | Bits per entry | Starting bit offset |
|---|---|---|---|---|
Anchors |
Vertex 0 - 2 |
3 |
11 |
0 |
Corrections |
Level 1 |
3 |
11 |
33 |
Level 2 |
9 |
11 |
66 |
|
Level 3 |
30 |
10 |
165 |
|
Level 4 |
108 |
5 |
465 |
|
Unused |
1 |
1 |
1005 |
|
Shifts |
Level 4 |
4 |
3 |
1006 |
Level 3 |
4 |
1 |
1018 |
|
Reserved |
Must be 0 |
1 |
2 |
1022 |
The bit encoding for
VK_DISPLACEMENT_MICROMAP_FORMAT_1024_TRIANGLES_128_BYTES_NV
| Section | Field | Entries | Bits per entry | Starting bit offset |
|---|---|---|---|---|
Anchors |
Vertex 0 - 2 |
3 |
11 |
0 |
Corrections |
Level 1 |
3 |
11 |
33 |
Level 2 |
9 |
8 |
66 |
|
Level 3 |
30 |
4 |
138 |
|
Level 4 |
108 |
2 |
258 |
|
Level 5 |
408 |
1 |
474 |
|
Unused |
1 |
88 |
882 |
|
Shifts |
Level 5 |
4 |
4 |
970 |
Level 4 |
4 |
4 |
986 |
|
Level 3 |
4 |
3 |
1002 |
|
Level 2 |
4 |
2 |
1014 |
|
Reserved |
Must be 0 |
1 |
2 |
1022 |