-
Notifications
You must be signed in to change notification settings - Fork 956
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
Validate bind group layouts by value #400
Validate bind group layouts by value #400
Conversation
d2b935f
to
20bda02
Compare
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.
Thank you for the PR!
Here is an idea on how we can implement this better.
wgpu-core/src/command/bind.rs
Outdated
}) if layout_id == bind_group_layout_id => { | ||
LayoutChange::Match(group_id.value, &self.dynamic_offsets) | ||
}) => { | ||
if layout_id == bind_group_layout_id { |
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 think we can do even better than this. What if we resolve the duplicate layouts earlier, in create_bind_group_layout
? If we see that a layout with the same content already exists, we can just return the same ID. This means we'd always be able to compare by ID.
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.
Nice! I'll give it a shot in the coming days 👍
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.
Thanks! And sorry for coming up with this late. I had a feeling that we were missing something, but didn't realize what it was until now 😅
20bda02
to
77b5a86
Compare
Alright, the changes you requested have some really nice properties: all the work is done at init time and the code is much simpler too 👍 Couple of caveats:
|
@@ -1182,6 +1182,15 @@ impl<F: IdentityFilter<BindGroupLayoutId>> Global<F> { | |||
let hub = B::hub(self); | |||
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) }; | |||
|
|||
{ | |||
let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token); |
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.
let's add a //TODO: figure out if
bindings order matters
wgpu-core/src/device.rs
Outdated
@@ -1182,6 +1182,15 @@ impl<F: IdentityFilter<BindGroupLayoutId>> Global<F> { | |||
let hub = B::hub(self); | |||
let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) }; | |||
|
|||
{ | |||
let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token); | |||
for (id, value) in bind_group_layout_guard.iter() { |
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.
let's use bind_group_layout_guard.iter().any(|| {..})
wgpu-core/src/hub.rs
Outdated
@@ -89,55 +89,67 @@ impl IdentityManager { | |||
#[derive(Debug)] | |||
pub struct Storage<T, I: TypedId> { | |||
//TODO: consider concurrent hashmap? | |||
map: VecMap<(T, Epoch)>, | |||
map: VecMap<(T, Epoch, Backend)>, |
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.
this is unexpected, why do we need to add the backend here?
Each storage, conceptually, only stores things for the same backend. There can't be two different indices of that map with different backends.
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.
Okay, I thought as much, but good to know! I will have to figure out a way to produce the TypedId
for the iterator (need a backend to zip
the TypedId
), but maybe I can just pass the backend to iter()
...
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.
Thank you!
bors r+
400: Validate bind group layouts by value r=kvark a=yanchith This PR widens the comparisons done between two bind group layouts to also consider them equivalent if their vectors of `BindGroupLayoutBinding`s are equal. Tested on various modifications of the cube example from wgpu-rs. https://gist.github.com/yanchith/56e15fe35658b14587ff9bfcbd53116f Fixes #335 Co-authored-by: yanchith <yanchi.toth@gmail.com>
You are right that we'll have an issue with deleting the bind groups, and that's something we need to have sooner rather than later. |
bors r- |
Canceled |
@yanchith can we please store the bindings in a map instead of a vec (i.e. binding number -> value)? we want to make sure the contents of the bindings match by value regardless of the order they are specified. |
No prob, I'll get to it tomorrow 👍
Do we want to tackle this now, or once we allow deleting bind group layouts? |
Everything that can be deleted is supposed to be refcounted internally, including the bind group layouts. |
8d96012
to
659abe7
Compare
Done as you requested. There is a caveat now, documented in a TODO I added. We can easily avoid it at the cost of allocating a hashmap that we possibly might throw away right after. |
wgpu-core/src/device.rs
Outdated
@@ -1203,7 +1230,7 @@ impl<F: IdentityFilter<BindGroupLayoutId>> Global<F> { | |||
|
|||
let layout = binding_model::BindGroupLayout { | |||
raw, | |||
bindings: bindings.to_vec(), | |||
bindings: bindings.iter().cloned().map(|b| (b.binding, b)).collect(), |
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.
This is the allocation that we can move up to simplify the comparison and also make it more correct. But we may end up not using it.
659abe7
to
6da253d
Compare
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.
Thank you! Let's go one more step, and we'll be golden
wgpu-core/src/device.rs
Outdated
bind_group_layout_guard | ||
.iter(device_id.backend()) | ||
.find(|(_, bgl)| { | ||
bindings.len() == bgl.bindings.len() |
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.
ok, I see what you did here. Let's move the hashmap creation early and just compare hashmaps here directly. The code would be simpler, and bind group layout creation is not a place that needs optimization - throwing away the hashmap is fine.
To make later bind group layout compatibility checks simpler (and cheaper), deduplicate them on creation. If two bind group layouts with same descriptors are requested, only one is created and the same id is returned for both.
6da253d
to
e9545c9
Compare
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.
Thank you!
bors r+
400: Validate bind group layouts by value r=kvark a=yanchith This PR widens the comparisons done between two bind group layouts to also consider them equivalent if their vectors of `BindGroupLayoutBinding`s are equal. Tested on various modifications of the cube example from wgpu-rs. https://gist.github.com/yanchith/56e15fe35658b14587ff9bfcbd53116f Fixes #335 Co-authored-by: yanchith <yanchi.toth@gmail.com>
Build succeeded |
Sorry it took us long, and congrats on your contribution! |
No prob, happy to help again in the future! |
400: Added test for "capture" example r=kvark a=bfrazho I've added a test to validate the capture example. I was planning on using the existing "screenshot.png" that was in there for the assertion for the test, but apparently was slightly different from the one that I was generating. I ended up replacing the screenshot.png with what the test was generating. I'm a little concerned that they were different from the start, but maybe the png generating library made some small changes over time. I did check to make sure that it generated the same png on Windows and Linux on the same computer. Let me know if there is anything that you would like me to change! Co-authored-by: Brian <brian@linux-ccip.lan>
This PR widens the comparisons done between two bind group layouts to also consider them equivalent if their vectors of
BindGroupLayoutBinding
s are equal.Tested on various modifications of the cube example from wgpu-rs. https://gist.github.com/yanchith/56e15fe35658b14587ff9bfcbd53116f
Fixes #335