-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Move adding DynamicUniformIndex to Extract #5037
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ use bevy_ecs::{ | |
use std::{marker::PhantomData, ops::Deref}; | ||
|
||
/// Stores the index of a uniform inside of [`ComponentUniforms`]. | ||
#[derive(Component)] | ||
#[derive(Component, Copy)] | ||
pub struct DynamicUniformIndex<C: Component> { | ||
index: u32, | ||
marker: PhantomData<C>, | ||
|
@@ -28,6 +28,24 @@ impl<C: Component> DynamicUniformIndex<C> { | |
} | ||
} | ||
|
||
impl<C: Component> Default for DynamicUniformIndex<C> { | ||
fn default() -> Self { | ||
Self { | ||
index: 0, | ||
marker: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<C: Component> Clone for DynamicUniformIndex<C> { | ||
fn clone(&self) -> Self { | ||
Self { | ||
index: self.index, | ||
marker: PhantomData, | ||
} | ||
} | ||
} | ||
Comment on lines
+40
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the manual There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/// Describes how a component gets extracted for rendering. | ||
/// | ||
/// Therefore the component is transferred from the "app world" into the "render world" | ||
|
@@ -100,28 +118,17 @@ impl<C: Component + ShaderType> Default for ComponentUniforms<C> { | |
/// This system prepares all components of the corresponding component type. | ||
/// They are transformed into uniforms and stored in the [`ComponentUniforms`] resource. | ||
fn prepare_uniform_components<C: Component>( | ||
mut commands: Commands, | ||
render_device: Res<RenderDevice>, | ||
render_queue: Res<RenderQueue>, | ||
mut component_uniforms: ResMut<ComponentUniforms<C>>, | ||
components: Query<(Entity, &C)>, | ||
mut components: Query<(&C, &mut DynamicUniformIndex<C>)>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this break the UniformComponentPlugin in the general case? We aren't currently using this anywhere else, but given that this is intended to be a generalized (and user facing) abstraction, I think we should discuss ways to make this "fool proof". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've dropped the ball on this PR, but thinking on this a bit more. I think it makes a lot of sense to take an approach where we keep indices as components while directly writing extracted components to their target staging buffers. Indices are small. 4-8 bytes typically. Compare this with the equivalent If we still need the intermediate data during Prepare or Queue, we can always refer back to the buffer in memory. It's less ergonomic, but alleviates the heaviest parts of running the Render World right now. |
||
) where | ||
C: ShaderType + WriteInto + Clone, | ||
{ | ||
component_uniforms.uniforms.clear(); | ||
let entities = components | ||
.iter() | ||
.map(|(entity, component)| { | ||
( | ||
entity, | ||
(DynamicUniformIndex::<C> { | ||
index: component_uniforms.uniforms.push(component.clone()), | ||
marker: PhantomData, | ||
},), | ||
) | ||
}) | ||
.collect::<Vec<_>>(); | ||
commands.insert_or_spawn_batch(entities); | ||
for (component, mut dynamic) in components.iter_mut() { | ||
dynamic.index = component_uniforms.uniforms.push(component.clone()); | ||
} | ||
|
||
component_uniforms | ||
.uniforms | ||
|
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 default impl also could be replaced by a derive.