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) } } }