Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline keys #10333

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
aeff65d
wip
robtfm Oct 27, 2023
9ad338b
before any
robtfm Oct 28, 2023
929127f
cleaner macros
robtfm Oct 28, 2023
5d5a9ec
dyn working
robtfm Oct 28, 2023
c72e85d
renames
robtfm Oct 29, 2023
814ab24
packed key
robtfm Oct 29, 2023
a325075
u64 key
robtfm Oct 29, 2023
78836e6
specialize use PipelineKey
robtfm Oct 30, 2023
5315299
move shader defs to fn
robtfm Oct 30, 2023
73a868b
fmt
robtfm Oct 30, 2023
1daffef
more keys
robtfm Oct 31, 2023
0e8e987
use keys for PbrMaterial
robtfm Oct 31, 2023
4abf872
fix deferred, clean enum macro, remove num_enum
robtfm Nov 1, 2023
5daa254
fix instancing
robtfm Nov 1, 2023
27e758a
move key store into pipeline cache
robtfm Nov 1, 2023
6e97ceb
fix load prepass normals
robtfm Nov 1, 2023
147456d
cleanup
robtfm Nov 1, 2023
57477a3
fix morph targets and instancing
robtfm Nov 1, 2023
934226a
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Nov 1, 2023
5e85e35
update for ssst
robtfm Nov 1, 2023
d06e50b
ci
robtfm Nov 1, 2023
85e4765
ci
robtfm Nov 1, 2023
fd97008
NewMaterialPipelineKey -> MaterialPipelineKey
robtfm Nov 2, 2023
9bd5ed6
new_packed_key -> packed_key
robtfm Nov 2, 2023
dfaafc4
comments and cleanup
robtfm Nov 3, 2023
2a6e8f1
remove redundant key structs
robtfm Nov 3, 2023
4824adc
ci
robtfm Nov 3, 2023
a9bb5a3
add size check
robtfm Nov 3, 2023
7383e0a
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Nov 3, 2023
2fc507d
ci
robtfm Nov 3, 2023
c0ef271
use BITS i/o size_of*8
robtfm Nov 3, 2023
37ec242
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Nov 3, 2023
23e7d7f
merge merge
robtfm Nov 3, 2023
b5bf8a5
3d gizmos
robtfm Nov 10, 2023
ca76e01
pbrviewkey -> struct
robtfm Nov 10, 2023
fb244e9
update deferred and remove old MeshPipelineKey
robtfm Nov 10, 2023
c0b6c92
rename NewMeshPipelineKey -> MeshPipelineKey
robtfm Nov 10, 2023
02e2014
cleanup skybox
robtfm Nov 10, 2023
5ce49ef
cleanup taa & tonemapping
robtfm Nov 10, 2023
544c414
rest of the pipelines
robtfm Nov 10, 2023
f5c3981
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Nov 11, 2023
7ae539f
ui material
robtfm Nov 11, 2023
aad13e1
fmt
robtfm Nov 11, 2023
1afd1fe
remove bevy_internal
robtfm Nov 11, 2023
7cb67ce
flatten Material2dPipelineKey
robtfm Nov 13, 2023
ce6007d
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Nov 17, 2023
f675a3b
Merge remote-tracking branch 'upstream/main' into pipeline-keys
robtfm Dec 3, 2023
934ca77
debug_assert
robtfm Dec 3, 2023
74d0ee3
ci
robtfm Dec 3, 2023
8c9da2e
SSTQKey -> SSTQ
robtfm Dec 3, 2023
7d2b0f2
comment MeshPipelineKey
robtfm Dec 3, 2023
fc1dae3
phase comment
robtfm Dec 3, 2023
4fea970
assert_eq -> debug_assert_eq
robtfm Dec 3, 2023
9c0fb76
remove packed type check fns
robtfm Dec 3, 2023
0b58e58
texture_format shader_defs
robtfm Dec 3, 2023
28ed8f0
comment Mesh2dPipelineKey
robtfm Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/bevy_core_pipeline/src/blit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use bevy_app::{App, Plugin};
use bevy_asset::{load_internal_asset, Handle};
use bevy_ecs::prelude::*;
use bevy_render::{render_resource::*, renderer::RenderDevice, RenderApp};
use bevy_render::{
pipeline_keys::PipelineKey, render_resource::*, renderer::RenderDevice, view::MsaaKey,
RenderApp,
};

use crate::fullscreen_vertex_shader::fullscreen_shader_vertex_state;

Expand Down Expand Up @@ -68,17 +71,17 @@ impl FromWorld for BlitPipeline {
}
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
#[derive(PipelineKey, Clone, Copy, Debug)]
pub struct BlitPipelineKey {
pub texture_format: TextureFormat,
pub blend_state: Option<BlendState>,
pub samples: u32,
pub msaa: MsaaKey,
}

impl SpecializedRenderPipeline for BlitPipeline {
type Key = BlitPipelineKey;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(&self, key: PipelineKey<Self::Key>) -> RenderPipelineDescriptor {
RenderPipelineDescriptor {
label: Some("blit pipeline".into()),
layout: vec![self.texture_bind_group.clone()],
Expand All @@ -96,7 +99,7 @@ impl SpecializedRenderPipeline for BlitPipeline {
primitive: PrimitiveState::default(),
depth_stencil: None,
multisample: MultisampleState {
count: key.samples,
count: key.msaa.samples(),
..Default::default()
},
push_constant_ranges: Vec::new(),
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_core_pipeline/src/bloom/downsampling_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_ecs::{
world::{FromWorld, World},
};
use bevy_math::Vec4;
use bevy_render::{render_resource::*, renderer::RenderDevice};
use bevy_render::{pipeline_keys::PipelineKey, render_resource::*, renderer::RenderDevice};

#[derive(Component)]
pub struct BloomDownsamplingPipelineIds {
Expand All @@ -21,7 +21,7 @@ pub struct BloomDownsamplingPipeline {
pub sampler: Sampler,
}

#[derive(PartialEq, Eq, Hash, Clone)]
#[derive(PipelineKey, PartialEq, Eq, Hash, Clone, Debug)]
pub struct BloomDownsamplingPipelineKeys {
prefilter: bool,
first_downsample: bool,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl FromWorld for BloomDownsamplingPipeline {
impl SpecializedRenderPipeline for BloomDownsamplingPipeline {
type Key = BloomDownsamplingPipelineKeys;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(&self, key: PipelineKey<Self::Key>) -> RenderPipelineDescriptor {
let layout = vec![self.bind_group_layout.clone()];

let entry_point = if key.first_downsample {
Expand Down Expand Up @@ -160,19 +160,19 @@ pub fn prepare_downsampling_pipeline(
let pipeline_id = pipelines.specialize(
&pipeline_cache,
&pipeline,
BloomDownsamplingPipelineKeys {
pipeline_cache.pack_key(&BloomDownsamplingPipelineKeys {
prefilter,
first_downsample: false,
},
}),
);

let pipeline_first_id = pipelines.specialize(
&pipeline_cache,
&pipeline,
BloomDownsamplingPipelineKeys {
pipeline_cache.pack_key(&BloomDownsamplingPipelineKeys {
prefilter,
first_downsample: true,
},
}),
);

commands
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_core_pipeline/src/bloom/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use super::downsampling_pipeline::BloomUniforms;
use bevy_ecs::{prelude::Component, query::QueryItem, reflect::ReflectComponent};
use bevy_math::{URect, UVec4, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
use bevy_render::{
extract_component::ExtractComponent, pipeline_keys::PipelineKey, prelude::Camera,
};

/// Applies a bloom effect to an HDR-enabled 2d or 3d camera.
///
Expand Down Expand Up @@ -175,7 +177,8 @@ pub struct BloomPrefilterSettings {
pub threshold_softness: f32,
}

#[derive(Clone, Reflect, PartialEq, Eq, Hash, Copy)]
#[derive(PipelineKey, Clone, Reflect, PartialEq, Eq, Hash, Copy, Debug)]
#[repr(u8)]
pub enum BloomCompositeMode {
EnergyConserving,
Additive,
Expand Down
16 changes: 9 additions & 7 deletions crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use bevy_ecs::{
system::{Commands, Query, Res, ResMut, Resource},
world::{FromWorld, World},
};
use bevy_render::{render_resource::*, renderer::RenderDevice, view::ViewTarget};
use bevy_render::{
pipeline_keys::PipelineKey, render_resource::*, renderer::RenderDevice, view::ViewTarget,
};

#[derive(Component)]
pub struct UpsamplingPipelineIds {
Expand All @@ -21,7 +23,7 @@ pub struct BloomUpsamplingPipeline {
pub bind_group_layout: BindGroupLayout,
}

#[derive(PartialEq, Eq, Hash, Clone)]
#[derive(PipelineKey, PartialEq, Eq, Hash, Clone, Debug)]
pub struct BloomUpsamplingPipelineKeys {
composite_mode: BloomCompositeMode,
final_pipeline: bool,
Expand Down Expand Up @@ -74,7 +76,7 @@ impl FromWorld for BloomUpsamplingPipeline {
impl SpecializedRenderPipeline for BloomUpsamplingPipeline {
type Key = BloomUpsamplingPipelineKeys;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(&self, key: PipelineKey<Self::Key>) -> RenderPipelineDescriptor {
let texture_format = if key.final_pipeline {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
Expand Down Expand Up @@ -153,19 +155,19 @@ pub fn prepare_upsampling_pipeline(
let pipeline_id = pipelines.specialize(
&pipeline_cache,
&pipeline,
BloomUpsamplingPipelineKeys {
pipeline_cache.pack_key(&BloomUpsamplingPipelineKeys {
composite_mode: settings.composite_mode,
final_pipeline: false,
},
}),
);

let pipeline_final_id = pipelines.specialize(
&pipeline_cache,
&pipeline,
BloomUpsamplingPipelineKeys {
pipeline_cache.pack_key(&BloomUpsamplingPipelineKeys {
composite_mode: settings.composite_mode,
final_pipeline: true,
},
}),
);

commands.entity(entity).insert(UpsamplingPipelineIds {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_reflect::Reflect;
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin},
pipeline_keys::PipelineKey,
prelude::Camera,
render_graph::RenderGraphApp,
render_resource::*,
Expand Down Expand Up @@ -212,7 +213,7 @@ impl FromWorld for CASPipeline {
}
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
#[derive(PipelineKey, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct CASPipelineKey {
texture_format: TextureFormat,
denoise: bool,
Expand All @@ -221,7 +222,7 @@ pub struct CASPipelineKey {
impl SpecializedRenderPipeline for CASPipeline {
type Key = CASPipelineKey;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(&self, key: PipelineKey<Self::Key>) -> RenderPipelineDescriptor {
let mut shader_defs = vec![];
if key.denoise {
shader_defs.push("RCAS_DENOISE".into());
Expand Down Expand Up @@ -259,14 +260,14 @@ fn prepare_cas_pipelines(
let pipeline_id = pipelines.specialize(
&pipeline_cache,
&sharpening_pipeline,
CASPipelineKey {
pipeline_cache.pack_key(&CASPipelineKey {
denoise: cas_settings.0,
texture_format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
},
}),
);

commands.entity(entity).insert(ViewCASPipeline(pipeline_id));
Expand Down
8 changes: 5 additions & 3 deletions crates/bevy_core_pipeline/src/core_3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use bevy_ecs::prelude::*;
use bevy_render::{
camera::{Camera, ExtractedCamera},
extract_component::ExtractComponentPlugin,
pipeline_keys::AddPipelineKey,
prelude::Msaa,
render_graph::{EmptyNode, RenderGraphApp, ViewNodeRunner},
render_phase::{
Expand All @@ -69,8 +70,8 @@ use crate::{
},
prepass::{
node::PrepassNode, AlphaMask3dPrepass, DeferredPrepass, DepthPrepass, MotionVectorPrepass,
NormalPrepass, Opaque3dPrepass, ViewPrepassTextures, MOTION_VECTOR_PREPASS_FORMAT,
NORMAL_PREPASS_FORMAT,
NormalPrepass, Opaque3dPrepass, PrepassKey, ViewPrepassTextures,
MOTION_VECTOR_PREPASS_FORMAT, NORMAL_PREPASS_FORMAT,
},
skybox::SkyboxPlugin,
tonemapping::TonemappingNode,
Expand Down Expand Up @@ -165,7 +166,8 @@ impl Plugin for Core3dPlugin {
END_MAIN_PASS_POST_PROCESSING,
UPSCALING,
],
);
)
.register_system_key::<PrepassKey, With<ExtractedView>>();
}
}

Expand Down
12 changes: 7 additions & 5 deletions crates/bevy_core_pipeline/src/fxaa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy_ecs::prelude::*;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render::{
extract_component::{ExtractComponent, ExtractComponentPlugin},
pipeline_keys::PipelineKey,
prelude::Camera,
render_graph::RenderGraphApp,
render_graph::ViewNodeRunner,
Expand All @@ -24,8 +25,9 @@ mod node;

pub use node::FxaaNode;

#[derive(Reflect, Eq, PartialEq, Hash, Clone, Copy)]
#[derive(PipelineKey, Reflect, Eq, PartialEq, Hash, Clone, Copy, Debug)]
#[reflect(PartialEq, Hash)]
#[repr(u8)]
pub enum Sensitivity {
Low,
Medium,
Expand Down Expand Up @@ -162,7 +164,7 @@ pub struct CameraFxaaPipeline {
pub pipeline_id: CachedRenderPipelineId,
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
#[derive(PipelineKey, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct FxaaPipelineKey {
edge_threshold: Sensitivity,
edge_threshold_min: Sensitivity,
Expand All @@ -172,7 +174,7 @@ pub struct FxaaPipelineKey {
impl SpecializedRenderPipeline for FxaaPipeline {
type Key = FxaaPipelineKey;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(&self, key: PipelineKey<Self::Key>) -> RenderPipelineDescriptor {
RenderPipelineDescriptor {
label: Some("fxaa".into()),
layout: vec![self.texture_bind_group.clone()],
Expand Down Expand Up @@ -212,15 +214,15 @@ pub fn prepare_fxaa_pipelines(
let pipeline_id = pipelines.specialize(
&pipeline_cache,
&fxaa_pipeline,
FxaaPipelineKey {
pipeline_cache.pack_key(&FxaaPipelineKey {
edge_threshold: fxaa.edge_threshold,
edge_threshold_min: fxaa.edge_threshold_min,
texture_format: if view.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
},
},
}),
);

commands
Expand Down
13 changes: 9 additions & 4 deletions crates/bevy_core_pipeline/src/msaa_writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use bevy_render::{
camera::ExtractedCamera,
pipeline_keys::PipelineKeys,
render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext},
render_resource::BindGroupEntries,
renderer::RenderContext,
Expand Down Expand Up @@ -117,21 +118,25 @@ fn prepare_msaa_writeback_pipelines(
pipeline_cache: Res<PipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<BlitPipeline>>,
blit_pipeline: Res<BlitPipeline>,
view_targets: Query<(Entity, &ViewTarget, &ExtractedCamera)>,
view_targets: Query<(Entity, &ViewTarget, &ExtractedCamera, &PipelineKeys)>,
msaa: Res<Msaa>,
) {
for (entity, view_target, camera) in view_targets.iter() {
for (entity, view_target, camera, keys) in view_targets.iter() {
// only do writeback if writeback is enabled for the camera and this isn't the first camera in the target,
// as there is nothing to write back for the first camera.
if msaa.samples() > 1 && camera.msaa_writeback && camera.sorted_camera_index_for_target > 0
{
let key = BlitPipelineKey {
texture_format: view_target.main_texture_format(),
samples: msaa.samples(),
msaa: *keys.get_key(&pipeline_cache).unwrap(),
blend_state: None,
};

let pipeline = pipelines.specialize(&pipeline_cache, &blit_pipeline, key);
let pipeline = pipelines.specialize(
&pipeline_cache,
&blit_pipeline,
pipeline_cache.pack_key(&key),
);
commands
.entity(entity)
.insert(MsaaWritebackBlitPipeline(pipeline));
Expand Down
Loading