Remove gpu-descriptor dependency by inlining the crate - #9078
Conversation
There was a problem hiding this comment.
So I'm no lawyer but if this is a line-for-line copy, that seems slightly legally dubious. More specifically, we will almost certainly need to bundle the copyright notice and license text, which it doesn't look like you did here. Overall, I'm not sure why we need this but I'll let another Mozillan handle it, since they have a whole system for these things.
Also, I realize this is an early review, and you might be in the middle of fixing the copyright fun business.
Also move the implementation to `descriptor.rs`.
This function is only ever used with a single item, so we can simplify it using this knowledge.
ad76441 to
3ee67e4
Compare
|
Well, from the MIT license:
Which I did in |
|
On licensing, yeah this is fine, the one note would be to make the LICENSE field of wgpu-hal "(MIT OR Apache-2.0) AND MIT" to be fully formally correct. |
|
Well
|
inner-daemons
left a comment
There was a problem hiding this comment.
Preliminary review.
I'm curious, what's necessarily the goal here? Is there a reason we need to remove the dependency? And if we do remove the dependency, why not just rewrite the logic as needed? It seems like copying the code over left us with some unnecessary artifacts.
Anyway, thanks for the work put in here. I'm gonna probably just gonna defer to the next reviewer for most stuff.
| }; | ||
|
|
||
| if pool_size == Default::default() { | ||
| pool_size.sampler = 1; |
There was a problem hiding this comment.
I don't know. Maybe to prevent zero-sized pools?
| .max(minimal_set_count) // at least enough for allocation | ||
| .max(self.total.min(MAX_SETS)) // at least as much as was allocated so far capped to MAX_SETS | ||
| .checked_next_power_of_two() // rounded up to nearest 2^N | ||
| .unwrap_or(i32::MAX as u32); |
There was a problem hiding this comment.
This seems sketchy, plus shouldn't it be i32::MAX as u32 + 1 either way?
There was a problem hiding this comment.
Yes, probably (this branch was not reachable anyway). Replaced this code by a much more readable clamp. Not sure about what the next_power_of_two() is about though.
| .checked_next_power_of_two() // rounded up to nearest 2^N | ||
| .unwrap_or(i32::MAX as u32); | ||
|
|
||
| max_sets = (u32::MAX / self.size.sampler.max(1)).min(max_sets); |
There was a problem hiding this comment.
This definitely needs a comment explainign what its doing dividing by the descriptor count.
There was a problem hiding this comment.
Well probably, but I can't really explain it.
There was a problem hiding this comment.
It's to avoid overflowing count * max_sets calculations below.
1af5b40 to
7a6ac42
Compare
7a6ac42 to
93a0882
Compare
Well, mainly the fact that it's not really maintained. Also this enables us to tailor fit this code.
This is what I started with some low-hanging fruits in commits after the first, but looks that I missed some. |
93a0882 to
1a787ab
Compare
1a787ab to
4b83123
Compare
|
CI failure is a DX12 timeout, so probably unrelated. |
teoxoy
left a comment
There was a problem hiding this comment.
I found some more improvements/simplifications and decided to implement the allocator from scratch (#9161). I think it ended up better suited to our Vulkan backend (using knowledge of BGL creation/destruction). A new implementation also avoids the question of how do we make sure we comply with the license brought up at the maintainers meeting last week (we talked about it but didn't come to a resolution).
| } | ||
| } | ||
| unsafe { self.raw.create_descriptor_pool(&vk_info, None) } | ||
| .map_err(super::map_host_device_oom_err) |
There was a problem hiding this comment.
This won't handle vk::Result::ERROR_FRAGMENTATION which is a valid error type for this cmd to return. We can probably just map it to an OOM error for now.
| Err(DeviceAllocationError::Unexpected) | ||
| } | ||
| } | ||
| .map_err(super::map_host_device_oom_err) |
There was a problem hiding this comment.
This one needs to additionally handle ERROR_FRAGMENTED_POOL (note that this one is different from ERROR_FRAGMENTATION) & ERROR_OUT_OF_POOL_MEMORY. Mapping them to an OOM error is probably fine.
| /// | ||
| /// Pool must be created from this device. | ||
| unsafe fn alloc_descriptor_sets<'a>( | ||
| unsafe fn alloc_descriptor_sets( |
There was a problem hiding this comment.
Should now be alloc_descriptor_set and can return a single vk::DescriptorSet. The docs also need updating.
| fn handle_unexpected(err: vk::Result) -> ! { | ||
| pub(super) fn handle_unexpected(err: vk::Result) -> ! { | ||
| panic!("Unexpected Vulkan error: `{err}`") | ||
| } |
There was a problem hiding this comment.
We shouldn't need to use this function anymore.
| .checked_next_power_of_two() // rounded up to nearest 2^N | ||
| .unwrap_or(i32::MAX as u32); | ||
|
|
||
| max_sets = (u32::MAX / self.size.sampler.max(1)).min(max_sets); |
There was a problem hiding this comment.
It's to avoid overflowing count * max_sets calculations below.
| .ok() | ||
| .is_some_and(|count| count <= bucket.total)); | ||
|
|
||
| unsafe { bucket.free(device, self.raw_sets_cache.drain(..), set.pool_id) }; |
There was a problem hiding this comment.
raw_sets_cache seems unnecessary.
| } | ||
|
|
||
| if let Some(last_id) = last { | ||
| unsafe { bucket.free(device, self.raw_sets_cache.drain(..), last_id) }; |
There was a problem hiding this comment.
We only ever allocate one set at a time, this looks like dead code.
Together with gfx-rs/wgpu#9078, this should deduplicate hashbrown for wgpu and eventually for Ruffle. Co-authored-by: Tomáš Procházka <SuchAFuriousDeath@users.noreply.github.com>
|
Yeah, this is what I figured out, this is why I didn't answer to the last reviews. |
Description
Stop depending on
gpu-descriptorand inline the part of their code that we need directly.gpu-descriptoris very passively maintained and has outdated dependencies. Inlining the crate intowgpu-halprevents this and simplifies our code at a small cost (~300 LoC). Additionally, this should reduce compile times a bit.Each commit can be reviewed independently. The first commit bring parts of
gpu-descriptorandgpu-descriptor-typesinwgpu-hal/src/vulkan/descriptor.rsand does minor import changes to accommodate for this. Other are refactoring that take advantage of the inlining.Testing
Ran tests
Squash or Rebase?
Rebase
Checklist
cargo fmt.taplo format.cargo clippy --tests. If applicable, add:--target wasm32-unknown-unknowncargo xtask testto run tests.CHANGELOG.mdentry.