Sign in to follow this  

Dynamic texture locking

This topic is 3334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a dynamic texture I created in the default pool using the D3DUSAGE_DYNAMIC flag. I need to lock it every frame (with the D3DLOCK_DISCARD flag) and dump in new data (for a movie). Everything works, but it causes the framerate to drop just barely below 60FPS. I've tracked it down to the locking and unlocking of the texture. I'm guessing that the driver is blocking until after the previous frame rendered before it lets me lock the texture for use, which is causing the frame rate drop. So I'm guessing there's just a best practice I'm not doing, but I can't find much info online about dynamic textures. Are there some flags to set that I'm not? Or is a double buffer method used so you update one texture while the old one is rendering?

Share this post


Link to post
Share on other sites
Using the D3DLOCK_DISCARD flag should save the driver from having to stall for the texture, but there's a limit on how many updates you can do, so if you're getting too far ahead, that might cause a stall.

However, my guess is that it's the other way around, and the card is waiting for the texture to be updated. In that case the idea of keeping several textures, as you suggested, is a good one. I'd say that three would be a good number, but play with that (maybe two is enough).

Keep them filled with data so that you can supply one to the card when needed, with any wait. Really all you need is to fill the textures before the first frame, and then fill one per frame.

Hopefully that'd make things a little smoother.

Share this post


Link to post
Share on other sites
Okay, I'm going to try implementing a double buffer on the dynamic texture, and see what happens :)

Are there any tricks for this in DirectX beyond just creating two textures and using them on alternate frames from each other?

Share this post


Link to post
Share on other sites
Double buffering made no difference. In fact, locking and unlocking a texture that was never used still caused slowdown. I've tried it with and without the D3DLOCK_DISCARD flag, which produced no visible effect.

Scaling down the texture to something less full screen-y (512x512xRGBA) seems to fix it (still takes several ms to unlock, but it fits within one frame), which would seem to indicate that the bottleneck is transferring bits to the card every frame. But I can play full screen movies outside my game at 60FPS, so I'm guessing it should be possible to transfer that much data fast enough.

Anyone have any other ideas? One thought I had was to copy the movie frames to a texture in the D3DPOOL_SYSTEMMEM or D3DPOOL_SCRATCH, and then copy it to the card with an UpdateTexture call. I have no idea if this will fix my issue, though.

Share this post


Link to post
Share on other sites
First of all, according to the SDK docs, D3DLOCK_DISCARD works better with bigger textures.
You may also check that your texture has only one level; If your texture has mip levels this will decrease FPS due to the additional overhead when locking the pixels.
Can you post some of your rendering code?

Share this post


Link to post
Share on other sites

This topic is 3334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this