From 66f72dd25bb9e3f3d035f2f14dcbcd25674f968c Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Wed, 25 Oct 2023 10:40:55 +0200 Subject: [PATCH] Use wildcard imports in bevy_pbr (#9847) # Objective - the style of import used by bevy guarantees merge conflicts when any file change - This is especially true when import lists are large, such as in `bevy_pbr` - Merge conflicts are tricky to resolve. This bogs down rendering PRs and makes contributing to bevy's rendering system more difficult than it needs to ## Solution - Use wildcard imports to replace multiline import list in `bevy_pbr` I suspect this is controversial, but I'd like to hear alternatives. Because this is one of many papercuts that makes developing render features near impossible. --- crates/bevy_pbr/src/environment_map/mod.rs | 5 +-- crates/bevy_pbr/src/light.rs | 7 +--- crates/bevy_pbr/src/material.rs | 19 +++-------- crates/bevy_pbr/src/pbr_material.rs | 8 ++--- crates/bevy_pbr/src/prepass/mod.rs | 36 +++------------------ crates/bevy_pbr/src/render/light.rs | 14 ++------ crates/bevy_pbr/src/render/mesh.rs | 17 ++-------- crates/bevy_pbr/src/render/mesh_bindings.rs | 10 ++---- crates/bevy_pbr/src/ssao/mod.rs | 10 +----- crates/bevy_pbr/src/wireframe.rs | 6 ++-- 10 files changed, 25 insertions(+), 107 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index 8cc74a212a396..9e8a1d517585f 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -6,10 +6,7 @@ use bevy_reflect::Reflect; use bevy_render::{ extract_component::{ExtractComponent, ExtractComponentPlugin}, render_asset::RenderAssets, - render_resource::{ - BindGroupLayoutEntry, BindingType, Sampler, SamplerBindingType, Shader, ShaderStages, - TextureSampleType, TextureView, TextureViewDimension, - }, + render_resource::*, texture::{FallbackImageCubemap, Image}, }; diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 7316604ad3f5c..9850d21f8c80e 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -17,12 +17,7 @@ use bevy_render::{ use bevy_transform::{components::GlobalTransform, prelude::Transform}; use bevy_utils::{tracing::warn, HashMap}; -use crate::{ - calculate_cluster_factors, spot_light_projection_matrix, spot_light_view_matrix, - CascadesVisibleEntities, CubeMapFace, CubemapVisibleEntities, ViewClusterBindings, - CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT, CUBE_MAP_FACES, MAX_UNIFORM_BUFFER_POINT_LIGHTS, - POINT_LIGHT_NEAR_Z, -}; +use crate::*; /// A light that emits light in all directions from a central point. /// diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 93d9064dd12a9..5a119c42b5d2d 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -1,8 +1,4 @@ -use crate::{ - render, AlphaMode, DrawMesh, DrawPrepass, EnvironmentMapLight, MeshPipeline, MeshPipelineKey, - PrepassPipelinePlugin, PrepassPlugin, RenderMeshInstances, ScreenSpaceAmbientOcclusionSettings, - SetMeshBindGroup, SetMeshViewBindGroup, Shadow, ShadowFilteringMethod, -}; +use crate::*; use bevy_app::{App, Plugin}; use bevy_asset::{Asset, AssetApp, AssetEvent, AssetId, AssetServer, Assets, Handle}; use bevy_core_pipeline::{ @@ -24,15 +20,8 @@ use bevy_render::{ mesh::{Mesh, MeshVertexBufferLayout}, prelude::Image, render_asset::{prepare_assets, RenderAssets}, - render_phase::{ - AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, - RenderPhase, SetItemPipeline, TrackedRenderPass, - }, - render_resource::{ - AsBindGroup, AsBindGroupError, BindGroup, BindGroupId, BindGroupLayout, - OwnedBindingResource, PipelineCache, RenderPipelineDescriptor, Shader, ShaderRef, - SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, - }, + render_phase::*, + render_resource::*, renderer::RenderDevice, texture::FallbackImage, view::{ExtractedView, Msaa, VisibleEntities}, @@ -42,7 +31,7 @@ use bevy_utils::{tracing::error, HashMap, HashSet}; use std::hash::Hash; use std::marker::PhantomData; -/// Materials are used alongside [`MaterialPlugin`] and [`MaterialMeshBundle`](crate::MaterialMeshBundle) +/// Materials are used alongside [`MaterialPlugin`] and [`MaterialMeshBundle`] /// to spawn entities that are rendered with a specific [`Material`] type. They serve as an easy to use high level /// way to render [`Mesh`] entities with custom shader logic. /// diff --git a/crates/bevy_pbr/src/pbr_material.rs b/crates/bevy_pbr/src/pbr_material.rs index a07c144374310..3b2efef6377a6 100644 --- a/crates/bevy_pbr/src/pbr_material.rs +++ b/crates/bevy_pbr/src/pbr_material.rs @@ -1,8 +1,3 @@ -use crate::{ - deferred::DEFAULT_PBR_DEFERRED_LIGHTING_PASS_ID, AlphaMode, Material, MaterialPipeline, - MaterialPipelineKey, OpaqueRendererMethod, ParallaxMappingMethod, PBR_PREPASS_SHADER_HANDLE, - PBR_SHADER_HANDLE, -}; use bevy_asset::{Asset, Handle}; use bevy_math::Vec4; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; @@ -11,6 +6,9 @@ use bevy_render::{ texture::Image, }; +use crate::deferred::DEFAULT_PBR_DEFERRED_LIGHTING_PASS_ID; +use crate::*; + /// A material with "standard" properties used in PBR lighting /// Standard property values with pictures here /// . diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index 54155ce385a0e..c519f7c32ab58 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -4,18 +4,8 @@ pub use prepass_bindings::*; use bevy_app::{Plugin, PreUpdate}; use bevy_asset::{load_internal_asset, AssetServer, Handle}; -use bevy_core_pipeline::{ - core_3d::CORE_3D_DEPTH_FORMAT, - deferred::{ - AlphaMask3dDeferred, Opaque3dDeferred, DEFERRED_LIGHTING_PASS_ID_FORMAT, - DEFERRED_PREPASS_FORMAT, - }, - prelude::Camera3d, - prepass::{ - AlphaMask3dPrepass, DeferredPrepass, DepthPrepass, MotionVectorPrepass, NormalPrepass, - Opaque3dPrepass, MOTION_VECTOR_PREPASS_FORMAT, NORMAL_PREPASS_FORMAT, - }, -}; +use bevy_core_pipeline::{core_3d::CORE_3D_DEPTH_FORMAT, prelude::Camera3d}; +use bevy_core_pipeline::{deferred::*, prepass::*}; use bevy_ecs::{ prelude::*, system::{ @@ -30,19 +20,8 @@ use bevy_render::{ mesh::MeshVertexBufferLayout, prelude::{Camera, Mesh}, render_asset::RenderAssets, - render_phase::{ - AddRenderCommand, DrawFunctions, PhaseItem, RenderCommand, RenderCommandResult, - RenderPhase, SetItemPipeline, TrackedRenderPass, - }, - render_resource::{ - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingType, BufferBindingType, ColorTargetState, ColorWrites, - CompareFunction, DepthBiasState, DepthStencilState, DynamicUniformBuffer, FragmentState, - FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState, PushConstantRange, - RenderPipelineDescriptor, Shader, ShaderRef, ShaderStages, ShaderType, - SpecializedMeshPipeline, SpecializedMeshPipelineError, SpecializedMeshPipelines, - StencilFaceState, StencilState, VertexState, - }, + render_phase::*, + render_resource::*, renderer::{RenderDevice, RenderQueue}, view::{ExtractedView, Msaa, ViewUniform, ViewUniformOffset, ViewUniforms, VisibleEntities}, Extract, ExtractSchedule, Render, RenderApp, RenderSet, @@ -50,12 +29,7 @@ use bevy_render::{ use bevy_transform::prelude::GlobalTransform; use bevy_utils::tracing::error; -use crate::{ - prepare_materials, setup_morph_and_skinning_defs, AlphaMode, DrawMesh, Material, - MaterialPipeline, MaterialPipelineKey, MeshLayouts, MeshPipeline, MeshPipelineKey, - OpaqueRendererMethod, RenderMaterialInstances, RenderMaterials, RenderMeshInstances, - SetMaterialBindGroup, SetMeshBindGroup, -}; +use crate::*; use std::{hash::Hash, marker::PhantomData}; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 258ea59f09065..62a7367520756 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1,11 +1,3 @@ -use crate::{ - directional_light_order, point_light_order, AlphaMode, AmbientLight, Cascade, - CascadeShadowConfig, Cascades, CascadesVisibleEntities, Clusters, CubemapVisibleEntities, - DirectionalLight, DirectionalLightShadowMap, DrawPrepass, EnvironmentMapLight, - GlobalVisiblePointLights, Material, MaterialPipelineKey, MeshPipeline, MeshPipelineKey, - PointLight, PointLightShadowMap, PrepassPipeline, RenderMaterialInstances, RenderMaterials, - RenderMeshInstances, SpotLight, VisiblePointLights, -}; use bevy_core_pipeline::core_3d::{Transparent3d, CORE_3D_DEPTH_FORMAT}; use bevy_ecs::prelude::*; use bevy_math::{Mat4, UVec3, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; @@ -15,9 +7,7 @@ use bevy_render::{ mesh::Mesh, render_asset::RenderAssets, render_graph::{Node, NodeRunError, RenderGraphContext}, - render_phase::{ - CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem, RenderPhase, - }, + render_phase::*, render_resource::*, renderer::{RenderContext, RenderDevice, RenderQueue}, texture::*, @@ -32,6 +22,8 @@ use bevy_utils::{ }; use std::{hash::Hash, num::NonZeroU64, ops::Range}; +use crate::*; + #[derive(Component)] pub struct ExtractedPointLight { color: Color, diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index cc5a1294417f7..758f86db10230 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -1,10 +1,3 @@ -use crate::{ - generate_view_layouts, prepare_mesh_view_bind_groups, MaterialBindGroupId, - MeshPipelineViewLayout, MeshPipelineViewLayoutKey, MeshViewBindGroup, NotShadowCaster, - NotShadowReceiver, PreviousGlobalTransform, Shadow, ViewFogUniformOffset, - ViewLightsUniformOffset, CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT, MAX_CASCADES_PER_LIGHT, - MAX_DIRECTIONAL_LIGHTS, -}; use bevy_app::{Plugin, PostUpdate}; use bevy_asset::{load_internal_asset, AssetId, Handle}; use bevy_core_pipeline::{ @@ -23,17 +16,12 @@ use bevy_render::{ batch_and_prepare_render_phase, write_batched_instance_buffer, GetBatchData, NoAutomaticBatching, }, - mesh::{ - GpuBufferInfo, InnerMeshVertexBufferLayout, Mesh, MeshVertexBufferLayout, - VertexAttributeDescriptor, - }, + mesh::*, render_asset::RenderAssets, render_phase::{PhaseItem, RenderCommand, RenderCommandResult, TrackedRenderPass}, render_resource::*, renderer::{RenderDevice, RenderQueue}, - texture::{ - BevyDefault, DefaultImageSampler, GpuImage, Image, ImageSampler, TextureFormatPixelInfo, - }, + texture::*, view::{ViewTarget, ViewUniformOffset, ViewVisibility}, Extract, ExtractSchedule, Render, RenderApp, RenderSet, }; @@ -58,6 +46,7 @@ use crate::render::{ skin::{extract_skins, no_automatic_skin_batching, prepare_skins, SkinUniform}, MeshLayouts, }; +use crate::*; use super::skin::SkinIndices; diff --git a/crates/bevy_pbr/src/render/mesh_bindings.rs b/crates/bevy_pbr/src/render/mesh_bindings.rs index bf45fd12b8c83..df935e1805c8a 100644 --- a/crates/bevy_pbr/src/render/mesh_bindings.rs +++ b/crates/bevy_pbr/src/render/mesh_bindings.rs @@ -1,13 +1,7 @@ //! Bind group layout related definitions for the mesh pipeline. use bevy_math::Mat4; -use bevy_render::{ - mesh::morph::MAX_MORPH_WEIGHTS, - render_resource::{ - BindGroup, BindGroupLayout, BindGroupLayoutDescriptor, BindingResource, Buffer, TextureView, - }, - renderer::RenderDevice, -}; +use bevy_render::{mesh::morph::MAX_MORPH_WEIGHTS, render_resource::*, renderer::RenderDevice}; use crate::render::skin::MAX_JOINTS; @@ -67,7 +61,7 @@ mod layout_entry { } } } -/// Individual [`BindGroupEntry`](bevy_render::render_resource::BindGroupEntry) +/// Individual [`BindGroupEntry`] /// for bind groups. mod entry { use super::{JOINT_BUFFER_SIZE, MORPH_BUFFER_SIZE}; diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 59fb57cfac3c6..6ad1d0116743a 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -20,15 +20,7 @@ use bevy_render::{ globals::{GlobalsBuffer, GlobalsUniform}, prelude::Camera, render_graph::{NodeRunError, RenderGraphApp, RenderGraphContext, ViewNode, ViewNodeRunner}, - render_resource::{ - AddressMode, BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor, - BindGroupLayoutEntry, BindingType, BufferBindingType, CachedComputePipelineId, - ComputePassDescriptor, ComputePipelineDescriptor, Extent3d, FilterMode, PipelineCache, - Sampler, SamplerBindingType, SamplerDescriptor, Shader, ShaderDefVal, ShaderStages, - ShaderType, SpecializedComputePipeline, SpecializedComputePipelines, StorageTextureAccess, - TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureUsages, - TextureView, TextureViewDescriptor, TextureViewDimension, - }, + render_resource::*, renderer::{RenderAdapter, RenderContext, RenderDevice, RenderQueue}, texture::{CachedTexture, TextureCache}, view::{Msaa, ViewUniform, ViewUniformOffset, ViewUniforms}, diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index bedefbb786be8..2d533e7e52f5c 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -7,10 +7,8 @@ use bevy_render::{ color::Color, extract_resource::ExtractResource, mesh::{Mesh, MeshVertexBufferLayout}, - prelude::Shader, - render_resource::{ - AsBindGroup, PolygonMode, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError, - }, + prelude::*, + render_resource::*, }; pub const WIREFRAME_SHADER_HANDLE: Handle = Handle::weak_from_u128(192598014480025766);