PocketMatrix forums

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

Direct access, filters etc

Is there any way to have fullscreen filters in my app whilst having good FPS? Something like blur effects and so on(like the one in Particles sample)

If only use get/setpixels once(all the screen), i'm getting terrible loss of FPS - only about 30 and less instead of 100++ if no this functions used.

Whatever can I do? Some tricks with lock or whatever? Anything?

I use Pfrog 7.0. I'm not quite understand what the PHAL is, but can it help?
if you're doing a lot of get/set pixels, you'll want to use the surface lock instead.

But... on some devices, the lock will have to internally rotate the surface (twice if you use that last option to keep the contents). This issue should be removed after the integration with pocketHAL.
Yeah, definitely don't use Get/SetPixel. For optimal performance, use PocketHAL and manipulate the back buffer directly.

Pam
fast_rx wrote:if you're doing a lot of get/set pixels, you'll want to use the surface lock instead.


I tried this also. No difference between get/setpixels. Or maybe I'm doing this the wrong way?


But... on some devices, the lock will have to internally rotate the surface (twice if you use that last option to keep the contents). This issue should be removed after the integration with pocketHAL.

The emulator runs quite slowly too..

So, I should integrate PHAL and use the direct access to surface somehow like this:

1.Lock
2. Cycle "buffer.pixels[y * dy + x] = m_something;"
3. Unlock
(Like in Plasma sample)

And this will give me extra perfomance, have i got it right?
Jaguard":3cb89xjk]
fast_rx wrote:if you're doing a lot of get/set pixels, you'll want to use the surface lock instead.


I tried this also. No difference between get/setpixels. Or maybe I'm doing this the wrong way?


When are you locking the surface? You want to lock it only once at the beginning of your frame update loop. Multiple lock/unlock can have really bad performance.

[quote="Jaguard wrote:

But... on some devices, the lock will have to internally rotate the surface (twice if you use that last option to keep the contents). This issue should be removed after the integration with pocketHAL.

The emulator runs quite slowly too..

So, I should integrate PHAL and use the direct access to surface somehow like this:

1.Lock
2. Cycle "buffer.pixels[y * dy + x] = m_something;"
3. Unlock
(Like in Plasma sample)

And this will give me extra perfomance, have i got it right?


Yes, that is basically it. With PocketHAL, you do not need to lock the surface anymore.

So, if you wanted to work directly on the backbuffer, you might do something like this:

Code:

display = GetDisplay();
Surface *BackSurface = display->GetBackBuffer();
Pixel* BackBuffer = BackSurface->GetPixels();
int pitch = BackSurface->GetPitch()>>1;

//clear to black
memset(BackBuffer,0,BackSurface->GetHeight()*pitch)

//cycle through some loop that manipulates the pixels like this
BackBuffer[y * pitch + x] = m_something;

//flip the back[buffer on screen
display->Swap();



You get faster performance for 2 main reasons. 1. You don't have go through the lock/unlock anymore. 2. Thierry has managed to squeeze extra performance out of the common display controllers found on Pocket PCs.

Oh yeah, and check out this demo by JoostB if you have any trouble figuring out PocketHAL http://www.pocketmatrix.com/forums/viewtopic.php?t=13298 Download the source, it has a basic PocketFrog-like wrapper around PocketHAL

If you want to post your source, we can take a look at it.

Hope that helps.

Pam
I admit I haven't had time to look a PHAL yet, but I'm a bit surprised by that code Pam... I had thought that one of the advantages of PHAL was that you no longer had to think about the whole pitch issue... Was I incorrect in my understanding?
fzammetti wrote:I admit I haven't had time to look a PHAL yet, but I'm a bit surprised by that code Pam... I had thought that one of the advantages of PHAL was that you no longer had to think about the whole pitch issue... Was I incorrect in my understanding?


Well, the pitch is only the "y" value, you don't need both x and y as you do in GapiDraw.

As for why it is needed, I'll leave that to Thierry, but I'd guess it has something to do with having a generic surface class that works the same on different hardware which may have specific requirements/optimizations.

Pam
Upon further thought, I believe you can't assume that GetPitch() == GetWidth() because on some devices like the E-125, it isn't. And if you create a Surface of arbitrary size, PocketHAL may be padding it to align on WORD boundaries for performance reasons. So the pitch may not be equal to the width and one can't assume it will, hence the function.

Pam
Pam wrote:Upon further thought, I believe you can't assume that GetPitch() == GetWidth() because on some devices like the E-125, it isn't. And if you create a Surface of arbitrary size, PocketHAL may be padding it to align on WORD boundaries for performance reasons. So the pitch may not be equal to the width and one can't assume it will, hence the function.

Pam


Yep, that's precisely it. Sometimes it is more efficient to have a backbfufer with GetPitch() != GetWidth().

PHAL takes care of orientation issues, but pitch should still be taken into consideration.
Well, thanks for the answers, I'm really appreciate it. There are some more:

I dont want to get into PHAL yet(partly because I've spent a lot of time making pfrog work, and don't want to spent more time for now), so I'm still interested in making pfrog fast enough.

1. Will it be the good idea to copy the video buffer into some temporary buffer to make operations on it and then send it back? If yes, what will be the best way - the cycle TempBuff = buffer.pixels[y*dy+x] or maybe memcpy()? But I'm not sure about the size to give into memcpy() - I suppose it should depend on pitch?
Maybe I'll receive some extra perfomance by using my own blit functions on this temporary buffer?

2. Is there any way to use alpha mask? There is display->SetBlending(), but it ifluence all the surface. I'm not sure about PixelShader, but it seems to me that it doesn't suit.
I need this basicly to make images look better. I tried blitting some prerendered images, and this looks terrible - There are a lot of almost black zones, something like Color(2,0,1). They are not filtrered by SetColorMask(0,0,0), of course, and the look is terrible. The usage of the same image as alpha blending mask could be nice sollution, I suppose.

3. And a little offtopic: I can't build my programm using any of: WCE ARM Debug, WCE ARM Release, WCE x86em Release. The only working target is WCE x86em Debug! When I try something different I get message about missing stlport_vc6_static.lib. I dont get this error when building WCE x86em Debug, but get it in all the other cases. That is really weird!
I've made the changes to stl_user_config.h, it helped me to compile PFrog lib, but I have no idea what to do with this error.. EVC3.0.

PS: Don't I tortune you with my poor english too hard? Sorry then ;)
Anonymous wrote:Well, thanks for the answers, I'm really appreciate it. There are some more:

I dont want to get into PHAL yet(partly because I've spent a lot of time making pfrog work, and don't want to spent more time for now), so I'm still interested in making pfrog fast enough.

1. Will it be the good idea to copy the video buffer into some temporary buffer to make operations on it and then send it back? If yes, what will be the best way - the cycle TempBuff = buffer.pixels[y*dy+x] or maybe memcpy()? But I'm not sure about the size to give into memcpy() - I suppose it should depend on pitch?
Maybe I'll receive some extra perfomance by using my own blit functions on this temporary buffer?

2. Is there any way to use alpha mask? There is display->SetBlending(), but it ifluence all the surface. I'm not sure about PixelShader, but it seems to me that it doesn't suit.
I need this basicly to make images look better. I tried blitting some prerendered images, and this looks terrible - There are a lot of almost black zones, something like Color(2,0,1). They are not filtrered by SetColorMask(0,0,0), of course, and the look is terrible. The usage of the same image as alpha blending mask could be nice sollution, I suppose.

3. And a little offtopic: I can't build my programm using any of: WCE ARM Debug, WCE ARM Release, WCE x86em Release. The only working target is WCE x86em Debug! When I try something different I get message about missing stlport_vc6_static.lib. I dont get this error when building WCE x86em Debug, but get it in all the other cases. That is really weird!
I've made the changes to stl_user_config.h, it helped me to compile PFrog lib, but I have no idea what to do with this error.. EVC3.0.

PS: Don't I tortune you with my poor english too hard? Sorry then ;)


1. Performance really depends on what you are trying to do. How many pixels do you manipulate at one time? Moving data around is slow, so you want to do it as little as possible.
For memcpy, remember that Pixels are 2 bytes, so 100 Pixels is 200 bytes. If you wanted to copy an entire buffer, the size would be height*pitch*2.
You can get some extra performance using your own blit functions, especially if you keep them really simple and don't try to add too much capability. But you should probably do some profiling first to see if this is really your bottleneck.

2. PocketFrog doesn't have an Alpha mask function. At least, not yet. This is a good case for you to write your own blit function. You might want to edit your image also to get rid of those almost black colors that aren't really visible anyway. It depends if your image is of something that has hard boundaries (like a rubber ball) or is supposed to have some transparency (like water).

3. Make sure you have the appropriate include and lib paths set up for each configuration.

Pam
1. Performance really depends on what you are trying to do. How many pixels do you manipulate at one time?

You mean do I have optimization to work on several pixels at once? No, I don't.

If you asking me what kind of operation I'm planning to do, this is: Filtering, blending, and blur-like explosions effects, so it should be very intense access. Oh, I'm affraid I wont get enough perfomance :(.

Moving data around is slow, so you want to do it as little as possible.
For memcpy, remember that Pixels are 2 bytes, so 100 Pixels is 200 bytes. If you wanted to copy an entire buffer, the size would be height*pitch*2.

Ok, I got it.

2. PocketFrog doesn't have an Alpha mask function. At least, not yet. This is a good case for you to write your own blit function. You might want to edit your image also to get rid of those almost black colors that aren't really visible anyway.

There still will be some artefacts on boundaries, where black areas(background) meets the sprite. I met this before :(.

3. Make sure you have the appropriate include and lib paths set up for each configuration.


It is set! They are all the same! At least it founds pocketfrog.h & PocketFrog_ARM.lib/PocketFrog_EMU_PPC2000.lib. The only error I get is this stl lib missing :(.
Anonymous wrote:It is set! They are all the same! At least it founds pocketfrog.h & PocketFrog_ARM.lib/PocketFrog_EMU_PPC2000.lib. The only error I get is this stl lib missing :(.


You need to disable STLport's IO streams:

http://pocketfrog.droneship.com/FAQ.html
Thierry":96oalw3q]

No, no, I'm not THAT stupid :). There is my upper quote:

I've made the changes to stl_user_config.h, it helped me to compile PFrog lib, but I have no idea what to do with this error.. EVC3.0.


Oh, I tried once again, and conquered :)! The problem was that I recompilled libs using batch build(several times, btw :)), so i tried "rebuild all" now, and that was the sollution :). Thanks Thierry, you pointed the right direction :). Well, almost ;).
Oh, now I'm completely shocked. I made the test app.

Code:
DisplayDevice* display = GetDisplay();

Surface::LockInfo buffer;
int offset = 0;

display->GetBackBuffer()->Lock( buffer );

// initialize vars
int dy = buffer.pitch >> 1;

int width = display->GetWidth();
int height = display->GetHeight();


memcpy(CBuff, buffer.pixels, buffer.pitch*height);
for (int i=0; i < buffer.pitch*height-1; i++)
{
CBuff[i] = rand() % 1000;
}


memcpy(buffer.pixels, CBuff, buffer.pitch*height);

display->GetBackBuffer()->Unlock();


And this is what gives me 30 fps on emulator. I do almost nothing and i'm already have terrible fps. Whatever I'm doing wrong??
jaguard wrote:Oh, now I'm completely shocked. I made the test app.

(...)

I do almost nothing and i'm already have terrible fps. Whatever I'm doing wrong??


You are using the emulator. Seriously, the emulator is really slow for development, even slower then an actual device.

It is far more preferable to use VC6 or VC7 for development on the desktop PC.
Is there a reason to copy the surface to CBuff, modify, then copy back?

Seems like you would want to just modify "buffer" directly.
Umm, I'd hardly call 30FPS "terrible". I don't imagine Halo's going to look too good at that speed, but it's still more than sufficient for a great many games.
You are using the emulator. Seriously, the emulator is really slow for development, even slower then an actual device.

I dont know what you do to make it run so slowly :). Well, as for what I get - the emulator is always faster. This particular ppc emulator. The one comes with VC7.1 emulating WM2003, is quite slow, but the ppc EVC3.0 emulator is fast. I have quite slow device, indeed..

Well, I checked the real device too. Very slow.


It is far more preferable to use VC6 or VC7 for development on the desktop PC.


It is not the development tool's problem. EVC suits good enough. The perfomance is not enough..


Umm, I'd hardly call 30FPS "terrible". I don't imagine Halo's going to look too good at that speed, but it's still more than sufficient for a great many games.

Well, I'm agree. But do you see the GAME in this code? It is only white noise generator. There is nothing here. No algorithms, no graphics, no music. Nothing. Actual game will be 1/5 fps, i suppose.

Is there a reason to copy the surface to CBuff, modify, then copy back?

Seems like you would want to just modify "buffer" directly.


Well, I tried this too. This, actually, was the first I tried.. 3x3 fullscreen filter gives me about 5 fps :(. There comes another problem - to translate color from Pixel to RGB and back - it also influence fps a lot.
jaguard wrote:Well, I tried this too. This, actually, was the first I tried.. 3x3 fullscreen filter gives me about 5 fps :(. There comes another problem - to translate color from Pixel to RGB and back - it also influence fps a lot.


What are you talking about? What is this 3x3 filter?

Pixels *are* RGB data... What are you converting and why?

You definitely should get rid of the CBuffer that doesn't give you anything.
If you are modifying the whole surface, for very fast performance, rather than calling Lock/Unlock, you might want to try modifying the PF sources and add a function to return a BackBuffer pointer.
Calling Lock/Unlock copies the display to a tempery buffer, and back again on calling Unlock.
The memory copying alone is a performance crippler!

Hope this helps.
Dave Johnston · 04 Mar 2004, 22:43 UTC
Also, remember that Debug builds are very slow compared to Release builds!

I remember getting around ~20fps in a PC Debug build for a PocketFrog game I was working on, which then shot up to well over 100fps (a lot lot higher I believe) when compiled using the 'Release' build config (which optimises the crap when set to optimise for speed).
What are you talking about? What is this 3x3 filter?

Well, its simple. We get 3x3 mask, multiply each on coefficients, sum them all, and return value to the middle element(i[1,1] zero-bazed).
The simplest filter is blur -
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]

Pixels *are* RGB data... What are you converting and why?


Well, I need to detach single R, G, B values to make operations on them( I
cant write buffer.Pixels[i] += 10 ) and then convert it back to Pixel.

You definitely should get rid of the CBuffer that doesn't give you anything.

Yes, I did it. It was just a test if I can get it faster.


If you are modifying the whole surface, for very fast performance, rather than calling Lock/Unlock, you might want to try modifying the PF sources and add a function to return a BackBuffer pointer.
Calling Lock/Unlock copies the display to a tempery buffer, and back again on calling Unlock.

I'm affraid there will be another problem - different pixels representation. I suppose Thierry makes it to be always 565.
[quote="jaguard]Well, its simple. We get 3x3 mask, multiply each on coefficients, sum them all, and return value to the middle element(i[1,1] zero-bazed).
The simplest filter is blur -
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]

[/quote]

Woah your doing how many divides and multiplies per pixel?? Im guessing this is where the huge performance hit is comming from.
Anonymous wrote:[quote="jaguard]Well, its simple. We get 3x3 mask, multiply each on coefficients, sum them all, and return value to the middle element(i[1,1] zero-bazed).
The simplest filter is blur -
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]
[1/9, 1/9, 1/9]



Woah your doing how many divides and multiplies per pixel?? Im guessing this is where the huge performance hit is comming from.[/quote]

It was just for better understanding. Of cource i use
(1,1,1)
(1,1,1) * 1/9
(1,1,1)
I really dont see the difference unless your using that matrix to represent something else.

Any constant multiplied or divided into a matrix has to do operate on element. Unless all those values are the same number and then you would only have to do it once.