After doing simple profiling, I know that it happens on a precise call of glBufferData. The application is doing the exact same thing during all the frames: rendering 2 rectangles, rendering 4 strings, and outputting sound. The time spike happens on the glBufferData call that sends vertex and uvs data for the 4th string (all strings go through the same code, but I store the profiler timing values for each one separated).
Does anyone has any idea of what could be causing this ?
Here is an overview of how the code works:
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 | while ( running ) { initCommandBuffer( ); handleInput( ); simulation( ); outputAudio( ); renderCommandBuffer( ); swapBuffer( ); } void initCommandBuffer( ){ glDeleteBuffers( ); // with buffers used in the previous frame. // Set the number of commands and commands data to 0. } void renderCommandBuffer( ){ for ( commands ) { glGenBuffers( ); glBindBuffer( vertex ); shaderSetup( ); glBufferData( vertex, GL_STATIC_DRAW ); glBindBuffer( index ); glBufferData( index, GL_STATIC_DRAW ); glEnable( GL_PRIMITIVE_RESTART ); glDrawElements( GL_TRIANGLE_STRIP ); } } |
Here are the profiling values. All the values bellow are from an unoptimized build launched in visual studio 2012 to clearly show the problem. If I run outside of visual studio or build with optimizations, the spike is still there but smaller (missing 1 frame instead of 10) and always on the same frame. If I remove the rendering of the 4th string, the spike happens at a latter frame.
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 | // fi = frame index // cyc = total cycles (__rdtsc difference) for the frame // sim = cycles for the simulation // ren = cycles for the rendering // syn = cycles for vsync // fi: 740 cyc: 46428064 sim: 21400025 ren: 1094274 syn: 23933106 // fi: 741 cyc: 46627764 sim: 22217575 ren: 1048855 syn: 23360148 // fi: 742 cyc: 46564577 sim: 22059713 ren: 958719 syn: 23545474 // fi: 743 cyc: 46048741 sim: 22540901 ren: 900595 syn: 22606731 // fi: 744 cyc: 46916673 sim: 22182977 ren: 949184 syn: 23783882 // fi: 745 cyc: 511899266 sim: 21164771 ren: 458690424 syn: 32043306 // Partial frame details from the rendering part // sf : total cycles // ss : cycles before sv // sv : cycles for glBufferData for the vertex // sb : cycles between sv and si // si : cycles for glBufferData for the indices // se : cycles after si // // string1 // fi: 744 sf: 32629 ss: 27189 sv: 714 sb: 2220 si: 226 se: 2063 // fi: 745 sf: 33385 ss: 27735 sv: 714 sb: 2210 si: 231 se: 2273 // string2 // fi: 744 sf: 325274 ss: 16548 sv: 17488 sb: 3869 si: 225356 se: 61793 // fi: 745 sf: 120346 ss: 16422 sv: 16091 sb: 2368 si: 26607 se: 58632 // string3 // fi: 744 sf: 112718 ss: 34508 sv: 24266 sb: 3376 si: 29558 se: 20716 // fi: 745 sf: 105267 ss: 32271 sv: 19798 sb: 16238 si: 16207 se: 20491 // string4 // fi: 744 sf: 98207 ss: 27195 sv: 29694 sb: 5975 si: 18443 se: 16648 // fi: 745 sf: 458054436 ss: 25746 sv: 457858831 sb: 11205 si: 15747 se: 142392 |