# ���� gpu-allocator
[![Actions Status](https://img.shields.io/github/actions/workflow/status/Traverse-Research/gpu-allocator/ci.yml?branch=main&logo=github)](https://github.com/Traverse-Research/gpu-allocator/actions)
[![Latest version](https://img.shields.io/crates/v/gpu-allocator.svg?logo=rust)](https://crates.io/crates/gpu-allocator)
[![Docs](https://img.shields.io/docsrs/gpu-allocator?logo=docs.rs)](https://docs.rs/gpu-allocator/)
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE-MIT)
[![LICENSE](https://img.shields.io/badge/license-apache-blue.svg?logo=apache)](LICENSE-APACHE)
[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../main/CODE_OF_CONDUCT.md)
[![MSRV](https://img.shields.io/badge/rustc-1.70.0+-ab6000.svg)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)
[![Banner](banner.png)](https://traverseresearch.nl)
```toml
[dependencies]
gpu-allocator = "0.27.0"
```
![Visualizer](visualizer.png)
This crate provides a fully written in Rust memory allocator for Vulkan, DirectX 12 and Metal.
## [Windows-rs] and [winapi]
`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.
[Windows-rs]: https://github.com/microsoft/windows-rs
[winapi]: https://github.com/retep998/winapi-rs
## Setting up the Vulkan memory allocator
```rust
use gpu_allocator::vulkan::*;
let mut allocator = Allocator::new(&AllocatorCreateDesc {
instance,
device,
physical_device,
debug_settings: Default::default(),
buffer_device_address: true, // Ideally, check the BufferDeviceAddressFeatures struct.
allocation_sizes: Default::default(),
});
```
## Simple Vulkan allocation example
```rust
use gpu_allocator::vulkan::*;
use gpu_allocator::MemoryLocation;
// Setup vulkan info
let vk_info = vk::BufferCreateInfo::default()
.size(512)
.usage(vk::BufferUsageFlags::STORAGE_BUFFER);
let buffer = unsafe { device.create_buffer(&vk_info, None) }.unwrap();
let requirements = unsafe { device.get_buffer_memory_requirements(buffer) };
let allocation = allocator
.allocate(&AllocationCreateDesc {
name: "Example allocation",
requirements,
location: MemoryLocation::CpuToGpu,
linear: true, // Buffers are always linear
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
}).unwrap();
// Bind memory to the buffer
unsafe { device.bind_buffer_memory(buffer, allocation.memory(), allocation.offset()).unwrap() };
// Cleanup
allocator.free(allocation).unwrap();
unsafe { device.destroy_buffer(buffer, None) };
```
## Setting up the D3D12 memory allocator
```rust
use gpu_allocator::d3d12::*;
let mut allocator = Allocator::new(&AllocatorCreateDesc {
device: ID3D12DeviceVersion::Device(device),
debug_settings: Default::default(),
allocation_sizes: Default::default(),
});
```
## Simple d3d12 allocation example
```rust
use gpu_allocator::d3d12::*;
use gpu_allocator::MemoryLocation;
let buffer_desc = Direct3D12::D3D12_RESOURCE_DESC {
Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER,
Alignment: 0,
Width: 512,
Height: 1,
DepthOrArraySize: 1,
MipLevels: 1,
Format: Dxgi::Common::DXGI_FORMAT_UNKNOWN,
SampleDesc: Dxgi::Common::DXGI_SAMPLE_DESC {
Count: 1,
Quality: 0,
},
Layout: Direct3D12::D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
Flags: Direct3D12::D3D12_RESOURCE_FLAG_NONE,
};
let allocation_desc = AllocationCreateDesc::from_d3d12_resource_desc(
&allocator.device(),
&buffer_desc,
"Example allocation",
MemoryLocation::GpuOnly,
);
let allocation = allocator.allocate(&allocation_desc).unwrap();
let mut resource: Option<Direct3D12::ID3D12Resource> = None;
let hr = unsafe {
device.CreatePlacedResource(
allocation.heap(),
allocation.offset(),
&buffer_desc,
Direct3D12::D3D12_RESOURCE_STATE_COMMON,
None,
&mut resource,
)
}?;
// Cleanup
drop(resource);
allocator.free(allocation).unwrap();
```
## Setting up the Metal memory allocator
```rust
use gpu_allocator::metal::*;
let mut allocator = Allocator::new(&AllocatorCreateDesc {
device: device.clone(),
debug_settings: Default::default(),
allocation_sizes: Default::default(),
});
```
## Simple Metal allocation example
```rust
use gpu_allocator::metal::*;
use gpu_allocator::MemoryLocation;
let allocation_desc = AllocationCreateDesc::buffer(
&device,
"Example allocation",
512, // size in bytes
MemoryLocation::GpuOnly,
);
let allocation = allocator.allocate(&allocation_desc).unwrap();
let resource = allocation.make_buffer().unwrap();
// Cleanup
drop(resource);
allocator.free(&allocation).unwrap();
```
## Minimum Supported Rust Version
The MSRV for this crate and the `vulkan`, `d3d12` and `metal` features is Rust 1.70. Any other features such as the `visualizer` (with all the `egui` dependencies) may have a higher requirement and are not tested in our CI.
## License
Licensed under either of
- Apache License, Version 2.0, ([LICENSE-APACHE](../master/LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](../master/LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
## Alternative libraries
- [vk-mem-rs](https://github.com/gwihlidal/vk-mem-rs)
## Contribution
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.
没有合适的资源?快使用搜索试试~ 我知道了~
Vulkan、DirectX 12 和 Metal 的 GPU 内存分配器 用纯 Rust 编写.zip
共37个文件
rs:20个
toml:3个
yml:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 16 浏览量
2024-11-27
14:48:15
上传
评论
收藏 3.28MB ZIP 举报
温馨提示
gpu 分配器 [dependencies]gpu-allocator = "0.27.0"该板条箱为 Vulkan、DirectX 12 和 Metal 提供了完全用 Rust 编写的内存分配器。Windows-rs和winapigpu-allocator最近从winapi迁移到windows-rs,但仍然提供方便的助手来转换为winapi类型,在使用public-winapicrate 功能进行编译时启用。设置 Vulkan 内存分配器use gpu_allocator::vulkan::*;let mut allocator = Allocator::new(&AllocatorCreateDesc { instance, device, physical_device, debug_settings: Default::default(), buffer_device_address: true, // Ideally, check the BufferDeviceAddressFeature
资源推荐
资源详情
资源评论
收起资源包目录
Vulkan、DirectX 12 和 Metal 的 GPU 内存分配器。用纯 Rust 编写.zip (37个子文件)
Cargo.toml 3KB
.mailmap 155B
banner.png 21KB
.github
dependabot.yml 201B
workflows
ci.yml 3KB
publish.yaml 294B
标签.txt 34B
src
d3d12
mod.rs 41KB
visualizer.rs 9KB
result.rs 879B
lib.rs 11KB
allocator
free_list_allocator
mod.rs 13KB
visualizer.rs 789B
dedicated_block_allocator
mod.rs 3KB
visualizer.rs 237B
mod.rs 5KB
metal
mod.rs 18KB
visualizer.rs 7KB
visualizer
mod.rs 2KB
allocation_reports.rs 5KB
memory_chunks.rs 5KB
vulkan
mod.rs 36KB
visualizer.rs 8KB
.cargo
config.toml 3KB
examples
d3d12-buffer.rs 10KB
vulkan-buffer.rs 7KB
metal-buffer.rs 4KB
d3d12-buffer-winrs.rs 8KB
LICENSE-MIT 1KB
CODE_OF_CONDUCT.md 3KB
release.toml 402B
资源内容.txt 661B
.gitignore 371B
README.md 6KB
README.tpl 2KB
LICENSE-APACHE 11KB
visualizer.png 3.22MB
共 37 条
- 1
资源评论
赵闪闪168
- 粉丝: 1564
- 资源: 3662
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 一个简单的 Universal Directx 11 Hook 来启动 ImGui.zip
- django-intro-readthedocs-io-en-latest.pdf
- AndroidAnimationDrawable帧动画的实现
- 安卓大作业 记账应用Kotlin.zip
- 基于rk3588的drm例子modeset-single-buffer
- 006-基于LED数码管的矩阵键值显示.rar
- Springboot+ChatGLM 实战AI数字人面试官系统完结14章
- Few-Shot Learning with Representative Global Prototype
- 005-基于LED数码管的数码秒表.rar
- 一个简单、直接、超薄的 CLR 库,用于高性能 Win32 Native Interop.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功