Screen Pointer Update glitch

GFA, ASM, STOS, ...

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 335
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Screen Pointer Update glitch

Postby Orion_ » Thu Jun 29, 2017 6:37 pm

I'm coding a little demo and because my code is a bit slow, I use the triple buffering technique which allow to start writing my next screen even if the next screen to show up is not already starting to be drawn by the TV.
But, because of this I don't wait for the next VBL, I just set the new screen address at any time, and it appears to make some glitches sometimes, the screen seems garbled, I suppose this is because the new screen address is set at the wrong time (for example when the screen address is set during the next frame switch ?)
how can I avoid this ?
how can I detect when the screen is going to switch to the next frame, and wait for this before setting the new screen address ?

thank you.

User avatar
Cyprian
Atari God
Atari God
Posts: 1405
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Screen Pointer Update glitch

Postby Cyprian » Thu Jun 29, 2017 7:08 pm

use VBL to ether change screen address or inform your routine about a new VBL.
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Aranym / Steem / Saint
http://260ste.appspot.com/

User avatar
npomarede
Atari God
Atari God
Posts: 1178
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Screen Pointer Update glitch

Postby npomarede » Thu Jun 29, 2017 9:27 pm

Hi
this is not a very known fact, but video address on STF is in fact reloaded at HBL 310 (3 HBL before next VBL starts at 50 Hz), not at start of VBL. So, if you set your new screen address as soon as the VBL starts, it's too late and this new address will in fact be used to display the next frame at VBL 'n+1', not the current frame at VBL 'n'.

So,depending on whether your program sets the new address before of after HBL 310, then it will be taken or not into account. If it's not taken into account, you will display the same screen a 2nd time and if you already start to draw on this screen then the partial result will be displayed.

As cyprian told, always set your next screen into VBL (to handle the rotation between your 3 addresses of triple buffering), but take into account that when doing so the new address will be used for the next displayed frame.

Nicolas

mikro
Atari God
Atari God
Posts: 1308
Joined: Sat Sep 10, 2005 11:11 am
Location: Brisbane, Queensland, Australia
Contact:

Re: Screen Pointer Update glitch

Postby mikro » Thu Jun 29, 2017 10:57 pm

Orion_ wrote:But, because of this I don't wait for the next VBL, I just set the new screen address at any time.

Well, this is exactly the use case why one wants to use triple buffer, no need for further tricks. ;) So triple buffer -- good, writing screen address anytime -- bad.

Double buffer works like this:
logical screen pointer <-- here you write
physical screen pointer <-- this is shown
...
now you're done with writing, you call Vsync() and swap the pointers

Triple buffer works like this:
logical screen pointer no.1 <-- here you write
logical screen pointer no.2 <-- this is unused right now
physical screen pointer <-- this is shown
...
now you're done with writing, you do not call Vsync but just exchange logical pointer no.1 & no.2. So where do set your screen address you ask? In VBL. Of course, this assumes that your effect always takes more than one VBL. In practice it's actually quite easy because the exchange is actually a rotation:

lea screen_adr1,a0
move.l (a0),d0
move.l 4(a0),(a0)+
move.l 4(a0),(a0)+
move.l d0,(a0)

and the VBL routine looks like this:

move.l screen_adr1,d0
cmp.l .var,d0
beq.s .noset
move.l d0,.var

.set:
move.l d0,d1
lsr.w #8,d0
move.l d0,$ffff8200.w
move.b d1,$ffff820d.w

.noset:
...

screen_adr1: ds.l 1 ;screen address 1
screen_adr: ;WORK ADDRESS!
screen_adr2: ds.l 1 ;screen address 2
screen_adr3: ds.l 1 ;screen address 3

(courtesy of DHS demosystem)

User avatar
Orion_
Captain Atari
Captain Atari
Posts: 335
Joined: Sat Jan 10, 2004 12:20 pm
Location: France
Contact:

Re: Screen Pointer Update glitch

Postby Orion_ » Fri Jun 30, 2017 11:41 am

I tried this (I'm working on ST)
but as npomarede mentioned, and as I already noticed, when setting the new screen address in the VBL interrupts, the new screen address seems to be valid only for the next frame, and not the one that will be drawn at this VBL.
even setting the address in the VBL, I had flickering on one of my effects that was taking around 1.25 VBL to complete, I don't quite understand why, I solved it using 4 buffers swap instead of 3 .. (brute force way of solving things, but well ...)

User avatar
npomarede
Atari God
Atari God
Posts: 1178
Joined: Sat Dec 01, 2007 7:38 pm
Location: France

Re: Screen Pointer Update glitch

Postby npomarede » Fri Jun 30, 2017 11:57 am

Triple buffer should be enough, but if your effect sometimes takes 1.25 VBL or more, then you must also handle the fact that you should not "rotate" the 3 buffers until you really finished drawing a complete frame.
Which means that sometimes you must display the same buffer twice on screen ; else, sooner or later, you will end up writing in the buffer you're displaying at the same time.

User avatar
leonard
Moderator
Moderator
Posts: 640
Joined: Thu May 23, 2002 10:48 pm
Contact:

Re: Screen Pointer Update glitch

Postby leonard » Thu Jul 13, 2017 10:52 pm

And if your frame rate has huge amplitude, you could generalize the algorithm to <n screen buffering> as in famous European demo 3D screen. I think they use 8 screens if I remind well.
Leonard/OXYGENE.


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: No registered users and 2 guests