BBC BASIC for Windows
« GFXLIB »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:48pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 ... 5 6 7 8 9  Notify Send Topic Print
 veryhotthread  Author  Topic: GFXLIB  (Read 2170 times)
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: GFXLIB
« Reply #90 on: Jun 9th, 2009, 08:52am »

Quote:
I thought I was operating on two pixels in parallel

Because of the processor's superscalar architecture, it's entirely possible your non-MMX version was processing "two pixels in parallel" too. Anyway, as I said, they may both have been memory-bandwidth bound, in which case the speed would be much the same.

Quote:
The ADC instruction in the non-MMX routine is quite an execution speed killer, it would seem.

As I expect you appreciate, it's not that ADC is particularly slow but it's because of the dependencies it introduces. You have to think of the effect of the instruction not on its own, but in the context of the instructions which surround it.

In this particular case the main significance is that since adc ebp,0 depends on the state of the carry flag, and since the preceding shr ebp,24 affects the carry flag, the two instructions are forced to be serialised and run on the same execution unit.

I expect that, when you remove the ADC, it gives the processor more opportunity to take advantage of out-of-order execution, and of scheduling instructions on the different execution units. Therefore the speed improvement is disproportionate to the time taken by the ADC in isolation.

It's for this kind of reason that modern compilers can sometimes beat 'hand assembly' for speed. They understand (better than the average human programmer!) the internal architecture of the CPU, and when it can be of benefit to change the sequence of instructions to improve performance even if the clarity of the code suffers.

Whether a similar issue explains the 'anomalous' speed difference between your two non-MMX versions I can't say, but it may do.

Quote:
Anyway, Richard, your MMX-powered alphablending routine would be a fine and very welcome addition to GFXLIB (if I may !?).

Of course you may, with the appropriate grovelling acknowledgement!!

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #91 on: Jan 1st, 2010, 6:57pm »

http://www.bb4w-games.com/bb4wprogs/superposealphamapdemo.zip

This demo employs a few new(-ish) GFXLIB routines:

* Richard's MMXAlphaBlend
* PlotBlendLD (LD = Luminosity-Dependent)
* MMXScale2X -- fast 2x scaling of a bitmap
* SuperposeAlphaMap -- Superposes (or should that be Superimposes?) an alpha map (or mask) over a bitmap
* BoxBlur3x3

This is all rather burdensome for the CPU, and I'm sure a similar effect can be achieved much more efficiently by other means, but really the point of the demo is to er... demonstrate SuperposeAlphaMap.


Regards,
David.
« Last Edit: Jan 18th, 2012, 5:05pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #92 on: Jan 2nd, 2010, 07:59am »

This one's a little bit prettier:

http://www.bb4w-games.com/bb4wprogs/superposealphamapdemo2.zip -- (1.3 MB)


David.
--
« Last Edit: Jan 18th, 2012, 5:05pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #93 on: Jan 9th, 2010, 8:38pm »

Another day, another GFXLIB routine.

This one's called PlotRearrangeInvertRGB.

(Yikes !)

It rearranges the RGB colour components of every non-black pixel in a given bitmap, and then inverts the specified RGB components, then plots the pixel.

Code:
SYS GFXLIB_PlotRearrangeInvertRGB%, dispVars{}, bmAddr, bmW, bmH, x, y, rgbRearrangementCode, rgbInversionFlags 


The RGB rearrangement parameter is an integer in the range 0 to 5:

0. RGB (no rearrangement)
1. RBG
2. GRB
3. GBR
4. BRG
5. BGR


The RGB inversion flags parameter:

bit 0 ---> invert Red value
bit 1 ---> invert Green value
bit 2 ---> invert Blue value

So supplying a value of 1 for the inversion flags parameter will result in the red channel being inverted, 6 would result in both green and blue channels being inverted, etc.

Here's a demo of the routine (the above colour-transforming operation is applied in real-time in this program):

http://www.bb4w-games.com/bb4wprogs/plotrearrangeinvertrgb_demo.zip


Below is the original, unadulterated 64x64 ball bitmap (from the demo):

User Image


I may soon post a question in the Assembly Language section on what is the fastest possible way of rearranging and/or inverting RGB components of a pixel, because I'm probably doing it in one of the slowest ways.


Regards,
David.

« Last Edit: Jan 18th, 2012, 5:05pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #94 on: Jan 11th, 2010, 9:49pm »

Just coloured balls with blurred trails:

http://www.bb4w-games.com/bb4wprogs/blurredcolouredballs.zip
-- (92 Kb)

The colouring is done with PlotRearrangeInvertRGB, and the blurring is achieved with Michael Hutton's fast blurring routine.


David.
« Last Edit: Jan 18th, 2012, 5:04pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #95 on: Feb 6th, 2010, 10:01am »

Thought I'd post this as it looks quite pretty (and uses not much CPU bandwidth):

http://www.bb4w-games.com/bb4wprogs/plotpixellist3_ex4.zip

Yes, OK, the Bézier curves are precalculated, but only because if they had to be calcluated in real time (in BASIC), the CPU usage would shoot right up (to ~50% on my laptop). The actual plotting of the curves takes next-to-no time.

What's supposed to be being demonstrated here is a new (but not terribly exciting) GFXLIB routine PlotPixelList3, which is faster and more flexible than the first two.

Interested folks might like to keep an eye on this page over the coming weeks:

http://www.bb4w-games.com/gfxlib2/gfxlib2page.html


Regards,
David.
« Last Edit: Jan 18th, 2012, 5:03pm by David Williams » User IP Logged

81RED
Guest
xx Re: GFXLIB
« Reply #96 on: Feb 6th, 2010, 10:34am »

on Feb 6th, 2010, 10:01am, David Williams wrote:
http://www.bb4w-games.com/gfxlib2/gfxlib2page.html

Yay!

Any benefits to be gained from recoding my stuff to use the new version (other than smaller code, which does not bother me), or is that better left off until my next project actually happens?

Simon

P.S. Weren't you supposed to be in rehab? wink
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #97 on: Feb 6th, 2010, 11:29am »

on Feb 6th, 2010, 10:34am, Simon Mathiassen wrote:
Yay!

Any benefits to be gained from recoding my stuff to use the new version (other than smaller code, which does not bother me), or is that better left off until my next project actually happens?


Not really. The routines may have been 'modularized', but they haven't (yet) been optimized or improved in any other way.

A multicore version of the 'workhorse' routine BPlot - the one you'd normally use to draw backgrounds - may be in the pipeline. Whilst I doubt that four cores would necessarily translate to "four times faster" (which would be nice), BPlot (and Plot, as it happens) are such frequently used routines that it may be worthwhile trying to produce multicore/multithreading versions of them. The skills of Michael Hutton and/or Richard may (or rather, will) be indispensable here.

(Not that I would ever take either of them for granted, let me just say.)


on Feb 6th, 2010, 10:34am, Simon Mathiassen wrote:
P.S. Weren't you supposed to be in rehab? wink


I evidently appear to be slipping.


Regards,
David.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #98 on: Feb 11th, 2010, 9:49pm »

Here is a simple demo of a new routine called DrawTileMap:

(Use the arrow keys to move around)

http://www.bb4w-games.com/bb4wprogs/tilemapdemo1.zip


Using DrawTileMap is simplicity itself. First you need a set of tile bitmaps (all of the same dimensions - 64x64 is quite typical). Then you create a tile map using a map editor (a simple one will ship with GFXLIB 2). Then once you've installed and initialised GFXLIB 2, DrawTileMap and TileMapFunctions, and loaded the tile map with PROCLoadTileMap, you draw the portion of the map you wish to display using:

Code:
SYS GFXLIB_DrawTileMap%, dispVars{}, mapInfo{}, x%, y% 


Simple as that.

Something to look forward to, right?


Regards,

David.



PS. There will be a number of routines for converting between screen and map world coordinates, and routines intended for the purposes of collision detection. In fact, the following routines are already in place (with lots more to come):

Code:
GFXLIB_TMConvertScrCoordsToWorldCoords%        | *mapInfoStruc{}, scrX%, scrY%, *worldX%, *worldY%
GFXLIB_TMConvertWorldCoordsToScrCoords%        | *mapInfoStruc{}, worldX%, worldY%, *scrX%, *scrY%
GFXLIB_TMConvertScrCoordsToWorldCoordsF64%     | *mapInfoStruc{}, *scrX#, *scrY#, *worldX%, *worldY%
GFXLIB_TMConvertWorldCoordsToScrCoordsF64%     | *mapInfoStruc{}, *worldX#, *worldY#, *scrX%, *scrY%
GFXLIB_TMGetTileIndexAtWorldPos%               | *mapInfoStruc{}, worldX%, worldY% (returns tile index in EAX)
GFXLIB_TMGetTileIndexAtScrPos%                 | *mapInfoStruc{}, scrX%, scrY% (returns tile index in EAX)
GFXLIB_TMGetPixelAtWorldPos%                   | *mapInfoStruc{}, worldX%, worldY% (returns 32-bit ARGB pixel in EAX)
GFXLIB_TMGetPixelAlphaValueAtWorldPos%         | *mapInfoStruc{}, worldX%, worldY% (returns 8-bit alpha value in EAX)
GFXLIB_TMTestPixelAlphaBitAtWorldPos%          | *mapInfoStruc{}, worldX%, worldY%, testBit% (returns 0 or 1 in EAX)
 
« Last Edit: Jan 18th, 2012, 5:03pm by David Williams » User IP Logged

Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Re: GFXLIB
« Reply #99 on: Feb 12th, 2010, 02:12am »

Very nifty piece of work!

My question is: What do the * mean in

*mapInfoStruc{}, *worldX#, *worldY#, *scrX%, *scrY%

I presume they are not C++ pointers?! Or is this a new type of BB4W addressing mode I haven't come accross? wink

Michael
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #100 on: Feb 12th, 2010, 02:49am »

on Feb 12th, 2010, 02:12am, Michael Hutton wrote:
My question is: What do the * mean in

*mapInfoStruc{}, *worldX#, *worldY#, *scrX%, *scrY%

I presume they are not C++ pointers?! Or is this a new type of BB4W addressing mode I haven't come accross? wink


Actually, I don't think it was correct of me to prefix mapInfoStruc{} with an asterisk.

Yes, an asterisk indicates that the parameter is a pointer to a memory location that contains (or is to contain) either an integer or a 64-bit float.

I realise that 32-bit floats can be supplied 'directly' using FN_f4, but it's probably not suitable for heavy use within a game loop.

By the way, those comments are really just notes to myself. I don't normally use asterisks to indicate pointer variables! I might from now on, though.


Regards,

David.
User IP Logged

Richard Russell
Guest
xx Re: GFXLIB
« Reply #101 on: Feb 12th, 2010, 08:11am »

on Feb 12th, 2010, 02:49am, David Williams wrote:
I don't normally use asterisks to indicate pointer variables! I might from now on, though.

Is there a particular reason why you don't use ^, to reflect the syntax you'd use if calling the routine from BASIC?

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #102 on: Feb 12th, 2010, 3:05pm »

on Feb 12th, 2010, 08:11am, Guest-Richard Russell wrote:
Is there a particular reason why you don't use ^, to reflect the syntax you'd use if calling the routine from BASIC?


Perhaps I suffered a momentary lapse of common sense.

undecided


David.
User IP Logged

81RED
Guest
xx Re: GFXLIB
« Reply #103 on: Feb 14th, 2010, 7:19pm »

on Feb 11th, 2010, 9:49pm, David Williams wrote:
Code:
SYS GFXLIB_DrawTileMap%, dispVars{}, mapInfo{}, x%, y% 


Simple as that.

Something to look forward to, right?


Bloody hell! That looks VERY useful indeed.
Am I correct in guessing your experiences coding Crystal Hunter II had something to do with it?

Simon
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: GFXLIB
« Reply #104 on: Feb 15th, 2010, 01:36am »

on Feb 14th, 2010, 7:19pm, Simon Mathiassen wrote:
Bloody hell! That looks VERY useful indeed.
Am I correct in guessing your experiences coding Crystal Hunter II had something to do with it?

Simon


No, I don't think so.

In addition to those tile map-related routines, I've started work on a new library called GAMEOBJLIB (Game Object Library), although don't be too surprised if the final release version is called something else. It's aim (whether it'll be achieved or not) is to simplify and speed up the development of 2D games, especially ones with extended 'worlds' - such as scrolling platformers, shoot-'em-ups, etc. I'll probably have some demos of it in action soon.


Regards,
David.

User IP Logged

Pages: 1 ... 5 6 7 8 9  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls