{"id":13728749,"url":"https://github.com/NVIDIA-RTX/RTXMU","last_synced_at":"2025-05-08T01:30:21.526Z","repository":{"id":100714320,"uuid":"385537462","full_name":"NVIDIA-RTX/RTXMU","owner":"NVIDIA-RTX","description":"RTX Memory Utility Library helps to reduce and compact ray tracing memory for games","archived":false,"fork":false,"pushed_at":"2025-02-24T17:55:56.000Z","size":120,"stargazers_count":117,"open_issues_count":2,"forks_count":18,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-04-05T16:05:04.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://developer.nvidia.com/blog/reducing-acceleration-structure-memory-with-nvidia-rtxmu/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NVIDIA-RTX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-13T08:46:26.000Z","updated_at":"2025-03-27T11:50:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"f347c775-7952-4799-844d-a441fbef9457","html_url":"https://github.com/NVIDIA-RTX/RTXMU","commit_stats":null,"previous_names":["nvidia-rtx/rtxmu"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA-RTX%2FRTXMU","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA-RTX%2FRTXMU/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA-RTX%2FRTXMU/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA-RTX%2FRTXMU/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NVIDIA-RTX","download_url":"https://codeload.github.com/NVIDIA-RTX/RTXMU/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252981349,"owners_count":21835413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:00:49.516Z","updated_at":"2025-05-08T01:30:21.101Z","avatar_url":"https://github.com/NVIDIA-RTX.png","language":"C++","readme":"# RTXMU - RTX Memory Utility\n\nPlease read the NVIDIA Blog post on how to use RTXMU:\nhttps://developer.nvidia.com/blog/reducing-acceleration-structure-memory-with-nvidia-rtxmu/\n\nPresentation with slides about RTXMU:\nhttps://www.nvidia.com/en-us/on-demand/session/gdc21-gdc21-01/\n\nTo generate a test project:\n1) Clone me\n2) at root directory mkdir build\n3) cd build\n4) cmake -G \"Visual Studio 16 2019\" -A x64 ..\n\nRTXMU - RTX Memory Utility SDK.\n\nThe design of this SDK is to allow developers to use compaction and suballocation of\nacceleration structure buffers to reduce the memory footprint.  Compaction is proven to reduce the total memory\nfootprint by more than a half.  Suballocation is proven to reduce memory as well by tightly packing\nacceleration structure buffers that are less than 64 KB.\n\nThe intended use of this SDK is to batch up all of the acceleration structure build inputs and pass them to\nRTXMU which in turn will perform all the suballocation memory requests and build details\nincluding compaction.  Post build info is abstracted away by the SDK in order to do compaction under the hood.\nRTXMU returns acceleration structure handle ids that are used to reference the underlying memory buffers.  These handle\nids are passed into RTXMU to create compaction copy workloads, deallocate unused build resources or remove all memory\nassociated with an acceleration structure.\n\n## Building Ray Traced Sample Application integrated with RTXMU:\nRequirements:\nWindows or Linux, CMake 3.12, C++ 17, Operating system that supports DXR and/or Vulkan RT, Git\n\nBuild Steps for running the donut sample application:\n1)  Clone the repository under the rtxmu branch using the command: git clone --recursive https://github.com/NVIDIAGameWorks/donut_examples.git\n2)  Open CMake and point “Where is the source code:” to the donut_examples folder.  Create a build folder in the donut_examples folder and point “Where to build the binaries:” to the build folder.\n    Then select the cmake variable NVRHI_WITH_RTXMU to ON, click Configure at the bottom and once that is complete, click Generate.  If you are building with Visual Studio then select 2019 and x64 version.\n    Now you have a Visual Studio project you can build.\n3)  Now open the donut_examples.sln file in Visual Studio and build the entire project.\n4)  Find the rt_bindless application folder under Examples/Bindless Ray Tracing and right click the project and set as Startup Project.\n5)  By default, Bindless Ray Tracing will run on DXR but if you want to run the Vulkan version just add -vk as a command line argument in the project.\n\nSample Application built on Nvidia’s Donut engine framework:\nhttps://github.com/NVIDIAGameWorks/donut_examples\n\nRTXMU SDK library code:\nhttps://github.com/NVIDIAGameWorks/RTXMU\n\n\n## Pseudocode examples using the SDK:\n\n    // Grab RTXMU singleton\n    rtxmu::DxAccelStructManager rtxMemUtil(device);\n\n    // Initialize suballocator blocks to 8 MB\n    rtxMemUtil.Initialize(8388608);\n    \n    // Batch up all the acceleration structure build inputs, can be compacted or non compacted\n    std::vector\u003cD3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS\u003e bottomLevelBuildDescs;\n    for (auto entity : entityList)\n    {\n        D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS bottomLevelInputs = {};\n    \n        bottomLevelInputs.Flags = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_COMPACTION;\n    \n        if (entity-\u003eisAnimated() == true)\n        {\n            bottomLevelInputs.Flags |=\n                D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_ALLOW_UPDATE |\n                D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_BUILD;\n        }\n        else\n        {\n            bottomLevelInputs.Flags |=\n                D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_TRACE;\n        }\n    \n        bottomLevelInputs.DescsLayout    = D3D12_ELEMENTS_LAYOUT_ARRAY;\n        bottomLevelInputs.NumDescs       = 1;\n        bottomLevelInputs.Type           = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL;\n        bottomLevelInputs.pGeometryDescs = GetBlasGeometryDesc(entity);\n    \n        bottomLevelBuildDescs.push_back(bottomLevelInputs);\n    }\n    \n    // Records all of the build calls and populates a list of acceleration structure ids\n    // that can be passed into the library to get the current GPUVA of the acceleration structure\n    std::vector\u003cuint64_t\u003e accelStructIds;\n    rtxMemUtil.PopulateBuildCommandList(commandList.Get(),\n                                        bottomLevelBuildDescs.data(),\n                                        bottomLevelBuildDescs.size(),\n                                        accelStructIds);\n\n    // Receives acceleration structure inputs and places UAV barriers for them\n    rtxMemUtil.PopulateUAVBarriersCommandList(commandList.Get(), accelStructIds);\n\n    // Performs copies to bring over any compaction size data\n    rtxMemUtil.PopulateCompactionSizeCopiesCommandList(commandList, accelStructIds);\n\n    // Create mapping of the accel struct ids to the model objects\n    for (int asBufferIndex = 0; asBufferIndex \u003c bottomLevelBuildModels.size(); asBufferIndex++)\n    {\n        _blasMap[bottomLevelBuildModels[asBufferIndex]] = accelStructIds[asBufferIndex];\n    }\n\n    // ----------------------------------------------------------------------------------- //\n    // Building the TLAS instance description arrays using AccelStructIds handle vector\n    // ----------------------------------------------------------------------------------- //\n    for (int instanceIndex = 0; instanceIndex \u003c instanceCount; instanceIndex++)\n    {\n        memcpy(\u0026_instanceDesc[instanceIndex].Transform,\n               \u0026_blasTransforms[instanceIndex * (transformOffset / sizeof(float))],\n               sizeof(float) * 12);\n    \n        _instanceDesc[instanceIndex].InstanceMask                        = 1;\n        _instanceDesc[instanceIndex].Flags                               = D3D12_RAYTRACING_INSTANCE_FLAG_NONE;\n        _instanceDesc[instanceIndex].InstanceID                          = 0;\n        _instanceDesc[instanceIndex].InstanceContributionToHitGroupIndex = 0;\n    \n        // Use the acceleration structure handle to get either the result or the compaction buffer based\n        //on the build state of the acceleration structure\n        const uint64_t asHandle = _blasMap[entity-\u003egetModel()];\n        _instanceDesc[instanceIndex].AccelerationStructure = rtxMemUtil.GetAccelStructGPUVA(asHandle);\n    }\n\n    // Executing all of the initial builds prior to generating the compaction workloads \n    // because the compaction sizes aren't available in system memory until execution is finished\n\n    commandList-\u003eClose();\n    gfxQueue-\u003eExecuteCommandLists(1, CommandListCast(commandList.GetAddressOf()));\n\n    int fenceValue = _gfxNextFenceValue[cmdListIndex]++;\n    _gfxQueue-\u003eSignal(_gfxCmdListFence[cmdListIndex].Get(), fenceValue);\n\n    HANDLE fenceWriteEventECL = CreateEvent(nullptr, FALSE, FALSE, nullptr);\n    // Wait for just-submitted command list to finish\n    _gfxCmdListFence[cmdListIndex]-\u003eSetEventOnCompletion(fenceValue, fenceWriteEventECL);\n    WaitForSingleObject(fenceWriteEventECL, INFINITE);\n\n    // Acceleration structures that have finished building on the GPU can now be queued to perform compaction\n    if (newBuildsToCompact.size() \u003e 0)\n    {\n        rtxMemUtil.PopulateCompactionCommandList(commandList.Get(), newBuildsToCompact);\n    }\n\n    // Executing all of the compaction workloads prior to cleaning up the initial larger\n    // acceleration structure buffer is required to peform the initial build to compaction build copy\n\n    commandList-\u003eClose();\n    gfxQueue-\u003eExecuteCommandLists(1, CommandListCast(commandList.GetAddressOf()));\n\n    int fenceValue = _gfxNextFenceValue[cmdListIndex]++;\n    _gfxQueue-\u003eSignal(_gfxCmdListFence[cmdListIndex].Get(), fenceValue);\n\n    HANDLE fenceWriteEventECL = CreateEvent(nullptr, FALSE, FALSE, nullptr);\n    // Wait for just-submitted command list to finish\n    _gfxCmdListFence[cmdListIndex]-\u003eSetEventOnCompletion(fenceValue, fenceWriteEventECL);\n    WaitForSingleObject(fenceWriteEventECL, INFINITE);\n\n    // Acceleration structures that have finished building and compacting which means we can deallocate resources\n    // used in the build and compaction process (scratch and original build buffer memory).\n    if (newBuildsToGarbageCollect.size() \u003e 0)\n    {\n        rtxMemUtil.GarbageCollection(newBuildsToGarbageCollect);\n    }\n\n\n    // Removing acceleration structure no longer required\n    std::vector\u003cuint64_t\u003e accelStructIds;\n    for (auto model : modelCountsInEntities)\n    {\n        if (model.second == 0)\n        {\n            // Push id onto remove list\n            accelStructIds.push_back(_blasMap[model.first]);\n            // Remove the blas entry from the list\n            _blasMap.erase(model.first);\n        }\n    }\n    \n    // Remove all of the no longer referenced accel struct ids by calling RemoveAccelerationStructures\n    if (accelStructIds.size() \u003e 0)\n    {\n        rtxMemUtil.RemoveAccelerationStructures(accelStructIds);\n    }\n\n## License\nRTXMU is licensed under the [MIT License](LICENSE.txt).\n","funding_links":[],"categories":["DirectX Tools, Libraries, and Frameworks"],"sub_categories":["VS Code Extensions for Developer Productivity","Enable Proton in Steam"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNVIDIA-RTX%2FRTXMU","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNVIDIA-RTX%2FRTXMU","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNVIDIA-RTX%2FRTXMU/lists"}