Skip to content

Support dynamic offsets #131

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

Merged
merged 1 commit into from
Apr 26, 2019
Merged

Support dynamic offsets #131

merged 1 commit into from
Apr 26, 2019

Conversation

cloudhead
Copy link
Contributor

@cloudhead cloudhead commented Apr 23, 2019

Closes #125

Adds support for dynamic offsets when setting a bind group.

I haven't actually tried if this works with my use-case, but it's fairly straight forward. 😅

@@ -776,8 +776,8 @@ impl CommandEncoder {
}

impl<'a> RenderPass<'a> {
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup) {
wgn::wgpu_render_pass_set_bind_group(self.id, index, bind_group.id);
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup, offsets: &[u32]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API spec states an optional sequence of u64, however gfx-hal expects u32, so that's why I used that here. I also opted for a slice instead of an Option, as that seems more idiomatic, and the underlying API also expects a slice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice is good here, no need for Option

@kvark
Copy link
Member

kvark commented Apr 23, 2019

Thank you!
We'll need to validate that offsets provided are 1) correspond to dynamic buffer descriptors, and 2) are within the range of those buffers, but that can be done later.

bors r+

Note: travis seems to experience outage on macOS, unfortunately

bors bot added a commit that referenced this pull request Apr 23, 2019
131: Support dynamic offsets r=kvark a=cloudhead

Closes #125

Adds support for dynamic offsets when setting a bind group.

I haven't actually tried if this works with my use-case, but it's fairly straight forward. 😅 

Co-authored-by: Alexis Sellier <alexis@cloudhead.io>
@bors
Copy link
Contributor

bors bot commented Apr 23, 2019

Build failed

@cloudhead
Copy link
Contributor Author

I'll look into this - indeed the descriptor type has to be set to UniformBufferDynamic, and I don't think you want to default to that for all Uniform buffers. If I understand correctly, the offsets list will offset into all dynamic buffers, in order. So if the bind group has 5 bindings and 2 of those are dynamic uniform buffers, then the offsets slice will contain 2 elements.

@kvark
Copy link
Member

kvark commented Apr 23, 2019 via email

@@ -25,6 +25,7 @@ pub enum BindingType {
Sampler = 1,
SampledTexture = 2,
StorageBuffer = 3,
UniformBufferDynamic = 4,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add StorageBufferDynamic please since we are at it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly!

@cloudhead
Copy link
Contributor Author

I'm making progress, however the one issue I'm encountering now is that Binder::provide_entry is caching the uniform buffer, and not re-setting the bind group after I set it with a different offset. I'm going to look more deeply into it, but I suspect the solution might be to not cache dynamic buffers, and always treat them as Provision::Changed. Thoughts?

@cloudhead
Copy link
Contributor Author

Put differently: bind groups with at least one dynamic buffer in them always get re-set. Otherwise it looks like we have to keep track of the offsets in BindGroupPair, for example.

@kvark
Copy link
Member

kvark commented Apr 26, 2019

Yes, I agree. let's always re-set bind groups containing any dynamic offsets

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thank you!
Might need a bit of squashing, so that each individual commit is buildable.

binding_model::BindingType::StorageBuffer => {
device.limits.min_storage_buffer_offset_alignment
}
_ => panic!("Mismatched buffer binding for {:?}", decl),
binding_model::BindingType::StorageBufferDynamic => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: merge the arm with the one above?

@@ -776,8 +776,8 @@ impl CommandEncoder {
}

impl<'a> RenderPass<'a> {
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup) {
wgn::wgpu_render_pass_set_bind_group(self.id, index, bind_group.id);
pub fn set_bind_group(&mut self, index: u32, bind_group: &BindGroup, offsets: &[u32]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice is good here, no need for Option

Closes gfx-rs#125

* Add support for dynamic offsets when setting a bind group.
* Add new binding types: `UniformBufferDynamic` and `StorageBufferDynamic`
@cloudhead
Copy link
Contributor Author

Merged the arms and squashed to one commit 👍

@kvark
Copy link
Member

kvark commented Apr 26, 2019 via email

bors bot added a commit that referenced this pull request Apr 26, 2019
131: Support dynamic offsets r=kvark a=cloudhead

Closes #125

Adds support for dynamic offsets when setting a bind group.

I haven't actually tried if this works with my use-case, but it's fairly straight forward. 😅 

Co-authored-by: Alexis Sellier <alexis@monadic.xyz>
@bors
Copy link
Contributor

bors bot commented Apr 26, 2019

Build succeeded

@bors bors bot merged commit c468840 into gfx-rs:master Apr 26, 2019
@cloudhead cloudhead deleted the f/dynamic-offsets branch April 27, 2019 06:41
Patryk27 pushed a commit to Patryk27/wgpu that referenced this pull request Nov 23, 2022
RandyMcMillan pushed a commit to RandyMcMillan/wgpu that referenced this pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Per-object uniform data
2 participants