[
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright© 2017 J.S. Obeid\n\nPermission is hereby granted, free of charge, to any person \nobtaining a copy of this software and associated documentation \nfiles(the \\Software\\), to deal in the Software without \nrestriction, including without limitation the rights to use, \ncopy, modify, merge, publish, distribute, sublicense, and / or \nsell copies of the Software, and to permit persons to whom the \nSoftware is furnished to do so, subject to the following \nconditions:\n\nThe above copyright notice and this permission notice shall be \nincluded in all copies or substantial portions of the Software. \n\nTHE SOFTWARE IS PROVIDED \\AS IS\\, WITHOUT WARRANTY OF ANY KIND, \nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES \nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  \nNONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, \nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING \nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR \nOTHER DEALINGS IN THE SOFTWARE. \t\t\n"
  },
  {
    "path": "README.md",
    "content": "# TrayPwrD3\n**Keeps dGPU on but idle** until needed. This addresses the Windows 10 (64bit) stutter/mouse freeze on dual GPU laptops (intel or AMD CPU with built in GPU in combination with NVIDIA). TrayPwrD3 runs in the background and stays in a tray icon.   ![Tray icon](screenshots/traypwr_icon1.png?raw=true \"Tray icon\")\n\n**Other functionality**: single click turns monitor off to save power until you wake it up by moving the mouse or using the keyboard; provides several menu options on right click; more details in Help menu.\n\nThis is to address the [Windows 10 and Optimus problem of stutters and mouse hangs](https://forums.geforce.com/default/topic/860554/geforce-mobile-gpus/windows-10-and-optimus/15/). For more about this issue see description on answers.microsoft [Intel + NVIDIA Laptop Freeze Problem](https://answers.microsoft.com/en-us/windows/forum/windows_10-hardware/mobile-gtx-1060-freeze-problem/93e7004a-62b1-4211-8e37-4c136608865e). Note: it is not for stutters in games. It only addresses the desktop stutters in Windows 10 (right click -> display settings, battery icon, chrome and firefox tabs, PowerPoint slideshow etc).  If you don't have any of these, then you don't need it. \n\n**Windows 10 May 2020 Update:** With this latest update Microsoft fixed the latency issue. However, you will need NVIDIA driver version 451.48 or later. For more information see this Windows Latest post: [Nvidia GeForce 451.48 adds Windows 10 GPU scheduling feature](https://www.windowslatest.com/2020/06/24/nvidia-geforce-451-48-windows-10-hardware-accelerated-gpu-scheduling/).\n  \n**Update 7/14/2020:** Still noticing some brief hanging during some activities with explorer. So latency issue not totally fixed.\n\n**Update 11/12/2020:** Still noticing some major hanging during some activities with explorer and when running certain apps e.g. Media Player Classic on AMD Ryzen systems. So NVIDIA GPU activation latency remains a problem. The updated version of TrayPwrD3 (v2020-11) now supports AMD Ryzen systems and prevents the GPU stutter or latency on both Intel and AMD Ryzen systems.\n\n**Update 12/25/2025:** Starting the app now checks if there is a running instance and gives the option to kill it.\n\n# Installation\nSimply download the latest version of the [executable](https://github.com/jobeid/TrayPwrD3/tree/master/executable), uncompress it in any folder and run it. \nNotes:\n- The executable was compliled for 64bit windows. \n- Direct3D version 12 is required.\n- If you don't already have [Visual C++ Redistributable for Visual Studio](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) installed, then you could download the 64bit version [directly from Microsoft](https://aka.ms/vs/16/release/vc_redist.x64.exe) and install it.\n- Optional: If you would like to start TrayPwrD3 when windows starts, you can place a shortcut of the executable in the startup folder (located at %USERPROFILE%\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\STARTUP). You can quickly open the startup folder by tapping the Windows key+R to bring up the \"Run\" dialog, and type `shell:startup` then enter.\n\n# Using the App\nWhen you start the app it simply runs in the background in a tray icon, keeping the dGPU on but idle. This addresses the well known Windows 10 stutter/mouse freeze on some dual GPU laptops.\n\n**To stop the app** simpley right-click the icon and click exit. **There is _no_ need to reboot the system**.\n\n# Screenshots\n\nTray icon:   ![Tray icon](screenshots/traypwr_icon1.png?raw=true \"Tray icon\")\n\n\nRight click menu:  ![Menu](screenshots/traypwr_rightclick1.png?raw=true \"Menu\")\n"
  },
  {
    "path": "src/AboutDlg.cpp",
    "content": "// AboutDlg.cpp : implementation file\r\n//\r\n\r\n#include \"stdafx.h\"\r\n#include \"traypwr.h\"\r\n#include \"AboutDlg.h\"\r\n\r\n#ifdef _DEBUG\r\n#define new DEBUG_NEW\r\n#undef THIS_FILE\r\nstatic char THIS_FILE[] = __FILE__;\r\n#endif\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CAboutDlg dialog\r\n\r\n\r\nBOOL CAboutDlg::m_bVisible = FALSE;\r\nHWND CAboutDlg::m_MyhWnd = NULL;\r\n\r\nCAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)\r\n{\r\n\tm_hChildProcess = NULL;\r\n\tm_dwChildProcessId = 0;\r\n\t//{{AFX_DATA_INIT(CAboutDlg)\r\n\t//}}AFX_DATA_INIT\r\n}\r\n\r\nvoid CAboutDlg::DoDataExchange(CDataExchange* pDX)\r\n{\r\n\tCDialog::DoDataExchange(pDX);\r\n\t//{{AFX_DATA_MAP(CAboutDlg)\r\n    //}}AFX_DATA_MAP\r\n}\r\n\r\nBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)\r\n\t//{{AFX_MSG_MAP(CAboutDlg)\r\n\tON_WM_DESTROY()\r\n\tON_WM_SHOWWINDOW()\r\n\tON_BN_CLICKED(IDSYSINFO, OnSysinfo)\r\n\t//}}AFX_MSG_MAP\r\nEND_MESSAGE_MAP()\r\n\r\nBOOL CAboutDlg::OnInitDialog() \r\n{\r\n\tconst char *mylic =\r\n\t\t\"MIT License\\r\\n\\r\\n\"\r\n\t\t\"Copyright 2020 J.S. Obeid\\r\\n\\r\\n\"\r\n\t\t\"Permission is hereby granted, free of charge, to any person obtaining a copy\\r\\n\"\r\n\t\t\"of this software and associated documentation files(the \\\"Software\\\"), to deal\\r\\n\"\r\n\t\t\"in the Software without restriction, including without limitation the rights\\r\\n\"\r\n\t\t\"to use, copy, modify, merge, publish, distribute, sublicense, and / or sell\\r\\n\"\r\n\t\t\"copies of the Software, and to permit persons to whom the Software is\\r\\n\"\r\n\t\t\"furnished to do so, subject to the following conditions : \\r\\n\\r\\n\"\r\n\t\t\"The above copyright notice and this permission notice shall be included in\\r\\n\"\r\n\t\t\"all copies or substantial portions of the Software.\\r\\n\\r\\n\"\r\n\t\t\"THE SOFTWARE IS PROVIDED \\\"AS IS\\\", WITHOUT WARRANTY OF ANY KIND,\\r\\n\"\r\n\t\t\"EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\\r\\n\"\r\n\t\t\"OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND \\r\\n\"\r\n\t\t\"NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\\r\\n\"\r\n\t\t\"HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\\r\\n\"\r\n\t\t\"WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\\r\\n\"\r\n\t\t\"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\\r\\n\"\r\n\t\t\"DEALINGS IN THE SOFTWARE.\";\r\n\tCDialog::OnInitDialog();\r\n\r\n\tGetDlgItem(IDC_EDITLIC)->SetWindowTextA(mylic);\r\n\treturn TRUE;  // return TRUE unless you set the focus to a control\r\n\t              // EXCEPTION: OCX Property Pages should return FALSE\r\n}\r\n\r\nvoid CAboutDlg::OnSize(UINT nType, int cx, int cy)\r\n{\r\n\tCDialog::OnSize(nType, cx, cy);\r\n}\r\n\r\nvoid CAboutDlg::OnDestroy() \r\n{\r\n\tCDialog::OnDestroy();\r\n\tm_MyhWnd=NULL;\r\n    //CSystemTray::MinimiseToTray(this);\r\n    m_bVisible = FALSE;\r\n}\r\n\r\nvoid CAboutDlg::OnShowWindow(BOOL bShow, UINT nStatus) \r\n{\r\n\tCDialog::OnShowWindow(bShow, nStatus);\r\n    m_MyhWnd=m_hWnd;\r\n    //if (bShow) CSystemTray::MaximiseFromTray(this);\r\n}\r\n\r\nINT_PTR CAboutDlg::DoModal()\r\n{\r\n    if (m_bVisible)\r\n\t{\t\r\n\t\tBringToTop();\r\n        return IDCANCEL;\r\n\t}\r\n    m_bVisible = TRUE;\r\n\treturn CDialog::DoModal();\r\n}\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CAboutDlg message handlers\r\n\r\nvoid CAboutDlg::OnSysinfo() \r\n{\r\n\tStartSysInfo();\r\n}\r\n\r\nvoid CAboutDlg::BringToTop()\r\n{\r\n\tif (m_MyhWnd!=0) \r\n\t{\r\n\t\t::SetWindowPos(m_MyhWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);\r\n\t}\r\n}\r\n\r\nBOOL CAboutDlg::OnCommand(WPARAM wParam, LPARAM lParam) \r\n{\r\n\t// TODO: Add your specialized code here and/or call the base class\r\n\t\r\n\treturn CDialog::OnCommand(wParam, lParam);\r\n}\r\n\r\n//-----------------------------------------------------------\r\n//\r\n// StartSysInfo()\r\n// Calls MSINFO32.EXE\r\n//\r\nBOOL CAboutDlg::StartSysInfo()\r\n{\r\n\tOnInvokeMSInfo(\"msinfo32.exe\");\r\n\treturn TRUE;\r\n}\r\n//-----------start external exe functions:\r\nvoid CAboutDlg::OnInvokeMSInfo(LPSTR SomeExeNm)\r\n{\r\n\tPROCESS_INFORMATION pi;\r\n\tSTARTUPINFO si;\r\n\tZeroMemory(&si, sizeof(STARTUPINFO));\r\n\tsi.cb = sizeof(STARTUPINFO);\r\n\r\n\tif (WaitForSingleObject(m_hChildProcess, 0) != WAIT_TIMEOUT &&\r\n\t\tCreateProcess(NULL, SomeExeNm,\r\n\t\t\tNULL, NULL,\r\n\t\t\tFALSE, 0,\r\n\t\t\tNULL, NULL,\r\n\t\t\t&si, &pi))\r\n\t{\r\n\t\t// Close the old process handle\r\n\t\tCloseHandle(m_hChildProcess);\r\n\r\n\t\t// Close the thread handle (process handle will be closed in ExitInstance)\r\n\t\tCloseHandle(pi.hThread);\r\n\r\n\t\t// store child process information\r\n\t\tm_hChildProcess = pi.hProcess;\r\n\t\tm_dwChildProcessId = pi.dwProcessId;\r\n\t}\r\n\telse\r\n\t{\r\n\t\t// ActivateChildProcess() activates all top-level windows whose PID matches m_dwChildProcessId.\r\n\t\tEnumWindows((WNDENUMPROC)CAboutDlg::ActivateChildProcess,\r\n\t\t\t(LPARAM)m_dwChildProcessId);\r\n\t}\r\n\tWaitForInputIdle(m_hChildProcess, 1000);\r\n}\r\n\r\nBOOL CALLBACK CAboutDlg::CloseChildProcess(HWND hWnd, LPARAM lParam)\r\n{\r\n\tDWORD dwID;\r\n\tGetWindowThreadProcessId(hWnd, &dwID);\r\n\tif (dwID == (DWORD)lParam)\r\n\t{\r\n\t\t::PostMessage(hWnd, WM_CLOSE, 0, 0);\r\n\t}\r\n\treturn TRUE;\r\n}\r\n\r\nBOOL CALLBACK CAboutDlg::ActivateChildProcess(HWND hWnd, LPARAM lParam)\r\n{\r\n\tDWORD dwID;\r\n\tGetWindowThreadProcessId(hWnd, &dwID);\r\n\tif (dwID == (DWORD)lParam)\r\n\t{\r\n\t\t// Note: This block is adapted from CFrameWnd::ActivateFrame\r\n\t\t// and from CFrameWnd::BringToTop.\r\n\t\tint nCmdShow = -1;\r\n\t\tHWND hWndLastPop;\r\n\r\n\t\t// translate default nCmdShow (-1)\r\n\t\tif (nCmdShow == -1)\r\n\t\t{\r\n\t\t\tif (::IsIconic(hWnd))\r\n\t\t\t\tnCmdShow = SW_RESTORE;\r\n\t\t}\r\n\t\tASSERT(nCmdShow != SW_HIDE &&\r\n\t\t\tnCmdShow != SW_MINIMIZE && nCmdShow != SW_SHOWMINNOACTIVE &&\r\n\t\t\tnCmdShow != SW_SHOWNA && nCmdShow != SW_SHOWNOACTIVATE);\r\n\r\n\t\t// bring to top before showing\r\n\t\t// if no last active popup, it will return hWnd\r\n\t\thWndLastPop = ::GetLastActivePopup(hWnd);\r\n\t\t::BringWindowToTop(hWndLastPop);\r\n\r\n\t\tif (nCmdShow != -1)\r\n\t\t{\r\n\t\t\t// show the window as specified\r\n\t\t\t::ShowWindow(hWnd, nCmdShow);\r\n\r\n\t\t\t// and finally, bring to top after showing\r\n\t\t\t// if no last active popup, it will return hWnd\r\n\t\t\thWndLastPop = ::GetLastActivePopup(hWnd);\r\n\t\t\t::BringWindowToTop(hWndLastPop);\r\n\t\t}\r\n\r\n\t\t::PostMessage(hWnd, WM_SETFOCUS, 0, 0);\r\n\t}\r\n\treturn TRUE;\r\n}\r\n"
  },
  {
    "path": "src/AboutDlg.h",
    "content": "// AboutDlg.h : header file\r\n//\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// CAboutDlg dialog\r\n\r\nclass CAboutDlg : public CDialog\r\n{\r\npublic:\r\n\tCAboutDlg();\r\n\r\n\tvoid BringToTop();\r\n// Dialog Data\r\n\t//{{AFX_DATA(CAboutDlg)\r\n\tenum { IDD = IDD_ABOUTBOX };\r\n    //}}AFX_DATA\r\n\r\n\t// ClassWizard generated virtual function overrides\r\n\t//{{AFX_VIRTUAL(CAboutDlg)\r\n\tpublic:\r\n\tvirtual INT_PTR DoModal();\r\n\tprotected:\r\n\tvirtual void DoDataExchange(CDataExchange* pDX);\r\n\tvirtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);\r\n\t//}}AFX_VIRTUAL\r\n\r\n// Implementation\r\nprotected:\r\n    static BOOL m_bVisible;\r\n\tstatic HWND m_MyhWnd;\r\n\t//stuff for calling external exe's:\r\n\tHANDLE m_hChildProcess;\r\n\tDWORD m_dwChildProcessId;\r\n\tvoid OnInvokeMSInfo(LPSTR SomeExeNm);\r\n\tstatic BOOL CALLBACK CloseChildProcess(HWND hWnd, LPARAM lParam);\r\n\tstatic BOOL CALLBACK ActivateChildProcess(HWND hWnd, LPARAM lParam);\r\n\tBOOL StartSysInfo();\r\n\r\n\t//{{AFX_MSG(CAboutDlg)\r\n\tvirtual BOOL OnInitDialog();\r\n\tafx_msg void OnDestroy();\r\n\tafx_msg void OnSize(UINT nType, int cx, int cy);\r\n\tafx_msg void OnShowWindow(BOOL bShow, UINT nStatus);\r\n\tafx_msg void OnSysinfo();\r\n\t//}}AFX_MSG\r\n\tDECLARE_MESSAGE_MAP()\r\n};\r\n"
  },
  {
    "path": "src/D3dx12jo.cpp",
    "content": "#include \"stdafx.h\"\r\n#include \"D3dx12jo.h\"\r\n\r\nusing namespace DirectX; // we will be using the directxmath library\r\n\r\nD3dx12jo::D3dx12jo()\r\n{\r\n\thwnd_jo = NULL;\r\n\tFullScreen_jo = false;\r\n\tRunning = true;\r\n}\r\n\r\nbool D3dx12jo::InitD3D(HWND hwnd_tmp)\r\n{\r\n\tHRESULT hr;\r\n\r\n\t// -- Create the Device -- //\r\n\r\n\tIDXGIFactory4* dxgiFactory;\r\n\r\n\thwnd_jo = hwnd_tmp;\r\n\thr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\tIDXGIAdapter1* adapter; // adapters are the graphics card (this includes the embedded graphics on the motherboard)\r\n\r\n\tint adapterIndex = 0; // we'll start looking for directx 12  compatible graphics devices starting at index 0\r\n\r\n\tbool adapterFound = false; // set this to true when a good one was found\r\n\r\n\t\t\t\t\t\t\t   // find first hardware gpu that supports d3d 12\r\n\t\t\t\t\t\t\t   //while (dxgiFactory->EnumAdapters1(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND)\r\n\twhile (adapterIndex<3)\r\n\t{\r\n\t\tDXGI_ADAPTER_DESC1 desc;\r\n\r\n\t\tif (dxgiFactory->EnumAdapters1(adapterIndex, &adapter) == DXGI_ERROR_NOT_FOUND)\r\n\t\t{\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tadapter->GetDesc1(&desc);\r\n\r\n\t\tif (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)\r\n\t\t{\r\n\t\t\t// we dont want a software device\r\n\t\t\tadapterIndex++;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (desc.VendorId == 32902)\r\n\t\t{\r\n\t\t\t// we dont want INTEL device (id=0x8086) look up vendor id in device manager\r\n\t\t\tadapterIndex++;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (desc.VendorId == 4098)\r\n\t\t{\r\n\t\t\t// we dont want AMD device (id=0x1002) look up vendor id in device manager\r\n\t\t\tadapterIndex++;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t// we want a device that is compatible with direct3d 12 (feature level 11 or higher)\r\n\t\thr = D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr);\r\n\t\tif (SUCCEEDED(hr))\r\n\t\t{\r\n\t\t\tadapterFound = true;\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\tadapterIndex++;\r\n\t}\r\n\r\n\tif (!adapterFound)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\t// Create the device\r\n\thr = D3D12CreateDevice(\r\n\t\tadapter,\r\n\t\tD3D_FEATURE_LEVEL_11_0,\r\n\t\tIID_PPV_ARGS(&device)\r\n\t);\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\t// -- Create a direct command queue -- //\r\n\r\n\tD3D12_COMMAND_QUEUE_DESC cqDesc = {};\r\n\tcqDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;\r\n\tcqDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; // direct means the gpu can directly execute this command queue\r\n\r\n\thr = device->CreateCommandQueue(&cqDesc, IID_PPV_ARGS(&commandQueue)); // create the command queue\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\t// -- Create the Swap Chain (double/tripple buffering) -- //\r\n\r\n\tDXGI_MODE_DESC backBufferDesc = {}; // this is to describe our display mode\r\n\tbackBufferDesc.Width = 300; //Width; // buffer width\r\n\tbackBufferDesc.Height = 240; //Height; // buffer height\r\n\tbackBufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // format of the buffer (rgba 32 bits, 8 bits for each chanel)\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// describe our multi-sampling. We are not multi-sampling, so we set the count to 1 (we need at least one sample of course)\r\n\tDXGI_SAMPLE_DESC sampleDesc = {};\r\n\tsampleDesc.Count = 1; // multisample count (no multisampling, so we just put 1, since we still need 1 sample)\r\n\r\n\t\t\t\t\t\t  // Describe and create the swap chain.\r\n\tDXGI_SWAP_CHAIN_DESC swapChainDesc = {};\r\n\tswapChainDesc.BufferCount = FRAME_BUFFER_COUNT_X; // number of buffers we have\r\n\tswapChainDesc.BufferDesc = backBufferDesc; // our back buffer description\r\n\tswapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // this says the pipeline will render to this swap chain\r\n\tswapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; // dxgi will discard the buffer (data) after we call present\r\n\tswapChainDesc.OutputWindow = hwnd_jo; // handle to our window\r\n\tswapChainDesc.SampleDesc = sampleDesc; // our multi-sampling description\r\n\tswapChainDesc.Windowed = !FullScreen_jo; // set to true, then if in fullscreen must call SetFullScreenState with true for full screen to get uncapped fps\r\n\r\n\tIDXGISwapChain* tempSwapChain;\r\n\r\n\tdxgiFactory->CreateSwapChain(\r\n\t\tcommandQueue, // the queue will be flushed once the swap chain is created\r\n\t\t&swapChainDesc, // give it the swap chain description we created above\r\n\t\t&tempSwapChain // store the created swap chain in a temp IDXGISwapChain interface\r\n\t);\r\n\r\n\tswapChain = static_cast<IDXGISwapChain3*>(tempSwapChain);\r\n\r\n\tframeIndex = swapChain->GetCurrentBackBufferIndex();\r\n\r\n\t// -- Create the Back Buffers (render target views) Descriptor Heap -- //\r\n\r\n\t// describe an rtv descriptor heap and create\r\n\tD3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};\r\n\trtvHeapDesc.NumDescriptors = FRAME_BUFFER_COUNT_X; // number of descriptors for this heap.\r\n\trtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; // this heap is a render target view heap\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t   // This heap will not be directly referenced by the shaders (not shader visible), as this will store the output from the pipeline\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t   // otherwise we would set the heap's flag to D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE\r\n\trtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;\r\n\thr = device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&rtvDescriptorHeap));\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\t// get the size of a descriptor in this heap (this is a rtv heap, so only rtv descriptors should be stored in it.\r\n\t// descriptor sizes may vary from device to device, which is why there is no set size and we must ask the \r\n\t// device to give us the size. we will use this size to increment a descriptor handle offset\r\n\trtvDescriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);\r\n\r\n\t// get a handle to the first descriptor in the descriptor heap. a handle is basically a pointer,\r\n\t// but we cannot literally use it like a c++ pointer.\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());\r\n\r\n\t// Create a RTV for each buffer (double buffering is two buffers, tripple buffering is 3).\r\n\tfor (int i = 0; i < FRAME_BUFFER_COUNT_X; i++)\r\n\t{\r\n\t\t// first we get the n'th buffer in the swap chain and store it in the n'th\r\n\t\t// position of our ID3D12Resource array\r\n\t\thr = swapChain->GetBuffer(i, IID_PPV_ARGS(&renderTargets[i]));\r\n\t\tif (FAILED(hr))\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\t// the we \"create\" a render target view which binds the swap chain buffer (ID3D12Resource[n]) to the rtv handle\r\n\t\tdevice->CreateRenderTargetView(renderTargets[i], nullptr, rtvHandle);\r\n\r\n\t\t// we increment the rtv handle by the rtv descriptor size we got above\r\n\t\trtvHandle.Offset(1, rtvDescriptorSize);\r\n\t}\r\n\r\n\t// -- Create the Command Allocators -- //\r\n\r\n\tfor (int i = 0; i < FRAME_BUFFER_COUNT_X; i++)\r\n\t{\r\n\t\thr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocator[i]));\r\n\t\tif (FAILED(hr))\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\t// -- Create a Command List -- //\r\n\r\n\t// create the command list with the first allocator\r\n\thr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, commandAllocator[0], NULL, IID_PPV_ARGS(&commandList));\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\t// command lists are created in the recording state. our main loop will set it up for recording again so close it now\r\n\tcommandList->Close();\r\n\r\n\t// -- Create a Fence & Fence Event -- //\r\n\r\n\t// create the fences\r\n\tfor (int i = 0; i < FRAME_BUFFER_COUNT_X; i++)\r\n\t{\r\n\t\thr = device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence[i]));\r\n\t\tif (FAILED(hr))\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\tfenceValue[i] = 0; // set the initial fence value to 0\r\n\t}\r\n\r\n\t// create a handle to a fence event\r\n\tfenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);\r\n\tif (fenceEvent == nullptr)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\treturn true;\r\n}\r\n\r\nvoid D3dx12jo::UpdatePipeline()\r\n{\r\n\tHRESULT hr;\r\n\r\n\t// We have to wait for the gpu to finish with the command allocator before we reset it\r\n\tWaitForPreviousFrame();\r\n\r\n\t// we can only reset an allocator once the gpu is done with it\r\n\t// resetting an allocator frees the memory that the command list was stored in\r\n\thr = commandAllocator[frameIndex]->Reset();\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\tRunning = false;\r\n\t}\r\n\r\n\t// reset the command list. by resetting the command list we are putting it into\r\n\t// a recording state so we can start recording commands into the command allocator.\r\n\t// the command allocator that we reference here may have multiple command lists\r\n\t// associated with it, but only one can be recording at any time. Make sure\r\n\t// that any other command lists associated to this command allocator are in\r\n\t// the closed state (not recording).\r\n\t// Here you will pass an initial pipeline state object as the second parameter,\r\n\t// but in this tutorial we are only clearing the rtv, and do not actually need\r\n\t// anything but an initial default pipeline, which is what we get by setting\r\n\t// the second parameter to NULL\r\n\thr = commandList->Reset(commandAllocator[frameIndex], NULL);\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\tRunning = false;\r\n\t}\r\n\r\n\t// here we start recording commands into the commandList (which all the commands will be stored in the commandAllocator)\r\n\r\n\t// transition the \"frameIndex\" render target from the present state to the render target state so the command list draws to it starting from here\r\n\tcommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(renderTargets[frameIndex], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));\r\n\r\n\t// here we again get the handle to our current render target view so we can set it as the render target in the output merger stage of the pipeline\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), frameIndex, rtvDescriptorSize);\r\n\r\n\t// set the render target for the output merger stage (the output of the pipeline)\r\n\tcommandList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);\r\n\r\n\t// Clear the render target by using the ClearRenderTargetView command\r\n\tconst float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };\t//DARK BLUE\r\n\tcommandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);\r\n\r\n\t// transition the \"frameIndex\" render target from the render target state to the present state. If the debug layer is enabled, you will receive a\r\n\t// warning if present is called on the render target when it's not in the present state\r\n\tcommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(renderTargets[frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));\r\n\r\n\thr = commandList->Close();\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\tRunning = false;\r\n\t}\r\n}\r\n\r\nvoid D3dx12jo::Render()\r\n{\r\n\tHRESULT hr;\r\n\r\n\tUpdatePipeline(); // update the pipeline by sending commands to the commandqueue\r\n\r\n\t\t\t\t\t  // create an array of command lists (only one command list here)\r\n\tID3D12CommandList* ppCommandLists[] = { commandList };\r\n\r\n\t// execute the array of command lists\r\n\tcommandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);\r\n\r\n\t// this command goes in at the end of our command queue. we will know when our command queue \r\n\t// has finished because the fence value will be set to \"fenceValue\" from the GPU since the command\r\n\t// queue is being executed on the GPU\r\n\thr = commandQueue->Signal(fence[frameIndex], fenceValue[frameIndex]);\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\tRunning = false;\r\n\t}\r\n\r\n\t// present the current backbuffer\r\n\thr = swapChain->Present(0, 0);\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\tRunning = false;\r\n\t}\r\n}\r\n\r\nvoid D3dx12jo::Cleanup()\r\n{\r\n\t// wait for the gpu to finish all frames\r\n\tfor (int i = 0; i < FRAME_BUFFER_COUNT_X; ++i)\r\n\t{\r\n\t\tframeIndex = i;\r\n\t\tWaitForPreviousFrame();\r\n\t}\r\n\r\n\t// get swapchain out of full screen before exiting\r\n\tBOOL fs = false;\r\n\tif (swapChain->GetFullscreenState(&fs, NULL))\r\n\t\tswapChain->SetFullscreenState(false, NULL);\r\n\r\n\tSAFE_RELEASE(device);\r\n\tSAFE_RELEASE(swapChain);\r\n\tSAFE_RELEASE(commandQueue);\r\n\tSAFE_RELEASE(rtvDescriptorHeap);\r\n\tSAFE_RELEASE(commandList);\r\n\r\n\tfor (int i = 0; i < FRAME_BUFFER_COUNT_X; ++i)\r\n\t{\r\n\t\tSAFE_RELEASE(renderTargets[i]);\r\n\t\tSAFE_RELEASE(commandAllocator[i]);\r\n\t\tSAFE_RELEASE(fence[i]);\r\n\t};\r\n}\r\n\r\nvoid D3dx12jo::WaitForPreviousFrame()\r\n{\r\n\tHRESULT hr;\r\n\r\n\t// if the current fence value is still less than \"fenceValue\", then we know the GPU has not finished executing\r\n\t// the command queue since it has not reached the \"commandQueue->Signal(fence, fenceValue)\" command\r\n\tif (fence[frameIndex]->GetCompletedValue() < fenceValue[frameIndex])\r\n\t{\r\n\t\t// we have the fence create an event which is signaled once the fence's current value is \"fenceValue\"\r\n\t\thr = fence[frameIndex]->SetEventOnCompletion(fenceValue[frameIndex], fenceEvent);\r\n\t\tif (FAILED(hr))\r\n\t\t{\r\n\t\t\tRunning = false;\r\n\t\t}\r\n\r\n\t\t// We will wait until the fence has triggered the event that it's current value has reached \"fenceValue\". once it's value\r\n\t\t// has reached \"fenceValue\", we know the command queue has finished executing\r\n\t\tWaitForSingleObject(fenceEvent, INFINITE);\r\n\t}\r\n\r\n\t// increment fenceValue for next frame\r\n\tfenceValue[frameIndex]++;\r\n\r\n\t// swap the current rtv buffer index so we draw on the correct buffer\r\n\tframeIndex = swapChain->GetCurrentBackBufferIndex();\r\n}\r\n\r\nvoid D3dx12jo::CloseFenceHandle()\r\n{\r\n\tWaitForPreviousFrame();\r\n\tCloseHandle(fenceEvent);\r\n}"
  },
  {
    "path": "src/D3dx12jo.h",
    "content": "#pragma once\r\n\r\n#include <d3d12.h>\r\n#include <dxgi1_4.h>\r\n#include <D3Dcompiler.h>\r\n#include <DirectXMath.h>\r\n#include \"d3dx12.h\"\r\n\r\n// this will only call release if an object exists (prevents exceptions calling release on non existant objects)\r\n#define SAFE_RELEASE(p) { if ( (p) ) { (p)->Release(); (p) = 0; } }\r\n#define FRAME_BUFFER_COUNT_X  2 // number of buffers we want, 2 for double buffering, 3 for tripple buffering\r\n\r\nclass D3dx12jo \r\n{\r\npublic:\r\n\tD3dx12jo();\r\n\r\n\t// function declarations\r\n\tbool InitD3D(HWND hwnd); // initializes direct3d 12\r\n\tvoid Render(); // execute the command list\r\n\tvoid Cleanup(); // release com ojects and clean up memory\r\n\tvoid CloseFenceHandle(); //CloseHandle(fenceEvent);\r\n\r\nprotected:\r\n\tvoid UpdatePipeline(); // update the direct3d pipeline (update command lists)\r\n\tvoid WaitForPreviousFrame(); // wait until gpu is finished with command list\r\n\t\t\t\t\t\t\t\t // Handle to the window\r\n\tHWND hwnd_jo;\r\n\t// is window full screen?\r\n\tbool FullScreen_jo;\r\n\r\n\t// we will exit the program when this becomes false\r\n\tbool Running;\r\n\t// direct3d stuff\r\n\r\n\tID3D12Device* device; // direct3d device\r\n\r\n\tIDXGISwapChain3* swapChain; // swapchain used to switch between render targets\r\n\r\n\tID3D12CommandQueue* commandQueue; // container for command lists\r\n\r\n\tID3D12DescriptorHeap* rtvDescriptorHeap; // a descriptor heap to hold resources like the render targets\r\n\r\n\tID3D12Resource* renderTargets[FRAME_BUFFER_COUNT_X]; // number of render targets equal to buffer count\r\n\r\n\tID3D12CommandAllocator* commandAllocator[FRAME_BUFFER_COUNT_X]; // we want enough allocators for each buffer * number of threads (we only have one thread)\r\n\r\n\tID3D12GraphicsCommandList* commandList; // a command list we can record commands into, then execute them to render the frame\r\n\r\n\tID3D12Fence* fence[FRAME_BUFFER_COUNT_X];    // an object that is locked while our command list is being executed by the gpu. We need as many \r\n\t\t\t\t\t\t\t\t\t\t\t //as we have allocators (more if we want to know when the gpu is finished with an asset)\r\n\r\n\tHANDLE fenceEvent; // a handle to an event when our fence is unlocked by the gpu\r\n\r\n\tUINT64 fenceValue[FRAME_BUFFER_COUNT_X]; // this value is incremented each frame. each fence will have its own value\r\n\r\n\tint frameIndex; // current rtv we are on\r\n\r\n\tint rtvDescriptorSize; // size of the rtv descriptor on the device (all front and back buffers will be the same size)\r\n};\r\n\r\n"
  },
  {
    "path": "src/LICENSE.txt",
    "content": "MIT License\r\n\r\nCopyright 2020 J.S. Obeid\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the \\Software\\), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. \r\n\r\nTHE SOFTWARE IS PROVIDED \\AS IS\\, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \t\t"
  },
  {
    "path": "src/Mainfrm.cpp",
    "content": "////////////////////////////////////////////////////////////////\r\n// Main frame window implementation\r\n//\r\n\r\n#include \"stdafx.h\"\r\n#include \"TrayPwr.h\"\r\n#include \"mainfrm.h\"\r\n#include <VersionHelpers.h>\r\n\r\n// Message ID used for tray notifications\r\n#define WM_MY_TRAY_NOTIFICATION WM_USER+0\r\n#define EWX_FORCEIFHUNG      0x00000010\r\n\r\nIMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)\r\n\r\nBEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)\r\n\t//{{AFX_MSG_MAP(CMainFrame)\r\n\tON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)\r\n\tON_WM_CREATE()\r\n\tON_WM_CLOSE()\r\n\tON_COMMAND(ID_APPTP_EXIT, OnAppTpExit)\r\n\tON_COMMAND(ID_TPLOGOFF, OnTpLogOff)\r\n\tON_COMMAND(ID_TPSHUTDOWN, OnTpShutDown)\r\n\tON_COMMAND(ID_TPRESTART, OnTpRestart)\r\n\tON_COMMAND(ID_TPSTANDBY, OnTpStandBy)\r\n\tON_WM_TIMER()\r\n\tON_COMMAND(ID_TPSCREENSAVE, OnTpScreenSave)\r\n\tON_WM_ENDSESSION()\r\n\t//}}AFX_MSG_MAP\r\nEND_MESSAGE_MAP()\r\n\r\nstatic UINT BASED_CODE indicators[] = {\r\n\tID_SEPARATOR,\t\t\t\t// status line indicator\r\n};\r\n\r\nCMainFrame::CMainFrame() : m_trayIcon(IDR_TRAYICON)\r\n{\r\n\tm_bShutdown = FALSE;\r\n\tm_DblClicked = FALSE;\r\n\tm_BtnClicked = 0;\r\n\tm_nTicks = 0;\r\n\tm_nTimer = 0;\r\n}\r\n\r\nCMainFrame::~CMainFrame()\r\n{\r\n}\r\n\r\nint CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)\r\n{\r\n\tif (CFrameWnd::OnCreate(lpCreateStruct) == -1)\r\n\t\treturn -1;\r\n\r\n\tif (!m_wndStatusBar.Create(this) ||\r\n\t\t!m_wndStatusBar.SetIndicators(indicators, \r\n\t\tsizeof(indicators)/sizeof(UINT))) \r\n\t\treturn -1;\t\t // fail to create\r\n\r\n\t//assign global hwnd for d3dx12\r\n\t//JJJ SET hwnd_jo IN DXjo class = m_hWnd;\r\n\tD3dx12jo* pD3jo = new D3dx12jo();\r\n\tm_pD3jo = pD3jo;\r\n\tif (!m_pD3jo->InitD3D(m_hWnd))\r\n\t{\r\n\t\t//MessageBox(0, L\"Failed to initialize direct3d 12\", L\"Error\", MB_OK);\r\n\t\tm_pD3jo->Cleanup();\r\n\t\treturn -1;\r\n\t}\r\n\r\n\t// Set up tray icon\r\n\tm_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);\r\n\tm_iWhichIcon = 1;\r\n\tm_trayIcon.SetIcon(IDI_MYICON);\r\n\r\n\t// start timer for dx rendering and managing messages\r\n\tOnStartTimer();\r\n\r\n\treturn 0;\r\n}\r\n\r\n//////////////////\r\n// Close window. Unless we are shutting down, just hide it.\r\n//\r\nvoid CMainFrame::OnClose() \r\n{\r\n\tif (m_bShutdown)\r\n\t\tCFrameWnd::OnClose();\r\n\telse\r\n\t\tShowWindow(SW_HIDE);\r\n}\r\n\r\n//////////////////\r\n// Handle notification from tray icon: display a message.\r\n//\r\nLRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)\r\n{\r\n\r\n\tswitch (lEvent)\r\n\t{\r\n\tcase WM_LBUTTONUP: \r\n\t\t//if one click then turn monitor off:\r\n\t\tm_BtnClicked=WM_LBUTTONUP;\r\n\t\tResetTimerTicks();\r\n\t\tbreak;\r\n\tcase WM_LBUTTONDBLCLK: \r\n\t\tif (m_nTimer!=0) \r\n\t\t{\r\n\t\t\tm_DblClicked=TRUE;\r\n\t\t\tm_BtnClicked = 0;\r\n\t\t\tif (IsShiftKeyDown())\r\n\t\t\t{\r\n\t\t\t\tOnTpStandBy();\r\n\t\t\t}else{ \r\n\t\t\t\t//OnTpShutDown();\r\n\t\t\t}\r\n\t\t}\r\n\t\tbreak;\r\n\tcase WM_RBUTTONUP: \r\n\t\tm_BtnClicked=WM_RBUTTONUP;\r\n\t\tResetTimerTicks();\r\n\t\tbreak;\r\n\tcase WM_RBUTTONDBLCLK: \r\n\t\tif (m_nTimer!=0) \r\n\t\t{\r\n\t\t\tm_DblClicked=TRUE;\r\n\t\t\tif (IsShiftKeyDown())\r\n\t\t\t{\r\n\t\t\t\tOnTpLogOff();\r\n\t\t\t}else{ \r\n\t\t\t\tOnTpRestart();\r\n\t\t\t}\r\n\t\t}\r\n\t\tbreak;\r\n\t}\r\n\t// let tray icon do default stuff\r\n\treturn 0;\r\n}\r\n\r\n////////////////////////////////////////////////////////////////\r\n// Command handlers below.\r\n//\r\n\r\nvoid CMainFrame::OnAppTpExit() \r\n{\r\n\tm_bShutdown = TRUE;\t\t// really exit\r\n\t//clean up dx12:\r\n\tOnStopTimer();\r\n\tm_pD3jo->CloseFenceHandle();\r\n\tm_pD3jo->Cleanup();\r\n\t//close and exit:\r\n\tSendMessage(WM_CLOSE);\t\r\n}\r\n\r\n\r\nvoid CMainFrame::OnTpLogOff()\r\n{\r\n\tTpExitWindows(FALSE,ID_TPLOGOFF);\r\n}\r\nvoid CMainFrame::OnTpShutDown()\r\n{\r\n\tTpExitWindows(FALSE,ID_TPSHUTDOWN);\r\n}\r\nvoid CMainFrame::OnTpRestart()\r\n{\r\n\tTpExitWindows(FALSE,ID_TPRESTART);\r\n}\r\nvoid CMainFrame::OnTpStandBy()\r\n{\r\n\tTpExitWindows(FALSE,ID_TPSTANDBY);\r\n}\r\nvoid CMainFrame::OnTpScreenSave() \r\n{\r\n\t// TODO: Add your command handler code here\r\n\tm_BtnClicked=WM_TPSCREENSAVER;\r\n\tResetTimerTicks();\r\n}\r\n\r\nvoid CMainFrame::TpExitWindows(BOOL Force,int shtdn)\r\n{\r\n\r\n\tif(IsWindowsVersionOrGreater(4, 0, 0)) {\r\n        // Get the access token of the current process.  Get it\r\n        // with the privileges of querying the access token and\r\n        // adjusting its privileges.\r\n\t\tHANDLE hToken=0;\r\n\t\tLUID tLuid;\r\n\t\tTOKEN_PRIVILEGES tTokenPriv;\r\n\r\n\t\tBOOL bRes=OpenProcessToken(GetCurrentProcess(), \r\n            TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, &hToken);\r\n\t\tif (bRes==0L){\r\n\t\t\treturn; //Failed\r\n\t\t}\r\n        // Get the locally unique identifier (LUID) which\r\n        // represents the shutdown privilege.\r\n\t\tif (LookupPrivilegeValue(0L, \"SeShutdownPrivilege\", &tLuid)==0L)\r\n\t\t\treturn; //Failed\r\n\r\n        // Populate the new TOKEN_PRIVILEGES values with the LUID\r\n        // and allow your current process to shutdown the computer.\r\n\t\ttTokenPriv.PrivilegeCount=1;\r\n\t\ttTokenPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\r\n\t\ttTokenPriv.Privileges[0].Luid = tLuid;\r\n\r\n\t\tAdjustTokenPrivileges(hToken, FALSE, &tTokenPriv, sizeof(TOKEN_PRIVILEGES),\r\n\t\t\t(PTOKEN_PRIVILEGES) NULL, (PDWORD) NULL);\r\n\t} //Now we have the correct privileges, hopefully.\r\n\t\r\n\t//Perform desired windows power-down:\r\n\t\r\n\tUINT FORCE_FLAG=(Force == TRUE ? EWX_FORCEIFHUNG : 0L);\r\n\r\n\tswitch (shtdn)\r\n\t{\r\n\tcase ID_TPLOGOFF:{\r\n\t\tExitWindowsEx(FORCE_FLAG | EWX_LOGOFF, 0L);\r\n\t\t}\r\n\t\tbreak;\r\n\r\n\tcase ID_TPSHUTDOWN:{\r\n\t\tExitWindowsEx(FORCE_FLAG | EWX_SHUTDOWN | EWX_POWEROFF, 0L);\r\n\t\t}\r\n\t\tbreak;\r\n\r\n\tcase ID_TPRESTART:{\r\n\t\tExitWindowsEx(FORCE_FLAG | EWX_REBOOT, 0L);\r\n\t\t}\r\n\t\tbreak;\r\n\r\n\tcase ID_TPSTANDBY:{\r\n\t\tSetSystemPowerState(1L, 1L);\r\n\t\t}\r\n\t\tbreak;\r\n\t}\r\n\r\n}\r\n\r\nvoid CMainFrame::OnTimer(UINT_PTR nIDEvent) \r\n{\r\n\t// TODO: Add your message handler code here and/or call default\r\n\tif (m_DblClicked==FALSE) \r\n\t{\r\n\t\t\r\n\t\tm_nTicks++;\r\n\t\tif (m_nTicks>2)\r\n\t\t{\r\n\t\t\t//Some useful debugging code:\r\n\t\t\t//CString msg;\r\n\t\t\t//msg.Format(\"Hello: m_nTicks=%d\", m_nTicks);   \r\n\t\t\t//MessageBeep(0xFFFFFFFF);   // Beep\r\n\t\t\t//MessageBox(msg); \r\n\t\t\tswitch (m_BtnClicked)\r\n\t\t\t{\r\n\t\t\tcase WM_RBUTTONUP:\r\n\t\t\t\tDoMenuDropDown();\r\n\t\t\t\tm_BtnClicked = 0;\r\n\t\t\t\tbreak;\r\n\t\t\tcase WM_LBUTTONUP:\r\n\t\t\t\t//if one click then turn monitor off:\r\n\t\t\t\tif (m_nTicks>18) // but wait longer: 18x50 =900 msec.\r\n\t\t\t\t{\r\n\t\t\t\t\tif (MonitorOffSupport()==TRUE)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tSendMessage(WM_SYSCOMMAND, SC_MONITORPOWER, 2L);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse //no monitor-off support, just kick in screen saver.\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tSendMessage(WM_SYSCOMMAND, SC_SCREENSAVE, 0L);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tm_BtnClicked = 0;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tcase WM_TPSCREENSAVER:\r\n\t\t\t\tif (m_nTicks>10) // but wait longer\r\n\t\t\t\t{\r\n\t\t\t\t\tSendMessage(WM_SYSCOMMAND, SC_SCREENSAVE, 0L);\r\n\t\t\t\t\tm_BtnClicked = 0;\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\tdefault:\r\n\t\t\t\tif (m_nTicks > 100)\r\n\t\t\t\t{\r\n\t\t\t\t\t//TRACE(_T(\"OnTimer - default, %d ticks.\\n\", m_nTicks));\r\n\t\t\t\t\tm_pD3jo->Render();\r\n\t\t\t\t\tResetTimerTicks();\r\n\r\n\t\t\t\t}\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse //m_DblClicked=TRUE;\r\n\t{\r\n\t\tm_DblClicked=FALSE;\r\n\t\tm_BtnClicked = 0;\r\n\t\tResetTimerTicks();\r\n\t}\r\n\tCFrameWnd::OnTimer(nIDEvent);\r\n}\r\n\r\nvoid CMainFrame::ResetTimerTicks()\r\n{\r\n\tm_nTicks = 0;\r\n}\r\n\r\nvoid CMainFrame::OnStartTimer()\r\n{\r\n\tm_nTicks = 0;\r\n\tm_nTimer = SetTimer(1, 50, 0);\r\n}\r\n\r\nvoid CMainFrame::OnStopTimer()\r\n{\r\n\tif (m_nTimer != 0)\r\n\t{\r\n\t\tKillTimer(m_nTimer);\r\n\t\tm_nTimer = 0;\r\n\t}\r\n}\r\n\r\nvoid CMainFrame::DoMenuDropDown()\r\n{\r\n\tCMenu menu;\r\n\tif (!menu.LoadMenu(IDR_TRAYICON))\r\n\t\treturn;\r\n\tCMenu* pSubMenu = menu.GetSubMenu(0);\r\n\tif (!pSubMenu) \r\n\t\treturn;\r\n\r\n\t\t// Make first menu item the default (bold font)\r\n\t\t//::SetMenuDefaultItem(pSubMenu->m_hMenu, 0, TRUE);\r\n\r\n\t\t// Display the menu at the current mouse location. There's a \"bug\"\r\n\t\t// (Microsoft calls it a feature) in Windows 95 that requires calling\r\n\t\t// SetForegroundWindow. To find out more, search for Q135788 in MSDN.\r\n\t\t//\r\n\t\tCPoint mouse;\r\n\t\tGetCursorPos(&mouse);\r\n\t\t::SetForegroundWindow(m_hWnd);\t\r\n\t\t::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,\r\n\t\t\tm_hWnd, NULL);\r\n}\r\n\r\nBOOL CMainFrame::IsShiftKeyDown()\r\n{\r\n\treturn ((GetAsyncKeyState(VK_SHIFT) & 0x8000)!=0);\r\n}\r\n\r\n// Function MonitorOffSupport()\r\n//This function determines if the operating system supports monitor off\r\n//Returns false for NT4, true for Win95,98,2000\r\nBOOL CMainFrame::MonitorOffSupport()\r\n{\r\n\tif(IsWindowsVersionOrGreater(4, 0, 0)) {\r\n\t\tif (IsWindowsVersionOrGreater(5, 0, 0))\r\n\t\t{\r\n\t\t\treturn TRUE; // NT 5 or more\r\n\t\t}\r\n\t\treturn FALSE; // NT 4 or less\r\n\t}\r\n\treturn TRUE; //Win95,98 etc...\r\n}\r\n\r\nvoid CMainFrame::OnEndSession(BOOL bEnding) \r\n{\r\n\tCFrameWnd::OnEndSession(bEnding);\r\n\t\r\n\t// Force app to quit:\r\n\tOnAppTpExit();\r\n}\r\n"
  },
  {
    "path": "src/TrayIcon.CPP",
    "content": "////////////////////////////////////////////////////////////////\r\n// CTrayIcon adopted from Microsoft Systems Journal's CTrayIcon by Paul DiLascia.\r\n//\r\n\r\n#include \"stdafx.h\"\r\n#include \"trayicon.h\"\r\n#include <afxpriv.h>\t\t// for AfxLoadString\r\n\r\nIMPLEMENT_DYNAMIC(CTrayIcon, CCmdTarget)\r\n\r\nCTrayIcon::CTrayIcon(UINT uID)\r\n{\r\n\t// Initialize NOTIFYICONDATA\r\n\tmemset(&m_nid, 0 , sizeof(m_nid));\r\n\tm_nid.cbSize = sizeof(m_nid);\r\n\tm_nid.uID = uID;\t// never changes after construction\r\n\r\n\t// Use resource string as tip if there is one\r\n\tAfxLoadString(uID, m_nid.szTip, sizeof(m_nid.szTip));\r\n}\r\n\r\nCTrayIcon::~CTrayIcon()\r\n{\r\n\tSetIcon(0); // remove icon from system tray\r\n}\r\n\r\n//////////////////\r\n// Set notification window. It must created already.\r\n//\r\nvoid CTrayIcon::SetNotificationWnd(CWnd* pNotifyWnd, UINT uCbMsg)\r\n{\r\n\t// If the following assert fails, you're probably\r\n\t// calling me before you created your window. Oops.\r\n\tASSERT(pNotifyWnd==NULL || ::IsWindow(pNotifyWnd->GetSafeHwnd()));\r\n\tm_nid.hWnd = pNotifyWnd->GetSafeHwnd();\r\n\r\n\tASSERT(uCbMsg==0 || uCbMsg>=WM_USER);\r\n\tm_nid.uCallbackMessage = uCbMsg;\r\n}\r\n\r\n//////////////////\r\n// This is the main variant for setting the icon.\r\n// Sets both the icon and tooltip from resource ID\r\n// To remove the icon, call SetIcon(0)\r\n//\r\nBOOL CTrayIcon::SetIcon(UINT uID)\r\n{ \r\n\tHICON hicon=NULL;\r\n\tif (uID) {\r\n\t\tAfxLoadString(uID, m_nid.szTip, sizeof(m_nid.szTip));\r\n\t\t//hicon = AfxGetApp()->LoadIcon(uID);\r\n\t\thicon=(HICON) LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(uID),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);\r\n\t}\r\n\treturn SetIcon(hicon, NULL);\r\n}\r\n\r\n//////////////////\r\n// Common SetIcon for all overloads. \r\n//\r\nBOOL CTrayIcon::SetIcon(HICON hicon, LPCSTR lpTip) \r\n{\r\n\tUINT msg;\r\n\tm_nid.uFlags = 0;\r\n\r\n\t// Set the icon\r\n\tif (hicon) {\r\n\t\t// Add or replace icon in system tray\r\n\t\tmsg = m_nid.hIcon ? NIM_MODIFY : NIM_ADD;\r\n\t\tm_nid.hIcon = hicon;\r\n\t\t//m_nid.uFlags |= NIF_ICON; //NIF_ICON Or NIF_TIP Or NIF_MESSAGE\r\n\t\tm_nid.uFlags = NIF_ICON; //NIF_ICON Or NIF_TIP Or NIF_MESSAGE\r\n\t} else { // remove icon from tray\r\n\t\tif (m_nid.hIcon==NULL)\r\n\t\t\treturn TRUE;\t\t// already deleted\r\n\t\tmsg = NIM_DELETE;\r\n\t}\r\n\r\n\t// Use the tip, if any\r\n\tif (lpTip)\r\n\t\tstrcpy_s(m_nid.szTip, sizeof(m_nid.szTip), lpTip);\r\n\tif (m_nid.szTip[0])\r\n\t\tm_nid.uFlags |= NIF_TIP;\r\n\r\n\t// Use callback if any\r\n\tif (m_nid.uCallbackMessage && m_nid.hWnd)\r\n\t\tm_nid.uFlags |= NIF_MESSAGE;\r\n\r\n\t// Do it\r\n\tBOOL bRet = Shell_NotifyIcon(msg, &m_nid);\r\n\tif (msg==NIM_DELETE || !bRet)\r\n\t\tm_nid.hIcon = NULL;\t// failed\r\n\treturn bRet;\r\n}\r\n"
  },
  {
    "path": "src/TrayPwr.cpp",
    "content": "////////////////////////////////////////////////////////////////\r\n// TrayPwr Adopted from Microsoft Systems Journal's CTrayIcon by Paul DiLascia.\r\n//\r\n// All the activity takes place in MainFrm.cpp.\r\n\r\n#include \"stdafx.h\"\r\n#include \"TrayPwr.h\"\r\n#include \"mainfrm.h\"\r\n#include \"AboutDlg.h\"\r\n#include <io.h>\r\n#include <TlHelp32.h>\r\n\r\nCMyApp theApp;\r\n\r\nBEGIN_MESSAGE_MAP(CMyApp, CWinApp)\r\n\t//{{AFX_MSG_MAP(CMyApp)\r\n\tON_COMMAND(ID_APP_ABOUT, OnAppAbout)\r\n\t//}}AFX_MSG_MAP\r\nEND_MESSAGE_MAP()\r\n\r\nnamespace {\r\n\t// Return PID of first other process that has the same executable name as this process.\r\n\tDWORD FindOtherInstancePid()\r\n\t{\r\n\t\tDWORD myPid = GetCurrentProcessId();\r\n\r\n\t\tTCHAR myPath[MAX_PATH] = { 0 };\r\n\t\tif (!GetModuleFileName(NULL, myPath, _countof(myPath)))\r\n\t\t\treturn 0;\r\n\t\t// Extract executable file name only (e.g. \"TrayPwrD3.exe\")\r\n\t\tTCHAR *pName = _tcsrchr(myPath, '\\\\');\r\n\t\tLPCTSTR myExeName = pName ? pName + 1 : myPath;\r\n\r\n\t\tHANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r\n\t\tif (hsnap == INVALID_HANDLE_VALUE)\r\n\t\t\treturn 0;\r\n\r\n\t\tPROCESSENTRY32 pe = { 0 };\r\n\t\tpe.dwSize = sizeof(pe);\r\n\t\tif (Process32First(hsnap, &pe))\r\n\t\t{\r\n\t\t\tdo\r\n\t\t\t{\r\n\t\t\t\t// szExeFile holds the base exe name\r\n\t\t\t\tif (pe.th32ProcessID != myPid &&\r\n\t\t\t\t\t_tcsicmp(pe.szExeFile, myExeName) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tCloseHandle(hsnap);\r\n\t\t\t\t\treturn pe.th32ProcessID;\r\n\t\t\t\t}\r\n\t\t\t} while (Process32Next(hsnap, &pe));\r\n\t\t}\r\n\t\tCloseHandle(hsnap);\r\n\t\treturn 0;\r\n\t}\r\n\r\n\t// Terminates the process with the given PID. Returns TRUE on success.\r\n\tBOOL TerminateProcessByPid(DWORD pid, DWORD timeoutMs = 5000)\r\n\t{\r\n\t\tHANDLE hProc = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, pid);\r\n\t\tif (!hProc)\r\n\t\t\treturn FALSE;\r\n\t\tBOOL ok = TerminateProcess(hProc, 0) != FALSE;\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\tWaitForSingleObject(hProc, timeoutMs);\r\n\t\t}\r\n\t\tCloseHandle(hProc);\r\n\t\treturn ok;\r\n\t}\r\n}\r\n\r\nCMyApp::CMyApp()\r\n{\r\n\r\n}\r\n\r\nBOOL CMyApp::InitInstance()\r\n{\r\n\t// Check for another running instance of this exe\r\n\tDWORD otherPid = FindOtherInstancePid();\r\n\tif (otherPid != 0)\r\n\t{\r\n\t\tCString msg;\r\n\t\tmsg.Format(_T(\"Another instance of %s is already running (PID %u).\\n\\n\"\r\n\t\t\t\"Do you want to terminate the running instance and continue?\"),\r\n\t\t\tAfxGetAppName(), otherPid);\r\n\t\tint res = AfxMessageBox(msg, MB_YESNO | MB_ICONQUESTION);\r\n\t\tif (res == IDYES)\r\n\t\t{\r\n\t\t\tif (!TerminateProcessByPid(otherPid))\r\n\t\t\t{\r\n\t\t\t\tAfxMessageBox(_T(\"Failed to terminate the running instance. Startup will be cancelled.\"),\r\n\t\t\t\t\tMB_OK | MB_ICONERROR);\r\n\t\t\t\treturn FALSE;\r\n\t\t\t}\r\n\t\t\t// optionally wait a moment to ensure process is gone\r\n\t\t\tSleep(200);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t// user chose not to terminate the other instance -> exit\r\n\t\t\treturn FALSE;\r\n\t\t}\r\n\t}\r\n\r\n\t// Create main frame window (don't use doc/view stuff)\r\n\tm_bAboutDialogActive=FALSE;\r\n\tCMainFrame* pMainFrame = new CMainFrame;\r\n\tif (!pMainFrame->LoadFrame(IDR_MAINFRAME))\r\n\t\treturn FALSE;\r\n\tm_pMainWnd = pMainFrame;\r\n\treturn TRUE;\r\n}\r\n\r\nvoid CMyApp::OnAppAbout()\r\n{\r\n\tCAboutDlg aboutDlg; \r\n\taboutDlg.DoModal();\r\n}\r\n"
  },
  {
    "path": "src/TrayPwr.h",
    "content": "////////////////////////////////////////////////////////////////\r\n// TrayPwr Copyright 1996 Microsoft Systems Journal.\r\n// See TrayPwr.CPP for description of program.\r\n//\r\n#include \"resource.h\"\r\n#include \"D3dx12jo.h\"\r\n\r\nclass CMyApp : public CWinApp {\r\npublic:\r\n\tCMyApp();\r\n\r\n\tvirtual BOOL InitInstance();\r\n\t//{{AFX_MSG(CMyApp)\r\n\tafx_msg void OnAppAbout();\r\n\t//}}AFX_MSG\r\n\tDECLARE_MESSAGE_MAP()\r\nprotected:\r\n\r\nprivate:\r\n\tBOOL m_bAboutDialogActive;\r\n};\r\n"
  },
  {
    "path": "src/TrayPwr.rc",
    "content": "// Microsoft Visual C++ generated resource script.\r\n//\r\n#include \"resource.h\"\r\n\r\n#define APSTUDIO_READONLY_SYMBOLS\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Generated from the TEXTINCLUDE 2 resource.\r\n//\r\n#include \"afxres.h\"\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n#undef APSTUDIO_READONLY_SYMBOLS\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// English (United States) resources\r\n\r\n#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\nLANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US\r\n#pragma code_page(1252)\r\n\r\n#ifdef APSTUDIO_INVOKED\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// TEXTINCLUDE\r\n//\r\n\r\n1 TEXTINCLUDE \r\nBEGIN\r\n    \"resource.h\\0\"\r\nEND\r\n\r\n2 TEXTINCLUDE \r\nBEGIN\r\n    \"#include \"\"afxres.h\"\"\\r\\n\"\r\n    \"\\0\"\r\nEND\r\n\r\n3 TEXTINCLUDE \r\nBEGIN\r\n    \"#define _AFX_NO_SPLITTER_RESOURCES\\r\\n\"\r\n    \"#define _AFX_NO_OLE_RESOURCES\\r\\n\"\r\n    \"#define _AFX_NO_TRACKER_RESOURCES\\r\\n\"\r\n    \"#define _AFX_NO_PROPERTY_RESOURCES\\r\\n\"\r\n    \"\\r\\n\"\r\n    \"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\\r\\n\"\r\n    \"#ifdef _WIN32\\r\\n\"\r\n    \"LANGUAGE 9, 1\\r\\n\"\r\n    \"#pragma code_page(1252)\\r\\n\"\r\n    \"#endif\\r\\n\"\r\n    \"#include \"\"res\\\\app.rc2\"\"  // non-Microsoft Visual C++ edited resources\\r\\n\"\r\n    \"#include \"\"afxres.rc\"\"         // Standard components\\r\\n\"\r\n    \"#endif\\0\"\r\nEND\r\n\r\n#endif    // APSTUDIO_INVOKED\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Icon\r\n//\r\n\r\n// Icon with lowest ID value placed first to ensure application icon\r\n// remains consistent on all systems.\r\nIDR_MAINFRAME           ICON                    \"res\\\\app.ico\"\r\n\r\nIDI_MYICON              ICON                    \"res\\\\myicon.ico\"\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Menu\r\n//\r\n\r\nIDR_MAINFRAME MENU\r\nBEGIN\r\n    POPUP \"&File\"\r\n    BEGIN\r\n        MENUITEM \"&About TrayPwr...\",           ID_APP_ABOUT\r\n        MENUITEM \"E&xit\",                       ID_APP_EXIT\r\n    END\r\n    POPUP \"&View\"\r\n    BEGIN\r\n        MENUITEM \"&Status Bar\",                 ID_VIEW_STATUS_BAR\r\n    END\r\nEND\r\n\r\nIDR_TRAYICON MENU\r\nBEGIN\r\n    POPUP \"&Tray\"\r\n    BEGIN\r\n        MENUITEM \"&Help...\",                    ID_APP_ABOUT\r\n        MENUITEM \"&Log off\",                    ID_TPLOGOFF\r\n        MENUITEM \"Shut &down\",                  ID_TPSHUTDOWN\r\n        MENUITEM \"&Restart\",                    ID_TPRESTART\r\n        MENUITEM \"Stand &by\",                   ID_TPSTANDBY\r\n        MENUITEM \"&Screen Saver\",               ID_TPSCREENSAVE\r\n        MENUITEM \"E&xit\",                       ID_APPTP_EXIT\r\n    END\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Dialog\r\n//\r\n\r\nIDD_ABOUTBOX DIALOGEX 0, 0, 268, 188\r\nSTYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU\r\nCAPTION \"TrayPower D3 Help\"\r\nFONT 8, \"MS Sans Serif\", 0, 0, 0x0\r\nBEGIN\r\n    DEFPUSHBUTTON   \"&OK\",IDOK,206,64,56,15,WS_GROUP\r\n    LTEXT           \"TrayPower D3 (Keeps dGPU on/idle)\\nVersion 1.7.0.0\",IDC_STATIC,36,7,154,17,NOT WS_GROUP\r\n    LTEXT           \"Copyright  2020  J. S. Obeid\",IDC_STATIC,36,23,167,9,NOT WS_GROUP\r\n    ICON            IDR_MAINFRAME,IDC_STATIC,9,9,20,20,SS_SUNKEN\r\n    LTEXT           \"Keeps dGPU idle + sits in tray icon. Options:\",IDC_STATIC,6,34,237,9,NOT WS_GROUP\r\n    LTEXT           \"Left click: turns monitor off, and saves battery power without powering down. \",IDC_STATIC,6,42,240,9,NOT WS_GROUP\r\n    PUSHBUTTON      \"&System Info...\",IDSYSINFO,206,6,56,15,WS_GROUP\r\n    LTEXT           \"Right click: power-down menu.\\nRight double click : restarts computer.\\nShift Left double click: goes into Stand by.\\nShift Right double click: logs off. \",IDC_STATIC,6,49,141,35,NOT WS_GROUP\r\n    EDITTEXT        IDC_EDITLIC,6,84,256,100,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Version\r\n//\r\n\r\nAFX_ID_PREVIEW_ZOOMOUT VERSIONINFO\r\n FILEVERSION 1,8,0,0\r\n PRODUCTVERSION 1,8,0,0\r\n FILEFLAGSMASK 0x3fL\r\n#ifdef _DEBUG\r\n FILEFLAGS 0x1L\r\n#else\r\n FILEFLAGS 0x0L\r\n#endif\r\n FILEOS 0x4L\r\n FILETYPE 0x1L\r\n FILESUBTYPE 0x0L\r\nBEGIN\r\n    BLOCK \"StringFileInfo\"\r\n    BEGIN\r\n        BLOCK \"040904b0\"\r\n        BEGIN\r\n            VALUE \"Comments\", \"Tray Power D3\"\r\n            VALUE \"CompanyName\", \"J Obeid Software\"\r\n            VALUE \"FileDescription\", \"TrayPwrD3\"\r\n            VALUE \"FileVersion\", \"1.8.0.0\"\r\n            VALUE \"InternalName\", \"TrayPwr\"\r\n            VALUE \"LegalCopyright\", \"Copyright  2025  J. S. Obeid\"\r\n            VALUE \"OriginalFilename\", \"TrayPwr.exe\"\r\n            VALUE \"ProductName\", \"Tray Power D3\"\r\n            VALUE \"ProductVersion\", \"1.8.0.0\"\r\n        END\r\n    END\r\n    BLOCK \"VarFileInfo\"\r\n    BEGIN\r\n        VALUE \"Translation\", 0x409, 1200\r\n    END\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// DESIGNINFO\r\n//\r\n\r\n#ifdef APSTUDIO_INVOKED\r\nGUIDELINES DESIGNINFO\r\nBEGIN\r\n    IDD_ABOUTBOX, DIALOG\r\n    BEGIN\r\n        LEFTMARGIN, 6\r\n        RIGHTMARGIN, 262\r\n        TOPMARGIN, 6\r\n        BOTTOMMARGIN, 184\r\n    END\r\nEND\r\n#endif    // APSTUDIO_INVOKED\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// AFX_DIALOG_LAYOUT\r\n//\r\n\r\nIDD_ABOUTBOX AFX_DIALOG_LAYOUT\r\nBEGIN\r\n    0\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// String Table\r\n//\r\n\r\nSTRINGTABLE\r\nBEGIN\r\n    IDR_MAINFRAME           \"Tray Power\"\r\nEND\r\n\r\nSTRINGTABLE\r\nBEGIN\r\n    IDI_MYICON              \"TrayPwrD3 - monitor off\"\r\nEND\r\n\r\nSTRINGTABLE\r\nBEGIN\r\n    AFX_IDS_APP_TITLE       \"TrayPwrD3\"\r\n    AFX_IDS_IDLEMESSAGE     \"Ready\"\r\nEND\r\n\r\nSTRINGTABLE\r\nBEGIN\r\n    ID_APP_ABOUT            \"Display program information\"\r\n    ID_APP_EXIT             \"Hide window\"\r\nEND\r\n\r\nSTRINGTABLE\r\nBEGIN\r\n    ID_APPTP_EXIT           \"Quit Tray Power and remove from system tray\"\r\nEND\r\n\r\n#endif    // English (United States) resources\r\n/////////////////////////////////////////////////////////////////////////////\r\n\r\n\r\n\r\n#ifndef APSTUDIO_INVOKED\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Generated from the TEXTINCLUDE 3 resource.\r\n//\r\n#define _AFX_NO_SPLITTER_RESOURCES\r\n#define _AFX_NO_OLE_RESOURCES\r\n#define _AFX_NO_TRACKER_RESOURCES\r\n#define _AFX_NO_PROPERTY_RESOURCES\r\n\r\n#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n#ifdef _WIN32\r\nLANGUAGE 9, 1\r\n#pragma code_page(1252)\r\n#endif\r\n#include \"res\\app.rc2\"  // non-Microsoft Visual C++ edited resources\r\n#include \"afxres.rc\"         // Standard components\r\n#endif\r\n/////////////////////////////////////////////////////////////////////////////\r\n#endif    // not APSTUDIO_INVOKED\r\n\r\n"
  },
  {
    "path": "src/TrayPwr.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n# Visual Studio 14\r\nVisualStudioVersion = 14.0.25420.1\r\nMinimumVisualStudioVersion = 10.0.40219.1\r\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"TrayPwr\", \"TrayPwr.vcxproj\", \"{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|x64 = Debug|x64\r\n\t\tDebug|x86 = Debug|x86\r\n\t\tRelease|x64 = Release|x64\r\n\t\tRelease|x86 = Release|x86\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Debug|x64.ActiveCfg = Debug|x64\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Debug|x64.Build.0 = Debug|x64\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Debug|x86.ActiveCfg = Debug|Win32\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Debug|x86.Build.0 = Debug|Win32\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Release|x64.ActiveCfg = Release|x64\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Release|x64.Build.0 = Release|x64\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Release|x86.ActiveCfg = Release|Win32\r\n\t\t{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}.Release|x86.Build.0 = Release|Win32\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "src/TrayPwr.vcxproj",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project DefaultTargets=\"Build\" ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <ItemGroup Label=\"ProjectConfigurations\">\r\n    <ProjectConfiguration Include=\"Debug|Win32\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Debug|x64\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|Win32\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|x64\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n  </ItemGroup>\r\n  <PropertyGroup Label=\"Globals\">\r\n    <SccProjectName />\r\n    <SccLocalPath />\r\n    <Keyword>MFCProj</Keyword>\r\n    <ProjectGuid>{8B5413C2-0C8A-4E4F-A42E-C3AE5A763DA4}</ProjectGuid>\r\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r\n    <ProjectName>TrayPwrD3</ProjectName>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n    <UseOfMfc>Dynamic</UseOfMfc>\r\n    <CharacterSet>MultiByte</CharacterSet>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n    <UseOfMfc>Dynamic</UseOfMfc>\r\n    <CharacterSet>MultiByte</CharacterSet>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n    <UseOfMfc>Dynamic</UseOfMfc>\r\n    <CharacterSet>MultiByte</CharacterSet>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n    <UseOfMfc>Dynamic</UseOfMfc>\r\n    <CLRSupport>true</CLRSupport>\r\n    <CharacterSet>NotSet</CharacterSet>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\r\n  <ImportGroup Label=\"ExtensionSettings\">\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n    <Import Project=\"$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n    <Import Project=\"$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n    <Import Project=\"$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n    <Import Project=\"$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props\" />\r\n  </ImportGroup>\r\n  <PropertyGroup Label=\"UserMacros\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <OutDir>.\\Release\\</OutDir>\r\n    <IntDir>.\\Release\\</IntDir>\r\n    <LinkIncremental>false</LinkIncremental>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <LinkIncremental>false</LinkIncremental>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <OutDir>.\\Debug\\</OutDir>\r\n    <IntDir>.\\Debug\\</IntDir>\r\n    <LinkIncremental>true</LinkIncremental>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <LinkIncremental>true</LinkIncremental>\r\n  </PropertyGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <ClCompile>\r\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r\n      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\r\n      <StringPooling>true</StringPooling>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <Optimization>MinSpace</Optimization>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <WarningLevel>Level3</WarningLevel>\r\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <AssemblerListingLocation>.\\Release\\</AssemblerListingLocation>\r\n      <BrowseInformation>true</BrowseInformation>\r\n      <PrecompiledHeaderOutputFile>.\\Release\\TrayPwr.pch</PrecompiledHeaderOutputFile>\r\n      <PrecompiledHeader>Use</PrecompiledHeader>\r\n      <PrecompiledHeaderFile>STDAFX.H</PrecompiledHeaderFile>\r\n      <ObjectFileName>.\\Release\\</ObjectFileName>\r\n      <ProgramDataBaseFileName>.\\Release\\</ProgramDataBaseFileName>\r\n    </ClCompile>\r\n    <Midl>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <TypeLibraryName>.\\Release\\TrayPwr.tlb</TypeLibraryName>\r\n      <MkTypLibCompatible>true</MkTypLibCompatible>\r\n      <TargetEnvironment>Win32</TargetEnvironment>\r\n    </Midl>\r\n    <ResourceCompile>\r\n      <Culture>0x0409</Culture>\r\n      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n    </ResourceCompile>\r\n    <Bscmake>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <OutputFile>.\\Release\\TrayPwr.bsc</OutputFile>\r\n    </Bscmake>\r\n    <Link>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <OutputFile>.\\Release\\TrayPwr.exe</OutputFile>\r\n      <AdditionalDependencies>oldnames.lib;%(AdditionalDependencies)</AdditionalDependencies>\r\n      <StackReserveSize>10240</StackReserveSize>\r\n      <SubSystem>Windows</SubSystem>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <ClCompile>\r\n      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>\r\n      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\r\n      <StringPooling>true</StringPooling>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <Optimization>MinSpace</Optimization>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <WarningLevel>Level3</WarningLevel>\r\n      <BrowseInformation>true</BrowseInformation>\r\n      <PrecompiledHeader>Use</PrecompiledHeader>\r\n      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>\r\n      <CompileAsManaged>true</CompileAsManaged>\r\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;NO_WARN_MBCS_MFC_DEPRECATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n    </ClCompile>\r\n    <Midl>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <TypeLibraryName>.\\Release\\TrayPwr.tlb</TypeLibraryName>\r\n      <MkTypLibCompatible>true</MkTypLibCompatible>\r\n    </Midl>\r\n    <ResourceCompile>\r\n      <Culture>0x0409</Culture>\r\n      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n    </ResourceCompile>\r\n    <Bscmake>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n    </Bscmake>\r\n    <Link>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <AdditionalDependencies>d3d12.lib;dxgi.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>\r\n      <StackReserveSize>10240</StackReserveSize>\r\n      <SubSystem>Windows</SubSystem>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <ClCompile>\r\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r\n      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\r\n      <FunctionLevelLinking>false</FunctionLevelLinking>\r\n      <Optimization>Disabled</Optimization>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <WarningLevel>Level3</WarningLevel>\r\n      <MinimalRebuild>true</MinimalRebuild>\r\n      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>\r\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <AssemblerListingLocation>.\\Debug\\</AssemblerListingLocation>\r\n      <BrowseInformation>true</BrowseInformation>\r\n      <PrecompiledHeaderOutputFile>.\\Debug\\TrayPwr.pch</PrecompiledHeaderOutputFile>\r\n      <PrecompiledHeader>Use</PrecompiledHeader>\r\n      <PrecompiledHeaderFile>STDAFX.H</PrecompiledHeaderFile>\r\n      <ObjectFileName>.\\Debug\\</ObjectFileName>\r\n      <ProgramDataBaseFileName>.\\Debug\\</ProgramDataBaseFileName>\r\n    </ClCompile>\r\n    <Midl>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <TypeLibraryName>.\\Debug\\TrayPwr.tlb</TypeLibraryName>\r\n      <MkTypLibCompatible>true</MkTypLibCompatible>\r\n      <TargetEnvironment>Win32</TargetEnvironment>\r\n    </Midl>\r\n    <ResourceCompile>\r\n      <Culture>0x0409</Culture>\r\n      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n    </ResourceCompile>\r\n    <Bscmake>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <OutputFile>.\\Debug\\TrayPwr.bsc</OutputFile>\r\n    </Bscmake>\r\n    <Link>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n      <OutputFile>.\\Debug\\TrayPwr.exe</OutputFile>\r\n      <AdditionalDependencies>oldnames.lib;%(AdditionalDependencies)</AdditionalDependencies>\r\n      <StackReserveSize>10240</StackReserveSize>\r\n      <SubSystem>Windows</SubSystem>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <ClCompile>\r\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\r\n      <InlineFunctionExpansion>Default</InlineFunctionExpansion>\r\n      <FunctionLevelLinking>false</FunctionLevelLinking>\r\n      <Optimization>Disabled</Optimization>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <WarningLevel>Level3</WarningLevel>\r\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;NO_WARN_MBCS_MFC_DEPRECATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <BrowseInformation>true</BrowseInformation>\r\n      <PrecompiledHeader>Use</PrecompiledHeader>\r\n      <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>\r\n      <ShowIncludes>false</ShowIncludes>\r\n    </ClCompile>\r\n    <Midl>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <TypeLibraryName>.\\Debug\\TrayPwr.tlb</TypeLibraryName>\r\n      <MkTypLibCompatible>true</MkTypLibCompatible>\r\n    </Midl>\r\n    <ResourceCompile>\r\n      <Culture>0x0409</Culture>\r\n      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n    </ResourceCompile>\r\n    <Bscmake>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n    </Bscmake>\r\n    <Link>\r\n      <SuppressStartupBanner>true</SuppressStartupBanner>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n      <AdditionalDependencies>d3d12.lib;dxgi.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>\r\n      <StackReserveSize>10240</StackReserveSize>\r\n      <SubSystem>Windows</SubSystem>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemGroup>\r\n    <ClCompile Include=\"AboutDlg.cpp\" />\r\n    <ClCompile Include=\"D3dx12jo.cpp\" />\r\n    <ClCompile Include=\"Mainfrm.cpp\" />\r\n    <ClCompile Include=\"stdafx.cpp\">\r\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">Create</PrecompiledHeader>\r\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">Create</PrecompiledHeader>\r\n    </ClCompile>\r\n    <ClCompile Include=\"TrayIcon.CPP\" />\r\n    <ClCompile Include=\"TrayPwr.cpp\">\r\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">Use</PrecompiledHeader>\r\n    </ClCompile>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ResourceCompile Include=\"TrayPwr.rc\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ClInclude Include=\"AboutDlg.h\" />\r\n    <ClInclude Include=\"d3dx12.h\" />\r\n    <ClInclude Include=\"D3dx12jo.h\" />\r\n    <ClInclude Include=\"mainfrm.h\" />\r\n    <ClInclude Include=\"RESOURCE.H\" />\r\n    <ClInclude Include=\"stdafx.h\" />\r\n    <ClInclude Include=\"trayicon.h\" />\r\n    <ClInclude Include=\"TrayPwr.h\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <Image Include=\"res\\APP.ICO\" />\r\n    <Image Include=\"res\\MYICON.ICO\" />\r\n  </ItemGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\r\n  <ImportGroup Label=\"ExtensionTargets\">\r\n  </ImportGroup>\r\n  <ProjectExtensions>\r\n    <VisualStudio>\r\n      <UserProperties RESOURCE_FILE=\"TrayPwr.rc\" />\r\n    </VisualStudio>\r\n  </ProjectExtensions>\r\n</Project>"
  },
  {
    "path": "src/TrayPwr.vcxproj.user",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <PropertyGroup>\r\n    <RESOURCE_FILE>TrayPwr.rc</RESOURCE_FILE>\r\n    <ShowAllFiles>true</ShowAllFiles>\r\n  </PropertyGroup>\r\n</Project>"
  },
  {
    "path": "src/d3dx12.h",
    "content": "//////////////////////////////////////////////////////////////////////////////\r\n//\r\n//  Copyright (C) Microsoft Corporation.  All Rights Reserved.\r\n//\r\n//  File:       d3dx12.h\r\n//  Content:    D3DX12 utility library\r\n//\r\n//////////////////////////////////////////////////////////////////////////////\r\n\r\n#ifndef __D3DX12_H__\r\n#define __D3DX12_H__\r\n\r\n#include \"d3d12.h\"\r\n\r\n#if defined( __cplusplus )\r\n\r\nstruct CD3DX12_DEFAULT {};\r\nextern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline bool operator==(const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r)\r\n{\r\n\treturn l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY && l.Width == r.Width &&\r\n\t\tl.Height == r.Height && l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline bool operator!=(const D3D12_VIEWPORT& l, const D3D12_VIEWPORT& r)\r\n{\r\n\treturn !(l == r);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RECT : public D3D12_RECT\r\n{\r\n\tCD3DX12_RECT()\r\n\t{}\r\n\texplicit CD3DX12_RECT(const D3D12_RECT& o) :\r\n\t\tD3D12_RECT(o)\r\n\t{}\r\n\texplicit CD3DX12_RECT(\r\n\t\tLONG Left,\r\n\t\tLONG Top,\r\n\t\tLONG Right,\r\n\t\tLONG Bottom)\r\n\t{\r\n\t\tleft = Left;\r\n\t\ttop = Top;\r\n\t\tright = Right;\r\n\t\tbottom = Bottom;\r\n\t}\r\n\t~CD3DX12_RECT() {}\r\n\toperator const D3D12_RECT&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_BOX : public D3D12_BOX\r\n{\r\n\tCD3DX12_BOX()\r\n\t{}\r\n\texplicit CD3DX12_BOX(const D3D12_BOX& o) :\r\n\t\tD3D12_BOX(o)\r\n\t{}\r\n\texplicit CD3DX12_BOX(\r\n\t\tLONG Left,\r\n\t\tLONG Right)\r\n\t{\r\n\t\tleft = Left;\r\n\t\ttop = 0;\r\n\t\tfront = 0;\r\n\t\tright = Right;\r\n\t\tbottom = 1;\r\n\t\tback = 1;\r\n\t}\r\n\texplicit CD3DX12_BOX(\r\n\t\tLONG Left,\r\n\t\tLONG Top,\r\n\t\tLONG Right,\r\n\t\tLONG Bottom)\r\n\t{\r\n\t\tleft = Left;\r\n\t\ttop = Top;\r\n\t\tfront = 0;\r\n\t\tright = Right;\r\n\t\tbottom = Bottom;\r\n\t\tback = 1;\r\n\t}\r\n\texplicit CD3DX12_BOX(\r\n\t\tLONG Left,\r\n\t\tLONG Top,\r\n\t\tLONG Front,\r\n\t\tLONG Right,\r\n\t\tLONG Bottom,\r\n\t\tLONG Back)\r\n\t{\r\n\t\tleft = Left;\r\n\t\ttop = Top;\r\n\t\tfront = Front;\r\n\t\tright = Right;\r\n\t\tbottom = Bottom;\r\n\t\tback = Back;\r\n\t}\r\n\t~CD3DX12_BOX() {}\r\n\toperator const D3D12_BOX&() const { return *this; }\r\n};\r\ninline bool operator==(const D3D12_BOX& l, const D3D12_BOX& r)\r\n{\r\n\treturn l.left == r.left && l.top == r.top && l.front == r.front &&\r\n\t\tl.right == r.right && l.bottom == r.bottom && l.back == r.back;\r\n}\r\ninline bool operator!=(const D3D12_BOX& l, const D3D12_BOX& r)\r\n{\r\n\treturn !(l == r);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC\r\n{\r\n\tCD3DX12_DEPTH_STENCIL_DESC()\r\n\t{}\r\n\texplicit CD3DX12_DEPTH_STENCIL_DESC(const D3D12_DEPTH_STENCIL_DESC& o) :\r\n\t\tD3D12_DEPTH_STENCIL_DESC(o)\r\n\t{}\r\n\texplicit CD3DX12_DEPTH_STENCIL_DESC(CD3DX12_DEFAULT)\r\n\t{\r\n\t\tDepthEnable = TRUE;\r\n\t\tDepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;\r\n\t\tDepthFunc = D3D12_COMPARISON_FUNC_LESS;\r\n\t\tStencilEnable = FALSE;\r\n\t\tStencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;\r\n\t\tStencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;\r\n\t\tconst D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =\r\n\t\t{ D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };\r\n\t\tFrontFace = defaultStencilOp;\r\n\t\tBackFace = defaultStencilOp;\r\n\t}\r\n\texplicit CD3DX12_DEPTH_STENCIL_DESC(\r\n\t\tBOOL depthEnable,\r\n\t\tD3D12_DEPTH_WRITE_MASK depthWriteMask,\r\n\t\tD3D12_COMPARISON_FUNC depthFunc,\r\n\t\tBOOL stencilEnable,\r\n\t\tUINT8 stencilReadMask,\r\n\t\tUINT8 stencilWriteMask,\r\n\t\tD3D12_STENCIL_OP frontStencilFailOp,\r\n\t\tD3D12_STENCIL_OP frontStencilDepthFailOp,\r\n\t\tD3D12_STENCIL_OP frontStencilPassOp,\r\n\t\tD3D12_COMPARISON_FUNC frontStencilFunc,\r\n\t\tD3D12_STENCIL_OP backStencilFailOp,\r\n\t\tD3D12_STENCIL_OP backStencilDepthFailOp,\r\n\t\tD3D12_STENCIL_OP backStencilPassOp,\r\n\t\tD3D12_COMPARISON_FUNC backStencilFunc)\r\n\t{\r\n\t\tDepthEnable = depthEnable;\r\n\t\tDepthWriteMask = depthWriteMask;\r\n\t\tDepthFunc = depthFunc;\r\n\t\tStencilEnable = stencilEnable;\r\n\t\tStencilReadMask = stencilReadMask;\r\n\t\tStencilWriteMask = stencilWriteMask;\r\n\t\tFrontFace.StencilFailOp = frontStencilFailOp;\r\n\t\tFrontFace.StencilDepthFailOp = frontStencilDepthFailOp;\r\n\t\tFrontFace.StencilPassOp = frontStencilPassOp;\r\n\t\tFrontFace.StencilFunc = frontStencilFunc;\r\n\t\tBackFace.StencilFailOp = backStencilFailOp;\r\n\t\tBackFace.StencilDepthFailOp = backStencilDepthFailOp;\r\n\t\tBackFace.StencilPassOp = backStencilPassOp;\r\n\t\tBackFace.StencilFunc = backStencilFunc;\r\n\t}\r\n\t~CD3DX12_DEPTH_STENCIL_DESC() {}\r\n\toperator const D3D12_DEPTH_STENCIL_DESC&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC\r\n{\r\n\tCD3DX12_BLEND_DESC()\r\n\t{}\r\n\texplicit CD3DX12_BLEND_DESC(const D3D12_BLEND_DESC& o) :\r\n\t\tD3D12_BLEND_DESC(o)\r\n\t{}\r\n\texplicit CD3DX12_BLEND_DESC(CD3DX12_DEFAULT)\r\n\t{\r\n\t\tAlphaToCoverageEnable = FALSE;\r\n\t\tIndependentBlendEnable = FALSE;\r\n\t\tconst D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =\r\n\t\t{\r\n\t\t\tFALSE,FALSE,\r\n\t\t\tD3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,\r\n\t\t\tD3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,\r\n\t\t\tD3D12_LOGIC_OP_NOOP,\r\n\t\t\tD3D12_COLOR_WRITE_ENABLE_ALL,\r\n\t\t};\r\n\t\tfor (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)\r\n\t\t\tRenderTarget[i] = defaultRenderTargetBlendDesc;\r\n\t}\r\n\t~CD3DX12_BLEND_DESC() {}\r\n\toperator const D3D12_BLEND_DESC&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC\r\n{\r\n\tCD3DX12_RASTERIZER_DESC()\r\n\t{}\r\n\texplicit CD3DX12_RASTERIZER_DESC(const D3D12_RASTERIZER_DESC& o) :\r\n\t\tD3D12_RASTERIZER_DESC(o)\r\n\t{}\r\n\texplicit CD3DX12_RASTERIZER_DESC(CD3DX12_DEFAULT)\r\n\t{\r\n\t\tFillMode = D3D12_FILL_MODE_SOLID;\r\n\t\tCullMode = D3D12_CULL_MODE_BACK;\r\n\t\tFrontCounterClockwise = FALSE;\r\n\t\tDepthBias = D3D12_DEFAULT_DEPTH_BIAS;\r\n\t\tDepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;\r\n\t\tSlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;\r\n\t\tDepthClipEnable = TRUE;\r\n\t\tMultisampleEnable = FALSE;\r\n\t\tAntialiasedLineEnable = FALSE;\r\n\t\tForcedSampleCount = 0;\r\n\t\tConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;\r\n\t}\r\n\texplicit CD3DX12_RASTERIZER_DESC(\r\n\t\tD3D12_FILL_MODE fillMode,\r\n\t\tD3D12_CULL_MODE cullMode,\r\n\t\tBOOL frontCounterClockwise,\r\n\t\tINT depthBias,\r\n\t\tFLOAT depthBiasClamp,\r\n\t\tFLOAT slopeScaledDepthBias,\r\n\t\tBOOL depthClipEnable,\r\n\t\tBOOL multisampleEnable,\r\n\t\tBOOL antialiasedLineEnable,\r\n\t\tUINT forcedSampleCount,\r\n\t\tD3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster)\r\n\t{\r\n\t\tFillMode = fillMode;\r\n\t\tCullMode = cullMode;\r\n\t\tFrontCounterClockwise = frontCounterClockwise;\r\n\t\tDepthBias = depthBias;\r\n\t\tDepthBiasClamp = depthBiasClamp;\r\n\t\tSlopeScaledDepthBias = slopeScaledDepthBias;\r\n\t\tDepthClipEnable = depthClipEnable;\r\n\t\tMultisampleEnable = multisampleEnable;\r\n\t\tAntialiasedLineEnable = antialiasedLineEnable;\r\n\t\tForcedSampleCount = forcedSampleCount;\r\n\t\tConservativeRaster = conservativeRaster;\r\n\t}\r\n\t~CD3DX12_RASTERIZER_DESC() {}\r\n\toperator const D3D12_RASTERIZER_DESC&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RESOURCE_ALLOCATION_INFO : public D3D12_RESOURCE_ALLOCATION_INFO\r\n{\r\n\tCD3DX12_RESOURCE_ALLOCATION_INFO()\r\n\t{}\r\n\texplicit CD3DX12_RESOURCE_ALLOCATION_INFO(const D3D12_RESOURCE_ALLOCATION_INFO& o) :\r\n\t\tD3D12_RESOURCE_ALLOCATION_INFO(o)\r\n\t{}\r\n\tCD3DX12_RESOURCE_ALLOCATION_INFO(\r\n\t\tUINT64 size,\r\n\t\tUINT64 alignment)\r\n\t{\r\n\t\tSizeInBytes = size;\r\n\t\tAlignment = alignment;\r\n\t}\r\n\toperator const D3D12_RESOURCE_ALLOCATION_INFO&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_HEAP_PROPERTIES : public D3D12_HEAP_PROPERTIES\r\n{\r\n\tCD3DX12_HEAP_PROPERTIES()\r\n\t{}\r\n\texplicit CD3DX12_HEAP_PROPERTIES(const D3D12_HEAP_PROPERTIES &o) :\r\n\t\tD3D12_HEAP_PROPERTIES(o)\r\n\t{}\r\n\tCD3DX12_HEAP_PROPERTIES(\r\n\t\tD3D12_CPU_PAGE_PROPERTY cpuPageProperty,\r\n\t\tD3D12_MEMORY_POOL memoryPoolPreference,\r\n\t\tUINT creationNodeMask = 1,\r\n\t\tUINT nodeMask = 1)\r\n\t{\r\n\t\tType = D3D12_HEAP_TYPE_CUSTOM;\r\n\t\tCPUPageProperty = cpuPageProperty;\r\n\t\tMemoryPoolPreference = memoryPoolPreference;\r\n\t\tCreationNodeMask = creationNodeMask;\r\n\t\tVisibleNodeMask = nodeMask;\r\n\t}\r\n\texplicit CD3DX12_HEAP_PROPERTIES(\r\n\t\tD3D12_HEAP_TYPE type,\r\n\t\tUINT creationNodeMask = 1,\r\n\t\tUINT nodeMask = 1)\r\n\t{\r\n\t\tType = type;\r\n\t\tCPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;\r\n\t\tMemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;\r\n\t\tCreationNodeMask = creationNodeMask;\r\n\t\tVisibleNodeMask = nodeMask;\r\n\t}\r\n\toperator const D3D12_HEAP_PROPERTIES&() const { return *this; }\r\n\tbool IsCPUAccessible() const\r\n\t{\r\n\t\treturn Type == D3D12_HEAP_TYPE_UPLOAD || Type == D3D12_HEAP_TYPE_READBACK || (Type == D3D12_HEAP_TYPE_CUSTOM &&\r\n\t\t\t(CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE || CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));\r\n\t}\r\n};\r\ninline bool operator==(const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r)\r\n{\r\n\treturn l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty &&\r\n\t\tl.MemoryPoolPreference == r.MemoryPoolPreference &&\r\n\t\tl.CreationNodeMask == r.CreationNodeMask &&\r\n\t\tl.VisibleNodeMask == r.VisibleNodeMask;\r\n}\r\ninline bool operator!=(const D3D12_HEAP_PROPERTIES& l, const D3D12_HEAP_PROPERTIES& r)\r\n{\r\n\treturn !(l == r);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_HEAP_DESC : public D3D12_HEAP_DESC\r\n{\r\n\tCD3DX12_HEAP_DESC()\r\n\t{}\r\n\texplicit CD3DX12_HEAP_DESC(const D3D12_HEAP_DESC &o) :\r\n\t\tD3D12_HEAP_DESC(o)\r\n\t{}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tUINT64 size,\r\n\t\tD3D12_HEAP_PROPERTIES properties,\r\n\t\tUINT64 alignment = 0,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = size;\r\n\t\tProperties = properties;\r\n\t\tAlignment = alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tUINT64 size,\r\n\t\tD3D12_HEAP_TYPE type,\r\n\t\tUINT64 alignment = 0,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = size;\r\n\t\tProperties = CD3DX12_HEAP_PROPERTIES(type);\r\n\t\tAlignment = alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tUINT64 size,\r\n\t\tD3D12_CPU_PAGE_PROPERTY cpuPageProperty,\r\n\t\tD3D12_MEMORY_POOL memoryPoolPreference,\r\n\t\tUINT64 alignment = 0,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = size;\r\n\t\tProperties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);\r\n\t\tAlignment = alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tconst D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,\r\n\t\tD3D12_HEAP_PROPERTIES properties,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = resAllocInfo.SizeInBytes;\r\n\t\tProperties = properties;\r\n\t\tAlignment = resAllocInfo.Alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tconst D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,\r\n\t\tD3D12_HEAP_TYPE type,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = resAllocInfo.SizeInBytes;\r\n\t\tProperties = CD3DX12_HEAP_PROPERTIES(type);\r\n\t\tAlignment = resAllocInfo.Alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\tCD3DX12_HEAP_DESC(\r\n\t\tconst D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,\r\n\t\tD3D12_CPU_PAGE_PROPERTY cpuPageProperty,\r\n\t\tD3D12_MEMORY_POOL memoryPoolPreference,\r\n\t\tD3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE)\r\n\t{\r\n\t\tSizeInBytes = resAllocInfo.SizeInBytes;\r\n\t\tProperties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);\r\n\t\tAlignment = resAllocInfo.Alignment;\r\n\t\tFlags = flags;\r\n\t}\r\n\toperator const D3D12_HEAP_DESC&() const { return *this; }\r\n\tbool IsCPUAccessible() const\r\n\t{\r\n\t\treturn static_cast< const CD3DX12_HEAP_PROPERTIES* >(&Properties)->IsCPUAccessible();\r\n\t}\r\n};\r\ninline bool operator==(const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r)\r\n{\r\n\treturn l.SizeInBytes == r.SizeInBytes &&\r\n\t\tl.Properties == r.Properties &&\r\n\t\tl.Alignment == r.Alignment &&\r\n\t\tl.Flags == r.Flags;\r\n}\r\ninline bool operator!=(const D3D12_HEAP_DESC& l, const D3D12_HEAP_DESC& r)\r\n{\r\n\treturn !(l == r);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_CLEAR_VALUE : public D3D12_CLEAR_VALUE\r\n{\r\n\tCD3DX12_CLEAR_VALUE()\r\n\t{}\r\n\texplicit CD3DX12_CLEAR_VALUE(const D3D12_CLEAR_VALUE &o) :\r\n\t\tD3D12_CLEAR_VALUE(o)\r\n\t{}\r\n\tCD3DX12_CLEAR_VALUE(\r\n\t\tDXGI_FORMAT format,\r\n\t\tconst FLOAT color[4])\r\n\t{\r\n\t\tFormat = format;\r\n\t\tmemcpy(Color, color, sizeof(Color));\r\n\t}\r\n\tCD3DX12_CLEAR_VALUE(\r\n\t\tDXGI_FORMAT format,\r\n\t\tFLOAT depth,\r\n\t\tUINT8 stencil)\r\n\t{\r\n\t\tFormat = format;\r\n\t\t/* Use memcpy to preserve NAN values */\r\n\t\tmemcpy(&DepthStencil.Depth, &depth, sizeof(depth));\r\n\t\tDepthStencil.Stencil = stencil;\r\n\t}\r\n\toperator const D3D12_CLEAR_VALUE&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RANGE : public D3D12_RANGE\r\n{\r\n\tCD3DX12_RANGE()\r\n\t{}\r\n\texplicit CD3DX12_RANGE(const D3D12_RANGE &o) :\r\n\t\tD3D12_RANGE(o)\r\n\t{}\r\n\tCD3DX12_RANGE(\r\n\t\tSIZE_T begin,\r\n\t\tSIZE_T end)\r\n\t{\r\n\t\tBegin = begin;\r\n\t\tEnd = end;\r\n\t}\r\n\toperator const D3D12_RANGE&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_TILED_RESOURCE_COORDINATE : public D3D12_TILED_RESOURCE_COORDINATE\r\n{\r\n\tCD3DX12_TILED_RESOURCE_COORDINATE()\r\n\t{}\r\n\texplicit CD3DX12_TILED_RESOURCE_COORDINATE(const D3D12_TILED_RESOURCE_COORDINATE &o) :\r\n\t\tD3D12_TILED_RESOURCE_COORDINATE(o)\r\n\t{}\r\n\tCD3DX12_TILED_RESOURCE_COORDINATE(\r\n\t\tUINT x,\r\n\t\tUINT y,\r\n\t\tUINT z,\r\n\t\tUINT subresource)\r\n\t{\r\n\t\tX = x;\r\n\t\tY = y;\r\n\t\tZ = z;\r\n\t\tSubresource = subresource;\r\n\t}\r\n\toperator const D3D12_TILED_RESOURCE_COORDINATE&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_TILE_REGION_SIZE : public D3D12_TILE_REGION_SIZE\r\n{\r\n\tCD3DX12_TILE_REGION_SIZE()\r\n\t{}\r\n\texplicit CD3DX12_TILE_REGION_SIZE(const D3D12_TILE_REGION_SIZE &o) :\r\n\t\tD3D12_TILE_REGION_SIZE(o)\r\n\t{}\r\n\tCD3DX12_TILE_REGION_SIZE(\r\n\t\tUINT numTiles,\r\n\t\tBOOL useBox,\r\n\t\tUINT width,\r\n\t\tUINT16 height,\r\n\t\tUINT16 depth)\r\n\t{\r\n\t\tNumTiles = numTiles;\r\n\t\tUseBox = useBox;\r\n\t\tWidth = width;\r\n\t\tHeight = height;\r\n\t\tDepth = depth;\r\n\t}\r\n\toperator const D3D12_TILE_REGION_SIZE&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_SUBRESOURCE_TILING : public D3D12_SUBRESOURCE_TILING\r\n{\r\n\tCD3DX12_SUBRESOURCE_TILING()\r\n\t{}\r\n\texplicit CD3DX12_SUBRESOURCE_TILING(const D3D12_SUBRESOURCE_TILING &o) :\r\n\t\tD3D12_SUBRESOURCE_TILING(o)\r\n\t{}\r\n\tCD3DX12_SUBRESOURCE_TILING(\r\n\t\tUINT widthInTiles,\r\n\t\tUINT16 heightInTiles,\r\n\t\tUINT16 depthInTiles,\r\n\t\tUINT startTileIndexInOverallResource)\r\n\t{\r\n\t\tWidthInTiles = widthInTiles;\r\n\t\tHeightInTiles = heightInTiles;\r\n\t\tDepthInTiles = depthInTiles;\r\n\t\tStartTileIndexInOverallResource = startTileIndexInOverallResource;\r\n\t}\r\n\toperator const D3D12_SUBRESOURCE_TILING&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_TILE_SHAPE : public D3D12_TILE_SHAPE\r\n{\r\n\tCD3DX12_TILE_SHAPE()\r\n\t{}\r\n\texplicit CD3DX12_TILE_SHAPE(const D3D12_TILE_SHAPE &o) :\r\n\t\tD3D12_TILE_SHAPE(o)\r\n\t{}\r\n\tCD3DX12_TILE_SHAPE(\r\n\t\tUINT widthInTexels,\r\n\t\tUINT heightInTexels,\r\n\t\tUINT depthInTexels)\r\n\t{\r\n\t\tWidthInTexels = widthInTexels;\r\n\t\tHeightInTexels = heightInTexels;\r\n\t\tDepthInTexels = depthInTexels;\r\n\t}\r\n\toperator const D3D12_TILE_SHAPE&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER\r\n{\r\n\tCD3DX12_RESOURCE_BARRIER()\r\n\t{}\r\n\texplicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o) :\r\n\t\tD3D12_RESOURCE_BARRIER(o)\r\n\t{}\r\n\tstatic inline CD3DX12_RESOURCE_BARRIER Transition(\r\n\t\t_In_ ID3D12Resource* pResource,\r\n\t\tD3D12_RESOURCE_STATES stateBefore,\r\n\t\tD3D12_RESOURCE_STATES stateAfter,\r\n\t\tUINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,\r\n\t\tD3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE)\r\n\t{\r\n\t\tCD3DX12_RESOURCE_BARRIER result;\r\n\t\tZeroMemory(&result, sizeof(result));\r\n\t\tD3D12_RESOURCE_BARRIER &barrier = result;\r\n\t\tresult.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;\r\n\t\tresult.Flags = flags;\r\n\t\tbarrier.Transition.pResource = pResource;\r\n\t\tbarrier.Transition.StateBefore = stateBefore;\r\n\t\tbarrier.Transition.StateAfter = stateAfter;\r\n\t\tbarrier.Transition.Subresource = subresource;\r\n\t\treturn result;\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_BARRIER Aliasing(\r\n\t\t_In_ ID3D12Resource* pResourceBefore,\r\n\t\t_In_ ID3D12Resource* pResourceAfter)\r\n\t{\r\n\t\tCD3DX12_RESOURCE_BARRIER result;\r\n\t\tZeroMemory(&result, sizeof(result));\r\n\t\tD3D12_RESOURCE_BARRIER &barrier = result;\r\n\t\tresult.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;\r\n\t\tbarrier.Aliasing.pResourceBefore = pResourceBefore;\r\n\t\tbarrier.Aliasing.pResourceAfter = pResourceAfter;\r\n\t\treturn result;\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_BARRIER UAV(\r\n\t\t_In_ ID3D12Resource* pResource)\r\n\t{\r\n\t\tCD3DX12_RESOURCE_BARRIER result;\r\n\t\tZeroMemory(&result, sizeof(result));\r\n\t\tD3D12_RESOURCE_BARRIER &barrier = result;\r\n\t\tresult.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;\r\n\t\tbarrier.UAV.pResource = pResource;\r\n\t\treturn result;\r\n\t}\r\n\toperator const D3D12_RESOURCE_BARRIER&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_PACKED_MIP_INFO : public D3D12_PACKED_MIP_INFO\r\n{\r\n\tCD3DX12_PACKED_MIP_INFO()\r\n\t{}\r\n\texplicit CD3DX12_PACKED_MIP_INFO(const D3D12_PACKED_MIP_INFO &o) :\r\n\t\tD3D12_PACKED_MIP_INFO(o)\r\n\t{}\r\n\tCD3DX12_PACKED_MIP_INFO(\r\n\t\tUINT8 numStandardMips,\r\n\t\tUINT8 numPackedMips,\r\n\t\tUINT numTilesForPackedMips,\r\n\t\tUINT startTileIndexInOverallResource)\r\n\t{\r\n\t\tNumStandardMips = numStandardMips;\r\n\t\tNumPackedMips = numPackedMips;\r\n\t\tNumTilesForPackedMips = numTilesForPackedMips;\r\n\t\tStartTileIndexInOverallResource = startTileIndexInOverallResource;\r\n\t}\r\n\toperator const D3D12_PACKED_MIP_INFO&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_SUBRESOURCE_FOOTPRINT : public D3D12_SUBRESOURCE_FOOTPRINT\r\n{\r\n\tCD3DX12_SUBRESOURCE_FOOTPRINT()\r\n\t{}\r\n\texplicit CD3DX12_SUBRESOURCE_FOOTPRINT(const D3D12_SUBRESOURCE_FOOTPRINT &o) :\r\n\t\tD3D12_SUBRESOURCE_FOOTPRINT(o)\r\n\t{}\r\n\tCD3DX12_SUBRESOURCE_FOOTPRINT(\r\n\t\tDXGI_FORMAT format,\r\n\t\tUINT width,\r\n\t\tUINT height,\r\n\t\tUINT depth,\r\n\t\tUINT rowPitch)\r\n\t{\r\n\t\tFormat = format;\r\n\t\tWidth = width;\r\n\t\tHeight = height;\r\n\t\tDepth = depth;\r\n\t\tRowPitch = rowPitch;\r\n\t}\r\n\texplicit CD3DX12_SUBRESOURCE_FOOTPRINT(\r\n\t\tconst D3D12_RESOURCE_DESC& resDesc,\r\n\t\tUINT rowPitch)\r\n\t{\r\n\t\tFormat = resDesc.Format;\r\n\t\tWidth = UINT(resDesc.Width);\r\n\t\tHeight = resDesc.Height;\r\n\t\tDepth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? resDesc.DepthOrArraySize : 1);\r\n\t\tRowPitch = rowPitch;\r\n\t}\r\n\toperator const D3D12_SUBRESOURCE_FOOTPRINT&() const { return *this; }\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION\r\n{\r\n\tCD3DX12_TEXTURE_COPY_LOCATION()\r\n\t{}\r\n\texplicit CD3DX12_TEXTURE_COPY_LOCATION(const D3D12_TEXTURE_COPY_LOCATION &o) :\r\n\t\tD3D12_TEXTURE_COPY_LOCATION(o)\r\n\t{}\r\n\tCD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes) { pResource = pRes; }\r\n\tCD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, D3D12_PLACED_SUBRESOURCE_FOOTPRINT const& Footprint)\r\n\t{\r\n\t\tpResource = pRes;\r\n\t\tType = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;\r\n\t\tPlacedFootprint = Footprint;\r\n\t}\r\n\tCD3DX12_TEXTURE_COPY_LOCATION(ID3D12Resource* pRes, UINT Sub)\r\n\t{\r\n\t\tpResource = pRes;\r\n\t\tType = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;\r\n\t\tSubresourceIndex = Sub;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE\r\n{\r\n\tCD3DX12_DESCRIPTOR_RANGE() { }\r\n\texplicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE &o) :\r\n\t\tD3D12_DESCRIPTOR_RANGE(o)\r\n\t{}\r\n\tCD3DX12_DESCRIPTOR_RANGE(\r\n\t\tD3D12_DESCRIPTOR_RANGE_TYPE rangeType,\r\n\t\tUINT numDescriptors,\r\n\t\tUINT baseShaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tUINT offsetInDescriptorsFromTableStart =\r\n\t\tD3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)\r\n\t{\r\n\t\tInit(rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);\r\n\t}\r\n\r\n\tinline void Init(\r\n\t\tD3D12_DESCRIPTOR_RANGE_TYPE rangeType,\r\n\t\tUINT numDescriptors,\r\n\t\tUINT baseShaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tUINT offsetInDescriptorsFromTableStart =\r\n\t\tD3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)\r\n\t{\r\n\t\tInit(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace, offsetInDescriptorsFromTableStart);\r\n\t}\r\n\r\n\tstatic inline void Init(\r\n\t\t_Out_ D3D12_DESCRIPTOR_RANGE &range,\r\n\t\tD3D12_DESCRIPTOR_RANGE_TYPE rangeType,\r\n\t\tUINT numDescriptors,\r\n\t\tUINT baseShaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tUINT offsetInDescriptorsFromTableStart =\r\n\t\tD3D12_DESCRIPTOR_RANGE_OFFSET_APPEND)\r\n\t{\r\n\t\trange.RangeType = rangeType;\r\n\t\trange.NumDescriptors = numDescriptors;\r\n\t\trange.BaseShaderRegister = baseShaderRegister;\r\n\t\trange.RegisterSpace = registerSpace;\r\n\t\trange.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE\r\n{\r\n\tCD3DX12_ROOT_DESCRIPTOR_TABLE() {}\r\n\texplicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE &o) :\r\n\t\tD3D12_ROOT_DESCRIPTOR_TABLE(o)\r\n\t{}\r\n\tCD3DX12_ROOT_DESCRIPTOR_TABLE(\r\n\t\tUINT numDescriptorRanges,\r\n\t\t_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)\r\n\t{\r\n\t\tInit(numDescriptorRanges, _pDescriptorRanges);\r\n\t}\r\n\r\n\tinline void Init(\r\n\t\tUINT numDescriptorRanges,\r\n\t\t_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)\r\n\t{\r\n\t\tInit(*this, numDescriptorRanges, _pDescriptorRanges);\r\n\t}\r\n\r\n\tstatic inline void Init(\r\n\t\t_Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,\r\n\t\tUINT numDescriptorRanges,\r\n\t\t_In_reads_opt_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* _pDescriptorRanges)\r\n\t{\r\n\t\trootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;\r\n\t\trootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS\r\n{\r\n\tCD3DX12_ROOT_CONSTANTS() {}\r\n\texplicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS &o) :\r\n\t\tD3D12_ROOT_CONSTANTS(o)\r\n\t{}\r\n\tCD3DX12_ROOT_CONSTANTS(\r\n\t\tUINT num32BitValues,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(num32BitValues, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tinline void Init(\r\n\t\tUINT num32BitValues,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(*this, num32BitValues, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tstatic inline void Init(\r\n\t\t_Out_ D3D12_ROOT_CONSTANTS &rootConstants,\r\n\t\tUINT num32BitValues,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\trootConstants.Num32BitValues = num32BitValues;\r\n\t\trootConstants.ShaderRegister = shaderRegister;\r\n\t\trootConstants.RegisterSpace = registerSpace;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR\r\n{\r\n\tCD3DX12_ROOT_DESCRIPTOR() {}\r\n\texplicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR &o) :\r\n\t\tD3D12_ROOT_DESCRIPTOR(o)\r\n\t{}\r\n\tCD3DX12_ROOT_DESCRIPTOR(\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tinline void Init(\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(*this, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tstatic inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table, UINT shaderRegister, UINT registerSpace = 0)\r\n\t{\r\n\t\ttable.ShaderRegister = shaderRegister;\r\n\t\ttable.RegisterSpace = registerSpace;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER\r\n{\r\n\tCD3DX12_ROOT_PARAMETER() {}\r\n\texplicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER &o) :\r\n\t\tD3D12_ROOT_PARAMETER(o)\r\n\t{}\r\n\r\n\tstatic inline void InitAsDescriptorTable(\r\n\t\t_Out_ D3D12_ROOT_PARAMETER &rootParam,\r\n\t\tUINT numDescriptorRanges,\r\n\t\t_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\trootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;\r\n\t\trootParam.ShaderVisibility = visibility;\r\n\t\tCD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);\r\n\t}\r\n\r\n\tstatic inline void InitAsConstants(\r\n\t\t_Out_ D3D12_ROOT_PARAMETER &rootParam,\r\n\t\tUINT num32BitValues,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\trootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;\r\n\t\trootParam.ShaderVisibility = visibility;\r\n\t\tCD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tstatic inline void InitAsConstantBufferView(\r\n\t\t_Out_ D3D12_ROOT_PARAMETER &rootParam,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\trootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;\r\n\t\trootParam.ShaderVisibility = visibility;\r\n\t\tCD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tstatic inline void InitAsShaderResourceView(\r\n\t\t_Out_ D3D12_ROOT_PARAMETER &rootParam,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\trootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;\r\n\t\trootParam.ShaderVisibility = visibility;\r\n\t\tCD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tstatic inline void InitAsUnorderedAccessView(\r\n\t\t_Out_ D3D12_ROOT_PARAMETER &rootParam,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\trootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;\r\n\t\trootParam.ShaderVisibility = visibility;\r\n\t\tCD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister, registerSpace);\r\n\t}\r\n\r\n\tinline void InitAsDescriptorTable(\r\n\t\tUINT numDescriptorRanges,\r\n\t\t_In_reads_(numDescriptorRanges) const D3D12_DESCRIPTOR_RANGE* pDescriptorRanges,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\tInitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges, visibility);\r\n\t}\r\n\r\n\tinline void InitAsConstants(\r\n\t\tUINT num32BitValues,\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\tInitAsConstants(*this, num32BitValues, shaderRegister, registerSpace, visibility);\r\n\t}\r\n\r\n\tinline void InitAsConstantBufferView(\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\tInitAsConstantBufferView(*this, shaderRegister, registerSpace, visibility);\r\n\t}\r\n\r\n\tinline void InitAsShaderResourceView(\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\tInitAsShaderResourceView(*this, shaderRegister, registerSpace, visibility);\r\n\t}\r\n\r\n\tinline void InitAsUnorderedAccessView(\r\n\t\tUINT shaderRegister,\r\n\t\tUINT registerSpace = 0,\r\n\t\tD3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL)\r\n\t{\r\n\t\tInitAsUnorderedAccessView(*this, shaderRegister, registerSpace, visibility);\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC\r\n{\r\n\tCD3DX12_STATIC_SAMPLER_DESC() {}\r\n\texplicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o) :\r\n\t\tD3D12_STATIC_SAMPLER_DESC(o)\r\n\t{}\r\n\tCD3DX12_STATIC_SAMPLER_DESC(\r\n\t\tUINT shaderRegister,\r\n\t\tD3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tFLOAT mipLODBias = 0,\r\n\t\tUINT maxAnisotropy = 16,\r\n\t\tD3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,\r\n\t\tD3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,\r\n\t\tFLOAT minLOD = 0.f,\r\n\t\tFLOAT maxLOD = D3D12_FLOAT32_MAX,\r\n\t\tD3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(\r\n\t\t\tshaderRegister,\r\n\t\t\tfilter,\r\n\t\t\taddressU,\r\n\t\t\taddressV,\r\n\t\t\taddressW,\r\n\t\t\tmipLODBias,\r\n\t\t\tmaxAnisotropy,\r\n\t\t\tcomparisonFunc,\r\n\t\t\tborderColor,\r\n\t\t\tminLOD,\r\n\t\t\tmaxLOD,\r\n\t\t\tshaderVisibility,\r\n\t\t\tregisterSpace);\r\n\t}\r\n\r\n\tstatic inline void Init(\r\n\t\t_Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc,\r\n\t\tUINT shaderRegister,\r\n\t\tD3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tFLOAT mipLODBias = 0,\r\n\t\tUINT maxAnisotropy = 16,\r\n\t\tD3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,\r\n\t\tD3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,\r\n\t\tFLOAT minLOD = 0.f,\r\n\t\tFLOAT maxLOD = D3D12_FLOAT32_MAX,\r\n\t\tD3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tsamplerDesc.ShaderRegister = shaderRegister;\r\n\t\tsamplerDesc.Filter = filter;\r\n\t\tsamplerDesc.AddressU = addressU;\r\n\t\tsamplerDesc.AddressV = addressV;\r\n\t\tsamplerDesc.AddressW = addressW;\r\n\t\tsamplerDesc.MipLODBias = mipLODBias;\r\n\t\tsamplerDesc.MaxAnisotropy = maxAnisotropy;\r\n\t\tsamplerDesc.ComparisonFunc = comparisonFunc;\r\n\t\tsamplerDesc.BorderColor = borderColor;\r\n\t\tsamplerDesc.MinLOD = minLOD;\r\n\t\tsamplerDesc.MaxLOD = maxLOD;\r\n\t\tsamplerDesc.ShaderVisibility = shaderVisibility;\r\n\t\tsamplerDesc.RegisterSpace = registerSpace;\r\n\t}\r\n\tinline void Init(\r\n\t\tUINT shaderRegister,\r\n\t\tD3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tD3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,\r\n\t\tFLOAT mipLODBias = 0,\r\n\t\tUINT maxAnisotropy = 16,\r\n\t\tD3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,\r\n\t\tD3D12_STATIC_BORDER_COLOR borderColor = D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,\r\n\t\tFLOAT minLOD = 0.f,\r\n\t\tFLOAT maxLOD = D3D12_FLOAT32_MAX,\r\n\t\tD3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,\r\n\t\tUINT registerSpace = 0)\r\n\t{\r\n\t\tInit(\r\n\t\t\t*this,\r\n\t\t\tshaderRegister,\r\n\t\t\tfilter,\r\n\t\t\taddressU,\r\n\t\t\taddressV,\r\n\t\t\taddressW,\r\n\t\t\tmipLODBias,\r\n\t\t\tmaxAnisotropy,\r\n\t\t\tcomparisonFunc,\r\n\t\t\tborderColor,\r\n\t\t\tminLOD,\r\n\t\t\tmaxLOD,\r\n\t\t\tshaderVisibility,\r\n\t\t\tregisterSpace);\r\n\t}\r\n\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC\r\n{\r\n\tCD3DX12_ROOT_SIGNATURE_DESC() {}\r\n\texplicit CD3DX12_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o) :\r\n\t\tD3D12_ROOT_SIGNATURE_DESC(o)\r\n\t{}\r\n\tCD3DX12_ROOT_SIGNATURE_DESC(\r\n\t\tUINT numParameters,\r\n\t\t_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,\r\n\t\tUINT numStaticSamplers = 0,\r\n\t\t_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,\r\n\t\tD3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)\r\n\t{\r\n\t\tInit(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);\r\n\t}\r\n\tCD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT)\r\n\t{\r\n\t\tInit(0, NULL, 0, NULL, D3D12_ROOT_SIGNATURE_FLAG_NONE);\r\n\t}\r\n\r\n\tinline void Init(\r\n\t\tUINT numParameters,\r\n\t\t_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,\r\n\t\tUINT numStaticSamplers = 0,\r\n\t\t_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,\r\n\t\tD3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)\r\n\t{\r\n\t\tInit(*this, numParameters, _pParameters, numStaticSamplers, _pStaticSamplers, flags);\r\n\t}\r\n\r\n\tstatic inline void Init(\r\n\t\t_Out_ D3D12_ROOT_SIGNATURE_DESC &desc,\r\n\t\tUINT numParameters,\r\n\t\t_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER* _pParameters,\r\n\t\tUINT numStaticSamplers = 0,\r\n\t\t_In_reads_opt_(numStaticSamplers) const D3D12_STATIC_SAMPLER_DESC* _pStaticSamplers = NULL,\r\n\t\tD3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE)\r\n\t{\r\n\t\tdesc.NumParameters = numParameters;\r\n\t\tdesc.pParameters = _pParameters;\r\n\t\tdesc.NumStaticSamplers = numStaticSamplers;\r\n\t\tdesc.pStaticSamplers = _pStaticSamplers;\r\n\t\tdesc.Flags = flags;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE\r\n{\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE() {}\r\n\texplicit CD3DX12_CPU_DESCRIPTOR_HANDLE(const D3D12_CPU_DESCRIPTOR_HANDLE &o) :\r\n\t\tD3D12_CPU_DESCRIPTOR_HANDLE(o)\r\n\t{}\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(other, offsetScaledByIncrementSize);\r\n\t}\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);\r\n\t}\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tptr += offsetInDescriptors * descriptorIncrementSize;\r\n\t\treturn *this;\r\n\t}\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tptr += offsetScaledByIncrementSize;\r\n\t\treturn *this;\r\n\t}\r\n\tbool operator==(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other)\r\n\t{\r\n\t\treturn (ptr == other.ptr);\r\n\t}\r\n\tbool operator!=(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE& other)\r\n\t{\r\n\t\treturn (ptr != other.ptr);\r\n\t}\r\n\tCD3DX12_CPU_DESCRIPTOR_HANDLE &operator=(const D3D12_CPU_DESCRIPTOR_HANDLE &other)\r\n\t{\r\n\t\tptr = other.ptr;\r\n\t\treturn *this;\r\n\t}\r\n\r\n\tinline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(*this, base, offsetScaledByIncrementSize);\r\n\t}\r\n\r\n\tinline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);\r\n\t}\r\n\r\n\tstatic inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\thandle.ptr = base.ptr + offsetScaledByIncrementSize;\r\n\t}\r\n\r\n\tstatic inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\thandle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE\r\n{\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE() {}\r\n\texplicit CD3DX12_GPU_DESCRIPTOR_HANDLE(const D3D12_GPU_DESCRIPTOR_HANDLE &o) :\r\n\t\tD3D12_GPU_DESCRIPTOR_HANDLE(o)\r\n\t{}\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(other, offsetScaledByIncrementSize);\r\n\t}\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);\r\n\t}\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tptr += offsetInDescriptors * descriptorIncrementSize;\r\n\t\treturn *this;\r\n\t}\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE& Offset(INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tptr += offsetScaledByIncrementSize;\r\n\t\treturn *this;\r\n\t}\r\n\tinline bool operator==(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other)\r\n\t{\r\n\t\treturn (ptr == other.ptr);\r\n\t}\r\n\tinline bool operator!=(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE& other)\r\n\t{\r\n\t\treturn (ptr != other.ptr);\r\n\t}\r\n\tCD3DX12_GPU_DESCRIPTOR_HANDLE &operator=(const D3D12_GPU_DESCRIPTOR_HANDLE &other)\r\n\t{\r\n\t\tptr = other.ptr;\r\n\t\treturn *this;\r\n\t}\r\n\r\n\tinline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(*this, base, offsetScaledByIncrementSize);\r\n\t}\r\n\r\n\tinline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\tInitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);\r\n\t}\r\n\r\n\tstatic inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetScaledByIncrementSize)\r\n\t{\r\n\t\thandle.ptr = base.ptr + offsetScaledByIncrementSize;\r\n\t}\r\n\r\n\tstatic inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle, _In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base, INT offsetInDescriptors, UINT descriptorIncrementSize)\r\n\t{\r\n\t\thandle.ptr = base.ptr + offsetInDescriptors * descriptorIncrementSize;\r\n\t}\r\n};\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline UINT D3D12CalcSubresource(UINT MipSlice, UINT ArraySlice, UINT PlaneSlice, UINT MipLevels, UINT ArraySize)\r\n{\r\n\treturn MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\ntemplate <typename T, typename U, typename V>\r\ninline void D3D12DecomposeSubresource(UINT Subresource, UINT MipLevels, UINT ArraySize, _Out_ T& MipSlice, _Out_ U& ArraySlice, _Out_ V& PlaneSlice)\r\n{\r\n\tMipSlice = static_cast<T>(Subresource % MipLevels);\r\n\tArraySlice = static_cast<U>((Subresource / MipLevels) % ArraySize);\r\n\tPlaneSlice = static_cast<V>(Subresource / (MipLevels * ArraySize));\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline UINT8 D3D12GetFormatPlaneCount(\r\n\t_In_ ID3D12Device* pDevice,\r\n\tDXGI_FORMAT Format\r\n\t)\r\n{\r\n\tD3D12_FEATURE_DATA_FORMAT_INFO formatInfo = { Format };\r\n\tif (FAILED(pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, &formatInfo, sizeof(formatInfo))))\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\treturn formatInfo.PlaneCount;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\nstruct CD3DX12_RESOURCE_DESC : public D3D12_RESOURCE_DESC\r\n{\r\n\tCD3DX12_RESOURCE_DESC()\r\n\t{}\r\n\texplicit CD3DX12_RESOURCE_DESC(const D3D12_RESOURCE_DESC& o) :\r\n\t\tD3D12_RESOURCE_DESC(o)\r\n\t{}\r\n\tCD3DX12_RESOURCE_DESC(\r\n\t\tD3D12_RESOURCE_DIMENSION dimension,\r\n\t\tUINT64 alignment,\r\n\t\tUINT64 width,\r\n\t\tUINT height,\r\n\t\tUINT16 depthOrArraySize,\r\n\t\tUINT16 mipLevels,\r\n\t\tDXGI_FORMAT format,\r\n\t\tUINT sampleCount,\r\n\t\tUINT sampleQuality,\r\n\t\tD3D12_TEXTURE_LAYOUT layout,\r\n\t\tD3D12_RESOURCE_FLAGS flags)\r\n\t{\r\n\t\tDimension = dimension;\r\n\t\tAlignment = alignment;\r\n\t\tWidth = width;\r\n\t\tHeight = height;\r\n\t\tDepthOrArraySize = depthOrArraySize;\r\n\t\tMipLevels = mipLevels;\r\n\t\tFormat = format;\r\n\t\tSampleDesc.Count = sampleCount;\r\n\t\tSampleDesc.Quality = sampleQuality;\r\n\t\tLayout = layout;\r\n\t\tFlags = flags;\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_DESC Buffer(\r\n\t\tconst D3D12_RESOURCE_ALLOCATION_INFO& resAllocInfo,\r\n\t\tD3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE)\r\n\t{\r\n\t\treturn CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER, resAllocInfo.Alignment, resAllocInfo.SizeInBytes,\r\n\t\t\t1, 1, 1, DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags);\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_DESC Buffer(\r\n\t\tUINT64 width,\r\n\t\tD3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,\r\n\t\tUINT64 alignment = 0)\r\n\t{\r\n\t\treturn CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER, alignment, width, 1, 1, 1,\r\n\t\t\tDXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags);\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_DESC Tex1D(\r\n\t\tDXGI_FORMAT format,\r\n\t\tUINT64 width,\r\n\t\tUINT16 arraySize = 1,\r\n\t\tUINT16 mipLevels = 0,\r\n\t\tD3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,\r\n\t\tD3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,\r\n\t\tUINT64 alignment = 0)\r\n\t{\r\n\t\treturn CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE1D, alignment, width, 1, arraySize,\r\n\t\t\tmipLevels, format, 1, 0, layout, flags);\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_DESC Tex2D(\r\n\t\tDXGI_FORMAT format,\r\n\t\tUINT64 width,\r\n\t\tUINT height,\r\n\t\tUINT16 arraySize = 1,\r\n\t\tUINT16 mipLevels = 0,\r\n\t\tUINT sampleCount = 1,\r\n\t\tUINT sampleQuality = 0,\r\n\t\tD3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,\r\n\t\tD3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,\r\n\t\tUINT64 alignment = 0)\r\n\t{\r\n\t\treturn CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE2D, alignment, width, height, arraySize,\r\n\t\t\tmipLevels, format, sampleCount, sampleQuality, layout, flags);\r\n\t}\r\n\tstatic inline CD3DX12_RESOURCE_DESC Tex3D(\r\n\t\tDXGI_FORMAT format,\r\n\t\tUINT64 width,\r\n\t\tUINT height,\r\n\t\tUINT16 depth,\r\n\t\tUINT16 mipLevels = 0,\r\n\t\tD3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,\r\n\t\tD3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,\r\n\t\tUINT64 alignment = 0)\r\n\t{\r\n\t\treturn CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE3D, alignment, width, height, depth,\r\n\t\t\tmipLevels, format, 1, 0, layout, flags);\r\n\t}\r\n\tinline UINT16 Depth() const\r\n\t{\r\n\t\treturn (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1);\r\n\t}\r\n\tinline UINT16 ArraySize() const\r\n\t{\r\n\t\treturn (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize : 1);\r\n\t}\r\n\tinline UINT8 PlaneCount(_In_ ID3D12Device* pDevice) const\r\n\t{\r\n\t\treturn D3D12GetFormatPlaneCount(pDevice, Format);\r\n\t}\r\n\tinline UINT Subresources(_In_ ID3D12Device* pDevice) const\r\n\t{\r\n\t\treturn MipLevels * ArraySize() * PlaneCount(pDevice);\r\n\t}\r\n\tinline UINT CalcSubresource(UINT MipSlice, UINT ArraySlice, UINT PlaneSlice)\r\n\t{\r\n\t\treturn D3D12CalcSubresource(MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize());\r\n\t}\r\n\toperator const D3D12_RESOURCE_DESC&() const { return *this; }\r\n};\r\ninline bool operator==(const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r)\r\n{\r\n\treturn l.Dimension == r.Dimension &&\r\n\t\tl.Alignment == r.Alignment &&\r\n\t\tl.Width == r.Width &&\r\n\t\tl.Height == r.Height &&\r\n\t\tl.DepthOrArraySize == r.DepthOrArraySize &&\r\n\t\tl.MipLevels == r.MipLevels &&\r\n\t\tl.Format == r.Format &&\r\n\t\tl.SampleDesc.Count == r.SampleDesc.Count &&\r\n\t\tl.SampleDesc.Quality == r.SampleDesc.Quality &&\r\n\t\tl.Layout == r.Layout &&\r\n\t\tl.Flags == r.Flags;\r\n}\r\ninline bool operator!=(const D3D12_RESOURCE_DESC& l, const D3D12_RESOURCE_DESC& r)\r\n{\r\n\treturn !(l == r);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\n// Row-by-row memcpy\r\ninline void MemcpySubresource(\r\n\t_In_ const D3D12_MEMCPY_DEST* pDest,\r\n\t_In_ const D3D12_SUBRESOURCE_DATA* pSrc,\r\n\tSIZE_T RowSizeInBytes,\r\n\tUINT NumRows,\r\n\tUINT NumSlices)\r\n{\r\n\tfor (UINT z = 0; z < NumSlices; ++z)\r\n\t{\r\n\t\tBYTE* pDestSlice = reinterpret_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;\r\n\t\tconst BYTE* pSrcSlice = reinterpret_cast<const BYTE*>(pSrc->pData) + pSrc->SlicePitch * z;\r\n\t\tfor (UINT y = 0; y < NumRows; ++y)\r\n\t\t{\r\n\t\t\tmemcpy(pDestSlice + pDest->RowPitch * y,\r\n\t\t\t\tpSrcSlice + pSrc->RowPitch * y,\r\n\t\t\t\tRowSizeInBytes);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\n// Returns required size of a buffer to be used for data upload\r\ninline UINT64 GetRequiredIntermediateSize(\r\n\t_In_ ID3D12Resource* pDestinationResource,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources)\r\n{\r\n\tD3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();\r\n\tUINT64 RequiredSize = 0;\r\n\r\n\tID3D12Device* pDevice;\r\n\tpDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));\r\n\tpDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, nullptr, nullptr, nullptr, &RequiredSize);\r\n\tpDevice->Release();\r\n\r\n\treturn RequiredSize;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\n// All arrays must be populated (e.g. by calling GetCopyableFootprints)\r\ninline UINT64 UpdateSubresources(\r\n\t_In_ ID3D12GraphicsCommandList* pCmdList,\r\n\t_In_ ID3D12Resource* pDestinationResource,\r\n\t_In_ ID3D12Resource* pIntermediate,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources,\r\n\tUINT64 RequiredSize,\r\n\t_In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,\r\n\t_In_reads_(NumSubresources) const UINT* pNumRows,\r\n\t_In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,\r\n\t_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData)\r\n{\r\n\t// Minor validation\r\n\tD3D12_RESOURCE_DESC IntermediateDesc = pIntermediate->GetDesc();\r\n\tD3D12_RESOURCE_DESC DestinationDesc = pDestinationResource->GetDesc();\r\n\tif (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||\r\n\t\tIntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||\r\n\t\tRequiredSize >(SIZE_T) - 1 ||\r\n\t\t(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&\r\n\t\t\t(FirstSubresource != 0 || NumSubresources != 1)))\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tBYTE* pData;\r\n\tHRESULT hr = pIntermediate->Map(0, NULL, reinterpret_cast<void**>(&pData));\r\n\tif (FAILED(hr))\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tfor (UINT i = 0; i < NumSubresources; ++i)\r\n\t{\r\n\t\tif (pRowSizesInBytes[i] >(SIZE_T)-1) return 0;\r\n\t\tD3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, pLayouts[i].Footprint.RowPitch * pNumRows[i] };\r\n\t\tMemcpySubresource(&DestData, &pSrcData[i], (SIZE_T)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth);\r\n\t}\r\n\tpIntermediate->Unmap(0, NULL);\r\n\r\n\tif (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)\r\n\t{\r\n\t\tCD3DX12_BOX SrcBox(UINT(pLayouts[0].Offset), UINT(pLayouts[0].Offset + pLayouts[0].Footprint.Width));\r\n\t\tpCmdList->CopyBufferRegion(\r\n\t\t\tpDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);\r\n\t}\r\n\telse\r\n\t{\r\n\t\tfor (UINT i = 0; i < NumSubresources; ++i)\r\n\t\t{\r\n\t\t\tCD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);\r\n\t\t\tCD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);\r\n\t\t\tpCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);\r\n\t\t}\r\n\t}\r\n\treturn RequiredSize;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\n// Heap-allocating UpdateSubresources implementation\r\ninline UINT64 UpdateSubresources(\r\n\t_In_ ID3D12GraphicsCommandList* pCmdList,\r\n\t_In_ ID3D12Resource* pDestinationResource,\r\n\t_In_ ID3D12Resource* pIntermediate,\r\n\tUINT64 IntermediateOffset,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,\r\n\t_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources,\r\n\t_In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)\r\n{\r\n\tUINT64 RequiredSize = 0;\r\n\tUINT64 MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;\r\n\tif (MemToAlloc > SIZE_MAX)\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\tvoid* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));\r\n\tif (pMem == NULL)\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\tD3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);\r\n\tUINT64* pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);\r\n\tUINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);\r\n\r\n\tD3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();\r\n\tID3D12Device* pDevice;\r\n\tpDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));\r\n\tpDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);\r\n\tpDevice->Release();\r\n\r\n\tUINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);\r\n\tHeapFree(GetProcessHeap(), 0, pMem);\r\n\treturn Result;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\n// Stack-allocating UpdateSubresources implementation\r\ntemplate <UINT MaxSubresources>\r\ninline UINT64 UpdateSubresources(\r\n\t_In_ ID3D12GraphicsCommandList* pCmdList,\r\n\t_In_ ID3D12Resource* pDestinationResource,\r\n\t_In_ ID3D12Resource* pIntermediate,\r\n\tUINT64 IntermediateOffset,\r\n\t_In_range_(0, MaxSubresources) UINT FirstSubresource,\r\n\t_In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,\r\n\t_In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA* pSrcData)\r\n{\r\n\tUINT64 RequiredSize = 0;\r\n\tD3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];\r\n\tUINT NumRows[MaxSubresources];\r\n\tUINT64 RowSizesInBytes[MaxSubresources];\r\n\r\n\tD3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();\r\n\tID3D12Device* pDevice;\r\n\tpDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));\r\n\tpDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);\r\n\tpDevice->Release();\r\n\r\n\treturn UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline bool D3D12IsLayoutOpaque(D3D12_TEXTURE_LAYOUT Layout)\r\n{\r\n\treturn Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;\r\n}\r\n\r\n//------------------------------------------------------------------------------------------------\r\ninline ID3D12CommandList * const * CommandListCast(ID3D12GraphicsCommandList * const * pp)\r\n{\r\n\t// This cast is useful for passing strongly typed command list pointers into\r\n\t// ExecuteCommandLists.\r\n\t// This cast is valid as long as the const-ness is respected. D3D12 APIs do\r\n\t// respect the const-ness of their arguments.\r\n\treturn reinterpret_cast<ID3D12CommandList * const *>(pp);\r\n}\r\n\r\n\r\n#endif // defined( __cplusplus )\r\n\r\n#endif //__D3DX12_H__\r\n\r\n\r\n"
  },
  {
    "path": "src/mainfrm.h",
    "content": "#include \"trayicon.h\"\r\n#include \"D3dx12jo.h\"\r\n\r\n// User defined Constants:\r\n\r\n#define WM_TPSCREENSAVER  WM_USER + 0x05\r\n\r\n//////////////////\r\n// Main frame for TRAYTEST.\r\n//\r\nclass CMainFrame : public CFrameWnd {\r\npublic:\r\n\tBOOL MonitorOffSupport();\r\n\tCMainFrame();\r\n\tBOOL IsShiftKeyDown();\r\n\tD3dx12jo* m_pD3jo;\r\n\r\n\tvirtual ~CMainFrame();\r\nprotected:\r\n\tDECLARE_DYNAMIC(CMainFrame)\r\n\tCStatusBar\tm_wndStatusBar;\r\n\r\n\tCTrayIcon\tm_trayIcon;\t\t// my tray icon\r\n\t//CEdit\t\t\tm_wndEdit;\t\t// to display tray notifications\r\n\tint\t\t\tm_iWhichIcon;\t// 0/1 which HICON to use\r\n\tBOOL\t\t\tm_bShutdown;\t// OK to terminate TRAYTEST\r\n\t//BOOL\t\t\tm_bShowTrayNotifications;\t// display info in main window\r\n\r\n\t//{{AFX_MSG(CMainFrame)\r\n\tafx_msg LRESULT OnTrayNotification(WPARAM wp, LPARAM lp);\r\n\tafx_msg int\t OnCreate(LPCREATESTRUCT lpCreateStruct);\r\n\tafx_msg void OnClose();\r\n\tafx_msg void OnAppTpExit();\r\n\tafx_msg void OnTpLogOff();\r\n\tafx_msg void OnTpShutDown();\r\n\tafx_msg void OnTpRestart();\r\n\tafx_msg void OnTpStandBy();\r\n\tafx_msg void OnTimer(UINT_PTR nIDEvent);\r\n\tafx_msg void OnTpScreenSave();\r\n\tafx_msg void OnEndSession(BOOL bEnding);\r\n\tvoid ResetTimerTicks();\r\n\t//}}AFX_MSG\r\n\tDECLARE_MESSAGE_MAP()\r\nprivate:\r\n\tvoid DoMenuDropDown();\r\n\tUINT_PTR m_nTimer;\r\n\tUINT m_BtnClicked;\r\n\tUINT m_nTicks;\r\n\tUINT m_DblClicked;\r\n\tvoid OnStopTimer();\r\n\tvoid OnStartTimer();\r\n\tvoid TpExitWindows(BOOL Force,int shtdn);\r\n};\r\n"
  },
  {
    "path": "src/res/APP.RC2",
    "content": "//\r\n// APP.RC2 - resources Microsoft Visual C++ does not edit directly\r\n//\r\n\r\n#ifdef APSTUDIO_INVOKED\r\n\t#error this file is not editable by Microsoft Visual C++\r\n#endif //APSTUDIO_INVOKED\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// Add manually edited resources here...\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n"
  },
  {
    "path": "src/resource.h",
    "content": "//{{NO_DEPENDENCIES}}\r\n// Microsoft Visual C++ generated include file.\r\n// Used by TrayPwr.rc\r\n//\r\n#define IDR_MAINFRAME                   2\r\n#define IDR_TRAYICON                    3\r\n#define IDSYSINFO                       81\r\n#define IDD_ABOUTBOX                    100\r\n#define IDI_MYICON                      101\r\n#define IDI_MYICON2                     102\r\n#define IDC_EDIT1                       1002\r\n#define IDC_EDITLIC                     1002\r\n#define ID_APPTP_EXIT                   32776\r\n#define ID_TPLOGOFF                     32777\r\n#define ID_TPSHUTDOWN                   32778\r\n#define ID_TPRESTART                    32779\r\n#define ID_TPSTANDBY                    32780\r\n#define ID_TPSCREENSAVE                 32781\r\n\r\n// Next default values for new objects\r\n// \r\n#ifdef APSTUDIO_INVOKED\r\n#ifndef APSTUDIO_READONLY_SYMBOLS\r\n#define _APS_NEXT_RESOURCE_VALUE        105\r\n#define _APS_NEXT_COMMAND_VALUE         32781\r\n#define _APS_NEXT_CONTROL_VALUE         1003\r\n#define _APS_NEXT_SYMED_VALUE           103\r\n#endif\r\n#endif\r\n"
  },
  {
    "path": "src/stdafx.cpp",
    "content": "#include \"stdafx.h\""
  },
  {
    "path": "src/stdafx.h",
    "content": "#pragma once\r\n\r\n#ifndef WIN32_LEAN_AND_MEAN\r\n#define WIN32_LEAN_AND_MEAN    // Exclude rarely-used stuff from Windows headers.\r\n#endif\r\n\r\n#include <afxwin.h>\t\t\t // MFC core and standard components\r\n#include <afxext.h>\t\t\t // MFC extensions (including VB)\r\n#include <string>\r\n"
  },
  {
    "path": "src/trayicon.h",
    "content": "////////////////////////////////////////////////////////////////\r\n// CTrayIcon Copyright 1996 Microsoft Systems Journal.\r\n//\r\n// If this code works, it was written by Paul DiLascia.\r\n// If not, I don't know who wrote it.\r\n\r\n#ifndef _TRAYICON_H\r\n#define _TRAYICON_H\r\n\r\n////////////////\r\n// CTrayIcon manages an icon in the Windows 95 system tray. \r\n// \r\nclass CTrayIcon : public CCmdTarget {\r\nprotected:\r\n\tDECLARE_DYNAMIC(CTrayIcon)\r\n\tNOTIFYICONDATA m_nid;\t\t\t// struct for Shell_NotifyIcon args\r\n\r\npublic:\r\n\tCTrayIcon(UINT uID);\r\n\t~CTrayIcon();\r\n\r\n\t// Call this to receive tray notifications\r\n\tvoid SetNotificationWnd(CWnd* pNotifyWnd, UINT uCbMsg);\r\n\r\n\t// SetIcon functions. To remove icon, call SetIcon(0)\r\n\t//\r\n\tBOOL SetIcon(UINT uID); // main variant you want to use\r\n\tBOOL SetIcon(HICON hicon, LPCSTR lpTip);\r\n\tBOOL SetIcon(LPCTSTR lpResName, LPCSTR lpTip)\r\n\t\t{ return SetIcon(lpResName ? \r\n\t\t\tAfxGetApp()->LoadIcon(lpResName) : NULL, lpTip); }\r\n\tBOOL SetStandardIcon(LPCTSTR lpszIconName, LPCSTR lpTip)\r\n\t\t{ return SetIcon(::LoadIcon(NULL, lpszIconName), lpTip); }\r\n\r\n};\r\n\r\n#endif\r\n"
  }
]