Skip to content

Commit a81cb60

Browse files
committed
Move MeshPipeline to bevy_material, and its render impls to bevy_render
1 parent 1290785 commit a81cb60

File tree

7 files changed

+712
-664
lines changed

7 files changed

+712
-664
lines changed

crates/bevy_internal/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ android-game-activity = ["bevy_winit/android-game-activity"]
145145

146146
# Transmission textures in `StandardMaterial`:
147147
pbr_transmission_textures = [
148+
"bevy_render?/pbr_transmission_textures",
148149
"bevy_pbr?/pbr_transmission_textures",
149150
"bevy_gltf?/pbr_transmission_textures",
150151
]
@@ -154,27 +155,34 @@ pbr_clustered_decals = ["bevy_pbr?/pbr_clustered_decals"]
154155

155156
# Light Texture support
156157
pbr_light_textures = [
158+
"bevy_render?/pbr_light_textures",
157159
"bevy_pbr?/pbr_clustered_decals",
158160
"bevy_pbr?/pbr_light_textures",
159161
]
160162

161163
# Multi-layer material textures in `StandardMaterial`:
162164
pbr_multi_layer_material_textures = [
165+
"bevy_render?/pbr_multi_layer_material_textures",
163166
"bevy_pbr?/pbr_multi_layer_material_textures",
164167
"bevy_gltf?/pbr_multi_layer_material_textures",
165168
]
166169

167170
# Anisotropy texture in `StandardMaterial`:
168171
pbr_anisotropy_texture = [
172+
"bevy_render?/pbr_anisotropy_texture",
169173
"bevy_pbr?/pbr_anisotropy_texture",
170174
"bevy_gltf?/pbr_anisotropy_texture",
171175
]
172176

173177
# Percentage-closer soft shadows
174-
experimental_pbr_pcss = ["bevy_pbr?/experimental_pbr_pcss"]
178+
experimental_pbr_pcss = [
179+
"bevy_render?/experimental_pbr_pcss",
180+
"bevy_pbr?/experimental_pbr_pcss",
181+
]
175182

176183
# Specular textures in `StandardMaterial`:
177184
pbr_specular_textures = [
185+
"bevy_render?/pbr_specular_textures",
178186
"bevy_pbr?/pbr_specular_textures",
179187
"bevy_gltf?/pbr_specular_textures",
180188
]

crates/bevy_material/src/render/mesh.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
use bevy_asset::Handle;
2+
use bevy_ecs::resource::Resource;
3+
use bevy_image::Image;
14
use bevy_mesh::BaseMeshPipelineKey;
2-
use crate::render_resource::*;
5+
use bevy_shader::Shader;
6+
use crate::{render::{MeshLayouts, MeshPipelineViewLayout, MeshPipelineViewLayoutKey, MeshPipelineViewLayouts}, render_resource::*};
37

48
use static_assertions::const_assert_eq;
59

@@ -16,7 +20,52 @@ use static_assertions::const_assert_eq;
1620
pub const MESH_PIPELINE_VIEW_LAYOUT_SAFE_MAX_TEXTURES: usize = 10;
1721

1822

19-
// pub struct MeshPipeline {
23+
/// All data needed to construct a pipeline for rendering 3D meshes.
24+
#[derive(Resource, Clone)]
25+
pub struct MeshPipeline {
26+
/// A reference to all the mesh pipeline view layouts.
27+
pub view_layouts: MeshPipelineViewLayouts,
28+
// This dummy white texture is to be used in place of optional StandardMaterial textures
29+
pub dummy_white_image: Handle<Image>,
30+
pub clustered_forward_buffer_binding_type: BufferBindingType,
31+
pub mesh_layouts: MeshLayouts,
32+
/// The shader asset handle.
33+
pub shader: Handle<Shader>,
34+
/// `MeshUniform`s are stored in arrays in buffers. If storage buffers are available, they
35+
/// are used and this will be `None`, otherwise uniform buffers will be used with batches
36+
/// of this many `MeshUniform`s, stored at dynamic offsets within the uniform buffer.
37+
/// Use code like this in custom shaders:
38+
/// ```wgsl
39+
/// ##ifdef PER_OBJECT_BUFFER_BATCH_SIZE
40+
/// @group(1) @binding(0) var<uniform> mesh: array<Mesh, #{PER_OBJECT_BUFFER_BATCH_SIZE}u>;
41+
/// ##else
42+
/// @group(1) @binding(0) var<storage> mesh: array<Mesh>;
43+
/// ##endif // PER_OBJECT_BUFFER_BATCH_SIZE
44+
/// ```
45+
pub per_object_buffer_batch_size: Option<u32>,
46+
47+
/// Whether binding arrays (a.k.a. bindless textures) are usable on the
48+
/// current render device.
49+
///
50+
/// This affects whether reflection probes can be used.
51+
pub binding_arrays_are_usable: bool,
52+
53+
/// Whether clustered decals are usable on the current render device.
54+
pub clustered_decals_are_usable: bool,
55+
56+
/// Whether skins will use uniform buffers on account of storage buffers
57+
/// being unavailable on this platform.
58+
pub skins_use_uniform_buffers: bool,
59+
}
60+
61+
impl MeshPipeline {
62+
pub fn get_view_layout(
63+
&self,
64+
layout_key: MeshPipelineViewLayoutKey,
65+
) -> &MeshPipelineViewLayout {
66+
self.view_layouts.get_view_layout(layout_key)
67+
}
68+
}
2069

2170
bitflags::bitflags! {
2271
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash)]

crates/bevy_pbr/src/prepass/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod prepass_bindings;
33
use crate::{
44
alpha_mode_pipeline_key, binding_arrays_are_usable, buffer_layout,
55
collect_meshes_for_gpu_building, init_material_pipeline, set_mesh_motion_vector_flags,
6-
setup_morph_and_skinning_defs, skin, DeferredDrawFunction, DeferredFragmentShader,
6+
skin, DeferredDrawFunction, DeferredFragmentShader,
77
DeferredVertexShader, DrawMesh, EntitySpecializationTicks, ErasedMaterialPipelineKey,
88
MaterialPipeline, MaterialProperties, MeshLayouts, MeshPipeline, MeshPipelineKey,
99
OpaqueRendererMethod, PreparedMaterial, PrepassDrawFunction, PrepassFragmentShader,
@@ -27,7 +27,7 @@ use bevy_render::{
2727
alpha::AlphaMode,
2828
batching::gpu_preprocessing::GpuPreprocessingSupport,
2929
globals::{GlobalsBuffer, GlobalsUniform},
30-
mesh::{allocator::MeshAllocator, RenderMesh},
30+
mesh::{allocator::MeshAllocator, pipeline::setup_morph_and_skinning_defs, RenderMesh},
3131
render_asset::{prepare_assets, RenderAssets},
3232
render_phase::*,
3333
render_resource::{binding_types::uniform_buffer, *},

0 commit comments

Comments
 (0)