pspgl freezes

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

Moderators: cheriff, TyRaNiD

cadaver
Posts: 21
Joined: Sun Aug 07, 2005 2:31 am

pspgl freezes

Post by cadaver »

I'm testing based on the pspgl glut-test sample (added some more polygons). I have 2 problems.

- can't get the depth buffer to work (tried with glEnable(GL_DEPTH_TEST))

- after a few seconds the prog. freezes on the psp, it works o.k. when just the polygons of the original sample are rendered, any buffers must be cleared before rendering ???
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: pspgl freezes

Post by Shine »

cadaver wrote:- after a few seconds the prog. freezes on the psp, it works o.k. when just the polygons of the original sample are rendered, any buffers must be cleared before rendering ???
Do you have a 1.0 or a 1.5 firmware PSP? I have the same problem, but only on 1.0 firmware. Can you post your code? I have two PSPs, a 1.0 and a 1.5 and I can test it.
cadaver
Posts: 21
Joined: Sun Aug 07, 2005 2:31 am

pspgl freezes + depthbuffer not working

Post by cadaver »

here ist the complete (modified) simple.c
- if you move a few seconds with the triangle and x buttons the prog hangs, also the depth buffer doesn't work (don't know why)
- I tested only on a psp with 1.0


#include <stdlib.h>
#include <GL/glut.h>

static float zPos = -2.5f;
char keys[256];

/******* PSP specific debugging ********************************************/
extern void __psp_log (const char *fmt, ...);

/* enable GLerror logging to "ms0:/log.txt" */
#if 1
#define GLCHK(x) \
do { \
GLint errcode; \
x; \
errcode = glGetError(); \
if (errcode != GL_NO_ERROR) { \
__psp_log("%s (%d): GL error 0x%04x\n", \
__FUNCTION__, __LINE__, \
(unsigned int) errcode); \
} \
} while (0)
#else
#define GLCHK(x) x
#endif
/******* end of PSP specific debugging *************************************/

void reshape(int w, int h)
{
float ratio = ((float)w/(float)h);

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, ratio, 1.5, 500);
}


static float delta = 1.0;

static
void display (void)
{
int x=0,y=0;
static GLfloat angle;
angle += delta;

if (keys['d'])
zPos += 0.5f;
if (keys['x'])
zPos -= 0.5f;

GLCHK(glMatrixMode(GL_MODELVIEW));
GLCHK(glLoadIdentity());
GLCHK(glTranslatef(0.0f, 0.0f, zPos));
GLCHK(glRotatef(angle * 1.32f, 0.0f, 0.0f, 1.0f));

GLCHK(glShadeModel(GL_SMOOTH));
GLCHK(glEnable(GL_DEPTH_TEST));

GLCHK(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
GLCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

for (y=-2; y<3; y++) {

for (x=-2; x<3; x++) {

GLCHK(glBegin(GL_TRIANGLES));
GLCHK(glColor3f(0.0f, 0.0f, 1.0f)); GLCHK(glVertex3f( 1.0f+x, 0.0f+y, 0.0f));
GLCHK(glColor3f(0.0f, 0.0f, 1.0f)); GLCHK(glVertex3f( 0.0f+x, 1.0f+y, 0.0f));
GLCHK(glColor3f(0.0f, 0.0f, 1.0f)); GLCHK(glVertex3f( -1.0f+x, 0.0f+y, 0.0f));
GLCHK(glEnd());

GLCHK(glBegin(GL_TRIANGLES));
GLCHK(glColor3f(0.0f, 1.0f, 0.0f)); GLCHK(glVertex3f( 1.0f+x*1.0f, 0.0f+y*1.0f, -2.0f));
GLCHK(glColor3f(0.0f, 1.0f, 0.0f)); GLCHK(glVertex3f( 0.0f+x*1.0f, 2.0f+y*1.0f, -2.0f));
GLCHK(glColor3f(0.0f, 1.0f, 0.0f)); GLCHK(glVertex3f( -1.0f+x*1.0f, 0.0f+y*1.0f, -2.0f));
GLCHK(glEnd());

}

}

glutSwapBuffers();
glutPostRedisplay();
}


static
void keydown (unsigned char key, int x, int y)
{
keys[key] = 1;

switch (key) {
case 'd': /* delta, triangle */
break;
case 'o': /* round */
delta = 0.0f;
break;
case 'q': /* square*/
break;
case 'x': /* cross button */
// exit(0);
break;
default:
;
}
}


static
void keyup (unsigned char key, int x, int y)
{
keys[key] = 0;

switch (key) {
case 'o':
delta = 1.0f;
break;
default:
;
}
}


static
void joystick (unsigned int buttonMask, int x, int y, int z)
{
// GLCHK(glClearColor(x * 1.0f/2000.0f + 0.5f, y * 1.0f/2000.0f + 0.5f, 1.0f, 1.0f));
}


int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutCreateWindow( __FILE__ );
glutKeyboardFunc(keydown);
glutKeyboardUpFunc(keyup);
glutJoystickFunc(joystick, 0);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: pspgl freezes + depthbuffer not working

Post by Shine »

Your code is difficult to read, please use the "code" markup, but I can reproduce the bug with your code on 1.00. I've tried to shrink it to the error, only and used a simplified test-egl/eglcube.c, merged with some of your triangle draw code, which is compiled with the test-egl Makefile target. This is the code:

Code: Select all

#include <pspctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#include <GLES/egl.h>
#include <GLES/gl.h>


static const EGLint attrib_list &#91;&#93; = &#123;
	EGL_RED_SIZE, 8,
	EGL_GREEN_SIZE, 8,
	EGL_BLUE_SIZE, 8,
	EGL_ALPHA_SIZE, 8,
	EGL_DEPTH_SIZE, 16,
	EGL_NONE
&#125;;


int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	EGLDisplay dpy;
	EGLConfig config;
	EGLint num_configs;
	EGLContext ctx;
	EGLSurface surface;
	GLfloat angle = 0.0f;
	GLfloat zPos = 0.0f;
	int x, y;	    
	
	/* pass NativeDisplay=0, we only have one screen... */
	dpy = eglGetDisplay&#40;0&#41;;
	eglInitialize&#40;dpy, NULL, NULL&#41;;
	eglChooseConfig&#40;dpy, attrib_list, &config, 1, &num_configs&#41;;

	ctx = eglCreateContext&#40;dpy, config, NULL, NULL&#41;;
	surface = eglCreateWindowSurface&#40;dpy, config, 0, NULL&#41;;
	eglMakeCurrent&#40;dpy, surface, surface, ctx&#41;;

	glViewport&#40;0.0f, 0.0f, 480.0f, 272.0f&#41;;
	glMatrixMode&#40;GL_PROJECTION&#41;;
	glLoadIdentity&#40;&#41;;
	gluPerspectivef&#40;75.0f, 16.0f/9.0f, 0.5f, 1000.0f&#41;;
	glMatrixMode&#40;GL_MODELVIEW&#41;;
	
	while &#40;1&#41; &#123;
		glClear&#40;GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT&#41;;
		glLoadIdentity&#40;&#41;;
		gluLookAtf&#40;0.0f, 0.0f, 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f&#41;;
		glRotatef&#40;angle, 0.0f, 0.0f, 1.0f&#41;;
		glTranslatef&#40;0.0f, 0.0f, zPos&#41;;
		angle += 1.0f;
		zPos += 0.01f;
		if &#40;zPos > 0.9f&#41; zPos = 0.9f;
	
		for &#40;y=-2; y<3; y++&#41; &#123; 
			for &#40;x=-2; x<3; x++&#41; &#123; 
				glBegin&#40;GL_TRIANGLES&#41;; 
				  glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
				  glVertex3f&#40; 1.0f+x, 0.0f+y, 0.0f&#41;; 
				  glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
				  glVertex3f&#40; 0.0f+x, 1.0f+y, 0.0f&#41;; 
				  glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
				  glVertex3f&#40; -1.0f+x, 0.0f+y, 0.0f&#41;; 
				glEnd&#40;&#41;;
			&#125; 
		&#125; 
		glFlush&#40;&#41;;

		eglSwapBuffers&#40;dpy, surface&#41;;
	&#125;

	eglTerminate&#40;dpy&#41;;
	return 0;
&#125;
On my 1.00 PSP firmware it freezes after 2 seconds, on my 1.50 PSP firmware it spins forever.

There is another bug: on both firmware versions I can see a black stripe on top, with the width of the screen and about 10 pixels high, but sometime more and sometimes less. Looks like the glClear command overlaps the triangle draw command. Perhaps this is the reason for the freeze, because two command writes at the same time to the video ram. Without the "zPos += 0.01f;" line it doesn't freeze on the 1.00 firmware.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

I only have a 1.50, so I can't test the 1.00 problem... if anybody of you can help to track down this problem this would be very welcome!

About the black stripe: we still have a sync problem in pspgl_vidmem.c, pspgl_vidmem_setup_write_and_display_buffer(). Basically we would like to call sceDisplaySetFrameBuf() with the PSP_DISPLAY_SETBUF_IMMEDIATE argument, but then we only get a black screen, no idea why. Need to investigate this in detail.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

I applied a slight modification to the command buffer code, could you please update your pspgl source tree from SVN and test+report whether this improves the situation?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

holger wrote:I applied a slight modification to the command buffer code, could you please update your pspgl source tree from SVN and test+report whether this improves the situation?
Thanks, your SVN changes fixed the problem with the black border on top, but it still freezes on 1.00.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

A friend of mine with a 1.00 did some testing: he experienced, that the GE always locks up when a triangle comes near the boundary to the clip area, so all depth values where transformed triangles are about to almost get clipped are affected.

It's probably a bug in the firmware, but there is likely a workaround (otherwise no commercial 3D game would work, clipping is something very common - ). Could you please port your code to the libgu and see how it behaves there?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

holger wrote:A friend of mine with a 1.00 did some testing: he experienced, that the GE always locks up when a triangle comes near the boundary to the clip area, so all depth values where transformed triangles are about to almost get clipped are affected.
It is not clipping related. I've tried my code above with fixed zPos = -1.0f and it works, but when I add a glFinish() after the glEnd() in the inner loop of the triangle drawing section, it freezes.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

holger wrote: It's probably a bug in the firmware, but there is likely a workaround (otherwise no commercial 3D game would work, clipping is something very common - ). Could you please port your code to the libgu and see how it behaves there?
It is not exactly the same (I think there are differences with the viewing frustrum), but the result looks like the pspgl sample. And it doesn't freeze.

main.c:

Code: Select all

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspgu.h>
#include <string.h>
#include <math.h>

/* Define the module info section */
PSP_MODULE_INFO&#40;"GUTEST", 0x1000, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

/* Exit callback */
int exit_callback&#40;void&#41;
&#123;

// Unload modules
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", &#40;void *&#41; exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

static unsigned int __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; list&#91;262144&#93;;

struct Vertex
&#123;
	unsigned int color;
	float x, y, z;
&#125;;

void matrix_identity&#40;float* matrix&#41;
&#123;
	matrix&#91;&#40;0<<2&#41;+0&#93; = 1.0f;
	matrix&#91;&#40;0<<2&#41;+1&#93; = 0.0f;
	matrix&#91;&#40;0<<2&#41;+2&#93; = 0.0f;
	matrix&#91;&#40;0<<2&#41;+3&#93; = 0.0f;

	matrix&#91;&#40;1<<2&#41;+0&#93; = 0.0f;
	matrix&#91;&#40;1<<2&#41;+1&#93; = 1.0f;
	matrix&#91;&#40;1<<2&#41;+2&#93; = 0.0f;
	matrix&#91;&#40;1<<2&#41;+3&#93; = 0.0f;

	matrix&#91;&#40;2<<2&#41;+0&#93; = 0.0f;
	matrix&#91;&#40;2<<2&#41;+1&#93; = 0.0f;
	matrix&#91;&#40;2<<2&#41;+2&#93; = 1.0f;
	matrix&#91;&#40;2<<2&#41;+3&#93; = 0.0f;

	matrix&#91;&#40;3<<2&#41;+0&#93; = 0.0f;
	matrix&#91;&#40;3<<2&#41;+1&#93; = 0.0f;
	matrix&#91;&#40;3<<2&#41;+2&#93; = 0.0f;
	matrix&#91;&#40;3<<2&#41;+3&#93; = 1.0f;
&#125;

void matrix_projection&#40;float* matrix, float fovy, float aspect, float near, float far&#41;
&#123;
	matrix_identity&#40;matrix&#41;;

		float angle = &#40;fovy / 2.0f&#41; * &#40;M_PI/180.0f&#41;;
	float cotangent = cosf&#40;angle&#41; / sinf&#40;angle&#41;;

	matrix&#91;&#40;0<<2&#41;+0&#93; = cotangent / aspect;
	matrix&#91;&#40;1<<2&#41;+1&#93; = cotangent;
	matrix&#91;&#40;2<<2&#41;+2&#93; = &#40;far + near&#41; / &#40;near - far&#41;;
	matrix&#91;&#40;3<<2&#41;+2&#93; = 2.0f * &#40;far * near&#41; / &#40;near - far&#41;;
	matrix&#91;&#40;2<<2&#41;+3&#93; = -1.0f;
	matrix&#91;&#40;3<<2&#41;+3&#93; = 0.0f;
&#125;

void matrix_multiply&#40;float* result, float* a, float* b&#41;
&#123;
	unsigned int i, j, k;
	float temp&#91;16&#93;;

	for &#40;i = 0; i < 4; ++i&#41;
	&#123;
		for &#40;j = 0; j < 4; ++j&#41;
		&#123;
			float t = 0.0f;
			for &#40;k = 0; k < 4; ++k&#41;
				t += a&#91;&#40;k << 2&#41;+j&#93; * b&#91;&#40;i << 2&#41;+k&#93;;
			temp&#91;&#40;i << 2&#41;+j&#93; = t;
		&#125;
	&#125;

	memcpy&#40;result, temp, sizeof&#40;float&#41;*16&#41;;
&#125;

void matrix_translate&#40;float* matrix, float x, float y, float z&#41;
&#123;
	float temp&#91;16&#93;;

	matrix_identity&#40;temp&#41;;
	temp&#91;&#40;3 << 2&#41;+0&#93; = x;
	temp&#91;&#40;3 << 2&#41;+1&#93; = y;
	temp&#91;&#40;3 << 2&#41;+2&#93; = z;

	matrix_multiply&#40;matrix, matrix, temp&#41;;
&#125;

void matrix_setrotatex&#40;float* matrix, float angle&#41;
&#123;
	float cs = cosf&#40;angle&#41;;
	float sn = sinf&#40;angle&#41;;

	matrix_identity&#40;matrix&#41;;
	matrix&#91;&#40;1<<2&#41;+1&#93; = cs;
	matrix&#91;&#40;1<<2&#41;+2&#93; = sn;
	matrix&#91;&#40;2<<2&#41;+1&#93; = -sn;
	matrix&#91;&#40;2<<2&#41;+2&#93; = cs;
&#125;

void matrix_setrotatey&#40;float* matrix, float angle&#41;
&#123;
	float cs = cosf&#40;angle&#41;;
	float sn = sinf&#40;angle&#41;;

	matrix_identity&#40;matrix&#41;;
	matrix&#91;&#40;0<<2&#41;+0&#93; = cs;
	matrix&#91;&#40;0<<2&#41;+2&#93; = -sn;
	matrix&#91;&#40;2<<2&#41;+0&#93; = sn;
	matrix&#91;&#40;2<<2&#41;+2&#93; = cs;
&#125;

void matrix_setrotatez&#40;float* matrix, float angle&#41;
&#123;
	float cs = cosf&#40;angle&#41;;
	float sn = sinf&#40;angle&#41;;

	matrix_identity&#40;matrix&#41;;
	matrix&#91;&#40;0<<2&#41;+0&#93; = cs;
	matrix&#91;&#40;0<<2&#41;+1&#93; = sn;
	matrix&#91;&#40;1<<2&#41;+0&#93; = -sn;
	matrix&#91;&#40;1<<2&#41;+1&#93; = cs;
&#125;

void matrix_rotate&#40;float* matrix, float x, float y, float z&#41;
&#123;
	float temp&#91;16&#93;;

	matrix_setrotatex&#40;temp, x&#41;;
	matrix_multiply&#40;matrix, matrix, temp&#41;;

	matrix_setrotatey&#40;temp, y&#41;;
	matrix_multiply&#40;matrix, matrix, temp&#41;;

	matrix_setrotatez&#40;temp, z&#41;;
	matrix_multiply&#40;matrix, matrix, temp&#41;;
&#125;

#define BUF_WIDTH &#40;512&#41;
#define SCR_WIDTH &#40;480&#41;
#define SCR_HEIGHT &#40;272&#41;
#define PIXEL_SIZE &#40;4&#41; /* change this if you change to another screenmode */
#define FRAME_SIZE &#40;BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE&#41;
#define ZBUF_SIZE &#40;BUF_WIDTH SCR_HEIGHT * 2&#41; /* zbuffer seems to be 16-bit? */

int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	ScePspFMatrix4 projection;
	ScePspFMatrix4 view;
	ScePspFMatrix4 world;
	int val = 0;
	
	SetupCallbacks&#40;&#41;;
	
	sceGuInit&#40;&#41;;
	
	// setup
	sceGuStart&#40;0, list&#41;;
	sceGuDrawBuffer&#40;GU_PSM_8888, &#40;void*&#41;0, BUF_WIDTH&#41;;
	sceGuDispBuffer&#40;SCR_WIDTH, SCR_HEIGHT, &#40;void*&#41;0x88000, BUF_WIDTH&#41;;
	sceGuDepthBuffer&#40;&#40;void*&#41;0x110000, BUF_WIDTH&#41;;
	sceGuOffset&#40;2048 - &#40;SCR_WIDTH/2&#41;, 2048 - &#40;SCR_HEIGHT/2&#41;&#41;;
	sceGuViewport&#40;2048, 2048, SCR_WIDTH, SCR_HEIGHT&#41;;
	sceGuDepthRange&#40;0xc350, 0x2710&#41;;
	sceGuScissor&#40;0, 0, SCR_WIDTH, SCR_HEIGHT&#41;;
	sceGuEnable&#40;GU_SCISSOR_TEST&#41;;
	sceGuDepthFunc&#40;GU_GEQUAL&#41;;
	sceGuEnable&#40;GU_DEPTH_TEST&#41;;
	sceGuDisable&#40;GU_CULL_FACE&#41;;
	sceGuFinish&#40;&#41;;
	sceGuSync&#40;0, 0&#41;;
	
	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuDisplay&#40;1&#41;;
	float zPos = -5.0;
	while &#40;1&#41; &#123;
		sceGuStart&#40;0, list&#41;;
		
		sceGuClearColor&#40;0&#41;;
		sceGuClearDepth&#40;0&#41;;
		sceGuClear&#40;GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT&#41;;
		
		val++;
		
		matrix_identity&#40;&#40;float*&#41;&projection&#41;;
		matrix_projection&#40;&#40;float*&#41;&projection, 75.0f, 16.0/9.0f, 1.0f, 1000.0f&#41;;
		sceGuSetMatrix&#40;GU_PROJECTION, &projection&#41;;
		
		matrix_identity&#40;&#40;float*&#41;&view&#41;;
		sceGuSetMatrix&#40;GU_VIEW, &view&#41;;
		
		matrix_identity&#40;&#40;float*&#41;&world&#41;;
		matrix_translate&#40;&#40;float*&#41;&world, 0.0f, 0.0f, zPos&#41;;
		zPos += 0.01f;
		if &#40;zPos > -2.0f&#41; zPos = -2.0f;
		matrix_rotate&#40;&#40;float*&#41;&world, 0, 0, val * 0.79f * &#40;M_PI/180.0f&#41;&#41;;
		sceGuSetMatrix&#40;GU_MODEL, &world&#41;;
		
		int x, y;		
		for &#40;y=-2; y<3; y++&#41; &#123; 
			for &#40;x=-2; x<3; x++&#41; &#123; 
				struct Vertex* vertices = &#40;struct Vertex*&#41; sceGuGetMemory&#40;3 * sizeof&#40;struct Vertex&#41;&#41;;
				vertices&#91;0&#93;.color = 0xffffffff;
				vertices&#91;0&#93;.x = 1.0f+x;
				vertices&#91;0&#93;.y = 0.0f+y;
				vertices&#91;0&#93;.z = 0.0f;
				vertices&#91;1&#93;.color = 0xffffffff;
				vertices&#91;1&#93;.x = 0.0f+x;
				vertices&#91;1&#93;.y = 1.0f+y;
				vertices&#91;1&#93;.z = 0.0f;
				vertices&#91;2&#93;.color = 0xffffffff;
				vertices&#91;2&#93;.x = -1.0f+x;
				vertices&#91;2&#93;.y = 0.0f+y;
				vertices&#91;2&#93;.z = 0.0f;
				sceGuDrawArray&#40;GU_TRIANGLES, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 3, 0, vertices&#41;;
			&#125; 
		&#125;
		sceGuFinish&#40;&#41;;
		
		
		sceGuSync&#40;0, 0&#41;;
		sceDisplayWaitVblankStart&#40;&#41;;
		sceGuSwapBuffers&#40;&#41;;
	&#125;
	sceGuTerm&#40;&#41;;
	
	return 0;
&#125;
Makefile:

Code: Select all

TARGET = gutest
OBJS = main.o

INCDIR =
CFLAGS = -G0 -Wall -O2 -fno-strict-aliasing
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
LIBS= -lpspgu -lm


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GU Test

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

ok, thanks - that's a good step toward a solution. let's see where exactly the difference is...
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Re: pspgl freezes

Post by holger »

cadaver wrote: - can't get the depth buffer to work (tried with glEnable(GL_DEPTH_TEST))
Can you please update your source tree and try again? Z coordinate direction was reversed, please let me know if that was the root of your problem.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: pspgl freezes

Post by Shine »

cadaver wrote:- after a few seconds the prog. freezes on the psp, it works o.k. when just the polygons of the original sample are rendered, any buffers must be cleared before rendering ???
Try the latest pspgl version from SVN, with the latest pspsdk and toolchain (see http://forums.ps2dev.org/viewtopic.php?p=26380#26380 ).
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Shine wrote:
holger wrote: It's probably a bug in the firmware, but there is likely a workaround (otherwise no commercial 3D game would work, clipping is something very common - ). Could you please port your code to the libgu and see how it behaves there?
It is not exactly the same (I think there are differences with the viewing frustrum), but the result looks like the pspgl sample. And it doesn't freeze.
If the problem relates to clipping, then this could make all the difference.

I adjusted the EGL test a little bit; it should be exactly the same, but it batches things in larger batches. It would be interesting to know if it makes a difference.

Just out of curiosity, is there any reason to not want to update 1.0->1.5?

Code: Select all

#include <pspctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

#include <GLES/egl.h>
#include <GLES/gl.h>


static const EGLint attrib_list &#91;&#93; = &#123;
	EGL_RED_SIZE, 8,
	EGL_GREEN_SIZE, 8,
	EGL_BLUE_SIZE, 8,
	EGL_ALPHA_SIZE, 8,
	EGL_DEPTH_SIZE, 16,
	EGL_NONE
&#125;;


int main&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	EGLDisplay dpy;
	EGLConfig config;
	EGLint num_configs;
	EGLContext ctx;
	EGLSurface surface;
	GLfloat angle = 0.0f;
	GLfloat zPos = 0.0f;
	int x, y;      
   
	/* pass NativeDisplay=0, we only have one screen... */
	dpy = eglGetDisplay&#40;0&#41;;
	eglInitialize&#40;dpy, NULL, NULL&#41;;
	eglChooseConfig&#40;dpy, attrib_list, &config, 1, &num_configs&#41;;

	ctx = eglCreateContext&#40;dpy, config, NULL, NULL&#41;;
	surface = eglCreateWindowSurface&#40;dpy, config, 0, NULL&#41;;
	eglMakeCurrent&#40;dpy, surface, surface, ctx&#41;;

	glViewport&#40;0.0f, 0.0f, 480.0f, 272.0f&#41;;
	glMatrixMode&#40;GL_PROJECTION&#41;;
	glLoadIdentity&#40;&#41;;
	gluPerspectivef&#40;75.0f, 16.0f/9.0f, 0.5f, 1000.0f&#41;;
	glMatrixMode&#40;GL_MODELVIEW&#41;;
   
	glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
	while &#40;1&#41; &#123;
		glClear&#40;GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT&#41;;
		glLoadIdentity&#40;&#41;;
		gluLookAtf&#40;0.0f, 0.0f, 2.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f&#41;;
		glRotatef&#40;angle, 0.0f, 0.0f, 1.0f&#41;;
		glTranslatef&#40;0.0f, 0.0f, zPos&#41;;
		angle += 1.0f;
		zPos += 0.01f;
		if &#40;zPos > 0.9f&#41; zPos = 0.f;
		
		glBegin&#40;GL_TRIANGLES&#41;;
		for &#40;y=-2; y<3; y++&#41; &#123;
			for &#40;x=-2; x<3; x++&#41; &#123;
				glVertex3f&#40; 1.0f+x, 0.0f+y, 0.0f&#41;;
				glVertex3f&#40; 0.0f+x, 1.0f+y, 0.0f&#41;;
				glVertex3f&#40; -1.0f+x, 0.0f+y, 0.0f&#41;;
			&#125;
		&#125;
		glEnd&#40;&#41;;
		//glFlush&#40;&#41;;

		eglSwapBuffers&#40;dpy, surface&#41;;
	&#125;

	eglTerminate&#40;dpy&#41;;
	return 0;
&#125; 
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

jsgf wrote:Just out of curiosity, is there any reason to not want to update 1.0->1.5?
  1. kxploit
  2. It's 1.5.
  3. 1.0 just has this hardcore feel to it.
:)
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

jsgf wrote:If the problem relates to clipping, then this could make all the difference.

I adjusted the EGL test a little bit; it should be exactly the same, but it batches things in larger batches. It would be interesting to know if it makes a difference.
It's the same. With the SVN version it works and with your tree of pspgl it freezes immediatly after startup (black screen, but exit game is possible).
jsgf wrote: Just out of curiosity, is there any reason to not want to update 1.0->1.5?
mrbrown answered this already :-) but seriously, homebrews programs starts faster on 1.0 firmware PSPs and I might be wrong, but I feel if it works on 1.0 and 1.5, then the program is more stable and it will work on every firmware version (once there will be exploits for it).
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Shine wrote:It's the same. With the SVN version it works and with your tree of pspgl it freezes immediatly after startup (black screen, but exit game is possible).
OK, so that's a different behaviour? Previously it would run for a bit before hanging?

The big, possibly relevent difference between my PSPGL and SVN is that I've flipped the Z direction around to get depth-testing working properly. Aside from that, there really isn't very much in PSPGL which could make a difference. I suspect that other programs will hang one or the other version of PSPGL.

The fact that the PSP doesn't lock solid suggests that GE is hanging, but the main CPU is still fine; I would guess it is blocked in a sceGeListSync() call.
mrbrown answered this already :-) but seriously, homebrews programs starts faster on 1.0 firmware PSPs and I might be wrong, but I feel if it works on 1.0 and 1.5, then the program is more stable and it will work on every firmware version (once there will be exploits for it).
Well, yes, but since the GE hangs with an apparently OK program, it looks like buggy GE firmware.

Could you grab a register dump of a hanging run? Set #if 1 around the pspgl_ge_register_dump defines in pspgl_misc.h; it will put a pspgl.ge file on the root of your stick (make sure you don't have an old one hanging around).
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

jsgf wrote:
Shine wrote:It's the same. With the SVN version it works and with your tree of pspgl it freezes immediatly after startup (black screen, but exit game is possible).
OK, so that's a different behaviour? Previously it would run for a bit before hanging?

The big, possibly relevent difference between my PSPGL and SVN is that I've flipped the Z direction around to get depth-testing working properly. Aside from that, there really isn't very much in PSPGL which could make a difference. I suspect that other programs will hang one or the other version of PSPGL.
a friend of mine did some testing on his 1.00 and the problem seems indeed depth-related.
Shine: Could you replace the glDepthRange() call by libGu's DepthRange() in your test program? This inverts the depth orientation but should avoid the lock-up if the theory above is true.
Well, yes, but since the GE hangs with an apparently OK program, it looks like buggy GE firmware.
yes, sounds like a bug, but since quite a lot of commercial games work there must at least be some workaround possible...
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

jsgf wrote:
Shine wrote:It's the same. With the SVN version it works and with your tree of pspgl it freezes immediatly after startup (black screen, but exit game is possible).
OK, so that's a different behaviour? Previously it would run for a bit before hanging?
Yes. I've done the register dump: http://www.frank-buss.de/tmp/pspgl.ge.zip
holger wrote: Shine: Could you replace the glDepthRange() call by libGu's DepthRange() in your test program? This inverts the depth orientation but should avoid the lock-up if the theory above is true.
I've changed it like this:

Code: Select all

void glDepthRangef &#40;GLclampf near, GLclampf far&#41;
&#123;
	unsigned int max = &#40;unsigned int&#41;near + &#40;unsigned int&#41;far;
	int val = &#40;int&#41;&#40;&#40;max >> 31&#41; + max&#41;;
	float z = &#40;float&#41;&#40;val >> 1&#41;;

        sendCommandf&#40;68,z - &#40;&#40;float&#41;near&#41;&#41;;
        sendCommandf&#40;71,z + &#40;&#40;float&#41;pspgl_curctx->depth_offset&#41;&#41;;

	if &#40;near > far&#41;
        &#123;
          int temp = near;
          near = far;
          far = temp;
        &#125;

        sendCommandi&#40;214,near&#41;;
        sendCommandi&#40;215,far&#41;;
&#125;
Same bug.

I know not much about the PSP internals, but I assume it must be a trivial, but subtle problem, perhaps the order in which some commands are sent is wrong or some caching problem, like GE doesn't allow some kind memory access after or before submitting commands.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

Shine wrote: Same bug.

I know not much about the PSP internals, but I assume it must be a trivial, but subtle problem, perhaps the order in which some commands are sent is wrong or some caching problem, like GE doesn't allow some kind memory access after or before submitting commands.
is the assumption correct that the bug goes away if you exchange the values for near and far (e.g. 0.0 and 65535)?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

holger wrote:is the assumption correct that the bug goes away if you exchange the values for near and far (e.g. 0.0 and 65535)?
no, same problem. I've tried far = 65535; near = 0.0; at the beginning of glDepthRangef and exchanged, but both freezed with jsgf's version. Perhaps a diff to the SVN version should show some hints. But perhaps it is not that much important, as long as it works with the SVN version.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Shine wrote:no, same problem. I've tried far = 65535; near = 0.0; at the beginning of glDepthRangef and exchanged, but both freezed with jsgf's version. Perhaps a diff to the SVN version should show some hints. But perhaps it is not that much important, as long as it works with the SVN version.
I would assume that some other test program would also hang with the SVN version, since the two versions aren't really doing anything very different for a simple test program like this.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Shine wrote:Yes. I've done the register dump: http://www.frank-buss.de/tmp/pspgl.ge.zip
Thanks, but I need a bit more info. Could you run two more tests, using this inner loop:

Code: Select all

      glFinish&#40;&#41;;
      for &#40;y=-2; y<3; y++&#41; &#123;
         for &#40;x=-2; x<3; x++&#41; &#123;
            glBegin&#40;GL_TRIANGLES&#41;;
              glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
              glVertex3f&#40; 1.0f+x, 0.0f+y, 0.0f&#41;;
              glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
              glVertex3f&#40; 0.0f+x, 1.0f+y, 0.0f&#41;;
              glColor3f&#40;0.0f, 0.0f, 1.0f&#41;;
              glVertex3f&#40; -1.0f+x, 0.0f+y, 0.0f&#41;;
            glEnd&#40;&#41;;
            glFinish&#40;&#41;;
         &#125;
      &#125;
and get a register dump from a run with both my and SVN PSPGL? That should really help pinpoint what actually causes the hang.

Thanks,
J
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

I'm being bit by similar hangs and crashes using PSPGL (the latest in SVN) on a 1.0 PSP. I just checked in support for PSPGL in SDL. If I try the spinning triangle test using PSPGL's glut.c (unmodified), the PSP crashes after the program launches. If I convert the glut.c test to go through SDL's OpenGL interface (source below), I get a hang instead.

Here is the source and Makefile for the SDL PSPGL test that I'm using:

Code: Select all

/* Test SDL OpenGL support. */
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include "SDL_opengl.h"

#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272

static GLfloat delta = 1.0f;
static GLfloat angle;

int main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
    int done = 0;

    if &#40;SDL_Init&#40;SDL_INIT_VIDEO | SDL_INIT_JOYSTICK&#41; < 0&#41;
    &#123;
        fprintf&#40;stderr, "Unable to initialize SDL&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
        return 1;
    &#125;

    if &#40;SDL_SetVideoMode&#40;SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_FULLSCREEN&#41; == NULL&#41;
    &#123;
        fprintf&#40;stderr, "Unable to create OpenGL screen&#58; %s\n", SDL_GetError&#40;&#41;&#41;;
        SDL_Quit&#40;&#41;;
        return 1;
    &#125;

    glViewport&#40;0, 0, SCREEN_WIDTH, SCREEN_HEIGHT&#41;;
    glMatrixMode&#40;GL_PROJECTION&#41;;
    glLoadIdentity&#40;&#41;;
    glOrtho&#40;-2, 2, -2, 2, -2, 2&#41;;
    glMatrixMode&#40;GL_MODELVIEW&#41;;
    glLoadIdentity&#40;&#41;;

//  while &#40;!done&#41;
    &#123;
        glClearColor&#40;0.0f, 0.0f, 0.0f, 0.0f&#41;;

        angle += delta;
        glMatrixMode&#40;GL_MODELVIEW&#41;;
        glLoadIdentity&#40;&#41;;
        glRotatef&#40;angle * 1.32f, 0.0f, 0.0f, 1.0f&#41;;

        glShadeModel&#40;GL_SMOOTH&#41;;

        glClear&#40;GL_COLOR_BUFFER_BIT&#41;;
        glBegin&#40;GL_TRIANGLES&#41;;
            glColor3f&#40;0.0f, 0.0f, 1.0f&#41;; glVertex3f&#40;1.0f, 0.0f, 0.0f&#41;;
            glColor3f&#40;0.0f, 1.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 1.0f, 0.0f&#41;;
            glColor3f&#40;1.0f, 0.0f, 0.0f&#41;; glVertex3f&#40;0.0f, 0.0f, 1.0f&#41;;
        glEnd&#40;&#41;;
        glFinish&#40;&#41;;

        SDL_GL_SwapBuffers&#40;&#41;;
    &#125;

    return 0;
&#125;

Code: Select all

TARGET = ogl-test
PSPSDK = $&#40;shell psp-config --pspsdk-path&#41;
PSPPREFIX = $&#40;shell psp-config --psp-prefix&#41;
PSPBIN = $&#40;PSPPREFIX&#41;/bin
SDL_CONFIG = $&#40;PSPBIN&#41;/sdl-config

OBJS =  $&#40;TARGET&#41;.o

DEFAULT_CFLAGS = $&#40;shell $&#40;SDL_CONFIG&#41; --cflags&#41;

MORE_CFLAGS = -O2 -fsingle-precision-constant #-ffast-math

CFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41;
CXXFLAGS = $&#40;DEFAULT_CFLAGS&#41; $&#40;MORE_CFLAGS&#41; -fno-exceptions

LDFLAGS = -L$&#40;PSPPREFIX&#41;/lib
LIBS = -lGLU $&#40;shell $&#40;SDL_CONFIG&#41; --libs&#41; -lstdc++ -lm

EXTRA_TARGETS = EBOOT.PBP

include $&#40;PSPSDK&#41;/lib/build.mak
I turned on both log.txt logging and the pspgl.ge dump, and grabbed the output from my 1.0 PSP and a friend's 1.5. The diff of PSPGL's log.txt is as follows (+ lines are from the 1.5 PSP):

Code: Select all

@@ -27,3 +27,8 @@
 __pspgl_vidmem_setup_write_and_display_buffer &#40;140&#41;&#58; color buffer adr 0x04044000
 __pspgl_vidmem_setup_write_and_display_buffer &#40;146&#41;&#58; depth buffer adr 0x04088000
 __pspgl_vidmem_setup_write_and_display_buffer &#40;167&#41;&#58; display @ adr 0x0x04000000

+__pspgl_vidmem_setup_write_and_display_buffer &#40;128&#41;&#58; current_front 1
+__pspgl_vidmem_setup_write_and_display_buffer &#40;135&#41;&#58; pixfmt 0
+__pspgl_vidmem_setup_write_and_display_buffer &#40;140&#41;&#58; color buffer adr 0x04000000
+__pspgl_vidmem_setup_write_and_display_buffer &#40;146&#41;&#58; depth buffer adr 0x04088000
+__pspgl_vidmem_setup_write_and_display_buffer &#40;167&#41;&#58; display @ adr 0x0x04044000
It looks like PSPGL hangs in glFinish(). A diff of the decode_ge_dump output from both PSPs also seems to indicate this. jsgf, I've PM'd you with info on where these dumps are (I don't have any publically accessible web site).
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

I've figured out a workaround to the hang: calling sceGuInit() at the top of my test program gets rid of the issues. The only thing sceGuInit() does is send a GE list and setup the GE callbacks (which do nothing if you don't use them). So it seems either that full init sequence must be sent to the GE, or the GE needs to be primed with the sceGeListEnqueue() and sceGeListSync() calls before doing anything else.

I've gone ahead and applied the workaround in the SDL backend.

Yeah, OK, I just added sceGuInit() to my local psp-setup.c, and all of the PSPGL tests appear to be working now.

Thanks goes to rinco for suggesting that this was the problem (and suggesting the workaround).
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Do you know if its the callback setup or the register writes which count? My guess would be that there's a 1.0 firmware bug in which it tries to call the callbacks even if they're not registered, so you need to always install no-op callbacks. Does that seem reasonable?
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Holger's original PSPGL did not set a GE callback, and it worked fine on 1.0 PSPs. However, he did initialize the GE (pspgl_ge_init()) by sending a list similiar to the one used in sceGuInit().
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Yeah, I've just confirmed it. If I comment out the list transfer and leave in the call, it crashes as before. If I comment out the sceGeSetCallback() call and leave in the list it works just fine.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

OK, so its some register which needs to be set to a default value. PSPGL still has that big table of initial settings, but it has been changed somewhat.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

OK, I'm confused. Current head PSPGL and Holger's last version are initializing the same set of registers, though not to precisely the same values.

The table sceGuInit uses zeros out a lot more of the register state, which could be a contributing factor. But I can't see why older PSPGLs would have worked but current ones not on 1.0 PSPs.

Hm, sceGuInit makes sure to initialize texture 0 to the base of VRAM, even though it doesn't set up any other textures. I wonder if 1.0 firmware makes spurious texture fetches even if texturing is disabled?

I'll check in a test change into SVN shortly...
Post Reply