From 6b8daf4802ef6a467b89087bfddd992bd854a325 Mon Sep 17 00:00:00 2001 From: Kai Angulo Date: Thu, 30 May 2024 01:12:00 -0700 Subject: [PATCH] Cleaned cache --- .gitignore | 2 + External/spirv-tools.zig | 775 -------- build.zig | 1621 +++-------------- known_good_zig.json | 25 + lack.cpp | 13 + test.cpp | 86 + update_glslang_sources.py | 8 +- .../h/916a2c2d22523ac2946045bc514be1a6.txt | 0 zig-cache/h/timestamp | 0 .../dependencies.zig | 2 - zig-cache/z/0fe4ee79a5f079bb208b60e7e999830b | Bin 110 -> 0 bytes 11 files changed, 370 insertions(+), 2162 deletions(-) delete mode 100644 External/spirv-tools.zig create mode 100644 known_good_zig.json create mode 100644 lack.cpp create mode 100644 test.cpp delete mode 100644 zig-cache/h/916a2c2d22523ac2946045bc514be1a6.txt delete mode 100644 zig-cache/h/timestamp delete mode 100644 zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig delete mode 100644 zig-cache/z/0fe4ee79a5f079bb208b60e7e999830b diff --git a/.gitignore b/.gitignore index 732b3459..5a841fa7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ tags TAGS bazel-* build/ +zig-cache/ +zig-out/ Test/localResults/ External/googletest External/spirv-tools diff --git a/External/spirv-tools.zig b/External/spirv-tools.zig deleted file mode 100644 index 16897c40..00000000 --- a/External/spirv-tools.zig +++ /dev/null @@ -1,775 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const Build = std.Build; - -/// When building from source, which repository and revision to clone. -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 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 spirv-tools as a shared library") orelse false; - - _ = build_spirv(b, optimize, target, debug_symbols, build_shared); -} - -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); - - if (!debug_symbols) { - try cflags.append("-g0"); - try cppflags.append("-g0"); - } - - try cppflags.append("-std=c++17"); - - const base_flags = &.{ - "-Wno-unused-command-line-argument", - "-Wno-unused-variable", - "-Wno-missing-exception-spec", - "-Wno-macro-redefined", - "-Wno-unknown-attributes", - "-Wno-implicit-fallthrough", - "-fms-extensions", - }; - - try cflags.appendSlice(base_flags); - try cppflags.appendSlice(base_flags); - - const spirv_cpp_sources = - spirv_tools ++ - spirv_tools_util ++ - spirv_tools_reduce ++ - spirv_tools_link ++ - spirv_tools_val ++ - // spirv_tools_wasm ++ // Wasm build support- requires emscripten toolchain - spirv_tools_opt; - - 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", ""); - } else if (target.result.os.tag == .linux) { - spv_lib.defineCMacro("SPIRV_LINUX", ""); - } else if (target.result.os.tag == .macos) { - spv_lib.defineCMacro("SPIRV_MAC", ""); - } else if (target.result.os.tag == .ios) { - spv_lib.defineCMacro("SPIRV_IOS", ""); - } else if (target.result.os.tag == .tvos) { - spv_lib.defineCMacro("SPIRV_TVOS", ""); - } else if (target.result.os.tag == .kfreebsd) { - spv_lib.defineCMacro("SPIRV_FREEBSD", ""); - } else if (target.result.os.tag == .openbsd) { - spv_lib.defineCMacro("SPIRV_OPENBSD", ""); - } else if (target.result.os.tag == .fuchsia) { - spv_lib.defineCMacro("SPIRV_FUCHSIA", ""); - } else { - log.err("Compilation target incompatible with SPIR-V.", .{}); - std.process.exit(1); - } - - 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, - .flags = cppflags.items, - }); - - spv_lib.defineCMacro("SPIRV_COLOR_TERMINAL", ""); // Pretty lights by default - - addSPIRVIncludes(spv_lib); - linkSPIRVDependencies(spv_lib); - - b.installArtifact(spv_lib); - - return spv_lib; -} - -fn linkSPIRVDependencies(step: *std.Build.Step.Compile) void { - const target = step.rootModuleTarget(); - - if (target.abi == .msvc) { - step.linkLibC(); - } else { - step.linkLibCpp(); - } - - if (target.os.tag == .windows) { - step.linkSystemLibrary("ole32"); - step.linkSystemLibrary("oleaut32"); - } -} - -fn addSPIRVIncludes(step: *std.Build.Step.Compile) void { - // Generated SPIR-V headers get thrown in here - step.addIncludePath(.{ .path = "generated-include" }); - - 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 = tools_prefix ++ "/external/SPIRV-Headers/include" }); -} - -fn ensureCommandExists(allocator: std.mem.Allocator, name: []const u8, exist_check: []const u8) bool { - const result = std.ChildProcess.run(.{ - .allocator = allocator, - .argv = &[_][]const u8{ name, exist_check }, - .cwd = ".", - }) catch // e.g. FileNotFound - { - return false; - }; - - defer { - allocator.free(result.stderr); - allocator.free(result.stdout); - } - - if (result.term.Exited != 0) - return false; - - return true; -} - -// ------------------------------------------ -// Source cloning logic -// ------------------------------------------ - -fn ensureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, dir: []const u8) !void { - if (isEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or isEnvVarTruthy(allocator, "NO_ENSURE_GIT")) { - return; - } - - ensureGit(allocator); - - if (std.fs.openDirAbsolute(dir, .{})) |_| { - const current_revision = try getCurrentGitRevision(allocator, dir); - if (!std.mem.eql(u8, current_revision, revision)) { - // Reset to the desired revision - exec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| log.warn("failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) }); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - } - return; - } else |err| return switch (err) { - error.FileNotFound => { - log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); - - try exec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, sdkPath("/")); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - return; - }, - else => err, - }; -} - -fn getCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { - const result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd }); - allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; -} - -// Command validation logic moved to ensureCommandExists() -fn ensureGit(allocator: std.mem.Allocator) void { - if (!ensureCommandExists(allocator, "git", "--version")) { - log.err("'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - } -} - -fn exec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void { - log.info("cd {s}", .{cwd}); - var buf = std.ArrayList(u8).init(allocator); - for (argv) |arg| { - try std.fmt.format(buf.writer(), "{s} ", .{arg}); - } - log.info("{s}", .{buf.items}); - - var child = std.ChildProcess.init(argv, allocator); - child.cwd = cwd; - _ = try child.spawnAndWait(); -} - -fn isEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { - if (std.process.getEnvVarOwned(allocator, name)) |truthy| { - defer allocator.free(truthy); - if (std.mem.eql(u8, truthy, "true")) return true; - return false; - } else |_| { - return false; - } -} - -fn sdkPath(comptime suffix: []const u8) []const u8 { - if (suffix[0] != '/') @compileError("suffix must be an absolute path"); - return comptime blk: { - const root_dir = std.fs.path.dirname(@src().file) orelse "."; - break :blk root_dir ++ suffix; - }; -} - -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, - - fn init(b: *std.Build) *DownloadSourceStep { - const download_step = b.allocator.create(DownloadSourceStep) catch unreachable; - download_step.* = .{ - .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: 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 - // 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(); - - try ensureGitRepoCloned(b.allocator, download_step.repository, download_step.revision, download_step.output); - } -}; - -// ------------------------------------------ -// SPIR-V include generation logic -// ------------------------------------------ - -fn ensurePython(allocator: std.mem.Allocator) void { - if (!ensureCommandExists(allocator, "python3", "--version")) { - log.err("'python3 --version' failed. Is python not installed?", .{}); - std.process.exit(1); - } -} - -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"; - -const debuginfo_insts_file = spirv_headers_path ++ "/include/spirv/unified1/extinst.debuginfo.grammar.json"; -const cldebuginfo100_insts_file = spirv_headers_path ++ "/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"; - -fn spvHeaderFile(comptime version: []const u8, comptime file_name: []const u8) []const u8 { - return spirv_headers_path ++ "/include/spirv/" ++ version ++ "/" ++ file_name; -} - -// Most of this was derived from the BUILD.gn file in SPIRV-Tools - -fn genSPIRVCoreTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - - // Outputs - const core_insts_file = spirv_output_path ++ "/core.insts-" ++ version ++ ".inc"; - const operand_kinds_file = spirv_output_path ++ "/operand.kinds-" ++ version ++ ".inc"; - - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--core-insts-output", core_insts_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--operand-kinds-output", operand_kinds_file, "--output-language", "c++" }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V core tables: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVCoreEnums(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - - const extension_enum_file = spirv_output_path ++ "/extension_enum.inc"; - const extension_map_file = spirv_output_path ++ "/enum_string_mapping.inc"; - - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--extension-enum-output", extension_enum_file, "--enum-string-mapping-output", extension_map_file, "--output-language", "c++" }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V core enums: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVGlslTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - const glsl_json_file = spvHeaderFile(version, "extinst.glsl.std.450.grammar.json"); - - const glsl_insts_file = spirv_output_path ++ "/glsl.std.450.insts.inc"; - - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--extinst-glsl-grammar", glsl_json_file, "--glsl-insts-output", glsl_insts_file, "--output-language", "c++" }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V GLSL tables: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVOpenCLTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - const opencl_json_file = spvHeaderFile(version, "extinst.opencl.std.100.grammar.json"); - - const opencl_insts_file = spirv_output_path ++ "/opencl.std.insts.inc"; - - const args = &[_][]const u8{ - "python3", grammar_tables_script, - "--spirv-core-grammar", core_json_file, - "--extinst-debuginfo-grammar", debuginfo_insts_file, - "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, - "--extinst-opencl-grammar", opencl_json_file, - "--opencl-insts-output", opencl_insts_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V OpenCL tables: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVLanguageHeader(allocator: std.mem.Allocator, comptime name: []const u8, comptime grammar_file: []const u8) void { - const script = spirv_tools_path ++ "/utils/generate_language_headers.py"; - - const extinst_output_path = spirv_output_path ++ "/" ++ name ++ ".h"; - - const args = &[_][]const u8{ - "python3", script, - "--extinst-grammar", grammar_file, - "--extinst-output-path", extinst_output_path, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V language header '" ++ name ++ "'. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -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-tools_prefix", operand_kind_tools_prefix, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V vendor table '" ++ name ++ "'. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVRegistryTables(allocator: std.mem.Allocator) void { - const script = spirv_tools_path ++ "/utils/generate_registry_tables.py"; - - const xml_file = spirv_headers_path ++ "/include/spirv/spir-v.xml"; - const inc_file = spirv_output_path ++ "/generators.inc"; - - const args = &[_][]const u8{ - "python3", script, - "--xml", xml_file, - "--generator", inc_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V registry tables. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn buildSPIRVVersion(allocator: std.mem.Allocator) void { - const script = spirv_tools_path ++ "/utils/update_build_version.py"; - - const changes_file = spirv_tools_path ++ "/CHANGES"; - const inc_file = spirv_output_path ++ "/build-version.inc"; - - const args = &[_][]const u8{ - "python3", script, - changes_file, inc_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V build version. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn generateSPIRVGrammar(allocator: std.mem.Allocator) void { - ensurePython(allocator); - - genSPIRVCoreTables(allocator, "unified1"); - genSPIRVCoreEnums(allocator, "unified1"); - - genSPIRVGlslTables(allocator, "1.0"); - - genSPIRVOpenCLTables(allocator, "1.0"); - - genSPIRVLanguageHeader(allocator, "DebugInfo", spvHeaderFile("unified1", "extinst.debuginfo.grammar.json")); - genSPIRVLanguageHeader(allocator, "OpenCLDebugInfo100", spvHeaderFile("unified1", "extinst.opencl.debuginfo.100.grammar.json")); - genSPIRVLanguageHeader(allocator, "NonSemanticShaderDebugInfo100", spvHeaderFile("unified1", "extinst.nonsemantic.shader.debuginfo.100.grammar.json")); - - genSPIRVVendorTable(allocator, "spv-amd-shader-explicit-vertex-parameter", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-shader-trinary-minmax", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-gcn-shader", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-shader-ballot", "...nil..."); - genSPIRVVendorTable(allocator, "debuginfo", "...nil..."); - genSPIRVVendorTable(allocator, "opencl.debuginfo.100", "CLDEBUG100_"); - genSPIRVVendorTable(allocator, "nonsemantic.clspvreflection", "...nil..."); - genSPIRVVendorTable(allocator, "nonsemantic.shader.debuginfo.100", "SHDEBUG100_"); - - genSPIRVRegistryTables(allocator); - - buildSPIRVVersion(allocator); -} - -const BuildSPIRVGrammarStep = struct { - step: std.Build.Step, - b: *std.Build, - - fn init(b: *std.Build) *BuildSPIRVGrammarStep { - const build_grammar_step = b.allocator.create(BuildSPIRVGrammarStep) catch unreachable; - - build_grammar_step.* = .{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = "generate grammar", - .owner = b, - .makeFn = &make, - }), - .b = b, - }; - - return build_grammar_step; - } - - fn make(step_ptr: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void { - _ = prog_node; - - 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 - // 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(); - - generateSPIRVGrammar(b.allocator); - } -}; - -const tools_source_path = tools_prefix ++ "/source/"; - -const spirv_tools = [_][]const u8{ - 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{ - 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{ - 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{ - 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{ - tools_source_path ++ "wasm/spirv-tools.cpp", -}; - -const spirv_tools_link = [_][]const u8{ - tools_source_path ++ "link/linker.cpp", -}; - -const tools_val_path = tools_source_path ++ "val/"; - -const spirv_tools_val = [_][]const u8{ - 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 95cc70c5..cc9eedef 100644 --- a/build.zig +++ b/build.zig @@ -1,668 +1,145 @@ const std = @import("std"); const builtin = @import("builtin"); +const spvtools = @import("External/spirv-tools/build.zig"); const Build = std.Build; -/// The latest binary release available at https://github.com/hexops/mach-dxcompiler/releases -const latest_binary_release = "2024.03.09+d19dd6d.1"; - -/// When building from source, which repository and revision to clone. -const spirv_tools_repository = "https://github.com/KhronosGroup/SPIRV-Tools"; - -const log = std.log.scoped(.mach_dxcompiler); -const prefix = "libs/DirectXShaderCompiler"; +const log = std.log.scoped(.glslang_zig); 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 debug = b.option(bool, "debug", "Whether to produce detailed debug symbols (g0) or not. These increase binary size considerably.") orelse false; + const shared = b.option(bool, "shared", "Build glslang as a shared library.") orelse false; + const enable_hlsl = !(b.option(bool, "no-hlsl", "Skip building glslang HLSL support.") orelse false); + const enable_opt = !(b.option(bool, "no-opt", "Skip building spirv-tools optimization.") orelse false); + const shared_tools = b.option(bool, "shared-tools", "Build and link spirv-tools as a shared library.") orelse false; - const machdxcompiler: struct { lib: *std.Build.Step.Compile, lib_path: ?[]const u8 } = blk: { - const lib = b.addStaticLibrary(.{ - .name = "machdxcompiler", - .root_source_file = b.addWriteFiles().add("empty.zig", ""), + const tools_libs: spvtools.SPVLibs = spvtools.build_spirv(b, optimize, target, shared_tools, debug) catch |err| { + log.err("Error building SPIRV-Tools: {s}", .{ @errorName(err) }); + std.process.exit(1); + }; + + var cppflags = std.ArrayList([]const u8).init(b.allocator); + + if (!debug) { + try cppflags.append("-g0"); + } + + try cppflags.append("-std=c++17"); + + const base_flags = &.{ + "-Wno-conversion", + "-Wno-extra-semi", + "-Wno-ignored-qualifiers", + "-Wno-implicit-fallthrough", + "-Wno-inconsistent-missing-override", + "-Wno-missing-field-initializers", + "-Wno-newline-eof", + "-Wno-sign-compare", + "-Wno-suggest-destructor-override", + "-Wno-suggest-override", + "-Wno-unused-variable", + "-fPIC", + }; + + try cppflags.appendSlice(base_flags); + +// ------------------ +// SPIRV-Tools +// ------------------ + + const build_headers = BuildHeadersStep.init(b); + + const sources = sources_spirv ++ + sources_generic_codegen ++ + sources_machine_independent ++ + sources_resource_limits ++ + sources_c_interface; + + var lib: *std.Build.Step.Compile = undefined; + + if (shared) { + lib = b.addSharedLibrary(.{ + .name = "glslang", + .root_source_file = b.addWriteFiles().add("empty.c", ""), .optimize = optimize, .target = target, }); - b.installArtifact(lib); - - var download_step = DownloadSourceStep.init(b); - lib.step.dependOn(&download_step.step); - - lib.addCSourceFile(.{ - .file = .{ .path = "src/mach_dxc.cpp" }, - .flags = &.{ - "-fms-extensions", // __uuidof and friends (on non-windows targets) - }, - }); - if (target.result.os.tag != .windows) lib.defineCMacro("HAVE_DLFCN_H", "1"); - - // The Windows 10 SDK winrt/wrl/client.h is incompatible with clang due to #pragma pack usages - // (unclear why), so instead we use the wrl/client.h headers from https://github.com/ziglang/zig/tree/225fe6ddbfae016395762850e0cd5c51f9e7751c/lib/libc/include/any-windows-any - // which seem to work fine. - if (target.result.os.tag == .windows and target.result.abi == .msvc) lib.addIncludePath(.{ .path = "msvc/" }); - - var cflags = std.ArrayList([]const u8).init(b.allocator); - var cppflags = std.ArrayList([]const u8).init(b.allocator); - if (!debug_symbols) { - try cflags.append("-g0"); - try cppflags.append("-g0"); - } - try cppflags.append("-std=c++17"); - - const base_flags = &.{ - "-Wno-unused-command-line-argument", - "-Wno-unused-variable", - "-Wno-missing-exception-spec", - "-Wno-macro-redefined", - "-Wno-unknown-attributes", - "-Wno-implicit-fallthrough", - "-fms-extensions", // __uuidof and friends (on non-windows targets) - }; - - try cflags.appendSlice(base_flags); - try cppflags.appendSlice(base_flags); - - addConfigHeaders(b, lib); - addIncludes(lib); - - const cpp_sources = - tools_clang_lib_lex_sources ++ - tools_clang_lib_basic_sources ++ - tools_clang_lib_driver_sources ++ - tools_clang_lib_analysis_sources ++ - tools_clang_lib_index_sources ++ - tools_clang_lib_parse_sources ++ - tools_clang_lib_ast_sources ++ - tools_clang_lib_edit_sources ++ - tools_clang_lib_sema_sources ++ - tools_clang_lib_codegen_sources ++ - tools_clang_lib_astmatchers_sources ++ - tools_clang_lib_tooling_core_sources ++ - tools_clang_lib_tooling_sources ++ - tools_clang_lib_format_sources ++ - tools_clang_lib_rewrite_sources ++ - tools_clang_lib_frontend_sources ++ - tools_clang_tools_libclang_sources ++ - tools_clang_tools_dxcompiler_sources ++ - lib_bitcode_reader_sources ++ - lib_bitcode_writer_sources ++ - lib_ir_sources ++ - lib_irreader_sources ++ - lib_linker_sources ++ - lib_asmparser_sources ++ - lib_analysis_sources ++ - lib_mssupport_sources ++ - lib_transforms_utils_sources ++ - lib_transforms_instcombine_sources ++ - lib_transforms_ipo_sources ++ - lib_transforms_scalar_sources ++ - lib_transforms_vectorize_sources ++ - lib_target_sources ++ - lib_profiledata_sources ++ - lib_option_sources ++ - lib_passprinters_sources ++ - lib_passes_sources ++ - lib_hlsl_sources ++ - lib_support_cpp_sources ++ - lib_dxcsupport_sources ++ - lib_dxcbindingtable_sources ++ - lib_dxil_sources ++ - lib_dxilcontainer_sources ++ - lib_dxilpixpasses_sources ++ - lib_dxilcompression_cpp_sources ++ - lib_dxilrootsignature_sources; - - const c_sources = - lib_support_c_sources ++ - lib_dxilcompression_c_sources; - - // Build and link SPIRV-Tools - if (build_spirv) { - const spirv_cpp_sources = - spirv_tools ++ - spirv_tools_util ++ - spirv_tools_reduce ++ - spirv_tools_link ++ - spirv_tools_val ++ - // 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, - }); - - if (target.result.os.tag == .windows) { - spv_lib.defineCMacro("SPIRV_WINDOWS", ""); - } else if (target.result.os.tag == .linux) { - spv_lib.defineCMacro("SPIRV_LINUX", ""); - } else if (target.result.os.tag == .macos) { - spv_lib.defineCMacro("SPIRV_MAC", ""); - } else if (target.result.os.tag == .ios) { - spv_lib.defineCMacro("SPIRV_IOS", ""); - } else if (target.result.os.tag == .tvos) { - spv_lib.defineCMacro("SPIRV_TVOS", ""); - } else if (target.result.os.tag == .kfreebsd) { - spv_lib.defineCMacro("SPIRV_FREEBSD", ""); - } else if (target.result.os.tag == .openbsd) { - spv_lib.defineCMacro("SPIRV_OPENBSD", ""); - } else if (target.result.os.tag == .fuchsia) { - spv_lib.defineCMacro("SPIRV_FUCHSIA", ""); - } else { - log.err("Compilation target incompatible with SPIR-V.", .{}); - std.process.exit(1); - } - - var build_grammar_step = BuildSPIRVGrammarStep.init(b); - spv_lib.step.dependOn(&build_grammar_step.step); - - spv_lib.addCSourceFiles(.{ - .files = &spirv_cpp_sources, - .flags = cppflags.items, - }); - - spv_lib.defineCMacro("SPIRV_COLOR_TERMINAL", ""); // Pretty lights by default - - addSPIRVIncludes(spv_lib); - linkMachDxcDependencies(spv_lib); - - b.installArtifact(spv_lib); - - lib.defineCMacro("ENABLE_SPIRV_CODEGEN", ""); - - addSPIRVIncludes(lib); - - // Add clang SPIRV tooling sources - lib.addCSourceFiles(.{ - .files = &lib_spirv, - .flags = cppflags.items, - }); - - lib.linkLibrary(spv_lib); - } - - lib.addCSourceFiles(.{ - .files = &cpp_sources, - .flags = cppflags.items, - }); - lib.addCSourceFiles(.{ - .files = &c_sources, - .flags = cflags.items, - }); - - if (target.result.abi != .msvc) lib.defineCMacro("NDEBUG", ""); // disable assertions - if (target.result.os.tag == .windows) { - lib.defineCMacro("LLVM_ON_WIN32", "1"); - if (target.result.abi == .msvc) lib.defineCMacro("CINDEX_LINKAGE", ""); - lib.linkSystemLibrary("version"); - } else { - lib.defineCMacro("LLVM_ON_UNIX", "1"); - } - - linkMachDxcDependencies(lib); - lib.addIncludePath(.{ .path = "src" }); - - // TODO: investigate SSE2 #define / cmake option for CPU target - // - // TODO: investigate how projects/dxilconv/lib/DxbcConverter/DxbcConverterImpl.h is getting pulled - // in, we can get rid of dxbc conversion presumably - - if (!skip_executables) { - // dxc.exe builds - const dxc_exe = b.addExecutable(.{ - .name = "dxc", - .optimize = optimize, - .target = target, - }); - const install_dxc_step = b.step("dxc", "Build and install dxc.exe"); - install_dxc_step.dependOn(&b.addInstallArtifact(dxc_exe, .{}).step); - dxc_exe.addCSourceFile(.{ - .file = .{ .path = prefix ++ "/tools/clang/tools/dxc/dxcmain.cpp" }, - .flags = &.{"-std=c++17"}, - }); - dxc_exe.defineCMacro("NDEBUG", ""); // disable assertions - - if (target.result.os.tag != .windows) dxc_exe.defineCMacro("HAVE_DLFCN_H", "1"); - dxc_exe.addIncludePath(.{ .path = prefix ++ "/tools/clang/tools" }); - dxc_exe.addIncludePath(.{ .path = prefix ++ "/include" }); - addConfigHeaders(b, dxc_exe); - addIncludes(dxc_exe); - dxc_exe.addCSourceFile(.{ - .file = .{ .path = prefix ++ "/tools/clang/tools/dxclib/dxc.cpp" }, - .flags = cppflags.items, - }); - b.installArtifact(dxc_exe); - dxc_exe.linkLibrary(lib); - - if (target.result.os.tag == .windows) { - // windows must be built with LTO disabled due to: - // https://github.com/ziglang/zig/issues/15958 - dxc_exe.want_lto = false; - if (builtin.os.tag == .windows and target.result.abi == .msvc) { - const msvc_lib_dir: ?[]const u8 = try @import("msvc.zig").MsvcLibDir.find(b.allocator); - - // The MSVC lib dir looks like this: - // C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\Lib\x64 - // But we need the atlmfc lib dir: - // C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\atlmfc\lib\x64 - const msvc_dir = try std.fs.path.resolve(b.allocator, &.{ msvc_lib_dir.?, "..\\.." }); - - const lib_dir_path = try std.mem.concat(b.allocator, u8, &.{ - msvc_dir, - "\\atlmfc\\lib\\", - if (target.result.cpu.arch == .aarch64) "arm64" else "x64", - }); - - const lib_path = try std.mem.concat(b.allocator, u8, &.{ lib_dir_path, "\\atls.lib" }); - const pdb_name = if (target.result.cpu.arch == .aarch64) - "atls.arm64.pdb" - else - "atls.amd64.pdb"; - const pdb_path = try std.mem.concat(b.allocator, u8, &.{ lib_dir_path, "\\", pdb_name }); - - // For some reason, msvc target needs atls.lib to be in the 'zig build' working directory. - // Addomg tp the library path like this has no effect: - dxc_exe.addLibraryPath(.{ .path = lib_dir_path }); - // So instead we must copy the lib into this directory: - try std.fs.cwd().copyFile(lib_path, std.fs.cwd(), "atls.lib", .{}); - try std.fs.cwd().copyFile(pdb_path, std.fs.cwd(), pdb_name, .{}); - // This is probably a bug in the Zig linker. - } - } - } - - if (build_shared) buildShared(b, lib, optimize, target); - - break :blk .{ .lib = lib, .lib_path = null }; - }; - }; - - if (skip_executables) - return; - - // Zig bindings - const mach_dxcompiler = b.addModule("mach-dxcompiler", .{ - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - mach_dxcompiler.addIncludePath(.{ .path = "src" }); - - mach_dxcompiler.linkLibrary(machdxcompiler.lib); - if (machdxcompiler.lib_path) |p| mach_dxcompiler.addLibraryPath(.{ .path = p }); - - if (skip_tests) - return; - - const main_tests = b.addTest(.{ - .name = "dxcompiler-tests", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - main_tests.addIncludePath(.{ .path = "src" }); - main_tests.linkLibrary(machdxcompiler.lib); - if (machdxcompiler.lib_path) |p| main_tests.addLibraryPath(.{ .path = p }); - - b.installArtifact(main_tests); - const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&b.addRunArtifact(main_tests).step); -} - -fn buildShared(b: *Build, lib: *Build.Step.Compile, optimize: std.builtin.OptimizeMode, target: std.Build.ResolvedTarget) void { - const sharedlib = b.addSharedLibrary(.{ - .name = "machdxcompiler", - .root_source_file = b.addWriteFiles().add("empty.c", ""), - .optimize = optimize, - .target = target, - }); - - sharedlib.addCSourceFile(.{ - .file = .{ .path = "src/shared_main.cpp" }, - }); - - const shared_install_step = b.step("machdxcompiler", "Build and install the machdxcompiler shared library"); - shared_install_step.dependOn(&b.addInstallArtifact(sharedlib, .{}).step); - - b.installArtifact(sharedlib); - sharedlib.linkLibrary(lib); -} - -fn linkMachDxcDependencies(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(); - 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; + lib.defineCMacro("GLSLANG_IS_SHARED_LIBRARY", "1"); + lib.defineCMacro("GLSLANG_EXPORTING", "1"); } else { - mod.link_libcpp = true; + lib = b.addStaticLibrary(.{ + .name = "glslang", + .root_source_file = b.addWriteFiles().add("empty.c", ""), + .optimize = optimize, + .target = target, + }); } - if (target.os.tag == .windows) { - mod.linkSystemLibrary("ole32", .{}); - mod.linkSystemLibrary("oleaut32", .{}); + + lib.addCSourceFiles(.{ + .files = &sources, + .flags = cppflags.items, + }); + + const tag = target.result.os.tag; + + if (tag == .windows) { + lib.addCSourceFiles(.{ + .files = &sources_win, + .flags = cppflags.items, + }); + + lib.defineCMacro("GLSLANG_OSINCLUDE_WIN32", ""); + } else { + lib.addCSourceFiles(.{ + .files = &sources_unix, + .flags = cppflags.items, + }); + + lib.defineCMacro("GLSLANG_OSINCLUDE_UNIX", ""); } -} -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", - }, - .{}, - )); + if (enable_hlsl) { + lib.addCSourceFiles(.{ + .files = &sources_hlsl, + .flags = cppflags.items, + }); - // /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", - }, - .{}, - )); + lib.defineCMacro("ENABLE_HLSL", "1"); + } - // /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", - }, - .{}, - )); + if (enable_opt) { + lib.addCSourceFiles(.{ + .files = &sources_opt, + .flags = cppflags.items, + }); - // /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", - }, - .{}, - )); + lib.defineCMacro("ENABLE_OPT", "1"); - // /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", - }, - .{}, - )); + lib.step.dependOn(&tools_libs.tools_opt.step); + lib.step.dependOn(&tools_libs.tools_val.step); + lib.linkLibrary(tools_libs.tools_opt); + lib.linkLibrary(tools_libs.tools_val); + } - // /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", - }, - .{}, - )); + addIncludes(lib); + spvtools.addSPIRVPublicIncludes(lib); - const target = step.rootModuleTarget(); - step.addConfigHeader(addConfigHeaderLLVMConfig(b, target, .llvm_config_h)); - step.addConfigHeader(addConfigHeaderLLVMConfig(b, target, .config_h)); + lib.linkLibCpp(); - // /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, - }, - )); + lib.step.dependOn(&build_headers.step); + + const build_step = b.step("glslang", "Build glslang"); + build_step.dependOn(&b.addInstallArtifact(lib, .{}).step); + + b.installArtifact(lib); } 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 = prefix ++ "/external/SPIRV-Tools" }); - step.addIncludePath(.{ .path = prefix ++ "/external/SPIRV-Tools/include" }); - step.addIncludePath(.{ .path = 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 = sdkPath("/" ++ output_path) }); + step.addIncludePath(.{ .path = sdkPath("/") }); } fn ensureCommandExists(allocator: std.mem.Allocator, name: []const u8, exist_check: []const u8) bool { @@ -686,54 +163,6 @@ fn ensureCommandExists(allocator: std.mem.Allocator, name: []const u8, exist_che return true; } -// ------------------------------------------ -// Source cloning logic -// ------------------------------------------ - -fn ensureGitRepoCloned(allocator: std.mem.Allocator, clone_url: []const u8, revision: []const u8, dir: []const u8) !void { - if (isEnvVarTruthy(allocator, "NO_ENSURE_SUBMODULES") or isEnvVarTruthy(allocator, "NO_ENSURE_GIT")) { - return; - } - - ensureGit(allocator); - - if (std.fs.openDirAbsolute(dir, .{})) |_| { - const current_revision = try getCurrentGitRevision(allocator, dir); - if (!std.mem.eql(u8, current_revision, revision)) { - // Reset to the desired revision - exec(allocator, &[_][]const u8{ "git", "fetch" }, dir) catch |err| log.warn("failed to 'git fetch' in {s}: {s}\n", .{ dir, @errorName(err) }); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - } - return; - } else |err| return switch (err) { - error.FileNotFound => { - log.info("cloning required dependency..\ngit clone {s} {s}..\n", .{ clone_url, dir }); - - try exec(allocator, &[_][]const u8{ "git", "clone", "-c", "core.longpaths=true", clone_url, dir }, sdkPath("/")); - try exec(allocator, &[_][]const u8{ "git", "checkout", "--quiet", "--force", revision }, dir); - try exec(allocator, &[_][]const u8{ "git", "submodule", "update", "--init", "--recursive" }, dir); - return; - }, - else => err, - }; -} - -fn getCurrentGitRevision(allocator: std.mem.Allocator, cwd: []const u8) ![]const u8 { - const result = try std.ChildProcess.run(.{ .allocator = allocator, .argv = &.{ "git", "rev-parse", "HEAD" }, .cwd = cwd }); - allocator.free(result.stderr); - if (result.stdout.len > 0) return result.stdout[0 .. result.stdout.len - 1]; // trim newline - return result.stdout; -} - -// Command validation logic moved to ensureCommandExists() -fn ensureGit(allocator: std.mem.Allocator) void { - if (!ensureCommandExists(allocator, "git", "--version")) { - log.err("'git --version' failed. Is git not installed?", .{}); - std.process.exit(1); - } -} - fn exec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) !void { log.info("cd {s}", .{cwd}); var buf = std.ArrayList(u8).init(allocator); @@ -747,41 +176,6 @@ fn exec(allocator: std.mem.Allocator, argv: []const []const u8, cwd: []const u8) _ = try child.spawnAndWait(); } -fn isEnvVarTruthy(allocator: std.mem.Allocator, name: []const u8) bool { - if (std.process.getEnvVarOwned(allocator, name)) |truthy| { - defer allocator.free(truthy); - if (std.mem.eql(u8, truthy, "true")) return true; - return false; - } else |_| { - return false; - } -} - -// 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: { @@ -790,256 +184,6 @@ fn sdkPath(comptime suffix: []const u8) []const u8 { }; } -const DownloadSourceStep = struct { - step: std.Build.Step, - b: *std.Build, - - fn init(b: *std.Build) *DownloadSourceStep { - const download_step = b.allocator.create(DownloadSourceStep) catch unreachable; - download_step.* = .{ - .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(DownloadSourceStep, "step", step_ptr); - const b = download_step.b; - - // 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(); - - try ensureGitRepoCloned(b.allocator, source_repository, source_revision, sdkPath("/libs/DirectXShaderCompiler")); - } -}; - -// ------------------------------------------ -// 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 -// ------------------------------------------ - fn ensurePython(allocator: std.mem.Allocator) void { if (!ensureCommandExists(allocator, "python3", "--version")) { log.err("'python3 --version' failed. Is python not installed?", .{}); @@ -1047,465 +191,176 @@ 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_output_path = "generated-include/spirv-tools"; - -const grammar_tables_script = spirv_tools_path ++ "/utils/generate_grammar_tables.py"; - -const debuginfo_insts_file = spirv_headers_path ++ "/include/spirv/unified1/extinst.debuginfo.grammar.json"; -const cldebuginfo100_insts_file = spirv_headers_path ++ "/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json"; - -fn spvHeaderFile(comptime version: []const u8, comptime file_name: []const u8) []const u8 { - return spirv_headers_path ++ "/include/spirv/" ++ version ++ "/" ++ file_name; -} - -// Most of this was derived from the BUILD.gn file in SPIRV-Tools - -fn genSPIRVCoreTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - - // Outputs - const core_insts_file = spirv_output_path ++ "/core.insts-" ++ version ++ ".inc"; - const operand_kinds_file = spirv_output_path ++ "/operand.kinds-" ++ version ++ ".inc"; - - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--core-insts-output", core_insts_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--operand-kinds-output", operand_kinds_file, "--output-language", "c++" }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V core tables: error: {s}", .{@errorName(err)}); +fn runPython(allocator: std.mem.Allocator, args: []const []const u8, errMsg: []const u8) void { + exec(allocator, args, sdkPath("/")) catch |err| { + log.err("{s}. error: {s}", .{ errMsg, @errorName(err) }); std.process.exit(1); }; } -fn genSPIRVCoreEnums(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - const extension_enum_file = spirv_output_path ++ "/extension_enum.inc"; - const extension_map_file = spirv_output_path ++ "/enum_string_mapping.inc"; - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--extension-enum-output", extension_enum_file, "--enum-string-mapping-output", extension_map_file, "--output-language", "c++" }; +// ------------------------------------------ +// Include generation logic +// ------------------------------------------ - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V core enums: error: {s}", .{@errorName(err)}); +pub const output_path = "build"; + +const build_info_script = "build_info.py"; +const ext_header_script = "gen_extension_headers.py"; + +fn outPath(comptime out_name: []const u8) []const u8 { + if (out_name[0] != '/') @compileError("suffix must be an absolute path"); + return sdkPath("/" ++ output_path ++ out_name); +} + +// Script usage derived from the BUILD.gn + +fn genBuildInfo(allocator: std.mem.Allocator) void { + const args = &[_][]const u8{ + "python3", build_info_script, + sdkPath("/"), + "-i", sdkPath("/build_info.h.tmpl"), + "-o", outPath("/glslang/build_info.h"), + }; + + runPython(allocator, args, "Failed to generate build info file."); +} + +fn genExtensionHeaders(allocator: std.mem.Allocator) void { + const args = &[_][]const u8 { + "python3", ext_header_script, + "-i", sdkPath("/glslang/ExtensionHeaders"), + "-o", outPath("/glslang/glsl_intrinsic_header.h"), + }; + + runPython(allocator, args, "Failed to generate extension headers"); +} + +fn generateHeaders(allocator: std.mem.Allocator) void { + if (!ensureCommandExists(allocator, "python3", "--version")) { + log.err("'python3 --version' failed. Is python not installed?", .{}); std.process.exit(1); - }; + } + + genBuildInfo(allocator); + genExtensionHeaders(allocator); } -fn genSPIRVGlslTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - const glsl_json_file = spvHeaderFile(version, "extinst.glsl.std.450.grammar.json"); +var build_mutex = std.Thread.Mutex{}; - const glsl_insts_file = spirv_output_path ++ "/glsl.std.450.insts.inc"; - - const args = &[_][]const u8{ "python3", grammar_tables_script, "--spirv-core-grammar", core_json_file, "--extinst-debuginfo-grammar", debuginfo_insts_file, "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, "--extinst-glsl-grammar", glsl_json_file, "--glsl-insts-output", glsl_insts_file, "--output-language", "c++" }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V GLSL tables: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVOpenCLTables(allocator: std.mem.Allocator, comptime version: []const u8) void { - const core_json_file = spvHeaderFile(version, "spirv.core.grammar.json"); - const opencl_json_file = spvHeaderFile(version, "extinst.opencl.std.100.grammar.json"); - - const opencl_insts_file = spirv_output_path ++ "/opencl.std.insts.inc"; - - const args = &[_][]const u8{ - "python3", grammar_tables_script, - "--spirv-core-grammar", core_json_file, - "--extinst-debuginfo-grammar", debuginfo_insts_file, - "--extinst-cldebuginfo100-grammar", cldebuginfo100_insts_file, - "--extinst-opencl-grammar", opencl_json_file, - "--opencl-insts-output", opencl_insts_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to build SPIR-V OpenCL tables: error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVLanguageHeader(allocator: std.mem.Allocator, comptime name: []const u8, comptime grammar_file: []const u8) void { - const script = spirv_tools_path ++ "/utils/generate_language_headers.py"; - - const extinst_output_path = spirv_output_path ++ "/" ++ name ++ ".h"; - - const args = &[_][]const u8{ - "python3", script, - "--extinst-grammar", grammar_file, - "--extinst-output-path", extinst_output_path, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V language header '" ++ name ++ "'. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVVendorTable(allocator: std.mem.Allocator, comptime name: []const u8, comptime operand_kind_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, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V vendor table '" ++ name ++ "'. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn genSPIRVRegistryTables(allocator: std.mem.Allocator) void { - const script = spirv_tools_path ++ "/utils/generate_registry_tables.py"; - - const xml_file = spirv_headers_path ++ "/include/spirv/spir-v.xml"; - const inc_file = spirv_output_path ++ "/generators.inc"; - - const args = &[_][]const u8{ - "python3", script, - "--xml", xml_file, - "--generator", inc_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V registry tables. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn buildSPIRVVersion(allocator: std.mem.Allocator) void { - const script = spirv_tools_path ++ "/utils/update_build_version.py"; - - const changes_file = spirv_tools_path ++ "/CHANGES"; - const inc_file = spirv_output_path ++ "/build-version.inc"; - - const args = &[_][]const u8{ - "python3", script, - changes_file, inc_file, - }; - - exec(allocator, args, sdkPath("/")) catch |err| - { - log.err("Failed to generate SPIR-V build version. error: {s}", .{@errorName(err)}); - std.process.exit(1); - }; -} - -fn generateSPIRVGrammar(allocator: std.mem.Allocator) void { - ensurePython(allocator); - - genSPIRVCoreTables(allocator, "unified1"); - genSPIRVCoreEnums(allocator, "unified1"); - - genSPIRVGlslTables(allocator, "1.0"); - - genSPIRVOpenCLTables(allocator, "1.0"); - - genSPIRVLanguageHeader(allocator, "DebugInfo", spvHeaderFile("unified1", "extinst.debuginfo.grammar.json")); - genSPIRVLanguageHeader(allocator, "OpenCLDebugInfo100", spvHeaderFile("unified1", "extinst.opencl.debuginfo.100.grammar.json")); - genSPIRVLanguageHeader(allocator, "NonSemanticShaderDebugInfo100", spvHeaderFile("unified1", "extinst.nonsemantic.shader.debuginfo.100.grammar.json")); - - genSPIRVVendorTable(allocator, "spv-amd-shader-explicit-vertex-parameter", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-shader-trinary-minmax", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-gcn-shader", "...nil..."); - genSPIRVVendorTable(allocator, "spv-amd-shader-ballot", "...nil..."); - genSPIRVVendorTable(allocator, "debuginfo", "...nil..."); - genSPIRVVendorTable(allocator, "opencl.debuginfo.100", "CLDEBUG100_"); - genSPIRVVendorTable(allocator, "nonsemantic.clspvreflection", "...nil..."); - genSPIRVVendorTable(allocator, "nonsemantic.shader.debuginfo.100", "SHDEBUG100_"); - - genSPIRVRegistryTables(allocator); - - buildSPIRVVersion(allocator); -} - -const BuildSPIRVGrammarStep = struct { +pub const BuildHeadersStep = struct { step: std.Build.Step, b: *std.Build, - fn init(b: *std.Build) *BuildSPIRVGrammarStep { - const build_grammar_step = b.allocator.create(BuildSPIRVGrammarStep) catch unreachable; + pub fn init(b: *std.Build) *BuildHeadersStep { + const build_headers = b.allocator.create(BuildHeadersStep) catch unreachable; - build_grammar_step.* = .{ + build_headers.* = .{ .step = std.Build.Step.init(.{ .id = .custom, - .name = "generate grammar", + .name = "Build header files.", .owner = b, .makeFn = &make, }), .b = b, }; - return build_grammar_step; + return build_headers; } 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 b = build_grammar_step.b; + const build_headers: *BuildHeadersStep = @fieldParentPtr("step", step_ptr); + const b = build_headers.b; // 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(); + build_mutex.lock(); + defer build_mutex.unlock(); - generateSPIRVGrammar(b.allocator); + generateHeaders(b.allocator); } }; -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", + + +const sources_spirv = [_][]const u8{ + "SPIRV/GlslangToSpv.cpp", + "SPIRV/InReadableOrder.cpp", + "SPIRV/Logger.cpp", + "SPIRV/SPVRemapper.cpp", + "SPIRV/SpvBuilder.cpp", + "SPIRV/SpvPostProcess.cpp", + "SPIRV/disassemble.cpp", + "SPIRV/doc.cpp", }; -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", +const sources_c_interface = [_][]const u8{ + "glslang/CInterface/glslang_c_interface.cpp", }; -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", +const sources_resource_limits = [_][]const u8{ + "glslang/ResourceLimits/resource_limits_c.cpp", + "glslang/ResourceLimits/ResourceLimits.cpp", }; -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", +const sources_generic_codegen = [_][]const u8{ + "glslang/GenericCodeGen/CodeGen.cpp", + "glslang/GenericCodeGen/Link.cpp", }; -const spirv_tools_wasm = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/wasm/spirv-tools.cpp", +const sources_machine_independent = [_][]const u8{ + "glslang/MachineIndependent/Constant.cpp", + "glslang/MachineIndependent/InfoSink.cpp", + "glslang/MachineIndependent/Initialize.cpp", + "glslang/MachineIndependent/IntermTraverse.cpp", + "glslang/MachineIndependent/Intermediate.cpp", + "glslang/MachineIndependent/ParseContextBase.cpp", + "glslang/MachineIndependent/ParseHelper.cpp", + "glslang/MachineIndependent/PoolAlloc.cpp", + "glslang/MachineIndependent/RemoveTree.cpp", + "glslang/MachineIndependent/Scan.cpp", + "glslang/MachineIndependent/ShaderLang.cpp", + "glslang/MachineIndependent/SpirvIntrinsics.cpp", + "glslang/MachineIndependent/SymbolTable.cpp", + "glslang/MachineIndependent/Versions.cpp", + "glslang/MachineIndependent/attribute.cpp", + "glslang/MachineIndependent/glslang_tab.cpp", + "glslang/MachineIndependent/intermOut.cpp", + "glslang/MachineIndependent/iomapper.cpp", + "glslang/MachineIndependent/limits.cpp", + "glslang/MachineIndependent/linkValidate.cpp", + "glslang/MachineIndependent/parseConst.cpp", + "glslang/MachineIndependent/preprocessor/Pp.cpp", + "glslang/MachineIndependent/preprocessor/PpAtom.cpp", + "glslang/MachineIndependent/preprocessor/PpContext.cpp", + "glslang/MachineIndependent/preprocessor/PpScanner.cpp", + "glslang/MachineIndependent/preprocessor/PpTokens.cpp", + "glslang/MachineIndependent/propagateNoContraction.cpp", + "glslang/MachineIndependent/reflection.cpp", }; -const spirv_tools_link = [_][]const u8{ - "libs/DirectXShaderCompiler/external/SPIRV-Tools/source/link/linker.cpp", +const sources_win = [_][]const u8{ + "glslang/OSDependent/Windows/ossource.cpp" }; -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", +const sources_unix = [_][]const u8{ + "glslang/OSDependent/Unix/ossource.cpp" }; + +const sources_hlsl = [_][]const u8{ + "glslang/HLSL/hlslAttributes.cpp", + "glslang/HLSL/hlslGrammar.cpp", + "glslang/HLSL/hlslOpMap.cpp", + "glslang/HLSL/hlslParseHelper.cpp", + "glslang/HLSL/hlslParseables.cpp", + "glslang/HLSL/hlslScanContext.cpp", + "glslang/HLSL/hlslTokenStream.cpp", +}; + +const sources_opt = [_][]const u8{ + "SPIRV/SpvTools.cpp", +}; \ No newline at end of file diff --git a/known_good_zig.json b/known_good_zig.json new file mode 100644 index 00000000..dcd85232 --- /dev/null +++ b/known_good_zig.json @@ -0,0 +1,25 @@ +{ + "commits" : [ + { + "name" : "spirv-tools", + "site" : "github", + "subrepo" : "sinnwrig/SPIRV-Tools-zig", + "subdir" : "External/spirv-tools", + "commit": "main" + }, + { + "name" : "spirv-tools/external/spirv-headers", + "site" : "github", + "subrepo" : "KhronosGroup/SPIRV-Headers", + "subdir" : "External/spirv-tools/external/SPIRV-Headers", + "commit" : "4f7b471f1a66b6d06462cd4ba57628cc0cd087d7" + }, + { + "name": "googletest", + "site": "github", + "subrepo": "google/googletest", + "subdir": "External/googletest", + "commit": "v1.14.0" + } + ] +} diff --git a/lack.cpp b/lack.cpp new file mode 100644 index 00000000..305173cf --- /dev/null +++ b/lack.cpp @@ -0,0 +1,13 @@ + " -D | --define-macro | --D \n" + " define a pre-processor macro\n" + " -H print human readable form of SPIR-V; turns on -V\n" + " -U | --undef-macro | --U \n" + " undefine a pre-processor macro\n" + " -e | --entry-point \n" + " specify as the entry-point function name\n" + + " --invert-y | --iy invert position.Y output in vertex shader\n" + " --nan-clamp favor non-NaN operand in min, max, and clamp\n" + + " --source-entrypoint the given shader source function is\n" + " renamed to be the given in -e\n" \ No newline at end of file diff --git a/test.cpp b/test.cpp new file mode 100644 index 00000000..2b737f4b --- /dev/null +++ b/test.cpp @@ -0,0 +1,86 @@ +#define GLSLANG_IS_SHARED_LIBRARY +#include +#include +#include + + +typedef struct SpirVBinary { + uint32_t *words; // SPIR-V words + int size; // number of words in SPIR-V binary +} SpirVBinary; + +SpirVBinary compileShaderToSPIRV_Vulkan(glslang_stage_t stage, const char* shaderSource, const char* fileName) { + const glslang_input_t input = { + .language = GLSLANG_SOURCE_HLSL, + .stage = stage, + .client = GLSLANG_CLIENT_VULKAN, + .client_version = GLSLANG_TARGET_VULKAN_1_2, + .target_language = GLSLANG_TARGET_SPV, + .target_language_version = GLSLANG_TARGET_SPV_1_5, + .code = shaderSource, + .default_version = 100, + .default_profile = GLSLANG_NO_PROFILE, + .force_default_version_and_profile = false, + .forward_compatible = false, + .messages = GLSLANG_MSG_DEFAULT_BIT, + .resource = glslang_default_resource(), + }; + + glslang_shader_t* shader = glslang_shader_create(&input); + + SpirVBinary bin = { + .words = NULL, + .size = 0, + }; + + if (!glslang_shader_preprocess(shader, &input)) { + printf("GLSL preprocessing failed %s\n", fileName); + printf("%s\n", glslang_shader_get_info_log(shader)); + printf("%s\n", glslang_shader_get_info_debug_log(shader)); + printf("%s\n", input.code); + glslang_shader_delete(shader); + return bin; + } + + if (!glslang_shader_parse(shader, &input)) { + printf("GLSL parsing failed %s\n", fileName); + printf("%s\n", glslang_shader_get_info_log(shader)); + printf("%s\n", glslang_shader_get_info_debug_log(shader)); + printf("%s\n", glslang_shader_get_preprocessed_code(shader)); + glslang_shader_delete(shader); + return bin; + } + + glslang_program_t* program = glslang_program_create(); + glslang_program_add_shader(program, shader); + + if (!glslang_program_link(program, GLSLANG_MSG_SPV_RULES_BIT | GLSLANG_MSG_VULKAN_RULES_BIT)) { + printf("GLSL linking failed %s\n", fileName); + printf("%s\n", glslang_program_get_info_log(program)); + printf("%s\n", glslang_program_get_info_debug_log(program)); + glslang_program_delete(program); + glslang_shader_delete(shader); + return bin; + } + + glslang_program_SPIRV_generate(program, stage); + + bin.size = glslang_program_SPIRV_get_size(program); + bin.words = malloc(bin.size * sizeof(uint32_t)); + glslang_program_SPIRV_get(program, bin.words); + + const char* spirv_messages = glslang_program_SPIRV_get_messages(program); + if (spirv_messages) + printf("(%s) %s\b", fileName, spirv_messages); + + glslang_program_delete(program); + glslang_shader_delete(shader); + + return bin; +} + + +int main(void) +{ + +} \ No newline at end of file diff --git a/update_glslang_sources.py b/update_glslang_sources.py index 2e02c96e..7deeda4a 100755 --- a/update_glslang_sources.py +++ b/update_glslang_sources.py @@ -26,11 +26,13 @@ import sys KNOWN_GOOD_FILE = 'known_good.json' SITE_TO_KNOWN_GOOD_FILE = { 'github' : 'known_good.json', - 'gitlab' : 'known_good_khr.json' } + 'gitlab' : 'known_good_khr.json', + 'zig-github' : 'known_good_zig.json' } # Maps a site name to its hostname. SITE_TO_HOST = { 'github' : 'https://github.com/', - 'gitlab' : 'git@gitlab.khronos.org:' } + 'gitlab' : 'git@gitlab.khronos.org:', + 'zig-github' : 'https://github.com/' } VERBOSE = True @@ -113,8 +115,10 @@ class GoodCommit(object): if not os.path.exists(os.path.join(self.subdir,'.git')): self.Clone() self.AddRemote() + if not self.HasCommit(): self.Fetch() + command_output(['git', 'checkout', self.commit], self.subdir) diff --git a/zig-cache/h/916a2c2d22523ac2946045bc514be1a6.txt b/zig-cache/h/916a2c2d22523ac2946045bc514be1a6.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/zig-cache/h/timestamp b/zig-cache/h/timestamp deleted file mode 100644 index e69de29b..00000000 diff --git a/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig b/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig deleted file mode 100644 index 72e4e833..00000000 --- a/zig-cache/o/20f8f8362ac39302905d03992fa818bc/dependencies.zig +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index de653401dbe178fd7fc34ae75c6d45144ad5a0a0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 110 zcmZQzU|^7AU|`??F&G#a;;%9?Ffd3nR4agJ28J(H+ajF~UKWQ+Gccr96r?7Xq^2mS mTdON1rj?`?DHN9^mZavU=9MroL6w2@f-s01#m2w@V*>!|mk|U2