forked from zig-gamedev/zig-gamedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
159 lines (144 loc) · 4.34 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
const std = @import("std");
const Options = @import("../../build.zig").Options;
const content_dir = "mesh_shader_test_content/";
pub fn build(b: *std.Build, options: Options) *std.Build.CompileStep {
const exe = b.addExecutable(.{
.name = "mesh_shader_test",
.root_source_file = .{ .path = thisDir() ++ "/src/mesh_shader_test.zig" },
.target = options.target,
.optimize = options.optimize,
});
const zwin32_pkg = @import("../../build.zig").zwin32_pkg;
const zd3d12_pkg = @import("../../build.zig").zd3d12_pkg;
const common_pkg = @import("../../build.zig").common_pkg;
const zmesh_pkg = @import("../../build.zig").zmesh_pkg;
zwin32_pkg.link(exe, .{ .d3d12 = true });
zmesh_pkg.link(exe);
common_pkg.link(exe);
zd3d12_pkg.link(exe);
const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options);
exe_options.addOption([]const u8, "content_dir", content_dir);
const dxc_step = buildShaders(b);
const install_content_step = b.addInstallDirectory(.{
.source_dir = thisDir() ++ "/" ++ content_dir,
.install_dir = .{ .custom = "" },
.install_subdir = "bin/" ++ content_dir,
});
install_content_step.step.dependOn(dxc_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;
return exe;
}
fn buildShaders(b: *std.Build) *std.Build.Step {
const dxc_step = b.step("mesh_shader_test-dxc", "Build shaders for 'mesh shader test' demo");
makeDxcCmd(
b,
dxc_step,
"../../libs/common/src/hlsl/common.hlsl",
"vsImGui",
"imgui.vs.cso",
"vs",
"PSO__IMGUI",
);
makeDxcCmd(
b,
dxc_step,
"../../libs/common/src/hlsl/common.hlsl",
"psImGui",
"imgui.ps.cso",
"ps",
"PSO__IMGUI",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"msMain",
"mesh_shader.ms.cso",
"ms",
"PSO__MESH_SHADER",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"psMain",
"mesh_shader.ps.cso",
"ps",
"PSO__MESH_SHADER",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"vsMain",
"vertex_shader.vs.cso",
"vs",
"PSO__VERTEX_SHADER",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"psMain",
"vertex_shader.ps.cso",
"ps",
"PSO__VERTEX_SHADER",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"vsMain",
"vertex_shader_fixed.vs.cso",
"vs",
"PSO__VERTEX_SHADER_FIXED",
);
makeDxcCmd(
b,
dxc_step,
"src/mesh_shader_test.hlsl",
"psMain",
"vertex_shader_fixed.ps.cso",
"ps",
"PSO__VERTEX_SHADER_FIXED",
);
return dxc_step;
}
fn makeDxcCmd(
b: *std.Build,
dxc_step: *std.Build.Step,
comptime input_path: []const u8,
comptime entry_point: []const u8,
comptime output_filename: []const u8,
comptime profile: []const u8,
comptime define: []const u8,
) void {
const shader_ver = "6_6";
const shader_dir = thisDir() ++ "/" ++ content_dir ++ "shaders/";
const dxc_command = [9][]const u8{
if (@import("builtin").target.os.tag == .windows)
thisDir() ++ "/../../libs/zwin32/bin/x64/dxc.exe"
else if (@import("builtin").target.os.tag == .linux)
thisDir() ++ "/../../libs/zwin32/bin/x64/dxc",
thisDir() ++ "/" ++ input_path,
"/E " ++ entry_point,
"/Fo " ++ shader_dir ++ output_filename,
"/T " ++ profile ++ "_" ++ shader_ver,
if (define.len == 0) "" else "/D " ++ define,
"/WX",
"/Ges",
"/O3",
};
const cmd_step = b.addSystemCommand(&dxc_command);
if (@import("builtin").target.os.tag == .linux)
cmd_step.setEnvironmentVariable("LD_LIBRARY_PATH", thisDir() ++ "/../../libs/zwin32/bin/x64");
dxc_step.dependOn(&cmd_step.step);
}
inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse ".";
}