diff --git a/crates/bevy_tape_drive_solari/src/lib.rs b/crates/bevy_tape_drive_solari/src/lib.rs index 0b2e731..bd9e629 100644 --- a/crates/bevy_tape_drive_solari/src/lib.rs +++ b/crates/bevy_tape_drive_solari/src/lib.rs @@ -1,4 +1,5 @@ #![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] +#![recursion_limit = "256"] //! Provides raytraced lighting. //! diff --git a/crates/bevy_tape_drive_solari/src/pathtracer/extract.rs b/crates/bevy_tape_drive_solari/src/pathtracer/extract.rs index 19db4f3..cfd21aa 100644 --- a/crates/bevy_tape_drive_solari/src/pathtracer/extract.rs +++ b/crates/bevy_tape_drive_solari/src/pathtracer/extract.rs @@ -1,11 +1,11 @@ -use super::{prepare::PathtracerAccumulationTexture, Pathtracer}; +use super::{Pathtracer, prepare::PathtracerAccumulationTexture}; use bevy_camera::Camera; use bevy_ecs::{ change_detection::DetectChanges, system::{Commands, Query}, world::Ref, }; -use bevy_render::{sync_world::RenderEntity, Extract}; +use bevy_render::{Extract, sync_world::RenderEntity}; use bevy_transform::components::GlobalTransform; pub fn extract_pathtracer( diff --git a/crates/bevy_tape_drive_solari/src/pathtracer/mod.rs b/crates/bevy_tape_drive_solari/src/pathtracer/mod.rs index 0528e9a..6025849 100644 --- a/crates/bevy_tape_drive_solari/src/pathtracer/mod.rs +++ b/crates/bevy_tape_drive_solari/src/pathtracer/mod.rs @@ -2,7 +2,7 @@ mod extract; mod node; mod prepare; -use crate::{scene::RaytracingSceneBindings, SolariPlugins}; +use crate::{SolariPlugins, scene::RaytracingSceneBindings}; use bevy_app::{App, Plugin, PostUpdate}; use bevy_asset::embedded_asset; use bevy_camera::Hdr; @@ -19,10 +19,10 @@ use bevy_ecs::{ system::{Commands, Query}, }; use bevy_light::AtmosphereEnvironmentMapLight; -use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +use bevy_reflect::{Reflect, std_traits::ReflectDefault}; use bevy_render::{ - init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup, - RenderSystems, + ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems, init_gpu_resource, + renderer::RenderDevice, }; use extract::extract_pathtracer; use node::{init_pathtracer_pipelines, pathtracer}; diff --git a/crates/bevy_tape_drive_solari/src/pathtracer/node.rs b/crates/bevy_tape_drive_solari/src/pathtracer/node.rs index be638b0..7a88c40 100644 --- a/crates/bevy_tape_drive_solari/src/pathtracer/node.rs +++ b/crates/bevy_tape_drive_solari/src/pathtracer/node.rs @@ -1,14 +1,14 @@ -use super::{prepare::PathtracerAccumulationTexture, Pathtracer}; +use super::{Pathtracer, prepare::PathtracerAccumulationTexture}; use crate::scene::RaytracingSceneBindings; -use bevy_asset::{load_embedded_asset, AssetServer}; +use bevy_asset::{AssetServer, load_embedded_asset}; use bevy_ecs::{prelude::*, resource::Resource, system::Commands}; use bevy_render::{ camera::ExtractedCamera, render_resource::{ - binding_types::{texture_storage_2d, uniform_buffer}, BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries, CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, ImageSubresourceRange, PipelineCache, ShaderStages, StorageTextureAccess, TextureFormat, + binding_types::{texture_storage_2d, uniform_buffer}, }, renderer::{RenderContext, RenderDevice, ViewQuery}, view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms}, diff --git a/crates/bevy_tape_drive_solari/src/realtime/extract.rs b/crates/bevy_tape_drive_solari/src/realtime/extract.rs index d2c1212..39e156f 100644 --- a/crates/bevy_tape_drive_solari/src/realtime/extract.rs +++ b/crates/bevy_tape_drive_solari/src/realtime/extract.rs @@ -1,8 +1,8 @@ -use super::{prepare::SolariLightingResources, SolariLighting}; +use super::{SolariLighting, prepare::SolariLightingResources}; use bevy_camera::Camera; use bevy_ecs::system::{Commands, ResMut}; use bevy_pbr::deferred::SkipDeferredLighting; -use bevy_render::{sync_world::RenderEntity, MainWorld}; +use bevy_render::{MainWorld, sync_world::RenderEntity}; pub fn extract_solari_lighting(mut main_world: ResMut, mut commands: Commands) { let mut cameras_3d = main_world.query::<(RenderEntity, &Camera, Option<&mut SolariLighting>)>(); diff --git a/crates/bevy_tape_drive_solari/src/realtime/mod.rs b/crates/bevy_tape_drive_solari/src/realtime/mod.rs index 28c2983..f34b8df 100644 --- a/crates/bevy_tape_drive_solari/src/realtime/mod.rs +++ b/crates/bevy_tape_drive_solari/src/realtime/mod.rs @@ -3,8 +3,8 @@ mod node; mod prepare; use crate::{ - scene::{prepare_raytracing_scene_resources, RaytracingSceneBindings}, SolariPlugins, + scene::{RaytracingSceneBindings, prepare_raytracing_scene_resources}, }; use bevy_app::{App, Plugin, PostUpdate}; use bevy_asset::embedded_asset; @@ -27,10 +27,10 @@ use bevy_ecs::{ }; use bevy_light::AtmosphereEnvironmentMapLight; use bevy_pbr::DefaultOpaqueRendererMethod; -use bevy_reflect::{std_traits::ReflectDefault, Reflect}; +use bevy_reflect::{Reflect, std_traits::ReflectDefault}; use bevy_render::{ - init_gpu_resource, renderer::RenderDevice, ExtractSchedule, Render, RenderApp, RenderStartup, - RenderSystems, + ExtractSchedule, Render, RenderApp, RenderStartup, RenderSystems, init_gpu_resource, + renderer::RenderDevice, }; use bevy_shader::load_shader_library; use extract::extract_solari_lighting; diff --git a/crates/bevy_tape_drive_solari/src/realtime/node.rs b/crates/bevy_tape_drive_solari/src/realtime/node.rs index 7c2ee5e..9a8464f 100644 --- a/crates/bevy_tape_drive_solari/src/realtime/node.rs +++ b/crates/bevy_tape_drive_solari/src/realtime/node.rs @@ -1,27 +1,27 @@ use super::prepare::{ - SolariLightingResources, LIGHT_TILE_BLOCKS, WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET, + LIGHT_TILE_BLOCKS, SolariLightingResources, WORLD_CACHE_ACTIVE_CELLS_COUNT_OFFSET, WORLD_CACHE_SIZE, }; use crate::scene::RaytracingSceneBindings; #[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] use bevy_anti_alias::dlss::ViewDlssRayReconstructionTextures; -use bevy_asset::{load_embedded_asset, AssetServer, Handle}; +use bevy_asset::{AssetServer, Handle, load_embedded_asset}; use bevy_core_pipeline::prepass::{ - PreviousViewData, PreviousViewUniformOffset, PreviousViewUniforms, ViewPrepassTextures, - MOTION_VECTOR_PREPASS_FORMAT, + MOTION_VECTOR_PREPASS_FORMAT, PreviousViewData, PreviousViewUniformOffset, + PreviousViewUniforms, ViewPrepassTextures, }; use bevy_ecs::{prelude::*, resource::Resource, system::Commands}; use bevy_render::{ diagnostic::RecordDiagnostics as _, render_resource::{ - binding_types::{ - storage_buffer_sized, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer, - uniform_buffer_sized, - }, BindGroupEntries, BindGroupLayoutDescriptor, BindGroupLayoutEntries, CachedComputePipelineId, ComputePassDescriptor, ComputePipelineDescriptor, LoadOp, PipelineCache, RenderPassDescriptor, ShaderStages, StorageTextureAccess, TextureFormat, TextureFormatFeatureFlags, TextureSampleType, + binding_types::{ + storage_buffer_sized, texture_2d, texture_depth_2d, texture_storage_2d, uniform_buffer, + uniform_buffer_sized, + }, }, renderer::{RenderAdapter, RenderContext, RenderDevice, ViewQuery}, view::{ViewTarget, ViewUniform, ViewUniformOffset, ViewUniforms}, diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/assets.rs b/crates/bevy_tape_drive_solari/src/scene/binder/assets.rs index 9b0a76b..cb6ec16 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/assets.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/assets.rs @@ -1,7 +1,7 @@ use super::{ + StandardMaterialAssets, allocator::{RetainedBindingArray, SlotAllocator}, instances::InstanceState, - StandardMaterialAssets, }; use bevy_asset::AssetId; use bevy_color::{ColorToComponents, LinearRgba}; diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/bind_group.rs b/crates/bevy_tape_drive_solari/src/scene/binder/bind_group.rs index 70b9c81..02b3fb4 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/bind_group.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/bind_group.rs @@ -37,9 +37,9 @@ impl BindGroupCacheState { // Binding arrays are dense, so freed slots still need something valid // bound into them let dummy_buffer = render_device.create_buffer(&BufferDescriptor { - label: Some("solari_dummy_binding_array_buffer"), - size: 48, - usage: BufferUsages::STORAGE, + label: Some("solari_dummy_binding_array_buffer"), + size: 48, + usage: BufferUsages::STORAGE, mapped_at_creation: false, }); @@ -179,7 +179,7 @@ impl RaytracingSceneBindings { let light_sources = BufferBinding { buffer: self.lights.sources.buffer().unwrap(), offset: 0, - size: BufferSize::new( + size: BufferSize::new( self.lights.index.len() as u64 * size_of::() as u64, ), }; @@ -341,7 +341,7 @@ pub fn prepare_raytracing_scene_bind_group( #[derive(ShaderType, Default)] pub struct GpuEnvironmentMapLight { pub light_from_world: Mat3, - pub intensity: f32, + pub intensity: f32, } fn prepare_environment_map_light<'a>( @@ -364,7 +364,7 @@ fn prepare_environment_map_light<'a>( light_from_world: Mat3::from_quat( extracted_environment_map_light.rotation.inverse(), ), - intensity: extracted_environment_map_light.intensity, + intensity: extracted_environment_map_light.intensity, }, ), None => ( diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/instances.rs b/crates/bevy_tape_drive_solari/src/scene/binder/instances.rs index d6e5cdc..9d70734 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/instances.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/instances.rs @@ -35,20 +35,20 @@ pub const MAX_TAPE_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap(); #[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] #[repr(C)] pub struct GpuInstanceGeometryIds { - vertex_buffer_id: u32, + vertex_buffer_id: u32, vertex_buffer_offset: u32, - index_buffer_id: u32, - index_buffer_offset: u32, - triangle_count: u32, + index_buffer_id: u32, + index_buffer_offset: u32, + triangle_count: u32, } #[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)] #[repr(C)] pub struct GpuInstanceTapeIds { - aabb_buffer_id: u32, - aabb_buffer_offset: u32, - aabb_count: u32, - metadata_buffer_id: u32, + aabb_buffer_id: u32, + aabb_buffer_offset: u32, + aabb_count: u32, + metadata_buffer_id: u32, metadata_buffer_offset: u32, } @@ -100,27 +100,27 @@ pub enum BlasKey { /// Everything tracked per raytracing instance. #[derive(Clone, Copy)] struct MeshInstance { - slot: u32, - mesh: AssetId, + slot: u32, + mesh: AssetId, material: AssetId, - opacity: MeshBlasOpacity, - buffers: Option<(BufferId, BufferId)>, + opacity: MeshBlasOpacity, + buffers: Option<(BufferId, BufferId)>, } /// Everything tracked per raytracing instance. #[derive(Clone, Copy)] struct TapeInstance { - slot: u32, - tape: AssetId, + slot: u32, + tape: AssetId, material: AssetId, - opacity: TapeBlasOpacity, - buffers: Option<(BufferId, BufferId)>, + opacity: TapeBlasOpacity, + buffers: Option<(BufferId, BufferId)>, } impl MeshInstance { fn blas_key(&self) -> MeshBlasKey { MeshBlasKey { - mesh: self.mesh, + mesh: self.mesh, opacity: self.opacity, } } @@ -129,7 +129,7 @@ impl MeshInstance { impl TapeInstance { fn blas_key(&self) -> TapeBlasKey { TapeBlasKey { - tape: self.tape, + tape: self.tape, opacity: self.opacity, } } @@ -262,24 +262,24 @@ pub struct InstanceState { impl InstanceState { pub fn new() -> Self { Self { - vertex_buffers: RetainedBindingArray::new(), - index_buffers: RetainedBindingArray::new(), - aabb_buffers: RetainedBindingArray::new(), - tape_metadata_buffers: RetainedBindingArray::new(), - transforms: storage_buffer("solari_transforms"), + vertex_buffers: RetainedBindingArray::new(), + index_buffers: RetainedBindingArray::new(), + aabb_buffers: RetainedBindingArray::new(), + tape_metadata_buffers: RetainedBindingArray::new(), + transforms: storage_buffer("solari_transforms"), previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"), - geometry_ids: storage_buffer("solari_geometry_ids"), - tape_ids: storage_buffer("solari_tape_ids"), - material_ids: storage_buffer("solari_material_ids"), - blas_refs: storage_buffer("solari_blas_refs"), - slots: IndexAllocator::new(), - retired_mesh_buffers: Vec::new(), - retired_tape_buffers: Vec::new(), - records: EntityHashMap::default(), - live_count: 0, - pending_refresh: EntityHashSet::default(), - object_instances: HashMap::default(), - material_instances: HashMap::default(), + geometry_ids: storage_buffer("solari_geometry_ids"), + tape_ids: storage_buffer("solari_tape_ids"), + material_ids: storage_buffer("solari_material_ids"), + blas_refs: storage_buffer("solari_blas_refs"), + slots: IndexAllocator::new(), + retired_mesh_buffers: Vec::new(), + retired_tape_buffers: Vec::new(), + records: EntityHashMap::default(), + live_count: 0, + pending_refresh: EntityHashSet::default(), + object_instances: HashMap::default(), + material_instances: HashMap::default(), } } @@ -339,11 +339,11 @@ pub type ChangedTapeInstanceFilter = ( /// The scene state an instance resolves its GPU data against. pub struct InstanceInputs<'a> { - pub assets: &'a AssetState, + pub assets: &'a AssetState, pub mesh_blas_manager: &'a MeshBlasManager, - pub mesh_allocator: &'a MeshAllocator, + pub mesh_allocator: &'a MeshAllocator, pub tape_blas_manager: &'a TapeBlasManager, - pub tape_allocator: &'a TapeAllocator, + pub tape_allocator: &'a TapeAllocator, } fn unlink(map: &mut HashMap, key: &K, entity: Entity) { @@ -442,11 +442,11 @@ impl InstanceState { match mesh_instances.get(entity) { Ok(data) => { self.refresh_instance(inputs, lights, entity, InstanceQueryData::Mesh(data)) - }, + } Err(_) => match tape_instances.get(entity) { Ok(data) => { self.refresh_instance(inputs, lights, entity, InstanceQueryData::Tape(data)) - }, + } Err(_) => self.remove_instance(lights, entity), }, } @@ -529,10 +529,10 @@ impl InstanceState { match instance { Instance::Mesh(instance) => { self.resolve_mesh_instance(inputs, lights, entity, instance) - }, + } Instance::Tape(instance) => { self.resolve_tape_instance(inputs, lights, entity, instance) - }, + } } } @@ -838,10 +838,10 @@ impl InstanceState { match instance { Instance::Mesh(mut instance) => { self.deactivate_mesh_instance(lights, entity, &mut instance) - }, + } Instance::Tape(mut instance) => { self.deactivate_tape_instance(lights, entity, &mut instance) - }, + } } self.slots.retire(instance.get_slot()); diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/lights.rs b/crates/bevy_tape_drive_solari/src/scene/binder/lights.rs index 67a6930..fa3fe17 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/lights.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/lights.rs @@ -4,7 +4,7 @@ use crate::scene::extract::{ ExtractedRaytracingRectLight, ExtractedRaytracingSpotLight, }; use bevy_ecs::{entity::Entity, query::Changed, system::Query}; -use bevy_math::{ops::cos, Vec3}; +use bevy_math::{Vec3, ops::cos}; use bevy_platform::collections::{HashMap, HashSet}; use bevy_render::render_resource::{AtomicSparseBufferVec, BufferUsages}; use bevy_render::{impl_atomic_pod, render_resource::AtomicPod}; diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/mod.rs b/crates/bevy_tape_drive_solari/src/scene/binder/mod.rs index 5a12291..b83122a 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/mod.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/mod.rs @@ -227,11 +227,11 @@ pub fn prepare_raytracing_scene_resources( .instances .remove_instances(&mut bindings.lights, removed_tape_instances.read()); let inputs = InstanceInputs { - assets: &bindings.assets, + assets: &bindings.assets, mesh_blas_manager: &mesh_blas_manager, - mesh_allocator: &mesh_allocator, + mesh_allocator: &mesh_allocator, tape_blas_manager: &tape_blas_manager, - tape_allocator: &tape_allocator, + tape_allocator: &tape_allocator, }; bindings.instances.refresh_instances( &inputs, diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/tlas.rs b/crates/bevy_tape_drive_solari/src/scene/binder/tlas.rs index 856634b..fd3a87a 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/tlas.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/tlas.rs @@ -30,7 +30,7 @@ use super::{ #[derive(Resource)] pub struct TlasInstanceSetupPipeline { pub layout: BindGroupLayoutDescriptor, - pub id: Option, + pub id: Option, } impl FromWorld for TlasInstanceSetupPipeline { @@ -280,9 +280,9 @@ impl TlasState { let capacity = tlas_capacity_for(needed); self.instance_descriptors = Some(render_device.create_buffer(&BufferDescriptor { - label: Some("solari_tlas_instance_descriptors"), - size: u64::from(capacity) * tlas_build::INSTANCE_DESCRIPTOR_SIZE, - usage: BufferUsages::STORAGE | BufferUsages::TLAS_INPUT, + label: Some("solari_tlas_instance_descriptors"), + size: u64::from(capacity) * tlas_build::INSTANCE_DESCRIPTOR_SIZE, + usage: BufferUsages::STORAGE | BufferUsages::TLAS_INPUT, mapped_at_creation: false, })); self.instance_descriptor_capacity = capacity; @@ -332,9 +332,9 @@ impl TlasState { let capacity = tlas_capacity_for(needed); self.structures[current_index] = Some(render_device.wgpu_device().create_tlas( &CreateTlasDescriptor { - label: Some("tlas"), - flags: AccelerationStructureFlags::PREFER_FAST_TRACE, - update_mode: AccelerationStructureUpdateMode::Build, + label: Some("tlas"), + flags: AccelerationStructureFlags::PREFER_FAST_TRACE, + update_mode: AccelerationStructureUpdateMode::Build, max_instances: capacity, }, )); @@ -356,18 +356,25 @@ pub fn build_raytracing_tlas( let bindings = &mut *bindings; let current_index = bindings.tlas.current_index; - let built = match bindings.tlas.raw { - Some(backend) => { - setup_tlas_instances(bindings, &pipeline_cache, &pipeline, &mut render_context) - && build_tlas_raw(bindings, backend, &mut render_context) - }, - None => build_tlas_through_wgpu_core( - bindings, - &mesh_blas_manager, - &tape_blas_manager, - &mut render_context, - ), - }; + //let built = match bindings.tlas.raw { + // Some(backend) => { + // setup_tlas_instances(bindings, &pipeline_cache, &pipeline, &mut render_context) + // && build_tlas_raw(bindings, backend, &mut render_context) + // } + // None => build_tlas_through_wgpu_core( + // bindings, + // &mesh_blas_manager, + // &tape_blas_manager, + // &mut render_context, + // ), + //}; + + let built = build_tlas_through_wgpu_core( + bindings, + &mesh_blas_manager, + &tape_blas_manager, + &mut render_context, + ); if built { bindings.tlas.built[current_index] = true; @@ -424,7 +431,7 @@ fn setup_tlas_instances( let time_span = diagnostics.time_span(command_encoder, "setup_tlas_instances"); { let mut pass = command_encoder.begin_compute_pass(&ComputePassDescriptor { - label: Some("setup_tlas_instances"), + label: Some("setup_tlas_instances"), timestamp_writes: None, }); pass.set_pipeline(compute_pipeline); @@ -437,11 +444,11 @@ fn setup_tlas_instances( [ BufferTransition { buffer: &**instances, - state: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + state: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, BufferTransition { buffer: &**scratch, - state: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + state: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, }, ] .into_iter(), diff --git a/crates/bevy_tape_drive_solari/src/scene/binder/tlas_build.rs b/crates/bevy_tape_drive_solari/src/scene/binder/tlas_build.rs index 0cb6d3f..cd8b333 100644 --- a/crates/bevy_tape_drive_solari/src/scene/binder/tlas_build.rs +++ b/crates/bevy_tape_drive_solari/src/scene/binder/tlas_build.rs @@ -36,7 +36,7 @@ use bevy_render::{ renderer::RenderDevice, }; use core::marker::PhantomData; -use wgpu::{hal, BufferUses}; +use wgpu::{BufferUses, hal}; /// Size of one TLAS instance descriptor, on both Vulkan and DXR. pub const INSTANCE_DESCRIPTOR_SIZE: u64 = 64; diff --git a/crates/bevy_tape_drive_solari/src/scene/extract.rs b/crates/bevy_tape_drive_solari/src/scene/extract.rs index b155723..1d77faa 100644 --- a/crates/bevy_tape_drive_solari/src/scene/extract.rs +++ b/crates/bevy_tape_drive_solari/src/scene/extract.rs @@ -182,7 +182,7 @@ pub fn extract_raytracing_scene_tapes_and_materials( /// world. #[derive(Resource, Default)] pub struct StandardMaterialAssets { - materials: HashMap, StandardMaterial>, + materials: HashMap, StandardMaterial>, /// Materials added or modified this frame. pub changed: Vec>, /// Materials removed this frame. @@ -213,54 +213,54 @@ pub fn extract_raytracing_material_assets( render_materials.materials.insert(*id, material.clone()); render_materials.changed.push(*id); } - }, + } AssetEvent::Removed { id } => { render_materials.materials.remove(id); render_materials.removed.push(*id); - }, - AssetEvent::Unused { .. } | AssetEvent::LoadedWithDependencies { .. } => {}, + } + AssetEvent::Unused { .. } | AssetEvent::LoadedWithDependencies { .. } => {} } } } #[derive(Component, Clone, Copy, PartialEq, Debug)] pub struct ExtractedRaytracingDirectionalLight { - pub direction_to_light: Vec3, - pub illuminance: Vec3, + pub direction_to_light: Vec3, + pub illuminance: Vec3, pub sun_disk_angular_size: f32, } #[derive(Component, Clone, Copy, PartialEq, Debug)] pub struct ExtractedRaytracingPointLight { - pub position: Vec3, - pub radius: f32, + pub position: Vec3, + pub radius: f32, pub intensity: Vec3, } #[derive(Component, Clone, Copy, PartialEq, Debug)] pub struct ExtractedRaytracingSpotLight { - pub position: Vec3, - pub radius: f32, + pub position: Vec3, + pub radius: f32, pub intensity: Vec3, - pub axis: Vec3, + pub axis: Vec3, pub cos_inner: f32, pub cos_outer: f32, } #[derive(Component, Clone, Copy, PartialEq, Debug)] pub struct ExtractedRaytracingRectLight { - pub center: Vec3, - pub edge_x: Vec3, - pub edge_y: Vec3, - pub area: f32, + pub center: Vec3, + pub edge_x: Vec3, + pub edge_y: Vec3, + pub area: f32, pub radiance: Vec3, } #[derive(Resource, Default, Clone, PartialEq)] pub struct ExtractedEnvironmentMapLight { - pub cubemap: Option>, + pub cubemap: Option>, pub intensity: f32, - pub rotation: Quat, + pub rotation: Quat, } /// Lights whose extracted data needs updating. @@ -337,8 +337,8 @@ pub fn extract_raytracing_directional_lights( } entity_commands.insert(ExtractedRaytracingDirectionalLight { - direction_to_light: transform.back().into(), - illuminance: LinearRgba::from(directional_light.color).to_vec3() + direction_to_light: transform.back().into(), + illuminance: LinearRgba::from(directional_light.color).to_vec3() * directional_light.illuminance, sun_disk_angular_size: sun_disk.unwrap_or_default().angular_size, }); @@ -370,8 +370,8 @@ pub fn extract_raytracing_point_lights( } entity_commands.insert(ExtractedRaytracingPointLight { - position: transform.translation(), - radius: point_light.radius, + position: transform.translation(), + radius: point_light.radius, // Map from luminous power in lumens to luminous intensity in candela intensity: LinearRgba::from(point_light.color).to_vec3() * point_light.intensity / (4.0 * PI), @@ -407,11 +407,11 @@ pub fn extract_raytracing_spot_lights( let inner_angle = spot_light.inner_angle.min(outer_angle); entity_commands.insert(ExtractedRaytracingSpotLight { - position: transform.translation(), - radius: spot_light.radius, + position: transform.translation(), + radius: spot_light.radius, intensity: LinearRgba::from(spot_light.color).to_vec3() * spot_light.intensity / (4.0 * PI), - axis: transform.forward().into(), + axis: transform.forward().into(), cos_inner: cos(inner_angle), cos_outer: cos(outer_angle), }); @@ -478,9 +478,9 @@ pub fn extract_raytracing_environment_map_light( }; let env_map_light = ExtractedEnvironmentMapLight { - cubemap: Some(env_map.specular_map.clone()), + cubemap: Some(env_map.specular_map.clone()), intensity: env_map.intensity, - rotation: env_map.rotation, + rotation: env_map.rotation, }; if extracted_env_map_light.cubemap.is_none() { diff --git a/crates/bevy_tape_drive_solari/src/scene/meshes/blas.rs b/crates/bevy_tape_drive_solari/src/scene/meshes/blas.rs index 846acbd..8a8056a 100644 --- a/crates/bevy_tape_drive_solari/src/scene/meshes/blas.rs +++ b/crates/bevy_tape_drive_solari/src/scene/meshes/blas.rs @@ -9,8 +9,8 @@ use bevy_platform::collections::HashMap; use bevy_render::{ diagnostic::{DiagnosticsRecorder, RecordDiagnostics}, mesh::{ - allocator::{MeshAllocator, MeshBufferSlice}, RenderMesh, + allocator::{MeshAllocator, MeshBufferSlice}, }, render_asset::ExtractedAssets, render_resource::*, @@ -174,6 +174,11 @@ pub fn prepare_raytracing_blas( render_queue: Res, mut diagnostics: Option>, ) { + std::process::Command::new("touch") + .arg("/tmp/trigger") + .status() + .unwrap(); + blas_manager.changed.clear(); // Delete BLAS for deleted or modified meshes diff --git a/crates/bevy_tape_drive_solari/src/scene/meshes/types.rs b/crates/bevy_tape_drive_solari/src/scene/meshes/types.rs index f0d6138..e19b3dc 100644 --- a/crates/bevy_tape_drive_solari/src/scene/meshes/types.rs +++ b/crates/bevy_tape_drive_solari/src/scene/meshes/types.rs @@ -3,7 +3,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{component::Component, prelude::ReflectComponent, template::FromTemplate}; use bevy_mesh::Mesh; use bevy_pbr::{MeshMaterial3d, StandardMaterial}; -use bevy_reflect::{prelude::ReflectDefault, Reflect}; +use bevy_reflect::{Reflect, prelude::ReflectDefault}; use bevy_render::sync_world::SyncToRenderWorld; use bevy_transform::components::Transform; use derive_more::derive::From; diff --git a/crates/bevy_tape_drive_solari/src/scene/tapes/blas.rs b/crates/bevy_tape_drive_solari/src/scene/tapes/blas.rs index e7456a2..ee57462 100644 --- a/crates/bevy_tape_drive_solari/src/scene/tapes/blas.rs +++ b/crates/bevy_tape_drive_solari/src/scene/tapes/blas.rs @@ -8,10 +8,10 @@ use bevy_ecs::{ use bevy_mesh::MeshRaytracingFlags; use bevy_platform::collections::HashMap; use bevy_render::{ - diagnostic::{DiagnosticsRecorder, RecordDiagnostics}, + diagnostic::RecordDiagnostics, render_asset::{ExtractedAssets, RenderAssets}, render_resource::*, - renderer::{RenderDevice, RenderQueue}, + renderer::{RenderContext, RenderDevice, RenderQueue}, }; use bevy_tape_load::{ Tape, @@ -217,17 +217,14 @@ pub fn compile_raytracing_blas( tapes: Res>, tape_allocator: Res, render_device: Res, - render_queue: Res, + mut render_context: RenderContext, pipeline_cache: Res, replacement_modules: Res, - mut diagnostics: Option>, ) { - let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor { - label: Some("blas_build_command_encoder"), - }); - let time_span = diagnostics - .as_mut() - .map(|diagnostics| diagnostics.time_span(&mut command_encoder, "tape_blas_build")); + let diagnostics = render_context.diagnostic_recorder(); + let diagnostics = diagnostics.as_deref(); + let mut command_encoder = render_context.command_encoder(); + let time_span = diagnostics.time_span(command_encoder, "tape_blas_build"); let mut compute_pass = command_encoder.begin_compute_pass(&ComputePassDescriptor { label: Some("enable_gen"), timestamp_writes: None, @@ -303,10 +300,7 @@ pub fn compile_raytracing_blas( drop(compute_pass); command_encoder.build_acceleration_structures(&build_entries, &[]); - if let Some(time_span) = time_span { - time_span.end(&mut command_encoder); - } - render_queue.submit([command_encoder.finish()]); + time_span.end(&mut command_encoder); } pub fn delete_raytracing_blas( diff --git a/crates/bevy_tape_load/build.rs b/crates/bevy_tape_load/build.rs index fb07606..23ce6da 100644 --- a/crates/bevy_tape_load/build.rs +++ b/crates/bevy_tape_load/build.rs @@ -142,9 +142,6 @@ fn compile_replacement_shader(name: &str, entry_point: String, stage: naga::Shad } fn main() { - println!("cargo::rerun-if-changed=build.rs"); - println!("cargo::rerun-if-changed=Cargo.lock"); - if std::fs::exists("shaders_out").unwrap() { std::fs::remove_dir_all("shaders_out").unwrap(); } diff --git a/crates/bevy_tape_load/src/lib.rs b/crates/bevy_tape_load/src/lib.rs index 41671fb..6560a86 100644 --- a/crates/bevy_tape_load/src/lib.rs +++ b/crates/bevy_tape_load/src/lib.rs @@ -1,4 +1,5 @@ #![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")] +#![recursion_limit = "256"] /** * Defines the [Tape] asset, which responds to a Tape Drive tape. */ diff --git a/crates/bevy_tape_load/src/primitives/sphere.rs b/crates/bevy_tape_load/src/primitives/sphere.rs index 31a29ca..5609430 100644 --- a/crates/bevy_tape_load/src/primitives/sphere.rs +++ b/crates/bevy_tape_load/src/primitives/sphere.rs @@ -31,21 +31,21 @@ impl SphereTapeBuilder { let pos = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAPosition, - size: 1, + size: 1, }, vec![], ); let sphere = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSASDFSphere, - size: 1, + size: 1, }, vec![pos[0], pos[1], pos[2], SSAInput::Constant(radius)], ); tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAReturn, - size: 1, + size: 1, }, sphere, ); diff --git a/examples/pica_pica.rs b/examples/pica_pica.rs index 963b37e..578be36 100644 --- a/examples/pica_pica.rs +++ b/examples/pica_pica.rs @@ -42,7 +42,7 @@ use rand::{RngExt, SeedableRng, rngs::SmallRng}; struct Args { /// use the reference pathtracer instead of the realtime lighting system. #[argh(switch)] - pathtracer: Option, + pathtracer: Option, /// stress test a scene with many lights. #[argh(switch)] many_lights: Option, @@ -102,14 +102,14 @@ fn create_csg(seed: u64) -> SSATape { let pos = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAPosition, - size: 1, + size: 1, }, vec![], ); let offset = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAAdd, - size: 3, + size: 3, }, vec![ pos[0], @@ -123,14 +123,14 @@ fn create_csg(seed: u64) -> SSATape { let sin = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSASin, - size: 1, + size: 1, }, vec![pos[3]], ); let offset = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAAdd, - size: 3, + size: 3, }, vec![ offset[0], @@ -144,7 +144,7 @@ fn create_csg(seed: u64) -> SSATape { let sphere = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSASDFSphere, - size: 1, + size: 1, }, vec![ offset[0], @@ -156,7 +156,7 @@ fn create_csg(seed: u64) -> SSATape { let torus = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSASDFTorus, - size: 1, + size: 1, }, vec![ pos[0], @@ -169,21 +169,21 @@ fn create_csg(seed: u64) -> SSATape { let min = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMin, - size: 1, + size: 1, }, vec![sphere[0], torus[0]], ); let scaled_time = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMul, - size: 1, + size: 1, }, vec![pos[3], SSAInput::Constant(0.2)], ); let moving_pos = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAAdd, - size: 3, + size: 3, }, vec![ pos[0], @@ -197,7 +197,7 @@ fn create_csg(seed: u64) -> SSATape { let pos_times_20 = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMul, - size: 3, + size: 3, }, vec![ moving_pos[0], @@ -211,14 +211,14 @@ fn create_csg(seed: u64) -> SSATape { let sine_of_the_times = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSASin, - size: 3, + size: 3, }, pos_times_20, ); let sine_of_the_times = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMul, - size: 3, + size: 3, }, vec![ sine_of_the_times[0], @@ -232,28 +232,28 @@ fn create_csg(seed: u64) -> SSATape { let multiply_out_1 = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMul, - size: 1, + size: 1, }, vec![sine_of_the_times[0], sine_of_the_times[1]], ); let multiply_out_2 = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAMul, - size: 1, + size: 1, }, vec![multiply_out_1[0], sine_of_the_times[2]], ); let displacement = tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAAdd, - size: 1, + size: 1, }, vec![min[0], multiply_out_2[0]], ); tape.push_instruction( SSAOpcodeSized { opcode: SSAOpcode::SSAReturn, - size: 1, + size: 1, }, displacement, ); @@ -320,9 +320,9 @@ fn setup_pica_pica( let csg = create_csg(0); let tape = Tape { - raytracing: MeshRaytracingFlags::OPAQUE, - parts: csg, - seed: 0, + raytracing: MeshRaytracingFlags::OPAQUE, + parts: csg, + seed: 0, subdivision: 8, }; let loaded_tape = asset_server.add(tape); @@ -423,7 +423,7 @@ fn setup_many_lights( match plane_mesh.attribute_mut(Mesh::ATTRIBUTE_UV_0).unwrap() { VertexAttributeValues::Float32x2(items) => { items.iter_mut().flatten().for_each(|x| *x *= 3.0); - }, + } _ => unreachable!(), } let plane_mesh = meshes.add(plane_mesh); @@ -737,7 +737,7 @@ fn toggle_lights( #[derive(Component)] struct PatrolPath { path: Vec<(Vec3, Quat)>, - i: usize, + i: usize, } fn patrol_path(mut query: Query<(&mut PatrolPath, &mut Transform)>, time: Res>) { @@ -802,10 +802,10 @@ fn update_control_text( match robot_light_material.and_then(|m| materials.get(&m.0)) { Some(robot_light_material) if robot_light_material.emissive != LinearRgba::BLACK => { text.0.push_str("\n(2): Disable robot emissive light"); - }, + } _ => { text.0.push_str("\n(2): Enable robot emissive light"); - }, + } } }