Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple profiling setup #181

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ midi-file = { path = "./midi-file" }
midi-io = { path = "./midi-io" }
piano-math = { path = "./piano-math" }

profiling = "1.0"

iced_style = "0.12"
iced_graphics = "0.12"
iced_core = "0.12"
Expand Down
1 change: 1 addition & 0 deletions neothesia-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ glyphon.workspace = true
wgpu-jumpstart.workspace = true
piano-math.workspace = true
midi-file.workspace = true
profiling.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2"
2 changes: 2 additions & 0 deletions neothesia-core/src/render/guidelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl GuidelineRenderer {
}
}

#[profiling::function]
fn update_horizontal_guidelines(
&mut self,
quads: &mut QuadPipeline,
Expand Down Expand Up @@ -108,6 +109,7 @@ impl GuidelineRenderer {
}
}

#[profiling::function]
pub fn update(
&mut self,
quads: &mut QuadPipeline,
Expand Down
10 changes: 8 additions & 2 deletions neothesia-core/src/render/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl KeyboardRenderer {
}

/// Reupload instances to GPU
#[profiling::function]
fn reupload(&mut self) {
let instances = &mut self.cache;

Expand Down Expand Up @@ -116,15 +117,20 @@ impl KeyboardRenderer {
}
}

#[profiling::function]
pub fn update(&mut self, quads: &mut QuadPipeline, layer: usize, text: &mut TextRenderer) {
if self.cache.is_empty() {
self.reupload();
}

for quad in self.cache.iter() {
quads.instances(layer).push(*quad);
{
profiling::scope!("push from cache");
for quad in self.cache.iter() {
quads.instances(layer).push(*quad);
}
}

profiling::scope!("push text");
let range_start = self.layout.range.start() as usize;
for key in self.layout.keys.iter().filter(|key| key.note_id() == 0) {
let x = self.pos.x + key.x();
Expand Down
2 changes: 2 additions & 0 deletions neothesia-core/src/render/quad/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<'a> QuadPipeline {
self.instances.push(Instances::new(&gpu.device, size));
}

#[profiling::function]
pub fn render(
&'a self,
batch_id: usize,
Expand Down Expand Up @@ -88,6 +89,7 @@ impl<'a> QuadPipeline {
self.instances[batch_id].data.push(quad)
}

#[profiling::function]
pub fn prepare(&mut self, device: &wgpu::Device, queue: &wgpu::Queue) {
for instances in self.instances.iter_mut() {
instances.update(device, queue);
Expand Down
1 change: 1 addition & 0 deletions neothesia-core/src/render/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl TextRenderer {
});
}

#[profiling::function]
pub fn update(&mut self, logical_size: (u32, u32), gpu: &Gpu) {
let elements = self.queue.iter().map(|area| glyphon::TextArea {
buffer: &area.buffer,
Expand Down
1 change: 1 addition & 0 deletions neothesia-core/src/render/waterfall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl WaterfallRenderer {
self.notes_pipeline.update_time(queue, time);
}

#[profiling::function]
pub fn render<'rpass>(
&'rpass mut self,
transform_uniform: &'rpass Uniform<TransformUniform>,
Expand Down
4 changes: 4 additions & 0 deletions neothesia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ cpal = { version = "0.15", optional = true }
fluidlite = { version = "0.2", features = ["builtin"], optional = true }
oxisynth = { version = "0.0.5", optional = true }

profiling = { workspace = true, features = ["profile-with-puffin"] }
puffin = "0.19"
puffin_http = "0.16"

[[bin]]
name = "neothesia"

Expand Down
6 changes: 6 additions & 0 deletions neothesia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl Neothesia {

self.update(delta);
self.render();
profiling::finish_frame!();
}
WindowEvent::CloseRequested => {
event_loop.exit();
Expand Down Expand Up @@ -162,6 +163,7 @@ impl Neothesia {
self.context.window.request_redraw();
}

#[profiling::function]
fn update(&mut self, delta: Duration) {
#[cfg(debug_assertions)]
{
Expand All @@ -176,6 +178,7 @@ impl Neothesia {
);
}

#[profiling::function]
fn render(&mut self) {
let frame = loop {
let swap_chain_output = self.surface.get_current_texture();
Expand Down Expand Up @@ -329,6 +332,9 @@ fn main() {
)
.init();

puffin::set_scopes_on(true); // tell puffin to collect data
let _server = puffin_http::Server::new("127.0.0.1:8585").ok();

let event_loop: EventLoop<NeothesiaEvent> = EventLoop::with_user_event().build().unwrap();
let proxy = event_loop.create_proxy();

Expand Down
2 changes: 2 additions & 0 deletions neothesia/src/scene/menu_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl MenuScene {
}

impl Scene for MenuScene {
#[profiling::function]
fn update(&mut self, ctx: &mut Context, delta: Duration) {
self.bg_pipeline.update_time(&mut ctx.gpu, delta);
self.iced_state.tick(ctx);
Expand Down Expand Up @@ -76,6 +77,7 @@ impl Scene for MenuScene {
}
}

#[profiling::function]
fn render<'pass>(
&'pass mut self,
_transform: &'pass Uniform<TransformUniform>,
Expand Down
1 change: 1 addition & 0 deletions neothesia/src/scene/playing_scene/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Keyboard {
self.renderer.position_on_bottom_of_parent(parent_height)
}

#[profiling::function]
pub fn resize(&mut self, ctx: &Context) {
let keyboard_layout = get_layout(
ctx.window_state.logical_size.width,
Expand Down
4 changes: 4 additions & 0 deletions neothesia/src/scene/playing_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl PlayingScene {
}
}

#[profiling::function]
fn update_midi_player(&mut self, ctx: &Context, delta: Duration) -> f32 {
if self.top_bar.loop_active && self.player.time() > self.top_bar.loop_end {
self.player.set_time(self.top_bar.loop_start);
Expand All @@ -116,6 +117,7 @@ impl PlayingScene {
self.player.time_without_lead_in() + ctx.config.playback_offset
}

#[profiling::function]
fn resize(&mut self, ctx: &mut Context) {
self.keyboard.resize(ctx);

Expand All @@ -132,6 +134,7 @@ impl PlayingScene {
}

impl Scene for PlayingScene {
#[profiling::function]
fn update(&mut self, ctx: &mut Context, delta: Duration) {
self.quad_pipeline.clear();

Expand All @@ -158,6 +161,7 @@ impl Scene for PlayingScene {
}
}

#[profiling::function]
fn render<'pass>(
&'pass mut self,
transform: &'pass Uniform<TransformUniform>,
Expand Down
1 change: 1 addition & 0 deletions neothesia/src/scene/playing_scene/rewind_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl RewindController {
}
}

#[profiling::function]
pub fn update(&self, player: &mut MidiPlayer, ctx: &Context) {
if let RewindController::Keyboard { speed, .. } = self {
if ctx.window_state.modifiers_state.shift_key() {
Expand Down
1 change: 1 addition & 0 deletions neothesia/src/scene/playing_scene/top_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl TopBar {
}
}

#[profiling::function]
pub fn update(scene: &mut PlayingScene, window_state: &WindowState, text: &mut TextRenderer) {
let PlayingScene {
top_bar,
Expand Down
Loading