1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package app
import "core:os"
import "core:strconv"
import "core:time"
import gpu ".."
GPU_BENCH :: #config(GPU_BENCH, false)
bench_init :: proc(state: ^State) {
when GPU_BENCH {
state.bench.start_time = time.now()
seconds_env := os.get_env("GPU_TEST_SECONDS", context.allocator)
if len(seconds_env) > 0 {
seconds, ok := strconv.parse_f64(seconds_env)
if ok && seconds > 0 {
state.bench.max_seconds = seconds
}
}
frames_env := os.get_env("GPU_TEST_FRAMES", context.allocator)
if len(frames_env) > 0 {
frames, ok := strconv.parse_u64(frames_env)
if ok && frames > 0 {
state.bench.max_frames = frames
}
}
state.bench.profile_path = os.get_env("GPU_PROFILE_JSON", context.allocator)
state.bench.screenshot_ready_path = os.get_env("GPU_SCREENSHOT_READY_FILE", context.allocator)
hold_env := os.get_env("GPU_SCREENSHOT_HOLD_SECONDS", context.allocator)
if len(hold_env) > 0 {
hold, ok := strconv.parse_f64(hold_env)
if ok && hold > 0 {
state.bench.screenshot_hold_seconds = hold
}
}
}
}
bench_should_close :: proc(state: ^State) -> bool {
when GPU_BENCH {
if state.bench.max_frames > 0 && state.platform.time.frame_count >= state.bench.max_frames {
return true
}
if state.bench.max_seconds > 0 && state.platform.time.total >= state.bench.max_seconds {
return true
}
}
return false
}
bench_shutdown :: proc(state: ^State) {
when GPU_BENCH {
if state != nil && len(state.bench.screenshot_ready_path) > 0 {
_ = os.write_entire_file(state.bench.screenshot_ready_path, "ready")
if state.bench.screenshot_hold_seconds > 0 {
time.sleep(time.Duration(state.bench.screenshot_hold_seconds * f64(time.Second)))
}
}
if state != nil && len(state.bench.profile_path) > 0 {
elapsed := time.duration_seconds(time.diff(state.bench.start_time, time.now()))
gpu.write_profile(state.bench.profile_path, elapsed, state.platform.time.frame_count)
}
}
}