mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-07 08:07:20 +02:00
Merge pull request #114 from mdiluz/fix-issue-113
Try and make an educated guess at the correct nvidia gpu index
This commit is contained in:
commit
746b463783
@ -67,44 +67,36 @@ static void print_usage_and_exit(void)
|
|||||||
/* Get the nvidia driver index for the current GPU */
|
/* Get the nvidia driver index for the current GPU */
|
||||||
static long get_gpu_index_id_nv(struct GameModeGPUInfo *info)
|
static long get_gpu_index_id_nv(struct GameModeGPUInfo *info)
|
||||||
{
|
{
|
||||||
// Default to using the current device number
|
|
||||||
long gpu_index = info->device;
|
|
||||||
|
|
||||||
if (info->vendor != Vendor_NVIDIA)
|
if (info->vendor != Vendor_NVIDIA)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!getenv("DISPLAY"))
|
/* NOTE: This is currently based off of a best guess of how the NVidia gpu index works
|
||||||
LOG_ERROR("Getting Nvidia parameters requires DISPLAY to be set - will likely fail!\n");
|
* ie. that the index is simply the index into available NV gpus in the same order as drm
|
||||||
long current = 0;
|
* If that is not the case then this may fail to discern the correct GPU
|
||||||
do {
|
*/
|
||||||
char arg[128] = { 0 };
|
|
||||||
char buf[EXTERNAL_BUFFER_MAX] = { 0 };
|
|
||||||
char *end;
|
|
||||||
|
|
||||||
/* Get the PCI id parameter */
|
int device = 0;
|
||||||
snprintf(arg, 128, NV_ATTRIBUTE_FORMAT, current, NV_PCIDEVICE_ATTRIBUTE);
|
int nv_device = -1;
|
||||||
const char *exec_args_core[] = { "/usr/bin/nvidia-settings", "-q", arg, "-t", NULL };
|
while (device <= info->device) {
|
||||||
if (run_external_process(exec_args_core, buf, -1) != 0) {
|
/* Get the vendor for each gpu sequentially */
|
||||||
LOG_ERROR("Failed to get %s! Will be defaulting to nvidia gpu index %ld\n",
|
enum GPUVendor vendor = gamemode_get_gpu_vendor(device++);
|
||||||
arg,
|
|
||||||
gpu_index);
|
switch (vendor) {
|
||||||
/* Failure just means we've overrun the device list */
|
case Vendor_NVIDIA:
|
||||||
|
/* If we've found an nvidia device, increment our counter */
|
||||||
|
nv_device++;
|
||||||
|
break;
|
||||||
|
case Vendor_Invalid:
|
||||||
|
/* Bail out, we've gone too far */
|
||||||
|
LOG_ERROR("Failed to find Nvidia GPU with expected index!\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* Non-NV gpu, continue */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
long pcidevice = strtol(buf, &end, 10);
|
return nv_device;
|
||||||
if (end == buf) {
|
|
||||||
LOG_ERROR("Failed to parse output for \"%s\" output was \"%s\"!\n", arg, buf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info->device == pcidevice) {
|
|
||||||
gpu_index = current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
return gpu_index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the max nvidia perf level */
|
/* Get the max nvidia perf level */
|
||||||
@ -405,13 +397,11 @@ int main(int argc, char *argv[])
|
|||||||
info.device = get_device(argv[1]);
|
info.device = get_device(argv[1]);
|
||||||
info.vendor = gamemode_get_gpu_vendor(info.device);
|
info.vendor = gamemode_get_gpu_vendor(info.device);
|
||||||
|
|
||||||
/* Adjust the device number to the gpu index for Nvidia */
|
|
||||||
if (info.vendor == Vendor_NVIDIA)
|
|
||||||
info.device = get_gpu_index_id_nv(&info);
|
|
||||||
|
|
||||||
/* Fetch the state and print it out */
|
/* Fetch the state and print it out */
|
||||||
switch (info.vendor) {
|
switch (info.vendor) {
|
||||||
case Vendor_NVIDIA:
|
case Vendor_NVIDIA:
|
||||||
|
/* Adjust the device number to the gpu index for Nvidia */
|
||||||
|
info.device = get_gpu_index_id_nv(&info);
|
||||||
|
|
||||||
if (get_gpu_state_nv(&info) != 0)
|
if (get_gpu_state_nv(&info) != 0)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -444,6 +434,9 @@ int main(int argc, char *argv[])
|
|||||||
info.nv_core = get_generic_value(argv[3]);
|
info.nv_core = get_generic_value(argv[3]);
|
||||||
info.nv_mem = get_generic_value(argv[4]);
|
info.nv_mem = get_generic_value(argv[4]);
|
||||||
|
|
||||||
|
/* Adjust the device number to the gpu index for Nvidia */
|
||||||
|
info.device = get_gpu_index_id_nv(&info);
|
||||||
|
|
||||||
/* Optional */
|
/* Optional */
|
||||||
info.nv_powermizer_mode = -1;
|
info.nv_powermizer_mode = -1;
|
||||||
if (argc >= 6)
|
if (argc >= 6)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user