From d76163ae84e033a3f517957f53700d76cc226316 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 28 Sep 2023 18:38:06 -0400 Subject: [PATCH] Fixed bugs with optimized builds Symbol table for engine module was out of order. --- .vscode/bookmarks.json | 6 +-- data/test_input.hmi | Bin 67259168 -> 67283808 bytes project/engine/engine.cpp | 1 - project/platform/macros.hpp | 2 +- project/platform/platform.hpp | 2 + project/platform/strings.hpp | 20 ++++---- project/platform/win32_platform.cpp | 11 +++-- scripts/build.ps1 | 74 ++++++++++++++++------------ scripts/handmade.natstepfilter | 7 +++ scripts/handmade.rdbg | Bin 905 -> 1123 bytes 10 files changed, 72 insertions(+), 51 deletions(-) diff --git a/.vscode/bookmarks.json b/.vscode/bookmarks.json index 278d53e..4d87d72 100644 --- a/.vscode/bookmarks.json +++ b/.vscode/bookmarks.json @@ -19,17 +19,17 @@ "label": "Timing" }, { - "line": 1477, + "line": 1478, "column": 4, "label": "Main Loop : Audio Processing" }, { - "line": 1596, + "line": 1597, "column": 2, "label": "Main Loop : Timing Update" }, { - "line": 1680, + "line": 1681, "column": 0, "label": "Main Loop : End" } diff --git a/data/test_input.hmi b/data/test_input.hmi index 359c89a783e587037840a56e8ad85901ad65cfd6..7759f0249e389be217622c741d3861e3d0ad271d 100644 GIT binary patch delta 4273 zcmX}rRhX7l1BGD+h8RLw(mix{4&5avA&r1^iL`{2uz;akQo5u&Mq0YNB&18F8~mU7 z{Vopf>sbfy-tW<#Jvlt|+S%cu(WeD{^2vyxfwF?EC{|P}*otOFw_;c^tq?1g72Aqq z#kD@QKC|Lk9QoXeZzZr2T8XU0RuU_zmCQpQEX^}W@}>TGqfx?0_=?p6=$2dk&m%j#|Q zv3|7rTK%m4)&Ogu^^-No8f@7bVhy#1S>e`jYlJn@8fA^P##m#man^Wif;G{aWKFhy zwx(E9t!dVDYlbz``o)@M&9>%PbFF#Sd~1QV&{||Iww74GT1%~E)^clwwbEK;t+v)! zYpr$GdTWEV(b{BfwzgOi)^FBU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qXcAM>vE>C?X&tA|W!u5Cu^Y z4bkx(Vjw00H)0_+;vg>KAwCiyArc`mk{~IPAvsbYB~syg{D9O*gS1G8^vHl8krA1Y z8Cj4OKOq~kBL{LK7jh#H@**GdqW}t`5DKFRilP{bqXbH#6iVY~ltEeif^sO23aE%m zsEjJ8ifZ^3)lmaAQ46(E2X#>o_0a$g(Fl#v1WnNl&Cvoa(F(2625r#}?a=`p(FvW= z1zph%-O&R*(F?uN2Yt~G{V@OoF$jY(1VdpA!*GniNQ}a0jKNrp!+1=V2o4AGBxP!a6hrjU;?&DwlhX;6wM|g}Uc#3Cuju&`|S9py#c#C&4 z_=<1gC#J|S|9QKR(8$~Kgw6^`F2*?8rqOAk3vF=?0mj2u-Cs1>Keyboard ) { *controller->Keyboard = new_input.Controllers[idx].Keyboard; - printf("keyboard D key: %d\n", controller->Keyboard->D.EndedDown ); } if ( controller->Mouse ) diff --git a/project/platform/macros.hpp b/project/platform/macros.hpp index 2223008..dfc918a 100644 --- a/project/platform/macros.hpp +++ b/project/platform/macros.hpp @@ -10,7 +10,7 @@ // Casting -#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) ) +#define ccast( Type, Value ) ( const_cast< Type >( (Value) ) ) #define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) ) #define rcast( Type, Value ) reinterpret_cast< Type >( Value ) #define scast( Type, Value ) static_cast< Type >( Value ) diff --git a/project/platform/platform.hpp b/project/platform/platform.hpp index 86d78b6..46190ea 100644 --- a/project/platform/platform.hpp +++ b/project/platform/platform.hpp @@ -18,6 +18,8 @@ #pragma warning( disable: 5045 ) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified #pragma warning( disable: 5264 ) // Support for 'const' variables unused #pragma warning( disable: 4820 ) // Support auto-adding padding to structs +#pragma warning( disable: 4711 ) // Support automatic inline expansion +#pragma warning( disable: 4710 ) // Support automatic inline expansion // TODO(Ed) : REMOVE THESE WHEN HE GETS TO THEM #include // TODO : Implement math ourselves diff --git a/project/platform/strings.hpp b/project/platform/strings.hpp index a8bd1f7..0b7eb57 100644 --- a/project/platform/strings.hpp +++ b/project/platform/strings.hpp @@ -7,7 +7,7 @@ void str_concat( u32 dest_size, char* dest , u32 str_b_len, char const* str_b ); u32 str_length( char const* str ); -#define str_ascii( str ) { sizeof( str ) - 1, str } +#define str_ascii( str ) { sizeof( str ) - 1, ccast( char*, str) } // Length tracked raw strings. struct Str @@ -118,10 +118,10 @@ void str_concat( u32 dest_size, char* dest char* dest_b = dest + str_a_len; if ( str_a_len > str_b_len ) { - u32 left = str_a_len; + u32 left = str_b_len; while ( left-- ) { - *dest_a = *str_a; + *dest_a = *str_a; *dest_b = *str_b; ++ dest_a; @@ -133,14 +133,14 @@ void str_concat( u32 dest_size, char* dest left = str_a_len - str_b_len; while ( left-- ) { - *dest_b = *str_b; - ++ dest_b; - ++ str_b; + *dest_a = *str_a; + ++ dest_a; + ++ str_a; } } else if ( str_a_len < str_b_len ) { - u32 left = str_b_len; + u32 left = str_a_len; while ( left-- ) { *dest_a = *str_a; @@ -154,9 +154,9 @@ void str_concat( u32 dest_size, char* dest left = str_b_len - str_a_len; while ( left-- ) { - *dest_a = *str_a; - ++ dest_a; - ++ str_a; + *dest_b = *str_b; + ++ dest_b; + ++ str_b; } } else diff --git a/project/platform/win32_platform.cpp b/project/platform/win32_platform.cpp index 4a5017c..d799345 100644 --- a/project/platform/win32_platform.cpp +++ b/project/platform/win32_platform.cpp @@ -1064,9 +1064,9 @@ void* get_binary_module_symbol( BinaryModule module, char const* symbol_name ) #pragma region Engine Module API -constexpr Str FName_Engine_DLL = str_ascii("handmade_engine.dll"); -constexpr Str FName_Engine_DLL_InUse = str_ascii("handmade_engine_in_use.dll"); -constexpr Str FName_Engine_PDB_Lock = str_ascii("handmade_engine.pdb.lock"); +constexpr const Str FName_Engine_DLL = str_ascii("handmade_engine.dll"); +constexpr const Str FName_Engine_DLL_InUse = str_ascii("handmade_engine_in_use.dll"); +constexpr const Str FName_Engine_PDB_Lock = str_ascii("handmade_engine.pdb.lock"); global HMODULE Lib_Handmade_Engine = nullptr; global StrFixed< S16_MAX > Path_Engine_DLL; @@ -1093,7 +1093,7 @@ engine::ModuleAPI load_engine_module_api() File symbol_table {}; symbol_table.Path = path_handmade_engine_symbols; - if ( ! file_read_content( & symbol_table ) ) + if ( file_read_content( & symbol_table ), symbol_table.Size == 0 ) { fatal( "Failed to load symbol table for handmade engine module!" ); return {}; @@ -1218,7 +1218,8 @@ WinMain( HINSTANCE instance, HINSTANCE prev_instance, LPSTR commandline, int sho } window_handle = CreateWindowExW( - WS_EX_LAYERED | WS_EX_TOPMOST, + // WS_EX_LAYERED | WS_EX_TOPMOST, + WS_EX_LAYERED, window_class.lpszClassName, L"Handmade Hero", WS_Overlapped_Window | WS_Initially_Visible, diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 198f7ad..5e8f62f 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -10,7 +10,7 @@ Push-Location $path_root #region Arguments $vendor = $null - $optimized = $null + $optimize = $null $debug = $null $analysis = $false $dev = $false @@ -25,7 +25,7 @@ Push-Location $path_root if ( $args ) { $args | ForEach-Object { switch ($_){ { $_ -in $vendors } { $vendor = $_; break } - "optimized" { $optimized = $true } + "optimize" { $optimize = $true } "debug" { $debug = $true } "analysis" { $analysis = $true } "dev" { $dev = $true } @@ -211,7 +211,7 @@ if ( $vendor -match "clang" ) $flag_section_functions, ( $flag_path_output + $object ) ) - if ( $optimized ) { + if ( $optimize ) { $compiler_args += $flag_optimize_fast } else { @@ -348,7 +348,7 @@ if ( $vendor -match "msvc" ) $compiler_args += ( $flag_path_debug + $path_build + '\' ) $compiler_args += $flag_link_win_rt_static_debug - if ( $optimized ) { + if ( $optimize ) { $compiler_args += $flag_optimized_debug } } @@ -524,48 +524,60 @@ if ( $engine ) # This is done by sifting through the emitter.map file from the linker for the base symbol names # and mapping them to their found decorated name - $engine_symbols = @( - 'on_module_reload', - 'startup', - 'shutdown', - 'update_and_render', - 'update_audio' - ) + # Initialize the hashtable with the desired order of symbols + $engine_symbols = [ordered]@{ + 'on_module_reload' = $null + 'startup' = $null + 'shutdown' = $null + 'update_and_render' = $null + 'update_audio' = $null + } + $path_engine_obj = Join-Path $path_build 'handmade_engine.obj' $path_engine_map = Join-Path $path_build 'handmade_engine.map' + $maxNameLength = ($engine_symbols.Keys | Measure-Object -Property Length -Maximum).Maximum - $maxNameLength = ($engine_symbols | Measure-Object -Property Length -Maximum).Maximum - - $engine_symbol_table = @() - $engine_symbol_list = @() Get-Content -Path $path_engine_map | ForEach-Object { - # Split each line by whitespace - $tokens = $_ -split '\s+', 3 - + # If all symbols are found, exit the loop + if ($engine_symbols.Values -notcontains $null) { + return + } + # Split the line into tokens + $tokens = $_ -split '\s+', 4 # Extract only the decorated name using regex for both MSVC and Clang conventions - $decoratedName = ($tokens[2] -match '(\?[\w@]+|_Z[\w@]+)' ) ? $matches[1] : $null + $decoratedName = ($tokens[2] -match '(\?[\w@]+|_Z[\w@]+)') ? $matches[1] : $null - # Check each regular name against the current line - foreach ($name in $engine_symbols) { - if ($decoratedName -like "*$name*") { - $engine_symbol_table += $name + ', ' + $decoratedName - $engine_symbol_list += $decoratedName - $engine_symbols = $engine_symbols -ne $name # Remove the found symbol from the array + # Check the origin of the symbol + # If the origin matches 'handmade_engine.obj', then process the symbol + $originParts = $tokens[3] -split '\s+' + $origin = if ($originParts.Count -eq 3) { $originParts[2] } else { $originParts[1] } + + # Diagnostic output + if ( $false -and $decoratedName) { + write-host "Found decorated name: $decoratedName" -ForegroundColor Yellow + write-host "Origin : $origin" -ForegroundColor Yellow + } + + if ($origin -like 'handmade_engine.obj') { + # Check each regular name against the current line + $engine_symbols.Keys | Where-Object { $engine_symbols[$_] -eq $null } | ForEach-Object { + if ($decoratedName -like "*$_*") { + $engine_symbols[$_] = $decoratedName + } } } } write-host "Engine Symbol Table:" -ForegroundColor Green - $engine_symbol_table | ForEach-Object { - $split = $_ -split ', ', 2 - $paddedName = $split[0].PadRight($maxNameLength) - $decoratedName = $split[1] + $engine_symbols.GetEnumerator() | ForEach-Object { + $paddedName = $_.Key.PadRight($maxNameLength) + $decoratedName = $_.Value write-host "`t$paddedName, $decoratedName" -ForegroundColor Green } # Write the symbol table to a file $path_engine_symbols = Join-Path $path_binaries 'handmade_engine.symbols' - $engine_symbol_list | Out-File -Path $path_engine_symbols + $engine_symbols.Values | Out-File -Path $path_engine_symbols } Remove-Item $path_pdb_lock -Force -Verbose @@ -592,7 +604,7 @@ if ( $platform ) $lib_jsl, $flag_link_win_subsystem_windows - $flag_link_optimize_references + # $flag_link_optimize_references ) $unit = Join-Path $path_project 'handmade_win32.cpp' diff --git a/scripts/handmade.natstepfilter b/scripts/handmade.natstepfilter index e69de29..c71dc54 100644 --- a/scripts/handmade.natstepfilter +++ b/scripts/handmade.natstepfilter @@ -0,0 +1,7 @@ + + + + StrFixed<*>::concat + NoStepInto + + diff --git a/scripts/handmade.rdbg b/scripts/handmade.rdbg index a90e6a6ea9d950b5f88eef3ed39926afd81b44e9..7ddac53a51aa913281f1966201b1af7a625b897b 100644 GIT binary patch delta 191 zcmeBVf6Or`fKx$EOW^qYsUP*9f zRVv67up%xXBNd`Iu^>|%BwU%Bl%ErypBJB-pHiBW8ef!}lb@IZlmUUsJD5Z#uVHdv XWSzW`NqaI2b2yMC$ZRmVm{|+}|5`fb delta 51 zcmaFN(aAm`pOuM$fx%|tT9wJ{jM5X=m~B>KT+BE*ky&AKB(uZh0%nQHN14OHv@eSo E0EX%g@c;k-