From f4ee9d8228eca20412e8a580baca8ca121b8bfce Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 15 May 2024 16:34:03 -0500 Subject: [PATCH] Shader upade works on windows --- scripts/engine.js | 2 +- scripts/render.js | 4 +++- scripts/std.js | 4 ++-- scripts/widget.js | 1 - source/engine/jsffi.c | 16 ++++++++++++++++ source/engine/log.c | 4 ++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/engine.js b/scripts/engine.js index a178a72..80450eb 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -129,7 +129,7 @@ qq = 'ms'; profile.report = function(start, msg = "[undefined report]") { - console.info(`${msg} in ${profile.best_t(profile.now()-start)}`); + say(`${msg} in ${profile.best_t(profile.now()-start)}`); } profile.addreport = function(cache, line, start) diff --git a/scripts/render.js b/scripts/render.js index 11f54c4..49e8b8d 100644 --- a/scripts/render.js +++ b/scripts/render.js @@ -152,6 +152,8 @@ var shaderlang = { ios: "metal_ios", } +say(`shaderlang is ${shaderlang[os.sys()]}`); + var attr_map = { a_pos: 0, a_uv: 1, @@ -296,7 +298,7 @@ render.make_shader = function(shader) io.slurpwrite(out, shader); var backend = shaderlang[os.sys()]; - var ret = os.system(`sokol-shdc -b -f bare_yaml --slang=${backend} -i ${out} -o ${out}`); + var ret = os.system(`sokol-shdc -f bare_yaml --slang=${backend} -i ${out} -o ${out}`); if (ret) { console.info(`error compiling shader`); return; diff --git a/scripts/std.js b/scripts/std.js index 878412c..b323a4a 100644 --- a/scripts/std.js +++ b/scripts/std.js @@ -455,8 +455,8 @@ function cmd_args(cmdargs) if (cmds.length === 0) cmds[0] = "play"; else if (!Cmdline.orders[cmds[0]]) { - console.warn(`Command ${cmds[0]} not found.`); - return; + console.warn(`Command ${cmds[0]} not found. Playing instead.`); + cmds[0] = "play"; } Cmdline.orders[cmds[0]](cmds.slice(1)); diff --git a/scripts/widget.js b/scripts/widget.js index 8b3ac55..4c3719f 100644 --- a/scripts/widget.js +++ b/scripts/widget.js @@ -1,4 +1,3 @@ - var inputpanel = { title: "untitled", toString() { return this.title; }, diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 31540d4..15729e9 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -64,6 +64,13 @@ const char *js2str(JSValue v) { return JS_ToCString(js, v); } +char *js2strdup(JSValue v) { + char *str = JS_ToCString(js, v); + char *ret = strdup(str); + JS_FreeCString(js, str); + return ret; +} + void sg_buffer_free(sg_buffer *b) { sg_destroy_buffer(*b); @@ -747,6 +754,15 @@ sg_shader js2shader(JSValue v) char *fsmain = js2str(js_getpropstr(fs, "entry_point")); desc.vs.entry = vsmain; desc.fs.entry = fsmain; + desc.vs.d3d11_target = "vs_4_0"; + desc.fs.d3d11_target = "ps_4_0"; + JSValue attrs = js_getpropstr(vs, "inputs"); + int atin = js_arrlen(attrs); + for (int i = 0; i < atin; i++) { + JSValue u = js_getpropidx(attrs, i); + desc.attrs[i].sem_name = js2strdup(js_getpropstr(u,"sem_name")); + desc.attrs[i].sem_index = js2number(js_getpropstr(u, "sem_index")); + } JSValue vsu = js_getpropstr(vs, "uniform_blocks"); int unin = js_arrlen(vsu); for (int i = 0; i < unin; i++) { diff --git a/source/engine/log.c b/source/engine/log.c index 096554b..9ddf8b7 100644 --- a/source/engine/log.c +++ b/source/engine/log.c @@ -15,6 +15,10 @@ #include "script.h" +#ifdef __WIN32 +#include "debugapi.h" +#endif + #define ESC "\033[" #define BLACK 30 #define RED 31