Sign in to follow this  
Headkaze

Fastest method to update video to texture

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
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
[quote name='Bacterius' timestamp='1353046220' post='5001456']
But you should try and benchmark it just to be sure.
[/quote]

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

[quote name='KingofNoobs' timestamp='1353085679' post='5001579']
Is this D3D9? I don't remember a LockRect() in D3D11.
[/quote]

Yes, as you can see I tagged my post with [url="http://www.gamedev.net/tags/forums/D3D9/"]D3D9[/url] Edited by Headkaze

Share this post


Link to post
Share on other sites

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