这里有点资料,顺便说一下我的理解 CPU 和GPU是可以并行工作的,如果GPU正在使用一块内存上的数据绘制,而CPU要修改这块数据,就会出现CPU等待GPU或GPU等待CPU的情况,造成资源浪费。 如果GPU在使用一块内存的时候,用D3DLOCK_DISCARD标志锁定,表示我们对原来的数据不敢兴趣了,丢弃是相对于我们来说的,GPU会分配一块新内存,用来保存我们更新的数据,这时GPU可以使用原来的内存继续绘制。 用D3DLOCK_NOOVERWRITE锁定表示,我们需要修改数据,并且仍然需要原来的数据,这时锁定GPU占用的内存会失败,并立即返回,如果不用该标志,CPU会等待GPU用完了才返回,如果锁定的内存没有被GPU占用,则会成功锁定。
To receive a performance improvement when using dynamic vertex buffers, the application must call IDirect3DVertexBuffer9::Lock or IDirect3DIndexBuffer9::Lock with the appropriate flags. D3DLOCK_DISCARD indicates that the application does not need to keep the old vertex or index data in the buffer. If the graphics processor is still using the buffer when lock is called with D3DLOCK_DISCARD, a pointer to a new region of memory is returned instead of the old buffer data. This allows the graphics processor to continue using the old data while the application places data in the new buffer. No additional memory management is required in the application; the old buffer is reused or destroyed automatically when the graphics processor is finished with it. Note that locking a buffer with D3DLOCK_DISCARD always discards the entire buffer, specifying a nonzero offset or limited size field does not preserve information in unlocked areas of the buffer.
There are cases where the amount of data the application needs to store per lock is small, such as adding four vertices to render a sprite. D3DLOCK_NOOVERWRITE indicates that the application will not overwrite data already in use in the dynamic buffer. The lock call will return a pointer to the old data, allowing the application to add new data in unused regions of the vertex or index buffer. The application should not modify vertices or indices used in a draw operation as they might still be in use by the graphics processor. The application should then use D3DLOCK_DISCARD after the dynamic buffer is full to receive a new region of memory, discarding the old vertex or index data after the graphics processor is finished.