### Install Header File Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Installs the main D3D12MemAlloc.h header file to the include directory. ```cmake install(FILES "${PROJECT_SOURCE_DIR}/include/D3D12MemAlloc.h" DESTINATION "include") ``` -------------------------------- ### Option to Build Documentation Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/CMakeLists.txt Configures whether to build and install the HTML-based API documentation. Requires Doxygen to be found. ```cmake option(BUILD_DOCUMENTATION "Create and install the HTML-based API documentation (requires Doxygen)" OFF) ``` -------------------------------- ### Buffer Creation for Upload Heap Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html Example of creating a buffer resource intended for an UPLOAD heap type. This setup is common for transferring data from the CPU to the GPU. ```cpp const UINT64 bufSize = 65536; const float* bufData = ...; D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; resourceDesc.Alignment = 0; resourceDesc.Width = bufSize; resourceDesc.Height = 1; resourceDesc.DepthOrArraySize = 1; resourceDesc.MipLevels = 1; resourceDesc.Format = DXGI_FORMAT_UNKNOWN; // Further configuration for UPLOAD heap type would typically follow here, // potentially involving specific flags or memory pool settings during allocation. ``` -------------------------------- ### Create Buffer Resource with Specific Allocation Strategy Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This example shows how to create a buffer resource using D3D12MA with a specific allocation strategy (minimum time) and defines the buffer's properties. ```cpp D3D12_RESOURCE_DESC resDesc; resDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; resDesc.Alignment = 0; resDesc.Width = myBufSize; resDesc.Height = 1; resDesc.DepthOrArraySize = 1; resDesc.MipLevels = 1; resDesc.Format = DXGI_FORMAT_UNKNOWN; resDesc.SampleDesc.Count = 1; resDesc.SampleDesc.Quality = 0; resDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; resDesc.Flags = D3D12_RESOURCE_FLAG_NONE; [D3D12MA::Allocation](class_d3_d12_m_a_1_1_allocation.html)* alloc; ID3D12Resource* res; HRESULT hr = allocator->[CreateResource](class_d3_d12_m_a_1_1_allocator.html#aa37d6b9fe8ea0864f7a35b9d68e8345a)(&allocDesc, &resDesc, ``` -------------------------------- ### BeginDefragmentation Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_pool-members.html Starts the defragmentation process for the pool. It takes a description of the defragmentation process and returns a context for managing it. ```APIDOC ## BeginDefragmentation ### Description Starts the defragmentation process for the pool. It takes a description of the defragmentation process and returns a context for managing it. ### Method [Method signature not explicitly defined, inferred as a member function call] ### Parameters * **pDesc** (const DEFRAGMENTATION_DESC *) - Description not explicitly defined. * **ppContext** (DefragmentationContext **) - Description not explicitly defined. ``` -------------------------------- ### Install CMake Config Files Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Installs CMake configuration files and export definitions for the D3D12MemoryAllocator library. ```cmake install( FILES "${D3D12MA_PROJECT_CONFIG}" "${D3D12MA_VERSION_CONFIG}" DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") install( EXPORT "${D3D12MA_TARGETS_EXPORT_NAME}" NAMESPACE "${D3D12MA_NAMESPACE}" DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") ``` -------------------------------- ### Create Resource with D3D12MA Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html Example of creating a D3D12 resource using the D3D12MA allocator. This snippet demonstrates setting up the resource description and allocation description before calling the CreateResource function. ```cpp resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; [D3D12MA::ALLOCATION_DESC](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html) allocationDesc = {}; allocationDesc.[HeapType](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aa46b3c0456e5a23edef3328607ebf4d7) = D3D12_HEAP_TYPE_UPLOAD; D3D12Resource* resource; [D3D12MA::Allocation](class_d3_d12_m_a_1_1_allocation.html)* allocation; HRESULT hr = allocator->[CreateResource](class_d3_d12_m_a_1_1_allocator.html#aa37d6b9fe8ea0864f7a35b9d68e8345a)( &allocationDesc, &resourceDesc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, &allocation, IID_PPV_ARGS(&resource)); ``` -------------------------------- ### Install Library Targets Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Installs the D3D12MemoryAllocator library targets, including runtime, archive, and library destinations. ```cmake install(TARGETS D3D12MemoryAllocator EXPORT ${D3D12MA_TARGETS_EXPORT_NAME} RUNTIME DESTINATION "bin" ARCHIVE DESTINATION "lib" LIBRARY DESTINATION "lib") ``` -------------------------------- ### Creating a Resource in GPU Upload Heap Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/optimal_allocation.html Example of creating a buffer resource in the D3D12_HEAP_TYPE_GPU_UPLOAD heap. Includes mapping, copying data, and accessing via GPU virtual address. Handles fallback if the heap is not supported. ```cpp [D3D12MA::CALLOCATION_DESC](struct_d3d12_m_a_1_1_c_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html) allocDesc = [D3D12MA::CALLOCATION_DESC](struct_d3d12_m_a_1_1_c_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html){ D3D12_HEAP_TYPE_GPU_UPLOAD }; // !!! CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer( 1048576); // Requested buffer size. [D3D12MA::Allocation](class_d3d12_m_a_1_1_allocation.html) * alloc; ID3D12Resource* res; hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &alloc, IID_PPV_ARGS(&res)); if(SUCCEEDED(hr)) { // Fast path for data upload. D3D12_RANGE emptyRange = {0, 0}; void* mappedPtr = NULL; hr = res->Map(0, &emptyRange, &mappedPtr); memcpy(mappedPtr, srcData, 1048576); res->Unmap(0, NULL); // Optional. You can leave it persistently mapped. D3D12_GPU_VIRTUAL_ADDRESS gpuva = res->GetGPUVirtualAddress(); // Use gpuva to access the buffer on the GPU... } else if(hr == E_NOTIMPL) { // GPU Upload Heap not supported in this system. // Fall back to creating a staging buffer in UPLOAD and another copy in DEFAULT. allocDesc.[HeapType](struct_d3d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aa46b3c0456e5a23edef3328607ebf4d7) = D3D12_HEAP_TYPE_UPLOAD; // ... } else // Some other error code e.g., out of memory... ``` -------------------------------- ### Custom CPU Memory Allocator Callbacks Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/configuration.html Example of defining custom allocation and free functions for CPU memory. These functions are then passed to the D3D12MA::ALLOCATOR_DESC. ```cpp #include void* CustomAllocate(size_t Size, size_t Alignment, void* pPrivateData) { void* memory = _aligned_malloc(Size, Alignment); // Your extra bookkeeping here... return memory; } void CustomFree(void* pMemory, void* pPrivateData) { // Your extra bookkeeping here... _aligned_free(pMemory); } ``` ```cpp D3D12MA::ALLOCATION_CALLBACKS allocationCallbacks = {}; allocationCallbacks.pAllocate = &CustomAllocate; allocationCallbacks.pFree = &CustomFree; D3D12MA::ALLOCATOR_DESC allocatorDesc = {}; allocatorDesc.pDevice = device; allocatorDesc.pAdapter = adapter; allocatorDesc.Flags = D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS; allocatorDesc.pAllocationCallbacks = &allocationCallbacks; D3D12MA::Allocator* allocator; HRESULT hr = D3D12MA::CreateAllocator(&allocatorDesc, &allocator); ``` -------------------------------- ### Iterative Defragmentation Pass Example Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/defragmentation.html This code demonstrates the iterative nature of defragmentation. It repeatedly calls BeginPass and EndPass until the defragmentation is complete (returns S_OK) or an error occurs. Ensure command lists are executed and fences are waited upon before updating descriptors. ```cpp // Make sure the copy commands finished executing. cmdQueue->ExecuteCommandLists(...); // ... WaitForSingleObject(fenceEvent, INFINITE); // Update appropriate descriptors to point to the new places... hr = defragCtx->EndPass(&pass); if(hr == S_OK) break; else if(hr != S_FALSE) // Handle error... } defragCtx->Release(); ``` -------------------------------- ### D3D12MA DefragmentationContext BeginPass Method Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/defragmentation.html Starts a single defragmentation pass. This function calculates and returns the list of allocations to be moved in the current pass. Note that this can be a time-consuming operation. ```cpp HRESULT BeginPass(DEFRAGMENTATION_PASS_MOVE_INFO* pPassInfo) // Starts single defragmentation pass. ``` -------------------------------- ### Create Resource with CALLOCATION_DESC Helper Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This example shows a more concise way to create a Direct3D 12 resource using the D3D12 Memory Allocator's helper structure `CALLOCATION_DESC`. This simplifies the initialization of allocation parameters. ```cpp // Assume allocator is initialized and valid D3D12MA::ALLOCATOR* allocator; // Example usage: UINT64 myBufSize = 1024 * 1024; // 1MB buffer D3D12MA::CALLOCATION_DESC allocDesc = { D3D12_HEAP_TYPE_UPLOAD, D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_TIME }; CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer(myBufSize); D3D12MA::Allocation* alloc; ID3D12Resource* res; HRESULT hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &alloc, IID_PPV_ARGS(&res)); // Check hr for success or failure... ``` -------------------------------- ### Create D3D12 Resource with Custom Allocation Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This snippet demonstrates how to create a D3D12 resource using the D3D12MA::Allocator::CreateResource function. It shows the setup of D3D12_RESOURCE_DESC and D3D12MA::ALLOCATION_DESC, including specifying the heap type. The created resource can be accessed via the Allocation object. ```cpp D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resourceDesc.Alignment = 0; resourceDesc.Width = 1024; resourceDesc.Height = 1024; resourceDesc.DepthOrArraySize = 1; resourceDesc.MipLevels = 1; resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; [D3D12MA::ALLOCATION_DESC](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html) allocationDesc = {}; allocationDesc.[HeapType](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aa46b3c0456e5a23edef3328607ebf4d7) = D3D12_HEAP_TYPE_DEFAULT; [D3D12MA::Allocation](class_d3_d12_m_a_1_1_allocation.html)* allocation; HRESULT hr = allocator->[CreateResource](class_d3_d12_m_a_1_1_allocator.html#aa37d6b9fe8ea0864f7a35b9d68e8345a)( &allocationDesc, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &allocation, IID_NULL, NULL); // Check hr... ID3D12Resource* res = allocation->[GetResource](class_d3_d12_m_a_1_1_allocation.html#ad00308118252f82d8f803c623c67bf18)(); // Use res... ``` -------------------------------- ### D3D12MA::DefragmentationContext::BeginPass Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_defragmentation_context-members.html Starts a defragmentation pass, providing information about the moves to be performed. This method is part of the defragmentation process for managing memory allocations. ```APIDOC ## BeginPass ### Description Starts a defragmentation pass, providing information about the moves to be performed. This method is part of the defragmentation process for managing memory allocations. ### Method [Method Signature] ### Parameters #### Path Parameters - **pPassInfo** (DEFRAGMENTATION_PASS_MOVE_INFO *) - Description of the pass information structure. ``` -------------------------------- ### D3D12MA::DefragmentationContext::BeginPass Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_defragmentation_context.html Starts a single defragmentation pass. It computes information for the current pass and returns it in pPassInfo. The function returns S_OK if no more moves are possible, allowing the defragmentation to end. Otherwise, it returns S_FALSE, indicating pending moves that need to be performed. ```APIDOC ## D3D12MA::DefragmentationContext::BeginPass ### Description Starts single defragmentation pass. ### Method (Implicitly called, not an HTTP method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **pPassInfo** ([DEFRAGMENTATION_PASS_MOVE_INFO]* ) - out - Computed informations for current pass. ### Request Example None ### Response #### Success Response (S_OK) * No more moves are possible. You can omit call to DefragmentationContext::EndPass() and simply end whole defragmentation. #### Success Response (S_FALSE) * There are pending moves returned in pPassInfo. You need to perform them, call DefragmentationContext::EndPass(), and then preferably try another pass with DefragmentationContext::BeginPass(). #### Response Example None ``` -------------------------------- ### Create a Custom Memory Pool with Explicit Block Size Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/optimal_allocation.html Create a custom memory pool with a specified block size. Resources allocated in such a pool will be placed within these blocks, ensuring they are not created as committed resources. This example demonstrates creating a pool for default heaps, allowing only buffers, with a 100MB block size. ```C++ D3D12MA::POOL_DESC poolDesc = {}; poolDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; poolDesc.Flags = D3D12MA_RECOMMENDED_HEAP_FLAGS | D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; poolDesc.BlockSize = 100ull * 1024 * 1024; // 100 MB. Explicit BlockSize guarantees placed. D3D12MA::Pool* pool; HRESULT hr = allocator->CreatePool(&poolDesc, &pool); // Check hr... D3D12MA::ALLOCATION_DESC allocDesc = {}; allocDesc.Pool = pool; CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer(90ull * 1024 * 1024); // 90 MB D3D12MA::Allocation* alloc; ID3D12Resource* res; hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &alloc, IID_PPV_ARGS(&res)); // Check hr... // Even a large buffer like this, filling 90% of the block, was created as placed! assert(alloc->GetHeap() != NULL); ``` -------------------------------- ### Initialize Allocation Description for Minimum Time Strategy Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html Demonstrates how to set up an ALLOCATION_DESC structure to prioritize minimum allocation time. This involves setting the ALLOCATION_FLAG_STRATEGY_MIN_TIME flag. ```cpp [D3D12MA::ALLOCATION_DESC](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html) allocDesc; allocDesc.[Flags](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a92dec49b788a334fc91c55340dfbace6) = [D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_TIME](namespace_d3_d12_m_a.html#abbad31a7e0b3d09d77f3fb704b77645eaa3ded8847563c24b4522af0586dbd2cb); allocDesc.[HeapType](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#aa46b3c0456e5a23edef3328607ebf4d7) = D3D12_HEAP_TYPE_UPLOAD; allocDesc.[ExtraHeapFlags](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#a97878838f976b2d1e6b1a76881035690) = D3D12_HEAP_FLAG_NONE; allocDesc.[CustomPool](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#ab06b85f3cf3254f855b29264477e3934) = NULL; allocDesc.[pPrivateData](struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_i_o_n___d_e_s_c.html#ac638dd987f1326e2fdab91892d994d35) = NULL; ``` -------------------------------- ### Run GpuMemDumpVis from Command Line Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/tools/GpuMemDumpVis/README.md Launches the visualization tool with input and output file paths. The output format is determined by the output file extension. ```bash python GpuMemDumpVis.py -o OUTPUT_FILE INPUT_FILE ``` -------------------------------- ### D3D12MA Allocation GetOffset Method Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/defragmentation.html Returns the offset in bytes from the start of the memory heap for a given allocation. ```cpp UINT64 GetOffset() const // Returns offset in bytes from the start of memory heap. ``` -------------------------------- ### Get Virtual Block Statistics Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Shows how to retrieve basic statistics of a virtual block, such as used bytes and allocation count. ```cpp D3D12MA::Statistics stats; block->GetStatistics(&stats); printf("My virtual block has %llu bytes used by %u virtual allocations\n", stats.AllocationBytes, stats.AllocationCount); ``` -------------------------------- ### Option to Build Sample Application Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/CMakeLists.txt Configures whether to build the sample application included with D3D12MemoryAllocator. This is off by default. ```cmake option(D3D12MA_BUILD_SAMPLE "Build D3D12MemoryAllocator sample application" OFF) ``` -------------------------------- ### Configure D3D12 Sample Application Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Configures the D3D12 sample application, including source files, shaders, and dependencies. ```cmake set(SHADER_DIR "Shaders") set(D3D12_SAMPLE_SOURCE_FILES Common.cpp Common.h Tests.cpp Tests.h D3D12Sample.cpp ) set(VERTEX_SHADERS "${SHADER_DIR}/VS.hlsl" ) set(PIXEL_SHADERS "${SHADER_DIR}/PS.hlsl" ) set( SHADERS ${VERTEX_SHADERS} ${PIXEL_SHADERS} ) source_group("Resources\\Shaders" FILES ${SHADERS}) set_source_files_properties(${VERTEX_SHADERS} PROPERTIES VS_SHADER_TYPE Vertex VS_SETTINGS "ExcludedFromBuild=true" ) set_source_files_properties( ${PIXEL_SHADERS} PROPERTIES VS_SHADER_TYPE Pixel VS_SETTINGS "ExcludedFromBuild=true" ) add_executable(D3D12Sample ${D3D12_SAMPLE_SOURCE_FILES} ${SHADERS}) add_dependencies(D3D12Sample D3D12MemoryAllocator) ``` -------------------------------- ### Status Message for Sample Build Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/CMakeLists.txt Prints the current value of the D3D12MA_BUILD_SAMPLE option to the console for user information. ```cmake message(STATUS "D3D12MA_BUILD_SAMPLE = ${D3D12MA_BUILD_SAMPLE}") ``` -------------------------------- ### Create a Custom Memory Pool Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/custom_pools.html Demonstrates how to create a custom memory pool using POOL_DESC and the Allocator::CreatePool function. Use D3D12MA_RECOMMENDED_POOL_FLAGS and D3D12MA_RECOMMENDED_HEAP_FLAGS for optimal performance. ```cpp POOL_DESC poolDesc = {}; poolDesc.HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT; poolDesc.Flags = D3D12MA_RECOMMENDED_POOL_FLAGS; poolDesc.HeapFlags = D3D12MA_RECOMMENDED_HEAP_FLAGS | D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; Pool* pool; HRESULT hr = allocator->CreatePool(&poolDesc, &pool); ``` -------------------------------- ### Get Allocation Info and Free Custom Data Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Retrieves allocation information, including custom private data, and demonstrates freeing the associated custom data before freeing the allocation. ```cpp VIRTUAL_ALLOCATION_INFO allocInfo; block->GetAllocationInfo(alloc, &allocInfo); delete (CustomAllocData*)allocInfo.pPrivateData; block->FreeAllocation(alloc); ``` -------------------------------- ### Get Memory Budget and Usage Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/optimal_allocation.html Retrieves the current memory usage and budget for a specific memory segment group. This information can be used to set the available free memory for other systems. ```cpp #include // Assuming 'allocator' is a pointer to a D3D12MA::Allocator object D3D12MA::Budget videoMemBudget = {}; allocator->GetBudget(&videoMemBudget, NULL); UINT64 freeBytes = videoMemBudget.BudgetBytes - videoMemBudget.UsageBytes; gameStreamingSystem->SetAvailableFreeMemory(freeBytes); ``` -------------------------------- ### Visual Studio Specific Settings for D3D12 Sample Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Applies Visual Studio specific build settings, including Unicode definitions, startup project, multithreaded compiling, and debugger working directory. ```cmake if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") # Use Unicode instead of multibyte set add_compile_definitions(UNICODE _UNICODE) # Set VmaSample as startup project set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "D3D12Sample") # Enable multithreaded compiling target_compile_options(D3D12Sample PRIVATE "/MP") # Set working directory for Visual Studio debugger set_target_properties( D3D12Sample PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin" ) endif() ``` -------------------------------- ### Get GPU Memory Budget and Usage Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/statistics.html Retrieves current memory usage and budget for a specific memory segment group. Useful for tracking memory usage and staying within budget. ```C++ #include // Assuming 'allocator' is a pointer to D3D12MA::Allocator D3D12MA::Budget localBudget; allocator->GetBudget(&localBudget, NULL); printf("My GPU memory currently has %u allocations taking %llu B,\n", localBudget.Statistics.AllocationCount, localBudget.Statistics.AllocationBytes); printf("allocated out of %u D3D12 memory heaps taking %llu B,\n", localBudget.Statistics.BlockCount, localBudget.Statistics.BlockBytes); printf("D3D12 reports total usage %llu B with budget %llu B.\n", localBudget.UsageBytes, localBudget.BudgetBytes); ``` -------------------------------- ### Create a Custom Memory Pool Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/optimal_allocation.html Demonstrates creating a custom memory pool with specific heap type and residency priority. Use this when you need fine-grained control over memory allocation for performance-critical resources. ```cpp #include // ... allocator is already created ... D3D12MA::POOL_DESC poolDesc = {}; poolDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; poolDesc.HeapFlags = D3D12MA_RECOMMENDED_HEAP_FLAGS | D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; poolDesc.ResidencyPriority = D3D12_RESIDENCY_PRIORITY_HIGH; D3D12MA::Pool* pool; HRESULT hr = allocator->CreatePool(&poolDesc, &pool); // Check hr... ``` -------------------------------- ### BeginDefragmentation Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_allocator.html Begins the defragmentation process of the default pools. ```APIDOC ## BeginDefragmentation ### Description Begins the defragmentation process of the default pools. ### Method void ### Parameters - **pDesc** (const [DEFRAGMENTATION_DESC](struct_d3_d12_m_a_1_1_d_e_f_r_a_g_m_e_n_t_a_t_i_o_n___d_e_s_c.html) *) - **ppContext** ([DefragmentationContext](class_d3_d12_m_a_1_1_defragmentation_context.html) **) ``` -------------------------------- ### Create Resource with Allocation Description Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This snippet demonstrates how to create a Direct3D 12 resource using the D3D12 Memory Allocator with a custom allocation description. It utilizes helper structs for concise initialization. ```cpp #include #include #include "D3D12MemAlloc.h" // Assume allocator is initialized and valid D3D12MA::ALLOCATOR* allocator; // Example usage: UINT64 myBufSize = 1024 * 1024; // 1MB buffer D3D12MA::ALLOCATION_DESC allocDesc = {}; allocDesc.HeapType = D3D12_HEAP_TYPE_UPLOAD; allocDesc.Flags = D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_TIME; CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer(myBufSize); D3D12MA::Allocation* alloc; ID3D12Resource* res; HRESULT hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &alloc, IID_PPV_ARGS(&res)); // Check hr for success or failure... ``` -------------------------------- ### Begin Defragmentation Process Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_allocator.html Initiates the defragmentation process for default memory pools. Requires a DEFRAGMENTATION_DESC structure to configure the process and returns a DefragmentationContext for management. ```cpp void D3D12MA::Allocator::BeginDefragmentation( const DEFRAGMENTATION_DESC* pDesc, DefragmentationContext** ppContext ) ``` -------------------------------- ### Map and Copy Data to Resource Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This snippet shows how to map a resource to CPU-visible memory, copy data into it using memcpy, and then unmap the resource. This is a common pattern for uploading data to the GPU. ```cpp D3D12_RANGE emptyRange = {0, 0}; void* mappedPtr; hr = resource->Map(0, &emptyRange, &mappedPtr); memcpy(mappedPtr, bufData, bufSize); resource->Unmap(0, NULL); ``` -------------------------------- ### Create Allocator Object Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html Initialize the D3D12MA::ALLOCATOR_DESC structure with your ID3D12Device and adapter, then call D3D12MA::CreateAllocator to create the main allocator object. The D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS are recommended for optimal performance. ```cpp IDXGIAdapter* adapter = ... ID3D12Device* device = ... D3D12MA::ALLOCATOR_DESC allocatorDesc = {}; allocatorDesc.pDevice = device; allocatorDesc.pAdapter = adapter; allocatorDesc.Flags = D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS; D3D12MA::Allocator* allocator; HRESULT hr = D3D12MA::CreateAllocator(&allocatorDesc, &allocator); // Check hr... ``` -------------------------------- ### Create Virtual Block Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Demonstrates how to create a D3D12MA::VirtualBlock object. This object manages a virtual block of memory. You need to specify the total size of the block. ```cpp #include // Example: Create a virtual block of 1MB D3D12MA::VIRTUAL_BLOCK_DESC blockDesc = {}; blockDesc.Size = 1048576; // 1 MB D3D12MA::VirtualBlock* block; HRESULT hr = CreateVirtualBlock(&blockDesc, &block); ``` -------------------------------- ### CVIRTUAL_ALLOCATION_DESC Constructor Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/struct_d3_d12_m_a_1_1_c_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html Initializes a description of a virtual allocation with the specified size, alignment, flags, and private data. ```APIDOC ## CVIRTUAL_ALLOCATION_DESC Constructor ### Description Initializes a description of a virtual allocation with the specified size, alignment, flags, and private data. ### Parameters #### Constructor Parameters - **_size** (UINT64) - The size of the virtual allocation. - **_alignment** (UINT64) - The alignment requirement for the virtual allocation. - **_flags** (VIRTUAL_ALLOCATION_FLAGS) - Flags that control the behavior of the virtual allocation. Defaults to VIRTUAL_ALLOCATION_FLAG_NONE. - **_privateData** (void *) - Optional pointer to private data associated with the allocation. Defaults to NULL. ``` -------------------------------- ### Link Libraries for D3D12 Sample Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Links the D3D12Sample executable against D3D12MemoryAllocator and necessary DirectX libraries. ```cmake target_link_libraries( D3D12Sample PRIVATE D3D12MemoryAllocator PUBLIC d3d12.lib PUBLIC dxgi.lib PUBLIC dxguid.lib PUBLIC Shlwapi.lib ) ``` -------------------------------- ### Basic Resource Creation with D3D12MA Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html This is the simplest use case where an Allocation object is obtained from CreateResource. The Allocation object remembers the ID3D12Resource and holds a reference to it. The resource will be released when allocation->Release() is called. ```cpp HRESULT hr = allocator->CreateResource(&allocationDesc, &resourceDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &allocation, IID_NULL); // Use allocation->GetResource() to get the ID3D12Resource* // Call allocation->Release() to release the resource and its memory. ``` -------------------------------- ### Make Virtual Allocation Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Shows how to make a virtual allocation within a D3D12MA::VirtualBlock. This allocates a region of a specified size within the virtual block. The result is a D3D12MA::VirtualAllocation object. ```cpp #include // Assuming 'block' is a pointer to an existing D3D12MA::VirtualBlock object D3D12MA::VIRTUAL_ALLOCATION_DESC allocDesc = {}; allocDesc.Size = 4096; // 4 KB D3D12MA::VirtualAllocation allocation; HRESULT hr = block->Allocate(&allocDesc, &allocation); ``` -------------------------------- ### Configure D3D12 Agility SDK Path Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Sets the directory for the DirectX 12 Agility SDK and defines options for its preview version. ```cmake set(D3D12MA_AGILITY_SDK_DIRECTORY "" CACHE STRING "Path to unpacked DX12 Agility SDK. Leave empty to compile without it.") option(D3D12MA_AGILITY_SDK_PREVIEW "Set if DX12 Agility SDK is preview version." OFF) ``` -------------------------------- ### Project Definition Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/CMakeLists.txt Defines the project name and version. ```cmake project(D3D12MemoryAllocator VERSION 3.2.0) ``` -------------------------------- ### Allocate with Specific Alignment Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Demonstrates how to allocate memory with a specific alignment requirement using D3D12MA::VIRTUAL_ALLOCATION_DESC. ```cpp D3D12MA::VIRTUAL_ALLOCATION_DESC allocDesc = {}; allocDesc.Size = 4096; // 4 KB allocDesc.Alignment = 4; // Returned offset must be a multiply of 4 B D3D12MA::VirtualAllocation alloc; UINT64 allocOffset; hr = block->Allocate(&allocDesc, &alloc, &allocOffset); ``` -------------------------------- ### D3D12MA_RECOMMENDED_HEAP_FLAGS Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/_d3_d12_mem_alloc_8h.html Recommended heap flags for D3D12MA. ```APIDOC #define D3D12MA_RECOMMENDED_HEAP_FLAGS (D3D12_HEAP_FLAG_NONE) Recommended heap flags for D3D12MA. ``` -------------------------------- ### Set C++ Standard and Extensions for D3D12 Sample Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/src/CMakeLists.txt Configures C++ extensions and standard for the D3D12Sample target, setting it to C++14. ```cmake set_target_properties( D3D12Sample PROPERTIES CXX_EXTENSIONS OFF # Use C++14 CXX_STANDARD 14 CXX_STANDARD_REQUIRED ON ) ``` -------------------------------- ### Release Custom Pool Allocation and Pool Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/custom_pools.html Illustrates the correct order for releasing resources and pools. Allocations must be released before the pool, and the pool must be released before the allocator. ```cpp alloc->Release(); pool->Release(); ``` -------------------------------- ### Allocate a Resource with Specific Flags Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/optimal_allocation.html Shows how to allocate a resource within a specific pool using custom allocation flags. Use this for resources that require specific properties like being committed. ```cpp #include #include // ... allocator and pool are already created ... D3D12MA::ALLOCATION_DESC allocDesc = {}; allocDesc.pPool = pool; allocDesc.Flags = ALLOCATION_FLAG_COMMITTED; CD3DX12_RESOURCE_DESC resDesc = CD3DX12_RESOURCE_DESC::Buffer(1048576); // Requested buffer size. D3D12MA::Allocation* alloc; HRESULT hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, NULL, &alloc, IID_NULL, NULL); // Check hr... ``` -------------------------------- ### CreateResource3 Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions.html Creates a resource using the Allocator with a comprehensive set of parameters. This is the most flexible version for resource creation. ```APIDOC ## CreateResource3 ### Description Creates a resource using the Allocator with a comprehensive set of parameters. This is the most flexible version for resource creation. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly listed in source. ### Response Creates a resource managed by [D3D12MA::Allocator](class_d3_d12_m_a_1_1_allocator.html#ab34796ba12e0aa05f4db80d8be5989a5). ``` -------------------------------- ### BeginDefragmentation() Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions_func.html Initiates the defragmentation process for either an Allocator or a Pool. This function is available in both D3D12MA::Allocator and D3D12MA::Pool classes. ```APIDOC ## BeginDefragmentation() ### Description Begins the defragmentation process. ### Method [Not specified in source] ### Endpoint [Not specified in source] ### Classes D3D12MA::Allocator, D3D12MA::Pool ``` -------------------------------- ### CreateVirtualBlock Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_virtual_block-members.html Creates a new virtual block with the specified description. The created virtual block is returned in ppVirtualBlock. ```APIDOC ## CreateVirtualBlock ### Description Creates a new virtual block with the specified description. The created virtual block is returned in ppVirtualBlock. ### Method Not specified (likely a C++ static method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **pDesc** (const VIRTUAL_BLOCK_DESC *) - Description of the virtual block to create. - **ppVirtualBlock** (VirtualBlock **) - Pointer to a pointer that will be filled with the created VirtualBlock object. ``` -------------------------------- ### Allocate Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_virtual_block-members.html Allocates a block of memory from the virtual block according to the specified description. The allocation is returned in pAllocation and its offset is returned in pOffset. ```APIDOC ## Allocate ### Description Allocates a block of memory from the virtual block according to the specified description. The allocation is returned in pAllocation and its offset is returned in pOffset. ### Method Not specified (likely a C++ method call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **pDesc** (const VIRTUAL_ALLOCATION_DESC *) - Description of the allocation request. - **pAllocation** (VirtualAllocation *) - Pointer to store the resulting virtual allocation. - **pOffset** (UINT64 *) - Pointer to store the offset of the allocated block within the virtual block. ``` -------------------------------- ### Create D3D12 Texture Resource Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/README.md Demonstrates the basic usage of the D3D12 Memory Allocator to create a 2D texture resource. This involves defining the resource description and allocation parameters, then calling the `CreateResource` function. ```cpp D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resourceDesc.Alignment = 0; resourceDesc.Width = 1024; resourceDesc.Height = 1024; resourceDesc.DepthOrArraySize = 1; resourceDesc.MipLevels = 1; resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; D3D12MA::ALLOCATION_DESC allocDesc = {}; allocDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; D3D12Resource* resource; D3D12MA::Allocation* allocation; HRESULT hr = allocator->CreateResource( &allocDesc, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &allocation, IID_PPV_ARGS(&resource)); ``` -------------------------------- ### CreateResource Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_allocator.html Allocates memory and creates a D3D12 resource (buffer or texture). This is the main allocation function, similar to ID3D12Device::CreateCommittedResource. ```APIDOC ## D3D12MA::Allocator::CreateResource ### Description Allocates memory and creates a D3D12 resource (buffer or texture). This is the main allocation function. It may call ID3D12Device::CreatePlacedResource to assign part of a larger, existing memory heap to the new resource. ### Method HRESULT ### Parameters - **_pAllocDesc** (const ALLOCATION_DESC*) - Parameters of the allocation. - **_pResourceDesc** (const D3D12_RESOURCE_DESC*) - Description of the created resource. - **_InitialResourceState** (D3D12_RESOURCE_STATES) - Initial resource state. - **_pOptimizedClearValue** (const D3D12_CLEAR_VALUE*) - Optional. Either null or optimized clear value. - **_ppAllocation** (Allocation**) - Filled with a pointer to the new allocation object created. - **_riidResource** (REFIID) - IID of a resource to be returned via ppvResource. - **_ppvResource** (void**) - Optional. If not null, filled with a pointer to the new resource created. ``` -------------------------------- ### D3D12MA Defragmentation Initialization Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/defragmentation.html Initializes the defragmentation process using D3D12MA::DEFRAGMENTATION_DESC. This snippet sets the algorithm to FAST and begins the defragmentation context. ```cpp D3D12MA::DEFRAGMENTATION_DESC defragDesc = {}; defragDesc.Flags = D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_FAST; D3D12MA::DefragmentationContext* defragCtx; allocator->BeginDefragmentation(&defragDesc, &defragCtx); ``` -------------------------------- ### CVIRTUAL_ALLOCATION_DESC() Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions_func.html Constructor for D3D12MA::CVIRTUAL_ALLOCATION_DESC. ```APIDOC ## CVIRTUAL_ALLOCATION_DESC() ### Description Constructor for CVIRTUAL_ALLOCATION_DESC. ### Method [Not specified in source] ### Endpoint [Not specified in source] ### Struct D3D12MA::CVIRTUAL_ALLOCATION_DESC ``` -------------------------------- ### Allocate Resource from Custom Pool Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/custom_pools.html Shows how to allocate a resource from a previously created custom pool by setting the CustomPool member in ALLOCATION_DESC. Ensure all allocations are released before releasing the pool and the allocator. ```cpp ALLOCATION_DESC allocDesc = {}; allocDesc.CustomPool = pool; D3D12_RESOURCE_DESC resDesc = ... Allocation* alloc; hr = allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, &alloc, IID_NULL, NULL); ``` -------------------------------- ### D3D12MA::CVIRTUAL_ALLOCATION_DESC Constructors Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/struct_d3_d12_m_a_1_1_c_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c-members.html This section details the constructors available for the D3D12MA::CVIRTUAL_ALLOCATION_DESC structure. ```APIDOC ## CVIRTUAL_ALLOCATION_DESC() ### Description Default constructor for D3D12MA::CVIRTUAL_ALLOCATION_DESC. ### Method Constructor ### Parameters None ## CVIRTUAL_ALLOCATION_DESC(const VIRTUAL_ALLOCATION_DESC &o) noexcept ### Description Copy constructor for D3D12MA::CVIRTUAL_ALLOCATION_DESC, taking another VIRTUAL_ALLOCATION_DESC object. ### Method Constructor ### Parameters - **o** (const VIRTUAL_ALLOCATION_DESC &) - The object to copy from. ## CVIRTUAL_ALLOCATION_DESC(UINT64 size, UINT64 alignment, VIRTUAL_ALLOCATION_FLAGS flags=VIRTUAL_ALLOCATION_FLAG_NONE, void *privateData=NULL) noexcept ### Description Constructor for D3D12MA::CVIRTUAL_ALLOCATION_DESC with explicit size, alignment, flags, and private data. ### Method Constructor ### Parameters - **size** (UINT64) - The size of the allocation. - **alignment** (UINT64) - The alignment of the allocation. - **flags** (VIRTUAL_ALLOCATION_FLAGS) - Optional flags for the allocation. Defaults to VIRTUAL_ALLOCATION_FLAG_NONE. - **privateData** (void *) - Optional pointer to private data. Defaults to NULL. ``` -------------------------------- ### Resource Creation with Explicit Resource Pointer Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/quick_start.html Retrieve a pointer to the resource along with the Allocation object. The creation function increases the resource reference counter, so the resource must be released separately before the allocation. ```cpp D3D12MA::Allocation* allocation; ID3D12Resource* resource; HRESULT hr = allocator->CreateResource( &allocationDesc, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &allocation, IID_PPV_ARGS(&resource)); // Use resource... // Release in reverse order of creation: resource->Release(); allocation->Release(); ``` -------------------------------- ### IsTightAlignmentSupported Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/class_d3_d12_m_a_1_1_allocator-members.html Checks if tight alignment is supported on the current system. ```APIDOC ## IsTightAlignmentSupported ### Description Checks if tight alignment is supported on the current system. ### Method IsTightAlignmentSupported ``` -------------------------------- ### CVIRTUAL_ALLOCATION_DESC Constructors Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/struct_d3_d12_m_a_1_1_c_v_i_r_t_u_a_l___a_l_l_o_c_a_t_i_o_n___d_e_s_c.html Provides constructors for the CVIRTUAL_ALLOCATION_DESC struct, allowing for default initialization, initialization from a VIRTUAL_ALLOCATION_DESC structure, or initialization with specific size, alignment, flags, and private data. ```APIDOC ## CVIRTUAL_ALLOCATION_DESC Constructors ### Description Provides constructors for the `D3D12MA::CVIRTUAL_ALLOCATION_DESC` struct. ### Constructors 1. **Default Constructor** * `CVIRTUAL_ALLOCATION_DESC() = default;` * Initializes the structure without specific values, leaving it uninitialized. 2. **Copy Constructor from VIRTUAL_ALLOCATION_DESC** * `CVIRTUAL_ALLOCATION_DESC(const VIRTUAL_ALLOCATION_DESC &o) noexcept;` * Initializes the structure from an existing `D3D12MA::VIRTUAL_ALLOCATION_DESC` object. 3. **Parameterized Constructor** * `CVIRTUAL_ALLOCATION_DESC(UINT64 size, UINT64 alignment, VIRTUAL_ALLOCATION_FLAGS flags = VIRTUAL_ALLOCATION_FLAG_NONE, void *privateData = NULL) noexcept;` * Initializes the virtual allocation description with the specified size, alignment, flags, and optional private data. ``` -------------------------------- ### CVIRTUAL_BLOCK_DESC() Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions_func.html Constructor for D3D12MA::CVIRTUAL_BLOCK_DESC. ```APIDOC ## CVIRTUAL_BLOCK_DESC() ### Description Constructor for CVIRTUAL_BLOCK_DESC. ### Method [Not specified in source] ### Endpoint [Not specified in source] ### Struct D3D12MA::CVIRTUAL_BLOCK_DESC ``` -------------------------------- ### Allocate Memory with VirtualBlock Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/virtual_allocator.html Allocates a virtual memory block using VirtualBlock::Allocate. Check the return HRESULT for success or failure. ```cpp D3D12MA::VirtualAllocation alloc; UINT64 allocOffset; hr = block->Allocate(&allocDesc, &alloc, &allocOffset); if(SUCCEEDED(hr)) { // Use the 4 KB of your memory starting at allocOffset. } else { // Allocation failed - no space for it could be found. Handle this error! } ``` -------------------------------- ### CreateResource Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions.html Creates a resource using the Allocator. This function handles the allocation of memory for the resource. ```APIDOC ## CreateResource ### Description Creates a resource using the Allocator. This function handles the allocation of memory for the resource. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly listed in source. ### Response Creates a resource managed by [D3D12MA::Allocator](class_d3_d12_m_a_1_1_allocator.html#aa37d6b9fe8ea0864f7a35b9d68e8345a). ``` -------------------------------- ### CVIRTUAL_BLOCK_DESC Constructors Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/struct_d3_d12_m_a_1_1_c_v_i_r_t_u_a_l___b_l_o_c_k___d_e_s_c.html Provides constructors for the CVIRTUAL_BLOCK_DESC struct, including a default constructor, a constructor initializing from a VIRTUAL_BLOCK_DESC, and a constructor initializing with size, flags, and allocation callbacks. ```APIDOC ## CVIRTUAL_BLOCK_DESC() ### Description Default constructor. Leaves the structure uninitialized. ### Method Constructor ## CVIRTUAL_BLOCK_DESC(const VIRTUAL_BLOCK_DESC &o) ### Description Constructor initializing from the base D3D12MA::VIRTUAL_BLOCK_DESC structure. ### Method Constructor ## CVIRTUAL_BLOCK_DESC(UINT64 size, VIRTUAL_BLOCK_FLAGS flags=VIRTUAL_BLOCK_FLAG_NONE, const ALLOCATION_CALLBACKS *allocationCallbacks=NULL) ### Description Constructor initializing description of a virtual block with given parameters. ### Parameters #### Path Parameters - **size** (UINT64) - Required - The total size of the block. - **flags** (VIRTUAL_BLOCK_FLAGS) - Optional - Flags for the virtual block. Defaults to VIRTUAL_BLOCK_FLAG_NONE. - **allocationCallbacks** (const ALLOCATION_CALLBACKS *) - Optional - Custom CPU memory allocation callbacks. Defaults to NULL. ### Method Constructor ``` -------------------------------- ### BeginPass() Source: https://github.com/gpuopen-librariesandsdks/d3d12memoryallocator/blob/master/docs/html/functions_func.html Marks the beginning of a defragmentation pass within a DefragmentationContext. This function is part of the DefragmentationContext class. ```APIDOC ## BeginPass() ### Description Marks the beginning of a defragmentation pass. ### Method [Not specified in source] ### Endpoint [Not specified in source] ### Class D3D12MA::DefragmentationContext ```