How to correctly update vertex buffers in DirectX 10

For a small background: I am working on a C ++ project in which I am trying to draw three-dimensional representations of objects based on real-time profile data. Profiling data is collected from external profiling equipment. The system moves around the object and at a speed of 300 times per second provides my software with a profile cut. Each fragment consists of a list of 8000 XY points. The movement of the profiler is recorded by the encoder. Encoder information provides 3rd scan size.

Another important note - the profiler can move forward and backward through the object. In this case, I want to replace the previously read / drawn fragments with new ones (based on the position of the encoder). At the moment, I am achieving this with a circular slice buffer, which I store on the encoder account. It also means that I want to throw away the fragments when the buffer is full and starts to rewrite the old fragments. To show the correct amount of the item on the screen, I need to draw 1000 pieces of profile data at a time. For now, I present the object as a cloud of points. In the future, we can try to join adjacent slices and display them in a list of triangles.

I'm new to DirectX, but using books and online examples, I got to the point where I draw an object in 3D, but I am convinced that I am not using Vertex Buffers efficiently / correctly. Most of the examples I found work with very static models. Therefore, they strive to create a single vertex buffer with their list of points, and then simply manipulate matrix transformations. I, on the other hand, very quickly update the scene when I receive profile data from our equipment.

I am currently creating a new vertex buffer for each fragment that I am reading. When I draw a scene, I look at a list of 1000 buffers and call Draw () for each of them. I noticed that if I halved the number of vertex buffers at a time, my FPS would increase significantly, while decreasing the number of vertex points per buffer decreased slightly, so I take this as an indication that several vertex buffers are not the right way to get closer to that.

So to the courage of my question ... I wonder if I can put all these vertices in one vertex buffer when the vertices change so often. Can I update points in an existing vertex buffer? Or should I just recreate one new new buffer every time I update the scene? The last thing to keep in mind is that the number of dots per piece of hardware will vary - so when it comes to overwriting previous fragments, a new slice can have more or fewer points than the replaced slice.

Thank you for your time. Any advice would be highly appreciated!

+4
source share
1 answer

You can always update points in the vertex buffer while you create a dynamic buffer (specify D3D10_USAGE_DYNAMIC and use ID3D10Device::CopySubresourceRegion to efficiently update only parts of the buffer). This should be more efficient than re-creating buffers too often.

However, different sizes for each fragment are bad. You could either implement some kind of memory manager to support the overall fragmentation of your vertex buffers, or this is the point where using multiple vb is inevitable. One way is to combine all the cuts to a reasonable limit and have one vb for each size.

+3
source

Source: https://habr.com/ru/post/1346255/


All Articles