Share code between passes for setting bind groups.
Renamed PipelineDescriptor to RenderPipelineDescriptor
This commit is contained in:
parent
cdf06ea293
commit
a0347195c0
@ -2,7 +2,7 @@ mod bind_group;
|
|||||||
mod binding;
|
mod binding;
|
||||||
mod compute_pipeline;
|
mod compute_pipeline;
|
||||||
#[allow(clippy::module_inception)]
|
#[allow(clippy::module_inception)]
|
||||||
mod pipeline;
|
mod render_pipeline;
|
||||||
mod pipeline_layout;
|
mod pipeline_layout;
|
||||||
mod state_descriptors;
|
mod state_descriptors;
|
||||||
mod vertex_buffer_descriptor;
|
mod vertex_buffer_descriptor;
|
||||||
@ -11,7 +11,7 @@ mod vertex_format;
|
|||||||
pub use bind_group::*;
|
pub use bind_group::*;
|
||||||
pub use binding::*;
|
pub use binding::*;
|
||||||
pub use compute_pipeline::*;
|
pub use compute_pipeline::*;
|
||||||
pub use pipeline::*;
|
pub use render_pipeline::*;
|
||||||
pub use pipeline_layout::*;
|
pub use pipeline_layout::*;
|
||||||
pub use state_descriptors::*;
|
pub use state_descriptors::*;
|
||||||
pub use vertex_buffer_descriptor::*;
|
pub use vertex_buffer_descriptor::*;
|
||||||
|
@ -27,7 +27,7 @@ impl PipelineId {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, TypeUuid)]
|
#[derive(Clone, Debug, TypeUuid)]
|
||||||
#[uuid = "ebfc1d11-a2a4-44cb-8f12-c49cc631146c"]
|
#[uuid = "ebfc1d11-a2a4-44cb-8f12-c49cc631146c"]
|
||||||
pub struct PipelineDescriptor {
|
pub struct RenderPipelineDescriptor {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub layout: PipelineLayout,
|
pub layout: PipelineLayout,
|
||||||
pub shader_stages: ShaderStages,
|
pub shader_stages: ShaderStages,
|
||||||
@ -39,9 +39,9 @@ pub struct PipelineDescriptor {
|
|||||||
pub color_target_states: Vec<ColorTargetState>,
|
pub color_target_states: Vec<ColorTargetState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PipelineDescriptor {
|
impl RenderPipelineDescriptor {
|
||||||
pub fn new(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
pub fn new(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
||||||
PipelineDescriptor {
|
RenderPipelineDescriptor {
|
||||||
name: None,
|
name: None,
|
||||||
layout,
|
layout,
|
||||||
color_target_states: Vec::new(),
|
color_target_states: Vec::new(),
|
||||||
@ -65,7 +65,7 @@ impl PipelineDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_config(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
pub fn default_config(shader_stages: ShaderStages, layout: PipelineLayout) -> Self {
|
||||||
PipelineDescriptor {
|
RenderPipelineDescriptor {
|
||||||
name: None,
|
name: None,
|
||||||
primitive: PrimitiveState {
|
primitive: PrimitiveState {
|
||||||
topology: PrimitiveTopology::TriangleList,
|
topology: PrimitiveTopology::TriangleList,
|
@ -1,6 +1,6 @@
|
|||||||
use super::RenderResourceContext;
|
use super::RenderResourceContext;
|
||||||
use crate::{
|
use crate::{
|
||||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineDescriptor, PipelineId},
|
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, RenderPipelineDescriptor, PipelineId},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
BindGroup, BufferId, BufferInfo, BufferMapMode, SamplerId, SwapChainDescriptor, TextureId,
|
BindGroup, BufferId, BufferInfo, BufferMapMode, SamplerId, SwapChainDescriptor, TextureId,
|
||||||
},
|
},
|
||||||
@ -97,7 +97,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
|||||||
|
|
||||||
fn remove_sampler(&self, _sampler: SamplerId) {}
|
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()
|
PipelineId::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineDescriptor, PipelineId},
|
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, RenderPipelineDescriptor, PipelineId},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
BindGroup, BufferId, BufferInfo, BufferMapMode, SamplerId, SwapChainDescriptor, TextureId,
|
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_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo>;
|
||||||
fn get_aligned_uniform_size(&self, size: usize, dynamic: bool) -> usize;
|
fn get_aligned_uniform_size(&self, size: usize, dynamic: bool) -> usize;
|
||||||
fn get_aligned_texture_size(&self, data_size: usize) -> 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(
|
fn create_compute_pipeline(
|
||||||
&self,
|
&self,
|
||||||
_pipeline_descriptor: &ComputePipelineDescriptor,
|
_pipeline_descriptor: &ComputePipelineDescriptor,
|
||||||
|
@ -22,7 +22,7 @@ use bytemuck::{Pod, Zeroable};
|
|||||||
|
|
||||||
pub struct SpriteShaders {
|
pub struct SpriteShaders {
|
||||||
pipeline: PipelineId,
|
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
|
// 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);
|
pipeline_layout.bind_groups[0].bindings[0].set_dynamic(true);
|
||||||
|
|
||||||
let pipeline_descriptor = PipelineDescriptor {
|
let pipeline_descriptor = RenderPipelineDescriptor {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
color_target_states: vec![ColorTargetState {
|
color_target_states: vec![ColorTargetState {
|
||||||
format: TextureFormat::default(),
|
format: TextureFormat::default(),
|
||||||
@ -94,7 +94,7 @@ impl FromWorld for SpriteShaders {
|
|||||||
clamp_depth: false,
|
clamp_depth: false,
|
||||||
conservative: false,
|
conservative: false,
|
||||||
},
|
},
|
||||||
..PipelineDescriptor::new(
|
..RenderPipelineDescriptor::new(
|
||||||
ShaderStages {
|
ShaderStages {
|
||||||
vertex,
|
vertex,
|
||||||
fragment: Some(fragment),
|
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::{
|
use bevy_render2::{
|
||||||
pass::ComputePass,
|
pass::ComputePass,
|
||||||
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineId},
|
pipeline::{BindGroupDescriptorId, ComputePipelineDescriptor, PipelineId},
|
||||||
render_resource::BindGroupId,
|
render_resource::BindGroupId,
|
||||||
renderer::RenderContext,
|
renderer::RenderContext,
|
||||||
};
|
};
|
||||||
use bevy_utils::tracing::trace;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WgpuComputePass<'a> {
|
pub struct WgpuComputePass<'a> {
|
||||||
@ -27,34 +26,14 @@ impl<'a> ComputePass for WgpuComputePass<'a> {
|
|||||||
bind_group: BindGroupId,
|
bind_group: BindGroupId,
|
||||||
dynamic_uniform_indices: Option<&[u32]>,
|
dynamic_uniform_indices: Option<&[u32]>,
|
||||||
) {
|
) {
|
||||||
if let Some(bind_group_info) = self
|
bind_group::set_bind_group(
|
||||||
.wgpu_resources
|
Pass::Compute(&mut self.compute_pass),
|
||||||
.bind_groups
|
&self.wgpu_resources,
|
||||||
.get(&bind_group_descriptor_id)
|
index,
|
||||||
{
|
bind_group_descriptor_id,
|
||||||
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
bind_group,
|
||||||
const EMPTY: &[u32] = &[];
|
dynamic_uniform_indices,
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
||||||
|
@ -8,6 +8,7 @@ mod render_resource_context;
|
|||||||
mod renderer;
|
mod renderer;
|
||||||
mod resources;
|
mod resources;
|
||||||
mod type_converter;
|
mod type_converter;
|
||||||
|
mod bind_group;
|
||||||
|
|
||||||
pub use compute_pass::*;
|
pub use compute_pass::*;
|
||||||
pub use render_context::*;
|
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::{
|
use bevy_render2::{
|
||||||
pass::RenderPass,
|
pass::RenderPass,
|
||||||
pipeline::{BindGroupDescriptorId, IndexFormat, PipelineDescriptor, PipelineId},
|
pipeline::{BindGroupDescriptorId, IndexFormat, RenderPipelineDescriptor, PipelineId},
|
||||||
render_resource::{BindGroupId, BufferId},
|
render_resource::{BindGroupId, BufferId},
|
||||||
renderer::RenderContext,
|
renderer::RenderContext,
|
||||||
};
|
};
|
||||||
use bevy_utils::tracing::trace;
|
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -13,7 +12,7 @@ pub struct WgpuRenderPass<'a> {
|
|||||||
pub render_pass: wgpu::RenderPass<'a>,
|
pub render_pass: wgpu::RenderPass<'a>,
|
||||||
pub render_context: &'a WgpuRenderContext,
|
pub render_context: &'a WgpuRenderContext,
|
||||||
pub wgpu_resources: WgpuResourceRefs<'a>,
|
pub wgpu_resources: WgpuResourceRefs<'a>,
|
||||||
pub pipeline_descriptor: Option<&'a PipelineDescriptor>,
|
pub pipeline_descriptor: Option<&'a RenderPipelineDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RenderPass for WgpuRenderPass<'a> {
|
impl<'a> RenderPass for WgpuRenderPass<'a> {
|
||||||
@ -62,34 +61,14 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
|
|||||||
bind_group: BindGroupId,
|
bind_group: BindGroupId,
|
||||||
dynamic_uniform_indices: Option<&[u32]>,
|
dynamic_uniform_indices: Option<&[u32]>,
|
||||||
) {
|
) {
|
||||||
if let Some(bind_group_info) = self
|
bind_group::set_bind_group(
|
||||||
.wgpu_resources
|
Pass::Render(&mut self.render_pass),
|
||||||
.bind_groups
|
&self.wgpu_resources,
|
||||||
.get(&bind_group_descriptor_id)
|
index,
|
||||||
{
|
bind_group_descriptor_id,
|
||||||
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
bind_group,
|
||||||
const EMPTY: &[u32] = &[];
|
dynamic_uniform_indices,
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
fn set_pipeline(&mut self, pipeline: PipelineId) {
|
||||||
|
@ -5,7 +5,7 @@ use crate::{
|
|||||||
use bevy_render2::{
|
use bevy_render2::{
|
||||||
pipeline::{
|
pipeline::{
|
||||||
BindGroupDescriptor, BindGroupDescriptorId, BindingShaderStage, ComputePipelineDescriptor,
|
BindGroupDescriptor, BindGroupDescriptorId, BindingShaderStage, ComputePipelineDescriptor,
|
||||||
PipelineDescriptor, PipelineId,
|
RenderPipelineDescriptor, PipelineId,
|
||||||
},
|
},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
BindGroup, BufferId, BufferInfo, BufferMapMode, RenderResourceBinding, SamplerId,
|
BindGroup, BufferId, BufferInfo, BufferMapMode, RenderResourceBinding, SamplerId,
|
||||||
@ -402,7 +402,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||||||
swap_chain_outputs.clear();
|
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;
|
let layout = &pipeline_descriptor.layout;
|
||||||
for bind_group_descriptor in layout.bind_groups.iter() {
|
for bind_group_descriptor in layout.bind_groups.iter() {
|
||||||
self.create_bind_group_layout(&bind_group_descriptor);
|
self.create_bind_group_layout(&bind_group_descriptor);
|
||||||
|
Loading…
Reference in New Issue
Block a user