Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Oct 19, 2024
1 parent 1c9f731 commit 0a5671a
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion armorlab/sources/nodes/brush_output_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type brush_output_node_t = {

let brush_output_node_inst: brush_output_node_t = null;

function brush_output_node_create(arg: any): brush_output_node_t {
function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_output_node_t {
let n: brush_output_node_t = {};
n.base = logic_node_create();

Expand Down
2 changes: 1 addition & 1 deletion armorlab/sources/nodes/image_texture_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type image_texture_node_t = {
color_space?: string;
};

function image_texture_node_create(arg: any): image_texture_node_t {
function image_texture_node_create(raw: ui_node_t, args: f32_array_t): image_texture_node_t {
let n: image_texture_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = image_texture_node_get_as_image;
Expand Down
14 changes: 9 additions & 5 deletions armorlab/sources/nodes/inpaint_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let inpaint_node_prompt: string = "";
let inpaint_node_strength: f32 = 0.5;
let inpaint_node_auto: bool = true;

function inpaint_node_create(arg: any): inpaint_node_t {
function inpaint_node_create(raw: ui_node_t, args: f32_array_t): inpaint_node_t {
let n: inpaint_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = inpaint_node_get_as_image;
Expand Down Expand Up @@ -115,7 +115,7 @@ function inpaint_node_texsynth_inpaint(image: image_t, tiling: bool, mask: image
let bytes_img: buffer_t = image_get_pixels(image);
let bytes_mask: buffer_t = mask != null ? image_get_pixels(mask) : buffer_create(w * h);
let bytes_out: buffer_t = buffer_create(w * h * 4);
iron_texsynth.inpaint(w, h, bytes_out, bytes_img, bytes_mask, tiling);
// texsynth_inpaint(w, h, bytes_out, bytes_img, bytes_mask, tiling);

inpaint_node_result = image_from_bytes(bytes_out, w, h);
return inpaint_node_result;
Expand Down Expand Up @@ -163,13 +163,17 @@ function inpaint_node_sd_inpaint(image: image_t, mask: image_t): image_t {
f32a[i + 512 * 512 * 2] = (u8a[i * 4 + 2] / 255.0) * 2.0 - 1.0;
}

let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], config_raw.gpu_inference);
let tensors: buffer_t[] = [f32a.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [1, 3, 512, 512];
array_push(input_shape, input_shape0);
let output_shape: i32[] = [1, 4, 64, 64];
let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let latents: f32_array_t = f32_array_create_from_buffer(latents_buf);
for (let i: i32 = 0; i < latents.length; ++i) {
latents[i] = 0.18215 * latents[i];
}
// let latents_orig: f32_array_t = array_slice(latents, 0, latents.length);
let latents_orig: f32_array_t = latents.slice(0, latents.length);
let latents_orig: f32_array_t = array_slice(latents, 0, latents.length);

let noise: f32_array_t = f32_array_create(latents.length);
for (let i: i32 = 0; i < noise.length; ++i) {
Expand Down
5 changes: 3 additions & 2 deletions armorlab/sources/nodes/photo_to_pbr_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let photo_to_pbr_node_border_w: i32 = 64;
let photo_to_pbr_node_tile_w: i32 = 2048;
let photo_to_pbr_node_tile_with_border_w: i32 = photo_to_pbr_node_tile_w + photo_to_pbr_node_border_w * 2;

function photo_to_pbr_node_create(arg: any): photo_to_pbr_node_t {
function photo_to_pbr_node_create(raw: ui_node_t, args: f32_array_t): photo_to_pbr_node_t {
let n: photo_to_pbr_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = photo_to_pbr_node_get_as_image;
Expand Down Expand Up @@ -78,7 +78,8 @@ function photo_to_pbr_node_get_as_image(self: photo_to_pbr_node_t, from: i32): i
}

let model_blob: buffer_t = data_get_blob("models/photo_to_" + photo_to_pbr_node_model_names[from] + ".quant.onnx");
let buf: buffer_t = iron_ml_inference(model_blob, [f32a.buffer], null, null, config_raw.gpu_inference);
let tensors: buffer_t[] = [f32a.buffer];
let buf: buffer_t = iron_ml_inference(model_blob, tensors, null, null, config_raw.gpu_inference);
let ar: f32_array_t = f32_array_create_from_buffer(buf);
u8a = u8_array_create(4 * photo_to_pbr_node_tile_w * photo_to_pbr_node_tile_w);
let offset_g: i32 = (from == channel_type_t.BASE_COLOR || from == channel_type_t.NORMAL_MAP) ? photo_to_pbr_node_tile_with_border_w * photo_to_pbr_node_tile_with_border_w : 0;
Expand Down
6 changes: 4 additions & 2 deletions armorlab/sources/nodes/rgb_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
type rgb_node_t = {
base?: logic_node_t;
image?: image_t;
raw?: ui_node_t;
};

function rgb_node_create(arg: any): rgb_node_t {
function rgb_node_create(raw: ui_node_t, args: f32_array_t): rgb_node_t {
let n: rgb_node_t = {};
n.raw = raw;
n.base = logic_node_create();
n.base.get_as_image = rgb_node_get_as_image;
n.base.get_cached_image = rgb_node_get_cached_image;
Expand All @@ -20,7 +22,7 @@ function rgb_node_get_as_image(self: rgb_node_t, from: i32): image_t {
}

let f32a: f32_array_t = f32_array_create(4);
let raw: ui_node_t = parser_logic_get_raw_node(self.base);
let raw: ui_node_t = self.raw;
let default_value: f32_array_t = raw.outputs[0].default_value;
f32a[0] = default_value[0];
f32a[1] = default_value[1];
Expand Down
34 changes: 28 additions & 6 deletions armorlab/sources/nodes/text_to_photo_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let text_to_photo_node_text_encoder_blob: buffer_t;
let text_to_photo_node_unet_blob: buffer_t;
let text_to_photo_node_vae_decoder_blob: buffer_t;

function text_to_photo_node_create(arg: any): text_to_photo_node_t {
function text_to_photo_node_create(raw: ui_node_t, args: f32_array_t): text_to_photo_node_t {
let n: text_to_photo_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = text_to_photo_node_get_as_image;
Expand Down Expand Up @@ -65,11 +65,17 @@ function text_to_photo_node_text_encoder(prompt: string, inpaint_latents: f32_ar
}

let i32a: i32_array_t = i32_array_create_from_array(text_to_photo_node_text_input_ids);
let text_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], config_raw.gpu_inference);
let tensors: buffer_t[] = [i32a.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [1, 77];
array_push(input_shape, input_shape0);
let output_shape: i32[] = [1, 77, 768];
let text_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let text_embeddings: f32_array_t = f32_array_create_from_buffer(text_embeddings_buf);

i32a = i32_array_create_from_array(text_to_photo_node_uncond_input_ids);
let uncond_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], config_raw.gpu_inference);
tensors = [i32a.buffer];
let uncond_embeddings_buf: buffer_t = iron_ml_inference(text_to_photo_node_text_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let uncond_embeddings: f32_array_t = f32_array_create_from_buffer(uncond_embeddings_buf);

let f32a: f32_array_t = f32_array_create(uncond_embeddings.length + text_embeddings.length);
Expand Down Expand Up @@ -106,7 +112,9 @@ function text_to_photo_node_unet(latents: f32_array_t, text_embeddings: f32_arra
let counter: i32 = 0;

while (true) {
console_progress(tr("Processing") + " - " + tr("Text to Photo") + " (" + (counter + 1) + "/" + (50 - offset) + ")");
let a: i32 = counter + 1;
let b: i32 = 50 - offset;
console_progress(tr("Processing") + " - " + tr("Text to Photo") + " (" + a + "/" + b + ")");
iron_g4_swap_buffers();

let timestep: i32 = text_to_photo_node_timesteps[counter + offset];
Expand All @@ -115,7 +123,16 @@ function text_to_photo_node_unet(latents: f32_array_t, text_embeddings: f32_arra

let t32: i32_array_t = i32_array_create(2);
t32[0] = timestep;
let noise_pred_buf: buffer_t = iron_ml_inference(text_to_photo_node_unet_blob, [latent_model_input.buffer, t32.buffer, text_embeddings.buffer], [[2, 4, 64, 64], [1], [2, 77, 768]], [2, 4, 64, 64], config_raw.gpu_inference);
let tensors: buffer_t[] = [latent_model_input.buffer, t32.buffer, text_embeddings.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [2, 4, 64, 64];
let input_shape1: i32[] = [1];
let input_shape2: i32[] = [2, 77, 768];
array_push(input_shape, input_shape0);
array_push(input_shape, input_shape1);
array_push(input_shape, input_shape2);
let output_shape: i32[] = [2, 4, 64, 64];
let noise_pred_buf: buffer_t = iron_ml_inference(text_to_photo_node_unet_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let noise_pred: f32_array_t = f32_array_create_from_buffer(noise_pred_buf);

for (let i: i32 = 0; i < noise_pred_uncond.length; ++i) noise_pred_uncond[i] = noise_pred[i];
Expand Down Expand Up @@ -216,7 +233,12 @@ function text_to_photo_node_vae_decoder(latents: f32_array_t, upscale: bool): im
latents[i] = 1.0 / 0.18215 * latents[i];
}

let pyimage_buf: buffer_t = iron_ml_inference(text_to_photo_node_vae_decoder_blob, [latents.buffer], [[1, 4, 64, 64]], [1, 3, 512, 512], config_raw.gpu_inference);
let tensors: buffer_t[] = [latents.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [1, 4, 64, 64];
array_push(input_shape, input_shape0);
let output_shape: i32[] = [1, 3, 512, 512];
let pyimage_buf: buffer_t = iron_ml_inference(text_to_photo_node_vae_decoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let pyimage: f32_array_t = f32_array_create_from_buffer(pyimage_buf);

for (let i: i32 = 0; i < pyimage.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion armorlab/sources/nodes/tiling_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let tiling_node_prompt: string = "";
let tiling_node_strength: f32 = 0.5;
let tiling_node_auto: bool = true;

function tiling_node_create(arg: any): tiling_node_t {
function tiling_node_create(raw: ui_node_t, args: f32_array_t): tiling_node_t {
let n: float_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = tiling_node_get_as_image;
Expand Down
9 changes: 7 additions & 2 deletions armorlab/sources/nodes/upscale_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let upscale_node_temp: image_t = null;
let upscale_node_image: image_t = null;
let upscale_node_esrgan_blob: buffer_t;

function upscale_node_create(arg: any): upscale_node_t {
function upscale_node_create(raw: ui_node_t, args: f32_array_t): upscale_node_t {
let n: float_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = upscale_node_get_as_image;
Expand Down Expand Up @@ -64,7 +64,12 @@ function upscale_node_do_tile(source: image_t): image_t {
f32a[i + size1w * size1w * 2] = (u8a[i * 4 + 2] / 255);
}

let esrgan2x_buf: buffer_t = iron_ml_inference(upscale_node_esrgan_blob, [f32a.buffer], [[1, 3, size1w, size1h]], [1, 3, size2w, size2h], config_raw.gpu_inference);
let tensors: buffer_t[] = [f32a.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [1, 3, size1w, size1h];
array_push(input_shape, input_shape0);
let output_shape: i32[] = [1, 3, size2w, size2h];
let esrgan2x_buf: buffer_t = iron_ml_inference(upscale_node_esrgan_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let esrgan2x: f32_array_t = f32_array_create_from_buffer(esrgan2x_buf);
for (let i: i32 = 0; i < esrgan2x.length; ++i) {
if (esrgan2x[i] < 0) {
Expand Down
16 changes: 11 additions & 5 deletions armorlab/sources/nodes/variance_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let variance_node_image: image_t = null;
let variance_node_inst: variance_node_t = null;
let variance_node_prompt: string = "";

function variance_node_create(arg: any): variance_node_t {
function variance_node_create(raw: ui_node_t, args: f32_array_t): variance_node_t {
let n: variance_node_t = {};
n.base = logic_node_create();
n.base.get_as_image = variance_node_get_as_image;
Expand All @@ -32,7 +32,8 @@ function variance_node_buttons(ui: ui_t, nodes: ui_nodes_t, node: ui_node_t) {
}

function variance_node_get_as_image(self: variance_node_t, from: i32): image_t {
let strength: f32 = variance_node_inst.base.inputs[1].node.value;
let node: float_node_t = variance_node_inst.base.inputs[1].node;
let strength: f32 = node.value;

let source: image_t = logic_node_input_get_as_image(variance_node_inst.base.inputs[0]);
g2_begin(variance_node_temp);
Expand All @@ -41,7 +42,7 @@ function variance_node_get_as_image(self: variance_node_t, from: i32): image_t {

let bytes_img: buffer_t = image_get_pixels(variance_node_temp);
let u8a: u8_array_t = bytes_img;
let f32a = f32_array_create(3 * 512 * 512);
let f32a: f32_array_t = f32_array_create(3 * 512 * 512);
for (let i: i32 = 0; i < (512 * 512); ++i) {
f32a[i ] = (u8a[i * 4 ] / 255) * 2.0 - 1.0;
f32a[i + 512 * 512 ] = (u8a[i * 4 + 1] / 255) * 2.0 - 1.0;
Expand All @@ -52,7 +53,12 @@ function variance_node_get_as_image(self: variance_node_t, from: i32): image_t {
iron_g4_swap_buffers();

let vae_encoder_blob: buffer_t = data_get_blob("models/sd_vae_encoder.quant.onnx");
let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], config_raw.gpu_inference);
let tensors: buffer_t[] = [f32a.buffer];
let input_shape: i32_array_t[] = [];
let input_shape0: i32[] = [1, 3, 512, 512];
array_push(input_shape, input_shape0);
let output_shape: i32[] = [1, 4, 64, 64];
let latents_buf: buffer_t = iron_ml_inference(vae_encoder_blob, tensors, input_shape, output_shape, config_raw.gpu_inference);
let latents: f32_array_t = f32_array_create_from_buffer(latents_buf);
for (let i: i32 = 0; i < latents.length; ++i) {
latents[i] = 0.18215 * latents[i];
Expand All @@ -65,7 +71,7 @@ function variance_node_get_as_image(self: variance_node_t, from: i32): image_t {
let num_inference_steps: i32 = 50;
let init_timestep: i32 = math_floor(num_inference_steps * strength);
let timesteps: i32 = text_to_photo_node_timesteps[num_inference_steps - init_timestep];
let alphas_cumprod: f32 = text_to_photo_node_alphas_cumprod;
let alphas_cumprod: f32[] = text_to_photo_node_alphas_cumprod;
let sqrt_alpha_prod: f32 = math_pow(alphas_cumprod[timesteps], 0.5);
let sqrt_one_minus_alpha_prod: f32 = math_pow(1.0 - alphas_cumprod[timesteps], 0.5);
for (let i: i32 = 0; i < latents.length; ++i) {
Expand Down
6 changes: 4 additions & 2 deletions armorlab/sources/ui_nodes_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ function ui_nodes_ext_draw_buttons(ew: f32, start_y: f32) {
g4_draw();
g4_end();

if (ui_header_worktab.position == space_type_t.SPACE3D &&
brush_output_node_inst.base.inputs[channel_type_t.HEIGHT].node.get != float_node_get) {
let is_float_node: bool = true;
// brush_output_node_inst.base.inputs[channel_type_t.HEIGHT].node.get != float_node_get

if (ui_header_worktab.position == space_type_t.SPACE3D && !is_float_node) {

// Make copy of vertices before displacement
let o: mesh_object_t = project_paint_objects[0];
Expand Down

0 comments on commit 0a5671a

Please sign in to comment.