PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PF + PocketHAL premilinary report

I just finished hooking a prototype version of the PocketHAL with PF v0.6. Basically, I get rid of the notion of "orientation" and replaced the GAPI layer with PocketHAL. Here are the preliminary results on my Maestro (ARM 206 mhz):


PocketFrog v0.6 - Blit (CW)...........: 110 FPS
PocketFrog v0.6 - Blit (CCW)..........: 110 FPS
PocketFrog v0.6 - Rotate (Normal).....: 80 FPS
PocketFrog v0.6 - Rotate (180 degrees): 80 FPS

Prototype HAL - Blit (CW)...........: 121 FPS
Prototype HAL - Blit (CCW)..........: 121 FPS
Prototype HAL - Rotate (Normal).....: 99 FPS
Prototype HAL - Rotate (180 degrees): 65 FPS

Analysis:

- Normal blits (straight copies) have been accelerated significantly as I was expecting them to be. (80 -> 99 FPS).

- Rotated blits have also been marginally accelerated (110 FPS -> 121 FPS). But consider that efficient use of the cache and write bursts allowed rotated blits to be even faster then your straight blits using memcpy().

- 180 degrees blits have been slowed down significantly (80 -> 65 FPS). As-is, this would be a problem for the iPAQ 38xx running in landscape mode and for landscape devices (e.g. iPAQ 36xx) running in inverted-landscape (almost never seen). I haven't spent any time yet on analysing cache usage for this blit.

- A significant advantage of PocketHAL is that there is no notion of "orientation" anymore. PF doesn't need to conduct any coordinates transforms anymore. There is also no need to rotate images while they are being loaded. This means a smaller memory footprint (no more intermediary buffer needed), but more importantly a significant speed up on loading time.

What is next:

- Optimizing the 180 degrees blit.
- Convert to assembly. This will affect all blits except the "normal" one. It is too soon to say how much speed I will get out of this.
- Conduct similar cache analysis on MIPS to optimize all blits. Although I don't expect a big speed increase (if any) on MIPS.


Also in the news: I have things to attend to in the next 2 weeks and won't be able to work on PF during that time. I will continue monitoring this forum and answering questions.

Thierry
Hi Thierry! Nice results & good work!

I have some questions related to the benchmarks results:

Here are the preliminary results on my Maestro (ARM 206 mhz):


If possible, could you provide the source code to this bench result program? It would be interesting to see where GD is relative to the soon-to-be-released new PF HAL. I could rewrite the benchmark quickly for GD 2.0.

A significant advantage of PocketHAL is that there is no notion of "orientation" anymore. PF doesn't need to conduct any coordinates transforms anymore.


Does this also mean that you get the infamous "tearing" on devices such as the ipaq 36xx or 38xx series since you have to rotate the final blit if running in "normal" (non-landscape) mode? Or have you worked around the tearing issue on these devices? Are there any other devices that can show the tearing issue?

There is also no need to rotate images while they are being loaded. This means a smaller memory footprint (no more intermediary buffer needed), but more importantly a significant speed up on loading time.


I guess this is only an issue if you still use the imgdecmp.dll image loaders. You will still however have a significant overhead with imgdecmp.dll since you have to decompress the entire image as an HBITMAP (from which you can then DC bitblt to your surface directly). If you used libpng for example, you can still use image rotations as before, and memory footprint will be down an additional 50% (compared to using non-rotated images and imgdecmp.dll). Using libraries such as libpng there is no advantage memory-wise to not rotate the images, performance-wise I would say it's marginal.

-----

I have another couple of questions which I feel have been unanswered as of yet:

(1) What happens with rasterize effects with the new HAL? Will they be removed, since you cannot inline code anymore since the HAL is a DLL? I know from feedback I have gotten than many PF users use it mainly for the rasterizers. I guess you would have to provide the source code for some blits in the user layer for the rasterizer effects to work as they do today, or?
(2) Operating on multiple pixels... While this was a pain to implement, performance-wise it was a huge step forward in performance. Will this be also in the new HAL? How will this affect existing code and rasterizing effects? Will there be two versions of each blit, for maximum code compatibility?

Sorry for all the questions, but I think this low-level hacking is kind of cool.
Oh, another question as well:


PocketFrog v0.6 - Blit (CW)...........: 110 FPS
PocketFrog v0.6 - Blit (CCW)..........: 110 FPS
PocketFrog v0.6 - Rotate (Normal).....: 80 FPS
PocketFrog v0.6 - Rotate (180 degrees): 80 FPS


My question is... Why doesn't PF perform the same in all image orientations if it pre-rotates the images? Using a simple full-screen blit for example, GD performs the same in all display orientations...
Johan wrote:
If possible, could you provide the source code to this bench result program?


"Blit" and "Rotate" refer to the samples distributed with PF. All the source code is available. Simply download the latest distribution.

Johan wrote:
Does this also mean that you get the infamous "tearing" on devices such as the ipaq 36xx or 38xx series since you have to rotate the final blit if running in "normal" (non-landscape) mode?


No matter what you do, if you don't sync with the refresh you WILL get tearing. Blitting with the same orientation as the native one simply minimize it's impact. Your typical LCD on PPC has a refresh between 40-60 hz. This is roughly 17-25 ms per refresh. PF HAL will allow you to blit during the "vblank" period, minimizing or eliminating tearing all together. Note that this will only be available for devices that uses the ARM or XSCALE built-in LCD controller (or GAPI implementations that provide a DRAM buffer such as the E-125). Other controllers (ex: MediaQ, Jornada 72x) will be supported if the documentation is available.

Johan wrote:
I guess this is only an issue if you still use the imgdecmp.dll image loaders. You will still however have a significant overhead with imgdecmp.dll since you have to decompress the entire image as an HBITMAP (from which you can then DC bitblt to your surface directly).


Agreed. PF image loading will be soon replaced with LIBPNG (and optionaly LIBJPG). Still, the temporary buffer to rotate the image is not needed anymore, saving both memory and execution time.


Johan wrote:
(1) What happens with rasterize effects with the new HAL? Will they be removed, since you cannot inline code anymore since the HAL is a DLL?


The PF rasterizers (and almost everything else) won't be touched. The PF HAL is meant to replace the low-level display driver code, not the high-level stuff. The rasterizers might eventually be optimized to work on 2 pixels at a time, if tests show that it's worth it.

Concerning the DLL stuff, I don't intend on releasing PF HAL as a DLL, but as a .LIB. This is easier to work with, one less file to handle, and is more efficient. If I change my mind and go with a DLL, it will use COM interfaces/objects to minimize the impact of calling functions in the DLL.

Johan wrote:
(2) Operating on multiple pixels... While this was a pain to implement, performance-wise it was a huge step forward in performance. Will this be also in the new HAL?


Optimized raster routines would indeed end up in PF HAL. I am sure some more performances can be squeezed out from PF by working on multiple pixels at a time. It is not a priority right now, as there is a few more optimizations I want to test that have the potential for bigger gains.


Johan wrote:
How will this affect existing code and rasterizing effects? Will there be two versions of each blit, for maximum code compatibility?


My idea on this is to add a method to the IPixelShader interface that is able to operate on two (or more) pixels at a time. I am not sure if this can work, I will have to conduct some research.


Johan wrote:
Sorry for all the questions, but I think this low-level hacking is kind of cool.


You're welcome.
Johan wrote:
My question is... Why doesn't PF perform the same in all image orientations if it pre-rotates the images? Using a simple full-screen blit for example, GD performs the same in all display orientations...


It does. These numbers are for two different samples (Blit and Rotate) that comes with PF. One sample (Blit) works in lanscape mode (and is easily changed to use inverted-lanscape). The other (Rotate) works in "Normal" mode (and is easily changed to upside-down). That's why I used them for benchmarking.
Impressive work, especially on the vsync on the ARM display controller! And thanks for the quick reply.
Thierry wrote:
PF HAL will allow you to blit during the "vblank" period, minimizing or eliminating tearing all together. Note that this will only be available for devices that uses the ARM or XSCALE built-in LCD controller (or GAPI implementations that provide a DRAM buffer such as the E-125). Other controllers (ex: MediaQ, Jornada 72x) will be supported if the documentation is available.


Do the iPaqs use these supported controllers?...

Am I understanding this correctly... we're talking about a system that bypasses GAPI and hits the hardware directly? Sounds very cool :D :D

Any chance of a standalone 'wait-for-vblank' lib?...
It would be interesting to see this in use.. Thierry: Have yoy benchmarked the vertical blanking period? You could do this by simply setting some pixels at the top position to red, and then to black again after n milliseconds. If it's not at least 5 msec than some tearing will show in some parts of the image - and I have no clue as to how it will look. It could look ok, but it could also look very odd...
Anonymous wrote:
It would be interesting to see this in use.. Thierry: Have yoy benchmarked the vertical blanking period? You could do this by simply setting some pixels at the top position to red, and then to black again after n milliseconds. If it's not at least 5 msec than some tearing will show in some parts of the image - and I have no clue as to how it will look. It could look ok, but it could also look very odd...


As long as you're copying the back buffer in the order/direction thet the VRAM is aligned, you can use up to a whole refresh (say 15ms) to flip the buffers - the screen refresh will be 'chasing' your memory writes down the screen. As long as it doesn't catch up (or get 'overtaken' - the usual cause of tearing), it won't tear

(Of course, that assumes that the LCD refreshes 'down' the screen (not neccesarily 'down' to the user, but incrementing through VRAM), in a similar way to a CRT... which is true for the GBA, not sure if it's the same for all LCD controllers)
Um. It was me posting as anonymous above btw.. Somehow I got logged out from PocketMatrix.

bluescrn: I agree, but since the new HAL uses rotation in the final blit on some devices, the contents of the display will not be "filled" in the same direction on all Pocket PCs. Thus there is a risk of "odd" tearing being shown (where e.g. 1/4 of the display inhibits tearing and the rest does not) - I guess this would only be visible using a full-screen-scrolling example...
Johan wrote:
bluescrn: I agree, but since the new HAL uses rotation in the final blit on some devices, the contents of the display will not be "filled" in the same direction on all Pocket PCs. Thus there is a risk of "odd" tearing being shown (where e.g. 1/4 of the display inhibits tearing and the rest does not) - I guess this would only be visible using a full-screen-scrolling example...


That depends if you rotate the reads or rotate the writes...

It should always be possible to write in VRAM order, even if the reads are rotated. Even if it's doing something clever for cache efficiency (maybe rotating small blocks), it should be possible to write in more-or-less VRAM order - keeping ahead of the screen refresh

(Is there a performance implication here? non-sequential reads from system RAM vs non-sequential writes to VRAM?)
bluescrn: Video memory on Pocket PCs is not cached, so rotated blits always read sequential from source and write non-sequential to the destination...
Actually... why are rotated blits needed at all? Shouldn't all blits be VRAM-aligned (pre-rotate sprites/bitmaps when the surfaces are loaded. Isn't that what GAPIDraw does?)


But back on topic... does this really mean VSyncing on PocketPCs is finally doing to be possible? :)
bluescrn wrote:
Do the iPaqs use these supported controllers?...


I know the iPAQ 36xx and my Maestro use it. I would expect most StrongARM devices to use it. Of course, if it's got a MediaQ or ATI chip, then it doesn't use it. Example: the Jornada 72x serie uses a chip by Epson. VBlanc synching is still possible with that chip as a library is available.

bluescrn wrote:
Any chance of a standalone 'wait-for-vblank' lib?...


That would be PF HAL.
bluescrn wrote:
But back on topic... does this really mean VSyncing on PocketPCs is finally doing to be possible? :)


Yes, if the LCD controller can be accessed (i.e. docs are available). What is actually possible to do right now is read the current scan line being refreshed.

The actual VBlank period is practically 0. It doesn't take much (if any) more time to go from the last pixel on your display to the first one. There is no "CRT cannon" involved.

So the basic idea is to wait for the current scan line to be near (or at) the end of the display before starting to blit the next image.

The LCD always read the memory in sequential order. This means that you must find a way to write sequentially to it. Unfortunately, this means inefficient use of the cache (video is not cached, source is).
bluescrn wrote:
Actually... why are rotated blits needed at all? Shouldn't all blits be VRAM-aligned (pre-rotate sprites/bitmaps when the surfaces are loaded. Isn't that what GAPIDraw does?)


That's what GD does, this is also what PF currently does (rotated surfaces). It allow for faster blits, but doesn't allow quick locking of the pixels (unless you are ready to work in the native orientation). Another problem is that it takes considerably more time to load images and rotate them then to simply load them.

Pre-rotated images are being used for two main reasons: 1) prevent tearing and 2) increased frame rate. Since I have found a way to do the same thing using "normal" surfaces and actually increase the frame rate, I don't see the point of using pre-rotated images anymore.
Um. I did a GD version of the blit sample and got 116FPS on my old 3870. Quite nice performance boost from the 32-bit masked blits in GapiDraw operating on two pixels simultaneously (considering it's only four sprites being drawn to the display the performance boost was larger than I expected - usually a game has a significant number of more masked blits resulting in much higher performance boost)... Also, there are some 32-bit optimizations that could be done to further improve performance (such as always aligning the sprites on even coordinates for guaranteed 32-bit writes)...

The demo is up at:
http://www.gapidraw.com/temp/gdpfbench_blit.zip

Key 1: Toggle opacity
Key 2: Flip 180 degrees
Key 3: Exit
Stylus down: Save screenshot as \\backbuffer.bmp

The first benchmark sample
Image

The second benchmark - now with 32-bit opacity! :)
Image

The code used to draw the images was virtually identical to PocketFrog:

Code:

HRESULT CMyApplication::ProcessNextFrame(CGapiSurface& backbuffer, DWORD dwFlags)
{
backbuffer.BltFast(0, 0, &m_background, NULL, 0, NULL); // display->Blit( 0, 0, m_background );

for (int i = 0; i < 4; ++i)
{
Rect& pos = m_position[i];

// Display image
if (m_bOpacity)
{
GDBLTFASTFX fx;
fx.dwOpacity = 128;
backbuffer.BltFast(pos.left, pos.top, &m_images[i], NULL, GDBLTFAST_KEYSRC | GDBLTFAST_OPACITY, &fx); // display->Blit( pos.left, pos.top, m_images[i] );
}
else
{
backbuffer.BltFast(pos.left, pos.top, &m_images[i], NULL, GDBLTFAST_KEYSRC, NULL); // display->Blit( pos.left, pos.top, m_images[i] );
}

if (i != m_dragImage)
{
// Move image (horizontal)
switch (rand() % 3)
{
case 0: break; // Don't move
case 1: if (pos.left > 0) pos.Translate( -1, 0 ); break;
case 2: if ((DWORD) pos.right < backbuffer.GetWidth()) pos.Translate( 1, 0 ); break;
}

// Move image (vertical)
switch (rand() % 3)
{
case 0: break; // Don't move
case 1: if (pos.top > 0) pos.Translate( 0, -1 ); break;
case 2: if ((DWORD) pos.bottom < backbuffer.GetHeight()) pos.Translate( 0, 1 ); break;
}
}
}

// Update FPS
FLOAT fps;
m_timer.GetActualFrameRate(&fps);
DWORD dwFPS = (DWORD) fps;
DWORD n100 = dwFPS / 100; dwFPS -= n100 * 100;
DWORD n10 = dwFPS / 10; dwFPS -= n10 * 10;
DWORD n1 = dwFPS;

if (n100 > 9) { n100 = 9; n10 = 9; n1 = 9; }

// Display fps
backbuffer.BltFast( 0, 0, &m_numbers, &Rect( n100 * 8, 0, (n100+1)*8, 11 ), 0, NULL);
backbuffer.BltFast( 8, 0, &m_numbers, &Rect( n10 * 8, 0, (n10+1)*8, 11 ), 0, NULL);
backbuffer.BltFast( 16, 0, &m_numbers, &Rect( n1 * 8, 0, (n1+1)*8, 11 ), 0, NULL);

return S_OK;
}
My point was to bench the "rotation blit" used to bring the backbuffer to the frontbuffer, not the "Blit" function of PF.

The two samples I choose (Blit and Rotate) are doing almost nothing. 99% of the time is spent blitting the backbuffer to the frontbuffer. I used them on purpose. And not to compare PF's performances to GD, but rather to compare PF 0.6 with the new HAL.

To properly compare GD and PF, we will need a much more elaborate program. But until I get around to optimizing my blits to work on multiple pixels...
Thierry: I know.. :) I was just curious to see if I also got 110 FPS with the sample..
How does one force allignment so that sprites ( or anything else ) are alligned as needed? I've seen references in eVC but never understood how it worked. Is there a simple way like '#allign 32' or somesuch?

( In PF the surface class would need to do this itself I assume if it was to work as GD does )

I'm obviously delighted to see speed improvements coming but it makes me think about how to make use of this extra speed as my code already runs faster than needed & needs slowed down. I might try some higher poly meshes to see what happens to the render time.
PF already allocates surfaces that are int32 aligned, so don't worry about it.

What does that extra speed give you? Think more graphic/sound effects. More sprites/polygons on the screen. Etc.
Actually, I think one of the biggest benefit is that your game will run on slower devices (think first generation PPC / iPAQ 38xx).
Slower devices ?

Heh .. I have yet to find a faster XScale device than my ipaq 3835.

Perhaps new PXA 255 based devices will finally deliver ...
warmi wrote:
Slower devices ?

Heh .. I have yet to find a faster XScale device than my ipaq 3835.

Perhaps new PXA 255 based devices will finally deliver ...


I though the 38xx was the one with the inverted-landscape display. Guess I was wrong? Cause the device with that problem had sluggish performances at one point (running in landscape).
Conan: What I meant was that you should always try to blit your sprites at (x % 2 == 0) and (y % 2 == 0). Once PF gets support for multiple pixels it will be able to read and write two pixels simultaneously...
On the performance front I'm finding my Axim's PXA255 at 400Mhz to be slightly faster with my PocketGL/PocketFrog hybrid than my iPaq h3650.

I never get time to do actual benchmarks but I've never before had to think 'how do I slow this down & keep it smooth' :)

Just thought of something, I better turn on the music before I say my code is too fast. Currently there's no soundtrack running in the background.
What is PocketHAL
As a side question, I am wondering about the licensing of PocketHAL. I mean, if you manage to improve the performance of MediaQ and ATI devices significantly it would not be unthinkable to include PocketHAL as the hardware layer in GapiDraw (I really don't have time to mess around with chip hardware). Heck, I am even considering incorporating SDL for simple Mac and Linux compatibility.

I know the current license requires one to include a copyright statement somewhere that the product uses PF. But what if a developer tool incorporates PocketHAL? Is it enough that the developer tool mentions the license agreement, or should all end products using this tool also incorporate this?
sbl wrote:
As a side question, I am wondering about the licensing of PocketHAL.


I haven't decided on the licensing agreement yet. I think that until PocketHAL is ready to go, it is premature to discuss it (i.e. I haven't decided yet).

sbl wrote:
I mean, if you manage to improve the performance of MediaQ and ATI devices


That's precisely what I am after. I know how to optimize for StrongARM. I am currently investigating other LCD controllers (XSCale, Imageon 100 and MediaQ 1100/32). When I have determined what is possible, I will decide what form PocketHAL will take.
So how far away is PocketHAL from some sort of release?

Or just a demo of smoooooth scrolling with vsyncing?... to prove it's possible? :)
The PocketHAL architecture has been implemented and currently works with two drivers: GDI and GAPI.

I am in the process of implementing the StrongARM driver (and hope to finish it today). This will be followed by the MediaQ driver (and possibly the Imageon and XScale).

I currently lack any useful demo... Does someone has anything I can use? I currently have the following:

1) Flip test (screen alternates between BLUE and YELLOW) in portrait orientation.
2) Flip test (same thing as #1) in landscape orientation.
3) Burning Sheep's Plasma Demo

I was thinking about adding a "Fire effect" demo.

I would also like to get my hand on a side-scrolling demo...

Anyone has anything?
there's my PocketFrog 'rocky' demo. It's a side scroller with a few sprites & a moving background.
See http://www.sundialsoft.freeserve.co.uk/ ... og_Ch4.htm
The article has a link to download the project (in red box towards end of article)

Image
Thanks Conan! I forgot about this demo =)
I will add it in my testing tool.
I had a quick look at the StrongARM SA-1110 docs last night...

Looks like you can set the vblank period to be anything from 1 to 64 lines

More interestingly, the chip supports 4 and 8bpp palettized modes! :) If possible, using 8bpp could be a nice optimization for 3D engines!

And it looks like the base address of VRAM can be changed (must be 4-byte aligned - so no smooth 'hardware scrolling' though)

Can an app just write to these registers ( 0xB0100000 area)? Or is that memory region protected? Does the code that writes to them have to be implemented as some sort of device driver? (I've got no idea how that'd work on PocketPC)
Thierry: Just a thought (being very interested in a non-rotated backbuffer since it would simplify development significantly):

If you use GDI and the user requests a landscape display (320x240), wouldn't you have to perform two blits to get the backbuffer to display instead of one (one - blit with rotation from 320x240 to 240x320 GDI offscreen bitmap, two - GDI BitBlt from offscreen bitmap to display)? Or did you find another fast way of blitting to the GDI back buffer?
bluescrn wrote:
I had a quick look at the StrongARM SA-1110 docs last night...

Looks like you can set the vblank period to be anything from 1 to 64 lines

More interestingly, the chip supports 4 and 8bpp palettized modes! :) If possible, using 8bpp could be a nice optimization for 3D engines!


Unfortunately I don't think you can do any of this. The StrongARM (or any other LCD controller) has to be programmed to match the requirements of the LCD panel. The StrongARM is flexible to support the widest possible range of LCD panel. If you change these settings at run time, you risk damaging your screen.

bluescrn wrote:
And it looks like the base address of VRAM can be changed (must be 4-byte aligned - so no smooth 'hardware scrolling' though)

Can an app just write to these registers ( 0xB0100000 area)?


That's the idea behind double buffering on StrongARM. But I am unsure if I will enable this. The gains aren't that big and if a game crashes, you risk that the display offset won't be set to the original value. This basically means that you won't see the desktop anymore while Windows will be happy to accept your stylus input. Not a really nice situation to be in.

bluescrn wrote:
Or is that memory region protected? Does the code that writes to them have to be implemented as some sort of device driver? (I've got no idea how that'd work on PocketPC)


This B0100000 is a physical address. You need to find the logical one.
Johan wrote:
If you use GDI and the user requests a landscape display (320x240), wouldn't you have to perform two blits to get the backbuffer to display instead of one (one - blit with rotation from 320x240 to 240x320 GDI offscreen bitmap, two - GDI BitBlt from offscreen bitmap to display)?


You are right. I currently need to do two blits (one to rotate + BitBlt). The performances do suffer from it. There is two reasons I include a GDI driver: 1) color conversion for for displays that aren't 16 bpp and 2) as a safety net if everything else fails (no GAPI installed for example).


Johan wrote:
Or did you find another fast way of blitting to the GDI back buffer?


I could incorporate PocketFrog's color conversion code to PocketHAL (and probably will do so), it is just not a priority right now.

As a safety net, I don't think there is much I can do to optimize this. But you never know... I'll keep my eyes open for any idea =)
Thierry wrote:
Unfortunately I don't think you can do any of this. The StrongARM (or any other LCD controller) has to be programmed to match the requirements of the LCD panel. The StrongARM is flexible to support the widest possible range of LCD panel. If you change these settings at run time, you risk damaging your screen.


Some of the timing settings obviously won't work, And there was an STN/TFT select, too... so there may well be potential to damage the display be messing with these. But I don't think it'd be easy to damage the screen by just changing timings - it's not as if you're changing the voltage (and otherwise there'd probably have been many reports of screening failing after the app or device crashed badly...)

But I can't see an obvious reason why the palettized modes could not work?...

Probably not really worth it, as it'd only work on older devices... but would be interesting to mess with.
Ok... :)

By the way... Let me know if you need any compatibility testing later.. I have a couple of devices lying around (e125, some sh3 oldie, 3600, 3800, e740, 2215, 54xx, and a spv100)...