qjs tracy d3d11
This commit is contained in:
@@ -64,7 +64,7 @@ deps += dependency('qjs-layout',static:true)
|
|||||||
deps += dependency('qjs-nota',static:true)
|
deps += dependency('qjs-nota',static:true)
|
||||||
deps += dependency('qjs-miniz',static:true)
|
deps += dependency('qjs-miniz',static:true)
|
||||||
deps += dependency('qjs-soloud',static:true)
|
deps += dependency('qjs-soloud',static:true)
|
||||||
#deps += dependency('qjs-dmon',static:true)
|
|
||||||
deps += dependency('threads')
|
deps += dependency('threads')
|
||||||
|
|
||||||
if get_option('chipmunk')
|
if get_option('chipmunk')
|
||||||
@@ -76,7 +76,8 @@ if get_option('enet')
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
sources = []
|
sources = []
|
||||||
src += ['anim.c', 'config.c', 'datastream.c','font.c','gameobject.c','HandmadeMath.c','jsffi.c','model.c','render.c','render_trace.cpp','script.c','simplex.c','spline.c','texture.c', 'timer.c', 'transform.c','warp.c','yugine.c', 'glad.c']
|
src += ['anim.c', 'config.c', 'datastream.c','font.c','gameobject.c','HandmadeMath.c','jsffi.c','model.c','render.c','render_trace.cpp','script.c','simplex.c','spline.c','texture.c', 'timer.c', 'transform.c','warp.c','yugine.c', 'glad.c', 'wildmatch.c']
|
||||||
|
|
||||||
imsrc = ['GraphEditor.cpp','ImCurveEdit.cpp','ImGradient.cpp','imgui_draw.cpp','imgui_tables.cpp','imgui_widgets.cpp','imgui.cpp','ImGuizmo.cpp','imnodes.cpp','implot_items.cpp','implot.cpp']
|
imsrc = ['GraphEditor.cpp','ImCurveEdit.cpp','ImGradient.cpp','imgui_draw.cpp','imgui_tables.cpp','imgui_widgets.cpp','imgui.cpp','ImGuizmo.cpp','imnodes.cpp','implot_items.cpp','implot.cpp']
|
||||||
|
|
||||||
srceng = 'source'
|
srceng = 'source'
|
||||||
@@ -94,6 +95,7 @@ if get_option('editor')
|
|||||||
foreach imgui : imsrc
|
foreach imgui : imsrc
|
||||||
sources += tp / 'imgui' / imgui
|
sources += tp / 'imgui' / imgui
|
||||||
endforeach
|
endforeach
|
||||||
|
deps += dependency('qjs-dmon',static:true)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
includers = []
|
includers = []
|
||||||
|
|||||||
@@ -460,9 +460,8 @@ Object.defHidden = function (obj, prop) {
|
|||||||
Object.hide = function hide(obj, ...props) {
|
Object.hide = function hide(obj, ...props) {
|
||||||
for (var prop of props) {
|
for (var prop of props) {
|
||||||
var p = Object.getOwnPropertyDescriptor(obj, prop);
|
var p = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
if (!p) continue;
|
if (p && p.enumerable)
|
||||||
p.enumerable = false;
|
Object.defineProperty(obj, prop, {...p, enumerable:false});
|
||||||
Object.defineProperty(obj, prop, p);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ frog = {
|
|||||||
...etc
|
...etc
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
function z_value() {return 100000 + this.gameobject.drawlayer * 1000 - this.gameobject.pos.y;}
|
|
||||||
var sprite = {
|
var sprite = {
|
||||||
image: undefined,
|
image: undefined,
|
||||||
get diffuse() { return this.image.texture; },
|
get diffuse() { return this.image.texture; },
|
||||||
set diffuse(x) {},
|
set diffuse(x) {},
|
||||||
z_value:z_value,
|
z_value() {return 100000 + this.gameobject.drawlayer * 1000 - this.gameobject.pos.y;},
|
||||||
anim_speed: 1,
|
anim_speed: 1,
|
||||||
play(str, loop = true, reverse = false, fn) {
|
play(str, loop = true, reverse = false, fn) {
|
||||||
if (!this.animset) {
|
if (!this.animset) {
|
||||||
|
|||||||
@@ -195,12 +195,13 @@ Object.defineProperty(Function.prototype, "hashify", {
|
|||||||
value: function () {
|
value: function () {
|
||||||
var hash = new Map();
|
var hash = new Map();
|
||||||
var fn = this;
|
var fn = this;
|
||||||
function ret() {
|
function hashified(...args) {
|
||||||
if (!hash.has(arguments[0])) hash.set(arguments[0], fn(...arguments));
|
var key = args[0];
|
||||||
|
if (!hash.has(key)) hash.set(key, fn(...args));
|
||||||
|
|
||||||
return hash.get(arguments[0]);
|
return hash.get(key);
|
||||||
}
|
}
|
||||||
return ret;
|
return hashified;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -235,7 +236,7 @@ console.rec = function(category, priority, line, file, msg)
|
|||||||
return `${file}:${line}: [${category} ${priority}]: ${msg}`;
|
return `${file}:${line}: [${category} ${priority}]: ${msg}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.pprint = function (msg, lvl = 0) {
|
console.pprint = function pprint(msg, lvl = 0) {
|
||||||
if (typeof msg === "object") msg = JSON.stringify(msg, null, 2);
|
if (typeof msg === "object") msg = JSON.stringify(msg, null, 2);
|
||||||
|
|
||||||
var file = "nofile";
|
var file = "nofile";
|
||||||
@@ -252,21 +253,22 @@ console.pprint = function (msg, lvl = 0) {
|
|||||||
}
|
}
|
||||||
var fmt = console.rec("script", lvl, line,file, msg);
|
var fmt = console.rec("script", lvl, line,file, msg);
|
||||||
console.log(fmt);
|
console.log(fmt);
|
||||||
|
if (tracy) tracy.message(fmt);
|
||||||
};
|
};
|
||||||
|
|
||||||
console.spam = function (msg) {
|
console.spam = function spam(msg) {
|
||||||
console.pprint(msg, 0);
|
console.pprint(msg, 0);
|
||||||
};
|
};
|
||||||
console.debug = function (msg) {
|
console.debug = function debug(msg) {
|
||||||
console.pprint(msg, 1);
|
console.pprint(msg, 1);
|
||||||
};
|
};
|
||||||
console.info = function (msg) {
|
console.info = function info(msg) {
|
||||||
console.pprint(msg, 2);
|
console.pprint(msg, 2);
|
||||||
};
|
};
|
||||||
console.warn = function (msg) {
|
console.warn = function warn(msg) {
|
||||||
console.pprint(msg, 3);
|
console.pprint(msg, 3);
|
||||||
};
|
};
|
||||||
console.error = function (msg) {
|
console.error = function error (msg) {
|
||||||
console.pprint(msg + "\n" + console.stackstr(2), 4);
|
console.pprint(msg + "\n" + console.stackstr(2), 4);
|
||||||
};
|
};
|
||||||
console.panic = function (msg) {
|
console.panic = function (msg) {
|
||||||
@@ -377,12 +379,14 @@ io.globToRegex = function globToRegex(glob) {
|
|||||||
return new RegExp(regexStr);
|
return new RegExp(regexStr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var tmpglob = io.glob;
|
||||||
io.glob = function glob(pat) {
|
io.glob = function glob(pat) {
|
||||||
return doglob(pat);
|
return allpaths.filter(str => tmpglob(pat,str)).sort();
|
||||||
var regex = io.globToRegex(pat);
|
|
||||||
return allpaths.filter(str => str.match(regex)).sort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(io.glob("sprites/*.png"))
|
||||||
|
console.log(io.glob("**/render.js"))
|
||||||
|
|
||||||
function splitPath(path) {
|
function splitPath(path) {
|
||||||
return path.split('/').filter(part => part.length > 0);
|
return path.split('/').filter(part => part.length > 0);
|
||||||
}
|
}
|
||||||
@@ -457,8 +461,6 @@ function doglob(pattern) {
|
|||||||
return matches.sort();
|
return matches.sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(doglob("sprites/*.png"))
|
|
||||||
|
|
||||||
function stripped_use(file, script) {
|
function stripped_use(file, script) {
|
||||||
file = Resources.find_script(file);
|
file = Resources.find_script(file);
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ var entity = {
|
|||||||
},
|
},
|
||||||
set pos(x) {
|
set pos(x) {
|
||||||
this.transform.pos = x;
|
this.transform.pos = x;
|
||||||
this.sync();
|
|
||||||
},
|
},
|
||||||
get angle() {
|
get angle() {
|
||||||
return this.transform.angle;
|
return this.transform.angle;
|
||||||
@@ -168,7 +167,7 @@ var entity = {
|
|||||||
*/
|
*/
|
||||||
ent.reparent(this);
|
ent.reparent(this);
|
||||||
|
|
||||||
for (var [prop, p] of Object.entries(ent)) {
|
/* for (var [prop, p] of Object.entries(ent)) {
|
||||||
if (!p) continue;
|
if (!p) continue;
|
||||||
if (typeof p !== "object") continue;
|
if (typeof p !== "object") continue;
|
||||||
if (!p.comp) continue;
|
if (!p.comp) continue;
|
||||||
@@ -176,6 +175,7 @@ var entity = {
|
|||||||
Object.merge(ent[prop], p);
|
Object.merge(ent[prop], p);
|
||||||
ent.components[prop] = ent[prop];
|
ent.components[prop] = ent[prop];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
check_registers(ent);
|
check_registers(ent);
|
||||||
|
|
||||||
@@ -185,8 +185,6 @@ var entity = {
|
|||||||
if (ent.start instanceof Function) ent.start();
|
if (ent.start instanceof Function) ent.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.hide(ent, "ur", "components", "objects", "timers", "guid", "master", "guid");
|
|
||||||
|
|
||||||
ent._ed = {
|
ent._ed = {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
@@ -194,7 +192,7 @@ var entity = {
|
|||||||
urdiff: {},
|
urdiff: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.hide(ent, "_ed");
|
Object.hide(ent, "ur", "components", "objects", "timers", "guid", "master", "guid", "_ed");
|
||||||
|
|
||||||
ent.sync();
|
ent.sync();
|
||||||
|
|
||||||
@@ -215,8 +213,8 @@ var entity = {
|
|||||||
|
|
||||||
if (callback) callback(ent);
|
if (callback) callback(ent);
|
||||||
|
|
||||||
ent.ur.fresh ??= json.decode(json.encode(ent));
|
// ent.ur.fresh ??= json.decode(json.encode(ent));
|
||||||
ent.ur.fresh.objects = {};
|
// ent.ur.fresh.objects = {};
|
||||||
// for (var i in ent.objects) ent.ur.fresh.objects[i] = ent.objects[i].instance_obj();
|
// for (var i in ent.objects) ent.ur.fresh.objects[i] = ent.objects[i].instance_obj();
|
||||||
|
|
||||||
return ent;
|
return ent;
|
||||||
@@ -407,10 +405,8 @@ var entity = {
|
|||||||
add_component(comp, data) {
|
add_component(comp, data) {
|
||||||
var name = prosperon.guid();
|
var name = prosperon.guid();
|
||||||
this.components[name] = comp(this);
|
this.components[name] = comp(this);
|
||||||
if (data) {
|
if (data)
|
||||||
Object.assign(this.components[name], data);
|
Object.assign(this.components[name], data);
|
||||||
this.components[name].sync?.();
|
|
||||||
}
|
|
||||||
return this.components[name];
|
return this.components[name];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ global.check_registers = function check_registers(obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var k in obj) {
|
/* for (var k in obj) {
|
||||||
if (!k.startsWith("on_")) continue;
|
if (!k.startsWith("on_")) continue;
|
||||||
var signal = k.fromfirst("on_");
|
var signal = k.fromfirst("on_");
|
||||||
Event.observe(signal, obj, obj[k]);
|
Event.observe(signal, obj, obj[k]);
|
||||||
}
|
}*/
|
||||||
};
|
};
|
||||||
|
|
||||||
globalThis.timers = []
|
globalThis.timers = []
|
||||||
|
|||||||
@@ -1446,6 +1446,12 @@ try{
|
|||||||
} catch(e) {
|
} catch(e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
// random tracy image
|
||||||
|
/* var vals = Object.values(game.texture.cache);
|
||||||
|
var tex = vals[Math.floor(Math.random()*vals.length)].texture;
|
||||||
|
var texdata = os.tex_data(tex)
|
||||||
|
tracy.image(texdata, tex.width, tex.height);
|
||||||
|
*/
|
||||||
render.end_pass();
|
render.end_pass();
|
||||||
render.commit();
|
render.commit();
|
||||||
endframe();
|
endframe();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ var audio = {};
|
|||||||
soloud.init();
|
soloud.init();
|
||||||
var pcms = {};
|
var pcms = {};
|
||||||
|
|
||||||
audio.pcm = function(file)
|
audio.pcm = function pcm(file)
|
||||||
{
|
{
|
||||||
file = Resources.find_sound(file);
|
file = Resources.find_sound(file);
|
||||||
if (!file) throw new Error(`Could not findfile ${file}`);
|
if (!file) throw new Error(`Could not findfile ${file}`);
|
||||||
@@ -14,13 +14,13 @@ audio.pcm = function(file)
|
|||||||
return newpcm;
|
return newpcm;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio.play = function (file) {
|
audio.play = function play(file) {
|
||||||
var pcm = audio.pcm(file);
|
var pcm = audio.pcm(file);
|
||||||
if (!pcm) return;
|
if (!pcm) return;
|
||||||
return soloud.play(pcm);
|
return soloud.play(pcm);
|
||||||
};
|
};
|
||||||
|
|
||||||
audio.cry = function (file) {
|
audio.cry = function cry(file) {
|
||||||
var voice = audio.play(file);
|
var voice = audio.play(file);
|
||||||
if (!voice) return;
|
if (!voice) return;
|
||||||
return function() {
|
return function() {
|
||||||
@@ -32,7 +32,7 @@ audio.cry = function (file) {
|
|||||||
var song;
|
var song;
|
||||||
|
|
||||||
// Play 'file' for new song, cross fade for seconds
|
// Play 'file' for new song, cross fade for seconds
|
||||||
audio.music = function (file, fade = 0.5) {
|
audio.music = function music(file, fade = 0.5) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
if (song) song.volume = 0;
|
if (song) song.volume = 0;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1810,33 +1810,16 @@ JSC_SCALL(io_rm, ret = number2js(js,remove(str)))
|
|||||||
JSC_SCALL(io_mkdir, ret = number2js(js,mkdir(str,0777)))
|
JSC_SCALL(io_mkdir, ret = number2js(js,mkdir(str,0777)))
|
||||||
|
|
||||||
// glob sprites/*.png
|
// glob sprites/*.png
|
||||||
// glob **/*.png
|
// glob sprite/**/*.png
|
||||||
|
// pattern: sprites/fool.png
|
||||||
int glob_twostar(char *glob, char *text)
|
// glob sprites/fool.png
|
||||||
{
|
#include "wildmatch.h"
|
||||||
|
JSC_SSCALL(io_glob,
|
||||||
}
|
if (wildmatch(str, str2, WM_PATHNAME | WM_PERIOD | WM_WILDSTAR) == WM_MATCH)
|
||||||
|
return JS_NewBool(js,1);
|
||||||
int glob_star(char *glob, char *text)
|
else
|
||||||
{
|
return JS_NewBool(js, 0);
|
||||||
|
)
|
||||||
}
|
|
||||||
|
|
||||||
int glob_match(char *glob, char *text)
|
|
||||||
{
|
|
||||||
if (glob[0] == '*') {
|
|
||||||
if (glob[1] == '*')
|
|
||||||
return glob_twostar(glob+2, text);
|
|
||||||
return glob_star(glob+1, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glob[0] == '?')
|
|
||||||
return glob_match(glob+1,text+1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSC_SSALL(io_glob, return JS_ToBool(js, glob_match(str, str2)); )
|
|
||||||
|
|
||||||
#include <quickjs.h>
|
#include <quickjs.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -1985,7 +1968,8 @@ static const JSCFunctionListEntry js_io_funcs[] = {
|
|||||||
MIST_FUNC_DEF(io, chmod, 2),
|
MIST_FUNC_DEF(io, chmod, 2),
|
||||||
MIST_FUNC_DEF(io, slurp, 2),
|
MIST_FUNC_DEF(io, slurp, 2),
|
||||||
MIST_FUNC_DEF(io, slurpwrite, 2),
|
MIST_FUNC_DEF(io, slurpwrite, 2),
|
||||||
MIST_FUNC_DEF(io, mod,1)
|
MIST_FUNC_DEF(io, mod,1),
|
||||||
|
MIST_FUNC_DEF(io, glob, 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
JSC_GETSET(transform, pos, vec3)
|
JSC_GETSET(transform, pos, vec3)
|
||||||
@@ -2873,6 +2857,26 @@ JSC_SCALL(os_kill,
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#include "glad.h"
|
||||||
|
JSC_CCALL(os_tex_data,
|
||||||
|
#ifdef SOKOL_GLCORE
|
||||||
|
texture *tex = js2texture(js, argv[0]);
|
||||||
|
sg_gl_image_info glinfo = sg_gl_query_image_info(tex->id);
|
||||||
|
glBindTexture(glinfo.tex_target, glinfo.tex[glinfo.active_slot]);
|
||||||
|
unsigned char *pixels = malloc(tex->width * tex->height * 4);
|
||||||
|
glGetTexImage(glinfo.tex_target, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
GLenum err = glGetError();
|
||||||
|
if (err != GL_NO_ERROR) {
|
||||||
|
free(pixels);
|
||||||
|
return JS_ThrowReferenceError(js, "could not pull pixel data");
|
||||||
|
}
|
||||||
|
glBindTexture(glinfo.tex_target,0);
|
||||||
|
ret = JS_NewArrayBufferCopy(js,pixels,tex->width*tex->height*4);
|
||||||
|
free(pixels);
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_os_funcs[] = {
|
static const JSCFunctionListEntry js_os_funcs[] = {
|
||||||
MIST_FUNC_DEF(os, turbulence, 4),
|
MIST_FUNC_DEF(os, turbulence, 4),
|
||||||
MIST_FUNC_DEF(os, fbm, 4),
|
MIST_FUNC_DEF(os, fbm, 4),
|
||||||
@@ -2926,6 +2930,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
|||||||
MIST_FUNC_DEF(os, gltf_skin, 1),
|
MIST_FUNC_DEF(os, gltf_skin, 1),
|
||||||
MIST_FUNC_DEF(os, skin_calculate, 1),
|
MIST_FUNC_DEF(os, skin_calculate, 1),
|
||||||
MIST_FUNC_DEF(os, kill, 1),
|
MIST_FUNC_DEF(os, kill, 1),
|
||||||
|
MIST_FUNC_DEF(os, tex_data,1),
|
||||||
};
|
};
|
||||||
|
|
||||||
#define JSSTATIC(NAME, PARENT) \
|
#define JSSTATIC(NAME, PARENT) \
|
||||||
@@ -2937,7 +2942,6 @@ JSValue js_layout_use(JSContext *js);
|
|||||||
JSValue js_miniz_use(JSContext *js);
|
JSValue js_miniz_use(JSContext *js);
|
||||||
JSValue js_soloud_use(JSContext *js);
|
JSValue js_soloud_use(JSContext *js);
|
||||||
JSValue js_chipmunk2d_use(JSContext *js);
|
JSValue js_chipmunk2d_use(JSContext *js);
|
||||||
//JSValue js_dmon_use(JSContext *js);
|
|
||||||
|
|
||||||
#ifdef TRACY_ENABLE
|
#ifdef TRACY_ENABLE
|
||||||
JSValue js_tracy_use(JSContext *js);
|
JSValue js_tracy_use(JSContext *js);
|
||||||
@@ -2945,6 +2949,7 @@ JSValue js_tracy_use(JSContext *js);
|
|||||||
|
|
||||||
#ifndef NEDITOR
|
#ifndef NEDITOR
|
||||||
JSValue js_imgui(JSContext *js);
|
JSValue js_imgui(JSContext *js);
|
||||||
|
JSValue js_dmon_use(JSContext *js);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void signal_handler(int sig) {
|
static void signal_handler(int sig) {
|
||||||
@@ -3027,7 +3032,7 @@ void ffi_load(JSContext *js) {
|
|||||||
JS_SetPropertyStr(js, globalThis, "miniz", js_miniz_use(js));
|
JS_SetPropertyStr(js, globalThis, "miniz", js_miniz_use(js));
|
||||||
JS_SetPropertyStr(js, globalThis, "soloud", js_soloud_use(js));
|
JS_SetPropertyStr(js, globalThis, "soloud", js_soloud_use(js));
|
||||||
JS_SetPropertyStr(js, globalThis, "chipmunk2d", js_chipmunk2d_use(js));
|
JS_SetPropertyStr(js, globalThis, "chipmunk2d", js_chipmunk2d_use(js));
|
||||||
// JS_SetPropertyStr(js, globalThis, "dmon", js_dmon_use(js));
|
|
||||||
|
|
||||||
#ifdef TRACY_ENABLE
|
#ifdef TRACY_ENABLE
|
||||||
JS_SetPropertyStr(js, globalThis, "tracy", js_tracy_use(js));
|
JS_SetPropertyStr(js, globalThis, "tracy", js_tracy_use(js));
|
||||||
@@ -3040,6 +3045,7 @@ void ffi_load(JSContext *js) {
|
|||||||
atexit(exit_handler);
|
atexit(exit_handler);
|
||||||
|
|
||||||
#ifndef NEDITOR
|
#ifndef NEDITOR
|
||||||
|
JS_SetPropertyStr(js, globalThis, "dmon", js_dmon_use(js));
|
||||||
JS_SetPropertyStr(js, globalThis, "imgui", js_imgui(js));
|
JS_SetPropertyStr(js, globalThis, "imgui", js_imgui(js));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
|
#include <sokol_app.h>
|
||||||
|
#include <sokol/sokol_gfx.h>
|
||||||
|
|
||||||
static JSValue js_tracy_fiber_enter(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_fiber_enter(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
@@ -33,7 +36,6 @@ static JSValue js_tracy_fiber_leave(JSContext *js, JSValue self, int argc, JSVal
|
|||||||
|
|
||||||
JSAtom atom = JS_ValueToAtom(js,argv[0]);
|
JSAtom atom = JS_ValueToAtom(js,argv[0]);
|
||||||
const char *str = JS_AtomToCString(js, atom);
|
const char *str = JS_AtomToCString(js, atom);
|
||||||
// printf("EXIT STR AT %p\n", str);
|
|
||||||
TracyCFiberLeave(str);
|
TracyCFiberLeave(str);
|
||||||
JS_FreeAtom(js,atom);
|
JS_FreeAtom(js,atom);
|
||||||
}
|
}
|
||||||
@@ -158,8 +160,6 @@ static JSValue js_tracy_gpu_zone_begin(JSContext *js, JSValue self, int argc, JS
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// glQueryCounter
|
|
||||||
|
|
||||||
glQueryCounter(ids[qhead], GL_TIMESTAMP);
|
glQueryCounter(ids[qhead], GL_TIMESTAMP);
|
||||||
struct ___tracy_gpu_zone_begin_data data;
|
struct ___tracy_gpu_zone_begin_data data;
|
||||||
|
|
||||||
@@ -175,11 +175,12 @@ static JSValue js_tracy_gpu_zone_begin(JSContext *js, JSValue self, int argc, JS
|
|||||||
data.queryId = ids[qhead];
|
data.queryId = ids[qhead];
|
||||||
data.context = 0;
|
data.context = 0;
|
||||||
___tracy_emit_gpu_zone_begin_alloc(data);
|
___tracy_emit_gpu_zone_begin_alloc(data);
|
||||||
JS_FreeCString(js,js_fn_name);
|
JS_FreeCString(js,js_fn_name);
|
||||||
|
JS_FreeCString(js, fn_src);
|
||||||
|
|
||||||
qhead = (qhead+1)%query_count;
|
qhead = (qhead+1)%query_count;
|
||||||
|
|
||||||
|
JSValue ret = JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL);
|
||||||
JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL);
|
|
||||||
|
|
||||||
glQueryCounter(ids[qhead], GL_TIMESTAMP);
|
glQueryCounter(ids[qhead], GL_TIMESTAMP);
|
||||||
struct ___tracy_gpu_zone_end_data enddata = {
|
struct ___tracy_gpu_zone_end_data enddata = {
|
||||||
@@ -190,7 +191,7 @@ static JSValue js_tracy_gpu_zone_begin(JSContext *js, JSValue self, int argc, JS
|
|||||||
qhead = (qhead+1)%query_count;
|
qhead = (qhead+1)%query_count;
|
||||||
|
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue js_tracy_gpu_sync(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_sync(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
@@ -213,6 +214,11 @@ static JSValue js_tracy_gpu_sync(JSContext *js, JSValue self, int argc, JSValue
|
|||||||
|
|
||||||
static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if (!TracyCIsConnected)
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
#endif
|
||||||
|
|
||||||
GLint available;
|
GLint available;
|
||||||
while (qtail != qhead) {
|
while (qtail != qhead) {
|
||||||
glGetQueryObjectiv(ids[qtail], GL_QUERY_RESULT_AVAILABLE, &available);
|
glGetQueryObjectiv(ids[qtail], GL_QUERY_RESULT_AVAILABLE, &available);
|
||||||
@@ -231,28 +237,216 @@ static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSVal
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_tracy_image(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
double width, height;
|
||||||
|
JS_ToFloat64(js,&width,argv[1]);
|
||||||
|
JS_ToFloat64(js,&height,argv[2]);
|
||||||
|
___tracy_emit_frame_image(JS_GetArrayBuffer(js, &len, argv[0]), width, height, 0, 0);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
#elifdef SOKOL_D3D11
|
#elifdef SOKOL_D3D11
|
||||||
static int max_queries = 64*1024;
|
#include <d3d11.h>
|
||||||
|
static int query_count = 64*1024;
|
||||||
|
|
||||||
|
ID3D11Device *device = NULL;
|
||||||
|
ID3D11DeviceContext *context = NULL;
|
||||||
|
ID3D11RenderTargetView *render_view = NULL;
|
||||||
|
ID3D11Query *disjoint_query = NULL;
|
||||||
|
ID3D11Query **queries;
|
||||||
|
|
||||||
|
int qtail = 0;
|
||||||
|
int qhead = 1;
|
||||||
|
|
||||||
static JSValue js_tracy_gpu_init(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_init(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
// D3D11_QUERY_DESC desc= {};
|
HRESULT hr;
|
||||||
|
queries = malloc(sizeof(ID3D11Query*) * query_count);
|
||||||
|
device = sapp_d3d11_get_device();
|
||||||
|
context = sapp_d3d11_get_device_context();
|
||||||
|
render_view = sapp_d3d11_get_render_view();
|
||||||
|
|
||||||
|
D3D11_QUERY_DESC disjoint_desc = {0};
|
||||||
|
disjoint_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
|
||||||
|
|
||||||
|
if (FAILED(hr = device->lpVtbl->CreateQuery(device, &disjoint_desc, &disjoint_query)))
|
||||||
|
return JS_ThrowReferenceError(js,"Failed to create disjoint query, HRESULT: 0x%X\n", hr);
|
||||||
|
|
||||||
|
D3D11_QUERY_DESC timestamp_desc = {0};
|
||||||
|
timestamp_desc.Query = D3D11_QUERY_TIMESTAMP;
|
||||||
|
|
||||||
|
for (int i = 0; i < query_count; ++i)
|
||||||
|
if (FAILED(hr = device->lpVtbl->CreateQuery(device, ×tamp_desc, &queries[i])))
|
||||||
|
return JS_ThrowReferenceError(js,"Failed to create query %d, HRESULT: 0x%X\n", i, hr);
|
||||||
|
|
||||||
|
UINT64 tgpu = 0;
|
||||||
|
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint_data;
|
||||||
|
|
||||||
|
context->lpVtbl->Begin(context, disjoint_query);
|
||||||
|
context->lpVtbl->End(context, queries[0]);
|
||||||
|
context->lpVtbl->End(context, disjoint_query);
|
||||||
|
while (context->lpVtbl->GetData(context, disjoint_query, &disjoint_data, sizeof(disjoint_data), 0) != S_OK);
|
||||||
|
while (context->lpVtbl->GetData(context, queries[0], &tgpu, sizeof(tgpu), 0) != S_OK);
|
||||||
|
|
||||||
|
struct ___tracy_gpu_new_context_data gpuctx = {
|
||||||
|
.gpuTime = tgpu * (1000000000 / disjoint_data.Frequency),
|
||||||
|
.period = 1.0f,
|
||||||
|
.context = 0,
|
||||||
|
.flags = 0,
|
||||||
|
.type = 2
|
||||||
|
};
|
||||||
|
___tracy_emit_gpu_new_context(gpuctx);
|
||||||
|
|
||||||
|
context->lpVtbl->Begin(context, disjoint_query);
|
||||||
|
qtail = qhead = 0;
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue js_tracy_gpu_zone_begin(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_zone_begin(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
return JS_Call(js,argv[0], JS_UNDEFINED, 0, NULL);
|
#ifdef TRACY_ON_DEMAND
|
||||||
return JS_UNDEFINED;
|
if (!TracyCIsConnected) {
|
||||||
|
JS_Call(js,argv[0], JS_UNDEFINED, 0, NULL);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
context->lpVtbl->End(context, queries[qhead]);
|
||||||
|
struct ___tracy_gpu_zone_begin_data data;
|
||||||
|
|
||||||
|
const char *fn_src = JS_AtomToCString(js, js_fn_filename(js, argv[0]));
|
||||||
|
const char *js_fn_name = get_func_name(js, argv[0]);
|
||||||
|
const char *fn_name;
|
||||||
|
if (!js_fn_name || js_fn_name[0] == 0)
|
||||||
|
fn_name = "<anonymous>";
|
||||||
|
else
|
||||||
|
fn_name = js_fn_name;
|
||||||
|
data.srcloc = ___tracy_alloc_srcloc(js_fn_linenum(js,argv[0]), fn_src, strlen(fn_src), fn_name, strlen(fn_name), (int)fn_src);
|
||||||
|
|
||||||
|
data.queryId = qhead;
|
||||||
|
data.context = 0;
|
||||||
|
___tracy_emit_gpu_zone_begin_alloc(data);
|
||||||
|
JS_FreeCString(js,js_fn_name);
|
||||||
|
JS_FreeCString(js, fn_src);
|
||||||
|
qhead = (qhead+1)%query_count;
|
||||||
|
|
||||||
|
JSValue ret = JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL);
|
||||||
|
context->lpVtbl->End(context, queries[qhead]);
|
||||||
|
struct ___tracy_gpu_zone_end_data enddata = {
|
||||||
|
.queryId = qhead,
|
||||||
|
.context = 0
|
||||||
|
};
|
||||||
|
___tracy_emit_gpu_zone_end(enddata);
|
||||||
|
qhead = (qhead+1)%query_count;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue js_tracy_gpu_sync(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_sync(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if (!TracyCIsConnected)
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
#endif
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSValue *argv)
|
static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
#ifdef TRACY_ON_DEMAND
|
||||||
|
if (!TracyCIsConnected)
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
#endif
|
||||||
|
HRESULT hr;
|
||||||
|
// Use the current head to get a sync value
|
||||||
|
context->lpVtbl->End(context, queries[qhead]);
|
||||||
|
context->lpVtbl->End(context, disjoint_query);
|
||||||
|
|
||||||
|
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint_data;
|
||||||
|
while(context->lpVtbl->GetData(context, disjoint_query, &disjoint_data, sizeof(disjoint_data), 0) != S_OK);
|
||||||
|
|
||||||
|
if (disjoint_data.Disjoint) {
|
||||||
|
qtail = qhead;
|
||||||
|
return JS_ThrowReferenceError(js,"disjoint timestamps detected; dropping.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* uint64_t synctime = 0;
|
||||||
|
while (context->lpVtbl->GetData(context, queries[qhead], &synctime, sizeof(synctime), 0) != S_OK);
|
||||||
|
___tracy_emit_gpu_time_sync((struct ___tracy_gpu_time_sync_data) {
|
||||||
|
.context = 0,
|
||||||
|
.gpuTime = synctime * 1000000000 / disjoint_data.Frequency
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
while (qtail != qhead) {
|
||||||
|
uint64_t time = 0;
|
||||||
|
while(context->lpVtbl->GetData(context, queries[qtail], &time, sizeof(time), 0) != S_OK);
|
||||||
|
|
||||||
|
struct ___tracy_gpu_time_data gtime = {
|
||||||
|
.gpuTime = time * (1000000000 / disjoint_data.Frequency),
|
||||||
|
.queryId = qtail,
|
||||||
|
.context = 0
|
||||||
|
};
|
||||||
|
qtail = (qtail+1)%query_count;
|
||||||
|
___tracy_emit_gpu_time(gtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
qtail = qhead;
|
||||||
|
context->lpVtbl->Begin(context, disjoint_query);
|
||||||
|
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <stb_image_resize2.h>
|
||||||
|
#include <stb_image_write.h>
|
||||||
|
|
||||||
|
static JSValue js_tracy_image(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
|
{
|
||||||
|
if (!TracyCIsConnected) return JS_UNDEFINED;
|
||||||
|
|
||||||
|
HRESULT hr;
|
||||||
|
// create staging texture
|
||||||
|
// Get render target texture
|
||||||
|
ID3D11Texture2D *render_target_tex = NULL;
|
||||||
|
render_view->lpVtbl->GetResource(sapp_d3d11_get_render_view(), &render_target_tex);
|
||||||
|
// if (FAILED(hr)) return JS_ThrowReferenceError(js, "Failed to query texture from render target");
|
||||||
|
|
||||||
|
D3D11_TEXTURE2D_DESC render_tex_desc;
|
||||||
|
render_target_tex->lpVtbl->GetDesc(render_target_tex, &render_tex_desc);
|
||||||
|
|
||||||
|
render_tex_desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
render_tex_desc.BindFlags = 0;
|
||||||
|
render_tex_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
render_tex_desc.MiscFlags = 0;
|
||||||
|
render_tex_desc.SampleDesc = (DXGI_SAMPLE_DESC){ .Count = 1, .Quality = 0, };
|
||||||
|
|
||||||
|
ID3D11Texture2D *staging_tex = NULL;
|
||||||
|
hr = device->lpVtbl->CreateTexture2D(device, &render_tex_desc, NULL, &staging_tex);
|
||||||
|
if (FAILED(hr)) return JS_ThrowReferenceError(js, "Failed to create staging texture: 0x%08X\n", hr);
|
||||||
|
|
||||||
|
context->lpVtbl->CopyResource(context, staging_tex, render_target_tex);
|
||||||
|
|
||||||
|
D3D11_MAPPED_SUBRESOURCE mapped_res;
|
||||||
|
hr = context->lpVtbl->Map(context, staging_tex, 0, D3D11_MAP_READ, 0, &mapped_res);
|
||||||
|
if (FAILED(hr)) return JS_ThrowReferenceError(js, "Failed to map subresource");
|
||||||
|
|
||||||
|
// resize
|
||||||
|
int newwidth = 320;
|
||||||
|
int newheight = 180;
|
||||||
|
void *newdata = malloc(320*180*4);
|
||||||
|
stbir_resize_uint8_linear(mapped_res.pData, render_tex_desc.Width, render_tex_desc.Height, 0, newdata, newwidth, newheight, 0, 4);
|
||||||
|
|
||||||
|
___tracy_emit_frame_image(newdata, newwidth, newheight, 0, 0);
|
||||||
|
|
||||||
|
context->lpVtbl->Unmap(context, staging_tex, 0);
|
||||||
|
staging_tex->lpVtbl->Release(staging_tex);
|
||||||
|
render_target_tex->lpVtbl->Release(render_target_tex);
|
||||||
|
free(newdata);
|
||||||
|
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,19 +472,25 @@ static JSValue js_tracy_gpu_collect(JSContext *js, JSValue self, int argc, JSVal
|
|||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_tracy_image(JSContext *js, JSValue self, int argc, JSValue *argv)
|
||||||
|
{
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_tracy_funcs[] = {
|
static const JSCFunctionListEntry js_tracy_funcs[] = {
|
||||||
JS_CFUNC_DEF("fiber", 1, js_tracy_fiber_enter),
|
JS_CFUNC_DEF("fiber", 1, js_tracy_fiber_enter),
|
||||||
JS_CFUNC_DEF("fiber_leave", 1, js_tracy_fiber_leave),
|
JS_CFUNC_DEF("fiber_leave", 1, js_tracy_fiber_leave),
|
||||||
JS_CFUNC_DEF("gpu_zone", 1, js_tracy_gpu_zone_begin),
|
JS_CFUNC_DEF("gpu_zone", 1, js_tracy_gpu_zone_begin),
|
||||||
JS_CFUNC_DEF("gpu_collect", 0, js_tracy_gpu_collect),
|
JS_CFUNC_DEF("gpu_collect", 1, js_tracy_gpu_collect),
|
||||||
JS_CFUNC_DEF("gpu_init", 0, js_tracy_gpu_init),
|
JS_CFUNC_DEF("gpu_init", 0, js_tracy_gpu_init),
|
||||||
JS_CFUNC_DEF("gpu_sync", 0, js_tracy_gpu_sync),
|
JS_CFUNC_DEF("gpu_sync", 0, js_tracy_gpu_sync),
|
||||||
JS_CFUNC_DEF("end_frame", 0, js_tracy_frame_mark),
|
JS_CFUNC_DEF("end_frame", 0, js_tracy_frame_mark),
|
||||||
JS_CFUNC_DEF("zone", 1, js_tracy_zone_begin),
|
JS_CFUNC_DEF("zone", 1, js_tracy_zone_begin),
|
||||||
JS_CFUNC_DEF("message", 1, js_tracy_message),
|
JS_CFUNC_DEF("message", 1, js_tracy_message),
|
||||||
JS_CFUNC_DEF("plot", 2, js_tracy_plot),
|
JS_CFUNC_DEF("plot", 2, js_tracy_plot),
|
||||||
|
JS_CFUNC_DEF("image", 3, js_tracy_image),
|
||||||
};
|
};
|
||||||
|
|
||||||
JSValue js_tracy_use(JSContext *js)
|
JSValue js_tracy_use(JSContext *js)
|
||||||
|
|||||||
Reference in New Issue
Block a user