PocketMatrix forums

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

texturemapping using intel GPP raster

hello, ive just started to implemente texturemapping in a renderer im building for pocketpc using intel's GPP library..
my problem is i havent been able to get UV coordinates to work correctly.
for testing purposes i was working on a simple sprite/image drawing routine, which would use intel's lib to draw a background on a 240x320 display (pocketpc normal).
i have been getting weird results.. also help from intel hasnt been that good..
anyone here tried intel's library and worked out texturing ? let me know if you did
thanks in advance
Would you be able to post a bit of your code so we can take a look ? :)
// Set raster struct
raster.m_pFrameBuf = (U16 *)buffer;
raster.m_rgba = 0x00ff0000;
raster.m_pZBuffer = NULL;
raster.m_texture[0].m_pTexBuffer = (U16 *)bitmap.GetData();
raster.m_texture[0].m_Width = bitmap.GetWidth();
raster.m_texture[0].m_Height = bitmap.GetHeight();

// Create an array of scanlines with texture info
I32 res;
for( int j=0; j<320; j++ ) // y
{
int startX = j*240;
int endX = j*240+240;

// get fixed-point v coord in [0..1] range
I32 tm = gppFloat_To_Fixed_16( (float)j );
I32 tn = gppFloat_To_Fixed_16( 320.0f );

// Set starting point array
startpoint[j].x = gppInt_To_Fixed_16( startX );
startpoint[j].w = 0;
startpoint[j].r = (0);
startpoint[j].g = (0);
startpoint[j].b = (0);
startpoint[j].a = (0);

// Get UV coords for startpoint
startpoint[j].tu = gppFloat_To_Fixed_16( 0.0 );
gppDiv_16_32s( tm, tn, &res );
startpoint[j].tv = (res);

// Set endpoints array
endpoint[j].x = gppInt_To_Fixed_16( endX );
endpoint[j].w = 0;
endpoint[j].r = (0);
endpoint[j].g = (0);
endpoint[j].b = (0);
endpoint[j].a = (0);

// Get UV coords for endpoint
endpoint[j].tu = gppFloat_To_Fixed_16( 1.0 );
gppDiv_16_32s( tm, tn, &res );
endpoint[j].tv = (res);
}



Then in the mainloop, rasterize:

// Gouraud texture scanlines (no depthbuffer used)
for( i=0; i<m_Height; i++ )
status = gppScanLine_G_Zal_Taw_16_32s( &startpoint[i], &endpoint[i], &raster );


I cant post any pictures right now, i dont have the pocketpc with me atm, but ill try to get a shot of how it should it and how it *is*.
I think something wrong with the texture coords, maybe the fixed-point conversion, or how it accepts the coords. I think it should accept coords within the texture size limits, not in a 0..1 range.. but using this, happens to be the best results i got so far!
it should be something dumb, but i havent traced it yet. maybe you can !
thanks in advance
I haven't used the Intel library but from looking at your code and their docs here's a few things you might try.

1) You need to change the raster.m_pFrameBuf to point at the start of each scan line you're going to rasterize. In the code you posted, you set it once to what I can only assume is the start of your render target.

2) Even though you're rasterizing without using a depth buffer, you might want to set the w component of the endpoints to the fixed point equivalent of 1.0.

3) Since you're setting the color of both endpoints of the scan line to black, use flat shading instead of Gouraud shading to increase performance.

I think Dan has actually evaluated the Intel library and can probably give you more info.
hi!

thanks for the tips ! i tried what you said, i was using different colors on scanline points thats why the gouraud code was still on. about the memory addressing for each scanline. i just tried it.. still gives me the same image results! nothing changed.. any other ideas ?
it has been quite painful :)
thanks in advance
vic
Beats me. You might try using the simpler "decal" texturing mode (ippgScanLine_Zal_Tdw_16_32s).

I guess the first thing I would do is try to simplify things as much as possible in an attempt to narrow down the problem. I'd try to rasterize a single scan line instead of the whole screen. I'd use a malloc'ed buffer for my texture and fill it with a known value (start with white) and then see if I got the expected results.

Maybe you can post a screen dump of what is happening with a simpler version of your code?
I never got the UV problems sorted either, but it worked fine with flat shading. I tried several things with the UV coords but never got the textures rendering quite right. However that was not required for me to get a decent comparison of the performance of the IGPP relative to my custom software rasterizers.

Note that you have to do all clipping in your poly routines. No where do you indicate the width of your output buffer, so obviously IGPP cannot clip to the end of the scanline, and will spill over to the next line or past the end of the buffer.

Dan East
i have tried a simpler version. i got flat shading and gouraud working. i tried every raster method, but it really doesnt matter, coz if texture doesnt work with one of the rasters, it wont work with any other. i ran into these problems just with texturemapping, nothing else.

as for a test heres what i did.. i just draw one big background image with a simple blit function, and then i try to render that same image using IGPP, scanline by scanline (using a timer)

about the clipping.. i just feed my start/end scanline points with the screen borders.. should be enough.

scanline1 sx=0, ex=239;
scanline2 sx=240, ex=479;
scanline2 sx=480, ex=719;
etc

the formula is as follows:
(sets start x point to first pixel of each screen scanline and end x point to the startpoint+(width-1)

for j=0; j<height; j++
{
int startX = j*width;
int endX = startX+(width-1);

startpoint[j].x = gppInt_To_Fixed_16( startX );
endpoint[j].x = gppInt_To_Fixed_16( endX );
}

then just go thru the scanlines array and render them all.

if you want to give it a try, i assembled a simple example (with source code and binaries). you can download it and also see some shots at:

www.pixelnerve.com/gpp

(original.jpg is the original image blitted to the screen. gpp_render.jpg is how it looks when rendered by my function using the intel GPP.
notice i just render half the screen height. theres a line to seperate it.. the top half is rendered by GPP. it screwed up the image as you can see)


hope to hear from you soon!
peace !
Sergey Chaban · 07 May 2003, 07:15 UTC
GPP only supports textures with power of 2 dimensions.
I think this is not in the docs.
Try to use something like 128x256 image instead of 240x320.

SC
OK, I got it to work, but I had to hack through your sample with a machete. A word of advice, when you're trying to find out how an API works (or asking others for help), write the shortest, simplest application possible.

First, for what you're trying to do, the endpoints of each of the scan lines should be 0 and 239, converted to fixed point.

Second, as I mentioned in my previous post, you must change the raster.m_pFrameBuf to the start address of the scan line you are texture mapping (i.e. the address of pixel position (0, y)). You've left it at the start of your render target (pixel position 0,0).

Third, apparently the Intel GPP only supports texture maps with dimensions that are a power of 2 in size. Your sample is using a 240x320 texture. I didn't see this in the docs; I found this out by trial and error.

Good luck!
thanks alot ppl!
i got it to work also.. just had to get a texture with dimensions of power of 2.. like mentioned!
i already updated the files, so if you can test if you want.. i just dont know why intel didnt talk about that in the help files.
thanks again for all the help and patience..
peace !
digby, yep the first code i posted had some errors, like the scanlines endpoints were wrong, but i explained that in the readme.txt file at the site..

one other thing. you dont need to address the framebuffer in the mainloop. you can just precalc every scanline in the screen, and address frambuf to the start of your buffer. once!
Hey question. I was going to start experimenting with the GPP library myself, but I have an ARM PocketPC (Audiovox Maestro). Is it true that the only functions that don't work on ARM processors are Inv and Div instructions? If so, how are people getting around this? Did you write your own Div routines in C? Or did you do it in ARM assembly?

Also, does usage of the GPP library still allow you to test code under the emulator in EVC++? Or do you have to start compiling it to the PocketPC for each time you want to run it?

Thanks.

Chris
DooMer_MP3 wrote:
Is it true that the only functions that don't work on ARM processors are Inv and Div instructions?


The library appears to handle that internally. IE they will work on ARM, but may not be as efficient.

DooMer_MP3 wrote:
Also, does usage of the GPP library still allow you to test code under the emulator in EVC++? Or do you have to start compiling it to the PocketPC for each time you want to run it?


Only ARM / XScale is supported. So no X86 / X86 emulation builds. I've already griped about this. It would have be very useful for Intel to build for Intel x86 as well.

Dan East
it would be nice if intel could compile the libraries for the emulator, meaning a x86 lib file. but that would also go against what they have been talking about.. iGPP for pxa250
but its up to the world, to make them change it.
working for the emulator would need them to recode their optimizations for the ppc processor. wouldnt make much sense no ? is some point yes.. but personally i like to code in the pc, before uploading to the pocket.. its really a pain to compile and need to upload the files to the pocket just to test any changes.. hope they understand that
Well thanks for the replies. Blah, that kind of sucks about the emulation stuff :(. Oh well, the only good thing is that the build I downloaded is from March 2003, so they are still updating it. Maybe if there are enough cries, they will make the option available.

Chris
Sergey Chaban · 07 May 2003, 16:48 UTC
The following functions don't work for me on StrongARM:
gppDivHP_16_32s
gppDivHP_n_32s
gppDiv_16_32s
gppDiv_n_32s
gppInvHP_16_32s
gppInvHP_n_32s
gppSqrtHP_16_32s
gppSqrtHP_n_32s
gppInvSqrtHP_16_32s
gppInvSqrtHP_n_32s
gppInv_16_32s
gppInv_n_32s

They use CLZ instr that is XScale only.
To make them run (on SA) I had to write illegal instr handler that replaces CLZ with a call to ARM routine to count zero bits.
It doesn't look like it's supported by the library itself. Maybe I have an outdated version?

SC
Holy crap, I sincerely apologize about the quadposting! It kept saying posting.php had an error, so I just tried it a couple of times. Appears the database update ocurred alright. But now I can't delete them because posting.php fails :(.

Chris
Sergey Chaban wrote:
It doesn't look like it's supported by the library itself. Maybe I have an outdated version?


No, I certainly may be incorrect. I must have misread your previous post, because I thought it was supported for ARM.

Dan East
Nope, no StrongARM support for GPP. I asked the Intel guys about this over a year ago and they said that "it might work, but we neither recommend or guarantee it."

Think about it. Intel wants to sell XScale chips. The StrongARM is dead as far as they are concerned. Any software they can give away that will get developers to write apps that only run on XScale helps their cause.
Sergey Chaban wrote:
The following functions don't work for me on StrongARM:
gppDivHP_16_32s
gppDivHP_n_32s
gppDiv_16_32s
gppDiv_n_32s
gppInvHP_16_32s
gppInvHP_n_32s
gppSqrtHP_16_32s
gppSqrtHP_n_32s
gppInvSqrtHP_16_32s
gppInvSqrtHP_n_32s
gppInv_16_32s
gppInv_n_32s

They use CLZ instr that is XScale only.
To make them run (on SA) I had to write illegal instr handler that replaces CLZ with a call to ARM routine to count zero bits.
It doesn't look like it's supported by the library itself. Maybe I have an outdated version?

SC


Sergey,
Could you clarify a bit more what you had to do to get those to work? Is the illegal instr handler going to cause a slowdown by getting called, as well as having to do the implementation of the instruction yourself as well?

Chris
Sergey Chaban · 07 May 2003, 20:48 UTC
As I said GPP uses CLZ instruction in several places. This instr counts number of leading zero bits in its operand.
So CLZ R0, R1 will set ARM register R0 to the number of leading zeros in the register R1.
ARM architecture also supports conditional prefixes on each instruction so CLZNE r0, r1 would execute CLZ only if Z flag is set to 0. Also all ARM instructions are 32-bits in size.
So the trick is to trap illegal operation exception (using Win32 Structured Exception Handling) and modify code memory to replace CLZ with another instruction that will perform the same operation on StrongARM, and then continue execution from the same place.
There is no equivalent instr on a StrongARM, but because all instrs are 32-bit we could use BL (branch with link, a subroutine call) to call appropriate routine to count zeroes. We need several routines to support all register combinations (e.g. CLZ r0, r1; CLZ r5, r3 etc.).
These routines must be coded in assembler because their parameters and return values are arbitrary registers, whereas C code uses ARM procedure call standard - params in R0-R3, results in R0-R1.
Also these routines must save/restore CPU flags.

So at the higher level you have code like this, there handle_ex modifies the code etc.
Code:

__try {
your_code_that_uses_GPP();
} __except(GetExceptionCode() == STATUS_ILLEGAL_INSTRUCTION
? (handle_ex(GetExceptionInformation()), EXCEPTION_CONTINUE_EXECUTION) : 0) {}


Performance:
Exception processing overhead is only present the first time instr is executed.
Because ARM istrs all have conditional prefixes, we replace CLZcc with BLcc (i.e. call with the same conditional code).
This is not trivial as you can see, so I could release the code for such emulation. Actual code I use is slightly different, because StrongARM routines to calc bits are not hard-coded but instead generated on demand (this is all part of a larger library). Just to support GPP it's possible to use simpler code than that.

In my tests after CLZ replacement performance of the DivHP, InvHP, SqrtHP routines are still faster than straightforward C implementation.

In fact I only use GPP to compare its performance with my own library for fix/float calcs. That library has optimized routines for RISC CPUs and emulated GPP on StrongARM is only marginally slower on those routines (div, inv, sqrt) optimized for StrongARM. So it's okay I guess to use such hack if you want to use GPP and at the same time maintain compatibility with older machines.


SC
Sergey Chaban · 07 May 2003, 21:35 UTC
BTW, it's possible to implement such emulation at the OS level (with PB), then it will be practically transparent.
This is often used for prototyping before actual h/w is available and such.
See e.g. Intel's WMMX simulator for XScale.

SC