gpu-alloc
gpu-alloc copied to clipboard
Sessioned reads and writes
It would be very useful to do multiple reads/writes in a single mapping session. Currently, write_bytes and read_bytes are limited to exactly one request. Case in question: laying out texture data into the staging buffer, it needs to be done row by row to respect the alignment of the target API.
In this case you can use map and unmap functions.
Sure, this isn't a blocker. However, doing map/unmap manually also requires handling the flush/invalidation for non-coherent memory, which is tedious. A session-based reader/writer would strictly be better in this case.
How about function that takes a closure in which reads and/or writes are available?
That would be inferior to RAII. Are you concerned about safety guarantees when doing this, so that closure helps you to preserve them? I think there are no guarantees here for the most part, so no need to try restricting the users too much.
I try to guarantee that memory gets unmapped. To prevent attempts to map memory when it's already mapped.
Drop impls may not run, so with RAII approach it would be necessary to flip mapped field to true and then back to false in Drop impl for returned guard, along with actual unmapping. This would require &mut self function.
With closure I can almost certainly guarantee unmapping to happen unless process is aborted, so mapped will be only checked and it will be &self function.
Mapping is already &mut self, so I'm not sure why you are concerned about it?