1 2 3 4 5 6 7 | uint32* pixel = ( uint32* ) buffer->memory; for ( int y = roundedMinY; y < roundedMaxY; y++ ) { for ( int x = roundedMinX; x < roundedMaxX; x++ ) { *( pixel + y * buffer->width + x ) = color; } } |
1 2 3 4 5 6 7 | FILETIME dllWriteTime = win32GetLastWriteTime( sourceGameCodeDllFullPath ); if ( CompareFileTime( &dllWriteTime, &game.dllLastWriteTime ) != 0 ) { Sleep( 155 ); win32UnloadGameCode( &game ); game = win32LoadGameCode( sourceGameCodeDllFullPath, tempGameCodeDllFullPath ); } |
Is there a downside to computing the pixel offset from x and y every loop cycle instead of incrementing a pixel pointer ?
1 2 3 4 5 6 7 8 | uint32* pixel = ( uint32* ) buffer->memory; uint32 width = buffer->width; for ( int y = roundedMinY; y < roundedMaxY; y++ ) { for ( int x = roundedMinX; x < roundedMaxX; x++ ) { *( pixel + y * width + x ) = color; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | internal void drawRectangle( GameOffscreenBuffer* buffer, real32 minX, real32 minY, real32 maxX, real32 maxY, real32 r, real32 g, real32 b ) { 000007FEF2061000 48 89 5C 24 08 mov qword ptr [buffer],rbx 000007FEF2061005 48 89 7C 24 10 mov qword ptr [minX],rdi int32 roundedMinX = roundReal32ToInt32( minX ); 000007FEF206100A F3 0F 10 25 46 A3 05 00 movss xmm4,dword ptr [__real@3f000000 (07FEF20BB358h)] int32 roundedMaxY = roundReal32ToInt32( maxY ); 000007FEF2061012 F3 0F 10 44 24 28 movss xmm0,dword ptr [maxY] if ( roundedMinX < 0 ) { 000007FEF2061018 33 C0 xor eax,eax 000007FEF206101A 48 8B D9 mov rbx,rcx int32 roundedMaxY = roundReal32ToInt32( maxY ); 000007FEF206101D F3 0F 58 C4 addss xmm0,xmm4 int32 roundedMinX = roundReal32ToInt32( minX ); 000007FEF2061021 F3 0F 58 CC addss xmm1,xmm4 int32 roundedMinY = roundReal32ToInt32( minY ); 000007FEF2061025 F3 0F 58 D4 addss xmm2,xmm4 int32 roundedMaxY = roundReal32ToInt32( maxY ); 000007FEF2061029 F3 0F 2C C8 cvttss2si ecx,xmm0 roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF206102D F3 0F 10 44 24 30 movss xmm0,dword ptr [r] int32 roundedMinX = roundReal32ToInt32( minX ); 000007FEF2061033 F3 44 0F 2C C9 cvttss2si r9d,xmm1 if ( roundedMinX < 0 ) { 000007FEF2061038 45 85 C9 test r9d,r9d 000007FEF206103B 44 0F 48 C8 cmovs r9d,eax roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF206103F F3 0F 10 0D 29 A3 05 00 movss xmm1,dword ptr [__real@437f0000 (07FEF20BB370h)] int32 roundedMinY = roundReal32ToInt32( minY ); 000007FEF2061047 F3 0F 2C FA cvttss2si edi,xmm2 int32 roundedMaxX = roundReal32ToInt32( maxX ); 000007FEF206104B F3 0F 58 DC addss xmm3,xmm4 roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF206104F F3 0F 59 C1 mulss xmm0,xmm1 000007FEF2061053 85 FF test edi,edi 000007FEF2061055 0F 48 F8 cmovs edi,eax 000007FEF2061058 F3 0F 58 C4 addss xmm0,xmm4 int32 roundedMaxX = roundReal32ToInt32( maxX ); 000007FEF206105C F3 44 0F 2C D3 cvttss2si r10d,xmm3 roundedMinX = 0; } if ( roundedMinY < 0 ) { roundedMinY = 0; } if ( roundedMaxX > buffer->width ) { 000007FEF2061061 44 3B 53 08 cmp r10d,dword ptr [rbx+8] roundedMinX = 0; } if ( roundedMinY < 0 ) { roundedMinY = 0; } if ( roundedMaxX > buffer->width ) { 000007FEF2061065 44 0F 4F 53 08 cmovg r10d,dword ptr [rbx+8] roundedMaxX = buffer->width; } if ( roundedMaxY > buffer->height ) { 000007FEF206106A 3B 4B 0C cmp ecx,dword ptr [rbx+0Ch] roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF206106D F3 4C 0F 2C D8 cvttss2si r11,xmm0 roundedMaxX = buffer->width; } if ( roundedMaxY > buffer->height ) { 000007FEF2061072 0F 4F 4B 0C cmovg ecx,dword ptr [rbx+0Ch] roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF2061076 41 C1 E3 08 shl r11d,8 000007FEF206107A F3 0F 10 44 24 38 movss xmm0,dword ptr [g] 000007FEF2061080 F3 0F 59 C1 mulss xmm0,xmm1 000007FEF2061084 F3 0F 58 C4 addss xmm0,xmm4 000007FEF2061088 F3 48 0F 2C C0 cvttss2si rax,xmm0 000007FEF206108D F3 0F 10 44 24 40 movss xmm0,dword ptr [b] 000007FEF2061093 F3 0F 59 C1 mulss xmm0,xmm1 000007FEF2061097 44 0B D8 or r11d,eax 000007FEF206109A F3 0F 58 C4 addss xmm0,xmm4 000007FEF206109E 41 C1 E3 08 shl r11d,8 000007FEF20610A2 F3 48 0F 2C C0 cvttss2si rax,xmm0 000007FEF20610A7 44 0B D8 or r11d,eax uint64 start = __rdtsc( ); uint8* leftSideStart = ( uint8* ) buffer->memory + roundedMinY * buffer->pitch + roundedMinX * buffer->bytesPerPixel; 000007FEF20610AA 8B 43 14 mov eax,dword ptr [rbx+14h] 000007FEF20610AD 41 0F AF C1 imul eax,r9d 000007FEF20610B1 48 63 D0 movsxd rdx,eax 000007FEF20610B4 8B 43 10 mov eax,dword ptr [rbx+10h] 000007FEF20610B7 0F AF C7 imul eax,edi 000007FEF20610BA 48 98 cdqe 000007FEF20610BC 48 03 D0 add rdx,rax 000007FEF20610BF 48 03 13 add rdx,qword ptr [rbx] for ( int y = roundedMinY; y < roundedMaxY; y++ ) { 000007FEF20610C2 3B F9 cmp edi,ecx 000007FEF20610C4 7D 29 jge drawRectangle+0EFh (07FEF20610EFh) roundedMaxY = buffer->height; } uint32 color = ( roundReal32ToUInt32( r * 255.0f ) << 16 ) | ( roundReal32ToUInt32( g * 255.0f ) << 8 ) | ( roundReal32ToUInt32( b * 255.0f ) << 0 ); 000007FEF20610C6 2B CF sub ecx,edi 000007FEF20610C8 44 8B C1 mov r8d,ecx 000007FEF20610CB 0F 1F 44 00 00 nop dword ptr [rax+rax] for ( int x = roundedMinX; x < roundedMaxX; x++ ) { 000007FEF20610D0 45 3B CA cmp r9d,r10d for ( int x = roundedMinX; x < roundedMaxX; x++ ) { 000007FEF20610D3 7D 0E jge drawRectangle+0E3h (07FEF20610E3h) uint32* pixel = ( uint32* ) leftSideStart; 000007FEF20610D5 41 8B CA mov ecx,r10d 000007FEF20610D8 41 8B C3 mov eax,r11d 000007FEF20610DB 48 8B FA mov rdi,rdx 000007FEF20610DE 41 2B C9 sub ecx,r9d 000007FEF20610E1 F3 AB rep stos dword ptr [rdi] ( *pixel ) = color; pixel++; } leftSideStart += buffer->pitch; 000007FEF20610E3 48 63 43 10 movsxd rax,dword ptr [rbx+10h] 000007FEF20610E7 48 03 D0 add rdx,rax 000007FEF20610EA 49 FF C8 dec r8 000007FEF20610ED 75 E1 jne drawRectangle+0D0h (07FEF20610D0h) } uint64 end = __rdtsc( ); uint64 diff = end - start; } 000007FEF20610EF 48 8B 5C 24 08 mov rbx,qword ptr [buffer] 000007FEF20610F4 48 8B 7C 24 10 mov rdi,qword ptr [minX] 000007FEF20610F9 C3 ret |
1 | volatile uint64_t diff = end - start; |
1 2 | static volatile uint64_t diff; diff = end - start; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | char pdbLockFullPath[ WIN32_STATE_FILE_NAME_COUNT ]; win32BuildExePathFileName( &state, "pdb.lock", pdbLockFullPath ); ... FILETIME dllWriteTime = win32GetLastWriteTime( sourceGameCodeDllFullPath ); if ( CompareFileTime( &dllWriteTime, &game.dllLastWriteTime ) != 0 ) { DWORD attributes = GetFileAttributes( pdbLockFullPath ); if ( attributes == INVALID_FILE_ATTRIBUTES ) { win32UnloadGameCode( &game ); game = win32LoadGameCode( sourceGameCodeDllFullPath, tempGameCodeDllFullPath ); } } |
1 2 3 4 5 6 | ... echo lock > pdb.lock cl %commonCompilerFlags% ..\code\handmade.cpp -LD -link -INCREMENTAL:NO -PDB:handmade_%random%.pdb -EXPORT:gameGetSoundSamples -EXPORT:gameUpdateAndRender del pdb.lock cl %commonCompilerFlags% ..\code\win32_handmade.cpp /link %commonLinkerFlags% ... |
1 2 3 4 5 6 7 | Visual Studio DLL Project Properties -> Build Events -> Pre-Link Event Command Line: echo lock > $(OutputPath)pdb.lock Post-Build Event Command Line: del $(OutputPath)pdb.lock |