this repo has no description

updated zmath

+62 -105
+3 -3
build.zig.zon
··· 3 3 .version = "0.1.0", 4 4 .minimum_zig_version = "0.12.0-dev.2631+3069669bc", 5 5 .dependencies = .{ 6 + // libs folder 7 + .zmath = .{ .path = "libs/zmath" }, 8 + 6 9 // See `zig fetch --save <url>` for a command-line interface for adding dependencies. 7 10 .a = .{ 8 11 .url = "git+https://git.sr.ht/~altagos/a#8c8f2cc405743d062f5b617e2f8ab85ce5dc0409", ··· 16 19 .url = "git+https://github.com/MidlightStudio/zigimg#29d34702995a7e84e097004e87ede905cdb674dd", 17 20 .hash = "12206b669a4712ff9c06d4111a650f298d7597dd39f9d4853858d7f298c819353a65", 18 21 }, 19 - 20 - // libs folder 21 - .zmath = .{ .path = "libs/zmath" }, 22 22 }, 23 23 .paths = .{ 24 24 "build.zig",
+5 -13
libs/zmath/README.md
··· 1 - # zmath v0.9.6 - SIMD math library for game developers 1 + # zmath v0.10.0 - SIMD math library for game developers 2 2 3 3 Tested on x86_64 and AArch64. 4 4 ··· 14 14 15 15 ## Getting started 16 16 17 - Copy `zmath` folder to a `libs` subdirectory of the root of your project and add the following to your `build.zig.zon` .dependencies: 17 + Copy `zmath` into a subdirectory of your project and add the following to your `build.zig.zon` .dependencies: 18 18 ```zig 19 19 .zmath = .{ .path = "libs/zmath" }, 20 20 ``` ··· 22 22 Then in your `build.zig` add: 23 23 24 24 ```zig 25 - const std = @import("std"); 26 - const zmath = @import("zmath"); 27 - 28 25 pub fn build(b: *std.Build) void { 29 - ... 30 - const optimize = b.standardOptimizeOption(.{}); 31 - const target = b.standardTargetOptions(.{}); 26 + const exe = b.addExecutable(.{ ... }); 32 27 33 - const zmath_pkg = zmath.package(b, target, optimize, .{ 34 - .options = .{ .enable_cross_platform_determinism = true }, 35 - }); 36 - 37 - zmath_pkg.link(exe); 28 + const zmath = b.dependency("zmath", .{}); 29 + exe.root_module.addImport("zmath", zmath.module("root")); 38 30 } 39 31 ``` 40 32
+36 -77
libs/zmath/build.zig
··· 1 1 const std = @import("std"); 2 2 3 - pub const Options = struct { 4 - enable_cross_platform_determinism: bool = true, 5 - }; 3 + pub fn build(b: *std.Build) void { 4 + const target = b.standardTargetOptions(.{}); 6 5 7 - pub const Package = struct { 8 - target: std.Build.ResolvedTarget, 9 - options: Options, 10 - zmath: *std.Build.Module, 11 - zmath_options: *std.Build.Module, 6 + const options = .{ 7 + .optimize = b.option( 8 + std.builtin.OptimizeMode, 9 + "optimize", 10 + "Select optimization mode", 11 + ) orelse b.standardOptimizeOption(.{ 12 + .preferred_optimize_mode = .ReleaseFast, 13 + }), 14 + .enable_cross_platform_determinism = b.option( 15 + bool, 16 + "enable_cross_platform_determinism", 17 + "Enable cross-platform determinism", 18 + ) orelse true, 19 + }; 12 20 13 - pub fn link(pkg: Package, exe: *std.Build.Step.Compile) void { 14 - exe.root_module.addImport("zmath", pkg.zmath); 15 - exe.root_module.addImport("zmath_options", pkg.zmath_options); 21 + const options_step = b.addOptions(); 22 + inline for (std.meta.fields(@TypeOf(options))) |field| { 23 + options_step.addOption(field.type, field.name, @field(options, field.name)); 16 24 } 17 - }; 18 25 19 - pub fn package( 20 - b: *std.Build, 21 - target: std.Build.ResolvedTarget, 22 - _: std.builtin.Mode, 23 - args: struct { 24 - options: Options = .{}, 25 - }, 26 - ) Package { 27 - const step = b.addOptions(); 28 - step.addOption( 29 - bool, 30 - "enable_cross_platform_determinism", 31 - args.options.enable_cross_platform_determinism, 32 - ); 26 + const options_module = options_step.createModule(); 33 27 34 - const zmath_options = step.createModule(); 35 - 36 - const zmath = b.addModule("zmath", .{ 37 - .root_source_file = .{ .path = thisDir() ++ "/src/main.zig" }, 28 + const zmath = b.addModule("root", .{ 29 + .root_source_file = .{ .path = "src/main.zig" }, 38 30 .imports = &.{ 39 - .{ .name = "zmath_options", .module = zmath_options }, 31 + .{ .name = "zmath_options", .module = options_module }, 40 32 }, 41 33 }); 42 34 43 - return .{ 44 - .target = target, 45 - .options = args.options, 46 - .zmath = zmath, 47 - .zmath_options = zmath_options, 48 - }; 49 - } 50 - 51 - pub fn build(b: *std.Build) void { 52 - const optimize = b.standardOptimizeOption(.{}); 53 - const target = b.standardTargetOptions(.{}); 54 - 55 - _ = package(b, target, optimize, .{ .options = .{ 56 - .enable_cross_platform_determinism = b.option(bool, "enable_cross_platform_determinism", "Whether to enable cross-platform determinism.") orelse true, 57 - } }); 58 - 59 35 const test_step = b.step("test", "Run zmath tests"); 60 - test_step.dependOn(runTests(b, optimize, target)); 61 36 62 - const benchmark_step = b.step("benchmark", "Run zmath benchmarks"); 63 - benchmark_step.dependOn(runBenchmarks(b, target)); 64 - } 65 - 66 - pub fn runTests( 67 - b: *std.Build, 68 - optimize: std.builtin.Mode, 69 - target: std.Build.ResolvedTarget, 70 - ) *std.Build.Step { 71 37 const tests = b.addTest(.{ 72 38 .name = "zmath-tests", 73 - .root_source_file = .{ .path = thisDir() ++ "/src/main.zig" }, 39 + .root_source_file = .{ .path = "src/main.zig" }, 74 40 .target = target, 75 - .optimize = optimize, 41 + .optimize = options.optimize, 76 42 }); 43 + b.installArtifact(tests); 77 44 78 - const zmath_pkg = package(b, target, optimize, .{}); 79 - tests.root_module.addImport("zmath_options", zmath_pkg.zmath_options); 45 + tests.root_module.addImport("zmath_options", options_module); 80 46 81 - return &b.addRunArtifact(tests).step; 82 - } 47 + test_step.dependOn(&b.addRunArtifact(tests).step); 83 48 84 - pub fn runBenchmarks( 85 - b: *std.Build, 86 - target: std.Build.ResolvedTarget, 87 - ) *std.Build.Step { 88 - const exe = b.addExecutable(.{ 49 + const benchmark_step = b.step("benchmark", "Run zmath benchmarks"); 50 + 51 + const benchmarks = b.addExecutable(.{ 89 52 .name = "zmath-benchmarks", 90 - .root_source_file = .{ .path = thisDir() ++ "/src/benchmark.zig" }, 53 + .root_source_file = .{ .path = "src/benchmark.zig" }, 91 54 .target = target, 92 - .optimize = .ReleaseFast, 55 + .optimize = options.optimize, 93 56 }); 94 - 95 - const zmath_pkg = package(b, target, .ReleaseFast, .{}); 96 - exe.root_module.addImport("zmath", zmath_pkg.zmath); 57 + b.installArtifact(benchmarks); 97 58 98 - return &b.addRunArtifact(exe).step; 99 - } 59 + benchmarks.root_module.addImport("zmath", zmath); 100 60 101 - inline fn thisDir() []const u8 { 102 - return comptime std.fs.path.dirname(@src().file) orelse "."; 61 + benchmark_step.dependOn(&b.addRunArtifact(benchmarks).step); 103 62 }
+1 -1
libs/zmath/build.zig.zon
··· 1 1 .{ 2 2 .name = "zmath", 3 - .version = "0.9.6", 3 + .version = "0.10.0", 4 4 .paths = .{ 5 5 "build.zig", 6 6 "build.zig.zon",
+5 -5
libs/zmath/src/benchmark.zig
··· 1 1 // ------------------------------------------------------------------------------------------------- 2 2 // zmath - benchmarks 3 3 // ------------------------------------------------------------------------------------------------- 4 - // 'zig build benchmark' in the root project directory will build and run 'ReleaseFast' configuration. 4 + // 'zig build benchmark -Doptimize=ReleaseFast' will build and benchmakrs with all optimisations. 5 5 // 6 6 // ------------------------------------------------------------------------------------------------- 7 - // 'AMD Ryzen 9 3950X 16-Core Processor', Windows 11, Zig 0.10.0-dev.2620+0e9458a3f 7 + // 'AMD Ryzen 9 3950X 16-Core Processor', Windows 11, Zig 0.10.0-dev.2620+0e9458a3f, ReleaseFast 8 8 // ------------------------------------------------------------------------------------------------- 9 9 // matrix mul benchmark (AOS) - scalar version: 1.5880s, zmath version: 1.0642s 10 10 // cross3, scale, bias benchmark (AOS) - scalar version: 0.9318s, zmath version: 0.6888s ··· 13 13 // wave benchmark (SOA) - scalar version: 4.8165s, zmath version: 0.7338s 14 14 // 15 15 // ------------------------------------------------------------------------------------------------- 16 - // 'AMD Ryzen 7 5800X 8-Core Processer', Linux 5.17.14, Zig 0.10.0-dev.2624+d506275a0 16 + // 'AMD Ryzen 7 5800X 8-Core Processer', Linux 5.17.14, Zig 0.10.0-dev.2624+d506275a0, ReleaseFast 17 17 // ------------------------------------------------------------------------------------------------- 18 18 // matrix mul benchmark (AOS) - scalar version: 1.3672s, zmath version: 0.8617s 19 19 // cross3, scale, bias benchmark (AOS) - scalar version: 0.6586s, zmath version: 0.4803s ··· 22 22 // wave benchmark (SOA) - scalar version: 3.6598s, zmath version: 0.4231s 23 23 // 24 24 // ------------------------------------------------------------------------------------------------- 25 - // 'Apple M1 Max', macOS Version 12.4, Zig 0.10.0-dev.2657+74442f350 25 + // 'Apple M1 Max', macOS Version 12.4, Zig 0.10.0-dev.2657+74442f350, ReleaseFast 26 26 // ------------------------------------------------------------------------------------------------- 27 27 // matrix mul benchmark (AOS) - scalar version: 1.0297s, zmath version: 1.0538s 28 28 // cross3, scale, bias benchmark (AOS) - scalar version: 0.6294s, zmath version: 0.6532s ··· 31 31 // wave benchmark (SOA) - scalar version: 3.4220s, zmath version: 1.0255s 32 32 // 33 33 // ------------------------------------------------------------------------------------------------- 34 - // '11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz', Windows 11, Zig 0.10.0-dev.2620+0e9458a3f 34 + // '11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz', Windows 11, Zig 0.10.0-dev.2620+0e9458a3f, ReleaseFast 35 35 // ------------------------------------------------------------------------------------------------- 36 36 // matrix mul benchmark (AOS) - scalar version: 2.2308s, zmath version: 0.9376s 37 37 // cross3, scale, bias benchmark (AOS) - scalar version: 1.0821s, zmath version: 0.5110s
+6
libs/zmath/src/util.zig
··· 30 30 return translation; 31 31 } 32 32 33 + pub fn setTranslationVec(m: *zm.Mat, translation: zm.Vec) void { 34 + const w = m[3][3]; 35 + m[3] = translation; 36 + m[3][3] = w; 37 + } 38 + 33 39 pub fn getScaleVec(m: zm.Mat) zm.Vec { 34 40 const scale_x = zm.length3(zm.f32x4(m[0][0], m[1][0], m[2][0], 0))[0]; 35 41 const scale_y = zm.length3(zm.f32x4(m[0][1], m[1][1], m[2][1], 0))[0];
+6 -6
libs/zmath/src/zmath.zig
··· 2265 2265 const az = normalize3(eyedir); 2266 2266 const ax = normalize3(cross3(updir, az)); 2267 2267 const ay = normalize3(cross3(az, ax)); 2268 - return transpose(.{ 2269 - f32x4(ax[0], ax[1], ax[2], -dot3(ax, eyepos)[0]), 2270 - f32x4(ay[0], ay[1], ay[2], -dot3(ay, eyepos)[0]), 2271 - f32x4(az[0], az[1], az[2], -dot3(az, eyepos)[0]), 2272 - f32x4(0.0, 0.0, 0.0, 1.0), 2273 - }); 2268 + return .{ 2269 + f32x4(ax[0], ay[0], az[0], 0), 2270 + f32x4(ax[1], ay[1], az[1], 0), 2271 + f32x4(ax[2], ay[2], az[2], 0), 2272 + f32x4(-dot3(ax, eyepos)[0], -dot3(ay, eyepos)[0], -dot3(az, eyepos)[0], 1.0), 2273 + }; 2274 2274 } 2275 2275 pub fn lookToRh(eyepos: Vec, eyedir: Vec, updir: Vec) Mat { 2276 2276 return lookToLh(eyepos, -eyedir, updir);