Avoid locking DirectX texture?

Started by
11 comments, last by CarlML 15 years, 3 months ago
Quote:Original post by Evil Steve
Quote:Original post by CarlML
A question though... what happens if you lock the texture, alter pixel data and then display the texture without unlocking? Then unlock after displaying. In my test there doesn't seem to be any issue with doing that and the texture is displayed ok. Could it lead to issues?
Rendering will probably fail, or may display corrupt. If it works on your card, then that's just luck. If the texture is locked, it means that the CPU is accessing it. Because the GPU can be up to 2.5 frames behind the CPU, the GPU might not read the texture at the time you render, but might try to read it at some other point, after you've modified the texture again, or even in the middle of a memcpy() operation.

The Debug Runtimes will probably shout at you for doing that, and I suppose it's technically possible to crash the video card driver and bring down the whole system in an absolute worst case scenario.
Ok sounds good to me.:P

Nah, but what I'm doing is rendering the mesh along with the texture manually at a certain time so there shouldn't be anything else trying to access the texture at that time. It could be as you say I'm just having luck with my card though. I might be back to locking/unlocking twice then argh.. unless I want to do a super hack and check in a hundred places if the texture needs to be reset before doing something.
Advertisement
Quote:Original post by CarlML
Nah, but what I'm doing is rendering the mesh along with the texture manually at a certain time so there shouldn't be anything else trying to access the texture at that time. It could be as you say I'm just having luck with my card though. I might be back to locking/unlocking twice then argh.. unless I want to do a super hack and check in a hundred places if the texture needs to be reset before doing something.
The way I'd do this is have all of your code write to a memory buffer (Just an array allocated with new[]), and set a dirty flag when it writes. At render time, you can see if the dirty flag is set, and if so you can LockRect(), memcpy() and Unlock() the texture.

Updating a (even dynamic) texture more than once a frame is absolutely terrible for performance.
I'm already using several buffers for other things like erasing and undo so I'm reluctant to add any additional buffers because of memory consumption. Will see how it pans out, thanks.

This topic is closed to new replies.

Advertisement