// File : profile.c // Coded by : Scotte // History : Created 12/03/00 17:13:03 // // Description : CPU and GPU profiling // // Notes : Uses root counter 1 to time code #include #include "profile.h" #include "fp.h" // Primitives used for the profile bars static GsBOXF bar; static GsLINE marker; // Draw time static volatile u_hword draw_count; // Profile object static sPROFILE profile; // Record time taken for GPU to render frame static void PROFILE_DrawTime(void); // Function : PROFILE_Initialise() // Coded by : Scotte // History : Created 12/03/00 17:21:30 // // Description : Set up the profiler // // Parameters : sw - screen width // sh - screen height // n - number of frames // // Returns : None // // Notes : None void PROFILE_Initialise(const u_hword sw,const u_hword sh,const u_hword n) { // Set the screen position of the profile bars profile.px=8; profile.py=sh-8-(BAR_H<<1); // Install GPU interrupt, to mark end of drawing EnterCriticalSection(); // Because the Yaroze libraries are so bollocks, we have no DrawSyncCallback() // I will have to find another way to do this... ExitCriticalSection(); // Time one frame VSync(0); mSetRCnt1_COUNT(0); VSync(0); profile.frametime=mGetRCnt1_COUNT(); // Scale the profile bars to fit the screen profile.nframes=n; profile.scale=mSETFP12_4S(sw-24)/(profile.frametime*profile.nframes); } // Function : PROFILE_Start() // Coded by : Scotte // History : Created 12/03/00 18:13:55 // // Description : Start profiling // // Parameters : None // // Returns : None // // Notes : None void PROFILE_Start(void) { profile.start_count=(u_hword)mGetRCnt1_COUNT(); profile.readings=0; } // Function : PROFILE_Read() // Coded by : Scotte // History : Created 12/03/00 18:14:53 // // Description : None // // Parameters : r,g,b - colour of profile bar // // Returns : None // // Notes : None void PROFILE_Read(const u_byte r,const u_byte g,const u_byte b) { if(profile.readings>1); for(i=1;i<=profile.nframes;i++) { // One frame marker x0+=step; marker.r=0xff; marker.g=0xff; marker.b=0xff; marker.x0=x0; marker.y0=profile.py-2; marker.x1=x0; marker.y1=profile.py+MARKER_H; GsSortLine(&marker,ot,0); // Half a frame marker marker.r=0x80; marker.g=0x80; marker.b=0x80; marker.x0=x1; marker.y0=profile.py; marker.x1=x1; marker.y1=profile.py+MARKER_H-2; GsSortLine(&marker,ot,0); x1+=step; } } // Function : PROFILE_DrawTime() // Coded by : Scotte // History : Created 12/03/00 19:51:54 // // Description : Time drawing // // Parameters : None // // Returns : None // // Notes : None static void PROFILE_DrawTime(void) { draw_count=0; } // Function : PROFILE_Frametime() // Coded by : Scotte // History : Created 14/03/00 22:18:55 // // Description : Get the time for one frame in scanlines // // Parameters : None // // Returns : Frame time // // Notes : None u_word PROFILE_Frametime(void) { // Time one frame VSync(0); mSetRCnt1_COUNT(0); VSync(0); return(mGetRCnt1_COUNT()); } // Function : PROFILE_Position() // Coded by : Scotte // History : Created 14/03/00 22:18:55 // // Description : Set the position of the profile bars // // Parameters : x,y - new screen position // // Returns : None // // Notes : None void PROFILE_Position(const u_hword x,const u_hword y) { profile.px=x; profile.py=y; }