mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[host] improve capture performance
Contrary to the MS documentation, benchmarking shows a substantial increase in performance when releasing the captured frame as soon as possible. This change makes it possible to achieve 60FPS at 4K resolutions.
This commit is contained in:
@@ -435,11 +435,7 @@ void DXGI::DeInitialize()
|
||||
m_mfTransform->DeleteInputStream(0);
|
||||
}
|
||||
|
||||
if (m_releaseFrame)
|
||||
{
|
||||
m_releaseFrame = false;
|
||||
m_dup->ReleaseFrame();
|
||||
}
|
||||
ReleaseFrame();
|
||||
|
||||
if (m_pointer)
|
||||
{
|
||||
@@ -611,26 +607,6 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (m_releaseFrame)
|
||||
{
|
||||
m_releaseFrame = false;
|
||||
status = m_dup->ReleaseFrame();
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case S_OK:
|
||||
break;
|
||||
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
DEBUG_ERROR("Frame was already released");
|
||||
return GRAB_STATUS_ERROR;
|
||||
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
WaitForDesktop();
|
||||
return GRAB_STATUS_REINIT;
|
||||
}
|
||||
}
|
||||
|
||||
status = m_dup->AcquireNextFrame(1000, &frameInfo, &res);
|
||||
if (status == DXGI_ERROR_WAIT_TIMEOUT)
|
||||
{
|
||||
@@ -745,6 +721,7 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs
|
||||
|
||||
if (!texture)
|
||||
{
|
||||
ReleaseFrame();
|
||||
DEBUG_ERROR("Failed to get src ID3D11Texture2D");
|
||||
return GRAB_STATUS_ERROR;
|
||||
}
|
||||
@@ -752,6 +729,30 @@ GrabStatus Capture::DXGI::GrabFrameTexture(struct FrameInfo & frame, struct Curs
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
||||
|
||||
GrabStatus Capture::DXGI::ReleaseFrame()
|
||||
{
|
||||
if (!m_releaseFrame)
|
||||
return GRAB_STATUS_OK;
|
||||
|
||||
m_releaseFrame = false;
|
||||
switch (m_dup->ReleaseFrame())
|
||||
{
|
||||
case S_OK:
|
||||
break;
|
||||
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
DEBUG_ERROR("Frame was already released");
|
||||
return GRAB_STATUS_ERROR;
|
||||
|
||||
case WAIT_ABANDONED:
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
WaitForDesktop();
|
||||
return GRAB_STATUS_REINIT;
|
||||
}
|
||||
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
||||
|
||||
GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cursor)
|
||||
{
|
||||
GrabStatus result;
|
||||
@@ -762,7 +763,10 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu
|
||||
{
|
||||
result = GrabFrameTexture(frame, cursor, src, timeout);
|
||||
if (result != GRAB_STATUS_OK)
|
||||
{
|
||||
ReleaseFrame();
|
||||
return result;
|
||||
}
|
||||
|
||||
if (timeout)
|
||||
{
|
||||
@@ -785,6 +789,10 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu
|
||||
m_deviceContext->CopyResource(m_texture, src);
|
||||
SafeRelease(&src);
|
||||
|
||||
result = ReleaseFrame();
|
||||
if (result != GRAB_STATUS_OK)
|
||||
return result;
|
||||
|
||||
if (m_surfaceMapped)
|
||||
{
|
||||
m_deviceContext->Unmap(m_texture, 0);
|
||||
@@ -855,6 +863,7 @@ GrabStatus Capture::DXGI::GrabFrameH264(struct FrameInfo & frame, struct CursorI
|
||||
result = GrabFrameTexture(frame, cursor, src, timeout);
|
||||
if (result != GRAB_STATUS_OK)
|
||||
{
|
||||
ReleaseFrame();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -898,6 +907,7 @@ GrabStatus Capture::DXGI::GrabFrameH264(struct FrameInfo & frame, struct CursorI
|
||||
SafeRelease(&sample);
|
||||
SafeRelease(&buffer);
|
||||
|
||||
ReleaseFrame();
|
||||
EnterCriticalSection(&m_encodeCS);
|
||||
}
|
||||
|
||||
|
@@ -117,6 +117,7 @@ namespace Capture
|
||||
bool InitH264Capture();
|
||||
|
||||
GrabStatus GrabFrameTexture(struct FrameInfo & frame, struct CursorInfo & cursor, ID3D11Texture2DPtr & texture, bool & timeout);
|
||||
GrabStatus ReleaseFrame();
|
||||
GrabStatus GrabFrameRaw (struct FrameInfo & frame, struct CursorInfo & cursor);
|
||||
GrabStatus GrabFrameH264 (struct FrameInfo & frame, struct CursorInfo & cursor);
|
||||
|
||||
|
Reference in New Issue
Block a user