/
redgpu
/
xess
Обзор
Документация
Войти
/
redgpu
/
xess
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/basic_sample_frame_generation/DXSample.cpp
238 строк
8 KB
Intel XeSS
XeSS SDK 3.0.1
17 апр 2026, 02:50
17 апр 2026, 02:50
207b703
Код
Авторство
О чём код?
//********************************************************* // // 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(std::move(name)), m_useWarpDevice(false), m_useDebugDevice(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"-debug", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/debug", wcslen(argv[i])) == 0) { m_useDebugDevice = true; m_title = m_title + L" (DEBUG)"; } if ((_wcsnicmp(argv[i], L"-fps", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/fps", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_minimumFrameTimeMS = 1000.f / static_cast<float>(_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; } if (_wcsnicmp(argv[i], L"-borderless", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/borderless", wcslen(argv[i])) == 0) { m_borderless = true; } if (_wcsnicmp(argv[i], L"-maximized", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/maximized", wcslen(argv[i])) == 0) { m_maximized = true; } if ((_wcsnicmp(argv[i], L"-width", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/width", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_width = _wtoi(argv[i + 1]); i++; } if ((_wcsnicmp(argv[i], L"-height", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/height", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_height = (UINT)_wtoi(argv[i + 1]); i++; } if (_wcsnicmp(argv[i], L"-top", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/top", wcslen(argv[i])) == 0) { m_topmost = true; } if ((_wcsnicmp(argv[i], L"-tag_interpolated_frames", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/tag_interpolated_frames", wcslen(argv[i])) == 0) && (i + 1 < argc)) { m_tagInterpolatedFrames = _wtoi(argv[i + 1]); i++; } if ((_wcsnicmp(argv[i], L"-max_frames", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/max_frames", wcslen(argv[i])) == 0) && (i + 1 < argc)) { int frames = _wtoi(argv[i + 1]); if (frames > 0) { m_maxFrames = frames; } i++; } if (_wcsnicmp(argv[i], L"-init_from_swap_chain", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/init_from_swap_chain", wcslen(argv[i])) == 0) { m_initializeFromApplicationSwapChain = true; } if (_wcsnicmp(argv[i], L"-external_descriptor_heap", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/external_descriptor_heap", wcslen(argv[i])) == 0) { m_enableExternalDescriptorHeap = true; } if (_wcsnicmp(argv[i], L"-mfg_count", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/mfg_count", wcslen(argv[i])) == 0) { ++i; if (i < argc) { // We rely on XeSS-FG to check if this value is supported. m_maxInterpolatedFrames = static_cast<uint32_t>(_wtoi(argv[i])); } } if (_wcsnicmp(argv[i], L"-waitable", wcslen(argv[i])) == 0 || _wcsnicmp(argv[i], L"/waitable", wcslen(argv[i])) == 0) { m_useWaitableSwapChain = true; } } }