-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
build.zig
96 lines (78 loc) · 4.31 KB
/
build.zig
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const builtin = @import("builtin");
const std = @import("std");
const Options = @import("../../build.zig").Options;
const demo_name = "rasterization";
const content_dir = demo_name ++ "_content/";
// in future zig version e342433
pub fn pathResolve(b: *std.Build, paths: []const []const u8) []u8 {
return std.fs.path.resolve(b.allocator, paths) catch @panic("OOM");
}
pub fn build(b: *std.Build, options: Options) *std.Build.Step.Compile {
const cwd_path = b.pathJoin(&.{ "samples", demo_name });
const src_path = b.pathJoin(&.{ cwd_path, "src" });
const exe = b.addExecutable(.{
.name = demo_name,
.root_source_file = b.path(b.pathJoin(&.{ src_path, demo_name ++ ".zig" })),
.target = options.target,
.optimize = options.optimize,
});
@import("system_sdk").addLibraryPathsTo(exe);
const zmath = b.dependency("zmath", .{
.target = options.target,
});
exe.root_module.addImport("zmath", zmath.module("root"));
const zmesh = b.dependency("zmesh", .{
.target = options.target,
});
exe.root_module.addImport("zmesh", zmesh.module("root"));
exe.linkLibrary(zmesh.artifact("zmesh"));
const zwin32 = b.dependency("zwin32", .{
.target = options.target,
});
const zwin32_module = zwin32.module("root");
exe.root_module.addImport("zwin32", zwin32_module);
const zd3d12 = b.dependency("zd3d12", .{
.target = options.target,
.debug_layer = options.zd3d12_enable_debug_layer,
.gbv = options.zd3d12_enable_gbv,
});
const zd3d12_module = zd3d12.module("root");
exe.root_module.addImport("zd3d12", zd3d12_module);
@import("../common/build.zig").link(exe, .{
.zwin32 = zwin32_module,
.zd3d12 = zd3d12_module,
});
const exe_options = b.addOptions();
exe.root_module.addOptions("build_options", exe_options);
exe_options.addOption([]const u8, "content_dir", content_dir);
const content_path = b.pathJoin(&.{ cwd_path, content_dir });
const install_content_step = b.addInstallDirectory(.{
.source_dir = b.path(content_path),
.install_dir = .{ .custom = "" },
.install_subdir = b.pathJoin(&.{ "bin", content_dir }),
});
if (builtin.os.tag == .windows or builtin.os.tag == .linux) {
const compile_shaders = @import("zwin32").addCompileShaders(b, demo_name, .{ .shader_ver = "6_6" });
const root_path = pathResolve(b, &.{ @src().file, "..", "..", ".." });
const shaders_path = b.pathJoin(&.{ root_path, content_path, "shaders" });
const common_hlsl_path = b.pathJoin(&.{ root_path, "samples", "common/src/hlsl/common.hlsl" });
compile_shaders.addVsShader(common_hlsl_path, "vsImGui", b.pathJoin(&.{ shaders_path, "imgui.vs.cso" }), "PSO__IMGUI");
compile_shaders.addPsShader(common_hlsl_path, "psImGui", b.pathJoin(&.{ shaders_path, "imgui.ps.cso" }), "PSO__IMGUI");
compile_shaders.addCsShader(common_hlsl_path, "csGenerateMipmaps", b.pathJoin(&.{ shaders_path, "generate_mipmaps.cs.cso" }), "PSO__GENERATE_MIPMAPS");
const hlsl_path = b.pathJoin(&.{ root_path, src_path, demo_name ++ ".hlsl" });
compile_shaders.addVsShader(hlsl_path, "vsRecordPixels", b.pathJoin(&.{ shaders_path, "record_pixels.vs.cso" }), "PSO__RECORD_PIXELS");
compile_shaders.addPsShader(hlsl_path, "psRecordPixels", b.pathJoin(&.{ shaders_path, "record_pixels.ps.cso" }), "PSO__RECORD_PIXELS");
compile_shaders.addVsShader(hlsl_path, "vsDrawMesh", b.pathJoin(&.{ shaders_path, "draw_mesh.vs.cso" }), "PSO__DRAW_MESH");
compile_shaders.addPsShader(hlsl_path, "psDrawMesh", b.pathJoin(&.{ shaders_path, "draw_mesh.ps.cso" }), "PSO__DRAW_MESH");
compile_shaders.addCsShader(hlsl_path, "csDrawPixels", b.pathJoin(&.{ shaders_path, "draw_pixels.cs.cso" }), "PSO__DRAW_PIXELS");
compile_shaders.addCsShader(hlsl_path, "csClearPixels", b.pathJoin(&.{ shaders_path, "clear_pixels.cs.cso" }), "PSO__CLEAR_PIXELS");
install_content_step.step.dependOn(compile_shaders.step);
}
exe.step.dependOn(&install_content_step.step);
// This is needed to export symbols from an .exe file.
// We export D3D12SDKVersion and D3D12SDKPath symbols which
// is required by DirectX 12 Agility SDK.
exe.rdynamic = true;
@import("zwin32").install_d3d12(&exe.step, .bin);
return exe;
}