Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: How can I Alphablit on AmigaOS 3.x ?  (Read 5140 times)

0 Members and 1 Guest are viewing this topic.

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
How can I Alphablit on AmigaOS 3.x ?
« on: June 16, 2013, 09:03:46 AM »

If I get a Radeon 256MB gfx card and plug it into my Mediator A1200 then how can I do a hardware alphablit?

Is it possible?

Can SDL do hardware-assisted gfx card blitting on OS3?
Or is SDL all software rendered like it used to be?
Logged

SamuraiCrow

  • Administrator
  • Sr. Member
  • *****
  • Gender: Male
  • Posts: 379
  • Coolness is compiled
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #1 on: June 16, 2013, 10:26:03 PM »

I think you'd have to use AROS 68k for that to work.  AmigaOS 3.x doesn't have adequate alpha support in its drivers IIRC, but the latest AROS 68k probably does.

If you killed the palette cycling and used a spread palette on AGA, I could probably get you about 2 bits of alpha-blending using about 5+ passes of the blitter and 2 temprasts.  :P  Not very fast though.  1 bit of alpha could be implemented in about 3 passes of the blitter.
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #2 on: June 16, 2013, 11:15:40 PM »

If I used a spread palette then I could do the 75% 50% 25% alpha in the cpu.

I can actually do full blown alpha with the CPU on AGA using the same crappy palette we have its just that I would have to do P2C, C2P and pixel value lookups so it would be really slow and I couldn't do it realtime.  But for fx that only need to be calculated every once in a while I could do it.

I actually had planned this, for having torches and lanterns on the walls.   I would calculate a full alpha 0-255 fx for the brightness of the light on the floor and then draw the fx ONCE and it would stay there forever until the light source was broken (like by killing the wall, or casting a Dark Spell)

But then I came to my senses and said "screw all this p2c, c2p, table lookup crap, I will just port the game to chunky 32-bit first and then do all the fancy lighting fx" :)
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #3 on: June 24, 2013, 12:12:38 PM »

I just realized that for my software Alphablitting routines to be fast I need to
store the alpha value exactly opposite of BMP and PNG. So when the game engine
processes the gfx files it will have to invert the alphabyte.

Testing for 255 is slow. Testing for 0 is fast. I need most pixels to have a
0 in the AlphaByte so I can test really really fast to blast thru all the regular pixels as
quickly as possible.

Anywayz gfx dept does not need to worry about that. As long as you send in PNG
or BMP gfx files then I will handle it from there.

Maybe I can work out a trick so that it doesn't matter.  Like maybe flip the bits realtime with a NOT.B for free using the superscalar 68060?  1. It prob won't work.  2. If it does work on 060 it still slows down 030.   I could store a 255 in a register but I doubt I will have any free registers to waste for that.   Bottom Line: I most likely will MOVE the Alpha byte from where it is to a reg where I can make use of it.  When that happens I get a FREE test for 0.  I don't ever get a FREE test for 255.  So no matter how you slice it or dice it, storing the Alpha oppositely to how BMP and PNG does it will be faster, smaller, more efficient, less electricity, save the planet, etc. etc.

[rant]
Its just annoying that I have to do this inversion.  It should have been called "Transparency Byte" not "Opacity Byte" and it should have been stored so that normal pixels would have a 0 there and then software Alphablitting would be nice and fast and ez.

Its seems like a trick.  The first gfx card companies wanted to justify the high price of their hardware alpha blitting hardware so they rigged up timing tests to make it look like their hardware was faster than the software by a large margin.  But it was rigged because they stored the alphabytes using the inverted method that they knew would slow down software processing, while providing no advantages.
[/rant]
Logged

Veda

  • Hero Member
  • *****
  • Gender: Male
  • Posts: 1008
  • Sleep is overrated
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #4 on: June 24, 2013, 01:37:23 PM »

EORI.B $FF TCL?
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #5 on: June 24, 2013, 02:05:21 PM »

EORI.B $FF TCL?
I can do that and then say BEQ or BNE but the EORI.B is still wasted a 32-bit instruction.

EORI.B #$FF, Dx is not even a fast instruction on 030.  Fast instructions on 030 are 2 cycles but this one is 4 cycles.

The guy who asked for the alphablending has an 030.

On 68060 EORI.B #$FF is drop dead fast!  It is fully superscalar so it can execute in 0.5 cycles which is 8x faster than 030!

But EORI.B #$FF, Dx does not work for me because it destroys the Alpha!   I would have to copy it first which wastes an instruction and a register and 2 bytes.   CMPI.B would probably be better.

Or if I could get those 3 operand instructions I asked for then I could perform an EORI.B without destroying the Alpha.  But it would still waste a register.   And the encoding for 3 op instructions would be "large".
Logged

Veda

  • Hero Member
  • *****
  • Gender: Male
  • Posts: 1008
  • Sleep is overrated
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #6 on: June 25, 2013, 08:48:18 AM »

Code: [Select]
Chunky_32:
MOVE.L (A0)+, D0 ;Load 32bit chunky pixel
MOVE.B D0, D1 ;Store Blue
LSR.L #8, D0
MOVE.B D0, D2 ;Store Green
LSR.L #8, D0
MOVE.B D0, D3 ;Store Red
LSR.L #8, D0
CLR.L D7
CMP D7, D0 ;check for transparant
BEQ Chunky_32
MOVEQ #$FF, D6
EOR.B D6, D0 ;inverse
CMP D7, D0 ;check for opaque
BEQ Store
...

You get the gist of what i mean.(I am sure i missed something I rarely do hand assembly from the top of my head)
I prefer to be the read then to be the writer when it comes to ASM.(Give me C any day of the week)
IIRC it was something like multiplying by the inverse is the same as dividing.
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #7 on: June 25, 2013, 09:41:36 AM »

Code: [Select]
Chunky_32:
MOVE.L (A0)+, D0 ;Load 32bit chunky pixel
MOVE.B D0, D1 ;Store Blue
LSR.L #8, D0
MOVE.B D0, D2 ;Store Green
LSR.L #8, D0
MOVE.B D0, D3 ;Store Red
LSR.L #8, D0
CLR.L D7
CMP D7, D0 ;check for transparant
BEQ Chunky_32
MOVEQ #$FF, D6
EOR.B D6, D0 ;inverse
CMP D7, D0 ;check for opaque
BEQ Store
...

You get the gist of what i mean.(I am sure i missed something I rarely do hand assembly from the top of my head)
I prefer to be the read then to be the writer when it comes to ASM.(Give me C any day of the week)
IIRC it was something like multiplying by the inverse is the same as dividing.

Even if I wrote it using ur style it would still be faster and more efficient to just do it like this:
Code: [Select]
Chunky_32:
MOVE.L (A0)+, D0 ;Load 32bit chunky pixel
MOVE.B D0, D1 ;Store Blue
LSR.L #8, D0
MOVE.B D0, D2 ;Store Green
LSR.L #8, D0
MOVE.B D0, D3 ;Store Red
LSR.L #8, D0
;CLR.L D7
;CMP D7, D0 ;check for transparant
BEQ Chunky_32 ; Skip Invisible Pixels
;MOVEQ #$FF, D6
;EOR.B D6, D0 ;inverse
CMPI.B #$FF,D0  ; Check for 100% Opaque Pixel
BEQ Store  ; Straight Copy Over 100% Opaque Pixels
...
My version of your code saves 4 instructions and 2 registers.

But u have made me realize that I (probably) always have to check for both 100% invisible pixels and 100% solid pixels.

I had been sort of planning to skip the invisibility check because they will almost never be used.

But at some point some gfxmage will want to be able to use invisible pixels set with an alphamask so I might not be able to take a shortcut by skipping that part.  I just hate having all these cmp branch.  Oh well at least on 060 the invisible pixel branch will be correctly predicted as not taken which "only" takes 1 cycle.  I guess I will have to rearrange the code so that it is correctly predicted as taken which takes 0 cycles.

When the code runs on UAE JIT do I want the correctly predicted branches to be taken or not taken?  Which one is faster on intel?

Just curious.   I might make 2 versions of the routine, 1 for ARM (Amiga Real Machines) and another version for AVM (Amiga Virtual Machines) which is like a JVM only way kewler.  ;)
Logged

Veda

  • Hero Member
  • *****
  • Gender: Male
  • Posts: 1008
  • Sleep is overrated
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #8 on: June 25, 2013, 10:06:41 AM »

When i code i prefer the branch taken to be the shortest loop.
To be honest I am not even sure MOVE.B is better then a AND.B Masking but it saves a register access and trashing.

Code: [Select]
Chunk_16:
MOVEQ #$1F, D1
MOVEQ #$1F, D2
MOVEQ #$1F, D3
MOVE.W (A0)+, D0
AND.B D0, D1
LSR.W #5, D0
AND.B D0, D2
LSR.W #5, D0
AND.B D0, D3
LSR.W #5, D0
BEQ Chunky_16
...

I realized something silly.

Code: [Select]
MOVE.W (A0)+, D0
MOVE.W D0, D1
MOVEQ #15, D2
LSR.W D2, D1
BEQ label
would be faster
« Last Edit: June 25, 2013, 10:17:33 AM by Veda »
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #9 on: July 06, 2013, 10:58:50 AM »

I can't find any alphablitting routines anywhere in AmigaOS
I only found 1 routine in AROS:
http://aros.sourceforge.net/documentation/developers/autodocs/cgfx.php#writepixelarrayalpha

And it does not even say if it uses hardware acceleration on any hardware in the universe.

If it is just using a software routine then I can just use my own (faster) routine to do the same thing.

If I use my own selfcoded routines then my software will guaranteed work on Amiga Real Machines like A1200T, Amiga Virtual Machines like Winuae 3Ghz i5, MorphOS machines, OS4 machines, AROS machines, AmikitOS machines, ClassicWB machines, AmigaSYS machines, AIAB machines, etc. etc.
Logged

itix

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #10 on: July 23, 2013, 08:55:55 AM »

There are no alpha blitting routines in AmigaOS and even if it had it wouldnt be hardware accelerated. I solved this problem by writing my own WritePixelArrayAlpha() routine for AmigaOS. However please be aware that you must carefully design your alpha blits to not trigger reads from video memory.

This is like chip vs fast ram memory in good old times. For fast CPU access it is preferred to have your data in fast ram but for any blitter access it need to be in video memory.
Logged

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #11 on: July 23, 2013, 09:45:10 AM »

There are no alpha blitting routines in AmigaOS and even if it had it wouldnt be hardware accelerated. I solved this problem by writing my own WritePixelArrayAlpha() routine for AmigaOS. However please be aware that you must carefully design your alpha blits to not trigger reads from video memory.
I have been psychotically avoiding reads from video memory since 1990 when on my A3000.  I even coded a turbocharged version of cpublit back in those days.

I always always always always avoid all video memory reads and writes that can be avoided.  I have taken really extreme measures in this regard.


Doesn't MorphOS have any hardware accelerated alphablitting routines when running on those fancy Mac machines?

I don't mind using software routines to do normal blits, alpha blits and anything else.  That way I know exactly what is happening and I understand everything.

But sometimes it nice to have another method of doing things so I can race MethodA vs. MethodB.


Did you code your alphablitting routine for MOS in C or in PPC asm?

If its in asm then how much faster is it than the C version?

What is your opinion on the quality of GCC PPC output?


Logged

itix

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: How can I Alphablit on AmigaOS 3.x ?
« Reply #12 on: July 25, 2013, 10:53:08 AM »

Doesn't MorphOS have any hardware accelerated alphablitting routines when running on those fancy Mac machines?

There are but they operate with bitmaps only BltBitmapAlpha() etc.). WritePixelArrayAlpha() is altivec accelerated where available.

Quote
Did you code your alphablitting routine for MOS in C or in PPC asm?

It was written in C and was for 68k systems.

Quote
If its in asm then how much faster is it than the C version?

Often it wouldnt be much faster because CPU is faster than memory...

Quote
What is your opinion on the quality of GCC PPC output?

GCC 2: okay
GCC 3: okay++
GCC 4: very good (if right options are used, otherwise okay++)
Logged