Optimize CaptureTexture

This commit is contained in:
Chuck Walbourn 2016-09-14 15:37:44 -07:00
parent 9290fcdf04
commit 1ee61fdcab

View File

@ -742,12 +742,19 @@ HRESULT DirectX::CaptureTexture(
D3D11_TEXTURE1D_DESC desc; D3D11_TEXTURE1D_DESC desc;
pTexture->GetDesc(&desc); pTexture->GetDesc(&desc);
ComPtr<ID3D11Texture1D> pStaging;
if ((desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
{
// Handle case where the source is already a staging texture we can use directly
pStaging = pTexture;
}
else
{
desc.BindFlags = 0; desc.BindFlags = 0;
desc.MiscFlags = 0; desc.MiscFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
ComPtr<ID3D11Texture1D> pStaging;
hr = pDevice->CreateTexture1D(&desc, 0, pStaging.GetAddressOf()); hr = pDevice->CreateTexture1D(&desc, 0, pStaging.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -755,6 +762,7 @@ HRESULT DirectX::CaptureTexture(
assert(pStaging); assert(pStaging);
pContext->CopyResource(pStaging.Get(), pSource); pContext->CopyResource(pStaging.Get(), pSource);
}
TexMetadata mdata; TexMetadata mdata;
mdata.width = desc.Width; mdata.width = desc.Width;
@ -840,6 +848,11 @@ HRESULT DirectX::CaptureTexture(
pContext->CopyResource(pStaging.Get(), pTemp.Get()); pContext->CopyResource(pStaging.Get(), pTemp.Get());
} }
else if ((desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
{
// Handle case where the source is already a staging texture we can use directly
pStaging = pTexture;
}
else else
{ {
desc.BindFlags = 0; desc.BindFlags = 0;
@ -887,12 +900,19 @@ HRESULT DirectX::CaptureTexture(
D3D11_TEXTURE3D_DESC desc; D3D11_TEXTURE3D_DESC desc;
pTexture->GetDesc(&desc); pTexture->GetDesc(&desc);
ComPtr<ID3D11Texture3D> pStaging;
if ((desc.Usage == D3D11_USAGE_STAGING) && (desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
{
// Handle case where the source is already a staging texture we can use directly
pStaging = pTexture;
}
else
{
desc.BindFlags = 0; desc.BindFlags = 0;
desc.MiscFlags = 0; desc.MiscFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
ComPtr<ID3D11Texture3D> pStaging;
hr = pDevice->CreateTexture3D(&desc, 0, pStaging.GetAddressOf()); hr = pDevice->CreateTexture3D(&desc, 0, pStaging.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -900,6 +920,7 @@ HRESULT DirectX::CaptureTexture(
assert(pStaging); assert(pStaging);
pContext->CopyResource(pStaging.Get(), pSource); pContext->CopyResource(pStaging.Get(), pSource);
}
TexMetadata mdata; TexMetadata mdata;
mdata.width = desc.Width; mdata.width = desc.Width;