PocketMatrix forums

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

Anyone using DirectX

So I have noticed there isn't very much talk about DirectX on WM5 based devices. I've been using it and aside from a few minor hacks you have to do in order to get it working on all devices, I really like it!

Some SmartPhones seem to have video acceleration (namely the Samsung Blackjack) so that makes things interesting as well. Although, I noticed that the Blackjack's CPU is a TI-OMAP processor which features video acceleration on-chip.

Do SmartPhone's/PocketPC's have a seperate video chip or is it done on board the CPU or... what?
I'm not using it, but have considered it. The main reason I haven't seriously considered it yet is because I want to support PPC2003 devices. Once everything is finished and happily working with older devices I will look at building in support for DirectX for newer devices.

What are the hacks you hinted at? Do you primarily just use it for faster blitting to screen?
Well it's just a little tricky setting up the primary/back buffer.

You create the direct draw object, get the caps and from there you can see if a backbuffer with flipping is supported. Well some phones (like the MotoQ) will say that indeed it is supported until you try to actually create the surfaces and then it fails. So the way around that is to create a primary surface and a seperate back buffer and then do a blt copy over each frame of the back buffer to the primary surface as opposed to using the hardware flipping capability.
Ok, so do you render all your graphics with your own code? How extensive use do you make of the DirectX drawing capabilities? I had a look a while back and from memory it didn't seem to support much more than drawing a surface onto another, or did I miss something?
Ya aside from blitting, you have to do it all yourself BUT the blitting will take advantage of hardware capabilities when present which makes a big difference.
How much of a performance increase do you get with one blit? I doubt its anything over what GAPI can do.

For example on the treo my GAPI blit is around 3ms.

I doubt anyone will be using it until WM5 devices are more widespread, which will be a few more years, a lot of people are still using 2003 devices and older.
mm40, do you have any actual stats on 2003 usage? I would have thought that there were now more WM5 devices in use than 2003, although I actually still use a 2003 device :)
PointOfLight · 17 May 2007, 11:21 UTC
I don't personally know anything about legitimate statistics on OS usage, but if I were to guess I'd say that more Smartphone users were probably using WM5, but more non-phone PDA users were still running WM2003- devices. I have two WM PDAs, one running WM2003 and the other WM2002.
mm40 wrote:How much of a performance increase do you get with one blit? I doubt its anything over what GAPI can do.

For example on the treo my GAPI blit is around 3ms.

I doubt anyone will be using it until WM5 devices are more widespread, which will be a few more years, a lot of people are still using 2003 devices and older.


Well DX will take advantage of hardware acceleration when present such as the features on the OMAP ARM processors (Samsung BlackJack for instance) so in that case you will get a VERY nice performance increase. Also, DX will take advantage of system-to-video memory DMA transfers that will allow blits to occur in parallel with CPU operation.

As far as I know, GAPI is obsolete on WM5.
Yep, I got some hard stats
Code:

2006 2007
Pocket PC 2002 3% 3%
Windows Mobile 2003 9% 6%
Windows Mobile 2003 SE 25% 14%
Windows Mobile 5.0 63% 77%


There is no way I would ditch 23% of the market by requiring DirectX Mobile.

I was actually surprised with these stats that no one is using CE2000. I also thought more people would be using 2002.
Cardinal wrote:As far as I know, GAPI is obsolete on WM5.


It is depreciated, but still supported on every device, even with WM6 I would guess.
Are those stats for device sales, or for what is supposed to be out on the streets?

Dan East
mm40 wrote:Yep, I got some hard stats
Code:

2006 2007
Pocket PC 2002 3% 3%
Windows Mobile 2003 9% 6%
Windows Mobile 2003 SE 25% 14%
Windows Mobile 5.0 63% 77%


There is no way I would ditch 23% of the market by requiring DirectX Mobile.

I was actually surprised with these stats that no one is using CE2000. I also thought more people would be using 2002.


Interesting stats! 23% is a big chunk BUT then you have to factor in how much of that 23% will actually play games on their devices let along buy one?
Dan East wrote:Are those stats for device sales, or for what is supposed to be out on the streets?
Dan East


These stats are from people who have bought at least 1 game in the last 5 months and are whats on the street. If you want device sale stats, I think thats in the Handango Yardstick. For device sales I would guess 95%+ are WM5.

Cardinal wrote:Interesting stats! 23% is a big chunk BUT then you have to factor in how much of that 23% will actually play games on their devices let along buy one?


Sorry, I forgot to mention, these stats are ONLY from registered users of a very popular PPC game. My guess is if the stats were from all users (not just registered ones) the WM2003 stats would be much higher, probably in the 30-40% range.

So to answer your concerns:
how much of that 23% will actually play games on their devices: 100%
let along buy one?: 100% :)
Interesting stats indeed! Our company's technology(www.eyemobile.com) requires camera access which is only done on WM5 via direct show. I've been toying with DirectDraw and D3D mobile for the past week or two and so far I like it. I was pretty impressed with the D3D software rasterizer!

So do you guys use floats heavily in your code or stick soley to fixed-point?
If those are sales stats, then obviously that's what matters, because that represent the customers you have to support. However I say those stats are a substantially off in the real world. The people buying new devices (and thus the new OS) are more likely to buy software. People that have owned a device for 3 years are well settled into their routines with the device. The novelty has worn off, and they use it for whatever day to day use they require of it.

Dan East
Anything in an inner loop is fixed point, almost everything else is float for ease of programming. The only things converted to fixed point are after it is deemed a bottleneck. Write first, test second, then rewrite if necessary.
So floating point performance on these devices ain't half bad then? I haven't had nearly as much time as I would have liked to really benchmark. I've just started getting into hardcore coding on these things. I VERY much like ARM assembler so I wanna see what I can do with the MMX unit on the Intel PX series of processors.

I have work on the Nintendo DS which is running an ARM9. Did alot of assembler on there.
Actually floating point sucks, as Dan East pointed out in the other thread, it depends on how much you use it I guess, if you are doing a few thousand floating point ops per frame then youre probably ok, if youre doing tens of thousands then you will want to do fixed point.
Floating point on these is abysmal.

Take the following rotation function as an example:
Code:
void Rotate(int _iX, int _iY, int _iAngle, Surface *_pSrc, Surface *_pDest)
{
// Convert to Radians
double dAngle = ((_iAngle % 360) / 360.0) * 2.0 * 3.141592654;
double dCosA = cos(dAngle);
double dSinA = sin(dAngle);
int iWidth = _pSrc->GetWidth();
int iHeight = _pSrc->GetHeight();
int iCenterX = _iX - (int) ((iWidth >> 1) * dCosA - (iHeight >> 1) * dSinA);
int iCenterY = _iY - (int) ((iWidth >> 1) * dSinA + (iHeight >> 1) * dCosA);
for(register int iSrcY = 0; iSrcY < iHeight; iSrcY++)
for(register int iSrcX = 0; iSrcX < iWidth; iSrcX++)
{
int iDestX = (int) (iSrcX * dCosA - iSrcY * dSinA);
int iDestY = (int) (iSrcX * dSinA + iSrcY * dCosA);
_pDest->SetPixel(iCenterX + iDestX, iCenterY + iDestY, _pSrc->GetPixel(iSrcX, iSrcY));
}
}
Even using registers and bit shifting, there are still 4 multiplications per pixel that use doubles, and you'll be watching a slideshow for any surface that isn't tiny. (Also, this code has holes in the rotated image. I'm just using it for an example.) But now consider this code:
Code:
void Rotate(int _iX, int _iY, int _iAngle, Surface *_pSrc, Surface *_pDest)
{
// Convert to Radians
double dAngle = ((_iAngle % 360) / 360.0) * 2.0 * 3.141592654;
int iCosA = (int) (cos(dAngle) * 1024);
int iSinA = (int) (sin(dAngle) * 1024);
int iWidth = _pSrc->GetWidth();
int iHeight = _pSrc->GetHeight();
int iCenterX = _iX - (((iWidth >> 1) * iCosA - (iHeight >> 1) * iSinA) >> 10);
int iCenterY = _iY - (((iWidth >> 1) * iSinA + (iHeight >> 1) * iCosA) >> 10);
for(register int iSrcY = 0; iSrcY < iHeight; iSrcY++)
for(register int iSrcX = 0; iSrcX < iWidth; iSrcX++)
{
int iDestX = (iSrcX * iCosA - iSrcY * iSinA) >> 10;
int iDestY = (iSrcX * iSinA + iSrcY * iCosA) >> 10;
_pDest->SetPixel(iCenterX + iDestX, iCenterY + iDestY, _pSrc->GetPixel(iSrcX, iSrcY));
}
}
And the rotation is super-smooth, since the floating points are removed from the loop. Of course, I don't recommend using this code, but it's a great example of how pathetic floating point math is. Use it as sparingly as possible.

-John
Well I did some benchmarking here at work. We have a slew of phones and I was curious as to what numbers I would get from each one. I used the following code sequence (which has been simplified for posting):

Code:

template <class T>
void BenchMark(TCHAR* szName)
{
DWORD dwStartTime = GetTickCount();

for (int n = 0; n < 1000; n++)
{
for (int m = 0; m < 1000; m++)
{
T nA = (T)n * (T)m;
}
}

DWORD dwEndTime = GetTickCount();

TCHAR szChar[1024];
wsprintf(szChar, L"%s Time: %d ms\n", szName, dwEndTime - dwStartTime);
OutputDebugString(szChar);
}

int WinMain(...)
{
BenchMark<int>(L"int");
BenchMark<float>(L"float");
BenchMark<double>(L"double");
}



And now the results:


DEBUG MODE

HP6915
CPU: 416 MHZ Intel XScale PXA270

Integer Time: 44 ms
Float Time: 550 ms
Double Time: 670 ms


Cingular 3125 aka HTC Startrek 100
CPU: 195 Mhz OMAP 850

Integer Time: 99 ms
Float Time: 998 ms
Double Time: 1381 ms


Motorola Q
CPU: 312 MHZ Intel XScale PXA270

Integer Time: 59 ms
Float Time: 646 ms
Double Time: 898 ms


Samsung BlackJack SGH-i607
CPU: 220 Mhz OMAP 1710

Integer Time: 86 ms
Float Time: 881 ms
Double Time: 1252 ms


RELEASE MODE

HP6915
CPU: 416 MHZ Intel XScale PXA270

int Time: 9 ms
float Time: 306 ms
double Time: 515 ms


Cingular 3125 aka HTC Startrek 100
CPU: 195 Mhz OMAP 850

int Time: 30 ms
float Time: 687 ms
double Time: 1145 ms


Motorola Q
CPU: 312 MHZ Intel XScale PXA270

int Time: 13 ms
float Time: 409 ms
double Time: 713 ms


Samsung BlackJack SGH-i607
CPU: 220 Mhz OMAP 1710

int Time: 29 ms
float Time: 598 ms
double Time: 1048 ms
Code:

for (int n = 0; n < 1000; n++)
{
for (int m = 0; m < 1000; m++)
{
T nA = (T)n * (T)m;
}
}


I'm surprised the compiler didn't optimize those loops out completely, since you're only storing to an otherwise unused local variable.

Dan East
What compiler are you using? I'm using EV4 and it optimizes out the inner loop, which I would expect since the result isn't used outside the loop. Also a better test of purely the math functions would be

Code:

template <class T>
void BenchMark(char* szName, T temp)
{
timer t;
T total=0;

for (T n = 0; n < 1000; n++)
{
for (T m = 0; m < 1000; m++)
{
total += n * m;
}
}

float t1 = t.stop();
logf("%s Time: %f ms total %d\n", szName, t1*1000.0f, (int)total);
}


this way you aren't timing the casts from int to float.

Dell Axim x50 PXA270-624Mhz
int Time: 8 ms
float Time: 765 ms
double Time: 902 ms

Treo 700w PXA272-312MHz
int Time: 16 ms
float Time: 1233 ms
double Time: 1916 ms
Also on a similiar note, here are some timings I took when optimizing my math library, its interesting seeing the comparision between desktop PCs and PDAs

basically for sinf a core 2 duo is about 12,500 times faster than an Axim X5 and for sqrtf about 7,700 times faster :)

I also have a bunch of basic math timings somewhere, can't find them though...

PIV 3.0 HT XP
operations per second
sqrtf 16,648,767.802154
isqrtf 14,991,505.333821
lengthf 9589908.151663
ilengthf 8582092.789774
ilength2 8569098.069292
sinf 8284069.737944
sinlu 2162167.922505

iPaq 3635 ARM 200 WM2000
operations per second
sqrtf 37428.093750
isqrtf 57359.843750
lengthf 29856.564453
ilengthf 44378.703125
ilength2 42118.210938
sinf 23351.898438
sinlu 217175.062500

Axim X5 ARM 300 WM2003
operations per second
sqrtf 45496.281250
isqrtf 75204.046875
lengthf 37610.253906
ilengthf 60013.242188
ilength2 56160.039063
sinf 27944.431641
sinlu 268172.031250

core2duo e6600 @ 2.66ghz
operations per second
sqrtf 347,858,407.635224
isqrtf 42,492,133.781402
lengthf 187372228.216928
ilengthf 42414689.669510
ilength2 42017061.616602
sinf 347894147.277696
sinlu 23579099.547440
getRotation 10532184.205979
getRotationFast 26456623.222499
The compiler might still optimize that out. Have the function return type T, and return your accumulator.

Dan East
Whoops my bad... the compiler does optimize that out... I had changed the code slightly to return the value of nA.

Thats how I got my numbers! :)