Micromap

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.

Building Micromaps

vkCmdBuildMicromapsEXTBuild a micromap
VkOpacityMicromapFormatEXTFormat enum for opacity micromaps
VkDisplacementMicromapFormatNVFormat enum for displacement micromaps
VkMicromapBuildInfoEXTStructure specifying the data used to build a micromap
VkBuildMicromapModeEXTEnum specifying the type of build operation to perform
VkMicromapUsageEXTStructure specifying the usage information used to build a micromap
VkMicromapTriangleEXTStructure specifying the micromap format and data for a triangle

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.

vkCmdWriteMicromapsPropertiesEXTWrite micromap result parameters to query results.
vkCmdCopyMicromapEXTCopy a micromap
VkCopyMicromapInfoEXTParameters for copying a micromap
VkCopyMicromapModeEXTMicromap copy mode
vkCmdCopyMicromapToMemoryEXTCopy a micromap to device memory
VkCopyMicromapToMemoryInfoEXTParameters for serializing a micromap
vkCmdCopyMemoryToMicromapEXTCopy device memory to a micromap
VkCopyMemoryToMicromapInfoEXTParameters for deserializing a micromap
vkGetDeviceMicromapCompatibilityEXTCheck if a serialized micromap is compatible with the current device
VkMicromapVersionInfoEXTMicromap version information

Host Micromap Operations

Implementations are also required to provide host implementations of the micromap operations if the micromapHostCommands feature is enabled:

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.

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.

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.

vkBuildMicromapsEXTBuild a micromap on the host
vkCopyMicromapEXTCopy a micromap on the host
vkCopyMemoryToMicromapEXTDeserialize a micromap on the host
vkCopyMicromapToMemoryEXTSerialize a micromap on the host
vkWriteMicromapsPropertiesEXTQuery micromap meta-data on the host

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.

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

The bit encoding for VK_DISPLACEMENT_MICROMAP_FORMAT_1024_TRIANGLES_128_BYTES_NV