/
redgpu
/
xess
Обзор
Документация
Войти
/
redgpu
/
xess
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/basic_sample_low_latency/DXSample.cpp
172 строки
6 KB
Intel XeSS
Updated to XeSS SDK 2.1.0
30 июл 2025, 22:47
30 июл 2025, 22:47
c159ef4
Код
Авторство
О чём код?
//********************************************************* // // Copyright (c) Microsoft. All rights reserved. // Copyright (c) 2023 Intel Corporation // // This code is licensed under the MIT License (MIT). // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* #include "stdafx.h" #include "DXSample.h" using namespace Microsoft::WRL; DXSample::DXSample(UINT width, UINT height, std::wstring name) : m_width(width), m_height(height), m_title(name), m_useWarpDevice(false), m_hardwareAdapterId(-1) { WCHAR assetsPath[512]; GetAssetsPath(assetsPath, _countof(assetsPath)); m_assetsPath = assetsPath; m_aspectRatio = static_cast<float>(width) / static_cast<float>(height); } DXSample::~DXSample() { } // Helper function for resolving the full path of assets. std::wstring DXSample::GetAssetFullPath(LPCWSTR assetName) { return m_assetsPath + assetName; } // Helper function for acquiring the first available hardware adapter that supports Direct3D 12. // If no such adapter can be found, *ppAdapter will be set to nullptr. _Use_decl_annotations_ void DXSample::GetHardwareAdapter( IDXGIFactory1* pFactory, IDXGIAdapter1** ppAdapter, bool requestHighPerformanceAdapter) { *ppAdapter = nullptr; ComPtr<IDXGIAdapter1> adapter; ComPtr<IDXGIFactory6> factory6; if (SUCCEEDED(pFactory->QueryInterface(IID_PPV_ARGS(&factory6)))) { for ( UINT adapterIndex = 0; SUCCEEDED(factory6->EnumAdapterByGpuPreference( adapterIndex, requestHighPerformanceAdapter == true ? DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE : DXGI_GPU_PREFERENCE_UNSPECIFIED, IID_PPV_ARGS(&adapter))); ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { // Don't select the Basic Render Driver adapter. // If you want a software adapter, pass in "/warp" on the command line. continue; } // Check to see whether the adapter supports Direct3D 12, but don't create the // actual device yet. if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) { break; } } } if (adapter.Get() == nullptr) { for (UINT adapterIndex = 0; SUCCEEDED(pFactory->EnumAdapters1(adapterIndex, &adapter)); ++adapterIndex) { DXGI_ADAPTER_DESC1 desc; adapter->GetDesc1(&desc); if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) { // Don't select the Basic Render Driver adapter. // If you want a software adapter, pass in "/warp" on the command line. continue; } // Check to see whether the adapter supports Direct3D 12, but don't create the // actual device yet. if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr))) { break; } } } *ppAdapter = adapter.Detach(); } // Helper function for setting the window's title text. void DXSample::SetCustomWindowText(LPCWSTR text) { std::wstring windowText = m_title + L" - " + text; SetWindowText(Win32Application::GetHwnd(), windowText.c_str()); } // Helper function for parsing any supplied command line args. _Use_decl_annotations_ void DXSample::ParseCommandLineArgs(WCHAR* argv[], int argc) { for (int i = 1; i < argc; ++i) { if (_wcsnicmp(argv[i], L"-warp", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/warp", wcslen(argv[i])) == 0) { m_useWarpDevice = true; m_title = m_title + L" (WARP)"; } if ((_wcsnicmp(argv[i], L"-gpu_id", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/gpu_id", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_hardwareAdapterId = _wtoi(argv[i + 1]); i++; } if (_wcsnicmp(argv[i], L"-async", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/async", wcslen(argv[i])) == 0) { m_useAsyncFlip = true; } if (_wcsnicmp(argv[i], L"-xell", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/xell", wcslen(argv[i])) == 0) { #ifdef ENABLE_XELL m_latencyReductionEnabled = true; #endif } if ((_wcsnicmp(argv[i], L"-frame_count", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/frame_count", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_frame_count_limit = _wtoi(argv[i + 1]); i++; } if (_wcsnicmp(argv[i], L"-fps", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/fps", wcslen(argv[i])) == 0) { m_frameMS = 1000 / _wtof(argv[i + 1]); i++; } if (_wcsnicmp(argv[i], L"-fullscreen", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/fullscreen", wcslen(argv[i])) == 0) { m_fullScreen = true; } } }