DirectX9 Performance questions
I created a Direct3D (DX9) application that creates realtime "visualizations". Each frame is different than the frame before it so there is no opportunity to cache vertices for performance. I am currently not using Vertex Buffers, just my own array. Since the vertices are different for each frame does this matter? Are they any tips for increasing performance for something like this? Right now, performance is not a problem but I am not experience with DirectX so I assume I can probably improve things through some discussion with more experienced users such as yourselves.
I think a better description of what you're actually visualizing might help. Dynamic buffers are going to be slower, and there is an upper limit to the number of dynamic values you can pass between your system program and your shader programs. But I'm not sure what that limit is, and also what your application requires.
So are you using UserPrimitives Instead of a dynamic vertex buffer ? My suggestion ( but I'm not an expert, just a serious enthusiast ) is to use a dynamic vertex buffer which was introduced into XNA 4 i think. I've used dynamic vertex buffers to manipulate textures, blendmaps and geometry.
So are you using UserPrimitives Instead of a dynamic vertex buffer ? My suggestion ( but I'm not an expert, just a serious enthusiast ) is to use a dynamic vertex buffer which was introduced into XNA 4 i think. I've used dynamic vertex buffers to manipulate textures, blendmaps and geometry.
DrawPrimitiveUP and DrawIndexedPrimitiveUP will actually use dynamic buffers behind the scenes, but they're managed by the D3D runtime rather than by your own code. It's likely that you can do better yourself, but the -UP versions are actually just fine to use if you don't feel like investing the time and effort. You'll get much better and more immediate return on investment by batching up states in order to minimize the number of draw calls.
(For a serious performance-critical program you would definitely want to use vertex and index buffers of course.)
(For a serious performance-critical program you would definitely want to use vertex and index buffers of course.)
First, I am not using XNA and will probably stay away from it unless there are some measurable benefits over using straight DX9. Nothing against it but I want to keep my applications prerequisites and installer as lean as possible.
I do use DrawPrimitiveUP for all of my drawing. What I am currently doing is creating some arrays of some size that I should never exceed and updating the vertex values in the same array over and over as I process frames. The frames themselves are trivial. Just a bunch of colored triangles, lines, or points. Usually less than items per frame. So the number of needed vertices is relatively low compared to some 3D shooter game. But, when I ran it through PIX it said my FPS was only around 4!
I don't know what you mean by batching up states but if you could give me Direct3D functions I should look at that would be helpful. Typically, I only issue two or three DrawPrimitiveUP calls per frame. And the only reason I don't do it in one call is because I have a mixture of triangle lists, line lists, and point lists. I populate the arrays I mentioned above with triangles, lines, and points during a single loop and then render each list afterwards.
So, do you suggest that I replace with arrays of user primitives with some VertexBuffers and then go with that? But, what I wonder is will I really see an improvement since in that case I would be updating the VertexBuffer which is probably on the hardware one item at a time instead of passing a complete array that is created by myself. And, I admit that I really don't know what is happening under the covers during these situations so that is why I am asking.
I do use DrawPrimitiveUP for all of my drawing. What I am currently doing is creating some arrays of some size that I should never exceed and updating the vertex values in the same array over and over as I process frames. The frames themselves are trivial. Just a bunch of colored triangles, lines, or points. Usually less than items per frame. So the number of needed vertices is relatively low compared to some 3D shooter game. But, when I ran it through PIX it said my FPS was only around 4!
I don't know what you mean by batching up states but if you could give me Direct3D functions I should look at that would be helpful. Typically, I only issue two or three DrawPrimitiveUP calls per frame. And the only reason I don't do it in one call is because I have a mixture of triangle lists, line lists, and point lists. I populate the arrays I mentioned above with triangles, lines, and points during a single loop and then render each list afterwards.
So, do you suggest that I replace with arrays of user primitives with some VertexBuffers and then go with that? But, what I wonder is will I really see an improvement since in that case I would be updating the VertexBuffer which is probably on the hardware one item at a time instead of passing a complete array that is created by myself. And, I admit that I really don't know what is happening under the covers during these situations so that is why I am asking.
I am new to DirectX programming myself, but I would definitely use vertex buffers, you should see a huge performance gain. And if you were using an immediate mode before and only getting 4 FPS, there could be something wrong with the code or possibly a bad driver.
I am new to DirectX programming myself, but I would definitely use vertex buffers, you should see a huge performance gain. And if you were using an immediate mode before and only getting 4 FPS, there could be something wrong with the code or possibly a bad driver.
Essential reading: http://tomsdxfaq.blogspot.com/2006_04_01_archive.html#114482755569486635
Note however that the *UP calls can be a bit slower than the other two - in general you should try to avoid them and use Vertex Buffers. However, if you spent too much CPU time avoiding the *UP calls, it becomes counter-productive, so don't avoid them like the plague - just be aware that they are slightly more expensive - they are still appropriate for some operations.[/quote]
(It can be assumed that Tom Forsyth knows what he's talking about.)
Thanks for the link. I will definitely read it. In the meantime, I have switched to using a VertexBuffer and it does seem like performance has been made better but I really don't have a way to measure the change. At any rate, I am sure it is better than before.
Next improvement I will make will be to change my control to stop creating a new device per instance and use swapchains. The difficulty is in synchronizing them when there is a lost device context. Also, each may or may not have a different Perspective matrix so there will be a performance hit switching during each call. If anyone knows where I am coming from I would like to hear your input.
Thanks! This has been a very productive discussion for me.
Next improvement I will make will be to change my control to stop creating a new device per instance and use swapchains. The difficulty is in synchronizing them when there is a lost device context. Also, each may or may not have a different Perspective matrix so there will be a performance hit switching during each call. If anyone knows where I am coming from I would like to hear your input.
Thanks! This has been a very productive discussion for me.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement