Problem with dynamic texturing

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
e_boris
Posts: 25
Joined: Sat May 19, 2007 2:45 pm

Problem with dynamic texturing

Post by e_boris »

Hi, buddy, has any one tried dynamic texture generated (by CPU not by GU) texture.
I got flicking result without set a hard waiting on sending GU commands.

Code: Select all

struct vertex_
{	unsigned short u, v;
	float x, y, z;
};
DWORD pG[64*64];

sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0,0);
sceGuTexMode(GU_PSM_8888,0,0,0);
{
	int x=sx;
	int y=sy;
	for&#40;;x<480;x+=64&#41;
	&#123;
		GenerateTexture&#40;pG,64,64&#41;; //pure CPU code, animates the buffer pG;
		sceKernelDcacheWritebackRange&#40;pG,64*64*4&#41;; // Patch A

		sceGuTexFunc&#40;GU_TFX_REPLACE,GU_TCC_RGBA&#41;;
		sceGuTexFilter&#40;GU_NEAREST,GU_NEAREST&#41;;
		sceGuTexImage&#40;0,64,64,64,pG&#41;;

		vertex_* vertices = &#40;vertex_*&#41;sceGuGetMemory&#40;2*sizeof&#40;vertex_&#41;&#41;;
		vertex_& v1=vertices&#91;0&#93;; vertex_& v2=vertices&#91;1&#93;;
		v1.u = 0;	v1.v = 0;
		v2.u = 64;	v2.v = 64;
		v1.z = 0;	v2.z = 0;

		v1.x = x;	v2.x = x+64;
		v1.y = y;	v2.y = y+64;
		sceGuDrawArray&#40;GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2,0,vertices&#41;;
		&#58;&#58;sceKernelDelayThread&#40;1000&#41;; // Patch B
	&#125;
&#125;
sceGuDisable&#40;GU_TEXTURE_2D&#41;;
sceGuDisable&#40;GU_BLEND&#41;;
At first I guess the generated texture was just in cache, so I add Patch A (call sceKernelDcacheWritebackRange). This makes a little bit better, but flicking remains at some region.

Then I guess sceGuDrawArray command is not finished while GenerateTexture modified the buffer (pG) in the next loop. So I add Patch B, call sceKernelDelayThread to wait for 1ms. This makes correct result, flicking totally disappeared. But FPS drops since I waited too much time.

So I am asking the way to sync with GPU at the end of sceGuDrawArray. I tried sceGuSync(0,0) / sceGuSync(0,1) / sceGuSync(0,2). None works.

Thanks ^_^
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

These are just guesses looking at the docs, have you tried sceGuTexSync() "Synchronize rendering pipeline with image upload"? It's used in the sdk gu samples "copy" and "spharm". There's also sceGuTexFlush() "Flush texture page-cache" but no sdk samples seem to be using that.
(+[__]%)
e_boris
Posts: 25
Joined: Sat May 19, 2007 2:45 pm

Post by e_boris »

Thanks Smong, but sceGuTexSync does not work. I checked the doc, it is used to sync with sceGuCopyImage.

In my code, the major issue is how to keep waiting until the execution of sceGuDrawArray finish. I suppose sceGuSync is the right method, but it is not, or I made some mistake in using it.
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

Have you tried it without a "dynamic texture generated by CPU"? If not do you have something like this at the end of your graphics code?

Code: Select all

	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0, 0&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;
(+[__]%)
e_boris
Posts: 25
Joined: Sat May 19, 2007 2:45 pm

Post by e_boris »

Everything is ok, If I move GenerateTexture outside the loop.

I have these lines of sceGuFinish and etc. I just get ride of them for simple
e_boris
Posts: 25
Joined: Sat May 19, 2007 2:45 pm

Post by e_boris »

I just tried sceGuTexFlush, the problem remains. :~(
Post Reply