From 43593d8aeaee7cfbe0c0574b94d212a9ae6e59e9 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 23 Jul 2018 15:21:43 +1000 Subject: [PATCH] [host] replaced MultiMemcpy with plain memcpySSE --- host/Capture/DXGI.cpp | 14 ++-- host/Capture/DXGI.h | 2 - host/MultiMemcpy.cpp | 90 ------------------------- host/MultiMemcpy.h | 82 ---------------------- host/looking-glass-host.vcxproj | 2 - host/looking-glass-host.vcxproj.filters | 6 -- 6 files changed, 4 insertions(+), 192 deletions(-) delete mode 100644 host/MultiMemcpy.cpp delete mode 100644 host/MultiMemcpy.h diff --git a/host/Capture/DXGI.cpp b/host/Capture/DXGI.cpp index 7f8852d8..c8877b6f 100644 --- a/host/Capture/DXGI.cpp +++ b/host/Capture/DXGI.cpp @@ -21,6 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA using namespace Capture; #include "common/debug.h" +#include "common/memcpySSE.h" #include #include @@ -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); diff --git a/host/Capture/DXGI.h b/host/Capture/DXGI.h index 02fd2ee9..146172ae 100644 --- a/host/Capture/DXGI.h +++ b/host/Capture/DXGI.h @@ -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 @@ -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; diff --git a/host/MultiMemcpy.cpp b/host/MultiMemcpy.cpp deleted file mode 100644 index 45f2c615..00000000 --- a/host/MultiMemcpy.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* -Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017 Geoffrey McRae -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); - } -} \ No newline at end of file diff --git a/host/MultiMemcpy.h b/host/MultiMemcpy.h deleted file mode 100644 index 188a17c8..00000000 --- a/host/MultiMemcpy.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -Looking Glass - KVM FrameRelay (KVMFR) Client -Copyright (C) 2017 Geoffrey McRae -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 -#include - -#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); -}; - diff --git a/host/looking-glass-host.vcxproj b/host/looking-glass-host.vcxproj index c40135bd..7f5de867 100644 --- a/host/looking-glass-host.vcxproj +++ b/host/looking-glass-host.vcxproj @@ -336,7 +336,6 @@ - @@ -347,7 +346,6 @@ - diff --git a/host/looking-glass-host.vcxproj.filters b/host/looking-glass-host.vcxproj.filters index 9bba02a4..26a2ff7c 100644 --- a/host/looking-glass-host.vcxproj.filters +++ b/host/looking-glass-host.vcxproj.filters @@ -42,9 +42,6 @@ Source Files - - Source Files - Source Files @@ -74,9 +71,6 @@ Header Files - - Header Files - Header Files