Sign in to follow this  
Magogan

Performance problems when loading heightmaps

Recommended Posts

Hi,

 

I have figured out how to build vertices from a heightmap. I currently load 33*33 heightmaps in my game. When I move in game, I delete the heightmaps and vertices that are too far away and build new ones at the right location. But when I load these vertices into the GPU memory, the framerate is dropping down to about 30 for a second, then it is 60 until new vertices are loaded and so on...

 

What my program is doing:

 

At initialization: Create buffers (with D3D11_USAGE_DEFAULT)

 

Multithreaded: Create arrays and store them in RAM

 

in render thread: Load arrays into the buffers (if updated) using the following code:

DeviceContext->UpdateSubresource(m_Buffers->VertexBuffer, 0, 0, m_vertices, 0, 0);
DeviceContext->UpdateSubresource(m_Buffers->IndexBuffer, 0, 0, m_indices, 0, 0);

I don't know how to increase the performance, I tried almost everything, but nothing seems to solve this problem...

 

There are 33*33 vertex arrays, each one for a 64x64 meter chunk, with 4 different quality levels (there are less vertices per chunk in chunks that are far away). At quality 0 there are 256*256 quads (4 vertices, 6 indices) per chunk, at quality level 3 only 32*32. 5*5 chunks have quality level 0, 9*9-5*5 have quality level 1, 13*13-9*9 have quality level 2 and the other chunks have quality level 3. So there are 33+13*2+9*2+5*2 chunks that are updated when I cross the border of a chunk.

 

Am I doing something basically wrong or should this work with a little bit of optimation?

 

Greetings,

Magogan

 

PS: Sorry for my bad english :(

Edited by Magogan

Share this post


Link to post
Share on other sites

I solved this issue! biggrin.png I added the following code to the multithreaded terrain chunk initialization:

if (ApplicationClass::InitializationState == STATE_IN_WORLD){
	while (WaitForSingleObject(ApplicationClass::DeviceContextMutex, 0) != WAIT_OBJECT_0){ // Mutex will only be hold when render thread is not holding it
			Sleep(5);
	}
}
else{
	WaitForSingleObject(ApplicationClass::DeviceContextMutex, INFINITE);
}
FillBuffers(ApplicationClass::m_Direct3D->GetDeviceContext());
ReleaseMutex(ApplicationClass::DeviceContextMutex);

(FillBuffers fills free vertex and index buffers with the previously generated vertices/indices using UpdateSubresource.)

 

Edit: Forget what I said, this doesn't work because loading is too slow now...

Edited by Magogan

Share this post


Link to post
Share on other sites

I think in situations like this you should profile. And the profile some more. Then send us the numbers so we can see if the look weird.

 

I can load, render and update LOD for a 64 square kilometer map in 100% single threaded mode, with a weird behavior that sometimes causes a simple touching of a buffer to take 12-14 ms and I don't get any framerate drops.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this