├── .gitignore ├── LICENSE ├── README.md ├── bin ├── linux │ ├── readme.txt │ └── sokol-shdc ├── linux_arm64 │ └── sokol-shdc ├── osx │ ├── readme.txt │ └── sokol-shdc ├── osx_arm64 │ └── sokol-shdc └── win32 │ ├── readme.txt │ └── sokol-shdc.exe ├── build.zig ├── build.zig.zon └── fips-files ├── generators └── SokolShader.py └── include.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | .zig-cache/ 3 | zig-out/ 4 | *.pyc 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Andre Weissflog 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sokol-tools-bin 2 | Binaries and fips integration for https://github.com/floooh/sokol-tools 3 | -------------------------------------------------------------------------------- /bin/linux/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled binaries for Linux go here (64-bit statically linked). 2 | 3 | -------------------------------------------------------------------------------- /bin/linux/sokol-shdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/floooh/sokol-tools-bin/90d2b9267813cbfb66e26c8e3eca5cc866f947e0/bin/linux/sokol-shdc -------------------------------------------------------------------------------- /bin/linux_arm64/sokol-shdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/floooh/sokol-tools-bin/90d2b9267813cbfb66e26c8e3eca5cc866f947e0/bin/linux_arm64/sokol-shdc -------------------------------------------------------------------------------- /bin/osx/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled binaries for macOS go here. 2 | 3 | -------------------------------------------------------------------------------- /bin/osx/sokol-shdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/floooh/sokol-tools-bin/90d2b9267813cbfb66e26c8e3eca5cc866f947e0/bin/osx/sokol-shdc -------------------------------------------------------------------------------- /bin/osx_arm64/sokol-shdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/floooh/sokol-tools-bin/90d2b9267813cbfb66e26c8e3eca5cc866f947e0/bin/osx_arm64/sokol-shdc -------------------------------------------------------------------------------- /bin/win32/readme.txt: -------------------------------------------------------------------------------- 1 | Precompiled binaries for Windows (64-bit) go here. 2 | 3 | -------------------------------------------------------------------------------- /bin/win32/sokol-shdc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/floooh/sokol-tools-bin/90d2b9267813cbfb66e26c8e3eca5cc866f947e0/bin/win32/sokol-shdc.exe -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | //! Helper code to invoke sokol-shdc from the Zig build system. 2 | //! See https://github.com/floooh/sokol-zig for an example 3 | //! of how to use sokol-tools-bin as dependency and 4 | //! compile shaders (search for `shdc.compile` in the sokol-zig build.zig) 5 | const std = @import("std"); 6 | const builtin = @import("builtin"); 7 | const Allocator = std.mem.Allocator; 8 | const Build = std.Build; 9 | 10 | pub const Options = struct { 11 | dep_shdc: *Build.Dependency, 12 | input: Build.LazyPath, 13 | output: Build.LazyPath, 14 | slang: Slang, 15 | format: Format = .sokol_zig, 16 | tmp_dir: ?Build.LazyPath = null, 17 | defines: ?[][]const u8 = null, 18 | module: ?[]const u8 = null, 19 | reflection: bool = false, 20 | bytecode: bool = false, 21 | dump: bool = false, 22 | genver: ?[]const u8 = null, 23 | ifdef: bool = false, 24 | noifdef: bool = false, 25 | save_intermediate_spirv: bool = false, 26 | no_log_cmdline: bool = true, 27 | }; 28 | 29 | pub fn compile(b: *Build, opts: Options) !*Build.Step.Run { 30 | const shdc_path = try getShdcLazyPath(opts.dep_shdc); 31 | const args = try optsToArgs(opts, b, shdc_path); 32 | var step = b.addSystemCommand(args); 33 | step.addFileArg(opts.input); 34 | return step; 35 | } 36 | 37 | /// target shader languages 38 | /// NOTE: make sure that field names match the cmdline arg string 39 | pub const Slang = packed struct(u10) { 40 | glsl410: bool = false, 41 | glsl430: bool = false, 42 | glsl300es: bool = false, 43 | glsl310es: bool = false, 44 | hlsl4: bool = false, 45 | hlsl5: bool = false, 46 | metal_macos: bool = false, 47 | metal_ios: bool = false, 48 | metal_sim: bool = false, 49 | wgsl: bool = false, 50 | }; 51 | 52 | fn slangToString(slang: Slang, a: Allocator) ![]const u8 { 53 | var strings: [16][]const u8 = undefined; 54 | var num_strings: usize = 0; 55 | inline for (std.meta.fields(Slang)) |field| { 56 | if (@field(slang, field.name)) { 57 | strings[num_strings] = field.name; 58 | num_strings += 1; 59 | } 60 | } 61 | return std.mem.join(a, ":", strings[0..num_strings]); 62 | } 63 | 64 | /// the code-generation target language 65 | /// NOTE: make sure that the item names match the cmdline arg string 66 | pub const Format = enum { 67 | sokol, 68 | sokol_impl, 69 | sokol_zig, 70 | sokol_nim, 71 | sokol_odin, 72 | sokol_rust, 73 | sokol_d, 74 | sokol_jai, 75 | }; 76 | 77 | fn formatToString(f: Format) []const u8 { 78 | return @tagName(f); 79 | } 80 | 81 | fn getShdcLazyPath(dep_shdc: *Build.Dependency) !Build.LazyPath { 82 | const intel = builtin.cpu.arch.isX86(); 83 | const opt_sub_path: ?[]const u8 = switch (builtin.os.tag) { 84 | .windows => "bin/win32/sokol-shdc.exe", 85 | .linux => if (intel) "bin/linux/sokol-shdc" else "bin/linux_arm64/sokol-shdc", 86 | .macos => if (intel) "bin/osx/sokol-shdc" else "bin/osx_arm64/sokol-shdc", 87 | else => null, 88 | }; 89 | if (opt_sub_path) |sub_path| { 90 | return dep_shdc.path(sub_path); 91 | } else { 92 | return error.ShdcUnsupportedPlatform; 93 | } 94 | } 95 | 96 | fn optsToArgs(opts: Options, b: *Build, tool_path: Build.LazyPath) ![]const []const u8 { 97 | const a = b.allocator; 98 | var arr: std.ArrayListUnmanaged([]const u8) = .empty; 99 | try arr.append(a, tool_path.getPath(b)); 100 | try arr.appendSlice(a, &.{ "-o", opts.output.getPath(b) }); 101 | try arr.appendSlice(a, &.{ "-l", try slangToString(opts.slang, a) }); 102 | try arr.appendSlice(a, &.{ "-f", formatToString(opts.format) }); 103 | if (opts.tmp_dir) |tmp_dir| { 104 | try arr.appendSlice(a, &.{ "--tmpdir", tmp_dir.getPath(b) }); 105 | } 106 | if (opts.defines) |defines| { 107 | try arr.appendSlice(a, &.{ "--defines", try std.mem.join(a, ":", defines) }); 108 | } 109 | if (opts.module) |module| { 110 | try arr.appendSlice(a, &.{ "--module", b.dupe(module) }); 111 | } 112 | if (opts.reflection) { 113 | try arr.append(a, "--reflection"); 114 | } 115 | if (opts.bytecode) { 116 | try arr.append(a, "--bytecode"); 117 | } 118 | if (opts.dump) { 119 | try arr.append(a, "--dump"); 120 | } 121 | if (opts.genver) |genver| { 122 | try arr.appendSlice(a, &.{ "--genver", b.dupe(genver) }); 123 | } 124 | if (opts.ifdef) { 125 | try arr.append(a, "--ifdef"); 126 | } 127 | if (opts.noifdef) { 128 | try arr.append(a, "--noifdef"); 129 | } 130 | if (opts.save_intermediate_spirv) { 131 | try arr.append(a, "--save-intermediate-spirv"); 132 | } 133 | if (opts.no_log_cmdline) { 134 | try arr.append(a, "--no-log-cmdline"); 135 | } 136 | // important: keep this last 137 | try arr.append(a, "-i"); 138 | return arr.toOwnedSlice(a); 139 | } 140 | 141 | pub fn build(b: *Build) void { 142 | _ = b; 143 | } 144 | -------------------------------------------------------------------------------- /build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = .sokolshdc, 3 | .fingerprint = 0xe0596dde0e9962af, 4 | .version = "0.1.0", 5 | .minimum_zig_version = "0.14.0", 6 | .paths = .{ "bin", "build.zig", "build.zig.zon" }, 7 | } 8 | -------------------------------------------------------------------------------- /fips-files/generators/SokolShader.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | # SokolShader.py 3 | # 4 | # Fips code-generator script for invoking sokol-shdc during the build. 5 | # 6 | # Use the cmake macro 'sokol_shader([glsl-file] [shader-dialects])' inside a 7 | # fips target (fips_begin_* / fips_end_*) to hook the code-generation 8 | # build job into the build process. 9 | #------------------------------------------------------------------------------- 10 | 11 | Version = 5 12 | 13 | import os, platform, subprocess 14 | import genutil as util 15 | from mod import log 16 | 17 | #------------------------------------------------------------------------------- 18 | def find_shdc(): 19 | shdc_path = os.path.dirname(os.path.abspath(__file__)) 20 | shdc_path += '/../../bin/' 21 | if platform.system() == 'Windows': 22 | shdc_path += 'win32/' 23 | elif platform.system() == 'Darwin': 24 | if platform.machine() == 'arm64': 25 | shdc_path += 'osx_arm64/' 26 | else: 27 | shdc_path += 'osx/' 28 | elif platform.system() == 'Linux': 29 | if platform.machine() in ['aarch64', 'arm64']: 30 | shdc_path += 'linux_arm64/' 31 | else: 32 | shdc_path += 'linux/' 33 | else: 34 | log.error('Unknown host system {}'.format(platform.system())) 35 | return shdc_path + 'sokol-shdc' 36 | 37 | #------------------------------------------------------------------------------- 38 | def generate(input, out_src, out_hdr, args): 39 | errfmt = 'msvc' if args['compiler']=='MSVC' else 'gcc' 40 | if util.isDirty(Version, [input], [out_hdr]): 41 | print('## sokol-shdc: {} {} {}'.format(input, out_hdr, str(args))) 42 | cmd = [find_shdc(), 43 | '--input', input, 44 | '--output', out_hdr, 45 | '--slang', args['slang'], 46 | '--genver', str(Version), 47 | '--errfmt', errfmt, 48 | '--format', 'sokol'] 49 | if 'defines' in args: 50 | cmd.extend(['--defines', args['defines']]) 51 | if 'module' in args: 52 | cmd.extend(['--module', args['module']]) 53 | if 'reflection' in args: 54 | if args['reflection']: 55 | cmd.extend(['--reflection']) 56 | if 'debuggable' in args and args['debuggable']: 57 | pass 58 | else: 59 | cmd.extend(['--bytecode']) 60 | res = subprocess.call(cmd) 61 | if res != 0: 62 | log.error('sokol-shdc returned with error code {}'.format(res)) 63 | -------------------------------------------------------------------------------- /fips-files/include.cmake: -------------------------------------------------------------------------------- 1 | macro(sokol_shader shd slang) 2 | set(args "{slang: '${slang}', compiler: '${CMAKE_C_COMPILER_ID}' }") 3 | fips_generate(TYPE SokolShader FROM ${shd} HEADER ${shd}.h OUT_OF_SOURCE ARGS ${args}) 4 | endmacro() 5 | 6 | # special version which doesn't generate binary output, this allows shaders to be debugged 7 | macro(sokol_shader_debuggable shd slang) 8 | set(args "{slang: '${slang}', compiler: '${CMAKE_C_COMPILER_ID}', debuggable: true }") 9 | fips_generate(TYPE SokolShader FROM ${shd} HEADER ${shd}.h OUT_OF_SOURCE ARGS ${args}) 10 | endmacro() 11 | 12 | macro(sokol_shader_variant shd slang module defines) 13 | set(args "{slang: '${slang}', compiler: '${CMAKE_C_COMPILER_ID}', defines: '${defines}', module: '${module}' }") 14 | fips_generate(TYPE SokolShader FROM ${shd} HEADER ${shd}.${module}.h OUT_OF_SOURCE ARGS ${args}) 15 | endmacro() 16 | 17 | macro(sokol_shader_with_reflection shd slang) 18 | set(args "{slang: '${slang}', compiler: '${CMAKE_C_COMPILER_ID}', reflection: true }") 19 | fips_generate(TYPE SokolShader FROM ${shd} HEADER ${shd}.h OUT_OF_SOURCE ARGS ${args}) 20 | endmacro() 21 | 22 | macro(sokol_shader_variant_with_reflection shd slang module defines) 23 | set(args "{slang: '${slang}', compiler: '${CMAKE_C_COMPILER_ID}', defines: '${defines}', module: '${module}', reflection: true }") 24 | fips_generate(TYPE SokolShader FROM ${shd} HEADER ${shd}.${module}.h OUT_OF_SOURCE ARGS ${args}) 25 | endmacro() 26 | --------------------------------------------------------------------------------