proactive memory free, option for zerocopy (seems slower), track prepare times

This commit is contained in:
Stewart Allen 2020-11-26 08:48:19 -05:00
commit 4da43685f4
8 changed files with 91 additions and 19 deletions

View file

@ -17,6 +17,7 @@
# cnc # cnc
# lathe? # lathe?
# complex process order # complex process order
# double-sided assistance
# fdm # fdm
# redo automatic supports using faces instead of deltas # redo automatic supports using faces instead of deltas
# bind process to z ranges or boxed regions # bind process to z ranges or boxed regions
@ -88,6 +89,7 @@
* `F` add option to spiral in vs out (optimal tool life) vs mixed (optimal path) * `F` add option to spiral in vs out (optimal tool life) vs mixed (optimal path)
* `F` add support for tapered ball mills * `F` add support for tapered ball mills
* `F` warn when part > stock or cuts go outside bed * `F` warn when part > stock or cuts go outside bed
* `F` A-B linked cutting profiles for double-sided milling / part flips
* `P` crossing open space check point is outside camshell before returning max z * `P` crossing open space check point is outside camshell before returning max z
* `P` detect render message backlog and pause or warn * `P` detect render message backlog and pause or warn

View file

@ -7,6 +7,8 @@
if (self.kiri.codec) return; if (self.kiri.codec) return;
const BASE = self.base, KIRI = self.kiri, handlers = {}; const BASE = self.base, KIRI = self.kiri, handlers = {};
const freeMem = true;
const zeroOut = false;
const codec = KIRI.codec = { const codec = KIRI.codec = {
encode: encode, encode: encode,
@ -123,12 +125,15 @@
}); });
KIRI.Slice.prototype.encode = function(state) { KIRI.Slice.prototype.encode = function(state) {
return { const rv = {
type: 'slice', type: 'slice',
z: this.z, z: this.z,
index: this.index, index: this.index,
render: encode(this.render, state) render: encode(this.render, state)
}; };
// aggressively free memory
if (freeMem) this.render = undefined;
return rv;
}; };
registerDecoder('slice', function(v, state) { registerDecoder('slice', function(v, state) {
@ -152,19 +157,28 @@
cface: layer.cface, cface: layer.cface,
color: layer.color, color: layer.color,
paths: layer.paths.map(lp => { paths: layer.paths.map(lp => {
return { const pe = {
z: lp.z, z: lp.z,
index: lp.index, index: lp.index,
faces: codec.allocFloat32Array(lp.faces) faces: codec.allocFloat32Array(lp.faces)
}; };
if (zeroOut && state.zeros && pe.faces.length) {
state.zeros.push(pe.faces.buffer);
}
return pe;
}), }),
cpath: layer.cpath, cpath: layer.cpath,
off: layer.off off: layer.off
}; };
if (zeroOut && state.zeros && e.faces.length) {
state.zeros.push(e.faces.buffer);
}
// console.log('-->',e); // console.log('-->',e);
return e; return e;
}) })
}; };
// aggressively free memory
if (freeMem) this.init();
return enc; return enc;
}; };
@ -253,6 +267,10 @@
array[pos++] = point.z; array[pos++] = point.z;
}); });
if (zeroOut && state.zeros) {
state.zeros.push(array.buffer);
}
return array; return array;
} }

View file

@ -740,7 +740,7 @@
totalProgress, totalProgress,
track = {}, track = {},
mode = settings.mode, mode = settings.mode,
now = UTIL.time(); now = Date.now();
// require topo be sent back from worker for local printing // require topo be sent back from worker for local printing
settings.synth.sendTopo = false; settings.synth.sendTopo = false;
@ -762,12 +762,13 @@
widget.stats.progress = 0; widget.stats.progress = 0;
widget.setColor(color.slicing); widget.setColor(color.slicing);
widget.slice(settings, function(sliced, error) { widget.slice(settings, function(sliced, error) {
let mark = UTIL.time(); let mark = Date.now();
// update UI info // update UI info
if (sliced) { if (sliced) {
// update segment time // update segment time
if (lastMsg) segtimes[`${segNumber++}_${lastMsg}`] = mark - startTime; if (lastMsg) {
segtimes.total = UTIL.time() - now; segtimes[`${segNumber++}_${lastMsg}`] = mark - startTime;
}
API.event.emit('slice', getMode()); API.event.emit('slice', getMode());
} }
// on done // on done
@ -786,6 +787,7 @@
SPACE.scene.active(); SPACE.scene.active();
API.event.emit('slice.end', getMode()); API.event.emit('slice.end', getMode());
// print stats // print stats
segtimes.total = Date.now() - now;
DBUG.log(segtimes); DBUG.log(segtimes);
if (callback && typeof callback === 'function') { if (callback && typeof callback === 'function') {
callback(); callback();
@ -801,8 +803,10 @@
} }
}, function(update, msg) { }, function(update, msg) {
if (msg !== lastMsg) { if (msg !== lastMsg) {
let mark = UTIL.time(); let mark = Date.now();
if (lastMsg) segtimes[`${segNumber++}_${lastMsg}`] = mark - startTime; if (lastMsg) {
segtimes[`${segNumber++}_${lastMsg}`] = mark - startTime;
}
lastMsg = msg; lastMsg = msg;
startTime = mark; startTime = mark;
} }
@ -847,21 +851,45 @@
setOpacity(color.preview_opacity); setOpacity(color.preview_opacity);
} }
let segtimes = {},
segNumber = 0,
startTime,
lastMsg,
now = Date.now();
KIRI.client.prepare(settings, function(progress, message) { KIRI.client.prepare(settings, function(progress, message) {
if (message !== lastMsg) {
let mark = Date.now();
if (lastMsg) {
segtimes[`${segNumber++}_${lastMsg}`] = mark - startTime;
}
lastMsg = message;
startTime = mark;
}
API.show.progress(progress, message); API.show.progress(progress, message);
}, function (output, maxSpeed) { }, function (output, maxSpeed) {
if (lastMsg) {
segtimes[`${segNumber++}_${lastMsg}`] = Date.now() - startTime;
}
API.show.progress(0); API.show.progress(0);
if (!isCam) setOpacity(0); if (!isCam) setOpacity(0);
output = KIRI.codec.decode(output); output = KIRI.codec.decode(output);
if (feature.preview && output) { if (feature.preview && output) {
startTime = Date.now();
STACKS.clear(); STACKS.clear();
const stack = STACKS.create('print', SPACE.platform.world) const stack = STACKS.create('print', SPACE.platform.world)
output.forEach(layer => { output.forEach(layer => {
stack.add(layer); stack.add(layer);
}); });
segtimes[`${segNumber}_draw`] = Date.now() - startTime;
} }
// print stats
segtimes.total = Date.now() - now;
DBUG.log(segtimes);
API.event.emit('print', pMode); API.event.emit('print', pMode);
API.event.emit('preview.end', pMode); API.event.emit('preview.end', pMode);

View file

@ -7,6 +7,10 @@
class Render { class Render {
constructor() { constructor() {
this.init();
}
init() {
this.layers = {}; this.layers = {};
this.profiles = {}; this.profiles = {};
this.stats = { this.stats = {

View file

@ -10,7 +10,8 @@
emissive = 0x101010, emissive = 0x101010,
metalness = 0, metalness = 0,
roughness = 0.3, roughness = 0.3,
newMat = createPhongMaterial; newMat = createPhongMaterial,
freeMem = true;
let stacks = {}, let stacks = {},
tallest = 0, tallest = 0,
@ -230,6 +231,9 @@
ctrl.group.appendAll(mat); ctrl.group.appendAll(mat);
} }
} }
if (freeMem) {
render.init();
}
}; };
function createLineMaterial(color, array) { function createLineMaterial(color, array) {

View file

@ -76,7 +76,7 @@ KIRI.worker = {
delete cache[data.id]; delete cache[data.id];
send.data({error: error}); send.data({error: error});
} else { } else {
let slices = widget.slices || []; const slices = widget.slices || [];
send.data({send_start: time()}); send.data({send_start: time()});
send.data({ send.data({
topo: settings.synth.sendTopo ? widget.topo : null, topo: settings.synth.sendTopo ? widget.topo : null,
@ -84,7 +84,8 @@ KIRI.worker = {
slices: slices.length slices: slices.length
}); });
slices.forEach(function(slice,index) { slices.forEach(function(slice,index) {
send.data({index: index, slice: slice.encode(state)}); const state = { zeros: [] };
send.data({index: index, slice: slice.encode(state)}, state.zeros);
}) })
send.data({send_end: time()}); send.data({send_end: time()});
} }
@ -125,12 +126,15 @@ KIRI.worker = {
const print = current.print || {}; const print = current.print || {};
const maxSpeed = print.maxSpeed || undefined; const maxSpeed = print.maxSpeed || undefined;
const state = { zeros: [] };
send.data({ progress: 1, message: "transfer" });
send.done({ send.done({
done: true, done: true,
output: KIRI.codec.encode(layers), output: KIRI.codec.encode(layers, state),
maxSpeed maxSpeed
}); }, state.zeros);
}, },
export: function(data, send) { export: function(data, send) {
@ -238,20 +242,32 @@ self.onmessage = function(e) {
run = dispatch[msg.task], run = dispatch[msg.task],
send = { send = {
data : function(data,direct) { data : function(data,direct) {
// if (direct && direct.length) {
// console.log({
// zeros: direct.length,
// sz:direct.map(z => z.byteLength).reduce((a,v) => a+v)
// });
// }
self.postMessage({ self.postMessage({
seq: msg.seq, seq: msg.seq,
task: msg.task, task: msg.task,
done: false, done: false,
data: data data: data
},direct); }, direct);
}, },
done : function(data,direct) { done : function(data,direct) {
// if (direct && direct.length) {
// console.log({
// zeros: direct.length,
// sz:direct.map(z => z.byteLength).reduce((a,v) => a+v)
// });
// }
self.postMessage({ self.postMessage({
seq: msg.seq, seq: msg.seq,
task: msg.task, task: msg.task,
done: true, done: true,
data: data data: data
},direct); }, direct);
} }
}; };

View file

@ -29,12 +29,12 @@
let point; let point;
widgets.forEach((widget, index) => { widgets.forEach((widget, index) => {
point = prepEach(widget, settings, print, point, progress => { point = prepEach(widget, settings, print, point, progress => {
update((index * weight + progress * weight) * 0.5); update((index * weight + progress * weight) * 0.5, "prepare");
}); });
}); });
print.render = KIRI.driver.FDM.prepareRender(print.output, progress => { print.render = KIRI.driver.FDM.prepareRender(print.output, progress => {
update(0.5 + progress * 0.5); update(0.5 + progress * 0.5, "render");
}, { }, {
thin: true, thin: true,
print: 0, print: 0,

View file

@ -367,7 +367,7 @@
// notify progress // notify progress
layerout.layer = layer++; layerout.layer = layer++;
update((layer / maxLayers) * 0.5); update((layer / maxLayers) * 0.5, "prepare");
// retract after last layer // retract after last layer
if (layer === maxLayers && layerout.length) { if (layer === maxLayers && layerout.length) {
@ -381,7 +381,7 @@
print.output = output; print.output = output;
print.render = FDM.prepareRender(output, progress => { print.render = FDM.prepareRender(output, progress => {
update(0.5 + progress * 0.5); update(0.5 + progress * 0.5, "render");
}, { tools: device.extruders, thin: isThin, flat: isFlat, fdm: true }); }, { tools: device.extruders, thin: isThin, flat: isFlat, fdm: true });
return print.render; return print.render;
}; };