nvEncMapInputResource with NV_ENC_ERR_INVALID_PARAM

  •   errorLog	0x000001f1f51daed0 "NvEncoder::MapResources : m_nvenc.nvEncMapInputResource(m_hEncoder, &mapInputResource) returned error 8 at D:\\windows\\Win32CaptureSample\\Samples\\NvCodec\\NvEncoder\\NvEncoder.cpp:370\n"	std::basic_ostringstream<char,std::char_traits<char>,std::allocator<char>>
    

I’m capture screen with Windows.Graphics.Capture,but failed in m_nvenc.nvEncMapInputResource. the origin sample capture with dxgi is ok.what’s the problem???

void NvEncoder::MapResources(uint32_t bfrIdx)
{
    NV_ENC_MAP_INPUT_RESOURCE mapInputResource = { NV_ENC_MAP_INPUT_RESOURCE_VER };

    mapInputResource.registeredResource = m_vRegisteredResources[bfrIdx];
    NVENC_API_CALL(m_nvenc.nvEncMapInputResource(m_hEncoder, &mapInputResource));
    m_vMappedInputBuffers[bfrIdx] = mapInputResource.mappedResource;

    if (m_bMotionEstimationOnly)
    {
        mapInputResource.registeredResource = m_vRegisteredResourcesForReference[bfrIdx];
        NVENC_API_CALL(m_nvenc.nvEncMapInputResource(m_hEncoder, &mapInputResource));
        m_vMappedRefBuffers[bfrIdx] = mapInputResource.mappedResource;
    }
}

void SimpleCapture::OnFrameArrived(winrt::Direct3D11CaptureFramePool const& sender, winrt::IInspectable const&)
{
	HRESULT hr = S_OK;
	auto frame = sender.TryGetNextFrame();
	auto surfaceTexture = GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame.Surface());
	...
	Preproc();//convert surfaceTexture, ConvertRGBToNV12
	Encode();//error in MapResources
}