gamemode-gpu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright (c) 2017-2018, Feral Interactive
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of Feral Interactive nor the names of its contributors
  12. may be used to endorse or promote products derived from this software
  13. without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #define _GNU_SOURCE
  27. #include "gamemode.h"
  28. #include "helpers.h"
  29. #include "logging.h"
  30. #include "daemon_config.h"
  31. #include "gpu-query.h"
  32. // TODO
  33. // Gather GPU type and information
  34. // Allow override of vendor and device
  35. // Apply Nvidia GPU settings (CoolBits will be needed)
  36. // Apply AMD GPU settings (Will need user changing pwm1_enable)
  37. // Intel?
  38. // Provide documentation on optimisations
  39. /**
  40. * Attempts to identify the current in use GPU information
  41. */
  42. int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info)
  43. {
  44. int status = 0;
  45. /* Verify input, this is programmer error */
  46. if (!info || *info)
  47. FATAL_ERROR("Invalid GameModeGPUInfo passed to %s", __func__);
  48. /* Early out if we have this feature turned off */
  49. long apply = 0;
  50. config_get_apply_gpu_optimisations(config, &apply);
  51. if (apply == 0)
  52. return 0;
  53. /* Create the context */
  54. GameModeGPUInfo *new_info = malloc(sizeof(GameModeGPUInfo));
  55. memset(new_info, 0, sizeof(GameModeGPUInfo));
  56. // TODO: Fill in the GPU vendor and device
  57. /* Load the config based on GPU */
  58. switch (new_info->vendor) {
  59. case Vendor_NVIDIA:
  60. config_get_nv_core_clock_mhz_offset(config, &new_info->core);
  61. config_get_nv_mem_clock_mhz_offset(config, &new_info->mem);
  62. break;
  63. case Vendor_AMD:
  64. config_get_amd_core_clock_percentage(config, &new_info->core);
  65. config_get_amd_mem_clock_percentage(config, &new_info->mem);
  66. break;
  67. default:
  68. break;
  69. }
  70. /* Give back the new gpu info */
  71. *info = new_info;
  72. return status;
  73. }
  74. /* Simply used to free the GPU info object */
  75. void game_mode_free_gpu(GameModeGPUInfo **info)
  76. {
  77. /* Simply free the object */
  78. free(*info);
  79. *info = NULL;
  80. }
  81. /**
  82. * Applies GPU optimisations when gamemode is active and removes them after
  83. */
  84. int game_mode_apply_gpu(const GameModeGPUInfo *info, bool apply)
  85. {
  86. // Null info means don't apply anything
  87. if (!info)
  88. return 0;
  89. /* TODO Call gpuclockctl set */
  90. return 0;
  91. }