Commit Graph

176 Commits

Author SHA1 Message Date
Tudor Brindus
982b4e6625 [host] use variable-relative sizeof where possible 2021-08-16 16:22:55 +10:00
Quantum
4f7ce91e7f [host] capture: switch all asserts to DEBUG_ASSERT 2021-08-14 12:19:07 +10:00
Quantum
10ee6cd031 [host] nvfbc: read nvfbc:diffRes option with the correct type 2021-08-14 09:21:34 +10:00
Quantum
e5d252290d [common] array: add ALIGN_PAD macro for common logic
ALIGN_PAD(x, a) returns x rounded up to the nearest multiple of a.
2021-08-14 08:05:29 +10:00
Quantum
acd5ce51db [host] dxgi: use FAILED macro instead of comparing against S_OK 2021-08-13 20:21:50 +10:00
Quantum
d3ea9662bf [host] nvfbc: remove rectangles that are entirely contained in others
This makes nvfbc report less useless damage and makes the client run faster.
2021-08-13 20:21:27 +10:00
Quantum
566c89e9d8 [host] dxgi: correctly count moved rectangles 2021-08-13 20:21:08 +10:00
Quantum
b3173bdddc [host] dxgi: include correct DXGI headers
The declarations in dxgi_extra.h are not missing, they are in dxgi1_2.h and
dxgi1_5.h, which exist in MinGW-w64 since 2017.
2021-08-12 12:35:45 +10:00
Quantum
61a4b0744d [host] dxgi: use standard MinGW libd3d11.a
MinGW has been shipping this file since 2014, and that version contains the
only function from the dll that we call: D3D11CreateDevice.
2021-08-12 11:58:34 +10:00
Quantum
9bded74543 [host] dxgi: use CopySubresourceRegion when possible
This commit adds damage tracking to the DXGI textures, and only copies the
damaged areas to the textures with ID3D11DeviceContext::CopySubresourceRegion.

The sleep logic in waitFrame makes it difficult for this to reduce the
latency, but removing it shows significant improvements (6-7 ms to ~3 ms)
when a tiny portion of the screen is damaged, while showing no difference on
full screen damage.
2021-08-11 19:01:52 +10:00
Quantum
5e13549f74 [host] windows: use DEBUG_WINERROR for MsgWaitForMultipleObjects 2021-08-09 17:07:25 +10:00
Quantum
87a21f5f5e [host] windows: use DEBUG_WINERROR for CallNtPowerInformation
We need to use the function RtlNtStatusToDosError to convert NTSTATUS to
Windows error codes.
2021-08-09 17:07:25 +10:00
Quantum
9246e00163 [host] windows: use DEBUG_WINERROR for exit event opening code 2021-08-09 17:07:25 +10:00
Quantum
cab95c5eed [common] rects: refactor rect buffer copy code to common module
This also fixes a bug of accidentally multiplying the stride by 4 when
the stride is already in bytes and not pixels.
2021-08-08 08:30:11 +10:00
Quantum
3d29967a8d [host] dxgi: copy only damaged regions to IVSHMEM
This implementation uses a line sweep algorithm to copy the precisely the
intersection of all accumulated damage rectangles, ensuring that every
pixel is copied exactly once, and no pixel is ever copied multiple times.
Furthermore, once a row has been swept, we update the framebuffer write
pointer immediately.
2021-08-06 22:55:15 +10:00
Quantum
3651852430 [host] nvfbc: round pitch to multiple of 128 for dmabuf import
Certain drivers do not support pitches that are not multiples of 128 bytes,
and instead just does some kind of rounding internally. On DXGI, this is not
a problem because the API rounds pixel pitch, but NvFBC does not. This causes
certain resolutions to simply not work with dmabuf, most notably 3440x1440,
which is 1440p ultrawide.

Since we are copying pixels with the CPU anyways, we might as well round the
pitch up to 128 bytes (32 pixels).
2021-08-06 22:48:33 +10:00
Geoffrey McRae
2856928b57 [host] windows: implement KVMFR_FEATURE_SETCURSORPOS 2021-08-05 22:35:22 +10:00
Quantum
4da0c64583 [host] nvfbc: make diff map size configurable
This commit adds a new host configuration option, nvfbc:diffRes, which
specifies the dimensions of every block in the diff map. This defaults to
128, meaning the default 128x128 block size.

Since block sizes other than 128x128 is not guaranteed to be supported by
NvFBC, the function NvFBCGetDiffMapBlockSize was introduced to query the
support and output the actual block size used.
2021-08-05 07:27:28 +10:00
Quantum
4e81c7f724 [host] windows: make copyright string in resource use © 2021-08-04 21:16:35 +10:00
Quantum
51b9cd4e5a [all] copyright: use unicode copyright sign ©
This is done for consistency with the license strings in appstrings.c.
2021-08-04 21:16:35 +10:00
arcnmx
c0aec7d8f4 [host] nvfbc: disable pointerThread when unused
fixes log spam that would occur when decoupleCursor=false
2021-08-03 21:05:39 +10:00
Quantum
7801575d99 [host] nvfbc: log error codes for various errors
This makes troubleshooting easier.

We also switch to use %d instead of 0x%x because all error codes in nvfbc.h
are negative decimal numbers.
2021-07-31 15:02:39 +10:00
Geoffrey McRae
5f5f497cbd [host/common] windows: provide delayExecution via nsleep
This change moves this platform specific sleep to `common` as the OS
agnostic `nsleep` function.

Ref PR #661
2021-07-26 16:36:56 +10:00
Quantum
8528969efd [host] nvfbc: clamp damage rectangles to screen size 2021-07-25 14:34:10 +10:00
arcnmx
2c745db544 [host] windows: use CMAKE_DLLTOOL if available
cmake automatically finds dlltool as of version 3.16
2021-07-24 14:52:32 +10:00
Quantum
3cf0257f34 [host] windows: do not complain about failed timer destruction at exit
When our window is destroyed, our timers are also destroyed. This causes our
attempt at destruction to fail. Instead, set MessageHWND to NULL in the
WM_DESTROY handler and don't try destroying the timers if the window is gone.
2021-07-23 15:52:45 +10:00
Quantum
4c60409aaf [host] windows: use WM_CLOSE to signal window destruction
DestroyWindow can only be invoked on the thread that created the window.
All other threads must use WM_CLOSE or another message to signal tell the
window to destroy itself.
2021-07-22 18:55:11 +10:00
Quantum
e58506f1a5 [all] copyright: refresh copyright notice for .nsi and .rc files 2021-07-21 18:19:46 +10:00
Quantum
f5dfc264ba [host] windows: trick MinGW into not using memcpy from ntdll
MinGW seems to decide at random whether it wants to use memcpy from
mscvrt.dll or ntdll.dll. Currently, on Debian buster, ntdll.dll is chosen,
while on sid, mscvrt.dll is chosen.

This commit declares a new .def file for ntdll containing only the
functions we want to link from ntdll.dll, and generates ntdll.a from it
with dlltool. This way, MinGW will never be tempted to link functions
like memcpy from ntdll.dll.
2021-07-21 15:45:59 +10:00
Quantum
8a70efafb5 [host] windows: use system thread pool to wait for exit event
This is much less annoying than creating our own thread just to wait on
a single event, then creating another event to signal that thread to exit.
2021-07-21 14:13:31 +10:00
Quantum
b1c26aaa95 [host] windows: log MsgWaitForMultipleObjects errors
This function is sometimes flaky and may fail for no apparent reason,
see https://stackoverflow.com/q/3945003. This has also been experienced
during the development of #610.

This commit adds logging so we may see if it ever fails for no reason
and work out some way to fix it.
2021-07-21 12:33:36 +10:00
Quantum
3400c2c141 [host] windows: add version resource
This allows friendly names and versions to be displayed in task manager
and other applications.
2021-07-21 12:32:41 +10:00
Quantum
80bc9604ba [host] windows: fix graceful exit
We were using an auto-reset event to signal the mousehook exit. This was
fine when there was only one thread, but with the addition of the update
thread, only one thread is signaled, causing the wait to last forever.

The fix is switching to a manual reset event and call ResetEvent after
the threads have exited.
2021-07-21 12:32:14 +10:00
Quantum
669148bca0 [host] service: respond to exit request while sleeping
Instead of Sleep, we can use WaitForSingleObject with a timeout to be
signalled when the service is exiting.
2021-07-21 12:30:27 +10:00
Quantum
26df3579a3 [host] windows/delay: cast to LONGLONG instead of int
The type of the QuadPart member of the LARGE_INTEGER union is actually
LONGLONG, so we should cast to LONGLONG instead of int.
This avoids truncation should (ms * 10000.0f) exceed 2^31-1.
2021-07-21 12:29:29 +10:00
Quantum
88fc1a6d24 [host] windows: directly invoke ChangeWindowMessageFilterEx
This requires bumping the minimum Windows version to Windows 7, but I
don't think we care about Vista anyways.
2021-07-20 12:16:49 +10:00
Quantum
28a67cad0d [host] windows: avoid compiling .rc file twice
a4f5ce08b9 has a regression that caused
the .rc file to be compiled twice. We do not want the version that's
added into the .a file.
2021-07-20 12:14:04 +10:00
Quantum
d82333519c [host] dxgi: use SDK versionhelpers.h to test for Windows version
Also, changed logic so that Windows versions before 8 is not treated as 10.
2021-07-20 11:34:57 +10:00
Quantum
5421bd8b1d [host] windows: declare Windows 10 support in manifest
This allows IsWindows10OrGreater from <versionhelpers.h> to work.
2021-07-20 11:34:57 +10:00
Quantum
f0c7e9bdfa [host] windows: declare high DPI support in manifest
This is the normal way of doing things, and it's easier and less sketchy
than GetProcAddress.
2021-07-20 11:34:45 +10:00
Quantum
f5ad14b109 [host] windows: directly link D3DKMTSetProcessSchedulingPriorityClass
This function is available since Windows Vista and can therefore be used
directly without going through GetProcAddress. Unfortunately, MinGW does
not have d3dkmthk.h, but we can declare the prototype ourselves and link
against gdi32.dll.
2021-07-20 11:32:41 +10:00
Quantum
323d321a77 [host] windows: correctly declare WINVER and _WIN32_WINNT
We wanted to target Windows Vista, which is 0x0600 not 0x6000.
0x6000 is in fact larger than Windows 10 which is 0x0a00.
2021-07-20 11:32:15 +10:00
Quantum
56833edae7 [host] delay: directly link against ntdll.dll
There is no need to LoadLibrary and GetProcAddress to get pointers to
NtDelayExecution or NtSetTimerResolution. These functions don't have
prototypes in any SDK header, but they are exported in ntdll.dll and
we can simply declare the prototype and link ntdll.

There is also no chance that the functions do not exist: I checked an
old install of Windows NT 4.0 and both of these functions exist.

Also used NtSetTimerResolution instead of ZeSetTimerResolution for
consistency (they are the same).

Also changed system timer resolution log message units to μs with
one decimal digit for readability. This is the actual amount of
precision available to us.
2021-07-20 11:30:12 +10:00
Quantum
d57b5a320e [host] service: fix adjustPriv return value
When OpenProcessToken fails, the function returned -1, which would be true
when converted to bool. This is wrong, and it should be returning false.
2021-07-20 11:29:32 +10:00
Quantum
b4dc021381 [host] service: pass CREATE_UNICODE_ENVIRONMENT unconditionally
According to MSDN documentation for CreateEnvironmentBlock, "[i]f the
environment block is passed to CreateProcessAsUser, you must also
specify the CREATE_UNICODE_ENVIRONMENT flag."

Also pass DETACHED_PROCESS because the host is a GUI application and
doesn't use the console.
2021-07-20 11:27:16 +10:00
Quantum
ebda52b18b [host] service: use SYSTEM token attached to the current process
Since with the service, we are already running as SYSTEM, we don't need
to use dupeSystemProcessToken to get the token for SYSTEM. This removes
the need for having SeDebugPrivilege, SeTcbPrivilege, and
SeAssignPrimaryTokenPrivilege, or otherwise doing sketchy things.

Furthermore, we now only open the token with the privileges we actually
need.
2021-07-20 11:27:03 +10:00
Quantum
16ee1a825c [host] windows: use event to gracefully signal exit
This allows the process to be terminated without resorting to
TerminateProcess. With some fixes, this allows the notification icon to be
removed when the service is restarted.

Furthermore, instead of sending WM_DESTROY to fool the window into believing
it's being destroyed, we actually call DestroyWindow now.
2021-07-20 11:26:49 +10:00
arcnmx
aa41e4d2ce Revert "Revert "[host] avoid manual windres command""
This reverts commit cd10e02862.
2021-07-20 11:25:55 +10:00
Quantum
9ab85fd0b8 [host] capture: stop sending DPI information
The client doesn't need DPI information anymore, so there is no point
fetching it.
2021-07-18 10:50:57 +10:00
Tudor Brindus
92706caddc [common]: move array length into a common helper
Since it is more generally useful, and less cryptic this way.
2021-07-18 10:41:50 +10:00