diff --git a/External/spirv-tools.zig b/External/spirv-tools.zig index a88ed1aa..16897c40 100644 --- a/External/spirv-tools.zig +++ b/External/spirv-tools.zig @@ -7,18 +7,20 @@ const spirv_tools_repository = "https://github.com/KhronosGroup/SPIRV-Tools"; const spirv_headers_repository = "https://github.com/KhronosGroup/SPIRV-Headers"; const log = std.log.scoped(.glslang_zig); -const prefix = "libs/DirectXShaderCompiler"; + +const tools_prefix = "SPIRV-Tools"; +const headers_prefix = "SPIRV-Headers"; pub fn build(b: *Build) !void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); const debug_symbols = b.option(bool, "debug_symbols", "Whether to produce detailed debug symbols (g0) or not. These increase binary size considerably.") orelse false; - const build_shared = b.option(bool, "shared", "Build dxcompiler shared libraries") orelse false; - const skip_executables = b.option(bool, "skip_executables", "Skip building executables") orelse false; - const skip_tests = b.option(bool, "skip_tests", "Skip building tests") orelse false; + const build_shared = b.option(bool, "shared", "Build spirv-tools as a shared library") orelse false; + + _ = build_spirv(b, optimize, target, debug_symbols, build_shared); } -pub fn build_tools(b: *Build, debug_symbols: bool) *std.Build.Step.Compile { +pub fn build_spirv(b: *Build, optimize: std.builtin.OptimizeMode, target: std.ResolvedTarget, debug_symbols: bool, build_shared: bool) *std.Build.Step.Compile { var cflags = std.ArrayList([]const u8).init(b.allocator); var cppflags = std.ArrayList([]const u8).init(b.allocator); @@ -36,7 +38,7 @@ pub fn build_tools(b: *Build, debug_symbols: bool) *std.Build.Step.Compile { "-Wno-macro-redefined", "-Wno-unknown-attributes", "-Wno-implicit-fallthrough", - "-fms-extensions", // __uuidof and friends (on non-windows targets) + "-fms-extensions", }; try cflags.appendSlice(base_flags); @@ -51,12 +53,23 @@ pub fn build_tools(b: *Build, debug_symbols: bool) *std.Build.Step.Compile { // spirv_tools_wasm ++ // Wasm build support- requires emscripten toolchain spirv_tools_opt; - const spv_lib = b.addStaticLibrary(.{ - .name = "SPIRV-Tools", - .root_source_file = b.addWriteFiles().add("empty.c", ""), - .optimize = optimize, - .target = target, - }); + var spv_lib = null; + + if (build_shared) { + spv_lib = b.addSharedLibrary(.{ + .name = "SPIRV-Tools", + .root_source_file = b.addWriteFiles().add("empty.c", ""), + .optimize = optimize, + .target = target, + }); + } else { + spv_lib = b.addStaticLibrary(.{ + .name = "SPIRV-Tools", + .root_source_file = b.addWriteFiles().add("empty.c", ""), + .optimize = optimize, + .target = target, + }); + } if (target.result.os.tag == .windows) { spv_lib.defineCMacro("SPIRV_WINDOWS", ""); @@ -79,8 +92,23 @@ pub fn build_tools(b: *Build, debug_symbols: bool) *std.Build.Step.Compile { std.process.exit(1); } - var build_grammar_step = BuildSPIRVGrammarStep.init(b); - spv_lib.step.dependOn(&build_grammar_step.step); + var download_source = DownloadSourceStep.init(b); + + download_source.repository = spirv_tools_repository; + download_source.revision = ""; + download_source.output = tools_prefix; + + var download_headers = DownloadSourceStep.init(b); + + download_headers.repository = spirv_headers_repository; + download_headers.revision = ""; + download_headers.output = headers_prefix; + + var build_grammar = BuildSPIRVGrammarStep.init(b); + + spv_lib.step.dependOn(&download_source); + spv_lib.step.dependOn(&download_headers); + spv_lib.step.dependOn(&build_grammar.step); spv_lib.addCSourceFiles(.{ .files = &spirv_cpp_sources, @@ -90,344 +118,37 @@ pub fn build_tools(b: *Build, debug_symbols: bool) *std.Build.Step.Compile { spv_lib.defineCMacro("SPIRV_COLOR_TERMINAL", ""); // Pretty lights by default addSPIRVIncludes(spv_lib); - linkMachDxcDependencies(spv_lib); + linkSPIRVDependencies(spv_lib); b.installArtifact(spv_lib); - lib.defineCMacro("ENABLE_SPIRV_CODEGEN", ""); - - addSPIRVIncludes(lib); + return spv_lib; } -fn linkMachDxcDependencies(step: *std.Build.Step.Compile) void { +fn linkSPIRVDependencies(step: *std.Build.Step.Compile) void { const target = step.rootModuleTarget(); + if (target.abi == .msvc) { - // https://github.com/ziglang/zig/issues/5312 step.linkLibC(); - } else step.linkLibCpp(); + } else { + step.linkLibCpp(); + } + if (target.os.tag == .windows) { step.linkSystemLibrary("ole32"); step.linkSystemLibrary("oleaut32"); } } -fn linkMachDxcDependenciesModule(mod: *std.Build.Module) void { - const target = mod.resolved_target.?.result; - if (target.abi == .msvc) { - // https://github.com/ziglang/zig/issues/5312 - mod.link_libc = true; - } else { - mod.link_libcpp = true; - } - if (target.os.tag == .windows) { - mod.linkSystemLibrary("ole32", .{}); - mod.linkSystemLibrary("oleaut32", .{}); - } -} - -fn addConfigHeaders(b: *Build, step: *std.Build.Step.Compile) void { - // /tools/clang/include/clang/Config/config.h.cmake - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/tools/clang/include/clang/Config/config.h.cmake" } }, - .include_path = "clang/Config/config.h", - }, - .{}, - )); - - // /include/llvm/Config/AsmParsers.def.in - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/AsmParsers.def.in" } }, - .include_path = "llvm/Config/AsmParsers.def", - }, - .{}, - )); - - // /include/llvm/Config/Disassemblers.def.in - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/Disassemblers.def.in" } }, - .include_path = "llvm/Config/Disassemblers.def", - }, - .{}, - )); - - // /include/llvm/Config/Targets.def.in - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/Targets.def.in" } }, - .include_path = "llvm/Config/Targets.def", - }, - .{}, - )); - - // /include/llvm/Config/AsmPrinters.def.in - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/AsmPrinters.def.in" } }, - .include_path = "llvm/Config/AsmPrinters.def", - }, - .{}, - )); - - // /include/llvm/Support/DataTypes.h.cmake - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Support/DataTypes.h.cmake" } }, - .include_path = "llvm/Support/DataTypes.h", - }, - .{ - .HAVE_INTTYPES_H = 1, - .HAVE_STDINT_H = 1, - .HAVE_UINT64_T = 1, - // /* #undef HAVE_U_INT64_T */ - }, - )); - - // /include/llvm/Config/abi-breaking.h.cmake - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/abi-breaking.h.cmake" } }, - .include_path = "llvm/Config/abi-breaking.h", - }, - .{}, - )); - - const target = step.rootModuleTarget(); - step.addConfigHeader(addConfigHeaderLLVMConfig(b, target, .llvm_config_h)); - step.addConfigHeader(addConfigHeaderLLVMConfig(b, target, .config_h)); - - // /include/dxc/config.h.cmake - step.addConfigHeader(b.addConfigHeader( - .{ - .style = .{ .cmake = .{ .path = "config-headers/include/dxc/config.h.cmake" } }, - .include_path = "dxc/config.h", - }, - .{ - .DXC_DISABLE_ALLOCATOR_OVERRIDES = false, - }, - )); -} - -fn addIncludes(step: *std.Build.Step.Compile) void { - // TODO: replace unofficial external/DIA submodule with something else (or eliminate dep on it) - step.addIncludePath(.{ .path = prefix ++ "/external/DIA/include" }); - // TODO: replace generated-include with logic to actually generate this code - step.addIncludePath(.{ .path = "generated-include/" }); - step.addIncludePath(.{ .path = prefix ++ "/tools/clang/include" }); - step.addIncludePath(.{ .path = prefix ++ "/include" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/llvm_assert" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Bitcode" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/IR" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/IRReader" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Linker" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Analysis" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms/Utils" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms/InstCombine" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms/IPO" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms/Scalar" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Transforms/Vectorize" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Target" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/ProfileData" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Option" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/PassPrinters" }); - step.addIncludePath(.{ .path = prefix ++ "/include/llvm/Passes" }); - step.addIncludePath(.{ .path = prefix ++ "/include/dxc" }); - step.addIncludePath(.{ .path = prefix ++ "/external/DirectX-Headers/include/directx" }); - - // SPIR-V generated include stuff- should be OK not having it behind an option check - step.addIncludePath(.{ .path = "generated-include/spirv-tools" }); - - const target = step.rootModuleTarget(); - if (target.os.tag != .windows) step.addIncludePath(.{ .path = prefix ++ "/external/DirectX-Headers/include/wsl/stubs" }); -} - fn addSPIRVIncludes(step: *std.Build.Step.Compile) void { // Generated SPIR-V headers get thrown in here - step.addIncludePath(.{ .path = "generated-include/spirv-tools" }); + step.addIncludePath(.{ .path = "generated-include" }); - step.addIncludePath(.{ .path = prefix ++ "/external/SPIRV-Tools" }); - step.addIncludePath(.{ .path = prefix ++ "/external/SPIRV-Tools/include" }); - step.addIncludePath(.{ .path = prefix ++ "/external/SPIRV-Tools/source" }); + step.addIncludePath(.{ .path = tools_prefix ++ "/external/SPIRV-Tools" }); + step.addIncludePath(.{ .path = tools_prefix ++ "/external/SPIRV-Tools/include" }); + step.addIncludePath(.{ .path = tools_prefix ++ "/external/SPIRV-Tools/source" }); - step.addIncludePath(.{ .path = prefix ++ "/external/SPIRV-Headers/include" }); -} - -// /include/llvm/Config/llvm-config.h.cmake -// /include/llvm/Config/config.h.cmake (derives llvm-config.h.cmake) -fn addConfigHeaderLLVMConfig(b: *Build, target: std.Target, which: anytype) *std.Build.Step.ConfigHeader { - // Note: LLVM_HOST_TRIPLEs can be found by running $ llc --version | grep Default - // Note: arm64 is an alias for aarch64, we always use aarch64 over arm64. - const cross_platform = .{ - .LLVM_PREFIX = "/usr/local", - .LLVM_DEFAULT_TARGET_TRIPLE = "dxil-ms-dx", - .LLVM_ENABLE_THREADS = 1, - .LLVM_HAS_ATOMICS = 1, - .LLVM_VERSION_MAJOR = 3, - .LLVM_VERSION_MINOR = 7, - .LLVM_VERSION_PATCH = 0, - .LLVM_VERSION_STRING = "3.7-v1.4.0.2274-1812-machdxcompiler", - }; - - const LLVMConfigH = struct { - LLVM_HOST_TRIPLE: []const u8, - LLVM_ON_WIN32: ?i64 = null, - LLVM_ON_UNIX: ?i64 = null, - HAVE_SYS_MMAN_H: ?i64 = null, - }; - const llvm_config_h = blk: { - if (target.os.tag == .windows) { - break :blk switch (target.abi) { - .msvc => switch (target.cpu.arch) { - .x86_64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "x86_64-w64-msvc", - .LLVM_ON_WIN32 = 1, - }), - .aarch64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "aarch64-w64-msvc", - .LLVM_ON_WIN32 = 1, - }), - else => @panic("target architecture not supported"), - }, - .gnu => switch (target.cpu.arch) { - .x86_64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "x86_64-w64-mingw32", - .LLVM_ON_WIN32 = 1, - }), - .aarch64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "aarch64-w64-mingw32", - .LLVM_ON_WIN32 = 1, - }), - else => @panic("target architecture not supported"), - }, - else => @panic("target ABI not supported"), - }; - } else if (target.os.tag.isDarwin()) { - break :blk switch (target.cpu.arch) { - .aarch64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "aarch64-apple-darwin", - .LLVM_ON_UNIX = 1, - .HAVE_SYS_MMAN_H = 1, - }), - .x86_64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "x86_64-apple-darwin", - .LLVM_ON_UNIX = 1, - .HAVE_SYS_MMAN_H = 1, - }), - else => @panic("target architecture not supported"), - }; - } else { - // Assume linux-like - // TODO: musl support? - break :blk switch (target.cpu.arch) { - .aarch64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "aarch64-linux-gnu", - .LLVM_ON_UNIX = 1, - .HAVE_SYS_MMAN_H = 1, - }), - .x86_64 => merge(cross_platform, LLVMConfigH{ - .LLVM_HOST_TRIPLE = "x86_64-linux-gnu", - .LLVM_ON_UNIX = 1, - .HAVE_SYS_MMAN_H = 1, - }), - else => @panic("target architecture not supported"), - }; - } - }; - - const tag = target.os.tag; - const if_windows: ?i64 = if (tag == .windows) 1 else null; - const if_not_windows: ?i64 = if (tag == .windows) null else 1; - const if_windows_or_linux: ?i64 = if (tag == .windows and !tag.isDarwin()) 1 else null; - const if_darwin: ?i64 = if (tag.isDarwin()) 1 else null; - const if_not_msvc: ?i64 = if (target.abi != .msvc) 1 else null; - const config_h = merge(llvm_config_h, .{ - .HAVE_STRERROR = if_windows, - .HAVE_STRERROR_R = if_not_windows, - .HAVE_MALLOC_H = if_windows_or_linux, - .HAVE_MALLOC_MALLOC_H = if_darwin, - .HAVE_MALLOC_ZONE_STATISTICS = if_not_windows, - .HAVE_GETPAGESIZE = if_not_windows, - .HAVE_PTHREAD_H = if_not_windows, - .HAVE_PTHREAD_GETSPECIFIC = if_not_windows, - .HAVE_PTHREAD_MUTEX_LOCK = if_not_windows, - .HAVE_PTHREAD_RWLOCK_INIT = if_not_windows, - .HAVE_DLOPEN = if_not_windows, - .HAVE_DLFCN_H = if_not_windows, // - .HAVE_UNISTD_H = if_not_msvc, - - .BUG_REPORT_URL = "http://llvm.org/bugs/", - .ENABLE_BACKTRACES = "", - .ENABLE_CRASH_OVERRIDES = "", - .DISABLE_LLVM_DYLIB_ATEXIT = "", - .ENABLE_PIC = "", - .ENABLE_TIMESTAMPS = 1, - .HAVE_CLOSEDIR = 1, - .HAVE_CXXABI_H = 1, - .HAVE_DECL_STRERROR_S = 1, - .HAVE_DIRENT_H = 1, - .HAVE_ERRNO_H = 1, - .HAVE_FCNTL_H = 1, - .HAVE_FENV_H = 1, - .HAVE_GETCWD = 1, - .HAVE_GETTIMEOFDAY = 1, - .HAVE_INT64_T = 1, - .HAVE_INTTYPES_H = 1, - .HAVE_ISATTY = 1, - .HAVE_LIBPSAPI = 1, - .HAVE_LIBSHELL32 = 1, - .HAVE_LIMITS_H = 1, - .HAVE_LINK_EXPORT_DYNAMIC = 1, - .HAVE_MKSTEMP = 1, - .HAVE_MKTEMP = 1, - .HAVE_OPENDIR = 1, - .HAVE_READDIR = 1, - .HAVE_SIGNAL_H = 1, - .HAVE_STDINT_H = 1, - .HAVE_STRTOLL = 1, - .HAVE_SYS_PARAM_H = 1, - .HAVE_SYS_STAT_H = 1, - .HAVE_SYS_TIME_H = 1, - .HAVE_UINT64_T = 1, - .HAVE_UTIME_H = 1, - .HAVE__ALLOCA = 1, - .HAVE___ASHLDI3 = 1, - .HAVE___ASHRDI3 = 1, - .HAVE___CMPDI2 = 1, - .HAVE___DIVDI3 = 1, - .HAVE___FIXDFDI = 1, - .HAVE___FIXSFDI = 1, - .HAVE___FLOATDIDF = 1, - .HAVE___LSHRDI3 = 1, - .HAVE___MAIN = 1, - .HAVE___MODDI3 = 1, - .HAVE___UDIVDI3 = 1, - .HAVE___UMODDI3 = 1, - .HAVE____CHKSTK_MS = 1, - .LLVM_ENABLE_ZLIB = 0, - .PACKAGE_BUGREPORT = "http://llvm.org/bugs/", - .PACKAGE_NAME = "LLVM", - .PACKAGE_STRING = "LLVM 3.7-v1.4.0.2274-1812-g84da60c6c-dirty", - .PACKAGE_VERSION = "3.7-v1.4.0.2274-1812-g84da60c6c-dirty", - .RETSIGTYPE = "void", - .WIN32_ELMCB_PCSTR = "PCSTR", - .HAVE__CHSIZE_S = 1, - }); - - return switch (which) { - .llvm_config_h => b.addConfigHeader(.{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/llvm-config.h.cmake" } }, - .include_path = "llvm/Config/llvm-config.h", - }, llvm_config_h), - .config_h => b.addConfigHeader(.{ - .style = .{ .cmake = .{ .path = "config-headers/include/llvm/Config/config.h.cmake" } }, - .include_path = "llvm/Config/config.h", - }, config_h), - else => unreachable, - }; + step.addIncludePath(.{ .path = tools_prefix ++ "/external/SPIRV-Headers/include" }); } fn ensureCommandExists(allocator: std.mem.Allocator, name: []const u8, exist_check: []const u8) bool { @@ -522,31 +243,6 @@ fn isEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { } } -// Merge struct types A and B -fn Merge(comptime a: type, comptime b: type) type { - const a_fields = @typeInfo(a).Struct.fields; - const b_fields = @typeInfo(b).Struct.fields; - - return @Type(std.builtin.Type{ - .Struct = .{ - .layout = .Auto, - .fields = a_fields ++ b_fields, - .decls = &.{}, - .is_tuple = false, - }, - }); -} - -// Merge struct values A and B -fn merge(a: anytype, b: anytype) Merge(@TypeOf(a), @TypeOf(b)) { - var merged: Merge(@TypeOf(a), @TypeOf(b)) = undefined; - inline for (@typeInfo(@TypeOf(merged)).Struct.fields) |f| { - if (@hasField(@TypeOf(a), f.name)) @field(merged, f.name) = @field(a, f.name); - if (@hasField(@TypeOf(b), f.name)) @field(merged, f.name) = @field(b, f.name); - } - return merged; -} - fn sdkPath(comptime suffix: []const u8) []const u8 { if (suffix[0] != '/') @compileError("suffix must be an absolute path"); return comptime blk: { @@ -555,7 +251,12 @@ fn sdkPath(comptime suffix: []const u8) []const u8 { }; } +var download_mutex = std.Thread.Mutex{}; + const DownloadSourceStep = struct { + repository: []const u8, + revision: []const u8, + output: []const u8, step: std.Build.Step, b: *std.Build, @@ -575,7 +276,8 @@ const DownloadSourceStep = struct { fn make(step_ptr: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void { _ = prog_node; - const download_step = @fieldParentPtr(DownloadSourceStep, "step", step_ptr); + + const download_step: DownloadSourceStep = @fieldParentPtr("step", step_ptr); const b = download_step.b; // Zig will run build steps in parallel if possible, so if there were two invocations of @@ -584,223 +286,10 @@ const DownloadSourceStep = struct { download_mutex.lock(); defer download_mutex.unlock(); - try ensureGitRepoCloned(b.allocator, source_repository, source_revision, sdkPath("/libs/DirectXShaderCompiler")); + try ensureGitRepoCloned(b.allocator, download_step.repository, download_step.revision, download_step.output); } }; -// ------------------------------------------ -// Binary download logic -// ------------------------------------------ -const project_name = "dxcompiler"; - -var download_mutex = std.Thread.Mutex{}; - -fn binaryZigTriple(arena: std.mem.Allocator, target: std.Target) ![]const u8 { - // Craft a zig_triple string that we will use to create the binary download URL. Remove OS - // version range / glibc version from triple, as we don't include that in our download URL. - var binary_target = std.zig.CrossTarget.fromTarget(target); - binary_target.os_version_min = .{ .none = undefined }; - binary_target.os_version_max = .{ .none = undefined }; - binary_target.glibc_version = null; - return try binary_target.zigTriple(arena); -} - -fn binaryOptimizeMode(optimize: std.builtin.OptimizeMode) []const u8 { - return switch (optimize) { - .Debug => "Debug", - // All Release* are mapped to ReleaseFast, as we only provide ReleaseFast and Debug binaries. - .ReleaseSafe => "ReleaseFast", - .ReleaseFast => "ReleaseFast", - .ReleaseSmall => "ReleaseFast", - }; -} - -fn binaryCacheDirPath(b: *std.Build, target: std.Target, optimize: std.builtin.OptimizeMode) ![]const u8 { - // Global Mach project cache directory, e.g. $HOME/.cache/zig/mach/ - // TODO: remove this once https://github.com/ziglang/zig/issues/16149 is fixed. - const global_cache_root = if (@hasField(std.Build, "graph")) b.graph.global_cache_root else b.global_cache_root; - const project_cache_dir_rel = try global_cache_root.join(b.allocator, &.{ "mach", project_name }); - - // Release-specific cache directory, e.g. $HOME/.cache/zig/mach//// - // where we will download the binary release to. - return try std.fs.path.join(b.allocator, &.{ - project_cache_dir_rel, - latest_binary_release, - try binaryZigTriple(b.allocator, target), - binaryOptimizeMode(optimize), - }); -} - -const DownloadBinaryStep = struct { - target: std.Target, - optimize: std.builtin.OptimizeMode, - step: std.Build.Step, - b: *std.Build, - - fn init(b: *std.Build, target: std.Target, optimize: std.builtin.OptimizeMode) *DownloadBinaryStep { - const download_step = b.allocator.create(DownloadBinaryStep) catch unreachable; - download_step.* = .{ - .target = target, - .optimize = optimize, - .step = std.Build.Step.init(.{ - .id = .custom, - .name = "download", - .owner = b, - .makeFn = &make, - }), - .b = b, - }; - return download_step; - } - - fn make(step_ptr: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void { - _ = prog_node; - const download_step = @fieldParentPtr(DownloadBinaryStep, "step", step_ptr); - const b = download_step.b; - const target = download_step.target; - const optimize = download_step.optimize; - - // Zig will run build steps in parallel if possible, so if there were two invocations of - // then this function would be called in parallel. We're manipulating the FS here - // and so need to prevent that. - download_mutex.lock(); - defer download_mutex.unlock(); - - // Check if we've already downloaded binaries to the cache dir - const cache_dir = try binaryCacheDirPath(b, target, optimize); - if (dirExists(cache_dir)) { - // Nothing to do. - return; - } - std.fs.cwd().makePath(cache_dir) catch |err| { - log.err("unable to create cache dir '{s}': {s}", .{ cache_dir, @errorName(err) }); - return error.DownloadFailed; - }; - - // Compose the download URL, e.g. - // https://github.com/hexops/mach-dxcompiler/releases/download/2023.11.30%2Ba451866.3/aarch64-linux-gnu_Debug_bin.tar.gz - const download_url = try std.mem.concat(b.allocator, u8, &.{ - "https://github.com", - "/hexops/mach-" ++ project_name ++ "/releases/download/", - latest_binary_release, - "/", - try binaryZigTriple(b.allocator, target), - "_", - binaryOptimizeMode(optimize), - "_lib", - ".tar.zst", - }); - - try downloadExtractTarball( - b.allocator, - cache_dir, - try std.fs.openDirAbsolute(cache_dir, .{}), - download_url, - ); - } -}; - -fn downloadExtractTarball( - arena: std.mem.Allocator, - out_dir_path: []const u8, - out_dir: std.fs.Dir, - url: []const u8, -) !void { - log.info("downloading {s}\n", .{url}); - const gpa = arena; - - // Fetch the file into memory. - var resp = std.ArrayList(u8).init(arena); - defer resp.deinit(); - var client: std.http.Client = .{ .allocator = gpa }; - defer client.deinit(); - var fetch_res = client.fetch(.{ - .location = .{ .url = url }, - .response_storage = .{ .dynamic = &resp }, - .max_append_size = 50 * 1024 * 1024, - }) catch |err| { - log.err("unable to fetch: error: {s}", .{@errorName(err)}); - return error.FetchFailed; - }; - if (fetch_res.status.class() != .success) { - log.err("unable to fetch: HTTP {}", .{fetch_res.status}); - return error.FetchFailed; - } - log.info("extracting {} bytes to {s}\n", .{ resp.items.len, out_dir_path }); - - // Decompress tarball - const window_buffer = try gpa.alloc(u8, 1 << 23); - defer gpa.free(window_buffer); - - var fbs = std.io.fixedBufferStream(resp.items); - var decompressor = std.compress.zstd.decompressor(fbs.reader(), .{ - .window_buffer = window_buffer, - }); - - // Unpack tarball - var diagnostics: std.tar.Options.Diagnostics = .{ .allocator = gpa }; - defer diagnostics.deinit(); - std.tar.pipeToFileSystem(out_dir, decompressor.reader(), .{ - .diagnostics = &diagnostics, - .strip_components = 1, - // TODO: we would like to set this to executable_bit_only, but two - // things need to happen before that: - // 1. the tar implementation needs to support it - // 2. the hashing algorithm here needs to support detecting the is_executable - // bit on Windows from the ACLs (see the isExecutable function). - .mode_mode = .ignore, - .exclude_empty_directories = true, - }) catch |err| { - log.err("unable to unpack tarball: {s}", .{@errorName(err)}); - return error.UnpackFailed; - }; - if (diagnostics.errors.items.len > 0) { - const notes_len: u32 = @intCast(diagnostics.errors.items.len); - log.err("unable to unpack tarball(2)", .{}); - for (diagnostics.errors.items, notes_len..) |item, note_i| { - _ = note_i; - - switch (item) { - .unable_to_create_sym_link => |info| { - log.err("unable to create symlink from '{s}' to '{s}': {s}", .{ info.file_name, info.link_name, @errorName(info.code) }); - }, - .unable_to_create_file => |info| { - log.err("unable to create file '{s}': {s}", .{ info.file_name, @errorName(info.code) }); - }, - .unsupported_file_type => |info| { - log.err("file '{s}' has unsupported type '{c}'", .{ info.file_name, @intFromEnum(info.file_type) }); - }, - } - } - return error.UnpackFailed; - } - log.info("finished\n", .{}); -} - -fn dirExists(path: []const u8) bool { - var dir = std.fs.openDirAbsolute(path, .{}) catch return false; - dir.close(); - return true; -} - -const hex_charset = "0123456789abcdef"; - -fn hex64(x: u64) [16]u8 { - var result: [16]u8 = undefined; - var i: usize = 0; - while (i < 8) : (i += 1) { - const byte = @as(u8, @truncate(x >> @as(u6, @intCast(8 * i)))); - result[i * 2 + 0] = hex_charset[byte >> 4]; - result[i * 2 + 1] = hex_charset[byte & 15]; - } - return result; -} - -test hex64 { - const s = "[" ++ hex64(0x12345678_abcdef00) ++ "]"; - try std.testing.expectEqualStrings("[00efcdab78563412]", s); -} - // ------------------------------------------ // SPIR-V include generation logic // ------------------------------------------ @@ -812,8 +301,8 @@ fn ensurePython(allocator: std.mem.Allocator) void { } } -const spirv_headers_path = prefix ++ "/external/SPIRV-Headers"; -const spirv_tools_path = prefix ++ "/external/SPIRV-Tools"; +const spirv_headers_path = tools_prefix ++ "/external/SPIRV-Headers"; +const spirv_tools_path = tools_prefix ++ "/external/SPIRV-Tools"; const spirv_output_path = "generated-include/spirv-tools"; const grammar_tables_script = spirv_tools_path ++ "/utils/generate_grammar_tables.py"; @@ -913,15 +402,15 @@ fn genSPIRVLanguageHeader(allocator: std.mem.Allocator, comptime name: []const u }; } -fn genSPIRVVendorTable(allocator: std.mem.Allocator, comptime name: []const u8, comptime operand_kind_prefix: []const u8) void { +fn genSPIRVVendorTable(allocator: std.mem.Allocator, comptime name: []const u8, comptime operand_kind_tools_prefix: []const u8) void { const extinst_vendor_grammar = spirv_headers_path ++ "/include/spirv/unified1/extinst." ++ name ++ ".grammar.json"; const extinst_file = spirv_output_path ++ "/" ++ name ++ ".insts.inc"; const args = &[_][]const u8{ - "python3", grammar_tables_script, - "--extinst-vendor-grammar", extinst_vendor_grammar, - "--vendor-insts-output", extinst_file, - "--vendor-operand-kind-prefix", operand_kind_prefix, + "python3", grammar_tables_script, + "--extinst-vendor-grammar", extinst_vendor_grammar, + "--vendor-insts-output", extinst_file, + "--vendor-operand-kind-tools_prefix", operand_kind_tools_prefix, }; exec(allocator, args, sdkPath("/")) catch |err| @@ -1019,7 +508,7 @@ const BuildSPIRVGrammarStep = struct { fn make(step_ptr: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void { _ = prog_node; - const build_grammar_step = @fieldParentPtr(BuildSPIRVGrammarStep, "step", step_ptr); + const build_grammar_step: BuildSPIRVGrammarStep = @fieldParentPtr("step", step_ptr); const b = build_grammar_step.b; // Zig will run build steps in parallel if possible, so if there were two invocations of @@ -1032,245 +521,255 @@ const BuildSPIRVGrammarStep = struct { } }; +const tools_source_path = tools_prefix ++ "/source/"; + const spirv_tools = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_reducer_options.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_validator_options.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_endian.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/table.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/text.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_fuzzer_options.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/parsed_operand.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/operand.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/assembly_grammar.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/text_handler.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opcode.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/pch_source.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/software_version.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/binary.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/ext_inst.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/print.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/disassemble.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/enum_string_mapping.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_optimizer_options.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/libspirv.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/diagnostic.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/spirv_target_env.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/name_mapper.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/extensions.cpp", + tools_source_path ++ "spirv_reducer_options.cpp", + tools_source_path ++ "spirv_validator_options.cpp", + tools_source_path ++ "spirv_endian.cpp", + tools_source_path ++ "table.cpp", + tools_source_path ++ "text.cpp", + tools_source_path ++ "spirv_fuzzer_options.cpp", + tools_source_path ++ "parsed_operand.cpp", + tools_source_path ++ "operand.cpp", + tools_source_path ++ "assembly_grammar.cpp", + tools_source_path ++ "text_handler.cpp", + tools_source_path ++ "opcode.cpp", + tools_source_path ++ "pch_source.cpp", + tools_source_path ++ "software_version.cpp", + tools_source_path ++ "binary.cpp", + tools_source_path ++ "ext_inst.cpp", + tools_source_path ++ "print.cpp", + tools_source_path ++ "disassemble.cpp", + tools_source_path ++ "enum_string_mapping.cpp", + tools_source_path ++ "spirv_optimizer_options.cpp", + tools_source_path ++ "libspirv.cpp", + tools_source_path ++ "diagnostic.cpp", + tools_source_path ++ "spirv_target_env.cpp", + tools_source_path ++ "name_mapper.cpp", + tools_source_path ++ "extensions.cpp", }; +const tools_reduce_path = tools_source_path ++ "reduce/"; + const spirv_tools_reduce = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/structured_construct_to_block_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/operand_to_undef_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_block_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/change_operand_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_unused_struct_member_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/simple_conditional_branch_to_branch_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_function_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/merge_blocks_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/simple_conditional_branch_to_branch_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/structured_construct_to_block_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/change_operand_to_undef_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_function_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_selection_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/operand_to_const_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_block_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/reduction_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/conditional_branch_to_simple_conditional_branch_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/conditional_branch_to_simple_conditional_branch_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_selection_reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/pch_source_reduce.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/reduction_util.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/merge_blocks_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/reducer.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_struct_member_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/structured_loop_to_selection_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/reduction_opportunity_finder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_instruction_reduction_opportunity.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/reduce/remove_unused_instruction_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "structured_loop_to_selection_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "structured_construct_to_block_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "operand_to_undef_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "remove_block_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "change_operand_reduction_opportunity.cpp", + tools_reduce_path ++ "remove_unused_struct_member_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "simple_conditional_branch_to_branch_opportunity_finder.cpp", + tools_reduce_path ++ "remove_function_reduction_opportunity.cpp", + tools_reduce_path ++ "merge_blocks_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "simple_conditional_branch_to_branch_reduction_opportunity.cpp", + tools_reduce_path ++ "structured_construct_to_block_reduction_opportunity.cpp", + tools_reduce_path ++ "reduction_opportunity.cpp", + tools_reduce_path ++ "change_operand_to_undef_reduction_opportunity.cpp", + tools_reduce_path ++ "remove_function_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "remove_selection_reduction_opportunity.cpp", + tools_reduce_path ++ "operand_to_const_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "operand_to_dominating_id_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "remove_block_reduction_opportunity.cpp", + tools_reduce_path ++ "reduction_pass.cpp", + tools_reduce_path ++ "conditional_branch_to_simple_conditional_branch_reduction_opportunity.cpp", + tools_reduce_path ++ "conditional_branch_to_simple_conditional_branch_opportunity_finder.cpp", + tools_reduce_path ++ "remove_selection_reduction_opportunity_finder.cpp", + tools_reduce_path ++ "pch_source_reduce.cpp", + tools_reduce_path ++ "reduction_util.cpp", + tools_reduce_path ++ "merge_blocks_reduction_opportunity.cpp", + tools_reduce_path ++ "reducer.cpp", + tools_reduce_path ++ "remove_struct_member_reduction_opportunity.cpp", + tools_reduce_path ++ "structured_loop_to_selection_reduction_opportunity.cpp", + tools_reduce_path ++ "reduction_opportunity_finder.cpp", + tools_reduce_path ++ "remove_instruction_reduction_opportunity.cpp", + tools_reduce_path ++ "remove_unused_instruction_reduction_opportunity_finder.cpp", }; +const tools_opt_path = tools_source_path ++ "opt/"; + const spirv_tools_opt = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_unswitch_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_output_stores_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dominator_tree.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/flatten_decoration_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/convert_to_half_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_unroller.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/interface_var_sroa.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/wrap_opkill.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inst_debug_printf_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/liveness.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_io_components_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/feature_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/instrument_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/scalar_replacement_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_dependence_helpers.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/redundancy_elimination.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/strip_nonsemantic_info_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/aggressive_dead_code_elim_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/fix_func_call_arguments.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/fold_spec_constant_op_and_composite_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dataflow.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/block_merge_util.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/relax_float_ops_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/interp_fixup_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/instruction.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/folding_rules.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inst_bindless_check_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/ssa_rewrite_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inline_exhaustive_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/amd_ext_to_khr.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dead_branch_elim_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_dependence.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_constant_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/simplification_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_functions_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_fusion_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/decoration_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/debug_info_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/basic_block.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/switch_descriptorset_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/code_sink.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/fix_storage_class.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/convert_to_sampled_image_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/graphics_robust_access_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inline_opaque_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/strip_debug_info_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dominator_analysis.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/upgrade_memory_model.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_peeling.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/register_pressure.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/unify_const_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/replace_desc_array_access_using_var_index.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/analyze_live_input_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/invocation_interlock_placement_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/scalar_analysis.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/local_redundancy_elimination.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inst_buff_addr_check_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/const_folding_rules.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/trim_capabilities_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/reduce_load_size.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/build_module.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/local_single_store_elim_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/mem_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/module.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/scalar_analysis_simplification.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/function.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/desc_sroa.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/def_use_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/compact_ids_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/workaround1209.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/instruction_list.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_fission.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/strength_reduction_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/remove_unused_interface_variables_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/fold.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/ccp_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/if_conversion.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/value_number_table.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_descriptor.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/inline_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/struct_cfg_analysis.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/composite.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/freeze_spec_constant_value_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/cfg.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/ir_loader.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/licm_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/replace_invalid_opc.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/propagator.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/types.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/private_to_local_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/spread_volatile_semantics.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dead_variable_elimination.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_utils.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/local_access_chain_convert_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/cfg_cleanup_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/combine_access_chains.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/copy_prop_arrays.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/type_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/ir_context.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/constants.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/remove_dontinline_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/dead_insert_elim_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/pass_manager.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/merge_return_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/remove_duplicates_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_functions_util.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/eliminate_dead_members_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/control_dependence.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/vector_dce.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/optimizer.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/block_merge_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/desc_sroa_util.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/local_single_block_elim_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/set_spec_constant_default_value_pass.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/pch_source_opt.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/opt/loop_fusion.cpp", + tools_opt_path ++ "loop_unswitch_pass.cpp", + tools_opt_path ++ "eliminate_dead_output_stores_pass.cpp", + tools_opt_path ++ "dominator_tree.cpp", + tools_opt_path ++ "flatten_decoration_pass.cpp", + tools_opt_path ++ "convert_to_half_pass.cpp", + tools_opt_path ++ "loop_unroller.cpp", + tools_opt_path ++ "interface_var_sroa.cpp", + tools_opt_path ++ "wrap_opkill.cpp", + tools_opt_path ++ "inst_debug_printf_pass.cpp", + tools_opt_path ++ "liveness.cpp", + tools_opt_path ++ "eliminate_dead_io_components_pass.cpp", + tools_opt_path ++ "feature_manager.cpp", + tools_opt_path ++ "instrument_pass.cpp", + tools_opt_path ++ "scalar_replacement_pass.cpp", + tools_opt_path ++ "loop_dependence_helpers.cpp", + tools_opt_path ++ "redundancy_elimination.cpp", + tools_opt_path ++ "strip_nonsemantic_info_pass.cpp", + tools_opt_path ++ "aggressive_dead_code_elim_pass.cpp", + tools_opt_path ++ "fix_func_call_arguments.cpp", + tools_opt_path ++ "fold_spec_constant_op_and_composite_pass.cpp", + tools_opt_path ++ "dataflow.cpp", + tools_opt_path ++ "block_merge_util.cpp", + tools_opt_path ++ "pass.cpp", + tools_opt_path ++ "relax_float_ops_pass.cpp", + tools_opt_path ++ "interp_fixup_pass.cpp", + tools_opt_path ++ "instruction.cpp", + tools_opt_path ++ "folding_rules.cpp", + tools_opt_path ++ "inst_bindless_check_pass.cpp", + tools_opt_path ++ "ssa_rewrite_pass.cpp", + tools_opt_path ++ "inline_exhaustive_pass.cpp", + tools_opt_path ++ "amd_ext_to_khr.cpp", + tools_opt_path ++ "dead_branch_elim_pass.cpp", + tools_opt_path ++ "loop_dependence.cpp", + tools_opt_path ++ "eliminate_dead_constant_pass.cpp", + tools_opt_path ++ "simplification_pass.cpp", + tools_opt_path ++ "eliminate_dead_functions_pass.cpp", + tools_opt_path ++ "loop_fusion_pass.cpp", + tools_opt_path ++ "decoration_manager.cpp", + tools_opt_path ++ "debug_info_manager.cpp", + tools_opt_path ++ "basic_block.cpp", + tools_opt_path ++ "switch_descriptorset_pass.cpp", + tools_opt_path ++ "code_sink.cpp", + tools_opt_path ++ "fix_storage_class.cpp", + tools_opt_path ++ "convert_to_sampled_image_pass.cpp", + tools_opt_path ++ "graphics_robust_access_pass.cpp", + tools_opt_path ++ "inline_opaque_pass.cpp", + tools_opt_path ++ "strip_debug_info_pass.cpp", + tools_opt_path ++ "dominator_analysis.cpp", + tools_opt_path ++ "upgrade_memory_model.cpp", + tools_opt_path ++ "loop_peeling.cpp", + tools_opt_path ++ "register_pressure.cpp", + tools_opt_path ++ "unify_const_pass.cpp", + tools_opt_path ++ "replace_desc_array_access_using_var_index.cpp", + tools_opt_path ++ "analyze_live_input_pass.cpp", + tools_opt_path ++ "invocation_interlock_placement_pass.cpp", + tools_opt_path ++ "scalar_analysis.cpp", + tools_opt_path ++ "local_redundancy_elimination.cpp", + tools_opt_path ++ "inst_buff_addr_check_pass.cpp", + tools_opt_path ++ "const_folding_rules.cpp", + tools_opt_path ++ "trim_capabilities_pass.cpp", + tools_opt_path ++ "reduce_load_size.cpp", + tools_opt_path ++ "build_module.cpp", + tools_opt_path ++ "local_single_store_elim_pass.cpp", + tools_opt_path ++ "mem_pass.cpp", + tools_opt_path ++ "module.cpp", + tools_opt_path ++ "scalar_analysis_simplification.cpp", + tools_opt_path ++ "function.cpp", + tools_opt_path ++ "desc_sroa.cpp", + tools_opt_path ++ "def_use_manager.cpp", + tools_opt_path ++ "compact_ids_pass.cpp", + tools_opt_path ++ "workaround1209.cpp", + tools_opt_path ++ "instruction_list.cpp", + tools_opt_path ++ "loop_fission.cpp", + tools_opt_path ++ "strength_reduction_pass.cpp", + tools_opt_path ++ "remove_unused_interface_variables_pass.cpp", + tools_opt_path ++ "fold.cpp", + tools_opt_path ++ "ccp_pass.cpp", + tools_opt_path ++ "if_conversion.cpp", + tools_opt_path ++ "value_number_table.cpp", + tools_opt_path ++ "loop_descriptor.cpp", + tools_opt_path ++ "inline_pass.cpp", + tools_opt_path ++ "struct_cfg_analysis.cpp", + tools_opt_path ++ "composite.cpp", + tools_opt_path ++ "freeze_spec_constant_value_pass.cpp", + tools_opt_path ++ "cfg.cpp", + tools_opt_path ++ "ir_loader.cpp", + tools_opt_path ++ "licm_pass.cpp", + tools_opt_path ++ "replace_invalid_opc.cpp", + tools_opt_path ++ "propagator.cpp", + tools_opt_path ++ "types.cpp", + tools_opt_path ++ "private_to_local_pass.cpp", + tools_opt_path ++ "spread_volatile_semantics.cpp", + tools_opt_path ++ "dead_variable_elimination.cpp", + tools_opt_path ++ "loop_utils.cpp", + tools_opt_path ++ "local_access_chain_convert_pass.cpp", + tools_opt_path ++ "cfg_cleanup_pass.cpp", + tools_opt_path ++ "combine_access_chains.cpp", + tools_opt_path ++ "copy_prop_arrays.cpp", + tools_opt_path ++ "type_manager.cpp", + tools_opt_path ++ "ir_context.cpp", + tools_opt_path ++ "constants.cpp", + tools_opt_path ++ "remove_dontinline_pass.cpp", + tools_opt_path ++ "dead_insert_elim_pass.cpp", + tools_opt_path ++ "pass_manager.cpp", + tools_opt_path ++ "merge_return_pass.cpp", + tools_opt_path ++ "remove_duplicates_pass.cpp", + tools_opt_path ++ "eliminate_dead_functions_util.cpp", + tools_opt_path ++ "eliminate_dead_members_pass.cpp", + tools_opt_path ++ "control_dependence.cpp", + tools_opt_path ++ "vector_dce.cpp", + tools_opt_path ++ "optimizer.cpp", + tools_opt_path ++ "block_merge_pass.cpp", + tools_opt_path ++ "desc_sroa_util.cpp", + tools_opt_path ++ "local_single_block_elim_pass.cpp", + tools_opt_path ++ "set_spec_constant_default_value_pass.cpp", + tools_opt_path ++ "pch_source_opt.cpp", + tools_opt_path ++ "loop_fusion.cpp", }; +const tools_util_path = tools_source_path ++ "util/"; + const spirv_tools_util = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/util/bit_vector.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/util/parse_number.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/util/string_utils.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/util/timer.cpp", + tools_util_path ++ "bit_vector.cpp", + tools_util_path ++ "parse_number.cpp", + tools_util_path ++ "string_utils.cpp", + tools_util_path ++ "timer.cpp", }; const spirv_tools_wasm = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/wasm/spirv-tools.cpp", + tools_source_path ++ "wasm/spirv-tools.cpp", }; const spirv_tools_link = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/link/linker.cpp", + tools_source_path ++ "link/linker.cpp", }; +const tools_val_path = tools_source_path ++ "val/"; + const spirv_tools_val = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_extensions.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_conversion.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_arithmetics.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_primitives.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_ray_tracing.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_builtins.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_atomics.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_memory.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/instruction.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_ray_tracing_reorder.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_ray_query.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_literals.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/construct.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/basic_block.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_small_type_uses.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_instruction.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_logicals.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_execution_limitations.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_mesh_shading.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_capability.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_decorations.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validation_state.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_function.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/function.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_interfaces.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_image.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_constants.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_derivatives.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_cfg.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_barriers.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_mode_setting.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_memory_semantics.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_type.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_misc.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_debug.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_bitwise.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_adjacency.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_annotation.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_layout.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_composites.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_scopes.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_non_uniform.cpp", - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/val/validate_id.cpp", + tools_val_path ++ "validate_extensions.cpp", + tools_val_path ++ "validate_conversion.cpp", + tools_val_path ++ "validate_arithmetics.cpp", + tools_val_path ++ "validate_primitives.cpp", + tools_val_path ++ "validate_ray_tracing.cpp", + tools_val_path ++ "validate_builtins.cpp", + tools_val_path ++ "validate_atomics.cpp", + tools_val_path ++ "validate_memory.cpp", + tools_val_path ++ "instruction.cpp", + tools_val_path ++ "validate_ray_tracing_reorder.cpp", + tools_val_path ++ "validate_ray_query.cpp", + tools_val_path ++ "validate_literals.cpp", + tools_val_path ++ "construct.cpp", + tools_val_path ++ "basic_block.cpp", + tools_val_path ++ "validate.cpp", + tools_val_path ++ "validate_small_type_uses.cpp", + tools_val_path ++ "validate_instruction.cpp", + tools_val_path ++ "validate_logicals.cpp", + tools_val_path ++ "validate_execution_limitations.cpp", + tools_val_path ++ "validate_mesh_shading.cpp", + tools_val_path ++ "validate_capability.cpp", + tools_val_path ++ "validate_decorations.cpp", + tools_val_path ++ "validation_state.cpp", + tools_val_path ++ "validate_function.cpp", + tools_val_path ++ "function.cpp", + tools_val_path ++ "validate_interfaces.cpp", + tools_val_path ++ "validate_image.cpp", + tools_val_path ++ "validate_constants.cpp", + tools_val_path ++ "validate_derivatives.cpp", + tools_val_path ++ "validate_cfg.cpp", + tools_val_path ++ "validate_barriers.cpp", + tools_val_path ++ "validate_mode_setting.cpp", + tools_val_path ++ "validate_memory_semantics.cpp", + tools_val_path ++ "validate_type.cpp", + tools_val_path ++ "validate_misc.cpp", + tools_val_path ++ "validate_debug.cpp", + tools_val_path ++ "validate_bitwise.cpp", + tools_val_path ++ "validate_adjacency.cpp", + tools_val_path ++ "validate_annotation.cpp", + tools_val_path ++ "validate_layout.cpp", + tools_val_path ++ "validate_composites.cpp", + tools_val_path ++ "validate_scopes.cpp", + tools_val_path ++ "validate_non_uniform.cpp", + tools_val_path ++ "validate_id.cpp", }; diff --git a/build.zig b/build.zig index 3277c9c2..95cc70c5 100644 --- a/build.zig +++ b/build.zig @@ -280,7 +280,7 @@ pub fn build(b: *Build) !void { if (build_shared) buildShared(b, lib, optimize, target); break :blk .{ .lib = lib, .lib_path = null }; - } + }; }; if (skip_executables) diff --git a/zig-cache/h/916a2c2d22523ac2946045bc514be1a6.txt b/zig-cache/h/916a2c2d22523ac2946045bc514be1a6.txt new file mode 100644 index 00000000..e69de29b diff --git a/zig-cache/h/timestamp b/zig-cache/h/timestamp new file mode 100644 index 00000000..e69de29b diff --git a/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig b/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig new file mode 100644 index 00000000..72e4e833 --- /dev/null +++ b/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig @@ -0,0 +1,2 @@ +pub const packages = struct {}; +pub const root_deps: []const struct { []const u8, []const u8 } = &.{}; diff --git a/zig-cache/z/0fe4ee79a5f079bb208b60e7e999830b b/zig-cache/z/0fe4ee79a5f079bb208b60e7e999830b new file mode 100644 index 00000000..de653401 Binary files /dev/null and b/zig-cache/z/0fe4ee79a5f079bb208b60e7e999830b differ