Gpu cleanup
This commit is contained in:
+554
-870
File diff suppressed because it is too large
Load Diff
@@ -6,45 +6,6 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
struct vk_depth {
|
||||
VkImage image;
|
||||
VkImageView view;
|
||||
VkDeviceMemory memory;
|
||||
};
|
||||
|
||||
struct vk_window {
|
||||
int width;
|
||||
int height;
|
||||
bool resized;
|
||||
bool surface_destroyed;
|
||||
int depth_bits;
|
||||
bool vsynced;
|
||||
uint32_t current_image;
|
||||
VkSurfaceKHR surface;
|
||||
VkSurfaceFormatKHR format;
|
||||
VkSwapchainKHR swapchain;
|
||||
uint32_t image_count;
|
||||
VkImage *images;
|
||||
VkImageView *views;
|
||||
struct vk_depth depth;
|
||||
};
|
||||
|
||||
struct vk_context {
|
||||
VkInstance instance;
|
||||
VkPhysicalDevice gpu;
|
||||
VkDevice device;
|
||||
VkPhysicalDeviceMemoryProperties memory_properties;
|
||||
VkCommandBuffer setup_cmd;
|
||||
VkCommandPool cmd_pool;
|
||||
VkQueue queue;
|
||||
struct vk_window windows[1];
|
||||
VkBuffer *uniform_buffer;
|
||||
#ifdef VALIDATE
|
||||
bool validation_found;
|
||||
VkDebugUtilsMessengerEXT debug_messenger;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct gpu_pipeline_impl {
|
||||
const char **textures;
|
||||
int *textureValues;
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
draw_font_t *draw_font = NULL;
|
||||
int draw_font_size;
|
||||
gpu_texture_t *_draw_current = NULL;
|
||||
bool _draw_in_use = false;
|
||||
|
||||
static iron_matrix4x4_t draw_projection_matrix;
|
||||
static iron_matrix3x3_t draw_transform;
|
||||
static bool draw_bilinear_filter = true;
|
||||
static uint32_t draw_color = 0;
|
||||
static gpu_pipeline_t *draw_custom_pipeline = NULL;
|
||||
static bool _draw_thrown = false;
|
||||
|
||||
static gpu_buffer_t rect_vertex_buffer;
|
||||
static gpu_buffer_t rect_index_buffer;
|
||||
@@ -215,14 +213,7 @@ void draw_init(buffer_t *image_vert, buffer_t *image_frag, buffer_t *rect_vert,
|
||||
}
|
||||
|
||||
void draw_begin(gpu_texture_t *target, bool clear, unsigned color) {
|
||||
if (_draw_in_use && !_draw_thrown) {
|
||||
_draw_thrown = true;
|
||||
iron_log("End before you begin");
|
||||
}
|
||||
_draw_in_use = true;
|
||||
|
||||
draw_set_color(0xffffffff);
|
||||
|
||||
_draw_current = target;
|
||||
if (target == NULL) {
|
||||
gpu_begin(NULL, 0, clear ? GPU_CLEAR_COLOR : GPU_CLEAR_NONE, color, 0.0);
|
||||
@@ -234,11 +225,6 @@ void draw_begin(gpu_texture_t *target, bool clear, unsigned color) {
|
||||
}
|
||||
|
||||
void draw_end(void) {
|
||||
if (!_draw_in_use && !_draw_thrown) {
|
||||
_draw_thrown = true;
|
||||
iron_log("Begin before you end");
|
||||
}
|
||||
_draw_in_use = false;
|
||||
gpu_end();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,4 +63,4 @@ void draw_cubic_bezier(f32_array_t *x, f32_array_t *y, int segments, float stren
|
||||
extern int draw_font_size;
|
||||
extern draw_font_t *draw_font;
|
||||
extern gpu_texture_t *_draw_current;
|
||||
extern bool _draw_in_use;
|
||||
extern bool gpu_in_use;
|
||||
|
||||
@@ -591,6 +591,7 @@ function base_render() {
|
||||
let h: f32 = img.height * ratio;
|
||||
let inv: i32 = 0;
|
||||
|
||||
draw_begin();
|
||||
draw_set_color(base_drag_tint);
|
||||
|
||||
let bg_rect: rect_t = base_get_drag_background();
|
||||
@@ -602,6 +603,7 @@ function base_render() {
|
||||
draw_scaled_image(img, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2) :
|
||||
draw_scaled_sub_image(img, base_drag_rect.x, base_drag_rect.y, base_drag_rect.w, base_drag_rect.h, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2);
|
||||
draw_set_color(0xffffffff);
|
||||
draw_end();
|
||||
}
|
||||
|
||||
let using_menu: bool = ui_menu_show && mouse_y > ui_header_h;
|
||||
|
||||
@@ -210,12 +210,12 @@ function box_projects_recent_tab(ui: ui_t) {
|
||||
|
||||
if (ui_button(file, ui_align_t.LEFT) && file_exists(path)) {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
import_arm_run_project(path);
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
ui_box_hide();
|
||||
}
|
||||
if (ui.is_hovered) {
|
||||
|
||||
@@ -252,10 +252,10 @@ function config_apply() {
|
||||
context_raw.ddirty = 2;
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
render_path_base_apply_config();
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function config_get_super_sample_quality(f: f32): i32 {
|
||||
|
||||
@@ -6,6 +6,7 @@ let console_last_traces: string[] = [""];
|
||||
let console_progress_text: string = null;
|
||||
|
||||
function console_draw_toast(s: string) {
|
||||
draw_begin();
|
||||
draw_set_color(0x55000000);
|
||||
draw_filled_rect(0, 0, iron_window_width(), iron_window_height());
|
||||
let scale: f32 = ui_SCALE(base_get_uis()[0]);
|
||||
@@ -15,6 +16,7 @@ function console_draw_toast(s: string) {
|
||||
draw_set_font(base_font, math_floor(22 * scale));
|
||||
draw_set_color(0xffffffff);
|
||||
draw_string(s, x - draw_string_width(draw_font, draw_font_size, s) / 2, y + 40 * scale - draw_font_height(draw_font, draw_font_size) / 2);
|
||||
draw_end();
|
||||
}
|
||||
|
||||
function _console_toast_render(s: string) {
|
||||
|
||||
@@ -546,14 +546,14 @@ function context_set_layer(l: slot_layer_t) {
|
||||
ui_header_handle.redraws = 2;
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
layers_set_object_mask();
|
||||
make_material_parse_mesh_material();
|
||||
make_material_parse_paint_material();
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
|
||||
ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
|
||||
ui_view2d_hwnd.redraws = 2;
|
||||
|
||||
@@ -31,12 +31,12 @@ function import_blend_material_run(path: string) {
|
||||
function _import_blend_material() {
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
console_toast(tr("Baking material"));
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
|
||||
sys_notify_on_init(function () {
|
||||
|
||||
|
||||
@@ -508,9 +508,7 @@ function sys_render() {
|
||||
|
||||
function sys_render_2d() {
|
||||
if (_sys_on_renders_2d.length > 0) {
|
||||
draw_begin();
|
||||
_sys_run_callbacks(_sys_on_renders_2d);
|
||||
draw_end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -401,8 +401,8 @@ function layers_update_fill_layers() {
|
||||
|
||||
function layers_update_fill_layer(parse_paint: bool = true) {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
let _tool: workspace_tool_t = context_raw.tool;
|
||||
let _fill_type: i32 = context_raw.fill_type_handle.position;
|
||||
@@ -421,7 +421,7 @@ function layers_update_fill_layer(parse_paint: bool = true) {
|
||||
context_raw.rdirty = 2;
|
||||
context_raw.tool = _tool;
|
||||
context_raw.fill_type_handle.position = _fill_type;
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function layers_set_object_mask() {
|
||||
|
||||
@@ -46,12 +46,12 @@ function project_open() {
|
||||
}
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
import_arm_run_project(path);
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -227,8 +227,8 @@ function project_new(reset_layers: bool = true) {
|
||||
let md: mesh_data_t = data_get_mesh("Scene", n);
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
///if is_paint
|
||||
context_raw.picker_mask_handle.position = picker_mask_t.NONE;
|
||||
@@ -316,7 +316,7 @@ function project_new(reset_layers: bool = true) {
|
||||
sys_notify_on_init(layers_init);
|
||||
}
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
|
||||
context_raw.saved_envmap = null;
|
||||
context_raw.envmap_loaded = false;
|
||||
|
||||
@@ -1154,7 +1154,6 @@ function ui_base_update_ui() {
|
||||
function ui_base_render() {
|
||||
if (!ui_base_show && config_raw.touch_ui) {
|
||||
ui_base_ui.input_enabled = true;
|
||||
draw_end();
|
||||
ui_begin(ui_base_ui);
|
||||
if (ui_window(ui_handle(__ID__), 0, 0, 150, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) {
|
||||
if (ui_button(tr("Close"))) {
|
||||
@@ -1162,7 +1161,6 @@ function ui_base_render() {
|
||||
}
|
||||
}
|
||||
ui_end();
|
||||
draw_begin(null);
|
||||
}
|
||||
|
||||
if (!ui_base_show || iron_window_width() == 0 || iron_window_height() == 0) {
|
||||
@@ -1184,7 +1182,6 @@ function ui_base_render() {
|
||||
ui_base_htabs[i].position = config_raw.layout_tabs[i];
|
||||
}
|
||||
|
||||
draw_end();
|
||||
ui_begin(ui_base_ui);
|
||||
|
||||
///if (is_paint || is_sculpt)
|
||||
@@ -1199,7 +1196,6 @@ function ui_base_render() {
|
||||
///end
|
||||
|
||||
ui_end();
|
||||
draw_begin(null);
|
||||
}
|
||||
|
||||
function ui_base_draw_sidebar() {
|
||||
@@ -1284,6 +1280,7 @@ function ui_base_render_cursor() {
|
||||
return;
|
||||
}
|
||||
|
||||
draw_begin();
|
||||
draw_set_color(0xffffffff);
|
||||
|
||||
context_raw.view_index = context_raw.view_index_last;
|
||||
@@ -1427,6 +1424,7 @@ function ui_base_render_cursor() {
|
||||
draw_scaled_image(cursor_img, mx - radius / 2, my - radius / 2, radius, radius);
|
||||
draw_set_color(0xffffffff);
|
||||
}
|
||||
draw_end();
|
||||
}
|
||||
|
||||
function ui_base_show_material_nodes() {
|
||||
|
||||
@@ -45,16 +45,16 @@ function ui_box_render() {
|
||||
}
|
||||
|
||||
if (config_raw.touch_ui) { // Darken bg
|
||||
draw_begin();
|
||||
///if (arm_android || arm_ios)
|
||||
draw_set_color(color_from_floats(0, 0, 0, ui_box_tween_alpha));
|
||||
///else
|
||||
draw_set_color(color_from_floats(0, 0, 0, 0.5));
|
||||
///end
|
||||
draw_filled_rect(0, 0, iron_window_width(), iron_window_height());
|
||||
draw_end();
|
||||
}
|
||||
|
||||
draw_end();
|
||||
|
||||
let ui: ui_t = base_ui_box;
|
||||
let appw: i32 = iron_window_width();
|
||||
let apph: i32 = iron_window_height();
|
||||
@@ -123,8 +123,6 @@ function ui_box_render() {
|
||||
ui_end();
|
||||
}
|
||||
|
||||
draw_begin(null);
|
||||
|
||||
ui_box_draws++;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ function ui_menu_render() {
|
||||
ui_menu_y -= iron_window_height() * 2;
|
||||
}
|
||||
|
||||
draw_begin();
|
||||
ui_begin_region(ui, ui_menu_x, ui_menu_y, menu_w);
|
||||
ui_menu_start(ui);
|
||||
|
||||
@@ -568,6 +569,7 @@ function ui_menu_render() {
|
||||
ui.ops.theme.ELEMENT_H = _ELEMENT_H;
|
||||
ui_menu_end(ui);
|
||||
ui_end_region();
|
||||
draw_end();
|
||||
|
||||
if (ui_menu_show_first) {
|
||||
ui_menu_show_first = false;
|
||||
|
||||
@@ -867,8 +867,6 @@ function ui_nodes_render() {
|
||||
|
||||
ui_nodes_ui.input_enabled = base_ui_enabled;
|
||||
|
||||
draw_end();
|
||||
|
||||
if (ui_nodes_grid_redraw) {
|
||||
if (ui_nodes_grid != null) {
|
||||
iron_unload_image(ui_nodes_grid);
|
||||
@@ -1252,8 +1250,6 @@ function ui_nodes_render() {
|
||||
|
||||
ui_end(!ui_nodes_show_menu);
|
||||
|
||||
draw_begin(null);
|
||||
|
||||
if (ui_nodes_show_menu) {
|
||||
///if (is_paint || is_sculpt)
|
||||
let list: node_list_t[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list;
|
||||
@@ -1278,6 +1274,7 @@ function ui_nodes_render() {
|
||||
|
||||
let py: i32 = ui_nodes_popup_y;
|
||||
let menuw: i32 = math_floor(ew * 2.3);
|
||||
draw_begin(null);
|
||||
ui_begin_region(ui_nodes_ui, math_floor(ui_nodes_popup_x), math_floor(py), menuw);
|
||||
let _FILL_BUTTON_BG: i32 = ui_nodes_ui.ops.theme.FILL_BUTTON_BG;
|
||||
ui_nodes_ui.ops.theme.FILL_BUTTON_BG = false;
|
||||
@@ -1349,6 +1346,7 @@ function ui_nodes_render() {
|
||||
ui_nodes_ui.ops.theme.ELEMENT_H = _ELEMENT_H;
|
||||
ui_menu_end(ui_nodes_ui);
|
||||
ui_end_region();
|
||||
draw_end();
|
||||
}
|
||||
|
||||
if (ui_nodes_hide_menu) {
|
||||
|
||||
@@ -92,8 +92,6 @@ function ui_view2d_render() {
|
||||
ui_view2d_hwnd.redraws = 2; // Paint was active
|
||||
}
|
||||
|
||||
draw_end();
|
||||
|
||||
// Cache grid
|
||||
if (ui_view2d_grid_redraw) {
|
||||
if (ui_view2d_grid != null) {
|
||||
@@ -181,17 +179,17 @@ function ui_view2d_render() {
|
||||
|
||||
if (ui_view2d_layer_mode == view_2d_layer_mode_t.VISIBLE) {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
layer = layers_flatten();
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
else if (slot_layer_is_group(layer)) {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
layer = layers_flatten(false, slot_layer_get_children(layer));
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
tex =
|
||||
@@ -421,7 +419,6 @@ function ui_view2d_render() {
|
||||
///end
|
||||
}
|
||||
ui_end();
|
||||
draw_begin(null);
|
||||
}
|
||||
|
||||
function ui_view2d_update() {
|
||||
|
||||
@@ -80,8 +80,8 @@ function util_render_make_material_preview() {
|
||||
|
||||
function util_render_make_decal_preview() {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
if (context_raw.decal_image == null) {
|
||||
context_raw.decal_image = gpu_create_render_target(util_render_decal_preview_size, util_render_decal_preview_size);
|
||||
@@ -139,13 +139,13 @@ function util_render_make_decal_preview() {
|
||||
make_material_parse_mesh_material();
|
||||
context_raw.ddirty = 1; // Refresh depth for decal paint
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function util_render_make_text_preview() {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
let text: string = context_raw.text_tool_text;
|
||||
let font: draw_font_t = context_raw.font.font;
|
||||
@@ -173,13 +173,13 @@ function util_render_make_text_preview() {
|
||||
draw_string(text, tex_w / 2 - text_w / 2, tex_w / 2 - text_h / 2);
|
||||
draw_end();
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function util_render_make_font_preview() {
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
let text: string = "Abg";
|
||||
let font: draw_font_t = context_raw.font.font;
|
||||
@@ -197,7 +197,7 @@ function util_render_make_font_preview() {
|
||||
draw_end();
|
||||
context_raw.font.preview_ready = true;
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function util_render_make_brush_preview() {
|
||||
@@ -206,8 +206,8 @@ function util_render_make_brush_preview() {
|
||||
}
|
||||
|
||||
let current: gpu_texture_t = _draw_current;
|
||||
let g2_in_use: bool = _draw_in_use;
|
||||
if (g2_in_use) draw_end();
|
||||
let in_use: bool = gpu_in_use;
|
||||
if (in_use) draw_end();
|
||||
|
||||
context_raw.material_preview = true;
|
||||
|
||||
@@ -382,7 +382,7 @@ function util_render_make_brush_preview() {
|
||||
context_raw.brush.preview_ready = true;
|
||||
context_raw.brush_blend_dirty = true;
|
||||
|
||||
if (g2_in_use) draw_begin(current);
|
||||
if (in_use) draw_begin(current);
|
||||
}
|
||||
|
||||
function util_render_make_node_preview(canvas: ui_node_canvas_t, node: ui_node_t, image: gpu_texture_t, group: ui_node_canvas_t = null, parents: ui_node_t[] = null) {
|
||||
|
||||
Reference in New Issue
Block a user