Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing directly into vertex buffer

The DirectX 9 application/game I inherited uses dynamic vertex buffers. Each frame, it:

  1. locks the vertex buffer
  2. cycles through meshes and writes vertex data to a temporary buffer (dynamically allocated at program start) until it's full
  3. copies the contents of the temporary buffer to the vertex buffer
  4. repeats steps 2 and 3 until all data is copied
  5. unlocks the vertex buffer

My question is, is the part with the temporary buffer necessary? Is there a reason why I shouldn't write vertex data directly into the vertex buffer?
I haven't found any evidence of this practice in the official documentation, and I don't trust the previous programmer enough.

like image 557
Smohn Jith Avatar asked Oct 30 '25 10:10

Smohn Jith


1 Answers

Discaimer: I don't know how DirectX vertex buffers work, I might be wrong here.

It would probably be slower: a vertex buffer is allocated to optimize access from the GPU, i.e. preferrably somewhere in the GPU's own memory. That means directly accessing it from the CPU is much slower than accessing ordinary RAM. Copying a whole array on the other hand can be done relatively fast, so it is better to prepare such an array in main memory and copying it to the vertex buffer in one go.

like image 72
leftaroundabout Avatar answered Nov 02 '25 01:11

leftaroundabout