Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Elliott Lee Newsgroups: scee.yaroze.beginners Subject: Re: Questions about VSync. Date: Mon, 04 May 1998 13:48:15 -0700 Organization: Cisco Systems Lines: 82 Message-ID: <354E298F.2865CC25@netmagic.net> References: <354C8851.709D2E83@chowfam.demon.co.uk> <6ij6jd$jpr18@chuka.playstation.co.uk> <354D8AA7.17CA37C6@chowfam.demon.co.uk> Reply-To: tenchi@cisco.com NNTP-Posting-Host: dhcp-e-39-237.cisco.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; U) James Chow wrote: [...] > I thought a vsync was the time taken to get from bottom right to the > bottom right again. > > (a)-------------->(b) > (c)-------------->(d) > .... > (e)-------------->(f) > > The tv traces the beam from (a) to (b), then jumps to (c) and traces to > (d), > and repeats this until (f). At this point the beam goes back to (a) to > repeat this process. > > Is the time for a hsync, > (1) the time it takes for the beam to trace a horizontal, ie (c) to (d), > (2) or the time since the last hysnc, ie (b) to (d)? > And the time for a vsync, > (3) (f) to (a), > (4) (f) back to (f), > The way you have explained it seems to give (1) and (3). > Is this correct? > I thought a vsync was (4). [...] You're close. The TV does trace like something like that. Assume an NTSC config w/ 240 lines per screenful: 0 1 2 ... 320 0 --------------> 1 --------------> 2 --------------> 3 --------------> : : 240 --------------> The ray gun hits the RGB strips on the screen for each pixel and goes from row to row. There is a "vertical retrace period" where the gun shuts off and travels from (320,240) back up to (0,0) to begin redrawing the next frame. That short period is actually pretty long (in terms of computer speed) and that's the best time to do a logical video page flip/swap. When the ray gun begins its retrace, an interrupt is set off in the Yaroze CPU and _that's_ what the VSync() function is waiting for. A VSync of 0 means that the VSync() function just waits for the vertical retrace interrupt. A value of 1 means that VSync waits for the 2nd interrupt. So, on a PAL system, if you wait for VSync(50), you will have caused VSync() to wait 1 full second while 50 video frames (and interrupts) have gone by. So your program goes along making its calculations, the GPU does its drawing, and all this stuff ends up somewhere in memory. Then you use the VSync() function to wait until the ray gun begins its retrace. At that point, you swap the Gs buffers, clear your order table, etc. etc. etc. And the return values for calling VSync(mode): - if mode>=0: the number of horizontal sync units should be returned. If I understand the docs correctly, this should probably be the total number of horizontal lines from the top of the screen to the bottom, including the lines before and after the visible screen data. This may also include some bogus horizontal retrace period interrupts triggered during the retrace period---the ray gun doesn't always travel in a straight line back to (0,0). - if mode<0: the number of horizontal syncs since the beginning of the program. As far as I can tell, the number of h-syncs is probably not a good way to time your program because you only get that value after every v-sync. You shouldn't really switch the video pages until the vertical retrace begins. And, getting an arbitrary time is probably not that useful because drawing the graphics with the GPU will take different amounts of time depending on the complexity of the scene you are rendering... - e! tenchi@netmagic.net http://www.netmagic.net/~tenchi/yaroze/