mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-05 10:14:04 +00:00
[host] dxgi: sleep until it's close to time to map
This change adds an average function to time how long it takes the GPU to copy and map the texture, and then uses this average to sleep for 80% of this average lowering CPU usage and potentially decreasing lock contention.
This commit is contained in:

committed by
Geoffrey McRae

parent
7f5f46c448
commit
f02d61d665
@@ -28,6 +28,7 @@ set(COMMON_SOURCES
|
||||
src/framebuffer.c
|
||||
src/KVMFR.c
|
||||
src/countedbuffer.c
|
||||
src/runningavg.c
|
||||
)
|
||||
|
||||
add_library(lg_common STATIC ${COMMON_SOURCES})
|
||||
|
28
common/include/common/runningavg.h
Normal file
28
common/include/common/runningavg.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Looking Glass
|
||||
Copyright (C) 2017-2021 The Looking Glass Authors
|
||||
https://looking-glass.io
|
||||
|
||||
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 <stdint.h>
|
||||
|
||||
typedef struct RunningAvg * RunningAvg;
|
||||
|
||||
RunningAvg runningavg_new(int length);
|
||||
void runningavg_free(RunningAvg * ra);
|
||||
void runningavg_push(RunningAvg ra, int64_t value);
|
||||
void runningavg_reset(RunningAvg ra);
|
||||
double runningavg_calc(RunningAvg ra);
|
69
common/src/runningavg.c
Normal file
69
common/src/runningavg.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Looking Glass
|
||||
Copyright (C) 2017-2021 The Looking Glass Authors
|
||||
https://looking-glass.io
|
||||
|
||||
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 "common/runningavg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct RunningAvg
|
||||
{
|
||||
int length, samples;
|
||||
int pos;
|
||||
int value;
|
||||
int64_t values[0];
|
||||
};
|
||||
|
||||
RunningAvg runningavg_new(int length)
|
||||
{
|
||||
struct RunningAvg * ra = calloc(1, sizeof(*ra) + sizeof(*ra->values) * length);
|
||||
ra->length = length;
|
||||
return ra;
|
||||
}
|
||||
|
||||
void runningavg_free(RunningAvg * ra)
|
||||
{
|
||||
free(*ra);
|
||||
*ra = NULL;
|
||||
}
|
||||
|
||||
void runningavg_push(RunningAvg ra, int64_t value)
|
||||
{
|
||||
if (ra->samples == ra->length)
|
||||
ra->value -= ra->values[ra->pos];
|
||||
else
|
||||
++ra->samples;
|
||||
|
||||
ra->value += value;
|
||||
ra->values[ra->pos++] = value;
|
||||
|
||||
if (ra->pos == ra->length)
|
||||
ra->pos = 0;
|
||||
}
|
||||
|
||||
void runningavg_reset(RunningAvg ra)
|
||||
{
|
||||
ra->samples = 0;
|
||||
ra->pos = 0;
|
||||
ra->value = 0;
|
||||
}
|
||||
|
||||
double runningavg_calc(RunningAvg ra)
|
||||
{
|
||||
return (double)ra->value / ra->samples;
|
||||
}
|
Reference in New Issue
Block a user