GPGMM is a General-Purpose GPU Memory Management library.
GPGMM uses the Chromium build system and dependency management so you need to install depot_tools and add it to the PATH.
Notes:
- On Windows, you'll need to set the environment variable
DEPOT_TOOLS_WIN_TOOLCHAIN=0. This tells depot_tools to use your locally installed version of Visual Studio (by default, depot_tools will try to download a Google-internal version).
Get the source code as follows:
# Clone the repo as "GPGMM"
> git clone https://github.com/intel/GPGMM.git GPGMM && cd GPGMM
# Bootstrap the gclient configuration
> cp scripts/standalone.gclient .gclient
# Fetch external dependencies and toolchains with gclient
> gclient syncGenerate build files using gn args out/Debug or gn args out/Release.
A text editor will appear asking build options, the most common option is is_debug=true/false; otherwise gn args out/Release --list shows all the possible options.
To build with a backend, please set the corresponding option from following table.
| Backend | Option |
|---|---|
| D3D12 | gpgmm_enable_d3d12=true (default on winos) |
| Vulkan | gpgmm_enable_vulkan=true |
Then use ninja -C out/Release or ninja -C out/Debug to build.
Run unit tests:
> out/Debug/gpgmm_unittestsRun end2end tests:
> out/Release/gpgmm_end2end_testsRun capture replay tests:
> out/Release/gpgmm_capture_replay_testsTo allocate, you create an allocator then create allocations from it:
D3D12_FEATURE_DATA_ARCHITECTURE arch = {};
device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch, sizeof(arch)
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)));
gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {};
allocatorDesc.Adapter = adapter;
allocatorDesc.Device = device;
allocatorDesc.IsUMA = arch.UMA;
allocatorDesc.ResourceHeapTier = options.ResourceHeapTier;
ComPtr<gpgmm::d3d12::ResourceAllocator> allocator;
gpgmm::d3d12::ResourceAllocator::CreateAllocator(desc, &allocator);/* Fill this out */
D3D12_RESOURCE_DESC& resourceDesc = {...};
D3D12_RESOURCE_STATES initialState = {...}
gpgmm::d3d12::ALLOCATION_DESC allocationDesc = {};
allocationDesc.HeapType = heapType;
ComPtr<gpgmm::d3d12::ResourceAllocation> allocation;
allocator->CreateResource(allocationDesc, resourceDesc, initialState, /*pOptimizedClear*/nullptr, &allocation);Then de-allocate:
/* Must make sure GPU is finished using it */
allocation.Release();To use basic residency:
- Create a
d3d12::ResourceAllocatorwithALLOCATOR_ALWAYS_IN_BUDGETflag. - Use
d3d12::ResourceAllocator::CreateResourcefor every resource you want residency managed. - Create a
d3d12::ResidencySetto track a collection of allocations that should be resident for a given command-list (1:1 relationship). d3d12::ResourceAllocation::UpdateResidencytracks the underlying heap for the resident set.- Use
d3d12::ResidencyManager::ExecuteCommandListswith the residency set, queue, and command list.
What about residency for other heaps (SV descriptor or query heaps)?
- Sub-class
d3d12::Heap. - Call
d3d12::ResidencyManager::InsertHeapon it after creation. - Use
d3d12::ResidencyManager::Lockord3d12::ResidencyManager::UnlockHeapto keep heap resident or not, respectively.
GPGMM has built-in GN or CMake build targets.
BUILD.gn
source_set("proj") {
deps = [ "${gpgmm_dir}/src:gpgmm" ]
}Create build_overrides/gpgmm.gni file in root directory.
CMakeLists.txt
add_subdirectory(gpgmm)
target_include_directories(proj PRIVATE gpgmm/src/include gpgmm/)
target_link_libraries(proj PRIVATE gpgmm ...)Then import:
#include <gpgmm_d3d12.h> // or gpgmm_vulkan.h- Error handing uses API error codes (
HRESULTandVkResultfor D3D12 and Vulkan, respectively).
Apache 2.0 Public License, please see LICENSE.