Skip to content
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

delegate layout reflection to RenderResourceContext #691

Merged
merged 2 commits into from
Nov 10, 2020

Conversation

mrk-its
Copy link
Member

@mrk-its mrk-its commented Oct 16, 2020

It is probably last but one PR required by current version of webgl2 backend.
The main thing here is to delegate pipeline layout reflection to RenderResourceContext.reflect_pipeline_layout method. This way webgl2 backend can easly replace layout reflection with custom implementation using webgl2 API itself - here is current implementation: https://github.com/mrk-its/bevy/blob/0ce1e2ab7885f9ee922713c10bfbb358d4ceaf79/crates/bevy_webgl2/src/renderer/webgl2_render_resource_context.rs#L122

The other, but related, thing is introducing of name field in DynamicBinding structure. It allows for defining dynamic bindings by name, in addition to (binding_group_index, binding_index) pair. This is required because version "300 es" of GLSL doesn't support declaring these layout(set = x, binding = y) parameters for uniform blocks and webgl2 backend uses matching by name.
(default implementation simply ignores this name field and still matches uniforms by (binding_group, binding) pair). This name field is also good as human readable description of particular DynamicBinding definition (I removed comments there because they are not necessary now).

@memoryruins memoryruins added O-Web Specific to web (WASM) builds A-Rendering Drawing game state to the screen labels Oct 17, 2020
@cart
Copy link
Member

cart commented Oct 20, 2020

Moving reflect_pipeline_layout to RenderResourceContext seems reasonable, but I'm less a fan of requiring a name and the set/binding in DynamicBindings.

Manually declaring DynamicBindings was meant to be a temporary measure anyway. I'd like to reflect them from the values on RenderResourceBindings if possible. That way nobody needs to manually specify those values in each component.

I know thats a big ask, but DynamicBindings are already a usability wart and I don't really want to make that worse.

@mrk-its mrk-its marked this pull request as draft October 21, 2020 23:30
@mrk-its mrk-its force-pushed the delegate_pipeline_layout_reflection branch from b39511a to 4cf9624 Compare October 22, 2020 06:59
@mrk-its
Copy link
Member Author

mrk-its commented Oct 22, 2020

I don't like these declarations as well. Maybe 4cf9624 is step in good direction?
Not sure how to reflect which bindings are dynamic automatically - maybe some naming convention in shaders, like "Dynamic_Transform" or so?

@cart
Copy link
Member

cart commented Oct 29, 2020

Yeah I think thats a better intermediate step while we sort out making it completely implicit. Your change both makes declarations consistent across backends and cuts down on boilerplate slightly.

I think we should read dynamic bindings from RenderResourceBindings, then set the PipelineSpecialization according to those values. If thats easy, lets just do that instead (rather than break a public api twice). If its hard, im cool with tabling it.

@cart
Copy link
Member

cart commented Oct 29, 2020

If dynamic_index is Some, then its a dynamic binding.

image

@mrk-its
Copy link
Member Author

mrk-its commented Oct 29, 2020

If dynamic_index is Some, then its a dynamic binding.

Ok, I'll try to go this way

@mrk-its mrk-its force-pushed the delegate_pipeline_layout_reflection branch 5 times, most recently from ad89d22 to 8c801c0 Compare November 1, 2020 23:22
@mrk-its
Copy link
Member Author

mrk-its commented Nov 1, 2020

It was easier than expected. No more manual dynamic bindings declarations!

@mrk-its mrk-its marked this pull request as ready for review November 1, 2020 23:56
@@ -26,21 +26,7 @@ impl Default for PbrComponents {
Self {
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
Copy link
Member

Choose a reason for hiding this comment

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

We can replace the specialized() constructor with new() now.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -18,7 +18,6 @@ use std::borrow::Cow;
pub struct PipelineSpecialization {
pub shader_specialization: ShaderSpecialization,
pub primitive_topology: PrimitiveTopology,
pub dynamic_bindings: Vec<DynamicBinding>,
Copy link
Member

Choose a reason for hiding this comment

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

Moving this out of PipelineSpecialization feels a bit wrong. I totally get that by directly consuming RenderResourceBindings, we can cut down on abstraction (and the extra Vec allocation), but having everything that "specializes" a pipeline in one place seems like a good design to keep. If in the future we want to do something like "hash pipeline specialization to identify a pipeline", we would need to undo the change you made here to ensure the dynamic bindings are accounted for.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, changed.

@mrk-its mrk-its force-pushed the delegate_pipeline_layout_reflection branch 4 times, most recently from 7bb2c8a to 4a7df1f Compare November 7, 2020 17:22
@cart
Copy link
Member

cart commented Nov 9, 2020

I pushed a proposed change that accomplishes the following:

  • Moves dynamic binding specialization "setup" to draw_render_pipelines_system (alongside the others)
  • Makes "dynamic bindings" adaptive. The approach in this pr prior to these changes would not adapt to an entity's change in dynamic bindings
  • Retains the desirable property of not recalculating/reallocating the dynamic bindings each frame. They will only be recomputed when they change.

@mrk-its
Copy link
Member Author

mrk-its commented Nov 9, 2020

Thanks, taking a look (I'll also check if this still works with bevy_webgl2).

@mrk-its
Copy link
Member Author

mrk-its commented Nov 9, 2020

It looks much better now. I've also checked it works with bevy_webgl. Ship it!
BTW no idea why CI failed on clippy (I've just ran the same clippy command locally and it passes).

@cart
Copy link
Member

cart commented Nov 10, 2020

Awesome its a new lint that they just rolled out. You've gotta do rustup update to get it. I fixed the breakage on master, so a rebase here should do the trick

mrk-its and others added 2 commits November 10, 2020 09:27
Also:
 * auto-reflect DynamicBindings
 * use RenderPipeline::new, update dynamic_bindings

linting.
@mrk-its mrk-its force-pushed the delegate_pipeline_layout_reflection branch from 761948c to a4b5f7f Compare November 10, 2020 08:27
@cart cart merged commit 60fa2d5 into bevyengine:master Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen O-Web Specific to web (WASM) builds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants