does this look ok jim im getting 73 fps so im guessing its not to bad.
i was getting 713 fps before i started updating the xor image each frame.
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspctrl.h>
#include <pspgu.h>
#include <psprtc.h>
#include "../common/callbacks.h"
#include "../common/vram.h"
PSP_MODULE_INFO("FrameBuffer", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
static unsigned int __attribute__((aligned(16))) list[262144];
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
static unsigned short __attribute__((aligned(16))) pixels[BUF_WIDTH*SCR_HEIGHT];
struct Vertex
{
unsigned short u, v;
unsigned short color;
short x, y, z;
};
void advancedBlit(int sx, int sy, int sw, int sh, int dx, int dy, int slice)
{
int start, end;
// blit maximizing the use of the texture-cache
for (start = sx, end = sx+sw; start < end; start += slice, dx += slice)
{
struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
int width = (start + slice) < end ? slice : end-start;
vertices[0].u = start; vertices[0].v = sy;
vertices[0].color = 0;
vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0;
vertices[1].u = start + width; vertices[1].v = sy + sh;
vertices[1].color = 0;
vertices[1].x = dx + width; vertices[1].y = dy + sh; vertices[1].z = 0;
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_4444|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
}
}
int main(int argc, char* argv[])
{
unsigned int x,y,xs,ys;
pspDebugScreenInit();
setupCallbacks();
void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
sceGuDepthBuffer(zbp,BUF_WIDTH);
sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
sceGuDepthRange(65535,0);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuFrontFace(GU_CW);
sceGuEnable(GU_TEXTURE_2D);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(1);
void* vram_buffer;
vram_buffer = getStaticVramTexture(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
float curr_ms = 1.0f;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(0);
u64 last_tick;
sceRtcGetCurrentTick(&last_tick);
u32 tick_frequency = sceRtcGetTickResolution();
int frame_count = 0;
while(running())
{
for (y = 0; y < SCR_HEIGHT; ++y)
{
unsigned short* row = &pixels[y * BUF_WIDTH];
for (x = 0; x < SCR_WIDTH; ++x)
{
row[x] = (x+xs)*(y+ys);
}
}
memcpy( vram_buffer , pixels , ( BUF_WIDTH * 2 ) * SCR_HEIGHT);
xs+=1;
ys+=1;
sceKernelDcacheWritebackAll();
sceGuStart(GU_DIRECT,list);
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,512,512,512,vram_buffer);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA);
sceGuTexFilter(GU_NEAREST,GU_NEAREST);
advancedBlit(0,0,SCR_WIDTH,SCR_HEIGHT,0,0,64);
sceGuFinish();
sceGuSync(0,0);
float curr_fps = 1.0f / curr_ms;
pspDebugScreenSetOffset((int)fbp0);
pspDebugScreenSetXY(0,0);
pspDebugScreenPrintf("fps: %d.%03d (%dMB/s)",(int)curr_fps,(int)((curr_fps-(int)curr_fps) * 1000.0f),(((int)curr_fps * SCR_WIDTH * SCR_HEIGHT * 2)/(1024*1024)));
fbp0 = sceGuSwapBuffers();
++frame_count;
u64 curr_tick;
sceRtcGetCurrentTick(&curr_tick);
if ((curr_tick-last_tick) >= tick_frequency)
{
float time_span = ((int)(curr_tick-last_tick)) / (float)tick_frequency;
curr_ms = time_span / frame_count;
frame_count = 0;
sceRtcGetCurrentTick(&last_tick);
}
}
sceGuTerm();
sceKernelExitGame();
return 0;
}