Compare commits

..

No commits in common. "24e1c0281e07d005fa70e659b4af9f44ecb36f02" and "25aa902e0247bda0ce67e55bd1df6753eb270dac" have entirely different histories.

10 changed files with 20 additions and 438 deletions

160
Cargo.lock generated
View File

@ -56,15 +56,6 @@ dependencies = [
"zerocopy", "zerocopy",
] ]
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "allocator-api2" name = "allocator-api2"
version = "0.2.16" version = "0.2.16"
@ -996,15 +987,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fps_counter"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff23a4d90ba4b859f370ee3c12ca3b1ca80d8ee144b279e135f6852cdadd6dd6"
dependencies = [
"instant",
]
[[package]] [[package]]
name = "fsevent-sys" name = "fsevent-sys"
version = "4.1.0" version = "4.1.0"
@ -1105,19 +1087,6 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "generator"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
dependencies = [
"cc",
"libc",
"log",
"rustversion",
"windows 0.48.0",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@ -1778,19 +1747,6 @@ dependencies = [
"value-bag", "value-bag",
] ]
[[package]]
name = "loom"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e045d70ddfbc984eacfa964ded019534e8f6cbf36f6410aee0ed5cefa5a9175"
dependencies = [
"cfg-if",
"generator",
"scoped-tls",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "lyra-ecs" name = "lyra-ecs"
version = "0.1.0" version = "0.1.0"
@ -1848,7 +1804,6 @@ dependencies = [
"tracing-appender", "tracing-appender",
"tracing-log 0.1.4", "tracing-log 0.1.4",
"tracing-subscriber", "tracing-subscriber",
"tracing-tracy",
"uuid", "uuid",
"wgpu", "wgpu",
"winit", "winit",
@ -1959,27 +1914,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "many-lights"
version = "0.1.0"
dependencies = [
"anyhow",
"async-std",
"fps_counter",
"lyra-engine",
"rand 0.8.5",
"tracing",
]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.1" version = "2.7.1"
@ -2721,50 +2655,6 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "regex"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.6",
"regex-syntax 0.8.3",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.3",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]] [[package]]
name = "remove_dir_all" name = "remove_dir_all"
version = "0.5.3" version = "0.5.3"
@ -2868,12 +2758,6 @@ dependencies = [
"base64 0.21.5", "base64 0.21.5",
] ]
[[package]]
name = "rustversion"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.16" version = "1.0.16"
@ -3471,49 +3355,14 @@ version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [ dependencies = [
"matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell",
"regex",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing",
"tracing-core", "tracing-core",
"tracing-log 0.2.0", "tracing-log 0.2.0",
] ]
[[package]]
name = "tracing-tracy"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6024d04f84a69fd0d1dc1eee3a2b070bd246530a0582f9982ae487cb6c703614"
dependencies = [
"tracing-core",
"tracing-subscriber",
"tracy-client",
]
[[package]]
name = "tracy-client"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fb931a64ff88984f86d3e9bcd1ae8843aa7fe44dd0f8097527bc172351741d"
dependencies = [
"loom",
"once_cell",
"tracy-client-sys",
]
[[package]]
name = "tracy-client-sys"
version = "0.22.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d104d610dfa9dd154535102cc9c6164ae1fa37842bc2d9e83f9ac82b0ae0882"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.5" version = "0.2.5"
@ -3954,15 +3803,6 @@ dependencies = [
"windows-targets 0.42.2", "windows-targets 0.42.2",
] ]
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets 0.48.5",
]
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.52.0" version = "0.52.0"

View File

@ -10,12 +10,11 @@ members = [
"lyra-ecs", "lyra-ecs",
"lyra-reflect", "lyra-reflect",
"lyra-scripting", "lyra-scripting",
"lyra-game", "lyra-math", "lyra-scene", "examples/many-lights"] "lyra-game", "lyra-math", "lyra-scene"]
[features] [features]
scripting = ["dep:lyra-scripting"] scripting = ["dep:lyra-scripting"]
lua_scripting = ["scripting", "lyra-scripting/lua"] lua_scripting = ["scripting", "lyra-scripting/lua"]
tracy = ["lyra-game/tracy"]
[dependencies] [dependencies]
lyra-game = { path = "lyra-game" } lyra-game = { path = "lyra-game" }

View File

@ -1,19 +0,0 @@
[package]
name = "many-lights"
version = "0.1.0"
edition = "2021"
[dependencies]
lyra-engine = { path = "../../", features = ["tracy"] }
anyhow = "1.0.75"
async-std = "1.12.0"
tracing = "0.1.37"
rand = "0.8.5"
fps_counter = "3.0.0"
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"]
[profile.release]
debug = true

View File

@ -1,189 +0,0 @@
use lyra_engine::{assets::{gltf::Gltf, ResourceManager}, ecs::query::{Res, ResMut, View}, game::Game, input::{Action, ActionHandler, ActionKind, ActionMapping, ActionMappingId, ActionSource, InputActionPlugin, KeyCode, LayoutId, MouseAxis, MouseInput}, math::{self, Quat, Transform, Vec3}, render::light::{directional::DirectionalLight, PointLight}, scene::{CameraComponent, FreeFlyCamera, FreeFlyCameraPlugin, ACTLBL_LOOK_LEFT_RIGHT, ACTLBL_LOOK_ROLL, ACTLBL_LOOK_UP_DOWN, ACTLBL_MOVE_FORWARD_BACKWARD, ACTLBL_MOVE_LEFT_RIGHT, ACTLBL_MOVE_UP_DOWN}, DeltaTime};
use rand::Rng;
use tracing::info;
const MAX_POINT_LIGHT_RANGE: f32 = 1.0;
const MIN_POINT_LIGHT_RANGE: f32 = 0.5;
const POINT_LIGHT_MAX_INTENSITY: f32 = 1.0;
const POINT_LIGHT_MIN_INTENSITY: f32 = 0.3;
const POINT_LIGHT_CUBE_SCALE: f32 = 0.2;
const POINT_LIGHT_NUM: u32 = 500;
const POINT_LIGHT_MAX_X: f32 = 9.0;
const POINT_LIGHT_MIN_X: f32 = -9.0;
const POINT_LIGHT_MAX_Y: f32 = 3.0;
const POINT_LIGHT_MIN_Y: f32 = 0.5;
const POINT_LIGHT_MAX_Z: f32 = 4.0;
const POINT_LIGHT_MIN_Z: f32 = -5.0;
#[async_std::main]
async fn main() {
let action_handler_plugin = |game: &mut Game| {
let action_handler = ActionHandler::builder()
.add_layout(LayoutId::from(0))
.add_action(ACTLBL_MOVE_FORWARD_BACKWARD, Action::new(ActionKind::Axis))
.add_action(ACTLBL_MOVE_LEFT_RIGHT, Action::new(ActionKind::Axis))
.add_action(ACTLBL_MOVE_UP_DOWN, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_LEFT_RIGHT, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_UP_DOWN, Action::new(ActionKind::Axis))
.add_action(ACTLBL_LOOK_ROLL, Action::new(ActionKind::Axis))
.add_action("Debug", Action::new(ActionKind::Button))
.add_mapping(ActionMapping::builder(LayoutId::from(0), ActionMappingId::from(0))
.bind(ACTLBL_MOVE_FORWARD_BACKWARD, &[
ActionSource::Keyboard(KeyCode::W).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::S).into_binding_modifier(-1.0)
])
.bind(ACTLBL_MOVE_LEFT_RIGHT, &[
ActionSource::Keyboard(KeyCode::A).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::D).into_binding_modifier(1.0)
])
.bind(ACTLBL_MOVE_UP_DOWN, &[
ActionSource::Keyboard(KeyCode::C).into_binding_modifier(1.0),
ActionSource::Keyboard(KeyCode::Z).into_binding_modifier(-1.0)
])
.bind(ACTLBL_LOOK_LEFT_RIGHT, &[
ActionSource::Mouse(MouseInput::Axis(MouseAxis::X)).into_binding(),
ActionSource::Keyboard(KeyCode::Left).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::Right).into_binding_modifier(1.0),
])
.bind(ACTLBL_LOOK_UP_DOWN, &[
ActionSource::Mouse(MouseInput::Axis(MouseAxis::Y)).into_binding(),
ActionSource::Keyboard(KeyCode::Up).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::Down).into_binding_modifier(1.0),
])
.bind(ACTLBL_LOOK_ROLL, &[
ActionSource::Keyboard(KeyCode::E).into_binding_modifier(-1.0),
ActionSource::Keyboard(KeyCode::Q).into_binding_modifier(1.0),
])
.bind("Debug", &[
ActionSource::Keyboard(KeyCode::B).into_binding(),
])
.finish()
).finish();
let world = game.world_mut();
world.add_resource(action_handler);
game.with_plugin(InputActionPlugin);
};
Game::initialize().await
.with_plugin(lyra_engine::DefaultPlugins)
.with_plugin(setup_scene_plugin)
.with_plugin(action_handler_plugin)
.with_plugin(camera_debug_plugin)
.with_plugin(FreeFlyCameraPlugin)
.run().await;
}
fn setup_scene_plugin(game: &mut Game) {
let fps_counter = |mut counter: ResMut<fps_counter::FPSCounter>, delta: Res<DeltaTime>| -> anyhow::Result<()> {
let tick = counter.tick();
info!("FPS: {}, frame time: {}", tick, **delta);
Ok(())
};
game.with_system("fps_counter", fps_counter, &[]);
let world = game.world_mut();
world.add_resource(fps_counter::FPSCounter::new());
let resman = world.get_resource_mut::<ResourceManager>();
let cube_gltf = resman.request::<Gltf>("../assets/texture-sep/texture-sep.gltf").unwrap();
cube_gltf.wait_recurse_dependencies_load();
let cube_mesh = &cube_gltf.data_ref()
.unwrap().meshes[0];
let sponza_model = resman.request::<Gltf>("../assets/sponza/Sponza.gltf").unwrap();
drop(resman);
sponza_model.wait_recurse_dependencies_load();
let sponza_scene = &sponza_model.data_ref()
.unwrap().scenes[0];
world.spawn((
sponza_scene.clone(),
Transform::from_xyz(0.0, 0.0, 0.0),
));
{
let mut light_tran = Transform::from_xyz(1.5, 2.5, 0.0);
light_tran.scale = Vec3::new(0.5, 0.5, 0.5);
light_tran.rotate_x(math::Angle::Degrees(-45.0));
light_tran.rotate_y(math::Angle::Degrees(25.0));
world.spawn((
DirectionalLight {
enabled: true,
color: Vec3::ONE,
intensity: 0.15
//..Default::default()
},
light_tran,
));
}
let x_range = POINT_LIGHT_MIN_X..POINT_LIGHT_MAX_X;
let y_range = POINT_LIGHT_MIN_Y..POINT_LIGHT_MAX_Y;
let z_range = POINT_LIGHT_MIN_Z..POINT_LIGHT_MAX_Z;
let mut rand = rand::thread_rng();
let mut rand_vec3 = || -> Vec3 {
let x = rand.gen_range(x_range.clone());
let y = rand.gen_range(y_range.clone());
let z = rand.gen_range(z_range.clone());
Vec3::new(x, y, z)
};
let mut rand = rand::thread_rng();
for _ in 0..POINT_LIGHT_NUM {
let range = rand.gen_range(MIN_POINT_LIGHT_RANGE..MAX_POINT_LIGHT_RANGE);
let intensity = rand.gen_range(POINT_LIGHT_MIN_INTENSITY..POINT_LIGHT_MAX_INTENSITY);
let color = rand_vec3().normalize();
world.spawn((
PointLight {
enabled: true,
color,
intensity,
range,
..Default::default()
},
Transform::new(
rand_vec3(),
Quat::IDENTITY,
Vec3::new(POINT_LIGHT_CUBE_SCALE, POINT_LIGHT_CUBE_SCALE, POINT_LIGHT_CUBE_SCALE),
),
cube_mesh.clone(),
));
}
let mut camera = CameraComponent::new_3d();
// these values were taken by manually positioning the camera in the scene.
camera.transform = Transform::new(
Vec3::new(-10.0, 0.94, -0.28),
Quat::from_xyzw(0.03375484, -0.7116095, 0.0342693, 0.70092666),
Vec3::ONE
);
world.spawn(( camera, FreeFlyCamera::default() ));
}
fn camera_debug_plugin(game: &mut Game) {
let sys = |handler: Res<ActionHandler>, view: View<&mut CameraComponent>| -> anyhow::Result<()> {
if handler.was_action_just_pressed("Debug") {
for mut cam in view.into_iter() {
cam.debug = !cam.debug;
}
}
Ok(())
};
game.with_system("camera_debug_trigger", sys, &[]);
}

View File

@ -11,14 +11,11 @@ lyra-math = { path = "../lyra-math" }
lyra-scene = { path = "../lyra-scene" } lyra-scene = { path = "../lyra-scene" }
winit = "0.28.1" winit = "0.28.1"
wgpu = "0.15.1"
tracing = "0.1.37" tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = [ "tracing-log" ] } tracing-subscriber = { version = "0.3.16", features = [ "tracing-log" ] }
tracing-log = "0.1.3" tracing-log = "0.1.3"
tracing-appender = "0.2.2" tracing-appender = "0.2.2"
tracing-tracy = { version = "0.11.0", optional = true } wgpu = "0.15.1"
async-std = { version = "1.12.0", features = [ "unstable", "attributes" ] } async-std = { version = "1.12.0", features = [ "unstable", "attributes" ] }
cfg-if = "1" cfg-if = "1"
bytemuck = { version = "1.12", features = [ "derive" ] } bytemuck = { version = "1.12", features = [ "derive" ] }
@ -33,6 +30,3 @@ quote = "1.0.29"
uuid = { version = "1.5.0", features = ["v4", "fast-rng"] } uuid = { version = "1.5.0", features = ["v4", "fast-rng"] }
itertools = "0.11.0" itertools = "0.11.0"
thiserror = "1.0.56" thiserror = "1.0.56"
[features]
tracy = ["dep:tracing-tracy"]

View File

@ -3,7 +3,7 @@ use std::{sync::Arc, collections::VecDeque, ptr::NonNull};
use async_std::task::block_on; use async_std::task::block_on;
use lyra_ecs::{World, system::{System, IntoSystem}}; use lyra_ecs::{World, system::{System, IntoSystem}};
use tracing::{error, info, Level}; use tracing::{info, error, Level};
use tracing_appender::non_blocking; use tracing_appender::non_blocking;
use tracing_subscriber::{ use tracing_subscriber::{
layer::SubscriberExt, layer::SubscriberExt,
@ -344,22 +344,15 @@ impl Game {
pub async fn run(&mut self) { pub async fn run(&mut self) {
// init logging // init logging
let (stdout_layer, _stdout_nb) = non_blocking(std::io::stdout()); let (stdout_layer, _stdout_nb) = non_blocking(std::io::stdout());
{ tracing_subscriber::registry()
let t = tracing_subscriber::registry() .with(fmt::layer().with_writer(stdout_layer))
.with(fmt::layer().with_writer(stdout_layer)); .with(filter::Targets::new()
#[cfg(feature = "tracy")]
let t = t.with(tracing_tracy::TracyLayer::default());
t.with(filter::Targets::new()
// done by prefix, so it includes all lyra subpackages // done by prefix, so it includes all lyra subpackages
.with_target("lyra", Level::DEBUG) .with_target("lyra", Level::DEBUG)
.with_target("wgpu", Level::WARN) .with_target("wgpu", Level::WARN)
.with_target("winit", Level::DEBUG) .with_target("winit", Level::DEBUG)
.with_default(Level::INFO)) .with_default(Level::INFO))
.init(); .init();
}
let world = self.world.take().unwrap_or_default(); let world = self.world.take().unwrap_or_default();

View File

@ -1,7 +1,6 @@
use std::{borrow::Cow, mem, rc::Rc}; use std::{borrow::Cow, mem, rc::Rc};
use glam::UVec2; use glam::UVec2;
use tracing::instrument;
use wgpu::{util::DeviceExt, ComputePipeline}; use wgpu::{util::DeviceExt, ComputePipeline};
use winit::dpi::PhysicalSize; use winit::dpi::PhysicalSize;
@ -203,7 +202,6 @@ impl LightCullCompute {
} }
} }
#[instrument(skip(self))]
pub fn update_screen_size(&mut self, size: PhysicalSize<u32>) { pub fn update_screen_size(&mut self, size: PhysicalSize<u32>) {
self.screen_size_buffer.write_buffer(&self.queue, 0, self.screen_size_buffer.write_buffer(&self.queue, 0,
&[UVec2::new(size.width, size.height)]); &[UVec2::new(size.width, size.height)]);
@ -214,9 +212,7 @@ impl LightCullCompute {
self.light_indices_grid = Self::create_grid(&self.device, self.workgroup_size); self.light_indices_grid = Self::create_grid(&self.device, self.workgroup_size);
} }
#[instrument(skip(self, camera_buffers, lights_buffers, depth_texture))]
pub fn compute(&mut self, camera_buffers: &BufferWrapper, lights_buffers: &LightUniformBuffers, depth_texture: &RenderTexture) { pub fn compute(&mut self, camera_buffers: &BufferWrapper, lights_buffers: &LightUniformBuffers, depth_texture: &RenderTexture) {
self.cleanup();
let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("LightCullCompute"), label: Some("LightCullCompute"),
}); });
@ -238,7 +234,8 @@ impl LightCullCompute {
} }
self.queue.submit(std::iter::once(encoder.finish())); self.queue.submit(std::iter::once(encoder.finish()));
//self.device.poll(wgpu::Maintain::Wait); self.device.poll(wgpu::Maintain::Wait);
self.cleanup();
} }
pub fn cleanup(&mut self) { pub fn cleanup(&mut self) {

View File

@ -12,7 +12,7 @@ use lyra_ecs::{Entity, Tick};
use lyra_ecs::query::{Entities, TickOf}; use lyra_ecs::query::{Entities, TickOf};
use lyra_ecs::World; use lyra_ecs::World;
use lyra_scene::{SceneGraph, WorldTransform}; use lyra_scene::{SceneGraph, WorldTransform};
use tracing::{debug, instrument, warn}; use tracing::{debug, warn};
use uuid::Uuid; use uuid::Uuid;
use wgpu::{BindGroupLayout, Limits}; use wgpu::{BindGroupLayout, Limits};
use wgpu::util::DeviceExt; use wgpu::util::DeviceExt;
@ -113,7 +113,6 @@ pub struct BasicRenderer {
} }
impl BasicRenderer { impl BasicRenderer {
#[instrument(skip(window))]
pub async fn create_with_window(window: Arc<Window>) -> BasicRenderer { pub async fn create_with_window(window: Arc<Window>) -> BasicRenderer {
let size = window.inner_size(); let size = window.inner_size();
@ -261,7 +260,6 @@ impl BasicRenderer {
} }
/// Checks if the mesh buffers in the GPU need to be updated. /// Checks if the mesh buffers in the GPU need to be updated.
#[instrument(skip(self, _entity, meshh))]
fn check_mesh_buffers(&mut self, _entity: Entity, meshh: &ResHandle<Mesh>) { fn check_mesh_buffers(&mut self, _entity: Entity, meshh: &ResHandle<Mesh>) {
let mesh_uuid = meshh.uuid(); let mesh_uuid = meshh.uuid();
@ -301,7 +299,6 @@ impl BasicRenderer {
} }
} }
#[instrument(skip(self, mesh))]
fn create_vertex_index_buffers(&mut self, mesh: &Mesh) -> (BufferStorage, Option<(wgpu::IndexFormat, BufferStorage)>) { fn create_vertex_index_buffers(&mut self, mesh: &Mesh) -> (BufferStorage, Option<(wgpu::IndexFormat, BufferStorage)>) {
let positions = mesh.position().unwrap(); let positions = mesh.position().unwrap();
let tex_coords: Vec<glam::Vec2> = mesh.tex_coords().cloned() let tex_coords: Vec<glam::Vec2> = mesh.tex_coords().cloned()
@ -351,7 +348,6 @@ impl BasicRenderer {
( vertex_buffer, indices ) ( vertex_buffer, indices )
} }
#[instrument(skip(self, mesh))]
fn create_mesh_buffers(&mut self, mesh: &Mesh) -> MeshBufferStorage { fn create_mesh_buffers(&mut self, mesh: &Mesh) -> MeshBufferStorage {
let (vertex_buffer, buffer_indices) = self.create_vertex_index_buffers(mesh); let (vertex_buffer, buffer_indices) = self.create_vertex_index_buffers(mesh);
@ -378,7 +374,6 @@ impl BasicRenderer {
} }
/// Processes the mesh for the renderer, storing and creating buffers as needed. Returns true if a new mesh was processed. /// Processes the mesh for the renderer, storing and creating buffers as needed. Returns true if a new mesh was processed.
#[instrument(skip(self, transform, mesh, entity))]
fn process_mesh(&mut self, entity: Entity, transform: Transform, mesh: &Mesh, mesh_uuid: Uuid) -> bool { fn process_mesh(&mut self, entity: Entity, transform: Transform, mesh: &Mesh, mesh_uuid: Uuid) -> bool {
let _ = transform; let _ = transform;
/* if self.transform_buffers.should_expand() { /* if self.transform_buffers.should_expand() {
@ -399,7 +394,6 @@ impl BasicRenderer {
} else { false } } else { false }
} }
#[instrument(skip(self, now, transform, entity))]
fn interpolate_transforms(&mut self, now: Instant, last_epoch: Tick, entity: Entity, transform: &Transform, transform_epoch: Tick) -> Transform { fn interpolate_transforms(&mut self, now: Instant, last_epoch: Tick, entity: Entity, transform: &Transform, transform_epoch: Tick) -> Transform {
let cached = match self.entity_last_transforms.get_mut(&entity) { let cached = match self.entity_last_transforms.get_mut(&entity) {
Some(last) if transform_epoch == last_epoch => { Some(last) if transform_epoch == last_epoch => {
@ -435,7 +429,6 @@ impl BasicRenderer {
} }
impl Renderer for BasicRenderer { impl Renderer for BasicRenderer {
#[instrument(skip(self, main_world))]
fn prepare(&mut self, main_world: &mut World) { fn prepare(&mut self, main_world: &mut World) {
let last_epoch = main_world.current_tick(); let last_epoch = main_world.current_tick();
let now_inst = Instant::now(); let now_inst = Instant::now();
@ -459,10 +452,6 @@ impl Renderer for BasicRenderer {
self.check_mesh_buffers(entity, &mesh_han); self.check_mesh_buffers(entity, &mesh_han);
} }
if self.transform_buffers.needs_expand() {
self.transform_buffers.expand_buffers(&self.device);
}
let group = TransformGroup::EntityRes(entity, mesh_han.uuid()); let group = TransformGroup::EntityRes(entity, mesh_han.uuid());
let transform_id = self.transform_buffers.update_or_push(&self.queue, &self.render_limits, let transform_id = self.transform_buffers.update_or_push(&self.queue, &self.render_limits,
group, || ( interop_pos.calculate_mat4(), glam::Mat3::from_quat(interop_pos.rotation) )); group, || ( interop_pos.calculate_mat4(), glam::Mat3::from_quat(interop_pos.rotation) ));
@ -477,10 +466,8 @@ impl Renderer for BasicRenderer {
if let Some((scene_han, scene_epoch)) = scene_pair { if let Some((scene_han, scene_epoch)) = scene_pair {
if let Some(scene) = scene_han.data_ref() { if let Some(scene) = scene_han.data_ref() {
if scene_epoch == last_epoch {
let view = scene.world().view::<(Entities, &mut WorldTransform, &Transform, Not<Has<RelationOriginComponent<ChildOf>>>)>(); let view = scene.world().view::<(Entities, &mut WorldTransform, &Transform, Not<Has<RelationOriginComponent<ChildOf>>>)>();
lyra_scene::system_update_world_transforms(scene.world(), view).unwrap(); lyra_scene::system_update_world_transforms(scene.world(), view).unwrap();
}
let interpo_pos = self.interpolate_transforms(now_inst, last_epoch, entity, &transform, transform_epoch); let interpo_pos = self.interpolate_transforms(now_inst, last_epoch, entity, &transform, transform_epoch);
@ -496,10 +483,6 @@ impl Renderer for BasicRenderer {
self.check_mesh_buffers(entity, &mesh_han); self.check_mesh_buffers(entity, &mesh_han);
} }
if self.transform_buffers.needs_expand() {
self.transform_buffers.expand_buffers(&self.device);
}
let scene_mesh_group = TransformGroup::Res(scene_han.uuid(), mesh_han.uuid()); let scene_mesh_group = TransformGroup::Res(scene_han.uuid(), mesh_han.uuid());
let group = TransformGroup::OwnedGroup(entity, scene_mesh_group.into()); let group = TransformGroup::OwnedGroup(entity, scene_mesh_group.into());
let transform_id = self.transform_buffers.update_or_push(&self.queue, &self.render_limits, let transform_id = self.transform_buffers.update_or_push(&self.queue, &self.render_limits,
@ -541,7 +524,6 @@ impl Renderer for BasicRenderer {
self.light_buffers.update_lights(&self.queue, last_epoch, main_world); self.light_buffers.update_lights(&self.queue, last_epoch, main_world);
} }
#[instrument(skip(self))]
fn render(&mut self) -> Result<(), wgpu::SurfaceError> { fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
let output = self.surface.get_current_texture()?; let output = self.surface.get_current_texture()?;
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default()); let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());
@ -642,7 +624,6 @@ impl Renderer for BasicRenderer {
Ok(()) Ok(())
} }
#[instrument(skip(self))]
fn on_resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) { fn on_resize(&mut self, new_size: winit::dpi::PhysicalSize<u32>) {
if new_size.width > 0 && new_size.height > 0 { if new_size.width > 0 && new_size.height > 0 {
self.size = new_size; self.size = new_size;

View File

@ -1,7 +1,6 @@
use std::{collections::{HashMap, VecDeque}, hash::{BuildHasher, DefaultHasher, Hash, Hasher, RandomState}, num::NonZeroU64}; use std::{collections::{HashMap, VecDeque}, hash::{BuildHasher, DefaultHasher, Hash, Hasher, RandomState}, num::NonZeroU64};
use lyra_ecs::Entity; use lyra_ecs::Entity;
use tracing::instrument;
use uuid::Uuid; use uuid::Uuid;
use wgpu::Limits; use wgpu::Limits;
@ -213,7 +212,6 @@ impl TransformBuffers {
/// ///
/// # Panics /// # Panics
/// Panics if the `entity_group` is not already inside of the buffers. /// Panics if the `entity_group` is not already inside of the buffers.
#[instrument(skip(self, queue, limits, entity_group, transform, normal_matrix))]
pub fn update_transform(&mut self, queue: &wgpu::Queue, limits: &Limits, entity_group: TransformGroup, transform: glam::Mat4, normal_matrix: glam::Mat3) -> TransformIndex { pub fn update_transform(&mut self, queue: &wgpu::Queue, limits: &Limits, entity_group: TransformGroup, transform: glam::Mat4, normal_matrix: glam::Mat3) -> TransformIndex {
let index = *self.groups.get(entity_group.into()) let index = *self.groups.get(entity_group.into())
.expect("Use 'push_transform' for new entities"); .expect("Use 'push_transform' for new entities");
@ -230,7 +228,6 @@ impl TransformBuffers {
} }
/// Push a new transform into the buffers. /// Push a new transform into the buffers.
#[instrument(skip(self, queue, limits, entity_group, transform, normal_matrix))]
pub fn push_transform(&mut self, queue: &wgpu::Queue, limits: &Limits, entity_group: TransformGroup, transform: glam::Mat4, normal_matrix: glam::Mat3) -> TransformIndex { pub fn push_transform(&mut self, queue: &wgpu::Queue, limits: &Limits, entity_group: TransformGroup, transform: glam::Mat4, normal_matrix: glam::Mat3) -> TransformIndex {
self.groups.insert(entity_group.into(), || { self.groups.insert(entity_group.into(), || {
// this closure is only called when there are no values that can be reused, // this closure is only called when there are no values that can be reused,
@ -267,7 +264,6 @@ impl TransformBuffers {
/// Update an existing transform group or if its not existing yet, pushes it to the buffer. /// Update an existing transform group or if its not existing yet, pushes it to the buffer.
/// ///
/// Returns: the index that the transform is at in the buffers. /// Returns: the index that the transform is at in the buffers.
#[instrument(skip(self, queue, limits, group, transform_fn))]
pub fn update_or_push<F>(&mut self, queue: &wgpu::Queue, limits: &Limits, group: TransformGroup, transform_fn: F) -> TransformIndex pub fn update_or_push<F>(&mut self, queue: &wgpu::Queue, limits: &Limits, group: TransformGroup, transform_fn: F) -> TransformIndex
where F: Fn() -> (glam::Mat4, glam::Mat3) where F: Fn() -> (glam::Mat4, glam::Mat3)
{ {
@ -283,7 +279,6 @@ impl TransformBuffers {
/// ///
/// This object has a chain of uniform buffers, when the buffers are expanded, a new /// This object has a chain of uniform buffers, when the buffers are expanded, a new
/// "chain-link" is created. /// "chain-link" is created.
#[instrument(skip(self, device))]
pub fn expand_buffers(&mut self, device: &wgpu::Device) { pub fn expand_buffers(&mut self, device: &wgpu::Device) {
let limits = device.limits(); let limits = device.limits();
let max_buffer_sizes = self.max_transform_count as u64 * limits.min_uniform_buffer_offset_alignment as u64; let max_buffer_sizes = self.max_transform_count as u64 * limits.min_uniform_buffer_offset_alignment as u64;
@ -370,13 +365,6 @@ impl TransformBuffers {
pub fn buffer_offset(&self, transform_index: TransformIndex) -> u32 { pub fn buffer_offset(&self, transform_index: TransformIndex) -> u32 {
Self::get_buffer_offset(&self.limits, transform_index) Self::get_buffer_offset(&self.limits, transform_index)
} }
/// Returns a boolean indicating if the buffers need to be expanded
pub fn needs_expand(&self) -> bool {
self.entries.last()
.map(|entry| entry.len >= self.max_transform_count)
.unwrap_or(false)
}
} }
#[repr(C)] #[repr(C)]

View File

@ -1,7 +1,7 @@
use std::{hash::{Hash, DefaultHasher, Hasher}, collections::{HashMap, HashSet, VecDeque}, ptr::NonNull, fmt::Debug}; use std::{hash::{Hash, DefaultHasher, Hasher}, collections::{HashMap, HashSet, VecDeque}, ptr::NonNull, fmt::Debug};
use lyra_ecs::{system::{GraphExecutor, GraphExecutorError, System}, World}; use lyra_ecs::{system::{GraphExecutor, GraphExecutorError, System}, World};
use tracing::{info_span, instrument}; use tracing::info_span;
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum StagedExecutorError { pub enum StagedExecutorError {
@ -112,7 +112,6 @@ impl StagedExecutor {
/// Execute the staged systems in order. /// Execute the staged systems in order.
/// ///
/// If `stop_on_error` is false but errors are encountered, those errors will be returned in a Vec. /// If `stop_on_error` is false but errors are encountered, those errors will be returned in a Vec.
#[instrument(skip(self, world, stop_on_error))]
pub fn execute(&mut self, world: NonNull<World>, stop_on_error: bool) -> Result<Vec<StagedExecutorError>, StagedExecutorError> { pub fn execute(&mut self, world: NonNull<World>, stop_on_error: bool) -> Result<Vec<StagedExecutorError>, StagedExecutorError> {
let mut stack = VecDeque::new(); let mut stack = VecDeque::new();
let mut visited = HashSet::new(); let mut visited = HashSet::new();
@ -121,14 +120,13 @@ impl StagedExecutor {
self.topological_sort(&mut stack, &mut visited, node)?; self.topological_sort(&mut stack, &mut visited, node)?;
} }
//let stage_span = info_span!("stage_exec", stage=tracing::field::Empty); let stage_span = info_span!("stage_exec", stage=tracing::field::Empty);
let mut errors = vec![]; let mut errors = vec![];
while let Some(node) = stack.pop_front() { while let Some(node) = stack.pop_front() {
let stage = self.stages.get_mut(&node).unwrap(); let stage = self.stages.get_mut(&node).unwrap();
let stage_span = info_span!("stage_exec", stage=stage.name.clone()); stage_span.record("stage", stage.name.clone());
//stage_span.record("stage", stage.name.clone());
let _e = stage_span.enter(); let _e = stage_span.enter();
if let Err(e) = stage.exec.execute(world, stop_on_error) { if let Err(e) = stage.exec.execute(world, stop_on_error) {