Fixed bugs with optimized builds

Symbol table for engine module was out of order.
This commit is contained in:
Edward R. Gonzalez 2023-09-28 18:38:06 -04:00
parent 0746cbd504
commit d76163ae84
10 changed files with 72 additions and 51 deletions

View File

@ -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"
}

Binary file not shown.

View File

@ -299,7 +299,6 @@ void play_input( EngineState* state, InputState* input, platform::ModuleAPI* pla
if ( controller->Keyboard )
{
*controller->Keyboard = new_input.Controllers[idx].Keyboard;
printf("keyboard D key: %d\n", controller->Keyboard->D.EndedDown );
}
if ( controller->Mouse )

View File

@ -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 )

View File

@ -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 <math.h> // TODO : Implement math ourselves

View File

@ -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

View File

@ -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,

View File

@ -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'

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<NatStepFiltering xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
<Function>
<Name>StrFixed&lt;*&gt;::concat</Name>
<Action>NoStepInto</Action>
</Function>
</NatStepFiltering>

Binary file not shown.