Experimental D3D11 optimizations and cleanup.
git-svn-id: svn://svn.code.sf.net/p/qsdecoder/code/trunk/IntelQuickSyncDecoder@89 dfccccb7-dd81-40b7-a334-5a7ba89c2b1d
This commit is contained in:
parent
bbc8f581a4
commit
4148c2e4dc
@ -107,7 +107,8 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;DEBUG;_DEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
|
||||
@ -133,7 +134,8 @@
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;DEBUG;_DEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
@ -159,7 +161,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
@ -193,7 +196,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;QUICKSYNC_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<DisableSpecificWarnings>4996;4995</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>
|
||||
</DisableSpecificWarnings>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalIncludeDirectories>$(INTELMEDIASDK_WINSDK_PATH)\Include;$(INTELMEDIASDK_WINSDK_PATH)\Include\um;$(INTELMEDIASDK_WINSDK_PATH)\Include\shared;MSDK\include</AdditionalIncludeDirectories>
|
||||
<Optimization>Full</Optimization>
|
||||
|
@ -1357,29 +1357,39 @@ void CQuickSync::CopyFrame(mfxFrameSurface1* pSurface, QsFrameData& outFrameData
|
||||
size_t height = pSurface->Info.CropH; // Cropped image height
|
||||
size_t pitch = frameData.Pitch; // Image line + padding in bytes --> set by the driver
|
||||
|
||||
// Offset output buffer's address for fastest SSE4.1 copy.
|
||||
// Page offset (12 lsb of addresses) sould be 2K apart from source buffer
|
||||
size_t offset = ((size_t)frameData.Y & PAGE_MASK) ^ (1 << 11);
|
||||
|
||||
// Mark Y, U & V pointers on output buffer
|
||||
outFrameData.y = pOutBuffer->GetBuffer() + offset;
|
||||
outFrameData.u = outFrameData.y + (pitch * height);
|
||||
outFrameData.v = 0;
|
||||
outFrameData.a = 0;
|
||||
if (m_pDecoder->IsD3D11Alloc())
|
||||
{
|
||||
outFrameData.y = frameData.Y + (pSurface->Info.CropY * pitch), height * pitch;
|
||||
outFrameData.u = frameData.CbCr + (pSurface->Info.CropY * pitch), pitch * height / 2;
|
||||
outFrameData.v = 0;
|
||||
outFrameData.a = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Offset output buffer's address for fastest SSE4.1 copy.
|
||||
// Page offset (12 lsb of addresses) sould be 2K apart from source buffer
|
||||
size_t offset = ((size_t)frameData.Y & PAGE_MASK) ^ (1 << 11);
|
||||
|
||||
// App can modify this buffer
|
||||
outFrameData.bReadOnly = false;
|
||||
// Mark Y, U & V pointers on output buffer
|
||||
outFrameData.y = pOutBuffer->GetBuffer() + offset;
|
||||
outFrameData.u = outFrameData.y + (pitch * height);
|
||||
outFrameData.v = 0;
|
||||
outFrameData.a = 0;
|
||||
|
||||
// App can modify this buffer
|
||||
outFrameData.bReadOnly = false;
|
||||
#if 1 // Use this to disable actual copying for benchmarking
|
||||
Tmemcpy memcpyFunc = (m_pDecoder->IsD3DAlloc()) ?
|
||||
( (m_Config.bEnableMtCopy) ? mt_gpu_memcpy : gpu_memcpy_sse41 ) :
|
||||
( (m_Config.bEnableMtCopy) ? mt_memcpy : memcpy );
|
||||
Tmemcpy memcpyFunc = (m_pDecoder->IsD3DAlloc()) ?
|
||||
( (m_Config.bEnableMtCopy) ? mt_gpu_memcpy : gpu_memcpy_sse41 ) :
|
||||
( (m_Config.bEnableMtCopy) ? mt_memcpy : memcpy );
|
||||
|
||||
// Copy Y
|
||||
!m_bNeedToFlush && memcpyFunc(outFrameData.y, frameData.Y + (pSurface->Info.CropY * pitch), height * pitch);
|
||||
// Copy Y
|
||||
!m_bNeedToFlush && memcpyFunc(outFrameData.y, frameData.Y + (pSurface->Info.CropY * pitch), height * pitch);
|
||||
|
||||
// Copy UV
|
||||
!m_bNeedToFlush && memcpyFunc(outFrameData.u, frameData.CbCr + (pSurface->Info.CropY * pitch), pitch * height / 2);
|
||||
// Copy UV
|
||||
!m_bNeedToFlush && memcpyFunc(outFrameData.u, frameData.CbCr + (pSurface->Info.CropY * pitch), pitch * height / 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug only - mark top left corner: when working with D3D
|
||||
|
@ -245,53 +245,15 @@ mfxStatus CQuickSyncDecoder::InternalReset(mfxVideoParam* pVideoParams, mfxU32 n
|
||||
// Reset decoder
|
||||
if (bInited)
|
||||
{
|
||||
// Kill the session for VC1 only (workaround)
|
||||
// Doing this for MPEG2 will cause issues like aspect ratio change will not be detected.
|
||||
if (pVideoParams->mfx.CodecId == MFX_CODEC_VC1 && pVideoParams->mfx.CodecProfile == MFX_PROFILE_VC1_ADVANCED)
|
||||
sts = m_pmfxDEC->Reset(pVideoParams);
|
||||
// Need to reset the frame allocator
|
||||
if (MSDK_FAILED(sts))
|
||||
{
|
||||
MFXVideoSession* saveSession = m_mfxVideoSession; // Kill the old session later so MSDK DLL will not unload
|
||||
m_mfxVideoSession = NULL;
|
||||
CloseSession();
|
||||
sts = InitSession(m_mfxImpl);
|
||||
delete saveSession;
|
||||
MSDK_CHECK_RESULT_P_RET(sts, MFX_ERR_NONE);
|
||||
if (m_bUseD3DAlloc)
|
||||
{
|
||||
// get D3D9 handle from HW device and notify the session
|
||||
if (!m_bUseD3D11Alloc)
|
||||
{
|
||||
mfxHDL h = m_HwDevice->GetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER);
|
||||
sts = m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, h);
|
||||
if (MSDK_FAILED(sts))
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: Session SetHandle failed!\n");
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
|
||||
// Note - setting the session allocator can be done only once (per session)!
|
||||
sts = m_mfxVideoSession->SetFrameAllocator(m_pFrameAllocator);
|
||||
if (MSDK_FAILED(sts))
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: Session SetFrameAllocator failed!\n");
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
|
||||
m_pmfxDEC->Close();
|
||||
FreeFrameAllocator();
|
||||
bInited = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = m_pmfxDEC->Reset(pVideoParams);
|
||||
// Need to reset the frame allocator
|
||||
if (MSDK_FAILED(sts))
|
||||
{
|
||||
m_pmfxDEC->Close();
|
||||
FreeFrameAllocator();
|
||||
bInited = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (m_pFrameSurfaces != NULL)
|
||||
{
|
||||
// Another VC1 decoder + VPP bug workaround
|
||||
@ -402,124 +364,6 @@ mfxStatus CQuickSyncDecoder::Decode(mfxBitstream* pBS, mfxFrameSurface1*& pOutSu
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus CQuickSyncDecoder::InitD3DFromRenderer()
|
||||
{
|
||||
/*
|
||||
MSDK_VTRACE("QsDecoder: InitD3DFromRenderer\n");
|
||||
|
||||
// Get DirectX Object
|
||||
HANDLE hDevice;
|
||||
IDirect3DDevice9* pDevice = NULL;
|
||||
CComPtr<IDirect3D9> pD3D;
|
||||
D3DDEVICE_CREATION_PARAMETERS devParames;
|
||||
D3DPRESENT_PARAMETERS d3dParams = {1, 1, D3DFMT_X8R8G8B8, 1, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, NULL, TRUE, FALSE, D3DFMT_UNKNOWN, 0, 0, D3DPRESENT_INTERVAL_IMMEDIATE};
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
HRESULT hr = m_pRendererD3dDeviceManager->OpenDeviceHandle(&hDevice);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: failed to open device handle!\n");
|
||||
goto done;
|
||||
}
|
||||
hr = m_pRendererD3dDeviceManager->LockDevice(hDevice, &pDevice, TRUE);
|
||||
if (FAILED(hr) || NULL == pDevice)
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: failed to lock device!\n");
|
||||
switch (hr)
|
||||
{
|
||||
case DXVA2_E_NEW_VIDEO_DEVICE:
|
||||
MSDK_TRACE("QsDecoder: The device handle is invalid.!\n");
|
||||
break;
|
||||
case DXVA2_E_NOT_INITIALIZED:
|
||||
MSDK_TRACE("QsDecoder: The Direct3D device manager was not initialized.!\n");
|
||||
break;
|
||||
case E_HANDLE:
|
||||
MSDK_TRACE("QsDecoder: The specified handle is not a Direct3D device handle.!\n");
|
||||
break;
|
||||
default:
|
||||
MSDK_TRACE("QsDecoder: Unknown error %x\n", hr);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
hr = pDevice->GetDirect3D(&pD3D);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: failed to get D3D9 object!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
hr = pDevice->GetCreationParameters(&devParames);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
MSDK_TRACE("QsDecoder: failed to get device creation params!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Find Intel adapter number - not always the default adapter
|
||||
int adapterId = GetIntelAdapterIdD3D9(pD3D);
|
||||
if (adapterId < 0)
|
||||
{
|
||||
hr = E_FAIL;
|
||||
MSDK_TRACE("QsDecoder: didn't find an Intel GPU.\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Create d3d device
|
||||
m_pD3dDevice = 0;
|
||||
d3dParams.hDeviceWindow = devParames.hFocusWindow;
|
||||
hr = pD3D->CreateDevice(
|
||||
adapterId,
|
||||
D3DDEVTYPE_HAL,
|
||||
devParames.hFocusWindow,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
|
||||
&d3dParams,
|
||||
&m_pD3dDevice);
|
||||
|
||||
if (FAILED(hr) || !m_pD3dDevice)
|
||||
{
|
||||
hr = E_FAIL;
|
||||
MSDK_TRACE("QsDecoder: InitD3d CreateDevice failed!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Create device manager
|
||||
hr = DXVA2CreateDirect3DDeviceManager9(&m_ResetToken, &m_pD3dDeviceManager);
|
||||
if (FAILED(hr) || !m_pD3dDeviceManager)
|
||||
{
|
||||
hr = E_FAIL;
|
||||
MSDK_TRACE("QsDecoder: InitD3d DXVA2CreateDirect3DDeviceManager9 failed!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Reset the d3d device
|
||||
hr = m_pD3dDeviceManager->ResetDevice(m_pD3dDevice, m_ResetToken);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
hr = E_FAIL;
|
||||
MSDK_TRACE("QsDecoder: InitD3d ResetDevice failed!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
done:
|
||||
if (FAILED(hr))
|
||||
{
|
||||
sts = MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
MSDK_SAFE_RELEASE(pDevice);
|
||||
if (hDevice != NULL)
|
||||
{
|
||||
m_pRendererD3dDeviceManager->UnlockDevice(hDevice, FALSE);
|
||||
m_pRendererD3dDeviceManager->CloseDeviceHandle(hDevice);
|
||||
}
|
||||
|
||||
return sts;
|
||||
*/
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void CQuickSyncDecoder::CloseD3D()
|
||||
{
|
||||
if (m_bUseD3DAlloc)
|
||||
|
@ -160,7 +160,6 @@ protected:
|
||||
mfxStatus InternalReset(mfxVideoParam* pVideoParams, mfxU32 nPitch, bool bInited);
|
||||
mfxStatus InitSession(mfxIMPL impl);
|
||||
void CloseSession();
|
||||
mfxStatus InitD3DFromRenderer();
|
||||
void CloseD3D();
|
||||
|
||||
// data members
|
||||
|
@ -315,6 +315,7 @@ mfxStatus CQuickSyncVPP::Process(mfxFrameSurface1* pInSurface, mfxFrameSurface1*
|
||||
}
|
||||
}
|
||||
|
||||
// Call VPP
|
||||
do
|
||||
{
|
||||
sts = m_pVPP->RunFrameVPPAsync(pInSurface, pOutSurface, NULL, &syncp);
|
||||
|
@ -79,7 +79,6 @@ public:
|
||||
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response);
|
||||
|
||||
protected:
|
||||
typedef std::list<mfxFrameAllocResponse>::iterator Iter;
|
||||
static const mfxU32 MEMTYPE_FROM_MASK = MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT;
|
||||
|
||||
struct UniqueResponse
|
||||
|
@ -27,10 +27,10 @@
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "QuickSync_defs.h"
|
||||
|
||||
#if MFX_D3D11_SUPPORT
|
||||
|
||||
#include "QuickSync_defs.h"
|
||||
#include "QuickSyncUtils.h"
|
||||
#include "d3d11_allocator.h"
|
||||
|
||||
#define D3DFMT_NV12 (DXGI_FORMAT)MAKEFOURCC('N','V','1','2')
|
||||
@ -120,7 +120,6 @@ mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
D3D11_MAPPED_SUBRESOURCE lockedRect = {0};
|
||||
|
||||
|
||||
//check that texture exists
|
||||
TextureSubResource sr = GetResourceFromMid(mid);
|
||||
if (!sr.GetTexture())
|
||||
@ -129,132 +128,58 @@ mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
D3D11_MAP mapType = D3D11_MAP_READ;
|
||||
UINT mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
|
||||
{
|
||||
if (NULL == sr.GetStaging())
|
||||
ASSERT(NULL != sr.GetStaging());
|
||||
sr.GetTexture()->GetDesc(&desc);
|
||||
|
||||
if (DXGI_FORMAT_NV12 != desc.Format)
|
||||
{
|
||||
hRes = m_pDeviceContext->Map(sr.GetTexture(), sr.GetSubResource(), D3D11_MAP_READ, D3D11_MAP_FLAG_DO_NOT_WAIT, &lockedRect);
|
||||
desc.Format = DXGI_FORMAT_P8;
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
}
|
||||
else
|
||||
|
||||
m_pDeviceContext->CopySubresourceRegion(sr.GetStaging(), 0, 0, 0, 0, sr.GetTexture(), sr.GetSubResource(), NULL);
|
||||
|
||||
do
|
||||
{
|
||||
sr.GetTexture()->GetDesc(&desc);
|
||||
|
||||
if (DXGI_FORMAT_NV12 != desc.Format &&
|
||||
DXGI_FORMAT_420_OPAQUE != desc.Format &&
|
||||
DXGI_FORMAT_YUY2 != desc.Format &&
|
||||
DXGI_FORMAT_P8 != desc.Format &&
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM != desc.Format)
|
||||
hRes = m_pDeviceContext->Map(sr.GetStaging(), 0, mapType, mapFlags, &lockedRect);
|
||||
if (S_OK != hRes && DXGI_ERROR_WAS_STILL_DRAWING != hRes)
|
||||
{
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
MSDK_TRACE("ERROR: m_pDeviceContext->Map = 0x%lX\n", hRes);
|
||||
}
|
||||
|
||||
//coping data only in case user wants to read from stored surface
|
||||
{
|
||||
|
||||
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isRead())
|
||||
{
|
||||
m_pDeviceContext->CopySubresourceRegion(sr.GetStaging(), 0, 0, 0, 0, sr.GetTexture(), sr.GetSubResource(), NULL);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
hRes = m_pDeviceContext->Map(sr.GetStaging(), 0, mapType, mapFlags, &lockedRect);
|
||||
if (S_OK != hRes && DXGI_ERROR_WAS_STILL_DRAWING != hRes)
|
||||
{
|
||||
MSDK_TRACE("ERROR: m_pDeviceContext->Map = 0x%lX\n", hRes);
|
||||
}
|
||||
}
|
||||
while (DXGI_ERROR_WAS_STILL_DRAWING == hRes);
|
||||
}
|
||||
|
||||
}
|
||||
while (DXGI_ERROR_WAS_STILL_DRAWING == hRes);
|
||||
}
|
||||
|
||||
if (FAILED(hRes))
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
switch (desc.Format)
|
||||
{
|
||||
case DXGI_FORMAT_NV12:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = (mfxU8 *)lockedRect.pData + desc.Height * lockedRect.RowPitch;
|
||||
ptr->V = ptr->U + 1;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_420_OPAQUE: // can be unsupported by standard ms guid
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->V = ptr->Y + desc.Height * lockedRect.RowPitch;
|
||||
ptr->U = ptr->V + (desc.Height * lockedRect.RowPitch) / 4;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_YUY2:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = ptr->Y + 1;
|
||||
ptr->V = ptr->Y + 3;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_P8 :
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = 0;
|
||||
ptr->V = 0;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM :
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->B = (mfxU8 *)lockedRect.pData;
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->A = ptr->B + 3;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
}
|
||||
MSDK_CHECK_NOT_EQUAL(desc.Format, DXGI_FORMAT_NV12, MFX_ERR_LOCK_MEMORY);
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = (mfxU8 *)lockedRect.pData + desc.Height * lockedRect.RowPitch;
|
||||
ptr->V = ptr->U + 1;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
mfxStatus D3D11FrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData* ptr)
|
||||
{
|
||||
//check that texture exists
|
||||
TextureSubResource sr = GetResourceFromMid(mid);
|
||||
if (!sr.GetTexture())
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
if (NULL == sr.GetStaging())
|
||||
{
|
||||
m_pDeviceContext->Unmap(sr.GetTexture(), sr.GetSubResource());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pDeviceContext->Unmap(sr.GetStaging(), 0);
|
||||
//only if user wrote something to texture
|
||||
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isWrite())
|
||||
{
|
||||
m_pDeviceContext->CopySubresourceRegion(sr.GetTexture(), sr.GetSubResource(), 0, 0, 0, sr.GetStaging(), 0, NULL);
|
||||
}
|
||||
}
|
||||
m_pDeviceContext->Unmap(sr.GetStaging(), 0);
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
ptr->Pitch=0;
|
||||
ptr->U=ptr->V=ptr->Y=0;
|
||||
ptr->A=ptr->R=ptr->G=ptr->B=0;
|
||||
ptr->U = ptr->V = ptr->Y = NULL;
|
||||
ptr->A = ptr->R = ptr->G = ptr->B = NULL;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
mfxStatus D3D11FrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
|
||||
{
|
||||
if (NULL == handle)
|
||||
@ -314,103 +239,79 @@ mfxStatus D3D11FrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
mfxStatus D3D11FrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
HRESULT hRes;
|
||||
|
||||
DXGI_FORMAT colorFormat = ConverColortFormat(request->Info.FourCC);
|
||||
|
||||
if (DXGI_FORMAT_UNKNOWN == colorFormat)
|
||||
{
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
// Only support NV12
|
||||
MSDK_CHECK_NOT_EQUAL(colorFormat, DXGI_FORMAT_NV12, MFX_ERR_UNSUPPORTED);
|
||||
|
||||
TextureResource newTexture;
|
||||
|
||||
if (request->Info.FourCC == MFX_FOURCC_P8)
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
|
||||
desc.Width = request->Info.Width;
|
||||
desc.Height = request->Info.Height;
|
||||
|
||||
desc.MipLevels = 1;
|
||||
//number of subresources is 1 in case of not single texture
|
||||
desc.ArraySize = m_initParams.bUseSingleTexture ? request->NumFrameSuggested : 1;
|
||||
desc.Format = ConverColortFormat(request->Info.FourCC);
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.MiscFlags = m_initParams.uncompressedResourceMiscFlags;
|
||||
|
||||
desc.BindFlags = D3D11_BIND_DECODER;
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPIN & request->Type) && (DXGI_FORMAT_YUY2 == desc.Format) ||
|
||||
(DXGI_FORMAT_B8G8R8A8_UNORM == desc.Format) )
|
||||
{
|
||||
D3D11_BUFFER_DESC desc = { 0 };
|
||||
|
||||
desc.ByteWidth = request->Info.Width * request->Info.Height;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.MiscFlags = 0;
|
||||
desc.StructureByteStride = 0;
|
||||
|
||||
ID3D11Buffer * buffer = 0;
|
||||
hRes = m_initParams.pDevice->CreateBuffer(&desc, 0, &buffer);
|
||||
if (FAILED(hRes))
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
newTexture.textures.push_back(reinterpret_cast<ID3D11Texture2D *>(buffer));
|
||||
}
|
||||
else
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPOUT & request->Type) ||
|
||||
(MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & request->Type))
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
desc.Width = request->Info.Width;
|
||||
desc.Height = request->Info.Height;
|
||||
|
||||
desc.MipLevels = 1;
|
||||
//number of subresources is 1 in case of not single texture
|
||||
desc.ArraySize = m_initParams.bUseSingleTexture ? request->NumFrameSuggested : 1;
|
||||
desc.Format = ConverColortFormat(request->Info.FourCC);
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.MiscFlags = m_initParams.uncompressedResourceMiscFlags;
|
||||
|
||||
desc.BindFlags = D3D11_BIND_DECODER;
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPIN & request->Type) && (DXGI_FORMAT_YUY2 == desc.Format) ||
|
||||
(DXGI_FORMAT_B8G8R8A8_UNORM == desc.Format) )
|
||||
{
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPOUT & request->Type) ||
|
||||
(MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & request->Type))
|
||||
{
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
if( DXGI_FORMAT_P8 == desc.Format )
|
||||
{
|
||||
desc.BindFlags = 0;
|
||||
}
|
||||
|
||||
ID3D11Texture2D* pTexture2D;
|
||||
|
||||
for(size_t i = 0; i < request->NumFrameSuggested / desc.ArraySize; i++)
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
MSDK_TRACE("CreateTexture2D(%d) failed, hr = 0x%lX\n", (int)i, hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.textures.push_back(pTexture2D);
|
||||
}
|
||||
|
||||
desc.ArraySize = 1;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
if( DXGI_FORMAT_P8 == desc.Format )
|
||||
{
|
||||
desc.BindFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < request->NumFrameSuggested; i++)
|
||||
ID3D11Texture2D* pTexture2D;
|
||||
|
||||
for(size_t i = 0; i < request->NumFrameSuggested / desc.ArraySize; i++)
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
MSDK_TRACE("Create staging texture(%d) failed hr = 0x%lX\n", (int)i, hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.stagingTexture.push_back(pTexture2D);
|
||||
MSDK_TRACE("CreateTexture2D(%d) failed, hr = 0x%lX\n", (int)i, hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.textures.push_back(pTexture2D);
|
||||
}
|
||||
|
||||
desc.ArraySize = 1;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.BindFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
for (size_t i = 0; i < request->NumFrameSuggested; ++i)
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
MSDK_TRACE("Create staging texture(%d) failed hr = 0x%lX\n", (int)i, hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.stagingTexture.push_back(pTexture2D);
|
||||
}
|
||||
|
||||
// mapping to self created handles array, starting from zero or from last assigned handle + 1
|
||||
@ -431,7 +332,7 @@ mfxStatus D3D11FrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrame
|
||||
response->NumFrameActual = request->NumFrameSuggested;
|
||||
|
||||
//iterator prior end()
|
||||
std::list <TextureResource>::iterator it_last = m_resourcesByRequest.end();
|
||||
auto it_last = m_resourcesByRequest.end();
|
||||
//fill map
|
||||
std::fill_n(std::back_inserter(m_memIdMap), request->NumFrameSuggested, --it_last);
|
||||
|
||||
|
@ -27,11 +27,10 @@
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#if MFX_D3D11_SUPPORT
|
||||
#include "QuickSync_defs.h"
|
||||
#include "d3d11_device.h"
|
||||
|
||||
#if MFX_D3D11_SUPPORT
|
||||
|
||||
CD3D11Device::CD3D11Device()
|
||||
{
|
||||
}
|
||||
@ -41,24 +40,9 @@ CD3D11Device::~CD3D11Device()
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd)
|
||||
{
|
||||
scd.Windowed = TRUE;
|
||||
scd.OutputWindow = (HWND)hWindow;
|
||||
scd.SampleDesc.Count = 1;
|
||||
scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
scd.BufferCount = 1;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::Init(int nAdapterNum)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
static D3D_FEATURE_LEVEL FeatureLevels[] = {
|
||||
static const D3D_FEATURE_LEVEL featureLevels[] = {
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
@ -66,6 +50,9 @@ mfxStatus CD3D11Device::Init(int nAdapterNum)
|
||||
};
|
||||
D3D_FEATURE_LEVEL pFeatureLevelsOut;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&m_pDXGIFactory) );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
@ -74,25 +61,23 @@ mfxStatus CD3D11Device::Init(int nAdapterNum)
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
hres = D3D11CreateDevice(m_pAdapter ,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
0,
|
||||
FeatureLevels,
|
||||
MSDK_ARRAY_LEN(FeatureLevels),
|
||||
D3D11_SDK_VERSION,
|
||||
&m_pD3D11Device,
|
||||
&pFeatureLevelsOut,
|
||||
&m_pD3D11Ctx);
|
||||
hres = D3D11CreateDevice(m_pAdapter,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
0,
|
||||
featureLevels,
|
||||
MSDK_ARRAY_LEN(featureLevels),
|
||||
D3D11_SDK_VERSION,
|
||||
&m_pD3D11Device,
|
||||
&pFeatureLevelsOut,
|
||||
&m_pD3D11Ctx);
|
||||
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
m_pDXGIDev = m_pD3D11Device;
|
||||
m_pDX11VideoDevice = m_pD3D11Device;
|
||||
m_pVideoContext = m_pD3D11Ctx;
|
||||
|
||||
MSDK_CHECK_POINTER(m_pDXGIDev.p, MFX_ERR_NULL_PTR);
|
||||
MSDK_CHECK_POINTER(m_pDX11VideoDevice.p, MFX_ERR_NULL_PTR);
|
||||
MSDK_CHECK_POINTER(m_pVideoContext.p, MFX_ERR_NULL_PTR);
|
||||
|
||||
@ -127,4 +112,4 @@ void CD3D11Device::Close()
|
||||
Reset();
|
||||
}
|
||||
|
||||
#endif // #if MFX_D3D11_SUPPORT
|
||||
#endif // #if MFX_D3D11_SUPPORT
|
||||
|
@ -34,23 +34,21 @@
|
||||
class CD3D11Device: public CHWDevice
|
||||
{
|
||||
public:
|
||||
// ctor/dtor
|
||||
CD3D11Device();
|
||||
virtual ~CD3D11Device();
|
||||
//
|
||||
virtual mfxStatus Init(int nAdapterNum);
|
||||
virtual mfxStatus Reset();
|
||||
virtual mfxHDL GetHandle(mfxHandleType type);
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
virtual mfxStatus FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd);
|
||||
|
||||
CComPtr<ID3D11Device> m_pD3D11Device;
|
||||
CComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
|
||||
CComQIPtr<ID3D11VideoDevice> m_pDX11VideoDevice;
|
||||
CComQIPtr<ID3D11VideoContext> m_pVideoContext;
|
||||
|
||||
CComQIPtr<IDXGIDevice1> m_pDXGIDev;
|
||||
CComQIPtr<IDXGIAdapter> m_pAdapter;
|
||||
|
||||
CComPtr<IDXGIFactory2> m_pDXGIFactory;
|
||||
CComPtr<ID3D11Device> m_pD3D11Device;
|
||||
CComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
|
||||
CComQIPtr<ID3D11VideoDevice> m_pDX11VideoDevice;
|
||||
CComQIPtr<ID3D11VideoContext> m_pVideoContext;
|
||||
CComQIPtr<IDXGIAdapter> m_pAdapter;
|
||||
CComPtr<IDXGIFactory2> m_pDXGIFactory;
|
||||
};
|
||||
#endif //#if MFX_D3D11_SUPPORT
|
||||
|
@ -29,12 +29,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "QuickSync_defs.h"
|
||||
#include "QuickSyncUtils.h"
|
||||
|
||||
//prefast singnature used in combaseapi.h
|
||||
#ifndef _PREFAST_
|
||||
#pragma warning(disable:4068)
|
||||
#endif
|
||||
|
||||
#include "d3d_device.h"
|
||||
|
||||
CD3D9Device::CD3D9Device(IDirect3DDeviceManager9* pDeviceManager9) :
|
||||
@ -155,7 +149,6 @@ mfxStatus CD3D9Device::InitFromScratch(int nAdapterNum)
|
||||
&m_D3DPP,
|
||||
&m_pD3DD9);
|
||||
|
||||
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
@ -194,6 +187,7 @@ mfxStatus CD3D9Device::InitFromRenderer(int nAdapterNum)
|
||||
MSDK_TRACE("QsDecoder: failed to open device handle!\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
hr = extD3DManager->LockDevice(hDevice, &pDevice, TRUE);
|
||||
if (FAILED(hr) || NULL == pDevice)
|
||||
{
|
||||
@ -210,7 +204,7 @@ mfxStatus CD3D9Device::InitFromRenderer(int nAdapterNum)
|
||||
MSDK_TRACE("QsDecoder: The specified handle is not a Direct3D device handle.!\n");
|
||||
break;
|
||||
default:
|
||||
MSDK_TRACE("QsDecoder: Unknown error %x\n", hr);
|
||||
MSDK_TRACE("QsDecoder: Unknown error while locking D3D device %x\n", hr);
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
16
d3d_device.h
16
d3d_device.h
@ -30,21 +30,6 @@
|
||||
|
||||
#include "hw_device.h"
|
||||
|
||||
#pragma warning(disable : 4201)
|
||||
#include <d3d9.h>
|
||||
#include <dxva2api.h>
|
||||
#include <dxva.h>
|
||||
#include <windows.h>
|
||||
|
||||
enum {
|
||||
MFX_HANDLE_GFXS3DCONTROL = 0x100 /* A handle to the IGFXS3DControl instance */
|
||||
}; //mfxHandleType
|
||||
|
||||
#define OVERLAY_BACKBUFFER_FORMAT D3DFMT_X8R8G8B8
|
||||
#define VIDEO_MAIN_FORMAT D3DFMT_YUY2
|
||||
|
||||
class IGFXS3DControl;
|
||||
|
||||
/** Direct3D 9 device implementation.
|
||||
@note Can be initilized for only 1 or two 2 views. Handle to
|
||||
MFX_HANDLE_GFXS3DCONTROL must be set prior if initializing for 2 views.
|
||||
@ -74,4 +59,3 @@ private:
|
||||
D3DPRESENT_PARAMETERS m_D3DPP;
|
||||
UINT m_ResetToken;
|
||||
};
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mfxvideo++.h"
|
||||
|
||||
/// Base class for hw device
|
||||
class CHWDevice
|
||||
{
|
||||
@ -44,4 +42,4 @@ public:
|
||||
/// Get handle can be used for MFX session SetHandle calls
|
||||
virtual mfxHDL GetHandle(mfxHandleType type) = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user