Skip to content

Commit 7830978

Browse files
committed
Unify benchmark types in rtx-bench crate
Move CatmullRomSpline, CameraPath, CameraFrame, GpuInfo, BenchmarkMetadata, and FrameRecord to rtx-bench. All types now use owned values with both Serialize and Deserialize. The host crate imports these types instead of defining its own.
1 parent c73f74a commit 7830978

10 files changed

Lines changed: 78 additions & 74 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/host/src/bench_app.rs

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use chrono::DateTime;
99
use chrono::Utc;
1010
use futures::executor::block_on;
1111
use glam::Vec3;
12+
use rtx_bench::BenchmarkMetadata;
13+
use rtx_bench::CameraPath;
14+
use rtx_bench::FrameRecord;
15+
use rtx_bench::GpuInfo;
1216
use serde::Deserialize;
13-
use serde::Serialize;
1417
use winit::application::ApplicationHandler;
1518
use winit::dpi::LogicalSize;
1619
use winit::event::ElementState;
@@ -23,7 +26,6 @@ use winit::keyboard::NamedKey;
2326
use winit::window::WindowAttributes;
2427
use winit::window::WindowId;
2528

26-
use crate::camera_path::CameraPath;
2729
use crate::gpu::GpuContext;
2830
use crate::window_surface::WindowSurface;
2931
use crate::window_surface::WindowSurfaceBuilder;
@@ -80,47 +82,10 @@ impl BenchmarkFile {
8082
}
8183
}
8284

83-
/// GPU information captured from the wgpu adapter.
84-
#[derive(Serialize)]
85-
pub struct GpuInfo {
86-
pub name: String,
87-
pub driver: String,
88-
pub backend: String,
89-
}
90-
91-
/// Per-frame timing and camera data.
92-
#[derive(Serialize)]
93-
pub struct FrameRecord {
94-
pub frame: u32,
95-
pub t: f32,
96-
pub time_us: u64,
97-
pub cam_pos: [f32; 3],
98-
pub cam_dir: [f32; 3],
99-
pub cam_vup: [f32; 3],
100-
}
101-
102-
/// Benchmark metadata written as the first line of the JSONL output.
103-
#[derive(Serialize)]
104-
pub struct BenchmarkMetadata<'a> {
105-
pub version: u32,
106-
pub timestamp: String,
107-
pub git_sha: &'a str,
108-
pub scene: &'a str,
109-
pub resolution: [u32; 2],
110-
pub gpu: &'a GpuInfo,
111-
pub camera_path: &'a CameraPath,
112-
}
113-
114-
impl GpuInfo {
115-
/// Extract GPU info from a wgpu adapter.
116-
pub fn from_adapter(adapter: &wgpu::Adapter) -> Self {
117-
let info = adapter.get_info();
118-
Self {
119-
name: info.name,
120-
driver: info.driver,
121-
backend: format!("{:?}", info.backend),
122-
}
123-
}
85+
/// Extract GPU info from a wgpu adapter.
86+
fn gpu_info_from_adapter(adapter: &wgpu::Adapter) -> GpuInfo {
87+
let info = adapter.get_info();
88+
GpuInfo::new(info.name, info.driver, format!("{:?}", info.backend))
12489
}
12590

12691
/// Git SHA baked in at build time via build.rs.
@@ -241,7 +206,7 @@ impl BenchApp {
241206
let surface = window_surface.borrow_surface();
242207

243208
let gpu = GpuContext::new(instance, Some(surface)).await?;
244-
let gpu_info = GpuInfo::from_adapter(&gpu.adapter);
209+
let gpu_info = gpu_info_from_adapter(&gpu.adapter);
245210

246211
let swapchain_format = surface.get_capabilities(&gpu.adapter).formats[0];
247212

@@ -392,11 +357,11 @@ impl BenchApp {
392357
let metadata = BenchmarkMetadata {
393358
version: 1,
394359
timestamp: self.timestamp.format("%Y-%m-%dT%H:%M:%SZ").to_string(),
395-
git_sha: GIT_SHA,
396-
scene: &self.scene,
360+
git_sha: GIT_SHA.to_string(),
361+
scene: self.scene.clone(),
397362
resolution: [config.width, config.height],
398-
gpu: gpu_info,
399-
camera_path: &self.camera_path,
363+
gpu: gpu_info.clone(),
364+
camera_path: self.camera_path.clone(),
400365
};
401366
serde_json::to_writer(&mut writer, &metadata)?;
402367
writeln!(writer)?;

crates/host/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ use clap::Parser;
77
use futures::executor::block_on;
88

99
mod bench_app;
10-
mod camera_path;
1110
mod cli;
1211
mod gpu;
1312
mod live_app;
14-
mod spline;
1513
mod window_surface;
1614

1715
use cli::Cli;

crates/rtx-bench/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
anyhow = "1"
8+
glam = { workspace = true }
89
serde = { workspace = true }
910
serde_json = { workspace = true }
1011
svg = "0.18"
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use glam::Vec3;
2+
use serde::Deserialize;
23
use serde::Serialize;
34

45
use crate::spline::CatmullRomSpline;
@@ -7,7 +8,7 @@ use crate::spline::CatmullRomSpline;
78
///
89
/// Interpolates camera position and look-at target along Catmull-Rom splines,
910
/// allowing smooth camera motion through a scene.
10-
#[derive(Serialize)]
11+
#[derive(Serialize, Deserialize, Clone)]
1112
pub struct CameraPath {
1213
position: CatmullRomSpline,
1314
look_at: CatmullRomSpline,

crates/rtx-bench/src/lib.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
mod camera_path;
12
mod chart;
3+
mod spline;
4+
mod types;
25

36
use std::collections::HashMap;
47
use std::fs;
@@ -8,26 +11,13 @@ use std::path::Path;
811

912
use anyhow::Context;
1013
use anyhow::Result;
14+
pub use camera_path::CameraFrame;
15+
pub use camera_path::CameraPath;
1116
pub use chart::generate_svg;
12-
use serde::Deserialize;
13-
14-
/// Metadata from the first line of a benchmark JSONL file.
15-
#[derive(Deserialize)]
16-
pub struct BenchmarkMetadata {
17-
pub version: u32,
18-
pub timestamp: String,
19-
pub git_sha: String,
20-
pub scene: String,
21-
pub resolution: [u32; 2],
22-
}
23-
24-
/// Per-frame timing data from benchmark JSONL files.
25-
#[derive(Deserialize)]
26-
pub struct FrameRecord {
27-
pub frame: u32,
28-
pub t: f32,
29-
pub time_us: u64,
30-
}
17+
pub use spline::CatmullRomSpline;
18+
pub use types::BenchmarkMetadata;
19+
pub use types::FrameRecord;
20+
pub use types::GpuInfo;
3121

3222
/// A single frame's data: frame number and render time.
3323
#[derive(Clone)]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use glam::Vec3;
2+
use serde::Deserialize;
23
use serde::Serialize;
34

45
/// A Catmull-Rom spline that interpolates through a series of control points.
56
///
67
/// Catmull-Rom splines pass through all control points (except the first and last,
78
/// which only influence the curve's tangents at the endpoints). The curve is C1
89
/// continuous (smooth first derivative) at all interior points.
9-
#[derive(Serialize)]
10+
#[derive(Serialize, Deserialize, Clone)]
1011
pub struct CatmullRomSpline {
1112
points: Vec<Vec3>,
1213
}

crates/rtx-bench/src/types.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use serde::Deserialize;
2+
use serde::Serialize;
3+
4+
use crate::CameraPath;
5+
6+
/// GPU information captured from the wgpu adapter.
7+
#[derive(Serialize, Deserialize, Clone)]
8+
pub struct GpuInfo {
9+
pub name: String,
10+
pub driver: String,
11+
pub backend: String,
12+
}
13+
14+
impl GpuInfo {
15+
/// Create a new GpuInfo with the given values.
16+
pub fn new(name: String, driver: String, backend: String) -> Self {
17+
Self {
18+
name,
19+
driver,
20+
backend,
21+
}
22+
}
23+
}
24+
25+
/// Benchmark metadata written as the first line of the JSONL output.
26+
#[derive(Serialize, Deserialize)]
27+
pub struct BenchmarkMetadata {
28+
pub version: u32,
29+
pub timestamp: String,
30+
pub git_sha: String,
31+
pub scene: String,
32+
pub resolution: [u32; 2],
33+
pub gpu: GpuInfo,
34+
pub camera_path: CameraPath,
35+
}
36+
37+
/// Per-frame timing and camera data.
38+
#[derive(Serialize, Deserialize)]
39+
pub struct FrameRecord {
40+
pub frame: u32,
41+
pub t: f32,
42+
pub time_us: u64,
43+
pub cam_pos: [f32; 3],
44+
pub cam_dir: [f32; 3],
45+
pub cam_vup: [f32; 3],
46+
}

docs/tasks/benchmark-charts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Create a new crate `rtx-bench` (`crates/rtx-bench/`) for all charting logic. The
7070

7171
- [x] Axis labels and tick marks
7272
- [x] **Consolidate benchmark directories**: Reorganized `benchmarks/`, `bench-results/`, and `bench-charts/` into a single `bench/` directory with subdirectories (`bench/configs/`, `bench/results/`, `bench/charts/`).
73-
- [ ] **Unify benchmark types**: `BenchmarkMetadata`, `FrameRecord`, `GpuInfo` are defined in `host/bench_app.rs` (Serialize, with lifetimes) and `rtx-bench` (Deserialize, owned). Consolidate into one set of owned types with `Serialize + Deserialize` in `rtx-bench`, and have `host` import them.
73+
- [x] **Unify benchmark types**: `BenchmarkMetadata`, `FrameRecord`, `GpuInfo`, `CameraPath`, and `CatmullRomSpline` are now defined in `rtx-bench` with owned types and `Serialize + Deserialize`. The `host` crate imports these types.
7474
- [x] **Interactive SVG with JavaScript**: Embed JS in the SVG for browser-based interactivity:
7575
- [x] Toggle commits on/off by clicking legend items (simpler - add IDs to polylines, toggle visibility)
7676
- [x] Rectangular selection to zoom into a region (mouse tracking, selection box, viewBox transform, reset button)

docs/tasks/benchmarking.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Track rendering performance across commits to detect regressions.
44

55
## Relevant Files
66

7-
- `crates/host/src/spline.rs` - `CatmullRomSpline` implementation
8-
- `crates/host/src/camera_path.rs` - `CameraPath` and `CameraFrame` types (frame = position + look-at target)
7+
- `crates/rtx-bench/src/spline.rs` - `CatmullRomSpline` implementation
8+
- `crates/rtx-bench/src/camera_path.rs` - `CameraPath` and `CameraFrame` types (frame = position + look-at target)
9+
- `crates/rtx-bench/src/types.rs` - `BenchmarkMetadata`, `FrameRecord`, `GpuInfo` types
910
- `crates/host/src/bench_app.rs` - Benchmark application with render loop
1011
- `crates/host/src/cli.rs` - CLI definitions including `bench` subcommand
1112
- `bench/configs/*.toml` - Benchmark definition files

0 commit comments

Comments
 (0)