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);
Fastest method to update video to texture
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.
But you should try and benchmark it just to be sure.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement