Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HW image version of this little stupid thing
#21
(09-12-2023, 01:53 PM)TerryRitchie Wrote:
(09-12-2023, 01:45 AM)bplus Wrote: I never worked with Hardware images the Wiki for _copyimage didn't show an example in my quick scan.

I wonder if Terry's tutorial might have something?

Sorry, it doesn't. Something I need to add in the near future.

Looking forward to that day @TerryRitchie
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#22
(09-12-2023, 07:11 PM)TerryRitchie Wrote: It's well worth learning to use hardware images. Here is a little demo I just wrote showing the power of hardware images. This program creates 8000 sprites and then let's the user switch between software and hardware mode to see the performance difference. I'm going to start creating demos for a lesson on hardware vs software images in the tutorial. It's long overdue.

Keys:
H     - hardware mode
S     - software mode
ESC - leave program

Note: You may need to decrease the amount of objects depending on your system's performance. Change the TOTAL = 8000 to a lower number that doesn't crash the program.

...and the day has come Big Grin

@TerryRitchie this is a FANTASTIC example and we should put this in the damned wiki.

I wish the forum had some way to mark posts as notable or something and then a way to just see them in a list.

Thanks Terry!
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#23
(09-12-2023, 09:46 PM)SMcNeill Wrote: Try this little demo to showcase the difference in speed between Hardware Images and Software Images:

On my PC, I get about 100 FPS for the software image animation, and about 130,000 FPS for the hardware image animation.

I think that's enough to showcase a slight difference in the performance between the two.  Wink

Thanks @SMcNeill I was getting almost similar results. 80,000 or so in hardware and 80-90 in software.

This is on a 8 year old macbook pro from 2015.
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#24
(09-12-2023, 10:54 PM)grymmjack Wrote:
(09-12-2023, 01:21 PM)a740g Wrote: Made a few changes.

Code: (Select All)

ALIEN_SPRITE& = _NEWIMAGE(w% + 1, h% + 1, 256)
_DEST ALIEN_SPRITE&
PSET (0, 10)
DRAW ALIEN$
_CLEARCOLOR 0, ALIEN_SPRITE&
ALIEN_32& = _NEWIMAGE(w% + 1, h% + 1, 32)
_SOURCE ALIEN_SPRITE&: _DEST ALIEN_32&: _PUTIMAGE
ALIEN_HW& = _COPYIMAGE(ALIEN_32&, 33)

Thanks @a740g ! I was missing `_CLEARCOLOR 0` somehow, and that was the fix?

I don't quite understand that because the screen is `320x200` and the sprite is only `50x50` or so.

Why was the entire background black and not showing the blue?

Thanks again!
The `_CLEARCOLOR` is for the sprite transparency. I removed the `_DISPLAYORDER _HARDWARE` line. `_DISPLAYORDER _HARDWARE` will render hardware surfaces only. So, basically `CLS , _RGB32(0, 0, 255)` had no effect with that line.
Reply
#25
Very cool demo, Terry! What a difference using hardware images. I'm on an M1 Mac Mini and I cranked the sprite total up to 20,000. The program ran fine @ 7 FPS software and ~500 FPS hardware, though the hardware speed jumped back'n'forth from 1000 to 500 constantly. 

This will come in handy for the game I'm working on... Thanks!
Reply
#26
Thumbs Up 
SMcNeill, thanks for your demo too. Very helpful!
Reply
#27
(09-12-2023, 11:48 PM)a740g Wrote:
(09-12-2023, 10:54 PM)grymmjack Wrote:
(09-12-2023, 01:21 PM)a740g Wrote: Made a few changes.

Code: (Select All)

ALIEN_SPRITE& = _NEWIMAGE(w% + 1, h% + 1, 256)
_DEST ALIEN_SPRITE&
PSET (0, 10)
DRAW ALIEN$
_CLEARCOLOR 0, ALIEN_SPRITE&
ALIEN_32& = _NEWIMAGE(w% + 1, h% + 1, 32)
_SOURCE ALIEN_SPRITE&: _DEST ALIEN_32&: _PUTIMAGE
ALIEN_HW& = _COPYIMAGE(ALIEN_32&, 33)

Thanks @a740g ! I was missing `_CLEARCOLOR 0` somehow, and that was the fix?

I don't quite understand that because the screen is `320x200` and the sprite is only `50x50` or so.

Why was the entire background black and not showing the blue?

Thanks again!
The `_CLEARCOLOR` is for the sprite transparency. I removed the `_DISPLAYORDER _HARDWARE` line. `_DISPLAYORDER _HARDWARE` will render hardware surfaces only. So, basically `CLS , _RGB32(0, 0, 255)` had no effect with that line.

But without that, it's not using _HARDWARE images?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#28
(09-12-2023, 09:46 PM)SMcNeill Wrote:
(09-12-2023, 07:41 PM)TerryRitchie Wrote: The reason you're getting 1000 FPS in hardware mode is because that's the upper limit that can be calculated with TIMER(.001). Only when hardware is taxed enough will the frame rate drop below 1000. The program crashes for me when I try to go a few more than 8000 sprites. Perhaps someone with a better video card and more RAM can tax the hardware layer enough to start seeing the FPS drop below 1000 in hardware mode. (or someone has a better timing method I can use)

Try this little demo to showcase the difference in speed between Hardware Images and Software Images:

Code: (Select All)
DIM AS LONG HWscreen, SWscreen, DisplayScreen, TempScreen
DisplayScreen = _NEWIMAGE(1280, 720, 32)
SWscreen = _NEWIMAGE(64, 8, 32)
TempScreen = _NEWIMAGE(64, 8, 32)

'draw a few characters for screen display
_DEST TempScreen 'make a temp software screen to print on
_FONT 8 'size 8 font
_PRINTSTRING (0, 0), "Hardware" 'print the word "Hardware"
HWscreen = _COPYIMAGE(TempScreen, 33) 'make a copy of that temp screen as a hardware screen
_FREEIMAGE TempScreen 'free the temp screen


_DEST SWscreen 'Draw on a software screen
_FONT 8 'same size font 8
_PRINTSTRING (0, 0), "Software" 'And print the word Software on this screen
_DEST DisplayScreen
SCREEN DisplayScreen

HardwareMode = 0 'let's start out in software mode


xdirection = 1: ydirection = 1

DO

    IF TIMER > t# THEN
        IF FPS > maxFPS THEN maxFPS = FPS
        _TITLE "FPS:" + STR$(FPS) + " -- MaxFPS:" + STR$(maxFPS)
        t# = TIMER
        FPS = 0
    ELSE
        FPS = FPS + 1
    END IF

    x = x + xdirection
    y = y + ydirection
    IF x < 0 OR x > _WIDTH THEN xdirection = -xdirection
    IF y < 0 OR y > _HEIGHT THEN ydirection = -ydirection


    IF HardwareMode THEN
        _DISPLAYORDER _HARDWARE
        _PUTIMAGE (x, y), HWscreen
    ELSE
        _DISPLAYORDER _SOFTWARE
        CLS
        _PUTIMAGE (x, y), SWscreen, DisplayScreen
    END IF
    k = _KEYHIT
    SELECT CASE k
        CASE 27: SYSTEM
        CASE ASC("H"), ASC("h"): HardwareMode = -1: maxFPS = 0: FPS = 0
        CASE ASC("S"), ASC("s"): HardwareMode = 0: maxFPS = 0: FPS = 0
    END SELECT
    _DISPLAY
LOOP

On my PC, I get about 100 FPS for the software image animation, and about 130,000 FPS for the hardware image animation.

I think that's enough to showcase a slight difference in the performance between the two.  Wink
Doh, it never occurred to me to use a simple counter to keep track of frames. That's why Steve is the master Smile
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#29
(09-13-2023, 12:28 AM)NakedApe Wrote: Very cool demo, Terry! What a difference using hardware images. I'm on an M1 Mac Mini and I cranked the sprite total up to 20,000. The program ran fine @ 7 FPS software and ~500 FPS hardware, though the hardware speed jumped back'n'forth from 1000 to 500 constantly. 

This will come in handy for the game I'm working on... Thanks!
Thanks everyone for the feedback.

NakedApe, you were able to crank the count up to 20,000? Wowsers. I wonder why I can't get much past 8000? I have 32GB of RAM, a 6th gen i7 and a GTX960 video card with 4GB of VRAM. When I try, for example, 8500, the program crashes before a screen in even seen. I just assumed I was using too much video ram creating all those hardware sprites.

Jumping back and forth between 500 and 1000 FPS is because my frame counter is timer based. It's a hack at best. --> 1 / .001 = 1000, 1 / .002 = 500, etc..
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#30
(09-12-2023, 11:04 PM)grymmjack Wrote:
(09-12-2023, 07:11 PM)TerryRitchie Wrote: It's well worth learning to use hardware images. Here is a little demo I just wrote showing the power of hardware images. This program creates 8000 sprites and then let's the user switch between software and hardware mode to see the performance difference. I'm going to start creating demos for a lesson on hardware vs software images in the tutorial. It's long overdue.

Keys:
H     - hardware mode
S     - software mode
ESC - leave program

Note: You may need to decrease the amount of objects depending on your system's performance. Change the TOTAL = 8000 to a lower number that doesn't crash the program.

...and the day has come Big Grin

@TerryRitchie this is a FANTASTIC example and we should put this in the damned wiki.

I wish the forum had some way to mark posts as notable or something and then a way to just see them in a list.

Thanks Terry!
Yes, I agree, a demo showing the virtues of hardware images needs to be in the Wiki, be it this program or someone else's.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 1 Guest(s)