Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 21, 2023. It is now read-only.
/gfx-memoryPublic archive

[DEPRECATED] Memory management library of gfx_hal

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

gfx-rs/gfx-memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is discontinued in favor ofrendy.

gfx-memory - graphics memory management for gfx-hal.

Build StatusDocsCrates.io

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.

Example

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 ofDevice must be used for allocating and freeing blocks.

Violating those rules may cause undefined behaviour.

License

Licensed under either of

at your option.

Contribution

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

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp