{"id":13672187,"url":"https://github.com/Traverse-Research/gpu-allocator","last_synced_at":"2025-04-27T21:32:23.015Z","repository":{"id":37806812,"uuid":"309704407","full_name":"Traverse-Research/gpu-allocator","owner":"Traverse-Research","description":"🦀 GPU memory allocator for Vulkan, DirectX 12 and Metal. Written in pure Rust","archived":false,"fork":false,"pushed_at":"2024-10-15T12:44:11.000Z","size":11700,"stargazers_count":379,"open_issues_count":31,"forks_count":51,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-10-31T11:27:22.636Z","etag":null,"topics":["allocator","dx12","metal","vulkan"],"latest_commit_sha":null,"homepage":"https://traverse.nl/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Traverse-Research.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-11-03T14:03:27.000Z","updated_at":"2024-10-24T11:03:01.000Z","dependencies_parsed_at":"2023-11-07T00:21:42.416Z","dependency_job_id":"95790964-dd48-41fd-9641-250481b7874a","html_url":"https://github.com/Traverse-Research/gpu-allocator","commit_stats":{"total_commits":189,"total_committers":17,"mean_commits":"11.117647058823529","dds":0.6984126984126984,"last_synced_commit":"1800231a31147f1d0d2774536ceaa251b5f72aa4"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traverse-Research%2Fgpu-allocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traverse-Research%2Fgpu-allocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traverse-Research%2Fgpu-allocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traverse-Research%2Fgpu-allocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Traverse-Research","download_url":"https://codeload.github.com/Traverse-Research/gpu-allocator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224087166,"owners_count":17253514,"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":["allocator","dx12","metal","vulkan"],"created_at":"2024-08-02T09:01:28.651Z","updated_at":"2025-04-27T21:32:23.010Z","avatar_url":"https://github.com/Traverse-Research.png","language":"Rust","funding_links":[],"categories":["Libraries \u0026 Frameworks:","Rust","Miscellaneous"],"sub_categories":["Graphics"],"readme":"# 📒 gpu-allocator\n\n[![Actions Status](https://img.shields.io/github/actions/workflow/status/Traverse-Research/gpu-allocator/ci.yml?branch=main\u0026logo=github)](https://github.com/Traverse-Research/gpu-allocator/actions)\n[![Latest version](https://img.shields.io/crates/v/gpu-allocator.svg?logo=rust)](https://crates.io/crates/gpu-allocator)\n[![Docs](https://img.shields.io/docsrs/gpu-allocator?logo=docs.rs)](https://docs.rs/gpu-allocator/)\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)\n[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg?logo=apache)](LICENSE-APACHE)\n[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)\n[![MSRV](https://img.shields.io/badge/rustc-1.71.0+-ab6000.svg)](https://blog.rust-lang.org/2023/07/13/Rust-1.71.0.html)\n\n[![Banner](banner.png)](https://traverseresearch.nl)\n\n```toml\n[dependencies]\ngpu-allocator = \"0.27.0\"\n```\n\n![Visualizer](visualizer.png)\n\nThis crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal.\n\n## [Windows-rs] and [winapi]\n\n`gpu-allocator` recently migrated from [winapi] to [windows-rs] but still provides convenient helpers to convert to and from [winapi] types, enabled when compiling with the `public-winapi` crate feature.\n\n[Windows-rs]: https://github.com/microsoft/windows-rs\n[winapi]: https://github.com/retep998/winapi-rs\n\n## Setting up the Vulkan memory allocator\n\n```rust\nuse gpu_allocator::vulkan::*;\n\nlet mut allocator = Allocator::new(\u0026AllocatorCreateDesc {\n    instance,\n    device,\n    physical_device,\n    debug_settings: Default::default(),\n    buffer_device_address: true,  // Ideally, check the BufferDeviceAddressFeatures struct.\n    allocation_sizes: Default::default(),\n});\n```\n\n## Simple Vulkan allocation example\n\n```rust\nuse gpu_allocator::vulkan::*;\nuse gpu_allocator::MemoryLocation;\n\n// Setup vulkan info\nlet vk_info = vk::BufferCreateInfo::default()\n    .size(512)\n    .usage(vk::BufferUsageFlags::STORAGE_BUFFER);\n\nlet buffer = unsafe { device.create_buffer(\u0026vk_info, None) }.unwrap();\nlet requirements = unsafe { device.get_buffer_memory_requirements(buffer) };\n\nlet allocation = allocator\n    .allocate(\u0026AllocationCreateDesc {\n        name: \"Example allocation\",\n        requirements,\n        location: MemoryLocation::CpuToGpu,\n        linear: true, // Buffers are always linear\n        allocation_scheme: AllocationScheme::GpuAllocatorManaged,\n    }).unwrap();\n\n// Bind memory to the buffer\nunsafe { device.bind_buffer_memory(buffer, allocation.memory(), allocation.offset()).unwrap() };\n\n// Cleanup\nallocator.free(allocation).unwrap();\nunsafe { device.destroy_buffer(buffer, None) };\n```\n\n## Setting up the D3D12 memory allocator\n\n```rust\nuse gpu_allocator::d3d12::*;\n\nlet mut allocator = Allocator::new(\u0026AllocatorCreateDesc {\n    device: ID3D12DeviceVersion::Device(device),\n    debug_settings: Default::default(),\n    allocation_sizes: Default::default(),\n});\n```\n\n## Simple d3d12 allocation example\n\n```rust\nuse gpu_allocator::d3d12::*;\nuse gpu_allocator::MemoryLocation;\n\n\nlet buffer_desc = Direct3D12::D3D12_RESOURCE_DESC {\n    Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER,\n    Alignment: 0,\n    Width: 512,\n    Height: 1,\n    DepthOrArraySize: 1,\n    MipLevels: 1,\n    Format: Dxgi::Common::DXGI_FORMAT_UNKNOWN,\n    SampleDesc: Dxgi::Common::DXGI_SAMPLE_DESC {\n        Count: 1,\n        Quality: 0,\n    },\n    Layout: Direct3D12::D3D12_TEXTURE_LAYOUT_ROW_MAJOR,\n    Flags: Direct3D12::D3D12_RESOURCE_FLAG_NONE,\n};\nlet allocation_desc = AllocationCreateDesc::from_d3d12_resource_desc(\n    \u0026allocator.device(),\n    \u0026buffer_desc,\n    \"Example allocation\",\n    MemoryLocation::GpuOnly,\n);\nlet allocation = allocator.allocate(\u0026allocation_desc).unwrap();\nlet mut resource: Option\u003cDirect3D12::ID3D12Resource\u003e = None;\nlet hr = unsafe {\n    device.CreatePlacedResource(\n        allocation.heap(),\n        allocation.offset(),\n        \u0026buffer_desc,\n        Direct3D12::D3D12_RESOURCE_STATE_COMMON,\n        None,\n        \u0026mut resource,\n    )\n}?;\n\n// Cleanup\ndrop(resource);\nallocator.free(allocation).unwrap();\n```\n\n## Setting up the Metal memory allocator\n\n```rust\nuse gpu_allocator::metal::*;\nlet mut allocator = Allocator::new(\u0026AllocatorCreateDesc {\n    device: device.clone(),\n    debug_settings: Default::default(),\n    allocation_sizes: Default::default(),\n});\n```\n\n## Simple Metal allocation example\n```rust\nuse gpu_allocator::metal::*;\nuse gpu_allocator::MemoryLocation;\nlet allocation_desc = AllocationCreateDesc::buffer(\n    \u0026device,\n    \"Example allocation\",\n    512, // size in bytes\n    MemoryLocation::GpuOnly,\n);\nlet allocation = allocator.allocate(\u0026allocation_desc).unwrap();\nlet heap = unsafe { allocation.heap() };\nlet resource = unsafe {\n    heap.newBufferWithLength_options_offset(\n        allocation.size() as usize,\n        heap.resourceOptions(),\n        allocation.offset() as usize,\n    )\n}\n.unwrap();\n\n// Cleanup\ndrop(resource);\nallocator.free(\u0026allocation).unwrap();\n```\n\n## Minimum Supported Rust Version\n\nThe MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.71.  Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0, ([LICENSE-APACHE](../master/LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](../master/LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Alternative libraries\n\n- [vk-mem-rs](https://github.com/gwihlidal/vk-mem-rs)\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms or\nconditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTraverse-Research%2Fgpu-allocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTraverse-Research%2Fgpu-allocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTraverse-Research%2Fgpu-allocator/lists"}