Skip to main content
gamedev.net
🔒 Locked

Framerate issues.

Started by robustpotato Mar 18, 2011 at 10:43 PM 5 replies 2k views
Original Post
robustpotato
robustpotato
recently implemented a water effect using a shader, and rendering a reflection map to a texture. my frame rate is fine when first running, but then dips after a while. I removed the water but kept in the part where it renders to a texture and the problem persists so I'm thinking its to do with that.

Heres my method




D3DXVECTOR3 oldCamPos= currentCamera->GetPosition();
float oldCamXRotation = currentCamera->GetRotation().x;

currentCamera->SetRotation(D3DXVECTOR3( - oldCamXRotation, currentCamera->GetRotation().y,currentCamera->GetRotation().x));
float newCamHeight = oldCamPos.y -((oldCamPos.y-(8.9*5))*2);
currentCamera->SetPosition(D3DXVECTOR3(oldCamPos.x,newCamHeight,oldCamPos.z));


//################################## RENDERING TO TEXTURE
//set render target
device->SetRenderTarget(0,pRenderSurface);
//############################ CLEAR
device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
//################//now draw scene
device->BeginScene();
device->SetTransform( D3DTS_VIEW, &currentCamera->GetViewMatrix() );
device->SetTransform( D3DTS_PROJECTION, &matProjection );

//render skydome with no zbuffer
device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
skydome->Render(device);

//re enable z buffer to draw everything else.
//device->SetRenderState(D3DRS_ZWRITEENABLE , D3DZB_TRUE);
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

//##########CLIPPING


D3DXMATRIXA16 matrix = myTerrain->GetWorldMatrix() * currentCamera->GetViewMatrix()* matProjection ;
D3DXMatrixInverse(&matrix, NULL, &matrix); // second parameter is an out parameter for the determinant
D3DXMatrixTranspose(&matrix, &matrix);

D3DXPLANE viewSpacePlane;
D3DXPlaneTransform(&viewSpacePlane, &plane, &matrix);

planearray[0] = viewSpacePlane.a;
planearray[1] = viewSpacePlane.b;
planearray[2] = viewSpacePlane.c;
planearray[3] = viewSpacePlane.d;

device->SetClipPlane(0, planearray);
device->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 );
//draw terrain
myTerrain->Render(device);
device->EndScene();

currentCamera->SetPosition(oldCamPos);
currentCamera->SetRotation(D3DXVECTOR3(oldCamXRotation,currentCamera->GetRotation().y,currentCamera->GetRotation().x));





The texture im rendering to is 256x256. I am rendering a fairly big scene, a terrain 256x256 verts, but the framerate is absolutely fine without running the above method. and even when it is running the method it starts off fine. I dunno what im doing wrong. can anyone help? cheers

Buckeye
Buckeye
First, you don't check for any errors. You should at least use the FAILED and SUCCEEDED macros to check functions that return HRESULT codes.

Does the Debug Runtime provide any information?
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
robustpotato
robustpotato
What sort of thinks an fail with HRESULT. Everything looks as it should. Im getting D3DX: MEMORY LEAKS DETECTED: 188 allocations unfreed (98839 bytes). Is that something to do with it.

i used the DX control panel and applied debug. now nothing draws except my skybox. Thats the only thing thts drawn with the fixed functin pipeline. my terrain and the water are both done with shaders.

Console Output:


First-chance exception at 0x769442eb in RenderEngine.exe: Microsoft C++ exception: long at memory location 0x0032ede4..
Direct3D9: (ERROR) :DrawPrimitive failed.

Direct3D9: (ERROR) :Primitive count or vertex count is too big. Check device caps.


I am quite new to DirectX and C++. Im not to experience at debugging. I find it strange how it wont draw using debug version but will with retail.
Aqua Costa
Aqua Costa

What sort of thinks an fail with HRESULT. Everything looks as it should. Im getting D3DX: MEMORY LEAKS DETECTED: 188 allocations unfreed (98839 bytes). Is that something to do with it.

Try to find whats causing this and try to fix it or post here and someone might help you...


First-chance exception at 0x769442eb in RenderEngine.exe: Microsoft C++ exception: long at memory location 0x0032ede4..
Direct3D9: (ERROR) :DrawPrimitive failed.

Direct3D9: (ERROR) :Primitive count or vertex count is too big. Check device caps.

Looks like you are trying to draw a mesh with too many vertices... Use the DeviceCaps Viewer (a tool in the DirectX SDK) and see whats the vertex cout limit of your GPU.
Probably you did some mistake when you created the mesh because in my GPU the max vertex count is over 8 million, and I dont believe you want to draw a mesh with 8 million vertices in a single draw call... Post some screenshots of what the scene look like and what it should look like.... And also try to find what line of code is causing this error...


I am quite new to DirectX and C++. Im not to experience at debugging. I find it strange how it wont draw using debug version but will with retail.

When developing you should use always a debug version... because in release version the compiler might ignore some errors and allow the game to render everything with with big performance issues like the one you are suffering from...
robustpotato
robustpotato
It says Max Primitives = 65, 535 Max Vertex Index = 65, 534

256 x 256 verts is 65, 536.

and its rendering twice... once to a texture for reflections and once to the scene. the render to texture is clipped though.

I want to have a huge terrain, I need some more optimization.





as for the memory leaks. I found something
D3DX: MEMORY LEAKS DETECTED: 188 allocations unfreed (98839 bytes).

I removed all rendering code and then tried again


D3DX: MEMORY LEAKS DETECTED: 186 allocations unfreed (98375 bytes)

Then i removed the following line in the load function:

HRESULT hr;
hr = D3DXCreateEffectFromFile(device,"WaterShader.fx",NULL,NULL,0,NULL,&anEffect,NULL);


and now i get:

D3DX: MEMORY LEAKS DETECTED: 127 allocations unfreed (80316 bytes)

how can loading in a .fx file create memory leaks.


I am calling this line in my clean function

anEffect->release();















21st Century Moose
21st Century Moose
ID3DXEffect also creates and uses stateblocks which won't get released if you just release the effect.

General rule: if a D3DX object has an OnLostDevice method you should always call it before releasing the object. So you need to call anEffect->OnLostDevice before anEffect->Release.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
robustpotato
robustpotato
Ok. cleaned out most of my project and eventually got to 0 memory leaks.
but i get the following in the console after exiting.


Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 1269791 bytes

No idea where that is coming from.

Anyway my real problem is framerate, and cleaning up at the end cant possibly have any effect on my in game frame rate. I switched to using less verticess and its fine.

EDIT: I cleaned out nearly everything. and slowly added stuff back. its the shader

it loads at the beginning

then in clean does this:

landShader->OnLostDevice();
landShader->Release()



and i get.

Direct3D9: (ERROR) :Memory still allocated! Alloc count = 276

without the load/clean functions I get no errors on shutting down the program.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.