D3DPOOL_SYSTEMMEM + D3DLOCK_DISCARD

Started by
6 comments, last by Jiia 18 years, 11 months ago
I'm just wondering if this isn't a waste? Is there really any reason to use the discard flag when locking system memory resources? Would this not actually hurt performance rather than gain some back? I plan to rewrite the entire buffer, but is there a reason to reallocate the memory?
Quote: For vertex and index buffers, the application discards the entire buffer. A pointer to a new memory area is returned so that the direct memory access (DMA) and rendering from the previous area do not stall.
edit: I might as well add another question in here. What is the main difference between using D3DLOCK_NOOVERWRITE and D3DLOCK_READONLY? Are they not specifying the same thing? Thanks for any information.
Advertisement
The benefit you get on hardware is that you don't stall the rendering, you get a pointer to new memory. Unless your device can render from system memory and you're actually doing so (a bad idea), it'd be a waste.

Did the documentation make you think otherwise somewhere?

Quote:Original post by Jiia
edit: I might as well add another question in here. What is the main difference between using D3DLOCK_NOOVERWRITE and D3DLOCK_READONLY? Are they not specifying the same thing?

NOOVERWRITE says you won't be overwriting any data that the card is using for rendering, but you'll be writing data in the end, for example. READONLY says you won't be writing anything.


Quote:Original post by Coder
Unless your device can render from system memory and you're actually doing so (a bad idea), it'd be a waste.

Did the documentation make you think otherwise somewhere?

I'm rendering this from system memory, so yes, if that's what you mean. As far as I know, the documentation doesn't mention much about different scenarios with these sort of things.

Quote:NOOVERWRITE says you won't be overwriting any data that the card is using for rendering, but you'll be writing data in the end, for example. READONLY says you won't be writing anything.


If I understand correctly, Microsoft says I'm promising to not overwrite any data in the buffers:
Quote:D3DLOCK_NOOVERWRITE - The application promises not to overwrite any data in the vertex and index buffers.


Thanks
Quote:Original post by Jiia
If I understand correctly, Microsoft says I'm promising to not overwrite any data in the buffers:
Quote:D3DLOCK_NOOVERWRITE - The application promises not to overwrite any data in the vertex and index buffers.

Consider the following dynamic vertex buffer that we just locked with DISCARD:
"xxxxxxxxxxxxxxxxxxx"
It doesn't contain any data, just garbage, because it's just been DISCARDed. Now you fill part of it:
"dddddxxxxxxxxxxxxxx"
Unlock it, and render this batch. While this batch is being rendered, we want to fill the rest of the buffer, so we lock with NOOVERWRITE telling d3d we won't overwrite data, but will overwrite garbage:
"dddddDDDDDDxxxxxxxx"
And render the new batch. Lock with NOOVERWRITE, add another, ...etc. When you run out of space to add stuff, you DISCARD.

Thanks for detaling that, but I understood what you were getting at. I'm just not sure why the documentation says any data, rather than used or valid data.

In other words, how can you be sure this is the behavior?
Quote:Original post by Jiia
Thanks for detaling that, but I understood what you were getting at. I'm just not sure why the documentation says any data, rather than used or valid data.

In other words, how can you be sure this is the behavior?

Because it's documented as such in the DISCARD/NOOVERWRITE scheme. Check "Dynamic Vertex and Index Buffers, Using" in the SDK documentation:
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.

Quote:Original post by Coder
Check "Dynamic Vertex and Index Buffers, Using" in the SDK documentation:

Thanks much for pointing that out. Very helpful [smile]

This topic is closed to new replies.

Advertisement