mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
Share code between passes for setting bind groups.
Renamed PipelineDescriptor to RenderPipelineDescriptor
This commit is contained in:
parent
cdf06ea293
commit
a0347195c0
10 changed files with 86 additions and 77 deletions
|
@ -2,7 +2,7 @@ mod bind_group;
|
|||
mod binding;
|
||||
mod compute_pipeline;
|
||||
#[allow(clippy::module_inception)]
|
||||
mod pipeline;
|
||||
mod render_pipeline;
|
||||
mod pipeline_layout;
|
||||
mod state_descriptors;
|
||||
mod vertex_buffer_descriptor;
|
||||
|
@ -11,7 +11,7 @@ mod vertex_format;
|
|||
pub use bind_group::*;
|
||||
pub use binding::*;
|
||||
pub use compute_pipeline::*;
|
||||
pub use pipeline::*;
|
||||
pub use render_pipeline::*;
|
||||
pub use pipeline_layout::*;
|
||||
pub use state_descriptors::*;
|
||||
pub use vertex_buffer_descriptor::*;
|
||||
|
|
|
@ -27,7 +27,7 @@ impl PipelineId {
|
|||
|
||||
#[derive(Clone, Debug, TypeUuid)]
|
||||
#[uuid = "ebfc1d11-a2a4-44cb-8f12-c49cc631146c"]
|
||||
pub struct PipelineDescriptor {
|
||||
pub struct RenderPipelineDescriptor {
|
||||
pub name: Option<String>,
|
||||
pub layout: PipelineLayout,
|
||||
pub shader_stages: ShaderStages,
|
||||
|
@ -39,9 +39,9 @@ pub struct PipelineDescriptor {
|
|||
pub color_target_states: Vec<ColorTargetState>,
|
||||
}
|
||||
|
||||
impl PipelineDescriptor {
|
||||
impl RenderPipelineDescriptor {
|
||||
pub fn new(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
||||
PipelineDescriptor {
|
||||
RenderPipelineDescriptor {
|
||||
name: None,
|
||||
layout,
|
||||
color_target_states: Vec::new(),
|
||||
|
@ -65,7 +65,7 @@ impl PipelineDescriptor {
|
|||
}
|
||||
|
||||
pub fn default_config(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
||||
PipelineDescriptor {
|
||||
RenderPipelineDescriptor {
|
||||
name: None,
|
||||
primitive: PrimitiveState {
|
||||
topology: PrimitiveTopology::TriangleList,
|
|
@ -1,6 +1,6 @@
|
|||
use super::RenderResourceContext;
|
||||
use crate::{
|
||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineDescriptor, PipelineId},
|
||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, RenderPipelineDescriptor, PipelineId},
|
||||
render_resource::{
|
||||
BindGroup, BufferId, BufferInfo, BufferMapMode, SamplerId, SwapChainDescriptor, TextureId,
|
||||
},
|
||||
|
@ -97,7 +97,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
|||
|
||||
fn remove_sampler(&self, _sampler: SamplerId) {}
|
||||
|
||||
fn create_render_pipeline(&self, _pipeline_descriptor: &PipelineDescriptor) -> PipelineId {
|
||||
fn create_render_pipeline(&self, _pipeline_descriptor: &RenderPipelineDescriptor) -> PipelineId {
|
||||
PipelineId::new()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineDescriptor, PipelineId},
|
||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, RenderPipelineDescriptor, PipelineId},
|
||||
render_resource::{
|
||||
BindGroup, BufferId, BufferInfo, BufferMapMode, SamplerId, SwapChainDescriptor, TextureId,
|
||||
},
|
||||
|
@ -64,7 +64,7 @@ pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
|
|||
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo>;
|
||||
fn get_aligned_uniform_size(&self, size: usize, dynamic: bool) -> usize;
|
||||
fn get_aligned_texture_size(&self, data_size: usize) -> usize;
|
||||
fn create_render_pipeline(&self, pipeline_descriptor: &PipelineDescriptor) -> PipelineId;
|
||||
fn create_render_pipeline(&self, pipeline_descriptor: &RenderPipelineDescriptor) -> PipelineId;
|
||||
fn create_compute_pipeline(
|
||||
&self,
|
||||
_pipeline_descriptor: &ComputePipelineDescriptor,
|
||||
|
|
|
@ -22,7 +22,7 @@ use bytemuck::{Pod, Zeroable};
|
|||
|
||||
pub struct SpriteShaders {
|
||||
pipeline: PipelineId,
|
||||
pipeline_descriptor: PipelineDescriptor,
|
||||
pipeline_descriptor: RenderPipelineDescriptor,
|
||||
}
|
||||
|
||||
// TODO: this pattern for initializing the shaders / pipeline isn't ideal. this should be handled by the asset system
|
||||
|
@ -67,7 +67,7 @@ impl FromWorld for SpriteShaders {
|
|||
|
||||
pipeline_layout.bind_groups[0].bindings[0].set_dynamic(true);
|
||||
|
||||
let pipeline_descriptor = PipelineDescriptor {
|
||||
let pipeline_descriptor = RenderPipelineDescriptor {
|
||||
depth_stencil: None,
|
||||
color_target_states: vec![ColorTargetState {
|
||||
format: TextureFormat::default(),
|
||||
|
@ -94,7 +94,7 @@ impl FromWorld for SpriteShaders {
|
|||
clamp_depth: false,
|
||||
conservative: false,
|
||||
},
|
||||
..PipelineDescriptor::new(
|
||||
..RenderPipelineDescriptor::new(
|
||||
ShaderStages {
|
||||
vertex,
|
||||
fragment: Some(fragment),
|
||||
|
|
50
pipelined/bevy_wgpu2/src/bind_group.rs
Normal file
50
pipelined/bevy_wgpu2/src/bind_group.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use bevy_render2::{pipeline::BindGroupDescriptorId, render_resource::BindGroupId};
|
||||
use bevy_utils::tracing::trace;
|
||||
use crate::resources::WgpuResourceRefs;
|
||||
|
||||
pub enum Pass<'a, 'b> {
|
||||
Render(&'b mut wgpu::RenderPass<'a>),
|
||||
Compute(&'b mut wgpu::ComputePass<'a>),
|
||||
}
|
||||
|
||||
pub fn set_bind_group<'a, 'b>(
|
||||
pass: Pass<'a, 'b>,
|
||||
wgpu_resources: &WgpuResourceRefs<'a>,
|
||||
index: u32,
|
||||
bind_group_descriptor_id: BindGroupDescriptorId,
|
||||
bind_group: BindGroupId,
|
||||
dynamic_uniform_indices: Option<&[u32]>,
|
||||
) {
|
||||
if let Some(bind_group_info) = wgpu_resources
|
||||
.bind_groups
|
||||
.get(&bind_group_descriptor_id)
|
||||
{
|
||||
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
||||
const EMPTY: &[u32] = &[];
|
||||
let dynamic_uniform_indices =
|
||||
if let Some(dynamic_uniform_indices) = dynamic_uniform_indices {
|
||||
dynamic_uniform_indices
|
||||
} else {
|
||||
EMPTY
|
||||
};
|
||||
wgpu_resources
|
||||
.used_bind_group_sender
|
||||
.send(bind_group)
|
||||
.unwrap();
|
||||
|
||||
trace!(
|
||||
"set bind group {:?} {:?}: {:?}",
|
||||
bind_group_descriptor_id,
|
||||
dynamic_uniform_indices,
|
||||
bind_group
|
||||
);
|
||||
|
||||
match pass {
|
||||
Pass::Render(render_pass) =>
|
||||
render_pass.set_bind_group(index, wgpu_bind_group, dynamic_uniform_indices),
|
||||
Pass::Compute(compute_pass) =>
|
||||
compute_pass.set_bind_group(index, wgpu_bind_group, dynamic_uniform_indices),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
use crate::{resources::WgpuResourceRefs, WgpuRenderContext};
|
||||
use crate::{WgpuRenderContext, bind_group::{self, Pass}, resources::WgpuResourceRefs};
|
||||
use bevy_render2::{
|
||||
pass::ComputePass,
|
||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineId},
|
||||
render_resource::BindGroupId,
|
||||
renderer::RenderContext,
|
||||
};
|
||||
use bevy_utils::tracing::trace;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WgpuComputePass<'a> {
|
||||
|
@ -27,34 +26,14 @@ impl<'a> ComputePass for WgpuComputePass<'a> {
|
|||
bind_group: BindGroupId,
|
||||
dynamic_uniform_indices: Option<&[u32]>,
|
||||
) {
|
||||
if let Some(bind_group_info) = self
|
||||
.wgpu_resources
|
||||
.bind_groups
|
||||
.get(&bind_group_descriptor_id)
|
||||
{
|
||||
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
||||
const EMPTY: &[u32] = &[];
|
||||
let dynamic_uniform_indices =
|
||||
if let Some(dynamic_uniform_indices) = dynamic_uniform_indices {
|
||||
dynamic_uniform_indices
|
||||
} else {
|
||||
EMPTY
|
||||
};
|
||||
self.wgpu_resources
|
||||
.used_bind_group_sender
|
||||
.send(bind_group)
|
||||
.unwrap();
|
||||
|
||||
trace!(
|
||||
"set bind group {:?} {:?}: {:?}",
|
||||
bind_group_descriptor_id,
|
||||
dynamic_uniform_indices,
|
||||
bind_group
|
||||
);
|
||||
self.compute_pass
|
||||
.set_bind_group(index, wgpu_bind_group, dynamic_uniform_indices);
|
||||
}
|
||||
}
|
||||
bind_group::set_bind_group(
|
||||
Pass::Compute(&mut self.compute_pass),
|
||||
&self.wgpu_resources,
|
||||
index,
|
||||
bind_group_descriptor_id,
|
||||
bind_group,
|
||||
dynamic_uniform_indices,
|
||||
)
|
||||
}
|
||||
|
||||
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
||||
|
|
|
@ -8,6 +8,7 @@ mod render_resource_context;
|
|||
mod renderer;
|
||||
mod resources;
|
||||
mod type_converter;
|
||||
mod bind_group;
|
||||
|
||||
pub use compute_pass::*;
|
||||
pub use render_context::*;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use crate::{resources::WgpuResourceRefs, type_converter::WgpuInto, WgpuRenderContext};
|
||||
use crate::{WgpuRenderContext, bind_group::{self, Pass}, resources::WgpuResourceRefs, type_converter::WgpuInto};
|
||||
use bevy_render2::{
|
||||
pass::RenderPass,
|
||||
pipeline::{BindGroupDescriptorId, IndexFormat, PipelineDescriptor, PipelineId},
|
||||
pipeline::{BindGroupDescriptorId, IndexFormat, RenderPipelineDescriptor, PipelineId},
|
||||
render_resource::{BindGroupId, BufferId},
|
||||
renderer::RenderContext,
|
||||
};
|
||||
use bevy_utils::tracing::trace;
|
||||
use std::ops::Range;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -13,7 +12,7 @@ pub struct WgpuRenderPass<'a> {
|
|||
pub render_pass: wgpu::RenderPass<'a>,
|
||||
pub render_context: &'a WgpuRenderContext,
|
||||
pub wgpu_resources: WgpuResourceRefs<'a>,
|
||||
pub pipeline_descriptor: Option<&'a PipelineDescriptor>,
|
||||
pub pipeline_descriptor: Option<&'a RenderPipelineDescriptor>,
|
||||
}
|
||||
|
||||
impl<'a> RenderPass for WgpuRenderPass<'a> {
|
||||
|
@ -62,34 +61,14 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
|
|||
bind_group: BindGroupId,
|
||||
dynamic_uniform_indices: Option<&[u32]>,
|
||||
) {
|
||||
if let Some(bind_group_info) = self
|
||||
.wgpu_resources
|
||||
.bind_groups
|
||||
.get(&bind_group_descriptor_id)
|
||||
{
|
||||
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
||||
const EMPTY: &[u32] = &[];
|
||||
let dynamic_uniform_indices =
|
||||
if let Some(dynamic_uniform_indices) = dynamic_uniform_indices {
|
||||
dynamic_uniform_indices
|
||||
} else {
|
||||
EMPTY
|
||||
};
|
||||
self.wgpu_resources
|
||||
.used_bind_group_sender
|
||||
.send(bind_group)
|
||||
.unwrap();
|
||||
|
||||
trace!(
|
||||
"set bind group {:?} {:?}: {:?}",
|
||||
bind_group_descriptor_id,
|
||||
dynamic_uniform_indices,
|
||||
bind_group
|
||||
);
|
||||
self.render_pass
|
||||
.set_bind_group(index, wgpu_bind_group, dynamic_uniform_indices);
|
||||
}
|
||||
}
|
||||
bind_group::set_bind_group(
|
||||
Pass::Render(&mut self.render_pass),
|
||||
&self.wgpu_resources,
|
||||
index,
|
||||
bind_group_descriptor_id,
|
||||
bind_group,
|
||||
dynamic_uniform_indices,
|
||||
)
|
||||
}
|
||||
|
||||
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
use bevy_render2::{
|
||||
pipeline::{
|
||||
BindGroupDescriptor, BindGroupDescriptorId, BindingShaderStage, ComputePipelineDescriptor,
|
||||
PipelineDescriptor, PipelineId,
|
||||
RenderPipelineDescriptor, PipelineId,
|
||||
},
|
||||
render_resource::{
|
||||
BindGroup, BufferId, BufferInfo, BufferMapMode, RenderResourceBinding, SamplerId,
|
||||
|
@ -402,7 +402,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
swap_chain_outputs.clear();
|
||||
}
|
||||
|
||||
fn create_render_pipeline(&self, pipeline_descriptor: &PipelineDescriptor) -> PipelineId {
|
||||
fn create_render_pipeline(&self, pipeline_descriptor: &RenderPipelineDescriptor) -> PipelineId {
|
||||
let layout = &pipeline_descriptor.layout;
|
||||
for bind_group_descriptor in layout.bind_groups.iter() {
|
||||
self.create_bind_group_layout(&bind_group_descriptor);
|
||||
|
|
Loading…
Add table
Reference in a new issue