-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change MemoryDevice::map/unmap_memory #34
Conversation
Now those methods require &mut M e.g. externally synchronized memory object Fixes #33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, if this doesn't look wonderful, then I don't know what does!
Great work on addressing the API concern!
I noted a few things to improve, overall very happy with the code. Looking forward to see it released soon on crates :)
core::{ | ||
convert::TryFrom as _, | ||
ptr::{copy_nonoverlapping, NonNull}, | ||
sync::atomic::{AtomicU8, Ordering::*}, | ||
// sync::atomic::{AtomicU8, Ordering::*}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line needs to be removed
@@ -158,37 +159,33 @@ impl<M> MemoryBlock<M> { | |||
"`offset + size` is out of memory block bounds" | |||
); | |||
|
|||
let ptr = match self.flavor { | |||
MemoryBlockFlavor::Dedicated => { | |||
let ptr = match &mut self.flavor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, in gfx/wgpu code we prefer to not match on references. It's your call here, so no objections, just fyi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And use ref
and ref mut
in patterns? As I understand it, the semantics is the same. Just choice of style and MSRV
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. My preference is to make this explicit at the match pattern side, i.e. knowing the type being matched it's easier to see what is referenced, how deep, what's moved, or copied otherwise, based on those ref
.
@@ -370,3 +318,21 @@ impl<M> MemoryBlock<M> { | |||
self.props.contains(MemoryPropertyFlags::HOST_CACHED) | |||
} | |||
} | |||
|
|||
fn acquire_mapping(mapped: &mut bool) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could probably be merged with release_mapping
into something like switch_mapping(mapped: &mut bool, to: bool) -> bool
"All blocks must be deallocated before cleanup" | ||
); | ||
device.deallocate_memory(chunk.memory); | ||
|
||
match Arc::try_unwrap(chunk.memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's redundant to call is_unique
only to follow by try_unwrap
. They do the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent was to panic in debug here and merely whining into traces in release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can still do this without is_unique
, can't you?
Err(_) => {
debug_assert!(false, "All blocks must be deallocated before cleanup"),
#[cfg(feature = "tracing")]
tracing::error!("Cleanup before all memory blocks are deallocated");
}
``
gpu-alloc/src/linear.rs
Outdated
if chunk.allocated == 0 { | ||
drop(block); | ||
|
||
if is_unique(&mut chunk.memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also do Arc::get_mut
here and scrap is_unique
completely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arc::get_mut
costs more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting indeed. It does the atomics on the weak count, which you don't want to, reasonably.
You'd need to make it so the debug_assert
code inside is_unique
doesn't run in optimized builds. Otherwise, as the PR stands, it also calls get_mut
internally, anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, debug_assert
code does not run in optimized builds by definition of debug_assert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it runs, it just doesn't panic. That's one of the weird things I stumbled upon back in the day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. It doesn't run, but compiles.
debug_assert!(expr)
expands to if cfg!(debug_assertions) { assert!(expr); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, indeed! I got confused here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about the type checks (i.e. using something that's under #[cfg(debug_assertions)]
is not possible in there), not run-time, so that was my confusion. Thank you for correcting me!
1160: Update gpu-alloc and remove the associated locking r=kvark a=kvark **Connections** Takes advantage of zakarumych/gpu-alloc#34 **Description** This PR removes the locking from our gpu-alloc wrapper. **Testing** Untested Co-authored-by: Dzmitry Malyshau <[email protected]>
Now those methods require &mut M
e.g. externally synchronized memory object
Fixes #33