What's the point of D3DUSAGE_WRITEONLY

Started by
3 comments, last by SparkyFlooner 18 years, 8 months ago
I'm not sure what it means to 'read from the vertex buffer.' I create a vertex buffer with the attribute D3DUSAGE_WRITEONLY. If I lock the vertex buffer, the pointer is initialized with the data inside the buffer. That implies a read. I assumed garbage would have been returned instead. I'm obviously missing something.
Advertisement
When you specify the write only flag, you give d3d a permission to place the memory in a place where it may not be available to read from. This does not mean that it is required to make it write-only, though - but if you requested it, you can't assume that you can read from the buffer then.

The buses involved in a graphics system are usually much faster in uploading (writing) than in downloading (reading) from the card. This is why it is beneficial to hint d3d about the intended usage of the data, so it can allocate the memory from the most suitable place. Write only static buffers are likely to be allocated in video memory, so that the performance is as high as possible when rendering the data.

Niko Suni

So far, the only way I know to read from a buffer involves locking the buffer and receiving a pointer to its contents. The documentation hints that when using WRITEONLY, reads shouldn't just 'maybe return buffer data or not'..but that it should be an error. (evil documentation. it's awful)

Using WRITEONLY, the documentation hints that it allows the driver to store the data in the most effecient way. So when you lock the buffer, it has to transfer the data to the storage structures that you used...

Aside from locking the buffer, what other way exists to read the memory?
None. Lock is the only way to read a buffer on the CPU.

WRITEONLY allows (not forces) the card to use video memory, rather than AGP memory, which is faster for the card to access. Some cards may return valid data when you attempt to read the locked data, but you cannot rely on it. Other cards, or even the same card with a different driver may return invalid data. Reading from a WRITEONLY buffer, while it may work, is an error... just not one that throws up a big assert box.

If you use a MANAGED buffer, D3D keeps a system memory copy around anyway for device loss management, and you can likely read it. If you use a DEFAULT buffer, the odds are higher that a read attempt is going to fail.
Thanks, that clears it up pretty well. So basically if I specify WRITEONLY, I should assume the pointer points to garbage even if it doesn't look like garbage. Gotcha.


This topic is closed to new replies.

Advertisement