Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
* switch math functions from wasm and pc target
* fix Range rvalue
* zig-build wasi target added
  • Loading branch information
kassane committed Jan 25, 2024
1 parent be0fc3f commit 1714046
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {

// C include path
for (lib_sokol.root_module.include_dirs.items) |include_dir| {
if (include_dir == .other_step) continue;
const path = if (include_dir == .path)
include_dir.path.getPath(b)
else if (include_dir == .path_system)
Expand Down Expand Up @@ -503,6 +504,8 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
b.fmt("{s}-apple-{s}", .{ if (options.target.result.cpu.arch.isAARCH64()) "arm64" else @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag) })
else if (options.target.result.isWasm())
b.fmt("{s}-unknown-unknown-wasm", .{@tagName(options.target.result.cpu.arch)})
else if (options.target.result.isWasm() and options.target.result.os.tag == .wasi)
b.fmt("{s}-unknown-{s}", .{ @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag) })
else
b.fmt("{s}-{s}-{s}", .{ @tagName(options.target.result.cpu.arch), @tagName(options.target.result.os.tag), @tagName(options.target.result.abi) });

Expand Down
6 changes: 4 additions & 2 deletions src/examples/mrt.d
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ void frame()
sg.beginPass(state.offscreen.pass, state.offscreen.pass_action);
sg.applyPipeline(state.offscreen.pip);
sg.applyBindings(state.offscreen.bind);
auto offs_rg = sgutil.asRange(offscreen_params);
sg.applyUniforms(
sg.ShaderStage.Vs,
shd.SLOT_OFFSCREEN_PARAMS,
sgutil.asRange(offscreen_params),
offs_rg,
);
sg.draw(0, 36, 1);
sg.endPass();
Expand All @@ -245,7 +246,8 @@ void frame()
sg.beginDefaultPass(state.dflt.pass_action, app.width(), app.height());
sg.applyPipeline(state.fsq.pip);
sg.applyBindings(state.fsq.bind);
sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, sgutil.asRange(fsq_params));
auto fsq_rg = sgutil.asRange(fsq_params);
sg.applyUniforms(sg.ShaderStage.Vs, shd.SLOT_FSQ_PARAMS, fsq_rg);
sg.draw(0, 4, 1);
sg.applyPipeline(state.dbg.pip);
foreach(i;[0,1,2]) {
Expand Down
33 changes: 22 additions & 11 deletions src/handmade/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ module handmade.math;

extern(C):

enum real PI = 0x1.921fb54442d18469898cc51701b84p+1L;
double zig_sqrt(double value) @nogc nothrow @trusted;
double zig_sqrtf(double value) @nogc nothrow @trusted;
double zig_cos(double value) @nogc nothrow @trusted;
double zig_sin(double value) @nogc nothrow @trusted;
double zig_tan(double value) @nogc nothrow @trusted;
alias sqrt = zig_sqrt;
alias sqrtf = zig_sqrtf;
alias cos = zig_cos;
alias sin = zig_sin;
alias tan = zig_tan;
version(WebAssembly){
enum PI = 3.14159265358979323846264338327950288419716939937510;
double zig_sqrt(ulong value) @nogc nothrow @trusted;
double zig_sqrtf(double value) @nogc nothrow @trusted;
double zig_cos(double value) @nogc nothrow @trusted;
double zig_sin(double value) @nogc nothrow @trusted;
double zig_tan(double value) @nogc nothrow @trusted;
alias cos = zig_cos;
alias sin = zig_sin;
alias tan = zig_tan;

auto sqrt(T)(T value){
static if(is(T == double) || is(T == float)){
return zig_sqrtf(value);
} else {
return zig_sqrt(value);
}
}
} else {
public import core.stdc.math: sqrt, cos, sin, tan;
public import std.math: PI;
}

@safe:

Expand Down
7 changes: 5 additions & 2 deletions tools/zigcc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ pub fn main() !void {
try cmds.append("zig");
try cmds.append("cc");

if (builtin.os.tag != .windows)
if (builtin.os.tag != .windows) {
// not working on msvc target (nostdlib++)
try cmds.append("-lunwind");
}

// LDC2 not setting triple targets on host build to cc/linker, except Apple (why?)
var isNative = true;
while (args.next()) |arg| {
// MacOS M1/M2 on ldc2 replace aarch64 to arm64 - (TODO: fix?)
// MacOS M1/M2 target, replace aarch64 to arm64
if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-apple-{s}", .{ if (builtin.cpu.arch.isAARCH64()) "arm64" else @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
try cmds.append("native-native");
try cmds.append("-fapple-link-rtlib");
} else if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-unknown-unknown-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
// wasm32 or wasm64
try cmds.append(std.fmt.comptimePrint("{s}-emscripten", .{@tagName(builtin.cpu.arch)}));
} else if (std.mem.eql(u8, arg, std.fmt.comptimePrint("{s}-unknown-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }))) {
try cmds.append(std.fmt.comptimePrint("{s}-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) }));
} else if (std.mem.eql(u8, arg, "-target")) {
isNative = false;
try cmds.append(arg); // get "-target" flag
Expand Down

0 comments on commit 1714046

Please sign in to comment.