Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Fast CLS routine  (Read 6076 times)

0 Members and 2 Guests are viewing this topic.

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Fast CLS routine
« on: November 30, 2009, 09:23:32 PM »

' Fast CLS by Kev G.
'
' This is a replacement for the AMOS/Pro CLS command. 68020+ cpu.
' 68000 users will not notice much difference but faster cpu owners will benefit (A1200 etc)
'
' It uses the cpu to clear the screen rather than the blitter. On a standard A1200 you
' can achieve a speed increase of 300%. If you are using a double buffered screen then you
' will have to set values for the LOGICAL planes as well as PHYSICAL planes.
'
Screen Open 0,320,256,8,Lowres : Flash Off : Curs Off : Ink 1,0 : Cls 0
'
Print "Press any key to start the test."
Wait Key
'
ITERATIONS=200
'
P0_PHYS=Phybase(0)
P1_PHYS=Phybase(1)
P2_PHYS=Phybase(2)
'
P0_END=P0_PHYS+10240
P1_END=P1_PHYS+10240
P2_END=P2_PHYS+10240
'
'First test.. AMOS CLS.
'
TIME1=Timer
For I=1 To ITERATIONS
    Cls 0
Next I
TIME2=Timer
TEST1=TIME2-TIME1
'
'Second test.. AMOS FILL
TIME1=Timer
For I=1 To ITERATIONS
    Fill P0_PHYS To P0_END,$0
    Fill P1_PHYS To P1_END,$0
    Fill P2_PHYS To P2_END,$0
Next I
TIME2=Timer
TEST2=TIME2-TIME1
'
' Print results....
'
Print "AMOS CLS  time = "+Str$(TEST1)+" (50ths/sec)"
Print "AMOS FILL time = "+Str$(TEST2)+" (50ths/sec)"
Print
Print "Press a key to end"
Wait Key

End
« Last Edit: November 30, 2009, 09:29:46 PM by KevG »
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: Fast CLS routine
« Reply #1 on: November 30, 2009, 11:08:01 PM »

Thanks Kev G!

One question I have is if it is possible to use both the CPU and the blitter at the same time to do a screen clear like this?  My understanding of the internal chipset timing is a bit fuzzy, but it would seem to me that it could be possible to set up the blitter to begin clearing a set number of bit planes and then use the CPU to clear the others concurrently.  What am I missing?
Logged
- Sidewinder

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Fast CLS routine
« Reply #2 on: December 01, 2009, 03:16:27 AM »

You'd have to call BlitBitMapRastPort using the PlanesPick parameter using a GfxCall command to be able to choose only some of the bitplanes to blit or the AMCAF extension allows something similar function.  You could CPU clear some of the bitplanes also though.
Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Fast CLS routine
« Reply #3 on: December 02, 2009, 05:09:05 AM »

Yes, it is possible if you have the Turbo Plus extension installed as it has a Blit Clear command.
This clears a bitplane using the blitter. What I suggest you try is alternate blitting and filling like this....

Blit Clear 1 - to clear the first plane
Fill  etc...
Blit Clear 3
Fill etc...
Blit Clear 5

If you blit first, then you can let the blitter get on with its job while you can carry on with cpu stuff. In theory you will save alot of time because while the blitter is working you can FILL.

I will try this tonight myself and let you know the results.

Logged

KevG

  • A600
  • *
  • Karma: 1
  • Offline Offline
  • Posts: 87
Re: Fast CLS routine
« Reply #4 on: December 05, 2009, 10:22:09 AM »

' Display Clear Test By Kev G. v2.0 - For The AMOS Factory
'
'
Screen Open 0,320,256,16,Lowres : Flash Off : Curs Off : Ink 1,0 : Cls 0
'
Print "Press any key to start the test."
Wait Key
'
Amos Lock
E=Execall(-132) : Rem disbale O.S.
'
ITERATIONS=100
'
P0_PHYS=Phybase(0)
P1_PHYS=Phybase(1)
P2_PHYS=Phybase(2)
P3_PHYS=Phybase(3)
'
P0_END=P0_PHYS+10240
P1_END=P1_PHYS+10240
P2_END=P2_PHYS+10240
P3_END=P3_PHYS+10240
'
'First test.. AMOS CLS.
'
TIME1=Timer
For I=1 To ITERATIONS
    Cls 0
Next I
TIME2=Timer
TEST1=TIME2-TIME1
'
'Second test.. AMOS FILL
TIME1=Timer
For I=1 To ITERATIONS
    Fill P0_PHYS To P0_END,$0
    Fill P1_PHYS To P1_END,$0
    Fill P2_PHYS To P2_END,$0
    Fill P3_PHYS To P3_END,$0
Next I
TIME2=Timer
TEST2=TIME2-TIME1
'
'Third test.. The Turbo Blit Clear command
TIME1=Timer
For I=1 To ITERATIONS
    Blit Clear -1
Next I
TIME2=Timer
TEST3=TIME2-TIME1
'
'Fourth Test.. The Turbo Blit + Fill Command
TIME1=Timer
For I=1 To ITERATIONS
    Blit Clear 1
    Fill P1_PHYS To P1_END,$0
    Blit Clear 3
    Fill P3_PHYS To P3_END,$0
Next I
TIME2=Timer
TEST4=TIME2-TIME1
'
' Print results....
'
Print "AMOS CLS  time    = "+Str$(TEST1)+" (50ths/sec)"
Print "AMOS FILL time    = "+Str$(TEST2)+" (50ths/sec)"
Print "TURBO BLIT time   = "+Str$(TEST3)+" (50ths/sec)"
Print "FILL + TURBO BLIT = "+Str$(TEST4)+" (50ths/sec)"
Print
Print "Press a key to end"
'  
E=Execall(-138) : Rem enable O.S.
Amos Unlock
'
Wait Key
End
'
' ********************
'      MY RESULTS
' ********************
'
' TEST 1 - A600 2MB Chip RAM
'
' AMOS CLS = 134
' AMOS FILL = 113
' TURBO BLIT = 86
' BLIT + FILL = 71
'
'
' TEST 2 - A1200 2MB Chip, 4MB Fast
'
' AMOS CLS = 133
' AMOS FILL = 30 !!!!!
' TURBO BLIT = 89
' BLIT + FILL = 43
'
'
' Conclusions from this test.
' There is no speed advantage using the turbo Blit command on its own or the AMOS CLS command.
' There was a slight improvement using a combination of BLIT + FILL.
' However, there is a massive improvement using the FILL command alone (A1200).
' If you are developing AMOS programs for the A1200 or above then use the FILL routine.
' If you need speed and compatibility with A500/A600 then go for BLIT + FILL
'
' The program was compiled and the resulting executable file was used for this test.
' All times are in 50ths of a second. Less is better.
« Last Edit: December 05, 2009, 10:28:45 AM by KevG »
Logged

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Fast CLS routine
« Reply #5 on: December 05, 2009, 05:36:00 PM »

If the AGA chipset weren't opened in 16-bit compatibility mode, the blitter would be 4 times faster than it is now on the A1200.  I've really got to get something done on AGA compatibility for AmosPro.   :(

-edit-
The CPU clear also assumes you have 32-bit access between the CPU and the Chip RAM.  This is only the case on A1200, A3000, and A4000.
« Last Edit: December 05, 2009, 05:39:52 PM by SamuraiCrow »
Logged

Volvo_0ne

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 71
  • A1200 lover
Re: Fast CLS routine
« Reply #6 on: November 15, 2015, 10:02:56 PM »

Can someone explain WHY speeding up CLS is advantageous unless you are needing to do it every vbl for some reason?

or is this just an exercise in coding?
Logged
Transuranic heavy elements may not be used where there is life.

SamuraiCrow

  • compile-time wierdo
  • Forum Mod
  • A1200
  • *****
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 946
  • Compile-time wierdo
Re: Fast CLS routine
« Reply #7 on: November 16, 2015, 04:06:40 PM »

Clearing a screen quickly is important for full-screen 3D animations.  Some computers even use triple-buffered displays so that the previous screen-buffer can be cleared by the blitter while the CPU computes the coordinates for the rendering of the next frame, thus freeing up blitter time for plotting polygons.

(Also, the blitter always uses 16-bit bus cycles on AGA, regardless of fetch rate.  That's the biggest, long-standing performance bug in AGA.)
Logged
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022