zakarumych / gpu-alloc

Implementation agnostic memory allocator for Vulkan-like APIs
Other
86 stars 18 forks source link

make GpuAllocator's public methods' call sites more concise #65

Closed nerditation closed 7 months ago

nerditation commented 2 years ago

previously caller need to explicitly wrap the backend type (ash::Device or erupt::DeviceLoader), which is verbose and tedious:

let device: ash::Device;
let mut allocator: gpu_alloc::GpuAllocator<vk::DeviceMemory>;
//...
allocator.cleanup(gpu_alloc::AshMemoryDevice::wrap(&device));

by change the generic parameter type to impl AsRef<MD> where MD: MemoryDevice<M>, and by adding impls for the appropriate backend wrapper types, the call site is much more concise:

let device: ash::Device;
let mut allocator: gpu_alloc::GpuAllocator<vk::DeviceMemory>;
//...
allocator.cleanup(&device);
nerditation commented 2 years ago

I just add the implementation, some examples and documentation are definitely needed, but I hesitate to make changes to the docs because I can't phrase it properly. feel free to make edit or suggest. thanks.

also, I tried to make it compatible to existing caller code, but more testing is needed to confirm.

nerditation commented 2 years ago

because I had just used the ash backend before, I overlooked the "mock" backend. I also forgot the MemoryBlock public api. sections are added to the ash and erupt examples.

nerditation commented 2 years ago

just found out, the example snippets inside the backend crate level documentation (i.e. the doc-comments in gpu-alloc-ash/src/lib.rs and gpu-alloc-erupt/src/lib.rs) is the exact same code in the "examples" crate. should we replicate the change in the "examples" crate for the docs, or should we instead replace the code snippet in the doc with a link to the "examples" crate?

I see the gpu-alloc-basic-example crate is not published, so the link would have to be pointing to the github repo instead of crates.io or docs.rs?

nerditation commented 1 year ago

sorry for the long delay, I've moved away since last time I dealt with GPU related project. is this change still relevant? shall we finish it? @zakarumych

zakarumych commented 7 months ago

How am I failed to see this?

Looks good to me.