Skip to content

Commit

Permalink
Bump bevy from 0.6 to 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Apr 17, 2022
1 parent dfe7671 commit 6bfe89c
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 140 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["game-engines", "rendering"]
exclude = ["assets"]

[dependencies]
bevy = { version = "0.6", default-features = false, features = [
bevy = { version = "0.7", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_pbr"
Expand All @@ -21,12 +21,12 @@ wgpu = { version = "0.12.0", features = ["spirv"] }
itertools = "0.10"

[dev-dependencies]
bevy = { version = "0.6", default-features = false, features = [
bevy = { version = "0.7", default-features = false, features = [
"bevy_gltf",
"jpeg",
"png",
"x11"
] }
bevy_full_throttle = { git = "https://github.com/lightsoutgames/bevy_full_throttle" }
bevy_flycam = "0.6.0"
smooth-bevy-cameras = "0.2.0"
bevy_flycam = "0.7"
smooth-bevy-cameras = "0.3"
46 changes: 27 additions & 19 deletions src/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use bevy::{
prelude::FromWorld,
prelude::*,
render::{
mesh::MeshVertexBufferLayout,
render_asset::RenderAssets,
render_graph::{self, SlotInfo, SlotType},
render_phase::{
sort_phase_system, AddRenderCommand, CachedPipelinePhaseItem, DrawFunctionId,
sort_phase_system, AddRenderCommand, CachedRenderPipelinePhaseItem, DrawFunctionId,
DrawFunctions, EntityPhaseItem, PhaseItem, RenderPhase, SetItemPipeline,
TrackedRenderPass,
},
Expand All @@ -29,7 +30,7 @@ impl Plugin for DeferredPlugin {
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<DeferredPipeline>()
.init_resource::<SpecializedPipelines<DeferredPipeline>>()
.init_resource::<SpecializedMeshPipelines<DeferredPipeline>>()
.init_resource::<DrawFunctions<Deferred<Opaque3d>>>()
.init_resource::<DrawFunctions<Deferred<AlphaMask3d>>>()
.init_resource::<DrawFunctions<Deferred<Transparent3d>>>()
Expand Down Expand Up @@ -82,21 +83,25 @@ impl FromWorld for DeferredPipeline {
}
}

impl SpecializedPipeline for DeferredPipeline {
impl SpecializedMeshPipeline for DeferredPipeline {
type Key = MeshPipelineKey;

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
fn specialize(
&self,
key: Self::Key,
layout: &MeshVertexBufferLayout,
) -> Result<RenderPipelineDescriptor, SpecializedMeshPipelineError> {
let shader = ALBEDO_SHADER_HANDLE.typed::<Shader>();

let mut descriptor = self.mesh_pipeline.specialize(key);
let mut descriptor = self.mesh_pipeline.specialize(key, layout)?;
descriptor.fragment.as_mut().unwrap().shader = shader;
descriptor.layout = Some(vec![
self.mesh_pipeline.view_layout.clone(),
self.material_layout.clone(),
self.mesh_pipeline.mesh_layout.clone(),
]);

descriptor
Ok(descriptor)
}
}

Expand All @@ -108,11 +113,11 @@ pub type DrawDeferredMesh<M> = (
DrawMesh,
);

pub struct Deferred<T: PhaseItem + EntityPhaseItem + CachedPipelinePhaseItem>(T);
pub struct Deferred<T: PhaseItem + EntityPhaseItem + CachedRenderPipelinePhaseItem>(T);

impl<T> PhaseItem for Deferred<T>
where
T: PhaseItem + EntityPhaseItem + CachedPipelinePhaseItem,
T: PhaseItem + EntityPhaseItem + CachedRenderPipelinePhaseItem,
{
type SortKey = T::SortKey;

Expand All @@ -127,18 +132,18 @@ where

impl<T> EntityPhaseItem for Deferred<T>
where
T: PhaseItem + EntityPhaseItem + CachedPipelinePhaseItem,
T: PhaseItem + EntityPhaseItem + CachedRenderPipelinePhaseItem,
{
fn entity(&self) -> Entity {
self.0.entity()
}
}

impl<T> CachedPipelinePhaseItem for Deferred<T>
impl<T> CachedRenderPipelinePhaseItem for Deferred<T>
where
T: PhaseItem + EntityPhaseItem + CachedPipelinePhaseItem,
T: PhaseItem + EntityPhaseItem + CachedRenderPipelinePhaseItem,
{
fn cached_pipeline(&self) -> CachedPipelineId {
fn cached_pipeline(&self) -> CachedRenderPipelineId {
self.0.cached_pipeline()
}
}
Expand All @@ -153,8 +158,8 @@ fn queue_deferred_meshes<M: SpecializedMaterial>(
material_meshes: Query<(&Handle<M>, &Handle<Mesh>, &MeshUniform)>,
render_meshes: Res<RenderAssets<Mesh>>,
render_materials: Res<RenderAssets<M>>,
mut pipelines: ResMut<SpecializedPipelines<DeferredPipeline>>,
mut pipeline_cache: ResMut<RenderPipelineCache>,
mut pipelines: ResMut<SpecializedMeshPipelines<DeferredPipeline>>,
mut pipeline_cache: ResMut<PipelineCache>,
msaa: Res<Msaa>,
mut view_query: Query<(
&ExtractedView,
Expand Down Expand Up @@ -195,9 +200,6 @@ fn queue_deferred_meshes<M: SpecializedMaterial>(
if let Some(mesh) = render_meshes.get(mesh_handle) {
let mesh_z = inverse_view_row_2.dot(mesh_uniform.transform.col(3));

if mesh.has_tangents {
mesh_key |= MeshPipelineKey::VERTEX_TANGENTS;
}
mesh_key |=
MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);

Expand All @@ -206,8 +208,14 @@ fn queue_deferred_meshes<M: SpecializedMaterial>(
mesh_key |= MeshPipelineKey::TRANSPARENT_MAIN_PASS;
}

let pipeline_id =
pipelines.specialize(&mut pipeline_cache, &deferred_pipeline, mesh_key);
let pipeline_id = pipelines
.specialize(
&mut pipeline_cache,
&deferred_pipeline,
mesh_key,
&mesh.layout,
)
.unwrap();

match alpha_mode {
AlphaMode::Opaque => opaque_phase.add(Deferred(Opaque3d {
Expand Down
71 changes: 40 additions & 31 deletions src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use bevy::{
core::FloatOrd,
ecs::system::{lifetimeless::SRes, SystemParamItem},
pbr::{
DrawMesh, MaterialPipeline, MeshPipelineKey, SetMaterialBindGroup, SetMeshBindGroup,
SetMeshViewBindGroup, SpecializedMaterial,
DrawMesh, MaterialPipeline, MaterialPipelineKey, MeshPipelineKey, SetMaterialBindGroup,
SetMeshBindGroup, SetMeshViewBindGroup, SpecializedMaterial,
},
prelude::*,
reflect::TypeUuid,
render::{
mesh::MeshVertexBufferLayout,
render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets},
render_component::ExtractComponentPlugin,
render_graph::{self, SlotInfo, SlotType},
render_phase::{
AddRenderCommand, CachedPipelinePhaseItem, DrawFunctionId, DrawFunctions,
AddRenderCommand, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions,
EntityPhaseItem, PhaseItem, RenderPhase, SetItemPipeline, TrackedRenderPass,
},
render_resource::*,
Expand All @@ -39,7 +40,7 @@ impl Plugin for OverlayPlugin {
render_app
.init_resource::<DrawFunctions<Overlay>>()
.init_resource::<MaterialPipeline<OverlayMaterial>>()
.init_resource::<SpecializedPipelines<MaterialPipeline<OverlayMaterial>>>()
.init_resource::<SpecializedMeshPipelines<MaterialPipeline<OverlayMaterial>>>()
.add_render_command::<Overlay, DrawMaterial<OverlayMaterial>>()
.add_system_to_stage(RenderStage::Extract, extract_screen_overlay)
.add_system_to_stage(RenderStage::Prepare, prepare_screen_overlay)
Expand Down Expand Up @@ -307,7 +308,12 @@ impl SpecializedMaterial for OverlayMaterial {
})
}

fn specialize(_key: Self::Key, descriptor: &mut RenderPipelineDescriptor) {
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
key: Self::Key,
_layout: &MeshVertexBufferLayout,
) -> Result<(), SpecializedMeshPipelineError> {
descriptor.fragment.as_mut().unwrap().targets[0].blend = Some(BlendState {
color: BlendComponent {
src_factor: BlendFactor::One,
Expand All @@ -319,7 +325,8 @@ impl SpecializedMaterial for OverlayMaterial {
dst_factor: BlendFactor::One,
operation: BlendOperation::Add,
},
})
});
Ok(())
}

fn alpha_mode(_material: &<Self as RenderAsset>::PreparedAsset) -> AlphaMode {
Expand Down Expand Up @@ -447,8 +454,8 @@ fn prepare_overlay_phase(
fn queue_material_meshes(
draw_functions: Res<DrawFunctions<Overlay>>,
material_pipeline: Res<MaterialPipeline<OverlayMaterial>>,
mut pipelines: ResMut<SpecializedPipelines<MaterialPipeline<OverlayMaterial>>>,
mut pipeline_cache: ResMut<RenderPipelineCache>,
mut pipelines: ResMut<SpecializedMeshPipelines<MaterialPipeline<OverlayMaterial>>>,
mut pipeline_cache: ResMut<PipelineCache>,
msaa: Res<Msaa>,
render_meshes: Res<RenderAssets<Mesh>>,
render_materials: Res<RenderAssets<OverlayMaterial>>,
Expand All @@ -467,27 +474,29 @@ fn queue_material_meshes(
if let Some(material) = render_materials.get(material) {
let mut mesh_key = mesh_key;
if let Some(mesh) = render_meshes.get(mesh) {
if mesh.has_tangents {
mesh_key |= MeshPipelineKey::VERTEX_TANGENTS;
}
mesh_key |= MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);
mesh_key |= MeshPipelineKey::from_primitive_topology(mesh.primitive_topology)
| MeshPipelineKey::TRANSPARENT_MAIN_PASS;

let material_key = OverlayMaterial::key(material);
let pipeline_id = pipelines
.specialize(
&mut pipeline_cache,
&material_pipeline,
MaterialPipelineKey {
mesh_key,
material_key,
},
&mesh.layout,
)
.unwrap();

phase.add(Overlay {
distance: 0.0,
entity,
pipeline: pipeline_id,
draw_function,
});
}

mesh_key |= MeshPipelineKey::TRANSPARENT_MAIN_PASS;

let specialized_key = OverlayMaterial::key(material);
let pipeline_id = pipelines.specialize(
&mut pipeline_cache,
&material_pipeline,
(mesh_key, specialized_key),
);

phase.add(Overlay {
distance: 0.0,
entity,
pipeline: pipeline_id,
draw_function,
});
}
}
}
Expand All @@ -496,7 +505,7 @@ fn queue_material_meshes(
pub struct Overlay {
distance: f32,
entity: Entity,
pipeline: CachedPipelineId,
pipeline: CachedRenderPipelineId,
draw_function: DrawFunctionId,
}

Expand All @@ -518,8 +527,8 @@ impl EntityPhaseItem for Overlay {
}
}

impl CachedPipelinePhaseItem for Overlay {
fn cached_pipeline(&self) -> CachedPipelineId {
impl CachedRenderPipelinePhaseItem for Overlay {
fn cached_pipeline(&self) -> CachedRenderPipelineId {
self.pipeline
}
}
Expand Down
Loading

0 comments on commit 6bfe89c

Please sign in to comment.