diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-13 15:07:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-13 15:07:42 -0300 |
| commit | d3074636fff0fbcd5fd9b71c0c3b1c1f5c0c1285 (patch) | |
| tree | 918d67acc8f00f72cc4ae1ba444e41238a689c2b /build.zig | |
| parent | 409c1accefeb7a775c0914c888b469a1e78fc69a (diff) | |
| download | sketchbook-d3074636fff0fbcd5fd9b71c0c3b1c1f5c0c1285.tar.gz sketchbook-d3074636fff0fbcd5fd9b71c0c3b1c1f5c0c1285.zip | |
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 35 |
1 files changed, 28 insertions, 7 deletions
@@ -37,13 +37,26 @@ pub fn build(b: *Build) void { const sketch_imports: []const Build.Module.Import = &.{ .{ .name = "abi", .module = abi }, .{ .name = "math", .module = math } }; const sketch = b.addModule("sketch", .{ .root_source_file = b.path("src/sketch/root.zig"), .imports = sketch_imports }); + const tracy_path = b.option([]const u8, "tracy", "Enable Tracy with this source checkout (disabled by default)") orelse ""; + const profile_options = b.addOptions(); + profile_options.addOption(bool, "enabled", tracy_path.len > 0); + const tracy = b.addModule("tracy", .{ .root_source_file = b.path("src/tracy.zig"), .target = target, .optimize = optimize }); + tracy.addOptions("profile_options", profile_options); + if (tracy_path.len > 0) { + tracy.addIncludePath(.{ .cwd_relative = tracy_path }); + tracy.addCSourceFile(.{ + .file = .{ .cwd_relative = b.pathJoin(&.{ tracy_path, "public", "TracyClient.cpp" }) }, + .flags = &.{ "-DTRACY_ENABLE=1", "-DTRACY_NO_SAMPLING", "-DTRACY_NO_CALLSTACK", "-DTRACY_NO_SYSTEM_TRACING", "-DTRACY_NO_CRASH_HANDLER", "-DTRACY_NO_CODE_TRANSFER", "-fno-sanitize=undefined" }, + }); + tracy.link_libcpp = true; + } const c = cModule(b, target, optimize); // No optimize mode of its own: the host's Zig code builds in the mode // of the executable it is part of (`script_optimize` makes use of it). const host = b.addModule("host", .{ .root_source_file = b.path("src/host/root.zig"), .target = target, - .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c } }, + .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c }, .{ .name = "tracy", .module = tracy } }, }); const host_exe = b.addExecutable(.{ @@ -68,7 +81,7 @@ pub fn build(b: *Build) void { }); b.installArtifact(probe); - var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .vector = undefined, .scope = undefined, .anim = undefined }, .host_exe = host_exe, .probe_exe = probe, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .script_optimize = optimize, .shared = .create(b) }; + var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .tracy = tracy, .vector = undefined, .scope = undefined, .anim = undefined }, .host_exe = host_exe, .probe_exe = probe, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .script_optimize = optimize, .shared = .create(b) }; // Vector graphics: built with the same shader step apps use. Both forms // of its shaders are exported, so apps' web builds can swap them too. @@ -124,7 +137,7 @@ pub fn build(b: *Build) void { b.createModule(.{ .root_source_file = b.path("src/abi.zig"), .target = target, .optimize = optimize }), b.createModule(.{ .root_source_file = b.path("src/sketch/root.zig"), .target = target, .optimize = optimize, .imports = sketch_imports }), b.createModule(.{ .root_source_file = b.path("src/math/root.zig"), .target = target, .optimize = optimize }), - b.createModule(.{ .root_source_file = b.path("src/host/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c } } }), + b.createModule(.{ .root_source_file = b.path("src/host/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "abi", .module = abi }, .{ .name = "c", .module = c }, .{ .name = "tracy", .module = tracy } } }), }) |module| test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = module })).step); // The noise tests again on wasm32 as the web builds it, under Node's @@ -362,7 +375,9 @@ fn fixSdlThreadCleanup(b: *Build, sdl: *Build.Module, source: Build.LazyPath) vo /// far went to the old texture and the rest to the copy, which shows the /// previous frame under it (seen after a large texture was freed, at /// 1920x1080 and up). Freed memory is still reused; it is only not -/// compacted. +/// compacted. With relocation disabled, small transfer buffers can also +/// suballocate safely instead of freeing hundreds of dedicated Vulkan +/// allocations during presentation. fn fixSdlVulkanAllocationLeak(b: *Build, sdl: *Build.Module, source: Build.LazyPath) void { const file = "src/gpu/vulkan/SDL_gpu_vulkan.c"; var found = false; @@ -388,6 +403,7 @@ fn fixSdlVulkanAllocationLeak(b: *Build, sdl: *Build.Module, source: Build.LazyP }) }); const edit = b.addRunArtifact(tool); edit.setName("patch SDL_gpu_vulkan.c"); + edit.addFileInput(source.path(b, "gpu/vulkan/SDL_gpu_vulkan.c")); edit.addDirectoryArg(source.path(b, "gpu/vulkan")); const out = edit.addOutputDirectoryArg("vulkan"); edit.addArgs(&.{ @@ -397,6 +413,9 @@ fn fixSdlVulkanAllocationLeak(b: *Build, sdl: *Build.Module, source: Build.LazyP "SDL_gpu_vulkan.c", " VULKAN_INTERNAL_MarkAllocationsForDefrag(renderer);\n", " (void)VULKAN_INTERNAL_MarkAllocationsForDefrag;\n", + "SDL_gpu_vulkan.c", + " VULKAN_BUFFER_TYPE_TRANSFER,\n true, // Dedicated allocations preserve the data even if a defrag is triggered.\n", + " VULKAN_BUFFER_TYPE_TRANSFER,\n false, // Sketchbook disables defrag, so small transfers can share allocations.\n", }); // The copy's relative includes (`../SDL_sysgpu.h`) resolve from the // original directory. @@ -413,6 +432,8 @@ pub const Options = struct { optimize: std.builtin.OptimizeMode, /// This package's name in the app's build.zig.zon. dependency: []const u8 = "sketchbook", + /// An existing Tracy checkout; null leaves native profiling compiled out. + tracy: ?[]const u8 = null, /// The optimize mode of the executables `e2e` plays scripts with /// (`App.addScriptExecutable`); `optimize` when null. Pass it a /// `b.option`, say `-Dscript-optimize=ReleaseSafe`, when Debug is too @@ -422,7 +443,7 @@ pub const Options = struct { }; pub fn init(b: *Build, options: Options) Sketchbook { - const dep = b.dependency(options.dependency, .{ .target = options.target, .optimize = options.optimize }); + const dep = b.dependency(options.dependency, .{ .target = options.target, .optimize = options.optimize, .tracy = options.tracy orelse "" }); const shared: *Shared = .create(b); for ([_][]const u8{ "vector_shaders", "scope_shaders" }) |name| { shared.web_twins.put(b.graph.arena, dep.module(name), dep.module(b.fmt("{s}_web", .{name}))) catch @panic("OOM"); @@ -431,7 +452,7 @@ pub fn init(b: *Build, options: Options) Sketchbook { .b = b, .target = options.target, .optimize = options.optimize, - .modules = .{ .abi = dep.module("abi"), .sketch = dep.module("sketch"), .host = dep.module("host"), .vector = dep.module("vector"), .scope = dep.module("scope"), .anim = dep.module("anim") }, + .modules = .{ .abi = dep.module("abi"), .sketch = dep.module("sketch"), .host = dep.module("host"), .tracy = dep.module("tracy"), .vector = dep.module("vector"), .scope = dep.module("scope"), .anim = dep.module("anim") }, .host_exe = dep.artifact("sketchbook"), .probe_exe = dep.artifact("sketchbook-probe"), .web = dep.path("web"), @@ -476,7 +497,7 @@ pub const Sketchbook = struct { /// `vector`: SVG, cubic geometry, and CPU and GPU renderers. `scope`: /// waveform, spectrogram, spectrum and oscilloscope views of a sound. /// `anim`: manim-style scenes as code (see `addScene`). - modules: struct { abi: *Build.Module, sketch: *Build.Module, host: *Build.Module, vector: *Build.Module, scope: *Build.Module, anim: *Build.Module }, + modules: struct { abi: *Build.Module, sketch: *Build.Module, host: *Build.Module, tracy: *Build.Module, vector: *Build.Module, scope: *Build.Module, anim: *Build.Module }, /// The generic host: loads and hot-reloads a sketch library. host_exe: *Build.Step.Compile, /// Prints any sketch's state file. |
