Skip to content

Implement PUSH_CONSTANTS feature #777

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
Jul 13, 2020
Merged

Conversation

cwfitzgerald
Copy link
Member

@cwfitzgerald cwfitzgerald commented Jul 11, 2020

Connections

Closes #734. Makes minor progress on #689.

Description

This one is a doozy.

Implements Push Constant support in wgpu.

Implementation Notes:

  • Push constants are unconditionally cleared on change to a pipeline with a different pipeline layout. This could be elided in a future revision, possibly making push constants slightly faster on non-vulkan platforms.
  • This exposes basically a direct port of vulkan push constants to wgpu. There might be design decisions that would want to be changed for an upstream webgpu implementation.

Code Notes:

  • The render bundle code needs to be heavily scrutinized because I wasn't able to test it and it requires pipeline invalidation.
  • Validation should be correct as I have tested it pretty throughly, but there are a lot of factors involved, so I could have accidentally missed something (or not allowed something I should have).

Other Work:

  • PipelineLayoutDescriptor was moved into wgt from wgpu-rs with a generic.

Testing

I have modified the wgpu-rs example to use push constants for its uniform fallback, which is a perfect use case for push constants. I have not tested compute constants, but I expect no issues with them.

gfx-rs/wgpu-rs#435

@cwfitzgerald cwfitzgerald requested a review from kvark July 11, 2020 04:33
Copy link
Contributor

@monocodus monocodus bot left a comment

Choose a reason for hiding this comment

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

The .monocodus config not found in your repo. Default config is used.
Check config documentation here

Copy link
Contributor

@monocodus monocodus bot left a comment

Choose a reason for hiding this comment

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

The .monocodus config not found in your repo. Default config is used.
Check config documentation here

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.

I think this looks great! A few concerns so far, and I would like to take another look for correctness after the next iteration

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.

I think this is almost good to go. Just a few fixes are needed, nothing major.

@cwfitzgerald
Copy link
Member Author

Alright, I think this is good to go, will update the wgpu-rs PR shortly.

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.

Ok, one last round!

/// None means there is no data and the data should be an array of zeros.
///
/// Facilitates clears in renderbundles which explicitly do their clears.
values_offset: Option<usize>,
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be usize? I.e. can we say that you aren't going to have more than 64k of push constants ever, and have this offset being u16 instead? We'd want to keep the enum RenderCommand size to be small. Even though right now it may not be the enum variant that makes it big, we don't want to face this later down the road when we try to shrink it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to make this a u32, as this index can be as large as the sum of all push constants used in a render pass, and if someone sets a lot of push constants (or used metal's 4k to their full advantage), it would overrun a u16 pretty quickly.

);
for range in non_overlapping {
let clear_bytes =
vec![0_u32; (range.range.end - range.range.start) as usize / 4];
Copy link
Member

Choose a reason for hiding this comment

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

I think the way we'd set this up in the near future (or now?) is: having a fixed-size zero vector somewhere, say in Device, say of 256 bytes. Then this code would have a loop that re-uses the same vector and calls push_graphics_constants as many times as needed to fill in zeroes.

@cwfitzgerald
Copy link
Member Author

Alrighty, should be good, rebasing...

@cwfitzgerald
Copy link
Member Author

That was a pretty nasty rebase, let me get wgpu-rs up to date to make sure I didn't break anything.

@cwfitzgerald
Copy link
Member Author

Fixed!
bors r=kvark

@bors
Copy link
Contributor

bors bot commented Jul 13, 2020

@bors bors bot merged commit f67771f into gfx-rs:master Jul 13, 2020
bors bot added a commit to gfx-rs/wgpu-rs that referenced this pull request Jul 13, 2020
435: Implement PUSH_CONSTANTS feature r=kvark a=cwfitzgerald

The rust half of the push constant extensions, continuing from gfx-rs/wgpu#777.

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
435: Implement PUSH_CONSTANTS feature r=kvark a=cwfitzgerald

The rust half of the push constant extensions, continuing from gfx-rs#777.

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
778: Return None from get_swap_chain_preferred_format if the adapter does not support the surface r=kvark a=OlegOAndreev

Fixes gfx-rs#777 

Almost every other method in wgpu panics on failure, so I decided to make the return value an `Option<TextureFormat>`, not a `Result<Option<TextureFormat>>`

Co-authored-by: Oleg Andreev <ooandreev@yandex-team.ru>
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.

Push constants extension
2 participants