# [MDX] Poor performance when rendering a mesh & strange fps limit

This topic is 4529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm working on a little research project to create a shader-based vertex morpher for which I need to render a mesh's subsets manually. To do this, I'm using the code below, where attributes is the mesh's attribute table.
[source lang=C#]
// simple mesh render
device.Transform.World = Matrix.Identity;
device.Transform.View = viewMatrix;
device.Transform.Projection = projectionMatrix;

device.SetStreamSource(0, baseMesh.VertexBuffer, 0, baseMesh.NumberBytesPerVertex);
device.Indices = baseMesh.IndexBuffer;
device.VertexFormat = baseMesh.VertexFormat;

for(int i = 0; i < attributes.Length; i++)
{
device.Material = materials;
device.SetTexture(0, textures);

device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, baseMesh.NumberVertices, attributes.FaceStart * 3, attributes.FaceCount );
}


I know passing in baseMesh.NumberVertices as the number of vertices specifies too many vertices and may cause a performance hit, but I tried several variations of this code I found on the internet and every one of them seems to 'cut off' the mesh, indicating I specified too little vertices to draw. To be sure, I also tried rendering the mesh using the normal Mesh.DrawSubset call and the performance was still pretty bad compared to MeshViewer. In short, the performances for the exact same mesh are: - MeshViewer: 1400 fps - MDX, Mesh.DrawSubset: 380 fps - MDX, manual attrib render: 180 fps The only thing I can think of would be that I'm somehow loading the mesh in the wrong way using Mesh.FromFile(file, flags, device, materials). I do pass in 0 for the MeshFlags value, but all other values I've tried either don't make a difference or throw an 'InvalidCallException'. I'm using the EmptyProject sample from the SDK (Dec 2005) as the starting point for my projects, so that shouldn't be causing these problems. I don't expect to match the performance of the good ol' MeshViewer, but I think a 500+ fps isn't too much to ask for, even with the manual attributeset rendering. Would anyone have any idea what might be causing this shabby performance? Anyway, I do have my morpher up and running, but it also seems to hit some performance limit. It does an average of 60 fps, which is quite accepatable. But the strange thing is, it does 60 fps no matter on what resolution I run it. 640x480 or 1280x1024, it makes no difference... VSync is definately off, so I'm wondering what could be limiting its performance. I am using 4 streams to supply the vertex data to the shader, so might that be causing some bandwidth limitation? I apologize if this topic isn't too coherent, but it's late and I spent too much time already on looking at PIX results that didn't tell me anything useful. So If I need to clear something up, please let me know. Thanks in advance for any answers/pointers/hints that might solve this problem!

##### Share on other sites
Just a guess off the bat, but if you are not making your mesh with any mesh flags than it is probably not making the best mesh for your situation -- I recomend using MeshFlags.Managed. Use the Dynamic flag if you are writing regularly to your mesh. There is a possibility that your mesh is going into system memory (though it is probably going into default). If you cannot use the flags you want durring loading you should be able to use Mesh.Clone() to get a mesh where you want it.

Many of the mesh flags do not apply at mesh creation but during optimization -- yet another thing that could be causing your slowdown. Optimize your mesh with OptimizeInPlace() or Optimize() specify some of the applicable flags that start with Optimize.

The mesh viewer probably does not call SetStreamSource every frame -- I have heard that this can be a slow call.

If you are doing alot of work on the cpu use device.GetSwapChain(0).Present() with the Present.DoNotWait flag instead of device.Present() to recapture cpu cycles.

The 60 fps limit is probably because of vsync turn it off in your present params by setting PresentationInterval to PresentInterval.Immediate.

hope this helps.

##### Share on other sites
Quote:
 Original post by turnpastJust a guess off the bat, but if you are not making your mesh with any mesh flags than it is probably not making the best mesh for your situation -- I recomend using MeshFlags.Managed.

MeshFlags.Managed upped the framerate to 330 for my morpher and 850 for the simple attrib set renderer. I guess I overlooked that one flag, confirming I really need to go get some sleep :)

Got my project back on track, thanks!

• 10
• 17
• 9
• 14
• 41