Jump to content
  • Advertisement
Sign in to follow this  
Headkaze

Fastest method to update video to texture

This topic is 2068 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 need to upload video frames to a texture and I have seen two different methods to do this. What I would like to know is which is the fastest method.

Method #1
- hr = m_pDevice->CreateTexture(m_width, m_height, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pTexture, NULL);
- hr = m_pTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_DISCARD);
- Write to d3dlr.pBits;
- m_pTexture->UnlockRect(0);

Method #2
- hr = pDevice->CreateTexture(m_width, m_height, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &m_memTexture,NULL);
- hr = pDevice->CreateTexture(m_width, m_height, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_texture,NULL);
- hr = m_memTexture->LockRect(0, &d3dRect, NULL, D3DLOCK_DISCARD | D3DLOCK_DONOTWAIT);
- Write to d3dlr.pBits;
- hr = m_memTexture->UnlockRect(0);
- hr = pDevice->UpdateTexture(m_memTexture, m_texture); Edited by Headkaze

Share this post


Link to post
Share on other sites
Advertisement
The difference between the two is that the first one directly locks the texture in GPU texture memory and writes there, whereas the second one creates a temporary texture in system memory, writes there, uploads it to the GPU and performs the copy GPU-side. I'm pretty sure both approaches use DMA ultimately to push the new texture to the GPU (in the first method, the transfer would occur upon UnlockRect, and in the second one, at UpdateTexture), so I don't think it'd make a difference. The first one might be a bit faster, but drivers are pretty smart nowadays.

But you should try and benchmark it just to be sure. Edited by Bacterius

Share this post


Link to post
Share on other sites

But you should try and benchmark it just to be sure.


I agree. Has anyone else performed any benchmarks using these two methods?


Is this D3D9? I don't remember a LockRect() in D3D11.


Yes, as you can see I tagged my post with D3D9 Edited by Headkaze

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!