Fastest method to update video to texture

Started by
2 comments, last by Headkaze 11 years, 5 months ago
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);
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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

I wonder as I wander...

http://www.davesgameoflife.com


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

This topic is closed to new replies.

Advertisement