From d0076fa2ad67a7e7e9c4fd4698156ccf687640d7 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 1 Mar 2025 06:56:08 +0100 Subject: [PATCH] fix release build --- asset/AssetArchive.h | 18 +++++++-- asset/AssetManagementSystem.h | 14 +++---- audio/Audio.cpp | 3 ++ audio/Qoa.h | 2 +- command/AppCmdBuffer.cpp | 22 +++++++++-- entity/AnimationEntityComponent.h | 4 +- font/Font.h | 4 +- gpuapi/direct3d/ShaderUtils.h | 6 +++ gpuapi/opengl/AppCmdBuffer.h | 6 +-- gpuapi/opengl/OpenglWin32.h | 3 ++ gpuapi/opengl/ShaderUtils.h | 22 +++++++---- gpuapi/opengl/UIOpengl.h | 61 ------------------------------ gpuapi/vulkan/ShaderUtils.h | 7 ++++ image/Bitmap.h | 15 +++----- image/Image.cpp | 3 ++ image/Png.h | 4 +- image/Qoi.h | 1 + log/PerformanceProfiler.h | 13 ++++--- memory/BufferMemory.h | 2 +- memory/ChunkMemory.h | 20 ++++++---- memory/RingMemory.h | 3 +- object/Mesh.h | 7 +++- platform/win32/LeanWin32.h | 2 +- platform/win32/audio/DirectSound.h | 16 ++++---- platform/win32/audio/Wasapi.h | 22 ++++++----- platform/win32/audio/XAudio2.h | 14 ++++--- stdlib/HashMap.h | 25 ++++++------ stdlib/PerfectHashMap.h | 30 ++++++--------- stdlib/Types.h | 2 +- thread/Thread.h | 4 +- thread/ThreadPool.h | 4 +- ui/UILayout.cpp | 25 ++++++++---- ui/UITheme.h | 12 ++++-- 33 files changed, 204 insertions(+), 192 deletions(-) delete mode 100644 gpuapi/opengl/UIOpengl.h diff --git a/asset/AssetArchive.h b/asset/AssetArchive.h index 9909f42..56a74f7 100644 --- a/asset/AssetArchive.h +++ b/asset/AssetArchive.h @@ -106,7 +106,7 @@ void asset_archive_header_load(AssetArchiveHeader* __restrict header, const byte SWAP_ENDIAN_LITTLE_SIMD( (int32 *) header->asset_element, (int32 *) header->asset_element, - header->asset_count * sizeof(AssetArchiveElement) / 4, // everything is 4 bytes -> super easy to swap + header->asset_count * sizeof(AssetArchiveElement) / 4, // everything is 4 bytes -> easy to swap steps ); @@ -118,7 +118,7 @@ void asset_archive_header_load(AssetArchiveHeader* __restrict header, const byte SWAP_ENDIAN_LITTLE_SIMD( (int32 *) header->asset_dependencies, (int32 *) header->asset_dependencies, - header->asset_count * header->asset_dependency_count, // everything is 4 bytes -> super easy to swap + header->asset_count * header->asset_dependency_count, // everything is 4 bytes -> easy to swap steps ); } @@ -133,6 +133,11 @@ void asset_archive_load(AssetArchive* archive, const char* path, BufferMemory* b { PROFILE_VERBOSE(PROFILE_ASSET_ARCHIVE_LOAD, path); + LOG_FORMAT_1( + "Load AssetArchive %s", + {{LOG_DATA_CHAR_STR, (void *) path}} + ); + archive->fd = file_read_handle(path); if (!archive->fd) { return; @@ -169,7 +174,7 @@ void asset_archive_load(AssetArchive* archive, const char* path, BufferMemory* b file_read(archive->fd, &file, 0, file.size); asset_archive_header_load(&archive->header, file.content, steps); - LOG_FORMAT_2( + LOG_FORMAT_1( "Loaded AssetArchive %s with %d assets", {{LOG_DATA_CHAR_STR, (void *) path}, {LOG_DATA_UINT32, (void *) &archive->header.asset_count}} ); @@ -199,6 +204,11 @@ Asset* asset_archive_asset_load(const AssetArchive* archive, int32 id, AssetMana byte component_id = archive->asset_type_map[element->type]; //AssetComponent* ac = &ams->asset_components[component_id]; + LOG_FORMAT_2( + "Load asset %d from archive %d for AMS %d with %n B compressed and %n B uncompressed", + {{LOG_DATA_UINT64, &id}, {LOG_DATA_UINT32, &element->type}, {LOG_DATA_BYTE, &component_id}, {LOG_DATA_UINT32, &element->length}, {LOG_DATA_UINT32, &element->uncompressed}} + ); + Asset* asset = thrd_ams_get_asset_wait(ams, id_str); if (asset) { @@ -305,7 +315,7 @@ Asset* asset_archive_asset_load(const AssetArchive* archive, int32 id, AssetMana thrd_ams_set_loaded(asset); LOG_FORMAT_2( - "Asset %d loaded from archive %d for AMS %d with %n B compressed and %n B uncompressed", + "Loaded asset %d from archive %d for AMS %d with %n B compressed and %n B uncompressed", {{LOG_DATA_UINT64, &id}, {LOG_DATA_UINT32, &element->type}, {LOG_DATA_BYTE, &component_id}, {LOG_DATA_UINT32, &element->length}, {LOG_DATA_UINT32, &element->uncompressed}} ); diff --git a/asset/AssetManagementSystem.h b/asset/AssetManagementSystem.h index 0cfc4bf..df159d4 100644 --- a/asset/AssetManagementSystem.h +++ b/asset/AssetManagementSystem.h @@ -42,28 +42,27 @@ struct AssetManagementSystem { inline void ams_create(AssetManagementSystem* ams, BufferMemory* buf, int32 asset_component_count, int32 count) { + LOG_FORMAT_1("Create AMS for %n assets", {{LOG_DATA_INT32, &count}}); hashmap_create(&ams->hash_map, count, sizeof(HashEntry) + sizeof(Asset), buf); ams->asset_component_count = asset_component_count; ams->asset_components = (AssetComponent *) buffer_get_memory(buf, asset_component_count * sizeof(AssetComponent), 64, true); - - LOG_FORMAT_2("Created AMS for %n assets", {{LOG_DATA_INT32, &count}}); } inline void ams_component_create(AssetComponent* ac, BufferMemory* buf, int32 chunk_size, int32 count) { ASSERT_SIMPLE(chunk_size); + LOG_FORMAT_1("Create AMS Component for %n assets and %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}}); chunk_init(&ac->asset_memory, buf, count, chunk_size, 64); pthread_mutex_init(&ac->mutex, NULL); - - LOG_FORMAT_2("Created AMS Component for %n assets and %n B = %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}, {LOG_DATA_UINT64, &ac->asset_memory.size}}); } inline void ams_component_create(AssetComponent* ac, byte* buf, int32 chunk_size, int32 count) { ASSERT_SIMPLE(chunk_size); + LOG_FORMAT_1("Create AMS Component for %n assets and %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}}); ac->asset_memory.count = count; ac->asset_memory.chunk_size = chunk_size; @@ -73,8 +72,6 @@ void ams_component_create(AssetComponent* ac, byte* buf, int32 chunk_size, int32 ac->asset_memory.free = (uint64 *) (ac->asset_memory.memory + ac->asset_memory.chunk_size * count); pthread_mutex_init(&ac->mutex, NULL); - - LOG_FORMAT_2("Created AMS Component for %n assets and %n B = %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}, {LOG_DATA_UINT64, &ac->asset_memory.size}}); } inline @@ -439,6 +436,7 @@ Asset* thrd_ams_reserve_asset(AssetManagementSystem* ams, byte type, const char* // @todo don't use uint64 for time, use uint32 and use relative time to start of program void thrd_ams_update(AssetManagementSystem* ams, uint64 time, uint64 dt) { + PROFILE(PROFILE_AMS_UPDATE); for (int32 i = 0; i < ams->asset_component_count; ++i) { ams->asset_components[i].vram_size = 0; ams->asset_components[i].ram_size = 0; @@ -447,7 +445,7 @@ void thrd_ams_update(AssetManagementSystem* ams, uint64 time, uint64 dt) // Iterate the hash map to find all assets uint32 chunk_id = 0; - chunk_iterate_start(&ams->hash_map.buf, chunk_id) + chunk_iterate_start(&ams->hash_map.buf, chunk_id) { HashEntry* entry = (HashEntry *) chunk_get_element(&ams->hash_map.buf, chunk_id); Asset* asset = (Asset *) entry->value; @@ -482,7 +480,7 @@ void thrd_ams_update(AssetManagementSystem* ams, uint64 time, uint64 dt) ams->asset_components[asset->component_id].vram_size -= asset->vram_size; } } - chunk_iterate_end; + } chunk_iterate_end; } Asset* ams_insert_asset(AssetManagementSystem* ams, Asset* asset_temp, const char* name) diff --git a/audio/Audio.cpp b/audio/Audio.cpp index 9e5e249..bc5ba1f 100644 --- a/audio/Audio.cpp +++ b/audio/Audio.cpp @@ -81,11 +81,14 @@ uint32 audio_header_to_data(const Audio* __restrict audio, byte* __restrict data uint32 audio_from_data(const byte* __restrict data, Audio* __restrict audio) { + LOG_3("Load audio"); data += audio_header_from_data(data, audio); memcpy(audio->data, data, audio->size); data += audio->size; + LOG_3("Loaded audio"); + return audio_data_size(audio); } diff --git a/audio/Qoa.h b/audio/Qoa.h index 9c95679..f874898 100644 --- a/audio/Qoa.h +++ b/audio/Qoa.h @@ -411,9 +411,9 @@ uint32 qoa_decode_frame(const byte* bytes, uint32 channels, QoaLms* lms, int16* return (uint32) (bytes - start); } - uint32 qoa_decode(const byte* data, Audio* audio) { + LOG_3("QOA decode audio"); uint32 header_length = audio_header_from_data(data, audio); uint32 p = header_length; uint32 frame_size; diff --git a/command/AppCmdBuffer.cpp b/command/AppCmdBuffer.cpp index 3a33568..98e67a6 100644 --- a/command/AppCmdBuffer.cpp +++ b/command/AppCmdBuffer.cpp @@ -40,7 +40,7 @@ void cmd_buffer_create(AppCmdBuffer* cb, BufferMemory* buf, int32 commands_count chunk_init(&cb->commands, buf, commands_count, sizeof(Command), 64); pthread_mutex_init(&cb->mutex, NULL); - LOG_FORMAT_2("Created AppCmdBuffer: %n B", {{LOG_DATA_UINT64, &cb->commands.size}}); + LOG_FORMAT_1("Created AppCmdBuffer: %n B", {{LOG_DATA_UINT64, &cb->commands.size}}); } // This doesn't load the asset directly but tells (most likely) a worker thread to load an asset @@ -356,9 +356,12 @@ inline void* cmd_func_run(AppCmdBuffer*, CommandFunction func) { } inline Asset* cmd_texture_load_sync(AppCmdBuffer* cb, int32 asset_id) { + LOG_FORMAT_1("Load texture %d", {{LOG_DATA_INT32, &asset_id}}); + // Check if asset already loaded char id_str[9]; int_to_hex(asset_id, id_str); + PROFILE_VERBOSE(PROFILE_CMD_ASSET_LOAD_SYNC, id_str); Asset* asset = thrd_ams_get_asset_wait(cb->ams, id_str); @@ -382,6 +385,9 @@ inline Asset* cmd_texture_load_sync(AppCmdBuffer* cb, int32 asset_id) { } inline Asset* cmd_texture_load_sync(AppCmdBuffer* cb, const char* name) { + LOG_FORMAT_1("Load texture %d", {{LOG_DATA_CHAR_STR, (void *) name}}); + PROFILE_VERBOSE(PROFILE_CMD_ASSET_LOAD_SYNC, name); + // Check if asset already loaded Asset* asset = thrd_ams_get_asset_wait(cb->ams, name); @@ -407,6 +413,8 @@ inline Asset* cmd_texture_load_sync(AppCmdBuffer* cb, const char* name) { inline Asset* cmd_font_load_sync(AppCmdBuffer* cb, int32 asset_id) { + LOG_FORMAT_1("Load font %d", {{LOG_DATA_INT32, &asset_id}}); + // Check if asset already loaded char id_str[9]; int_to_hex(asset_id, id_str); @@ -434,6 +442,7 @@ inline Asset* cmd_font_load_sync(AppCmdBuffer* cb, int32 asset_id) inline Asset* cmd_font_load_sync(AppCmdBuffer* cb, const char* name) { + LOG_FORMAT_1("Load font %s", {{LOG_DATA_CHAR_STR, (void *) name}}); PROFILE_VERBOSE(PROFILE_CMD_FONT_LOAD_SYNC, name); // Check if asset already loaded @@ -463,11 +472,13 @@ UILayout* cmd_layout_load_sync( UILayout* __restrict layout, const char* __restrict layout_path ) { PROFILE_VERBOSE(PROFILE_CMD_LAYOUT_LOAD_SYNC, layout_path); + LOG_FORMAT_1("Load layout %s", {{LOG_DATA_CHAR_STR, (void *) layout_path}}); + FileBody layout_file = {}; file_read(layout_path, &layout_file, cb->mem_vol); if (!layout_file.content) { - LOG_FORMAT_1("Failed loading layout \"%s\"\n", {{LOG_DATA_CHAR_STR, &layout_path}}); + LOG_FORMAT_1("Failed loading layout \"%s\"", {{LOG_DATA_CHAR_STR, (void *) layout_path}}); return NULL; } @@ -482,6 +493,7 @@ UIThemeStyle* cmd_theme_load_sync( UIThemeStyle* __restrict theme, const char* __restrict theme_path ) { PROFILE_VERBOSE(PROFILE_CMD_THEME_LOAD_SYNC, theme_path); + LOG_FORMAT_1("Load theme %s", {{LOG_DATA_CHAR_STR, (void *) theme_path}}); FileBody theme_file = {}; file_read(theme_path, &theme_file, cb->mem_vol); @@ -507,6 +519,8 @@ UILayout* cmd_ui_load_sync( const Camera* __restrict camera ) { PROFILE_VERBOSE(PROFILE_CMD_UI_LOAD_SYNC, layout_path); + LOG_FORMAT_1("Load ui with layout %s and theme %s", {{LOG_DATA_CHAR_STR, (void *) layout_path}, {LOG_DATA_CHAR_STR, (void *) theme_path}}); + if (!cmd_layout_load_sync(cb, layout, layout_path)) { // We have to make sure that at least the font is set layout->font = general_theme->font; @@ -606,7 +620,7 @@ void cmd_iterate(AppCmdBuffer* cb) PROFILE(PROFILE_CMD_ITERATE); int32 last_element = 0; uint32 chunk_id = 0; - chunk_iterate_start(&cb->commands, chunk_id) + chunk_iterate_start(&cb->commands, chunk_id) { Command* cmd = (Command *) chunk_get_element(&cb->commands, chunk_id); bool remove = true; @@ -671,7 +685,7 @@ void cmd_iterate(AppCmdBuffer* cb) if (chunk_id == (uint32) cb->last_element) { break; } - chunk_iterate_end; + } chunk_iterate_end; cb->last_element = last_element; } diff --git a/entity/AnimationEntityComponent.h b/entity/AnimationEntityComponent.h index 974fab8..484a5fc 100644 --- a/entity/AnimationEntityComponent.h +++ b/entity/AnimationEntityComponent.h @@ -56,14 +56,14 @@ void update_animation_entity(AnimationEntityComponent* anim, uint32 time, uint32 void update_animation_entities(ChunkMemory* anim_ec, uint32 time, uint32 delay) { uint32 chunk_id = 0; - chunk_iterate_start(anim_ec, chunk_id) + chunk_iterate_start(anim_ec, chunk_id) { AnimationEntityComponent* anim = (AnimationEntityComponent *) chunk_get_element(anim_ec, chunk_id); if (anim->setting & ANIMATION_SETTING_PAUSE) { continue; } update_animation_entity(anim, time, delay); - chunk_iterate_end; + } chunk_iterate_end; } #endif \ No newline at end of file diff --git a/font/Font.h b/font/Font.h index aa03dc5..1af9cac 100644 --- a/font/Font.h +++ b/font/Font.h @@ -204,7 +204,7 @@ int32 font_from_data( SWAP_ENDIAN_LITTLE_SIMD( (int32 *) font->glyphs, (int32 *) font->glyphs, - font->glyph_count * sizeof(Glyph) / 4, // everything in here is 4 bytes -> super easy to swap + font->glyph_count * sizeof(Glyph) / 4, // everything in here is 4 bytes -> easy to swap steps ); @@ -244,7 +244,7 @@ int32 font_to_data( SWAP_ENDIAN_LITTLE_SIMD( (int32 *) file.content, (int32 *) file.content, - size / 4, // everything in here is 4 bytes -> super easy to swap + size / 4, // everything in here is 4 bytes -> easy to swap steps ); diff --git a/gpuapi/direct3d/ShaderUtils.h b/gpuapi/direct3d/ShaderUtils.h index 39d4886..1357da9 100644 --- a/gpuapi/direct3d/ShaderUtils.h +++ b/gpuapi/direct3d/ShaderUtils.h @@ -35,6 +35,7 @@ const char* shader_type_index(ShaderType type) ID3DBlob* shader_make(const char* type, const char* source, int32 source_size) { + LOG_1("Create shader"); #if DEBUG || INTERNAL uint32 compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION; #else @@ -52,6 +53,8 @@ ID3DBlob* shader_make(const char* type, const char* source, int32 source_size) errMsgs->Release(); } + LOG_1("Created shader"); + return blob; } @@ -63,6 +66,8 @@ ID3D12PipelineState* pipeline_make( ID3DBlob* fragment_shader, ID3DBlob* ) { + PROFILE_VERBOSE(PROFILE_PIPELINE_MAKE, ""); + LOG_1("Create pipeline"); // @todo We need to find a way to do this somewhere else: D3D12_INPUT_ELEMENT_DESC input_element_info[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, @@ -123,6 +128,7 @@ ID3D12PipelineState* pipeline_make( } // @question When do I ->Release() vertex_shader and fragment_shader? + LOG_1("Created pipeline"); return *pipeline; } diff --git a/gpuapi/opengl/AppCmdBuffer.h b/gpuapi/opengl/AppCmdBuffer.h index e05f0d8..33564b1 100644 --- a/gpuapi/opengl/AppCmdBuffer.h +++ b/gpuapi/opengl/AppCmdBuffer.h @@ -49,8 +49,7 @@ void* cmd_shader_load_sync(AppCmdBuffer* __restrict cb, Shader* __restrict shade // Make sub shader shader_assets[i] = shader_make( shader_type_index((ShaderType) (i + 1)), - (char *) shader_asset->self, - cb->mem_vol + (char *) shader_asset->self ); shader_asset->state |= ASSET_STATE_RAM_GC; @@ -59,8 +58,7 @@ void* cmd_shader_load_sync(AppCmdBuffer* __restrict cb, Shader* __restrict shade // Make shader/program shader->id = pipeline_make( - shader_assets[0], shader_assets[1], shader_assets[2], - cb->mem_vol + shader_assets[0], shader_assets[1], shader_assets[2] ); return NULL; diff --git a/gpuapi/opengl/OpenglWin32.h b/gpuapi/opengl/OpenglWin32.h index 90a967b..e93c1e8 100644 --- a/gpuapi/opengl/OpenglWin32.h +++ b/gpuapi/opengl/OpenglWin32.h @@ -854,6 +854,7 @@ void opengl_destroy(Window* window) void opengl_instance_create(Window* window, int32 multisample = 0) { + LOG_1("Load opengl"); gl_extensions_load(); opengl_init_wgl(); @@ -872,6 +873,7 @@ void opengl_instance_create(Window* window, int32 multisample = 0) } if(!wglMakeCurrent(window->hdc, window->openGLRC)) { + LOG_1("Couldn't load opengl"); return; } @@ -880,6 +882,7 @@ void opengl_instance_create(Window* window, int32 multisample = 0) if (wglSwapIntervalEXT) { wglSwapIntervalEXT(0); } + LOG_1("Loaded opengl"); } #endif \ No newline at end of file diff --git a/gpuapi/opengl/ShaderUtils.h b/gpuapi/opengl/ShaderUtils.h index 33cf7ac..7ca3c62 100644 --- a/gpuapi/opengl/ShaderUtils.h +++ b/gpuapi/opengl/ShaderUtils.h @@ -205,8 +205,9 @@ int32 shader_program_optimize(const char* input, char* output) return (int32) (write_ptr - output); } -GLuint shader_make(GLenum type, const char* source, RingMemory* ring) +GLuint shader_make(GLenum type, const char* source) { + LOG_1("Create shader"); GLuint shader = glCreateShader(type); glShaderSource(shader, 1, (GLchar **) &source, NULL); glCompileShader(shader); @@ -219,8 +220,9 @@ GLuint shader_make(GLenum type, const char* source, RingMemory* ring) GLint length; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); - GLchar* info = (GLchar *) ring_get_memory(ring, length * sizeof(GLchar)); - + GLchar info[4096]; + length = OMS_MIN(length, ARRAY_COUNT(info) - 1); + info[length] = '\0'; glGetShaderInfoLog(shader, length, NULL, info); LOG_1(info); @@ -228,6 +230,8 @@ GLuint shader_make(GLenum type, const char* source, RingMemory* ring) } #endif + LOG_1("Created shader"); + return shader; } @@ -243,9 +247,10 @@ int32 program_get_size(uint32 program) GLuint pipeline_make( GLuint vertex_shader, GLuint fragment_shader, - GLint geometry_shader, - RingMemory* ring + GLint geometry_shader ) { + PROFILE_VERBOSE(PROFILE_PIPELINE_MAKE, ""); + LOG_1("Create pipeline"); GLuint program = glCreateProgram(); if (geometry_shader > -1) { @@ -265,8 +270,9 @@ GLuint pipeline_make( GLint length; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &length); - GLchar *info = (GLchar *) ring_get_memory(ring, length * sizeof(GLchar)); - + GLchar info[4096]; + length = OMS_MIN(length, ARRAY_COUNT(info) - 1); + info[length] = '\0'; glGetProgramInfoLog(program, length, NULL, info); LOG_1(info); @@ -290,6 +296,8 @@ GLuint pipeline_make( glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); + LOG_1("Created pipeline"); + return program; } diff --git a/gpuapi/opengl/UIOpengl.h b/gpuapi/opengl/UIOpengl.h deleted file mode 100644 index 5de2850..0000000 --- a/gpuapi/opengl/UIOpengl.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Jingga - * - * @copyright Jingga - * @license OMS License 2.0 - * @version 1.0.0 - * @link https://jingga.app - */ -#ifndef TOS_GPUAPI_OPENGL_UI_H -#define TOS_GPUAPI_OPENGL_UI_H - -#include "../../stdlib/Types.h" - -#include "../../ui/UIButton.h" -#include "../../ui/UIWindow.h" - -#include - -void render_button(UIButton* btn) -{ - // Draw the background rectangle (button) - glColor3f(btn->layout_default->color_background.r, btn->layout_default->color_background.g, btn->layout_default->color_background.b); - glBegin(GL_QUADS); - glVertex2f(btn->layout_default->x, btn->layout_default->y); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y + btn->layout_default->height); - glVertex2f(btn->layout_default->x, btn->layout_default->y + btn->layout_default->height); - glEnd(); - - // Draw the border - glColor3f(btn->layout_default->border_color.r, btn->layout_default->border_color.g, btn->layout_default->border_color.b); - // Bottom border - glLineWidth(btn->layout_default->border_width[0]); - glBegin(GL_LINES); - glVertex2f(btn->layout_default->x, btn->layout_default->y); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y); - glEnd(); - - // Right border - glLineWidth(btn->layout_default->border_width[1]); - glBegin(GL_LINES); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y + btn->layout_default->height); - glEnd(); - - // Top border - glLineWidth(btn->layout_default->border_width[2]); - glBegin(GL_LINES); - glVertex2f(btn->layout_default->x + btn->layout_default->width, btn->layout_default->y + btn->layout_default->height); - glVertex2f(btn->layout_default->x, btn->layout_default->y + btn->layout_default->height); - glEnd(); - - // Left border - glLineWidth(btn->layout_default->border_width[3]); - glBegin(GL_LINES); - glVertex2f(btn->layout_default->x, btn->layout_default->y + btn->layout_default->height); - glVertex2f(btn->layout_default->x, btn->layout_default->y); - glEnd(); -} - -#endif \ No newline at end of file diff --git a/gpuapi/vulkan/ShaderUtils.h b/gpuapi/vulkan/ShaderUtils.h index e5f22b9..8268b80 100644 --- a/gpuapi/vulkan/ShaderUtils.h +++ b/gpuapi/vulkan/ShaderUtils.h @@ -53,6 +53,7 @@ void shader_set_value(VkDevice device, VkDescriptorSet descriptorSet, uint32_t b inline VkShaderModule shader_make(VkDevice device, const char* source, int32 source_size) { + LOG_1("Create shader"); // Create shader module create info VkShaderModuleCreateInfo create_info = {}; create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; @@ -70,6 +71,8 @@ VkShaderModule shader_make(VkDevice device, const char* source, int32 source_siz return VK_NULL_HANDLE; } + LOG_1("Created shader"); + return shader_module; } @@ -196,6 +199,8 @@ VkPipeline pipeline_make( VkShaderModule vertex_shader, VkShaderModule fragment_shader, VkShaderModule ) { + PROFILE_VERBOSE(PROFILE_PIPELINE_MAKE, ""); + LOG_1("Create pipeline"); VkPipelineShaderStageCreateInfo vertex_shader_stage_info = {}; vertex_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; vertex_shader_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT; @@ -313,6 +318,8 @@ VkPipeline pipeline_make( vkDestroyShaderModule(device, fragment_shader, NULL); vkDestroyShaderModule(device, vertex_shader, NULL); + LOG_1("Created pipeline"); + // @question Do we want to return the value or the pointer? // I think the value is already a pointer? return *pipeline; diff --git a/image/Bitmap.h b/image/Bitmap.h index 773f4c4..c4a859f 100644 --- a/image/Bitmap.h +++ b/image/Bitmap.h @@ -198,10 +198,7 @@ void generate_default_bitmap_references(const FileBody* file, Bitmap* bitmap) no bitmap->size = (uint32) file->size; bitmap->data = file->content; - if (bitmap->size < BITMAP_HEADER_SIZE) { - // This shouldn't happen - return; - } + ASSERT_SIMPLE(bitmap->size >= BITMAP_HEADER_SIZE); // Fill header bitmap->header.identifier[0] = *(file->content + 0); @@ -229,11 +226,11 @@ void generate_default_bitmap_references(const FileBody* file, Bitmap* bitmap) no bitmap->dib_header.bits_per_pixel = SWAP_ENDIAN_LITTLE(*((uint16 *) (dib_header_offset + 10))); bitmap->dib_header.color_palette = 1U << bitmap->dib_header.bits_per_pixel; } break; - case DIB_BITMAP_TYPE_BITMAPV5HEADER: - case DIB_BITMAP_TYPE_BITMAPV4HEADER: - case DIB_BITMAP_TYPE_BITMAPV3INFOHEADER: - case DIB_BITMAP_TYPE_BITMAPV2INFOHEADER: - case DIB_BITMAP_TYPE_OS22XBITMAPHEADER: + case DIB_BITMAP_TYPE_BITMAPV5HEADER: [[fallthrough]]; + case DIB_BITMAP_TYPE_BITMAPV4HEADER: [[fallthrough]]; + case DIB_BITMAP_TYPE_BITMAPV3INFOHEADER: [[fallthrough]]; + case DIB_BITMAP_TYPE_BITMAPV2INFOHEADER: [[fallthrough]]; + case DIB_BITMAP_TYPE_OS22XBITMAPHEADER: [[fallthrough]]; case DIB_BITMAP_TYPE_BITMAPINFOHEADER: { bitmap->dib_header.size = SWAP_ENDIAN_LITTLE(*((uint32 *) (dib_header_offset))); bitmap->dib_header.width = SWAP_ENDIAN_LITTLE(*((int32 *) (dib_header_offset + 4))); diff --git a/image/Image.cpp b/image/Image.cpp index f9160c0..240bc9b 100644 --- a/image/Image.cpp +++ b/image/Image.cpp @@ -86,6 +86,7 @@ uint32 image_header_from_data(const byte* __restrict data, Image* __restrict ima uint32 image_from_data(const byte* __restrict data, Image* __restrict image) noexcept { + LOG_3("Load image"); const byte* pos = data; pos += image_header_from_data(data, image); @@ -93,6 +94,8 @@ uint32 image_from_data(const byte* __restrict data, Image* __restrict image) noe memcpy(image->pixels, pos, image_size = (image_pixel_size_from_type(image->image_settings) * image->pixel_count)); pos += image_size; + LOG_3("Loaded image"); + return (int32) (pos - data); } diff --git a/image/Png.h b/image/Png.h index 6337fcc..482ff4d 100644 --- a/image/Png.h +++ b/image/Png.h @@ -638,10 +638,10 @@ bool image_png_generate(const FileBody* src_data, Image* image, RingMemory* ring uint16 len = *((uint16 *) stream.pos); stream.pos += 2; - uint16 nlen = *((uint16 *) stream.pos); + //uint16 nlen = *((uint16 *) stream.pos); + ASSERT_SIMPLE(len == ~(*((uint16 *) stream.pos))); stream.pos += 2; - ASSERT_SIMPLE(len == ~nlen); memcpy(dest, stream.pos, len); stream.pos += len; diff --git a/image/Qoi.h b/image/Qoi.h index 7764a3c..4407326 100644 --- a/image/Qoi.h +++ b/image/Qoi.h @@ -292,6 +292,7 @@ int32 qoi_decode_3(const byte* data, Image* image) noexcept int32 qoi_decode(const byte* data, Image* image) noexcept { + LOG_3("QOI decode image"); int32 header_length = image_header_from_data(data, image); const int32 channels = (image->image_settings & IMAGE_SETTING_CHANNEL_COUNT); diff --git a/log/PerformanceProfiler.h b/log/PerformanceProfiler.h index 290d677..abe9f0a 100644 --- a/log/PerformanceProfiler.h +++ b/log/PerformanceProfiler.h @@ -22,7 +22,7 @@ #ifndef PERFORMANCE_PROFILE_STATS #define PERFORMANCE_PROFILE_STATS 1 enum TimingStats { - PROFILE_TEMP, // used for quick test debugging, not for permanent use + PROFILE_TEMP, PROFILE_FILE_UTILS, PROFILE_BUFFER_ALLOC, @@ -34,6 +34,7 @@ PROFILE_CMD_LAYOUT_LOAD_SYNC, PROFILE_CMD_THEME_LOAD_SYNC, PROFILE_CMD_UI_LOAD_SYNC, + PROFILE_CMD_ASSET_LOAD_SYNC, PROFILE_LAYOUT_FROM_DATA, PROFILE_LAYOUT_FROM_THEME, PROFILE_THEME_FROM_THEME, @@ -42,8 +43,10 @@ PROFILE_AUDIO_MIXER_MIX, PROFILE_ASSET_ARCHIVE_LOAD, PROFILE_ASSET_ARCHIVE_ASSET_LOAD, + PROFILE_AMS_UPDATE, PROFILE_VERTEX_RECT_CREATE, PROFILE_VERTEX_TEXT_CREATE, + PROFILE_PIPELINE_MAKE, PROFILE_SIZE, }; @@ -150,7 +153,7 @@ struct PerformanceProfiler { if (this->auto_log) { if (this->info_msg && this->info_msg[0]) { LOG_FORMAT_2( - "%s (%s): %l cycles", + "-PERF %s (%s): %l cycles", { {LOG_DATA_CHAR_STR, (void *) perf->name}, {LOG_DATA_CHAR_STR, (void *) this->info_msg}, @@ -159,7 +162,7 @@ struct PerformanceProfiler { ); } else { LOG_FORMAT_2( - "%s: %l cycles", + "-PERF %s: %l cycles", { {LOG_DATA_CHAR_STR, (void *) perf->name}, {LOG_DATA_INT64, (void *) &perf->total_cycle}, @@ -233,7 +236,7 @@ void performance_profiler_end(int32 id) noexcept #define PROFILE_RESET(id) if(_perf_active && *_perf_active) performance_profiler_reset((id)) #elif LOG_LEVEL == 1 #define PROFILE(id) ((void) 0) - #define PROFILE_VERBOSE(name) ((void) 0) + #define PROFILE_VERBOSE(name, info) ((void) 0) #define PROFILE_STATELESS(id, info) ((void) 0) #define PROFILE_START(id, name) ((void) 0) @@ -242,7 +245,7 @@ void performance_profiler_end(int32 id) noexcept #define PROFILE_RESET(id) ((void) 0) #elif LOG_LEVEL == 0 #define PROFILE(id) ((void) 0) - #define PROFILE_VERBOSE(name) ((void) 0) + #define PROFILE_VERBOSE(name, info) ((void) 0) #define PROFILE_STATELESS() ((void) 0) #define PROFILE_START(id, name) ((void) 0) diff --git a/memory/BufferMemory.h b/memory/BufferMemory.h index d813603..f26bb26 100644 --- a/memory/BufferMemory.h +++ b/memory/BufferMemory.h @@ -35,6 +35,7 @@ void buffer_alloc(BufferMemory* buf, uint64 size, int32 alignment = 64) { ASSERT_SIMPLE(size); PROFILE_VERBOSE(PROFILE_BUFFER_ALLOC, ""); + LOG_FORMAT_1("Allocating BufferMemory: %n B", {{LOG_DATA_UINT64, &size}}); buf->memory = alignment < 2 ? (byte *) platform_alloc(size) @@ -50,7 +51,6 @@ void buffer_alloc(BufferMemory* buf, uint64 size, int32 alignment = 64) DEBUG_MEMORY_INIT((uintptr_t) buf->memory, buf->size); LOG_INCREMENT_BY(DEBUG_COUNTER_MEM_ALLOC, buf->size); - LOG_FORMAT_2("Allocated BufferMemory: %n B", {{LOG_DATA_UINT64, &buf->size}}); } inline diff --git a/memory/ChunkMemory.h b/memory/ChunkMemory.h index 1b3f57d..b4fba9d 100644 --- a/memory/ChunkMemory.h +++ b/memory/ChunkMemory.h @@ -44,6 +44,7 @@ void chunk_alloc(ChunkMemory* buf, uint32 count, uint32 chunk_size, int32 alignm ASSERT_SIMPLE(chunk_size); ASSERT_SIMPLE(count); PROFILE_VERBOSE(PROFILE_CHUNK_ALLOC, ""); + LOG_1("Allocating ChunkMemory"); chunk_size = ROUND_TO_NEAREST(chunk_size, alignment); @@ -64,7 +65,7 @@ void chunk_alloc(ChunkMemory* buf, uint32 count, uint32 chunk_size, int32 alignm DEBUG_MEMORY_INIT((uintptr_t) buf->memory, buf->size); LOG_INCREMENT_BY(DEBUG_COUNTER_MEM_ALLOC, buf->size); - LOG_FORMAT_2("Allocated ChunkMemory: %n B", {{LOG_DATA_UINT64, &buf->size}}); + LOG_FORMAT_1("Allocated ChunkMemory: %n B", {{LOG_DATA_UINT64, &buf->size}}); } inline @@ -302,6 +303,7 @@ void chunk_free_elements(ChunkMemory* buf, uint64 element, uint32 element_count inline int64 chunk_dump(const ChunkMemory* buf, byte* data) { + LOG_1("Dump ChunkMemory"); byte* start = data; // Count @@ -329,12 +331,16 @@ int64 chunk_dump(const ChunkMemory* buf, byte* data) memcpy(data, buf->memory, buf->size); data += buf->size; + LOG_FORMAT_1("Dumped ChunkMemory: %n B", {{LOG_DATA_UINT64, (void *) &buf->size}}); + return data - start; } inline int64 chunk_load(ChunkMemory* buf, const byte* data) { + LOG_1("Loading ChunkMemory"); + // Count buf->count = SWAP_ENDIAN_LITTLE(*((uint32 *) data)); data += sizeof(buf->count); @@ -360,16 +366,16 @@ int64 chunk_load(ChunkMemory* buf, const byte* data) buf->free = (uint64 *) (buf->memory + buf->count * buf->chunk_size); - LOG_FORMAT_2("Loaded ChunkMemory: %n B", {{LOG_DATA_UINT64, &buf->size}}); + LOG_FORMAT_1("Loaded ChunkMemory: %n B", {{LOG_DATA_UINT64, &buf->size}}); return buf->size; } // @performance Is _BitScanForward faster? // @performance We could probably even reduce the number of iterations by only iterating until popcount is reached? -#define chunk_iterate_start(buf, chunk_id) { \ - uint32 free_index = 0; \ - uint32 bit_index = 0; \ +#define chunk_iterate_start(buf, chunk_id) { \ + uint32 free_index = 0; \ + uint32 bit_index = 0; \ \ /* Iterate the chunk memory */ \ for (; chunk_id < (buf)->count; ++chunk_id) { \ @@ -379,11 +385,9 @@ int64 chunk_load(ChunkMemory* buf, const byte* data) /* @performance Consider to only check 1 byte instead of 8 */ \ /* There are probably even better ways by using compiler intrinsics if available */ \ bit_index += 63; /* +64 - 1 since the loop also increases by 1 */ \ - } else if ((buf)->free[free_index] & (1ULL << bit_index)) { + } else if ((buf)->free[free_index] & (1ULL << bit_index)) #define chunk_iterate_end \ - } \ - \ ++bit_index; \ if (bit_index > 63) { \ bit_index = 0; \ diff --git a/memory/RingMemory.h b/memory/RingMemory.h index 9d4933d..fdad0da 100644 --- a/memory/RingMemory.h +++ b/memory/RingMemory.h @@ -48,6 +48,7 @@ void ring_alloc(RingMemory* ring, uint64 size, uint32 alignment = 64) { ASSERT_SIMPLE(size); PROFILE_VERBOSE(PROFILE_RING_ALLOC, ""); + LOG_FORMAT_1("Allocating RingMemory: %n B", {{LOG_DATA_UINT64, &size}}); ring->memory = alignment < 2 ? (byte *) platform_alloc(size) @@ -63,7 +64,7 @@ void ring_alloc(RingMemory* ring, uint64 size, uint32 alignment = 64) DEBUG_MEMORY_INIT((uintptr_t) ring->memory, ring->size); LOG_INCREMENT_BY(DEBUG_COUNTER_MEM_ALLOC, ring->size); - LOG_FORMAT_2("Allocated RingMemory: %n B", {{LOG_DATA_UINT64, &ring->size}}); + LOG_FORMAT_1("Allocated RingMemory: %n B", {{LOG_DATA_UINT64, &ring->size}}); } inline diff --git a/object/Mesh.h b/object/Mesh.h index c857ae7..c96f0dc 100644 --- a/object/Mesh.h +++ b/object/Mesh.h @@ -467,6 +467,7 @@ int32 mesh_from_data( [[maybe_unused]] int32 steps = 8 ) { + LOG_3("Load mesh"); const byte* pos = data; // Read version, use to handle different versions differently @@ -527,10 +528,12 @@ int32 mesh_from_data( SWAP_ENDIAN_LITTLE_SIMD( (int32 *) mesh->data, (int32 *) mesh->data, - offset / 4, // everything is 4 bytes -> super easy to swap + offset / 4, // everything is 4 bytes -> easy to swap steps ); + LOG_3("Loaded mesh"); + return offset; } @@ -616,7 +619,7 @@ int32 mesh_to_data( SWAP_ENDIAN_LITTLE_SIMD( (int32 *) data, (int32 *) data, - size / 4, // everything in here is 4 bytes -> super easy to swap + size / 4, // everything in here is 4 bytes -> easy to swap steps ); diff --git a/platform/win32/LeanWin32.h b/platform/win32/LeanWin32.h index 0bee680..f8ffacc 100644 --- a/platform/win32/LeanWin32.h +++ b/platform/win32/LeanWin32.h @@ -32,7 +32,7 @@ #define NOKERNEL 1 //#define NOUSER 0 #define NONLS 1 - #define NOMB 1 + //#define NOMB 1 #define NOMEMMGR 1 #define NOMETAFILE 1 #define NOMINMAX 1 diff --git a/platform/win32/audio/DirectSound.h b/platform/win32/audio/DirectSound.h index 2c17162..9724377 100644 --- a/platform/win32/audio/DirectSound.h +++ b/platform/win32/audio/DirectSound.h @@ -32,9 +32,11 @@ HRESULT WINAPI DirectSoundCreate8Stub(LPCGUID, LPDIRECTSOUND8*, LPUNKNOWN) { // END: Dynamically load DirectSound void audio_load(HWND hwnd, AudioSetting* setting, DirectSoundSetting* api_setting) { + LOG_1("Load audio API"); + HMODULE lib = LoadLibraryExA((LPCSTR) "dsound.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!lib) { - LOG_1("DirectSound: Couldn't load dsound.dll\n"); + LOG_1("DirectSound: Couldn't load dsound.dll"); return; } @@ -42,13 +44,13 @@ void audio_load(HWND hwnd, AudioSetting* setting, DirectSoundSetting* api_settin DirectSoundCreate8_t* DirectSoundCreate8 = (DirectSoundCreate8_t *) GetProcAddress(lib, "DirectSoundCreate8"); if (!DirectSoundCreate8 || !SUCCEEDED(DirectSoundCreate8(0, &api_setting->audio_handle, 0))) { - LOG_1("DirectSound: DirectSoundCreate8 failed\n"); + LOG_1("DirectSound: DirectSoundCreate8 failed"); return; } if(!SUCCEEDED(api_setting->audio_handle->SetCooperativeLevel(hwnd, DSSCL_PRIORITY))) { - LOG_1("DirectSound: SetCooperativeLevel failed.\n"); + LOG_1("DirectSound: SetCooperativeLevel failed."); return; } @@ -70,13 +72,13 @@ void audio_load(HWND hwnd, AudioSetting* setting, DirectSoundSetting* api_settin buffer_desc.dwFlags = DSBCAPS_PRIMARYBUFFER; if(!SUCCEEDED(api_setting->audio_handle->CreateSoundBuffer(&buffer_desc, &api_setting->primary_buffer, 0))) { - LOG_1("DirectSound: CreateSoundBuffer1 failed.\n"); + LOG_1("DirectSound: CreateSoundBuffer1 failed."); return; } if (!SUCCEEDED(api_setting->primary_buffer->SetFormat(&wf))) { - LOG_1("DirectSound: SetFormat failed.\n"); + LOG_1("DirectSound: SetFormat failed."); return; } @@ -92,7 +94,7 @@ void audio_load(HWND hwnd, AudioSetting* setting, DirectSoundSetting* api_settin buffer_desc2.lpwfxFormat = &wf; if(!SUCCEEDED(api_setting->audio_handle->CreateSoundBuffer(&buffer_desc2, &api_setting->secondary_buffer, 0))) { - LOG_1("DirectSound: CreateSoundBuffer2 failed.\n"); + LOG_1("DirectSound: CreateSoundBuffer2 failed."); return; } @@ -144,7 +146,7 @@ uint32 audio_buffer_fillable(const AudioSetting* setting, const DirectSoundSetti DWORD player_cursor; DWORD write_cursor; if (!SUCCEEDED(api_setting->secondary_buffer->GetCurrentPosition(&player_cursor, &write_cursor))) { - LOG_1("DirectSound: GetCurrentPosition failed.\n"); + LOG_1("DirectSound: GetCurrentPosition failed."); return 0; } diff --git a/platform/win32/audio/Wasapi.h b/platform/win32/audio/Wasapi.h index adaf3ea..b406f72 100644 --- a/platform/win32/audio/Wasapi.h +++ b/platform/win32/audio/Wasapi.h @@ -41,9 +41,11 @@ typedef HRESULT WINAPI IAudioClient_GetService_t(IAudioClient*, REFIID, void**); // END: Dynamically load DirectSound void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { + LOG_1("Load audio API"); + HMODULE ole32 = LoadLibraryExA((LPCSTR) "ole32.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!ole32) { - LOG_1("Wasapi: Couldn't load ole32.dll\n"); + LOG_1("Wasapi: Couldn't load ole32.dll"); return; } @@ -52,14 +54,14 @@ void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { CoCreateInstance_t* co_create_instance = (CoCreateInstance_t *) GetProcAddress(ole32, "CoCreateInstance"); if (!co_initialize_ex || !co_create_instance) { - LOG_1("Wasapi: ole32 function binding failed\n"); + LOG_1("Wasapi: ole32 function binding failed"); return; } HMODULE mmdevapi = LoadLibraryExA((LPCSTR) "mmdevapi.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!mmdevapi) { - LOG_1("Wasapi: Couldn't load mmdevapi.dll\n"); + LOG_1("Wasapi: Couldn't load mmdevapi.dll"); return; } @@ -68,14 +70,14 @@ void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { IMMDevice_Activate_t* IMMDevice_Activate = (IMMDevice_Activate_t *) GetProcAddress(mmdevapi, "IMMDevice_Activate"); if (!IMMDeviceEnumerator_GetDefaultAudioEndpoint || !IMMDevice_Activate) { - LOG_1("Wasapi: mmdevapi function binding failed\n"); + LOG_1("Wasapi: mmdevapi function binding failed"); return; } HMODULE audioclient = LoadLibraryExA((LPCSTR) "audioclient.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!audioclient) { - LOG_1("Wasapi: Couldn't load audioclient.dll\n"); + LOG_1("Wasapi: Couldn't load audioclient.dll"); return; } @@ -87,14 +89,14 @@ void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { IAudioClient_GetService_t* pIAudioClient_GetService = (IAudioClient_GetService_t *) GetProcAddress(audioclient, "IAudioClient_GetService"); if (!pIAudioClient_GetMixFormat || !pIAudioClient_Initialize || !pIAudioClient_Start || !pIAudioClient_Stop || !pIAudioClient_GetService) { - LOG_1("Wasapi: audioclient function binding failed\n"); + LOG_1("Wasapi: audioclient function binding failed"); return; } HRESULT hr = co_initialize_ex(NULL, COINIT_MULTITHREADED); if (FAILED(hr)) { - LOG_1("Wasapi: Wasapi initialize failed\n"); + LOG_1("Wasapi: Wasapi initialize failed"); return; } @@ -104,14 +106,14 @@ void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { hr = co_create_instance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **) &enumerator); if (FAILED(hr)) { - LOG_1("Wasapi: Wasapi CreateInstance failed\n"); + LOG_1("Wasapi: Wasapi CreateInstance failed"); return; } hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(enumerator, eRender, eConsole, &device); if (FAILED(hr)) { - LOG_1("Wasapi: Wasapi DefaultAudioEndpoint failed\n"); + LOG_1("Wasapi: Wasapi DefaultAudioEndpoint failed"); enumerator->Release(); @@ -120,7 +122,7 @@ void audio_load(HWND hwnd, AudioSetting* setting, WasapiSetting* api_setting) { hr = IMMDevice_Activate(device, IID_IAudioClient, CLSCTX_ALL, NULL, (void **) &api_setting->audio_handle); if (FAILED(hr)) { - LOG_1("Wasapi: Wasapi DeviceActivate failed\n"); + LOG_1("Wasapi: Wasapi DeviceActivate failed"); device->Release(); enumerator->Release(); diff --git a/platform/win32/audio/XAudio2.h b/platform/win32/audio/XAudio2.h index 610f18b..62ae8ca 100644 --- a/platform/win32/audio/XAudio2.h +++ b/platform/win32/audio/XAudio2.h @@ -34,23 +34,25 @@ HRESULT WINAPI XAudio2CreateStub(IXAudio2**, UINT32, XAUDIO2_PROCESSOR) { // END: Dynamically load XAudio2 void audio_load(HWND hwnd, AudioSetting* setting, XAudio2Setting* api_setting) { + LOG_1("Load audio API"); + CoInitialize(NULL); HMODULE lib = LoadLibraryExA((LPCSTR) "xaudio2_9.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (!lib) { - LOG_1("Xaudio2: Couldn't load xaudio2_9.dll\n"); + LOG_1("Xaudio2: Couldn't load xaudio2_9.dll"); lib = LoadLibraryExA((LPCSTR) "xaudio2_8.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); } if (!lib) { - LOG_1("Xaudio2: Couldn't load xaudio2_8.dll\n"); + LOG_1("Xaudio2: Couldn't load xaudio2_8.dll"); return; } XAudio2Create_t* XAudio2Create = (XAudio2Create_t *) GetProcAddress(lib, "XAudio2Create"); if (!XAudio2Create || !SUCCEEDED(XAudio2Create(&api_setting->audio_handle, 0, XAUDIO2_DEFAULT_PROCESSOR))) { - LOG_1("Xaudio2: XAudio2Create failed\n"); + LOG_1("Xaudio2: XAudio2Create failed"); return; } @@ -63,7 +65,7 @@ void audio_load(HWND hwnd, AudioSetting* setting, XAudio2Setting* api_setting) { 0, NULL)) ) { - LOG_1("Xaudio2: CreateMasteringVoice failed\n"); + LOG_1("Xaudio2: CreateMasteringVoice failed"); return; } @@ -78,7 +80,7 @@ void audio_load(HWND hwnd, AudioSetting* setting, XAudio2Setting* api_setting) { wf.cbSize = 0; if (!SUCCEEDED(api_setting->audio_handle->CreateSourceVoice(&api_setting->source_voice, &wf))) { - LOG_1("Xaudio2: CreateSourceVoice failed\n"); + LOG_1("Xaudio2: CreateSourceVoice failed"); return; } @@ -190,7 +192,7 @@ void audio_play_buffer(AudioSetting* setting, XAudio2Setting* api_setting) { ); if (!SUCCEEDED(api_setting->source_voice->SubmitSourceBuffer(&api_setting->internal_buffer[idx]))) { - LOG_1("Xaudio2: SubmitSourceBuffer failed\n"); + LOG_1("Xaudio2: SubmitSourceBuffer failed"); return; } diff --git a/stdlib/HashMap.h b/stdlib/HashMap.h index fd03da2..94458f9 100644 --- a/stdlib/HashMap.h +++ b/stdlib/HashMap.h @@ -124,6 +124,7 @@ struct HashMap { inline void hashmap_alloc(HashMap* hm, int32 count, int32 element_size) { + LOG_FORMAT_1("Allocate HashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); byte* data = (byte *) platform_alloc( count * (sizeof(uint16) + element_size) + CEIL_DIV(count, 64) * sizeof(hm->buf.free) @@ -134,7 +135,6 @@ void hashmap_alloc(HashMap* hm, int32 count, int32 element_size) DEBUG_MEMORY_INIT((uintptr_t) hm->buf.memory, hm->buf.size); LOG_INCREMENT_BY(DEBUG_COUNTER_MEM_ALLOC, hm->buf.size); - LOG_FORMAT_2("Allocated HashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); } inline @@ -153,6 +153,7 @@ void hashmap_free(HashMap* hm) inline void hashmap_create(HashMap* hm, int32 count, int32 element_size, RingMemory* ring) noexcept { + LOG_FORMAT_1("Create HashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); byte* data = ring_get_memory( ring, count * (sizeof(uint16) + element_size) @@ -161,14 +162,13 @@ void hashmap_create(HashMap* hm, int32 count, int32 element_size, RingMemory* ri hm->table = (uint16 *) data; chunk_init(&hm->buf, data + sizeof(uint16) * count, count, element_size, 8); - - LOG_FORMAT_2("Created HashMap for %n elements with %n B per element = %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}, {LOG_DATA_UINT64, &hm->buf.size}}); } // WARNING: element_size = element size + remaining HashEntry data size inline void hashmap_create(HashMap* hm, int32 count, int32 element_size, BufferMemory* buf) noexcept { + LOG_FORMAT_1("Create HashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); byte* data = buffer_get_memory( buf, count * (sizeof(uint16) + element_size) @@ -177,18 +177,15 @@ void hashmap_create(HashMap* hm, int32 count, int32 element_size, BufferMemory* hm->table = (uint16 *) data; chunk_init(&hm->buf, data + sizeof(uint16) * count, count, element_size, 8); - - LOG_FORMAT_2("Created HashMap for %n elements with %n B per element = %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}, {LOG_DATA_UINT64, &hm->buf.size}}); } // WARNING: element_size = element size + remaining HashEntry data size inline void hashmap_create(HashMap* hm, int32 count, int32 element_size, byte* buf) noexcept { + LOG_FORMAT_1("Create HashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); hm->table = (uint16 *) buf; chunk_init(&hm->buf, buf + sizeof(uint16) * count, count, element_size, 8); - - LOG_FORMAT_2("Created HashMap for %n elements with %n B per element = %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}, {LOG_DATA_UINT64, &hm->buf.size}}); } inline @@ -747,6 +744,7 @@ int32 hashmap_value_size(const HashMap* hm) noexcept inline int64 hashmap_dump(const HashMap* hm, byte* data, [[maybe_unused]] int32 steps = 8) { + LOG_1("Dump HashMap"); *((uint32 *) data) = SWAP_ENDIAN_LITTLE(hm->buf.count); data += sizeof(hm->buf.count); @@ -755,7 +753,7 @@ int64 hashmap_dump(const HashMap* hm, byte* data, [[maybe_unused]] int32 steps = SWAP_ENDIAN_LITTLE_SIMD( (uint16 *) data, (uint16 *) data, - sizeof(uint16) * hm->buf.count / 2, // everything is 2 bytes -> super easy to swap + sizeof(uint16) * hm->buf.count / 2, // everything is 2 bytes -> easy to swap steps ); data += sizeof(uint16) * hm->buf.count; @@ -804,6 +802,8 @@ int64 hashmap_dump(const HashMap* hm, byte* data, [[maybe_unused]] int32 steps = // dump free array memcpy(data, hm->buf.free, sizeof(uint64) * CEIL_DIV(hm->buf.count, 64)); + LOG_FORMAT_1("Dumped HashMap: %n B", {{LOG_DATA_UINT64, (void *) &hm->buf.size}}); + return sizeof(hm->buf.count) // hash map count = buffer count + hm->buf.count * sizeof(uint16) // table content + hm->buf.size; // hash map content + free array @@ -813,6 +813,7 @@ int64 hashmap_dump(const HashMap* hm, byte* data, [[maybe_unused]] int32 steps = inline int64 hashmap_load(HashMap* hm, const byte* data, [[maybe_unused]] int32 steps = 8) { + LOG_1("Load HashMap"); uint64 count = SWAP_ENDIAN_LITTLE(*((uint32 *) data)); data += sizeof(uint32); @@ -821,7 +822,7 @@ int64 hashmap_load(HashMap* hm, const byte* data, [[maybe_unused]] int32 steps = SWAP_ENDIAN_LITTLE_SIMD( (uint16 *) hm->table, (uint16 *) hm->table, - sizeof(uint16) * count / 2, // everything is 2 bytes -> super easy to swap + sizeof(uint16) * count / 2, // everything is 2 bytes -> easy to swap steps ); data += sizeof(uint16) * count; @@ -839,7 +840,7 @@ int64 hashmap_load(HashMap* hm, const byte* data, [[maybe_unused]] int32 steps = // Switch endian AND turn offsets to pointers uint32 chunk_id = 0; - chunk_iterate_start(&hm->buf, chunk_id) + chunk_iterate_start(&hm->buf, chunk_id) { HashEntry* entry = (HashEntry *) chunk_get_element((ChunkMemory *) &hm->buf, chunk_id); // key is already loaded with the memcpy @@ -853,9 +854,9 @@ int64 hashmap_load(HashMap* hm, const byte* data, [[maybe_unused]] int32 steps = } else if (value_size == 8) { ((HashEntryInt64 *) entry)->value = SWAP_ENDIAN_LITTLE(((HashEntryInt64 *) entry)->value); } - chunk_iterate_end; + } chunk_iterate_end; - LOG_FORMAT_2("Loaded HashMap: %n B", {{LOG_DATA_UINT64, &hm->buf.size}}); + LOG_FORMAT_1("Loaded HashMap: %n B", {{LOG_DATA_UINT64, &hm->buf.size}}); // How many bytes was read from data return sizeof(hm->buf.count) // hash map count = buffer count diff --git a/stdlib/PerfectHashMap.h b/stdlib/PerfectHashMap.h index 7b75ee5..5276315 100644 --- a/stdlib/PerfectHashMap.h +++ b/stdlib/PerfectHashMap.h @@ -111,6 +111,7 @@ PerfectHashMap* perfect_hashmap_prepare(PerfectHashMap* hm, const char** keys, i // WARNING: element_size = element size + remaining HashEntry data size void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, BufferMemory* buf) { + LOG_FORMAT_1("Create PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); hm->map_size = count; hm->entry_size = element_size; hm->hash_entries = buffer_get_memory( @@ -118,18 +119,15 @@ void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, count * element_size, 0, true ); - - LOG_FORMAT_2("Created PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); } // WARNING: element_size = element size + remaining HashEntry data size void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, byte* buf) { + LOG_FORMAT_1("Create PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); hm->map_size = count; hm->entry_size = element_size; hm->hash_entries = buf; - - LOG_FORMAT_2("Created PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); } // Calculates how large a hashmap will be @@ -284,13 +282,11 @@ bool perfect_hashmap_from_hashmap(PerfectHashMap* phm, const HashMap* hm, int32 // Find all keys int32 key_index = 0; - for (int32 i = 0; i < hm->buf.count; ++i) { - const HashEntry* entry = (HashEntry *) hashmap_get_entry_by_index((HashMap *) hm, i); - while (entry != NULL) { - keys[key_index++] = entry->key; - entry = (HashEntry *) hashmap_get_entry_by_element((HashMap *) hm, entry->next); - } - } + uint32 chunk_id = 0; + chunk_iterate_start(&hm->buf, chunk_id) { + HashEntry* entry = (HashEntry *) chunk_get_element((ChunkMemory *) &hm->buf, chunk_id); + keys[key_index++] = entry->key; + } chunk_iterate_end; // Check if we can turn it into a perfect hash map PerfectHashMap* is_perfect = perfect_hashmap_prepare(phm, keys, key_index, seed_trys, ring); @@ -299,13 +295,11 @@ bool perfect_hashmap_from_hashmap(PerfectHashMap* phm, const HashMap* hm, int32 } // Fill perfect hash map - for (int32 i = 0; i < hm->buf.count; ++i) { - const HashEntry* entry = (HashEntry *) hashmap_get_entry_by_index((HashMap *) hm, i); - while (entry != NULL) { - perfect_hashmap_insert(phm, entry->key, entry->value); - entry = (HashEntry *) hashmap_get_entry_by_element((HashMap *) hm, entry->next); - } - } + chunk_id = 0; + chunk_iterate_start(&hm->buf, chunk_id) { + HashEntry* entry = (HashEntry *) chunk_get_element((ChunkMemory *) &hm->buf, chunk_id); + perfect_hashmap_insert(phm, entry->key, entry->value); + } chunk_iterate_end; return true; } diff --git a/stdlib/Types.h b/stdlib/Types.h index 28af015..021c097 100644 --- a/stdlib/Types.h +++ b/stdlib/Types.h @@ -19,7 +19,7 @@ #define MAX_PATH PATH_MAX #endif -#define ARRAY_COUNT(a) (sizeof(a) / sizeof((a)[0])) +#define ARRAY_COUNT(a) ((a) == NULL ? 0 : (sizeof(a) / sizeof((a)[0]))) typedef int8_t int8; typedef int16_t int16; diff --git a/thread/Thread.h b/thread/Thread.h index 0d45645..97bc857 100644 --- a/thread/Thread.h +++ b/thread/Thread.h @@ -25,7 +25,7 @@ void thread_create(Worker* worker, ThreadJobFunc routine, void* arg) { - LOG_2("Thread started"); + LOG_1("Thread started"); pthread_create(&worker->thread, NULL, routine, arg); } @@ -33,7 +33,7 @@ void thread_stop(Worker* worker) { atomic_set_acquire(&worker->state, 0); pthread_join(worker->thread, NULL); - LOG_2("Thread ended"); + LOG_1("Thread ended"); } #endif \ No newline at end of file diff --git a/thread/ThreadPool.h b/thread/ThreadPool.h index 2ec2d42..0ad068a 100644 --- a/thread/ThreadPool.h +++ b/thread/ThreadPool.h @@ -60,9 +60,9 @@ static THREAD_RETURN thread_pool_worker(void* arg) atomic_increment_relaxed(&pool->working_cnt); atomic_set_release(&work->state, 2); - LOG_FORMAT_2("ThreadPool worker started", {}); + LOG_2("ThreadPool worker started"); work->func(work); - LOG_FORMAT_2("ThreadPool worker ended", {}); + LOG_2("ThreadPool worker ended"); // At the end of a thread the ring memory automatically is considered freed DEBUG_MEMORY_FREE((uintptr_t) work->ring.memory, work->ring.size); LOG_FORMAT_2("Freed thread RingMemory: %n B", {{LOG_DATA_UINT64, &work->ring.size}}); diff --git a/ui/UILayout.cpp b/ui/UILayout.cpp index 7e12b66..570d12a 100644 --- a/ui/UILayout.cpp +++ b/ui/UILayout.cpp @@ -415,6 +415,7 @@ int32 layout_to_data( const UILayout* __restrict layout, byte* __restrict data ) { + LOG_1("Save layout"); byte* out = data; // version @@ -426,10 +427,12 @@ int32 layout_to_data( // UIElement data uint32 chunk_id = 0; - chunk_iterate_start(&layout->hash_map.buf, chunk_id) + chunk_iterate_start(&layout->hash_map.buf, chunk_id) { HashEntryInt32* entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &layout->hash_map.buf, chunk_id); ui_layout_serialize_element(entry, layout->data, &out); - chunk_iterate_end; + } chunk_iterate_end; + + LOG_1("Saved layout"); return (int32) (out - data); } @@ -568,6 +571,7 @@ int32 layout_from_data( UILayout* __restrict layout ) { PROFILE_VERBOSE(PROFILE_LAYOUT_FROM_DATA, ""); + LOG_1("Load layout"); const byte* in = data; @@ -583,13 +587,15 @@ int32 layout_from_data( // layout data // @performance We are iterating the hashmap twice (hashmap_load and here) uint32 chunk_id = 0; - chunk_iterate_start(&layout->hash_map.buf, chunk_id) + chunk_iterate_start(&layout->hash_map.buf, chunk_id) { HashEntryInt32* entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &layout->hash_map.buf, chunk_id); ui_layout_parse_element(entry, layout->data, &in); - chunk_iterate_end; + } chunk_iterate_end; layout->layout_size = (uint32) (in - data); + LOG_1("Loaded layout"); + return (int32) layout->layout_size; } @@ -601,6 +607,7 @@ void layout_from_theme( const UIThemeStyle* __restrict theme ) { PROFILE_VERBOSE(PROFILE_LAYOUT_FROM_THEME, ""); + LOG_1("Load theme for layout"); // @todo Handle animations // @todo Handle vertices_active offset @@ -615,7 +622,7 @@ void layout_from_theme( // We first need to handle the default element -> iterate all elements but only handle the default style // The reason for this is, later on in the specialized style we use the base style and copy it over as foundation uint32 chunk_id = 0; - chunk_iterate_start(&theme->hash_map.buf, chunk_id) + chunk_iterate_start(&theme->hash_map.buf, chunk_id) { HashEntryInt32* style_entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &theme->hash_map.buf, chunk_id); // We don't handle special styles here, only the default one @@ -664,7 +671,7 @@ void layout_from_theme( ); } break; } - chunk_iterate_end; + } chunk_iterate_end; // We iterate every style // 1. Fill default element if it is default style @@ -673,7 +680,7 @@ void layout_from_theme( // If we could see if the default element is already populated we could easily combine this // We could use a helper array to keep track of initialized chunk_id but we also don't have access to malloc/ring memory here chunk_id = 0; - chunk_iterate_start(&theme->hash_map.buf, chunk_id) + chunk_iterate_start(&theme->hash_map.buf, chunk_id) { HashEntryInt32* style_entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &theme->hash_map.buf, chunk_id); // We only handle special styles here, not the default one @@ -739,7 +746,7 @@ void layout_from_theme( ); } break; } - chunk_iterate_end; + } chunk_iterate_end; } void ui_layout_update(UILayout* layout, UIElement* element) { @@ -792,6 +799,8 @@ void ui_layout_update(UILayout* layout, UIElement* element) { UNREACHABLE(); } } + + LOG_1("Loaded theme for layout"); } // @question We might want to change the names of update/render diff --git a/ui/UITheme.h b/ui/UITheme.h index d1f803b..e3a492d 100644 --- a/ui/UITheme.h +++ b/ui/UITheme.h @@ -268,6 +268,8 @@ int32 theme_from_data( UIThemeStyle* __restrict theme ) { PROFILE_VERBOSE(PROFILE_THEME_FROM_THEME, ""); + LOG_1("Load theme"); + const byte* in = data; int32 version = SWAP_ENDIAN_LITTLE(*((int32 *) in)); @@ -284,10 +286,12 @@ int32 theme_from_data( // Layout: first load the size of the group, then load the individual attributes // @performance We are iterating the hashmap twice (hashmap_load and here) uint32 chunk_id = 0; - chunk_iterate_start(&theme->hash_map.buf, chunk_id) + chunk_iterate_start(&theme->hash_map.buf, chunk_id) { HashEntryInt32* entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &theme->hash_map.buf, chunk_id); ui_theme_parse_group(entry, theme->data, &in); - chunk_iterate_end; + } chunk_iterate_end; + + LOG_1("Loaded theme"); return (int32) (in - data); } @@ -378,10 +382,10 @@ int32 theme_to_data( // theme data // Layout: first save the size of the group, then save the individual attributes uint32 chunk_id = 0; - chunk_iterate_start(&theme->hash_map.buf, chunk_id) + chunk_iterate_start(&theme->hash_map.buf, chunk_id) { const HashEntryInt32* entry = (HashEntryInt32 *) chunk_get_element((ChunkMemory *) &theme->hash_map.buf, chunk_id); ui_theme_serialize_group(entry, theme->data, &out); - chunk_iterate_end; + } chunk_iterate_end; return (int32) (out - data); }