Skip to content

Commit a650d23

Browse files
committed
rebased onto #6968
1 parent d8b5527 commit a650d23

File tree

16 files changed

+46
-59
lines changed

16 files changed

+46
-59
lines changed

crates/bevy_core_pipeline/src/core_2d/main_pass_2d_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bevy_gpu::{
1010
use bevy_render::{
1111
camera::ExtractedCamera,
1212
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
13-
render_phase::{DrawFunctions, RenderPhase, TrackedRenderPass},
13+
render_phase::RenderPhase,
1414
view::{ExtractedView, ViewTarget},
1515
};
1616
#[cfg(feature = "trace")]

crates/bevy_core_pipeline/src/core_3d/main_pass_3d_node.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bevy_gpu::{
1010
use bevy_render::{
1111
camera::ExtractedCamera,
1212
render_graph::{Node, NodeRunError, RenderGraphContext, SlotInfo, SlotType},
13-
render_phase::{DrawFunctions, RenderPhase, TrackedRenderPass},
13+
render_phase::RenderPhase,
1414
view::{ExtractedView, ViewDepthTexture, ViewTarget},
1515
};
1616
#[cfg(feature = "trace")]
@@ -97,20 +97,13 @@ impl Node for MainPass3dNode {
9797
}),
9898
};
9999

100-
let draw_functions = world.resource::<DrawFunctions<Opaque3d>>();
101-
102-
let render_pass = render_context
103-
.command_encoder
104-
.begin_render_pass(&pass_descriptor);
105-
let mut draw_functions = draw_functions.write();
106-
let mut tracked_pass = TrackedRenderPass::new(render_pass);
107-
if let Some(viewport) = camera.viewport.as_ref() {
108-
tracked_pass.set_camera_viewport(viewport);
109-
}
110-
for item in &opaque_phase.items {
111-
let draw_function = draw_functions.get_mut(item.draw_function).unwrap();
112-
draw_function.draw(world, &mut tracked_pass, view_entity, item);
113-
}
100+
opaque_phase.render(
101+
world,
102+
gpu_context,
103+
view_entity,
104+
camera.viewport.as_ref(),
105+
pass_descriptor,
106+
);
114107
}
115108

116109
if !alpha_mask_phase.items.is_empty() {
@@ -136,20 +129,13 @@ impl Node for MainPass3dNode {
136129
}),
137130
};
138131

139-
let draw_functions = world.resource::<DrawFunctions<AlphaMask3d>>();
140-
141-
let render_pass = render_context
142-
.command_encoder
143-
.begin_render_pass(&pass_descriptor);
144-
let mut draw_functions = draw_functions.write();
145-
let mut tracked_pass = TrackedRenderPass::new(render_pass);
146-
if let Some(viewport) = camera.viewport.as_ref() {
147-
tracked_pass.set_camera_viewport(viewport);
148-
}
149-
for item in &alpha_mask_phase.items {
150-
let draw_function = draw_functions.get_mut(item.draw_function).unwrap();
151-
draw_function.draw(world, &mut tracked_pass, view_entity, item);
152-
}
132+
alpha_mask_phase.render(
133+
world,
134+
gpu_context,
135+
view_entity,
136+
camera.viewport.as_ref(),
137+
pass_descriptor,
138+
);
153139
}
154140

155141
if !transparent_phase.items.is_empty() {

crates/bevy_core_pipeline/src/tonemapping/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Node for TonemappingNode {
106106
};
107107

108108
let mut render_pass = gpu_context
109-
.command_encoder
109+
.gpu_command_encoder
110110
.begin_render_pass(&pass_descriptor);
111111

112112
render_pass.set_pipeline(pipeline);

crates/bevy_gpu/src/gpu_resource/bind_group.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use crate::gpu_resource::resource_macros::*;
2-
use bevy_reflect::Uuid;
1+
use crate::{define_atomic_id, gpu_resource::resource_macros::*};
32
use std::ops::Deref;
43

4+
define_atomic_id!(BindGroupId);
55
gpu_resource_wrapper!(ErasedBindGroup, wgpu::BindGroup);
66

7-
/// A [`BindGroup`] identifier.
8-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
9-
pub struct BindGroupId(Uuid);
10-
117
/// Bind groups are responsible for binding render resources (e.g. buffers, textures, samplers)
128
/// to a render pass.
139
/// This makes them accessible in the pipeline (shaders) as uniforms.
@@ -31,7 +27,7 @@ impl BindGroup {
3127
impl From<wgpu::BindGroup> for BindGroup {
3228
fn from(value: wgpu::BindGroup) -> Self {
3329
BindGroup {
34-
id: BindGroupId(Uuid::new_v4()),
30+
id: BindGroupId::new(),
3531
value: ErasedBindGroup::new(value),
3632
}
3733
}

crates/bevy_gpu/src/gpu_resource/bind_group_layout.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::gpu_resource::{define_atomic_id, resource_macros::*};
2-
use bevy_reflect::Uuid;
1+
use crate::{define_atomic_id, gpu_resource::resource_macros::*};
32
use std::ops::Deref;
43

54
define_atomic_id!(BindGroupLayoutId);
@@ -32,7 +31,7 @@ impl BindGroupLayout {
3231
impl From<wgpu::BindGroupLayout> for BindGroupLayout {
3332
fn from(value: wgpu::BindGroupLayout) -> Self {
3433
BindGroupLayout {
35-
id: BindGroupLayoutId(Uuid::new_v4()),
34+
id: BindGroupLayoutId::new(),
3635
value: ErasedBindGroupLayout::new(value),
3736
}
3837
}

crates/bevy_gpu/src/gpu_resource/buffer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
use crate::gpu_resource::{define_atomic_id, resource_macros::*};
2-
use bevy_utils::Uuid;
1+
use crate::{define_atomic_id, gpu_resource::resource_macros::*};
32
use std::ops::{Bound, Deref, RangeBounds};
43

5-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
6-
pub struct BufferId(Uuid);
7-
84
define_atomic_id!(BufferId);
95
gpu_resource_wrapper!(ErasedBuffer, wgpu::Buffer);
106

crates/bevy_gpu/src/gpu_resource/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use wgpu::{
3737
ImageCopyTexture, ImageCopyTextureBase, ImageDataLayout, ImageSubresourceRange, IndexFormat,
3838
Limits as WgpuLimits, LoadOp, MapMode, MultisampleState, Operations, Origin3d, PipelineLayout,
3939
PipelineLayoutDescriptor, PolygonMode, PresentMode as WgpuPresentMode, PrimitiveState,
40-
PrimitiveTopology, RenderPass as WgpuRenderPass, RenderPassColorAttachment,
40+
PrimitiveTopology, RenderPass as WgpuRenderPass, RenderPass, RenderPassColorAttachment,
4141
RenderPassDepthStencilAttachment, RenderPassDescriptor,
4242
RenderPipelineDescriptor as RawRenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor,
4343
ShaderModule, ShaderModuleDescriptor, ShaderSource, ShaderStages, StencilFaceState,

crates/bevy_gpu/src/gpu_resource/pipeline.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::{define_atomic_id, gpu_resource::{resource_macros::*, BindGroupLayout, Shader, ShaderDefVal}};
1+
use crate::{
2+
define_atomic_id,
3+
gpu_resource::{resource_macros::*, BindGroupLayout, Shader, ShaderDefVal},
4+
};
25
use bevy_asset::Handle;
36
use std::{borrow::Cow, ops::Deref};
47
use wgpu::{
@@ -7,7 +10,7 @@ use wgpu::{
710
};
811

912
define_atomic_id!(RenderPipelineId);
10-
render_resource_wrapper!(ErasedRenderPipeline, wgpu::RenderPipeline);
13+
gpu_resource_wrapper!(ErasedRenderPipeline, wgpu::RenderPipeline);
1114

1215
/// A [`RenderPipeline`] represents a graphics pipeline and its stages (shaders), bindings and vertex buffers.
1316
///

crates/bevy_gpu/src/gpu_resource/resource_macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,4 @@ macro_rules! define_atomic_id {
148148
};
149149
}
150150

151-
152151
pub use gpu_resource_wrapper;

crates/bevy_gpu/src/gpu_resource/texture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::define_atomic_id;
2-
use std::ops::Deref;
32
use crate::gpu_resource::resource_macros::*;
3+
use std::ops::Deref;
44

55
define_atomic_id!(TextureId);
66
gpu_resource_wrapper!(ErasedTexture, wgpu::Texture);

crates/bevy_gpu/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,21 @@ pub struct GpuAdapterInfo(pub AdapterInfo);
110110
#[derive(Resource, Clone, Deref, DerefMut)]
111111
pub struct GpuQueue(pub Arc<Queue>);
112112

113+
/// Encodes a series of GPU operations.
114+
///
115+
/// A command encoder can record [`RenderPass`]es,
116+
/// [`ComputePass`]es, and transfer operations between
117+
/// driver-managed resources like [`Buffer`]s and
118+
/// [`Texture`]s.
119+
pub type GpuCommandEncoder = CommandEncoder;
120+
113121
/// The context with all information required to interact with the GPU.
114122
///
115-
/// The [`GpuDevice`] is used to create render resources and the
116-
/// the [`CommandEncoder`] is used to record a series of GPU operations.
123+
/// The [`GpuDevice`] is used to create gpu resources (buffers, bind groups, pipelines, etc.) and
124+
/// the [`GpuCommandEncoder`] is used to record a series of GPU operations.
117125
pub struct GpuContext {
118126
pub gpu_device: GpuDevice,
119-
pub command_encoder: CommandEncoder,
127+
pub gpu_command_encoder: GpuCommandEncoder,
120128
}
121129

122130
gpu_resource_wrapper!(ErasedGpuDevice, wgpu::Device);

crates/bevy_render/src/render_graph/node.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use crate::render_graph::{
33
SlotInfo, SlotInfos, SlotType, SlotValue,
44
};
55
use bevy_ecs::world::World;
6-
use bevy_utils::Uuid;
6+
use bevy_gpu::{define_atomic_id, GpuContext};
77
use downcast_rs::{impl_downcast, Downcast};
88
use std::{borrow::Cow, fmt::Debug};
99
use thiserror::Error;
10-
use bevy_gpu::{define_atomic_id};
1110

1211
define_atomic_id!(NodeId);
1312

crates/bevy_render/src/render_phase/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ mod draw_state;
44
pub use draw::*;
55
pub use draw_state::*;
66

7-
use crate::{camera::Viewport, renderer::GpuContext};
7+
use crate::camera::Viewport;
88
use bevy_ecs::{
99
entity::Entity,
1010
prelude::{Component, Query},
1111
world::World,
1212
};
13-
use wgpu::RenderPassDescriptor;
13+
use bevy_gpu::{gpu_resource::RenderPassDescriptor, GpuContext};
1414

1515
/// A resource to collect and sort draw requests for specific [`PhaseItems`](PhaseItem).
1616
#[derive(Component)]

crates/bevy_render/src/render_resource/mod.rs

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

crates/bevy_render/src/renderer/graph_runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl RenderGraphRunner {
6666
{
6767
#[cfg(feature = "trace")]
6868
let _span = info_span!("submit_graph_commands").entered();
69-
queue.submit(vec![render_context.command_encoder.finish()]);
69+
queue.submit(vec![gpu_context.gpu_command_encoder.finish()]);
7070
}
7171
Ok(())
7272
}

0 commit comments

Comments
 (0)