Improve scheduling

This commit is contained in:
luboslenco
2020-10-28 12:25:01 +01:00
parent d05b285fcd
commit 4fbd35fcb7
5 changed files with 95 additions and 54 deletions
+33 -9
View File
@@ -66,23 +66,39 @@ class Layers {
var C = Config.raw;
if (App.resHandle.position >= Std.int(Res16384)) { // Save memory for >=16k
C.undo_steps = 1;
if (Context.undoHandle != null) Context.undoHandle.value = C.undo_steps;
while (History.undoLayers.length > C.undo_steps) { var l = History.undoLayers.pop(); l.unload(); }
if (Context.undoHandle != null) {
Context.undoHandle.value = C.undo_steps;
}
while (History.undoLayers.length > C.undo_steps) {
var l = History.undoLayers.pop();
App.notifyOnNextFrame(function() {
l.unload();
});
}
}
for (l in Project.layers) l.resizeAndSetBits();
for (l in History.undoLayers) l.resizeAndSetBits();
var rts = RenderPath.active.renderTargets;
rts.get("texpaint_blend0").image.unload();
var _texpaint_blend0 = rts.get("texpaint_blend0").image;
App.notifyOnNextFrame(function() {
_texpaint_blend0.unload();
});
rts.get("texpaint_blend0").raw.width = Config.getTextureResX();
rts.get("texpaint_blend0").raw.height = Config.getTextureResY();
rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8);
rts.get("texpaint_blend1").image.unload();
var _texpaint_blend1 = rts.get("texpaint_blend1").image;
App.notifyOnNextFrame(function() {
_texpaint_blend1.unload();
});
rts.get("texpaint_blend1").raw.width = Config.getTextureResX();
rts.get("texpaint_blend1").raw.height = Config.getTextureResY();
rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8);
Context.brushBlendDirty = true;
if (rts.get("texpaint_blur") != null) {
rts.get("texpaint_blur").image.unload();
var _texpaint_blur = rts.get("texpaint_blur").image;
App.notifyOnNextFrame(function() {
_texpaint_blur.unload();
});
var sizeX = Std.int(Config.getTextureResX() * 0.95);
var sizeY = Std.int(Config.getTextureResY() * 0.95);
rts.get("texpaint_blur").raw.width = sizeX;
@@ -233,7 +249,10 @@ class Layers {
public static function makeTempImg() {
var l = Project.layers[0];
if (imga != null && (imga.width != l.texpaint.width || imga.height != l.texpaint.height)) {
RenderPath.active.renderTargets.get("temptex0").unload();
var _temptex0 = RenderPath.active.renderTargets.get("temptex0");
App.notifyOnNextFrame(function() {
_temptex0.unload();
});
RenderPath.active.renderTargets.remove("temptex0");
imga = null;
}
@@ -253,9 +272,14 @@ class Layers {
public static function makeExportImg() {
var l = Project.layers[0];
if (expa != null && (expa.width != l.texpaint.width || expa.height != l.texpaint.height)) {
expa.unload();
expb.unload();
expc.unload();
var _expa = expa;
var _expb = expb;
var _expc = expc;
App.notifyOnNextFrame(function() {
_expa.unload();
_expb.unload();
_expc.unload();
});
expa = null;
expb = null;
expc = null;
+35 -25
View File
@@ -113,11 +113,15 @@ class LayerSlot {
public function unload() {
if (texpaint == null) return; // Layer is group
var _texpaint = texpaint;
var _texpaint_nor = texpaint_nor;
var _texpaint_pack = texpaint_pack;
var _texpaint_preview = texpaint_preview;
function _next() {
texpaint.unload();
texpaint_nor.unload();
texpaint_pack.unload();
texpaint_preview.unload();
_texpaint.unload();
_texpaint_nor.unload();
_texpaint_pack.unload();
_texpaint_preview.unload();
}
App.notifyOnNextFrame(_next);
@@ -223,7 +227,11 @@ class LayerSlot {
inverted.g2.drawImage(texpaint_mask, 0, 0);
inverted.g2.pipeline = null;
inverted.g2.end();
texpaint_mask.unload();
var _texpaint_mask = texpaint_mask;
function _next() {
_texpaint_mask.unload();
}
App.notifyOnNextFrame(_next);
texpaint_mask = RenderPath.active.renderTargets.get("texpaint_mask" + id).image = inverted;
Context.layerPreviewDirty = true;
Context.ddirty = 3;
@@ -232,11 +240,11 @@ class LayerSlot {
public function deleteMask() {
if (texpaint_mask == null) return;
var _mask = texpaint_mask;
var _preview = texpaint_mask_preview;
var _texpaint_mask = texpaint_mask;
var _texpaint_mask_preview = texpaint_mask_preview;
function _next() {
_mask.unload();
_preview.unload();
_texpaint_mask.unload();
_texpaint_mask_preview.unload();
}
App.notifyOnNextFrame(_next);
@@ -347,9 +355,9 @@ class LayerSlot {
var resY = Config.getTextureResY();
var rts = RenderPath.active.renderTargets;
var texpaint = this.texpaint;
var texpaint_nor = this.texpaint_nor;
var texpaint_pack = this.texpaint_pack;
var _texpaint = this.texpaint;
var _texpaint_nor = this.texpaint_nor;
var _texpaint_pack = this.texpaint_pack;
this.texpaint = Image.createRenderTarget(resX, resY, format);
this.texpaint_nor = Image.createRenderTarget(resX, resY, format);
@@ -359,45 +367,47 @@ class LayerSlot {
this.texpaint.g2.begin(false);
this.texpaint.g2.pipeline = Layers.pipeCopy;
this.texpaint.g2.drawScaledImage(texpaint, 0, 0, resX, resY);
this.texpaint.g2.drawScaledImage(_texpaint, 0, 0, resX, resY);
this.texpaint.g2.pipeline = null;
this.texpaint.g2.end();
this.texpaint_nor.g2.begin(false);
this.texpaint_nor.g2.pipeline = Layers.pipeCopy;
this.texpaint_nor.g2.drawScaledImage(texpaint_nor, 0, 0, resX, resY);
this.texpaint_nor.g2.drawScaledImage(_texpaint_nor, 0, 0, resX, resY);
this.texpaint_nor.g2.pipeline = null;
this.texpaint_nor.g2.end();
this.texpaint_pack.g2.begin(false);
this.texpaint_pack.g2.pipeline = Layers.pipeCopy;
this.texpaint_pack.g2.drawScaledImage(texpaint_pack, 0, 0, resX, resY);
this.texpaint_pack.g2.drawScaledImage(_texpaint_pack, 0, 0, resX, resY);
this.texpaint_pack.g2.pipeline = null;
this.texpaint_pack.g2.end();
iron.App.notifyOnInit(function() { // Out of command list execution
texpaint.unload();
texpaint_nor.unload();
texpaint_pack.unload();
});
function _next() { // Out of command list execution
_texpaint.unload();
_texpaint_nor.unload();
_texpaint_pack.unload();
}
App.notifyOnNextFrame(_next);
rts.get("texpaint" + this.ext).image = this.texpaint;
rts.get("texpaint_nor" + this.ext).image = this.texpaint_nor;
rts.get("texpaint_pack" + this.ext).image = this.texpaint_pack;
if (this.texpaint_mask != null && (this.texpaint_mask.width != resX || this.texpaint_mask.height != resY)) {
var texpaint_mask = this.texpaint_mask;
var _texpaint_mask = this.texpaint_mask;
this.texpaint_mask = Image.createRenderTarget(resX, resY, TextureFormat.L8);
this.texpaint_mask.g2.begin(false);
this.texpaint_mask.g2.pipeline = Layers.pipeCopy8;
this.texpaint_mask.g2.drawScaledImage(texpaint_mask, 0, 0, resX, resY);
this.texpaint_mask.g2.drawScaledImage(_texpaint_mask, 0, 0, resX, resY);
this.texpaint_mask.g2.pipeline = null;
this.texpaint_mask.g2.end();
iron.App.notifyOnInit(function() { // Out of command list execution
texpaint_mask.unload();
});
function _next() { // Out of command list execution
_texpaint_mask.unload();
}
App.notifyOnNextFrame(_next);
rts.get("texpaint_mask" + this.ext).image = this.texpaint_mask;
}
+24 -17
View File
@@ -188,21 +188,26 @@ class ImportArm {
var tex = Project.layers[0].texpaint;
if (tex.width != Config.getTextureResX() || tex.height != Config.getTextureResY()) {
for (l in Project.layers) l.resizeAndSetBits();
if (History.undoLayers != null) for (l in History.undoLayers) l.resizeAndSetBits();
var rts = RenderPath.active.renderTargets;
rts.get("texpaint_blend0").image.unload();
var _texpaint_blend0 = rts.get("texpaint_blend0").image;
App.notifyOnNextFrame(function() {
_texpaint_blend0.unload();
});
rts.get("texpaint_blend0").raw.width = Config.getTextureResX();
rts.get("texpaint_blend0").raw.height = Config.getTextureResY();
rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil);
rts.get("texpaint_blend1").image.unload();
var _texpaint_blend1 = rts.get("texpaint_blend1").image;
App.notifyOnNextFrame(function() {
_texpaint_blend1.unload();
});
rts.get("texpaint_blend1").raw.width = Config.getTextureResX();
rts.get("texpaint_blend1").raw.height = Config.getTextureResY();
rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil);
Context.brushBlendDirty = true;
}
// for (l in Project.layers) l.unload();
for (l in Project.layers) l.unload();
Project.layers = [];
for (i in 0...project.layer_datas.length) {
var ld = project.layer_datas[i];
@@ -216,34 +221,34 @@ class ImportArm {
if (Layers.pipeMerge == null) Layers.makePipe();
// TODO: create render target from bytes
var texpaint = Image.fromBytes(Lz4.decode(ld.texpaint, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
var _texpaint = Image.fromBytes(Lz4.decode(ld.texpaint, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint.g2.begin(false);
l.texpaint.g2.pipeline = project.is_bgra ? Layers.pipeCopyBGRA : Layers.pipeCopy;
l.texpaint.g2.drawImage(texpaint, 0, 0);
l.texpaint.g2.drawImage(_texpaint, 0, 0);
l.texpaint.g2.pipeline = null;
l.texpaint.g2.end();
var texpaint_nor = Image.fromBytes(Lz4.decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
var _texpaint_nor = Image.fromBytes(Lz4.decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint_nor.g2.begin(false);
l.texpaint_nor.g2.pipeline = project.is_bgra ? Layers.pipeCopyBGRA : Layers.pipeCopy;
l.texpaint_nor.g2.drawImage(texpaint_nor, 0, 0);
l.texpaint_nor.g2.drawImage(_texpaint_nor, 0, 0);
l.texpaint_nor.g2.pipeline = null;
l.texpaint_nor.g2.end();
var texpaint_pack = Image.fromBytes(Lz4.decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
var _texpaint_pack = Image.fromBytes(Lz4.decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint_pack.g2.begin(false);
l.texpaint_pack.g2.pipeline = project.is_bgra ? Layers.pipeCopyBGRA : Layers.pipeCopy;
l.texpaint_pack.g2.drawImage(texpaint_pack, 0, 0);
l.texpaint_pack.g2.drawImage(_texpaint_pack, 0, 0);
l.texpaint_pack.g2.pipeline = null;
l.texpaint_pack.g2.end();
var texpaint_mask: kha.Image = null;
var _texpaint_mask: kha.Image = null;
if (ld.texpaint_mask != null) {
l.createMask(0, false);
texpaint_mask = Image.fromBytes(Lz4.decode(ld.texpaint_mask, ld.res * ld.res), ld.res, ld.res, TextureFormat.L8);
_texpaint_mask = Image.fromBytes(Lz4.decode(ld.texpaint_mask, ld.res * ld.res), ld.res, ld.res, TextureFormat.L8);
l.texpaint_mask.g2.begin(false);
l.texpaint_mask.g2.pipeline = Layers.pipeCopy8;
l.texpaint_mask.g2.drawImage(texpaint_mask, 0, 0);
l.texpaint_mask.g2.drawImage(_texpaint_mask, 0, 0);
l.texpaint_mask.g2.pipeline = null;
l.texpaint_mask.g2.end();
}
@@ -264,10 +269,12 @@ class ImportArm {
l.paintEmis = ld.paint_emis;
l.paintSubs = ld.paint_subs;
// texpaint.unload();
// texpaint_nor.unload();
// texpaint_pack.unload();
// if (texpaint_mask != null) texpaint_mask.unload();
App.notifyOnNextFrame(function() {
_texpaint.unload();
_texpaint_nor.unload();
_texpaint_pack.unload();
if (_texpaint_mask != null) _texpaint_mask.unload();
});
}
}
+2 -2
View File
@@ -19,7 +19,7 @@ class ImportTexture {
// Set envmap
if (path.toLowerCase().endsWith(".hdr")) {
Data.getImage(path, function(image: kha.Image) {
iron.App.notifyOnInit(function() { // Make sure file browser process did finish
App.notifyOnNextFrame(function() { // Make sure file browser process did finish
ImportEnvmap.run(path, image);
});
});
@@ -46,7 +46,7 @@ class ImportTexture {
// Set envmap
if (path.toLowerCase().endsWith(".hdr")) {
iron.App.notifyOnInit(function() { // Make sure file browser process did finish
App.notifyOnNextFrame(function() { // Make sure file browser process did finish
ImportEnvmap.run(path, image);
});
}
+1 -1
View File
@@ -117,7 +117,7 @@ class TabTextures {
Project.assetMap.set(asset.id, image);
// Set envmap
if (asset.file.toLowerCase().endsWith(".hdr")) {
iron.App.notifyOnInit(function() { // Make sure file browser process did finish
App.notifyOnNextFrame(function() { // Make sure file browser process did finish
arm.io.ImportEnvmap.run(asset.file, image);
});
}