From e19c53ebbd9f281b96ea1677843ae71d69b391ce Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 9 Oct 2024 17:12:27 +0000 Subject: [PATCH] Remove `Handle` trait implementations that are dependent on `Component` (#15749) # Objective - Another step towards #15716 - Remove trait implementations that are dependent on `Handle` being a `Component` ## Solution - Remove unused `ExtractComponent` trait implementation for `Handle` - Remove unused `ExtractInstance` trait implementation for `AssetId` - Although the `ExtractInstance` trait wasn't used, the `AssetId`s were being stored inside of `ExtractedInstances` which has an `ExtractInstance` trait bound on its contents. I've upgraded the `RenderMaterialInstances` type alias to be its own resource, identical to `ExtractedInstances>` to get around that with minimal breakage. ## Testing Tested `many_cubes`, rendering did not explode --- crates/bevy_pbr/src/material.rs | 14 +++++++++++--- crates/bevy_render/src/extract_component.rs | 13 ------------- crates/bevy_render/src/extract_instances.rs | 15 +-------------- 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index ca9b63e95d..903daab5c0 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -18,6 +18,7 @@ use bevy_core_pipeline::{ }; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ + entity::EntityHashMap, prelude::*, system::{lifetimeless::SRes, SystemParamItem}, }; @@ -25,7 +26,6 @@ use bevy_reflect::std_traits::ReflectDefault; use bevy_reflect::Reflect; use bevy_render::{ camera::TemporalJitter, - extract_instances::ExtractedInstances, extract_resource::ExtractResource, mesh::{Mesh3d, MeshVertexBufferLayoutRef, RenderMesh}, render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, @@ -276,7 +276,7 @@ where if let Some(render_app) = app.get_sub_app_mut(RenderApp) { render_app .init_resource::>() - .init_resource::>>() + .init_resource::>() .add_render_command::>() .add_render_command::>() .add_render_command::>() @@ -490,7 +490,15 @@ impl RenderCommand

for SetMaterial } } -pub type RenderMaterialInstances = ExtractedInstances>; +/// Stores all extracted instances of a [`Material`] in the render world. +#[derive(Resource, Deref, DerefMut)] +pub struct RenderMaterialInstances(pub EntityHashMap>); + +impl Default for RenderMaterialInstances { + fn default() -> Self { + Self(Default::default()) + } +} pub const fn alpha_mode_pipeline_key(alpha_mode: AlphaMode, msaa: &Msaa) -> MeshPipelineKey { match alpha_mode { diff --git a/crates/bevy_render/src/extract_component.rs b/crates/bevy_render/src/extract_component.rs index 29c9d229ab..2000046548 100644 --- a/crates/bevy_render/src/extract_component.rs +++ b/crates/bevy_render/src/extract_component.rs @@ -7,12 +7,10 @@ use crate::{ Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; use bevy_app::{App, Plugin}; -use bevy_asset::{Asset, Handle}; use bevy_ecs::{ component::Component, prelude::*, query::{QueryFilter, QueryItem, ReadOnlyQueryData}, - system::lifetimeless::Read, }; use core::{marker::PhantomData, ops::Deref}; @@ -197,17 +195,6 @@ impl Plugin for ExtractComponentPlugin { } } -impl ExtractComponent for Handle { - type QueryData = Read>; - type QueryFilter = (); - type Out = Handle; - - #[inline] - fn extract_component(handle: QueryItem<'_, Self::QueryData>) -> Option { - Some(handle.clone_weak()) - } -} - /// This system extracts all components of the corresponding [`ExtractComponent`], for entities that are synced via [`crate::sync_world::SyncToRenderWorld`]. fn extract_components( mut commands: Commands, diff --git a/crates/bevy_render/src/extract_instances.rs b/crates/bevy_render/src/extract_instances.rs index 37edd85076..24cde74619 100644 --- a/crates/bevy_render/src/extract_instances.rs +++ b/crates/bevy_render/src/extract_instances.rs @@ -7,13 +7,12 @@ use core::marker::PhantomData; use bevy_app::{App, Plugin}; -use bevy_asset::{Asset, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ entity::EntityHashMap, prelude::Entity, query::{QueryFilter, QueryItem, ReadOnlyQueryData}, - system::{lifetimeless::Read, Query, ResMut, Resource}, + system::{Query, ResMut, Resource}, }; use crate::{prelude::ViewVisibility, Extract, ExtractSchedule, RenderApp}; @@ -134,15 +133,3 @@ fn extract_visible( } } } - -impl ExtractInstance for AssetId -where - A: Asset, -{ - type QueryData = Read>; - type QueryFilter = (); - - fn extract(item: QueryItem<'_, Self::QueryData>) -> Option { - Some(item.id()) - } -}