PocketMatrix forums

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

New article from Phantom...

I haven't seen an announcement here, so I thought I'd mention it.

Phantom/Jacco's got a new article/column at flipcode:
<a href="http://www.flipcode.com/articles/article_mobilegfx01.shtml">3D Graphics on Mobile Devices</a>
There will be four articles, all in all. They will appear weekly, the next one is scheduled for Friday.
The second article, covering fixed point math, is now available on http://www.flipcode.com . I included some source code.
nice articles phantom ! how about releasing your symbian hal, perhaps as "easyS60" ? anyway, i'm looking forward to read the rest of the series ;) (btw., i'm not really sure but, it seems like there should be a left-shift with 4 instead of one to the right side at the end of the fixedpoint division approximation FPDIV)
We plan to release something called 'Easym-b' soon. On Symbian, starting is a major pain, much worse than on the PPC.
MirekCz forgot his pass.. · 18 Aug 2003, 20:28 UTC
Docs are nice, althrought I'm a bit dissapointed.

There are tons of docs regarding stuff described by phantom (and he even talks about stuff he has described in his previous articles).

I was hoping that Jacco will write more about ARM and/or Symbian specific topics (texture mapping/persp.correct. tmapping optimizations, arm asm optiimzations etc).
The stuff he covered by now could be mostly described with few url links to his/other previous articles + few words of wisdom about additional, less known, optimizations he used.

Nothing really against those tuts, they are great, althought there are tons of fairly unknown topics on Symbian/arm programming (like fast tmapping) and as for now there's no word about it... Jacco describes stuff that is fairly well known to anyone that has done some programming in the days before pentium/hardware acceleration and this stuff is covered in many other docs.

One bad point is that instead covering how to write 32/64bit fixedpoint math lib with asm Jacco talks about how to use 32bit fixedpoint math and squeeze 3d engine into it (maybe Jacco's stuff is better, but I have got some very ugly previous experience with such stuff on PPC emu as my 3d engine died because of it in the end - fine quality and speed but small world size because of mul/div limitations with 32bits C math)


So to sum it up, tuts idea is great and Jacco has got some words of wisdom, but I think it could be much more useable if Jacco would concentrate on Symbian specific stuff/optimizations and leave the basic explanation for users to read from other docs if they miss this knowledge (as a set of links at the beggining)

Thanks for the nice tips as for now :-)
+/- 16k integer coords have been completely acceptable to me (and Randall).

Dan East
Mirek, I see your point, however keep the following in mind:

I didn't write those docs just for Symbian people, it's 'mobile games coding'. That means that I have summarized my experiences with both PocketPC and Symbian. And when I'm doing 32bit integer math, that's because I don't want to use the heavily platform specific ARM assembly stuff for 64bit. As you know, I like writing HALs that make Windows, Symbian and PocketPC as much equal as possible; I hope that future devices will fit in the same strategy. The idea behind this is that I want to concentrate on coding, or more specifically: The 3D coding challenges, rather than platform specifics.

That being said, I know for some hardcore coders the articles have too little info. Rest assured, the following two articles have a bit more info, the last one even completely focusses on texture mapping. Still, it's generic stuff, so it might still not be your cup of tea.

I do however believe that someone new to mobile game development will have a pretty good idea of the pitfalls ahead after reading the four articles. That was the main goal, and also the reason for posting the articles on a generic game coding site like Flipcode.

I hope that explains things a bit.

- Jacco.
Phantom wrote:
I don't want to use the heavily platform specific ARM assembly stuff for 64bit.


Nearly all mobile devices seem to be ARM-based these days, so it's not all that platform-specific...
Hm, maybe 64bit integer support should be part of the lib. :) However, personally I didn't have a big problem with 32bit integers. The 3D engine that is introduced in article 3 doesn't have severe range problems: I use the full range for vertex coordinates, so that objects can't be larger than n * n * n, however I use a different scale for object positions in world space, as I don't need the same precision there. Total world space is 127x127x127 with 16bit precision, and it's up to the coder to decide what '127' means. :)
although i think that parts of this have already been posted to this forum somewhen, here we go again:

64/32bit Fixed-Point Multiplication & Division
the division approximation was done by peter teichmann and takes always 131 cpu cycles. it works with unsigned numbers only, therefor there is a second division routine which handles the signs.

c code:
Code:
extern "C" inline int FIXMUL64(int a, int b);
extern "C" inline int FIXDIV64(unsigned int a, unsigned int b);
extern inline int FIXDIV64S(int a, int b);


and somewhere else:
Code:
inline int FIXDIV64S(int a, int b)
{
if (a < 0 && b < 0)
return FIXDIV64((unsigned int)-a, (unsigned int)-b);
else if (a < 0)
return -FIXDIV64((unsigned int)-a, b);
else if (b < 0)
return -FIXDIV64(a, (unsigned int)-b);

return FIXDIV64(a, b);
}


finally, the asm code:
Code:
AREA FIX,CODE,READONLY
EXPORT FIXMUL64
EXPORT FIXDIV64

FIXMUL64
smull r2, r3, r0, r1
mov r0, r2, lsr #16
orr r0, r0, r3, lsl #16

mov pc, lr

FIXDIV64
mov r2, r1
mov r3, r0, asr #31
mov r3, r3, lsl #16
orr r1, r3, r0, lsr #16
mov r0, r0, lsl #16

adds r0, r0, r0
adc r1, r1, r1

GBLA i
i SETA 31
WHILE i > 0

cmp r1, r2
subcs r1, r1, r2
adcs r0, r0, r0
adc r1, r1, r1

i SETA i - 1
WEND

cmp r1, r2
subcs r1, r1, r2
adcs r0, r0, r0

mov pc, lr

END


have fun,
andreas "pazazzo" wuthe[/code]
I know that was posted on the forum. :)

Anyway, you mention it takes 131 cycles always, plus some overhead for signed division. That's an aweful lot! I'm not sure how much a division in C takes, but I'm positive that a 32bit custom made division function would be way faster than the 64bit version you presented. So it's not that obvious to use 64bit fixed point, personally, I would only use it when porting from float to fixed point code, to ease the transition. For new code, 32bit is almost always possible, better, faster and more portable.

There. :)
of course it is not faster than a plain 32bit division approximation ;) it's just more accurate and thought for those who claimed that your articles lacked of asm-code. i for myself am using just the arm multiplication since it is precise while beeing as fast as your approximation. for divisions i'm using a 32bit approximation too; for some cases (eg: rasterizer) i'm using a lookup table with 1/n values to be able to use the precise multiplication routine instead of the in-accurate division macro. btw, i guess you should change the macro code in your article to
Code:
#define FPDIV(x, y) ((((x)<<6)/((y)>>6))<<4)
since
Code:
#define FPDIV(x, y) ((((x)<<6)/((y)>>6))>>4)
will return a 8.16/16.8 value instead of the correct 16.16 number...
Phantom's version looks correct to me...
Phantom's version is being used in a 3D engine as we speak. ;)
MCz begs admins for pass · 20 Aug 2003, 21:50 UTC — send to kherin@go2.pl for my MirekCz account ;-)
ok Jacco, got your point...

I will wait for the end of the tut series, maybe some more nifty tricks will fall into my bag ;-)

I'm mainly interested in tmapping, as there are several ways to do persp.correct one and I don't have a clue which would fit ARM best :-)

And about mul/div , div is darn slow on ARM, avoid at all cost :-)

PS.I don't see the stuff in "Code".. anyone knows why?!? (w2k SP3 in here with IE5.0)
well, maybe i'm just too stupid to understand it :(
maybe you can explain me where i'm wrong: a "correct" n.16 fixed point division should look like this:
Code:
v=(x<<16)/y
you're also pointing this out in your article, to get a n.16 result we need to shift x 16bits to the left side. now, for the 32bit approximation:
Code:
((x<<6)/(y>>6))>>4)
+6 +6 -4 = 8 additional bits
= n.8 result
and otherwise
Code:
((x<<6)/(y>>6))<<4)
+6 +6 +4 = 16 additional bits
= n.16 result
btw, i'm using the version b) in my 3d engine for more than a year now and changing it to version a) screwed up everything...
Hmm, strange. I think you're right. I'll check my code to see if something went wrong in the conversion to html.

<time elapsed>

OK, I checked, and it turns out that I don't use the macro anywhere in my code. I rarely use the macro's anyway, as this tends to hide things that could have been optimized.

I'm sorry that I didn't spot the error when you first reported it.
that's a big relief! i almost thought i'm crazy and couldn't sleep last night ;)
Me neither but that was because of other coding projects. :) Anywone here interested in AI? I'm working on something better than WinAlice.
Phantom wrote:
Anywone here interested in AI? I'm working on something better than WinAlice.


That's intriguing! I think WinAlice is awesome and I chat with her often, just to see what kind of responses I can get. If I didn't know any better, I'd say she has a pretty good sense of humor.

Care to elaborate?

Pam
Oh well, I was wrong! :oops:

Thanks for clearing that up guys!

Phantom, maybe you could correct the article so that future readers don't get the wrong version.

While I'm at it, thanks for the articles! The question of how to do fixed point math whilst preserving some precision/avoiding overflow had been bothering me and you explained it nicely. I look forward to the article on texture mapping.

Do you have any more info on the HAL you mentioned? i.e. what features it has and which platforms will be supported? Thanks again.
Eldo: The HAL is extremely simple. Under Win9x etc. it opens a window and provides the programmer with a linear frame buffer plus access to the keys and mouse. Under Symbian it sets up a CSymbianContainer & CSymbianApp, initializes timed screen updates, and provides the user with a linear frame buffer plus access to buttons. On the PocketPC, it goes fullscreen, provides the user with a linear frame buffer plus access to buttons and stylus. Extremely simple stuff (the result), but in the end, all platforms are more or less the same to program for, wich is nice.
I added some stuff for surfaces (including tga loading), fonts, sprites and zlib compression, as I use those for virtually every project.
Pam: Right now, it's better for the programmer, not yet better to talk to. :) WinAlice is very simple: You enter a sentence, and WinAlice compares it to 10.000 patterns. A pattern can have one wildcard ('*') so that a pattern can match multiple sentences. There's more to WinAlice, like a spellchecker and some other stuff, but the basis is very simple.

The new program allows for much more complex patterns, with unlimited wildcards and optional parts, plus 'selections':

'a *' matches 'a cat' or 'a dog' or any other sentence starting with 'a '.
'a {cat|dog}' matches only 'a cat' or 'a dog'.
'a (lazy )cat' matches 'a cat' or 'a lazy cat'.

Curly brackets and regular brackets can be nested and mixed unlimited. This way, you can make very powerful patterns that match lots of subtle variations of the same sentence. This is very useful for reducing natural language to info that can be handled by the computer.

Once a match is made, a response is constructed, using a 'template'. This template can again have optional parts: This time, text between brackets is used in the asnwer in 50% of the cases. This is useful for randomizing responses, so that the chatbot does not give the same response all the time.

The template can also make use of variables (including stacks), if-then-else commands, recursion and so on to write really complex programs.

Anyway, it was fun building the interpreter. :)

- Jacco.
Phantom, thanks for the response. The HAL sounds very useful.

When you say access to a linear frame buffer, is this an off-screen back buffer that can be blitted to the real screen memory, or is it actually the screen memory itself?

In the latter case, I guess it would be trivial for an application to create its own back buffer to draw to and then perform the blit. Taking advantage of any hardware blit support would then be down to the application.
Eldo: The linear frame buffer is always an off-screen back buffer, indeed.

I do not agree however that an application should create it's own back buffer: That would force the app to take platform differences into account, and that's exactly what I wnated to prevent.

Besides, knowledge about faster ways to blit are available to all apps using the HAL. The application programmer should not have to worry about things like that (unless he likes the topic and deliberately dives into the matter).