diff --git a/armorlab/sources/render_path_paint.ts b/armorlab/sources/render_path_paint.ts index fe9bc9df..e5d2e3b2 100644 --- a/armorlab/sources/render_path_paint.ts +++ b/armorlab/sources/render_path_paint.ts @@ -198,20 +198,19 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 gpu_set_float3(pipes_cursor_camera_right, right.x, right.y, right.z); gpu_set_float3(pipes_cursor_tint, tint_r, tint_g, tint_b); gpu_set_matrix4(pipes_cursor_vp, scene_camera.vp); - let help_mat: mat4_t = mat4_identity(); - help_mat = mat4_inv(scene_camera.vp); - gpu_set_matrix4(pipes_cursor_inv_vp, help_mat); - ///if (arm_metal || arm_vulkan) - let vs: vertex_element_t[] = [ - { - name: "tex", - data: "short2norm" - } - ]; - gpu_set_vertex_buffer(mesh_data_get(geom, vs)); - ///else + let inv_vp: mat4_t = mat4_inv(scene_camera.vp); + gpu_set_matrix4(pipes_cursor_inv_vp, inv_vp); + ////if (arm_metal || arm_vulkan) + // let vs: vertex_element_t[] = [ + // { + // name: "tex", + // data: "short2norm" + // } + // ]; + // gpu_set_vertex_buffer(mesh_data_get(geom, vs)); + ////else gpu_set_vertex_buffer(geom._.vertex_buffer); - ///end + ////end gpu_set_index_buffer(geom._.index_buffers[0]); gpu_draw_indexed_vertices(); diff --git a/armorpaint/shaders/layer_invert.kong b/armorpaint/shaders/layer_invert.kong index e4670fb4..65bff574 100644 --- a/armorpaint/shaders/layer_invert.kong +++ b/armorpaint/shaders/layer_invert.kong @@ -2,6 +2,9 @@ #[set(everything)] const constants: { P: float4x4; + pos: float4; // xywh + tex: float4; // xywh + col: float4; }; #[set(everything)] @@ -11,9 +14,7 @@ const tex: tex2d; const sampler_linear: sampler; struct vert_in { - pos: float3; - tex: float2; - col: float4; + pos: float2; } struct vert_out { @@ -24,9 +25,12 @@ struct vert_out { fun layer_invert_vert(input: vert_in): vert_out { var output: vert_out; - output.pos = constants.P * float4(input.pos, 1.0); - output.tex = input.tex; - output.col = input.col; + output.pos = float4(input.pos, 0.0, 1.0); + output.pos.xy = output.pos.xy * constants.pos.zw + constants.pos.xy; + output.pos.xy = output.pos.xy * 2.0 - 1.0; + output.pos.y = -output.pos.y; + output.tex = input.pos * constants.tex.zw + constants.tex.xy; + output.col = constants.col; return output; } diff --git a/armorpaint/shaders/layer_view.kong b/armorpaint/shaders/layer_view.kong index 24a65f1e..3d7f5ae0 100644 --- a/armorpaint/shaders/layer_view.kong +++ b/armorpaint/shaders/layer_view.kong @@ -2,6 +2,9 @@ #[set(everything)] const constants: { P: float4x4; + pos: float4; // xywh + tex: float4; // xywh + col: float4; channel: int; }; @@ -12,9 +15,7 @@ const tex: tex2d; const sampler_linear: sampler; struct vert_in { - pos: float3; - tex: float2; - col: float4; + pos: float2; } struct vert_out { @@ -25,9 +26,12 @@ struct vert_out { fun layer_view_vert(input: vert_in): vert_out { var output: vert_out; - output.pos = constants.P * float4(input.pos, 1.0); - output.tex = input.tex; - output.col = input.col; + output.pos = float4(input.pos, 0.0, 1.0); + output.pos.xy = output.pos.xy * constants.pos.zw + constants.pos.xy; + output.pos.xy = output.pos.xy * 2.0 - 1.0; + output.pos.y = -output.pos.y; + output.tex = input.pos * constants.tex.zw + constants.tex.xy; + output.col = constants.col; return output; } diff --git a/armorpaint/sources/render_path_paint.ts b/armorpaint/sources/render_path_paint.ts index 0e2b84d1..03cbb249 100644 --- a/armorpaint/sources/render_path_paint.ts +++ b/armorpaint/sources/render_path_paint.ts @@ -450,20 +450,19 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 gpu_set_float3(pipes_cursor_camera_right, right.x, right.y, right.z); gpu_set_float3(pipes_cursor_tint, tint_r, tint_g, tint_b); gpu_set_matrix4(pipes_cursor_vp, scene_camera.vp); - let help_mat: mat4_t = mat4_identity(); - help_mat = mat4_inv(scene_camera.vp); - gpu_set_matrix4(pipes_cursor_inv_vp, help_mat); - ///if (arm_metal || arm_vulkan) - let vs: vertex_element_t[] = [ - { - name: "tex", - data: "short2norm" - } - ]; - gpu_set_vertex_buffer(mesh_data_get(geom, vs)); - ///else + let inv_vp: mat4_t = mat4_inv(scene_camera.vp); + gpu_set_matrix4(pipes_cursor_inv_vp, inv_vp); + ////if (arm_metal || arm_vulkan) + // let vs: vertex_element_t[] = [ + // { + // name: "tex", + // data: "short2norm" + // } + // ]; + // gpu_set_vertex_buffer(mesh_data_get(geom, vs)); + ////else gpu_set_vertex_buffer(geom._.vertex_buffer); - ///end + ////end gpu_set_index_buffer(geom._.index_buffers[0]); gpu_draw_indexed_vertices(); diff --git a/base/shaders/layer_copy.kong b/base/shaders/layer_copy.kong index 14f1069b..ee87e236 100644 --- a/base/shaders/layer_copy.kong +++ b/base/shaders/layer_copy.kong @@ -2,6 +2,9 @@ #[set(everything)] const constants: { P: float4x4; + pos: float4; // xywh + tex: float4; // xywh + col: float4; }; #[set(everything)] @@ -11,9 +14,7 @@ const tex: tex2d; const sampler_linear: sampler; struct vert_in { - pos: float3; - tex: float2; - col: float4; + pos: float2; } struct vert_out { @@ -24,9 +25,12 @@ struct vert_out { fun layer_copy_vert(input: vert_in): vert_out { var output: vert_out; - output.pos = constants.P * float4(input.pos, 1.0); - output.tex = input.tex; - output.col = input.col; + output.pos = float4(input.pos, 0.0, 1.0); + output.pos.xy = output.pos.xy * constants.pos.zw + constants.pos.xy; + output.pos.xy = output.pos.xy * 2.0 - 1.0; + output.pos.y = -output.pos.y; + output.tex = input.pos * constants.tex.zw + constants.tex.xy; + output.col = constants.col; return output; } diff --git a/base/shaders/layer_copy_bgra.kong b/base/shaders/layer_copy_bgra.kong index 97217eb0..e2c5feae 100644 --- a/base/shaders/layer_copy_bgra.kong +++ b/base/shaders/layer_copy_bgra.kong @@ -2,6 +2,9 @@ #[set(everything)] const constants: { P: float4x4; + pos: float4; // xywh + tex: float4; // xywh + col: float4; }; #[set(everything)] @@ -11,9 +14,7 @@ const tex: tex2d; const sampler_linear: sampler; struct vert_in { - pos: float3; - tex: float2; - col: float4; + pos: float2; } struct vert_out { @@ -24,9 +25,12 @@ struct vert_out { fun layer_copy_bgra_vert(input: vert_in): vert_out { var output: vert_out; - output.pos = constants.P * float4(input.pos, 1.0); - output.tex = input.tex; - output.col = input.col; + output.pos = float4(input.pos, 0.0, 1.0); + output.pos.xy = output.pos.xy * constants.pos.zw + constants.pos.xy; + output.pos.xy = output.pos.xy * 2.0 - 1.0; + output.pos.y = -output.pos.y; + output.tex = input.pos * constants.tex.zw + constants.tex.xy; + output.col = constants.col; return output; } diff --git a/base/sources/iron_gpu.c b/base/sources/iron_gpu.c index 228b7cda..d313482c 100644 --- a/base/sources/iron_gpu.c +++ b/base/sources/iron_gpu.c @@ -7,9 +7,9 @@ #include "iron_file.h" #define CONSTANT_BUFFER_SIZE 256 +// #define CONSTANT_BUFFER_MULTIPLE 1024 #define CONSTANT_BUFFER_MULTIPLE 10240 #define FRAMEBUFFER_COUNT 2 -#define MAX_TEXTURES 16 iron_gpu_command_list_t commandList; static iron_gpu_buffer_t vertexConstantBuffer; @@ -35,9 +35,19 @@ void gpu_internal_init_window(int depthBufferBits, bool vsync) { void iron_gpu_draw_indexed_vertices(void) { iron_gpu_constant_buffer_unlock(&vertexConstantBuffer); - iron_gpu_command_list_set_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * CONSTANT_BUFFER_SIZE, CONSTANT_BUFFER_SIZE);\ + iron_gpu_command_list_set_constant_buffer(&commandList, &vertexConstantBuffer, constantBufferIndex * CONSTANT_BUFFER_SIZE, CONSTANT_BUFFER_SIZE); iron_gpu_command_list_draw_indexed_vertices(&commandList); ++constantBufferIndex; + + // Flush + if (constantBufferIndex == CONSTANT_BUFFER_MULTIPLE) { + iron_gpu_command_list_end(&commandList); + iron_gpu_command_list_execute(&commandList); + iron_gpu_command_list_wait_for_execution_to_finish(&commandList); + iron_gpu_command_list_begin(&commandList); + constantBufferIndex = 0; + } + iron_gpu_constant_buffer_lock(&vertexConstantBuffer, constantBufferIndex * CONSTANT_BUFFER_SIZE, CONSTANT_BUFFER_SIZE); } @@ -57,7 +67,6 @@ void iron_gpu_clear(unsigned color, float depth, unsigned flags) { void gpu_begin() { constantBufferIndex = 0; iron_gpu_constant_buffer_lock(&vertexConstantBuffer, constantBufferIndex, CONSTANT_BUFFER_SIZE); - window_currentBuffer = (window_currentBuffer + 1) % FRAMEBUFFER_COUNT; // if (window_resized) { diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 661b2540..0a8b8f5b 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -1018,13 +1018,11 @@ function _ui_image(image: iron_gpu_texture_t, tint: i32 = 0xffffffff, h: f32 = - } function ui_window(handle: ui_handle_t, x: i32, y: i32, w: i32, h: i32, drag: bool = false): bool { - _draw_current = ADDRESS(handle.texture); _draw_in_use = true; return _ui_window(handle, x, y, w, h, drag); } function ui_end(last: bool = true) { - _draw_current = null; _draw_in_use = false; _ui_end(last); } diff --git a/base/sources/ts/pipes.ts b/base/sources/ts/pipes.ts index 53245563..bbd015fa 100644 --- a/base/sources/ts/pipes.ts +++ b/base/sources/ts/pipes.ts @@ -92,9 +92,7 @@ function pipes_init() { pipes_copy.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy.input_layout = vs; gpu_compile_pipeline(pipes_copy); } @@ -104,9 +102,7 @@ function pipes_init() { pipes_copy_bgra.vertex_shader = sys_get_shader("layer_copy_bgra.vert"); pipes_copy_bgra.fragment_shader = sys_get_shader("layer_copy_bgra.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy_bgra.input_layout = vs; gpu_compile_pipeline(pipes_copy_bgra); } @@ -116,9 +112,7 @@ function pipes_init() { pipes_copy8.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy8.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy8.input_layout = vs; pipes_copy8.color_attachment_count = 1; ARRAY_ACCESS(pipes_copy8.color_attachment, 0) = tex_format_t.R8; @@ -130,9 +124,7 @@ function pipes_init() { pipes_copy128.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy128.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy128.input_layout = vs; pipes_copy128.color_attachment_count = 1; ARRAY_ACCESS(pipes_copy128.color_attachment, 0) = tex_format_t.RGBA128; @@ -145,9 +137,7 @@ function pipes_init() { pipes_invert8.vertex_shader = sys_get_shader("layer_invert.vert"); pipes_invert8.fragment_shader = sys_get_shader("layer_invert.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_invert8.input_layout = vs; pipes_invert8.color_attachment_count = 1; ARRAY_ACCESS(pipes_invert8.color_attachment, 0) = tex_format_t.R8; @@ -206,9 +196,7 @@ function pipes_init() { pipes_copy_r.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy_r.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy_r.input_layout = vs; ARRAY_ACCESS(pipes_copy_r.color_write_mask_green, 0) = false; ARRAY_ACCESS(pipes_copy_r.color_write_mask_blue, 0) = false; @@ -221,9 +209,7 @@ function pipes_init() { pipes_copy_g.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy_g.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy_g.input_layout = vs; ARRAY_ACCESS(pipes_copy_g.color_write_mask_red, 0) = false; ARRAY_ACCESS(pipes_copy_g.color_write_mask_blue, 0) = false; @@ -266,9 +252,7 @@ function pipes_init() { pipes_copy_rgb.vertex_shader = sys_get_shader("layer_copy.vert"); pipes_copy_rgb.fragment_shader = sys_get_shader("layer_copy.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); pipes_copy_rgb.input_layout = vs; ARRAY_ACCESS(pipes_copy_rgb.color_write_mask_alpha, 0) = false; gpu_compile_pipeline(pipes_copy_rgb); diff --git a/base/sources/ts/render_path_preview.ts b/base/sources/ts/render_path_preview.ts index 8f8fbdc7..34a21f8b 100644 --- a/base/sources/ts/render_path_preview.ts +++ b/base/sources/ts/render_path_preview.ts @@ -116,7 +116,7 @@ function render_path_preview_commands_decal() { render_path_draw_meshes("mesh"); // Deferred light - render_path_set_target("tex"); + render_path_set_target("buf"); render_path_bind_target("_main", "gbufferD"); render_path_bind_target("gbuffer0", "gbuffer0"); render_path_bind_target("gbuffer1", "gbuffer1"); @@ -125,12 +125,12 @@ function render_path_preview_commands_decal() { } render_path_draw_shader("shader_datas/deferred_light/deferred_light"); - render_path_set_depth_from("tex", "gbuffer0"); // Bind depth for world pass + render_path_set_depth_from("buf", "gbuffer0"); // Bind depth for world pass - render_path_set_target("tex"); + render_path_set_target("buf"); render_path_draw_skydome("shader_datas/world_pass/world_pass"); - render_path_set_depth_from("tex", "gbuffer1"); // Unbind depth + render_path_set_depth_from("buf", "gbuffer1"); // Unbind depth let framebuffer: string = "texpreview"; let texpreview: render_target_t = map_get(render_path_render_targets, "texpreview"); @@ -138,6 +138,6 @@ function render_path_preview_commands_decal() { render_path_set_target(framebuffer); - render_path_bind_target("tex", "tex"); + render_path_bind_target("buf", "tex"); render_path_draw_shader("shader_datas/compositor_pass/compositor_pass"); } diff --git a/base/sources/ts/ui_view2d.ts b/base/sources/ts/ui_view2d.ts index 80d20754..bba6a8f0 100644 --- a/base/sources/ts/ui_view2d.ts +++ b/base/sources/ts/ui_view2d.ts @@ -36,15 +36,17 @@ function ui_view2d_init() { ui_view2d_pipe.vertex_shader = sys_get_shader("layer_view.vert"); ui_view2d_pipe.fragment_shader = sys_get_shader("layer_view.frag"); let vs: iron_gpu_vertex_structure_t = gpu_vertex_struct_create(); - gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - gpu_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - gpu_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + gpu_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); ui_view2d_pipe.input_layout = vs; ui_view2d_pipe.blend_source = blend_factor_t.BLEND_ONE; ui_view2d_pipe.blend_destination = blend_factor_t.BLEND_ZERO; ARRAY_ACCESS(ui_view2d_pipe.color_write_mask_alpha, 0) = false; gpu_compile_pipeline(ui_view2d_pipe); pipes_offset = 0; + pipes_get_constant_location(ui_view2d_pipe, "P", "mat4"); + pipes_get_constant_location(ui_view2d_pipe, "pos", "float4"); + pipes_get_constant_location(ui_view2d_pipe, "tex", "float4"); + pipes_get_constant_location(ui_view2d_pipe, "col", "float4"); ui_view2d_channel_loc = pipes_get_constant_location(ui_view2d_pipe, "channel", "int"); ///end @@ -193,14 +195,14 @@ function ui_view2d_render() { } tex = - slot_layer_is_mask(context_raw.layer) ? layer.texpaint : - ui_view2d_tex_type == paint_tex_t.BASE ? layer.texpaint : - ui_view2d_tex_type == paint_tex_t.OPACITY ? layer.texpaint : - ui_view2d_tex_type == paint_tex_t.NORMAL ? layer.texpaint_nor : - layer.texpaint_pack; + slot_layer_is_mask(context_raw.layer) ? layer.texpaint : + ui_view2d_tex_type == paint_tex_t.BASE ? layer.texpaint : + ui_view2d_tex_type == paint_tex_t.OPACITY ? layer.texpaint : + ui_view2d_tex_type == paint_tex_t.NORMAL ? layer.texpaint_nor : + layer.texpaint_pack; channel = - slot_layer_is_mask(context_raw.layer) ? 1 : + slot_layer_is_mask(context_raw.layer) ? 1 : ui_view2d_tex_type == paint_tex_t.OCCLUSION ? 1 : ui_view2d_tex_type == paint_tex_t.ROUGHNESS ? 2 : ui_view2d_tex_type == paint_tex_t.METALLIC ? 3 :