summaryrefslogtreecommitdiff
path: root/examples/micscope/build.zig
blob: 2de639d526ab9f2b5a49a8d04171f8a7d2a04934 (plain) (blame)
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
const std = @import("std");
const sketchbook = @import("sketchbook");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize });

    // The tuner's shaders, as SPIR-V for the native host and WGSL for the
    // web; their uniform blocks come from the Zig structs in src/layouts.zig.
    // The waveform, spectrogram and spectrum are the scope module's.
    const layouts = b.createModule(.{ .root_source_file = b.path("src/layouts.zig") });
    const shaders = sb.addShaders(.{
        .layouts = .{ .module = layouts, .types = &.{"TunerParams"} },
        .sources = &.{
            b.path("shaders/tuner_difference.comp"),
            b.path("shaders/tuner.comp"),
        },
    });

    const app = sb.app(.{
        .name = "micscope",
        .root_source_file = b.path("src/main.zig"),
        .imports = &.{
            .{ .name = "layouts", .module = layouts },
            .{ .name = "shaders", .module = shaders.module },
            .{ .name = "scope", .module = sb.modules.scope },
        },
    });
    const steps = app.addSteps(.{
        // Installable, and it opens offline (icons from web/icon.svg).
        .web = .{ .pwa = .{
            .description = "Records the microphone, shows its waveform, spectrogram and spectrum, and tunes any instrument.",
            .background = "#0b0c0f",
            .theme = "#0b0c0f",
            .icons = &.{
                .{ .source = b.path("web/icon-192.png"), .size = 192 },
                .{ .source = b.path("web/icon-512.png"), .size = 512 },
            },
        } },
        .scripts = &.{ b.path("test/transport.script"), b.path("test/record.script"), b.path("test/render.script"), b.path("test/tuner.script") },
    });

    // GPU time per command while zooming, which recomputes every frame.
    const profile = b.addRunArtifact(steps.exe);
    profile.addArgs(&.{ "--headless", "--fresh", "--profile-gpu", "--script" });
    profile.addFileArg(b.path("test/profile.script"));
    profile.addArg("--state");
    _ = profile.addOutputFileArg("profile.state");
    profile.setCwd(b.path("."));
    profile.has_side_effects = true;
    profile.stdio = .inherit;
    b.step("profile", "Print GPU time per command while zooming the reference").dependOn(&profile.step);
}