daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // clang++ -o SetStablePower.exe SetStablePower.cpp
  2.  
  3. #include <dxgi1_4.h>
  4. #include <d3d12.h>
  5. #include <stdio.h>
  6.  
  7. #pragma comment(lib, "d3d12.lib")
  8. #pragma comment(lib, "dxgi.lib")
  9.  
  10. void Error(const char *str)
  11. {
  12.     fprintf(stderr, "ERROR: %s\n", str);
  13.     Sleep(INFINITE);
  14. }
  15.  
  16. void GetHardwareAdapter(IDXGIFactory4 *pFactory, IDXGIAdapter1 **ppAdapter)
  17. {
  18.     *ppAdapter = nullptr;
  19.     for (UINT AdapterIndex = 0;; ++AdapterIndex)
  20.     {
  21.         IDXGIAdapter1 *pAdapter = nullptr;
  22.         if (DXGI_ERROR_NOT_FOUND == pFactory->EnumAdapters1(AdapterIndex, &pAdapter))
  23.         {
  24.             break;
  25.         }
  26.  
  27.         if (SUCCEEDED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
  28.         {
  29.             *ppAdapter = pAdapter;
  30.             return;
  31.         }
  32.         pAdapter->Release();
  33.     }
  34. }
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38.     IDXGIFactory4 *pFactory = nullptr;
  39.     if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&pFactory))))
  40.     {
  41.         Error("CreateDXGIFactory1 failed");
  42.     }
  43.  
  44.     IDXGIAdapter1 *pAdapter = nullptr;
  45.     GetHardwareAdapter(pFactory, &pAdapter);
  46.     if (!pAdapter)
  47.     {
  48.         Error("Failed to find DX12-compatible DXGI adapter");
  49.     }
  50.  
  51.     ID3D12Device *pDevice = nullptr;
  52.     if (FAILED(D3D12CreateDevice(pAdapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&pDevice))))
  53.     {
  54.         Error("D3D12CreateDevice failed for Adapter");
  55.     }
  56.  
  57.     if (FAILED(pDevice->SetStablePowerState(TRUE)))
  58.     {
  59.         Error("SetStablePowerState failed. Do you have the Win10 SDK installed?");
  60.     }
  61.  
  62.     printf("SUCCESS. Close this program to restore default clocks.\n");
  63.     Sleep(INFINITE);
  64.  
  65.     return 0;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top