• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

djeedai / bevy_hanabi / 12128238298

02 Dec 2024 09:24PM UTC coverage: 48.661% (-7.6%) from 56.217%
12128238298

Pull #401

github

web-flow
Merge 30c486d1a into 19aee8dbc
Pull Request #401: Upgrade to Bevy v0.15.0

39 of 284 new or added lines in 11 files covered. (13.73%)

435 existing lines in 8 files now uncovered.

3106 of 6383 relevant lines covered (48.66%)

21.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/render/batch.rs
1
use std::{
2
    fmt::Debug,
3
    ops::{Index, Range},
4
};
5

6
#[cfg(feature = "2d")]
7
use bevy::math::FloatOrd;
8
use bevy::{
9
    prelude::*,
10
    render::render_resource::{Buffer, CachedComputePipelineId},
11
};
12

13
use super::{
14
    effect_cache::{DispatchBufferIndices, EffectSlices},
15
    EffectCacheId, GpuCompressedTransform, LayoutFlags,
16
};
17
use crate::{
18
    spawn::EffectInitializer, AlphaMode, EffectAsset, EffectShader, ParticleLayout, PropertyLayout,
19
    TextureLayout,
20
};
21

22
/// Data needed to render all batches pertaining to a specific effect.
23
#[derive(Debug, Component)]
24
pub(crate) struct EffectBatches {
25
    /// Handle of the underlying effect asset describing the effect.
26
    pub handle: Handle<EffectAsset>,
27
    /// One batch per particle group.
28
    pub group_batches: Vec<EffectBatch>,
29
    /// Index of the buffer.
30
    pub buffer_index: u32,
31
    /// Index of the first Spawner of the effects in the batch.
32
    pub spawner_base: u32,
33
    /// The initializer (spawner or cloner) for each particle group.
34
    pub initializers: Vec<EffectInitializer>,
35
    /// The effect cache ID.
36
    pub effect_cache_id: EffectCacheId,
37
    /// The indices within the various indirect dispatch buffers.
38
    pub dispatch_buffer_indices: DispatchBufferIndices,
39
    /// The index of the first [`GpuParticleGroup`] structure in the global
40
    /// [`EffectsMeta::particle_group_buffer`] buffer. The buffer is currently
41
    /// re-created each frame, so the rows for multiple groups of an effect are
42
    /// guaranteed to be contiguous.
43
    pub first_particle_group_buffer_index: u32,
44
    /// Particle layout.
45
    pub particle_layout: ParticleLayout,
46
    /// Flags describing the render layout.
47
    pub layout_flags: LayoutFlags,
48
    /// Asset handle of the effect mesh to draw.
49
    pub mesh: Handle<Mesh>,
50
    /// GPU buffer storing the [`mesh`] of the effect.
51
    pub mesh_buffer: Buffer,
52
    /// Slice inside the GPU buffer for the effect mesh.
53
    pub mesh_slice: Range<u32>,
54
    /// Texture layout.
55
    pub texture_layout: TextureLayout,
56
    /// Textures.
57
    pub textures: Vec<Handle<Image>>,
58
    /// Alpha mode.
59
    pub alpha_mode: AlphaMode,
60
    /// Entities holding the source [`ParticleEffect`] instances which were
61
    /// batched into this single batch. Used to determine visibility per view.
62
    ///
63
    /// [`ParticleEffect`]: crate::ParticleEffect
64
    pub entities: Vec<u32>,
65
    /// Configured shaders used for the particle rendering of this batch.
66
    /// Note that we don't need to keep the init/update shaders alive because
67
    /// their pipeline specialization is doing it via the specialization key.
68
    pub render_shaders: Vec<Handle<Shader>>,
69
    /// Init and update compute pipelines specialized for this batch.
70
    pub init_and_update_pipeline_ids: Vec<InitAndUpdatePipelineIds>,
71
    /// The order in which we evaluate groups.
72
    pub group_order: Vec<u32>,
73
}
74

75
impl Index<u32> for EffectBatches {
76
    type Output = EffectBatch;
77

78
    fn index(&self, index: u32) -> &Self::Output {
×
79
        &self.group_batches[index as usize]
×
80
    }
81
}
82

83
/// Single effect batch to drive rendering.
84
///
85
/// This component is spawned into the render world during the prepare phase
86
/// ([`prepare_effects()`]), once per effect batch per group. In turns it
87
/// references an [`EffectBatches`] component containing all the shared data for
88
/// all the groups of the effect.
89
#[derive(Debug, Component)]
90
pub(crate) struct EffectDrawBatch {
91
    /// Group index of the batch.
92
    pub group_index: u32,
93
    /// Entity holding the [`EffectBatches`] this batch is part of.
94
    pub batches_entity: Entity,
95
    /// For 2D rendering, the Z coordinate used as the sort key. Ignored for 3D
96
    /// rendering.
97
    #[cfg(feature = "2d")]
98
    pub z_sort_key_2d: FloatOrd,
99
    /// For 3d rendering, the position of the emitter so we can compute distance
100
    /// to camera. Ignored for 2D rendering.
101
    #[cfg(feature = "3d")]
102
    pub translation_3d: Vec3,
103
}
104

105
/// Batch data specific to a single particle group.
106
#[derive(Debug)]
107
pub(crate) struct EffectBatch {
108
    /// Slice of particles in the GPU effect buffer for the entire batch.
109
    pub slice: Range<u32>,
110
}
111

112
impl EffectBatches {
113
    /// Create a new batch from a single input.
114
    pub fn from_input(
×
115
        input: BatchesInput,
116
        spawner_base: u32,
117
        effect_cache_id: EffectCacheId,
118
        init_and_update_pipeline_ids: Vec<InitAndUpdatePipelineIds>,
119
        dispatch_buffer_indices: DispatchBufferIndices,
120
        first_particle_group_buffer_index: u32,
121
    ) -> EffectBatches {
122
        EffectBatches {
123
            buffer_index: input.effect_slices.buffer_index,
×
124
            spawner_base,
125
            initializers: input.initializers.clone(),
×
126
            particle_layout: input.effect_slices.particle_layout,
×
127
            effect_cache_id,
128
            dispatch_buffer_indices,
129
            first_particle_group_buffer_index,
130
            group_batches: input
×
131
                .effect_slices
132
                .slices
133
                .windows(2)
134
                .map(|range| EffectBatch {
135
                    slice: range[0]..range[1],
136
                })
137
                .collect(),
138
            handle: input.handle,
×
139
            layout_flags: input.layout_flags,
×
140
            mesh: input.mesh.clone(),
×
NEW
141
            mesh_buffer: input.mesh_buffer,
×
NEW
142
            mesh_slice: input.mesh_slice,
×
143
            texture_layout: input.texture_layout,
×
144
            textures: input.textures,
×
145
            alpha_mode: input.alpha_mode,
×
146
            render_shaders: input
×
147
                .effect_shaders
148
                .iter()
149
                .map(|shaders| shaders.render.clone())
150
                .collect(),
151
            init_and_update_pipeline_ids,
152
            entities: vec![input.entity.index()],
×
153
            group_order: input.group_order,
×
154
        }
155
    }
156
}
157

158
/// Effect batching input, obtained from extracted effects.
159
#[derive(Debug)]
160
pub(crate) struct BatchesInput {
161
    /// Handle of the underlying effect asset describing the effect.
162
    pub handle: Handle<EffectAsset>,
163
    /// Entity index excluding generation ([`Entity::index()`]). This is
164
    /// transient for a single frame, so the generation is useless.
165
    pub entity: Entity,
166
    /// Effect slices.
167
    pub effect_slices: EffectSlices,
168
    /// Layout of the effect properties.
169
    pub property_layout: PropertyLayout,
170
    /// Effect shaders.
171
    pub effect_shaders: Vec<EffectShader>,
172
    /// Various flags related to the effect.
173
    pub layout_flags: LayoutFlags,
174
    /// Asset handle of the effect mesh to draw.
175
    pub mesh: Handle<Mesh>,
176
    /// GPU buffer storing the [`mesh`] of the effect.
177
    pub mesh_buffer: Buffer,
178
    /// Slice inside the GPU buffer for the effect mesh.
179
    pub mesh_slice: Range<u32>,
180
    /// Texture layout.
181
    pub texture_layout: TextureLayout,
182
    /// Textures.
183
    pub textures: Vec<Handle<Image>>,
184
    /// Alpha mode.
185
    pub alpha_mode: AlphaMode,
186
    pub particle_layout: ParticleLayout,
187
    pub initializers: Vec<EffectInitializer>,
188
    /// The order in which we evaluate groups.
189
    pub group_order: Vec<u32>,
190
    /// Emitter transform.
191
    pub transform: GpuCompressedTransform,
192
    /// Emitter inverse transform.
193
    pub inverse_transform: GpuCompressedTransform,
194
    /// GPU buffer where properties for this batch need to be written.
195
    pub property_buffer: Option<Buffer>,
196
    /// Serialized property data.
197
    // FIXME - Contains a single effect's data; should handle multiple ones.
198
    pub property_data: Option<Vec<u8>>,
199
    /// Sort key, for 2D only.
200
    #[cfg(feature = "2d")]
201
    pub z_sort_key_2d: FloatOrd,
202
}
203

204
#[derive(Debug)]
205
pub(crate) struct InitAndUpdatePipelineIds {
206
    pub(crate) init: CachedComputePipelineId,
207
    pub(crate) update: CachedComputePipelineId,
208
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc