- Notifications
You must be signed in to change notification settings - Fork7
[DEPRECATED] Memory management library of gfx_hal
License
Apache-2.0, MIT licenses found
Licenses found
gfx-rs/gfx-memory
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project is discontinued in favor ofrendy.
This crate provides tools to manage GPU memory provided bygfx-hal.
The main tool is theMemoryAllocator trait, which can be used to allocateBlocks of memory.The most notableMemoryAllocator implementation isSmartAllocator which can be used as-is.All other allocators in this crate are used internally inSmartAllocator, but are also exposedfor users who want to create their own implementations in caseSmartAllocator don't satisfy their needs.
AFactory is also provided, that wraps the allocation logic in this crate, along with creation of memory resourceson aDevice (such asBuffer orImage). For most use cases, theFactory provides all capabilities needed tomanage memory based resources on agfx_hal::Device.
Simple example of usingSmartAllocator to create a vertexBuffer:
externcrate gfx_hal;externcrate gfx_memory;use std::error::Error;use gfx_hal::{Backend,Device};use gfx_hal::buffer::Usage;use gfx_hal::memory::Properties;use gfx_memory::{MemoryAllocator,SmartAllocator,Type,Block};typeSmartBlock<B> = <SmartAllocator<B>asMemoryAllocator<B>>::Block;fnmake_vertex_buffer<B:Backend>(device:&B::Device,allocator:&mutSmartAllocator<B>,size:u64,) ->Result<(SmartBlock<B>,B::Buffer),Box<Error>>{// Create unbounded buffer object. It has no memory assigned.letmut buf =unsafe{ device.create_buffer(size,Usage::VERTEX).map_err(Box::new)?};// Get memory requirements for the buffer.let reqs =unsafe{ device.get_buffer_requirements(&buf)};// Allocate block of device-local memory that satisfy requirements for buffer.let block =unsafe{ allocator.alloc(device,(Type::General,Properties::DEVICE_LOCAL), reqs).map_err(Box::new)?};// Bind memory block to the buffer.Ok(unsafe{ device.bind_buffer_memory(block.memory(), block.range().start,&mut buf).map(|buffer|(block, buffer)).map_err(Box::new)?})}
This crate is mid-level and it requires the user to follow a few simple rules:
- When memory blocks are to be freed, they must be returned to the allocator they were allocated from.
- The same instance of
Devicemust be used for allocating and freeing blocks.
Violating those rules may cause undefined behaviour.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT orhttp://opensource.org/licenses/MIT)
at your option.
We are a community project that welcomes contribution from anyone. If you're interested in helping out, you can contactus either through GitHub, or viagitter.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without anyadditional terms or conditions.
About
[DEPRECATED] Memory management library of gfx_hal
Topics
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.