Skip to content

Commit

Permalink
Introduce SGL_RUN_WITH_LOW_PRIORITY
Browse files Browse the repository at this point in the history
* improved smoothness on windows by lowering the process priority
  • Loading branch information
dmaivel committed Jun 9, 2024
1 parent b1dd75e commit 336d830
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,14 @@ options:
```
### Environment variables
When running clients, a user may specify one or more of the following environment variables for version control:
```
GL_VERSION_OVERRIDE=X.X
GLX_VERSION_OVERRIDE=X.X
GLSL_VERSION_OVERRIDE=X.X
```
If networking on the server is enabled (using `-n`), the client must be aware of the address and port (both of which are outputted by the server):
```
SGL_NET_OVER_SHARED=HOST_ADDRESS:PORT
```
| **Option** | **Legal values** | **Default** | **Description** |
|---------------------------|------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| GL_VERSION_OVERRIDE | Integer.Integer | 3.3 | Override the OpenGL version on the client side. |
| GLX_VERSION_OVERRIDE | Integer.Integer | 1.4 | Override the GLX version on the client side. |
| GLSL_VERSION_OVERRIDE | Integer.Integer | 3.3 | Override the GLSL version on the client side. |
| SGL_NET_OVER_SHARED | Ip:Port | | If networking is enabled, this environment variable must exist on the guest. |
| SGL_RUN_WITH_LOW_PRIORITY | Boolean | true | On older CPUs, by setting the process priority to low / `IDLE_PRIORITY_CLASS`, applications will run smoother as the kernel driver is given more CPU time. This may not be needed on systems with newer CPUs. Set on the client side. |
### Network
Expand Down
14 changes: 14 additions & 0 deletions src/client/winmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <windows.h>
#include <client/platform/windrv.h>
#include <client/glimpl.h>
#include <string.h>

static char sgl_run_with_low_priority_env_value[16];

VOID Main()
{
Expand All @@ -15,6 +18,17 @@ VOID Main()
BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
{
if (reason == DLL_PROCESS_ATTACH) {
/*
* some weird hack that can speed up processes, reducing apparent lag;
* by setting the priority of the program to "low", we give the kernel
* more CPU time, which is crucial because the kernel driver is how data
* between the VM and host move.
*/

DWORD result = GetEnvironmentVariableA("SGL_RUN_WITH_LOW_PRIORITY", sgl_run_with_low_priority_env_value, 16);
if (result == 0 || strcmp(sgl_run_with_low_priority_env_value, "true") == 0)
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);

WinDrvSetModuleAddress(module);
Main();
}
Expand Down

0 comments on commit 336d830

Please sign in to comment.