mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[host] replaced MultiMemcpy with plain memcpySSE
This commit is contained in:
parent
1f90010cbd
commit
43593d8aea
@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
using namespace Capture;
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/memcpySSE.h"
|
||||
|
||||
#include <mfapi.h>
|
||||
#include <wmcodecdsp.h>
|
||||
@ -771,14 +772,13 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu
|
||||
{
|
||||
if (!m_surfaceMapped)
|
||||
continue;
|
||||
m_memcpy.Wake();
|
||||
|
||||
// send the last frame again if we timeout to prevent the client stalling on restart
|
||||
frame.pitch = m_mapping.RowPitch;
|
||||
frame.stride = m_mapping.RowPitch >> 2;
|
||||
|
||||
unsigned int size = m_height * m_mapping.RowPitch;
|
||||
m_memcpy.Copy(frame.buffer, m_mapping.pData, LG_MIN(size, frame.bufferSize));
|
||||
memcpySSE(frame.buffer, m_mapping.pData, LG_MIN(size, frame.bufferSize));
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
||||
|
||||
@ -811,14 +811,11 @@ GrabStatus Capture::DXGI::GrabFrameRaw(FrameInfo & frame, struct CursorInfo & cu
|
||||
}
|
||||
m_surfaceMapped = true;
|
||||
|
||||
// wake up the copy threads
|
||||
m_memcpy.Wake();
|
||||
|
||||
frame.pitch = m_mapping.RowPitch;
|
||||
frame.stride = m_mapping.RowPitch >> 2;
|
||||
|
||||
const unsigned int size = m_height * m_mapping.RowPitch;
|
||||
m_memcpy.Copy(frame.buffer, m_mapping.pData, LG_MIN(size, frame.bufferSize));
|
||||
memcpySSE(frame.buffer, m_mapping.pData, LG_MIN(size, frame.bufferSize));
|
||||
|
||||
return GRAB_STATUS_OK;
|
||||
}
|
||||
@ -918,9 +915,6 @@ GrabStatus Capture::DXGI::GrabFrameH264(struct FrameInfo & frame, struct CursorI
|
||||
m_encodeHasData = false;
|
||||
LeaveCriticalSection(&m_encodeCS);
|
||||
|
||||
// wake up the copy threads
|
||||
m_memcpy.Wake();
|
||||
|
||||
MFT_OUTPUT_STREAM_INFO streamInfo;
|
||||
status = m_mfTransform->GetOutputStreamInfo(0, &streamInfo);
|
||||
if (FAILED(status))
|
||||
@ -952,7 +946,7 @@ GrabStatus Capture::DXGI::GrabFrameH264(struct FrameInfo & frame, struct CursorI
|
||||
BYTE *pixels;
|
||||
DWORD maxLen, curLen;
|
||||
buffer->Lock(&pixels, &maxLen, &curLen);
|
||||
m_memcpy.Copy(frame.buffer, pixels, curLen);
|
||||
memcpySSE(frame.buffer, pixels, curLen);
|
||||
buffer->Unlock();
|
||||
SafeRelease(&buffer);
|
||||
|
||||
|
@ -20,7 +20,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#pragma once
|
||||
|
||||
#include "ICapture.h"
|
||||
#include "MultiMemcpy.h"
|
||||
|
||||
#define W32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
@ -132,7 +131,6 @@ namespace Capture
|
||||
unsigned int m_height;
|
||||
enum FrameType m_frameType;
|
||||
|
||||
MultiMemcpy m_memcpy;
|
||||
IDXGIFactory1Ptr m_dxgiFactory;
|
||||
ID3D11DevicePtr m_device;
|
||||
D3D_FEATURE_LEVEL m_featureLevel;
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "MultiMemcpy.h"
|
||||
#include "common/memcpySSE.h"
|
||||
|
||||
MultiMemcpy::MultiMemcpy()
|
||||
{
|
||||
for (int i = 0; i < MULTIMEMCPY_THREADS; ++i)
|
||||
{
|
||||
m_workers[i].id = (1 << i);
|
||||
m_workers[i].running = &m_running;
|
||||
m_workers[i].abort = false;
|
||||
m_workers[i].start = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
|
||||
m_workers[i].thread = CreateThread(0, 0, WorkerFunction, &m_workers[i], 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
MultiMemcpy::~MultiMemcpy()
|
||||
{
|
||||
for(int i = 0; i < MULTIMEMCPY_THREADS; ++i)
|
||||
{
|
||||
TerminateThread(m_workers[i].thread, 0);
|
||||
CloseHandle(m_workers[i].start);
|
||||
}
|
||||
}
|
||||
|
||||
void MultiMemcpy::Copy(void * dst, void * src, size_t size)
|
||||
{
|
||||
const size_t block = (size / MULTIMEMCPY_THREADS) & ~0x7F;
|
||||
if (block == 0)
|
||||
{
|
||||
Abort();
|
||||
memcpySSE(dst, src, size);
|
||||
return;
|
||||
}
|
||||
|
||||
Wake();
|
||||
for (int i = 0; i < MULTIMEMCPY_THREADS; ++i)
|
||||
{
|
||||
m_workers[i].dst = (uint8_t *)dst + i * block;
|
||||
m_workers[i].src = (uint8_t *)src + i * block;
|
||||
if (i == MULTIMEMCPY_THREADS - 1)
|
||||
m_workers[i].size = size - (block * i);
|
||||
else
|
||||
m_workers[i].size = block;
|
||||
}
|
||||
|
||||
INTERLOCKED_OR8(&m_running, (1 << MULTIMEMCPY_THREADS) - 1);
|
||||
while(m_running) {}
|
||||
|
||||
m_awake = false;
|
||||
}
|
||||
|
||||
DWORD WINAPI MultiMemcpy::WorkerFunction(LPVOID param)
|
||||
{
|
||||
struct Worker * w = (struct Worker *)param;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
WaitForSingleObject(w->start, INFINITE);
|
||||
while(!(*w->running & w->id)) {}
|
||||
if (w->abort)
|
||||
{
|
||||
w->abort = false;
|
||||
INTERLOCKED_AND8(w->running, ~w->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpySSE(w->dst, w->src, w->size);
|
||||
INTERLOCKED_AND8(w->running, ~w->id);
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
Looking Glass - KVM FrameRelay (KVMFR) Client
|
||||
Copyright (C) 2017 Geoffrey McRae <geoff@hostfission.com>
|
||||
https://looking-glass.hostfission.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#define MULTIMEMCPY_THREADS 4
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
#pragma once
|
||||
class MultiMemcpy
|
||||
{
|
||||
public:
|
||||
MultiMemcpy();
|
||||
~MultiMemcpy();
|
||||
|
||||
// preempt the copy and wake up the threads early
|
||||
inline void Wake()
|
||||
{
|
||||
if (m_awake)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < MULTIMEMCPY_THREADS; ++i)
|
||||
ReleaseSemaphore(m_workers[i].start, 1, NULL);
|
||||
|
||||
m_awake = true;
|
||||
}
|
||||
|
||||
// abort a pre-empted copy
|
||||
inline void Abort()
|
||||
{
|
||||
if (!m_awake)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < MULTIMEMCPY_THREADS; ++i)
|
||||
m_workers[i].abort = true;
|
||||
|
||||
INTERLOCKED_OR8(&m_running, (1 << MULTIMEMCPY_THREADS) - 1);
|
||||
while (m_running) {}
|
||||
|
||||
m_awake = false;
|
||||
}
|
||||
|
||||
|
||||
void Copy(void * dst, void * src, size_t size);
|
||||
private:
|
||||
struct Worker
|
||||
{
|
||||
unsigned int id;
|
||||
volatile char *running;
|
||||
bool abort;
|
||||
|
||||
HANDLE start;
|
||||
HANDLE thread;
|
||||
void * dst;
|
||||
void * src;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
bool m_awake;
|
||||
volatile char m_running;
|
||||
struct Worker m_workers[MULTIMEMCPY_THREADS];
|
||||
static DWORD WINAPI WorkerFunction(LPVOID param);
|
||||
};
|
||||
|
@ -336,7 +336,6 @@
|
||||
<ClCompile Include="CrashHandler.cpp" />
|
||||
<ClCompile Include="ivshmem.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="MultiMemcpy.cpp" />
|
||||
<ClCompile Include="Service.cpp" />
|
||||
<ClCompile Include="TraceUtil.cpp" />
|
||||
</ItemGroup>
|
||||
@ -347,7 +346,6 @@
|
||||
<ClInclude Include="CrashHandler.h" />
|
||||
<ClInclude Include="ICapture.h" />
|
||||
<ClInclude Include="ivshmem.h" />
|
||||
<ClInclude Include="MultiMemcpy.h" />
|
||||
<ClInclude Include="Service.h" />
|
||||
<ClInclude Include="TraceUtil.h" />
|
||||
<ClInclude Include="Util.h" />
|
||||
|
@ -42,9 +42,6 @@
|
||||
<ClCompile Include="CrashHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MultiMemcpy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TraceUtil.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -74,9 +71,6 @@
|
||||
<ClInclude Include="CrashHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MultiMemcpy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TraceUtil.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
Loading…
Reference in New Issue
Block a user