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
# lathe?
# complex process order
# double-sided assistance
# fdm
# redo automatic supports using faces instead of deltas
# 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 support for tapered ball mills
* `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` detect render message backlog and pause or warn

View file

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

View file

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

View file

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

View file

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

View file

@ -76,7 +76,7 @@ KIRI.worker = {
delete cache[data.id];
send.data({error: error});
} else {
let slices = widget.slices || [];
const slices = widget.slices || [];
send.data({send_start: time()});
send.data({
topo: settings.synth.sendTopo ? widget.topo : null,
@ -84,7 +84,8 @@ KIRI.worker = {
slices: slices.length
});
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()});
}
@ -125,12 +126,15 @@ KIRI.worker = {
const print = current.print || {};
const maxSpeed = print.maxSpeed || undefined;
const state = { zeros: [] };
send.data({ progress: 1, message: "transfer" });
send.done({
done: true,
output: KIRI.codec.encode(layers),
output: KIRI.codec.encode(layers, state),
maxSpeed
});
}, state.zeros);
},
export: function(data, send) {
@ -238,20 +242,32 @@ self.onmessage = function(e) {
run = dispatch[msg.task],
send = {
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({
seq: msg.seq,
task: msg.task,
done: false,
data: data
},direct);
}, 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({
seq: msg.seq,
task: msg.task,
done: true,
data: data
},direct);
}, direct);
}
};

View file

@ -29,12 +29,12 @@
let point;
widgets.forEach((widget, index) => {
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 => {
update(0.5 + progress * 0.5);
update(0.5 + progress * 0.5, "render");
}, {
thin: true,
print: 0,

View file

@ -367,7 +367,7 @@
// notify progress
layerout.layer = layer++;
update((layer / maxLayers) * 0.5);
update((layer / maxLayers) * 0.5, "prepare");
// retract after last layer
if (layer === maxLayers && layerout.length) {
@ -381,7 +381,7 @@
print.output = output;
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 });
return print.render;
};