Skip to content

ComputeMeshlets

Chuck Walbourn edited this page Jun 1, 2020 · 20 revisions

Computes meshlets from mesh subsets for use with DirectX 12 Mesh Shaders.

Computing meshlets for a single submesh:

HRESULT ComputeMeshlets(
    const uint16_t* indices, size_t nFaces,
    const XMFLOAT3* positions, size_t nVerts,
    const uint32_t* adjacency,
    std::vector<Meshlet>& meshlets,
    std::vector<uint8_t>& uniqueVertexIndices,
    std::vector<MeshletTriangle>& primitiveIndices,
    size_t maxVerts = MESHLET_DEFAULT_MAX_VERTS,
    size_t maxPrims = MESHLET_DEFAULT_MAX_PRIMS);
HRESULT ComputeMeshlets(
    const uint32_t* indices, size_t nFaces,
    const XMFLOAT3* positions, size_t nVerts,
    const uint32_t* adjacency,
    std::vector<Meshlet>& meshlets,
    std::vector<uint8_t>& uniqueVertexIndices,
    std::vector<MeshletTriangle>& primitiveIndices,
    size_t maxVerts = MESHLET_DEFAULT_MAX_VERTS,
    size_t maxPrims = MESHLET_DEFAULT_MAX_PRIMS);

Computing meshlets for multiple subsets of a mesh:

HRESULT ComputeMeshlets(
    const uint16_t* indices, size_t nFaces,
    const XMFLOAT3* positions, size_t nVerts,
    const std::pair<size_t, size_t>* indexSubsets, size_t nSubsets,
    _In_reads_opt_(nFaces * 3) const uint32_t* adjacency,
    std::vector<Meshlet>& meshlets,
    std::vector<uint8_t>& uniqueVertexIndices,
    std::vector<MeshletTriangle>& primitiveIndices,
    std::pair<size_t, size_t>* meshletSubsets,
    size_t maxVerts = MESHLET_DEFAULT_MAX_VERTS,
    size_t maxPrims = MESHLET_DEFAULT_MAX_PRIMS);
HRESULT __cdecl ComputeMeshlets(
    const uint32_t* indices, size_t nFaces,
    const XMFLOAT3* positions, size_t nVerts,
    const std::pair<size_t, size_t>* subsets, size_t nSubsets,
    const uint32_t* adjacency,
    std::vector<Meshlet>& meshlets,
    std::vector<uint8_t>& uniqueVertexIndices,
    std::vector<MeshletTriangle>& primitiveIndices,
    std::pair<size_t, size_t>* meshletSubsets,
    size_t maxVerts = MESHLET_DEFAULT_MAX_VERTS,
    size_t maxPrims = MESHLET_DEFAULT_MAX_PRIMS);

Parameters

Remarks

Example

auto mesh = std::make_unique<WaveFrontReader<uint16_t>>();

if ( FAILED( mesh->Load( L"test.obj" ) ) )
   // Error

size_t nFaces = mesh->indices.size() / 3;
size_t nVerts = mesh->vertices.size();

std::unique_ptr<XMFLOAT3[]> pos( new XMFLOAT3[ nVerts ] );
for( size_t j = 0; j < nVerts; ++j )
   pos[ j ] = mesh->vertices[ j ].position;

std::vector<Meshlet> meshlets;
std::vector<uint8_t> uniqueVertexIndices;
std::vector<MeshletTriangle> primitiveIndices;
if ( FAILED( ComputeMeshlets( mesh->indices.data(), nFaces,
    pos.get(), nVerts,
    nullptr,
    meshlets, uniqueVertexIndices, primitiveIndices) )
    // Error

auto ib = reinterpret_cast<const uint16_t*>(uniqueVertexIndices.data());
size_t count = uniqueVertexIndices.size() / sizeof(uint16_t);

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v20
  • GCC 10.5, 11.4, 12.3, 13.3, 14.2
  • MinGW 12.2, 13.2
  • CMake 3.21

Related Projects

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXTex

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally