From 2a26c5f5da9c3782277a73c5dd5009e6af41b7b8 Mon Sep 17 00:00:00 2001 From: Danilo Date: Sun, 21 Jul 2024 21:54:50 -0300 Subject: [PATCH] Melhorias em createDevice --- CMakeLists.txt | 2 +- framework/platform-dx/adapter.cpp | 2 + framework/platform-dx/device.cpp | 62 +++++++++++++++++++------------ inc/xna/xna-dx.hpp | 14 ++++++- samples/CMakeLists.txt | 2 +- 5 files changed, 56 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3757379..562ba32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,6 @@ project ("xna") include_directories(${PROJECT_INCLUDES_DIR}) add_subdirectory ("framework") -#add_subdirectory ("samples") +add_subdirectory ("samples") diff --git a/framework/platform-dx/adapter.cpp b/framework/platform-dx/adapter.cpp index 0c962be..102783e 100644 --- a/framework/platform-dx/adapter.cpp +++ b/framework/platform-dx/adapter.cpp @@ -37,6 +37,8 @@ namespace xna { setOutputVars(pAdapter, adp->deviceName, adp->monitorHandle); + adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter); + setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color, GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode); diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index dfa1e50..2427add 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -21,42 +21,58 @@ namespace xna { } static void createDevice(GraphicsDevice::PlatformImplementation& impl) { + // + // See ref + // + // D3D_DRIVER_TYPE + // https://learn.microsoft.com/en-us/windows/win32/api/d3dcommon/ne-d3dcommon-d3d_driver_type + // + // D3D11CreateDevice function + // https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11createdevice + // + auto createDeviceFlags = 0; #if _DEBUG createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG; #endif + const auto& currentAdapter = impl._adapter; + const auto& pAdapter = GraphicsAdapter::UseNullDevice() ? NULL : currentAdapter->impl->dxAdapter.Get(); + + // + // if pAdapter is not NULL driverType must be D3D_DRIVER_TYPE_UNKNOWN + // + auto driverType = D3D_DRIVER_TYPE_UNKNOWN; + + if (GraphicsAdapter::UseReferenceDevice()) + driverType = D3D_DRIVER_TYPE_WARP; + else if (GraphicsAdapter::UseNullDevice()) + driverType = D3D_DRIVER_TYPE_HARDWARE; auto hr = D3D11CreateDevice( - currentAdapter ? currentAdapter->impl->dxAdapter.Get() : NULL, - D3D_DRIVER_TYPE_UNKNOWN, + //_In_opt_ IDXGIAdapter* pAdapter, + pAdapter, + //D3D_DRIVER_TYPE DriverType, + driverType, + //HMODULE Software, NULL, + //UINT Flags, createDeviceFlags, - NULL, - 0, + //_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels, + impl.featureLevels, + //UINT FeatureLevels, + 7, + //UINT SDKVersion, D3D11_SDK_VERSION, + //_COM_Outptr_opt_ ID3D11Device** ppDevice impl._device.GetAddressOf(), - &impl._featureLevel, + //_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel, + &impl.currentFeatureLevel, + //_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext impl._context.GetAddressOf()); - if (FAILED(hr)) { - OutputDebugString("---> Usando Adaptador WARP: não há suporte ao D3D11\n"); - - hr = D3D11CreateDevice( - NULL, - D3D_DRIVER_TYPE_WARP, - NULL, - createDeviceFlags, - NULL, - 0, - D3D11_SDK_VERSION, - impl._device.GetAddressOf(), - &impl._featureLevel, - impl._context.GetAddressOf()); - - if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); - } + if FAILED(hr) + Exception::Throw(Exception::FAILED_TO_CREATE); } static void initAndApplyState(GraphicsDevice::PlatformImplementation& impl, PGraphicsDevice const& device) { diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index 59242bf..1f3433c 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -845,7 +845,19 @@ namespace xna { sptr _gameWindow = nullptr; xna::Viewport _viewport{}; sptr _presentationParameters; - D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 }; + + D3D_FEATURE_LEVEL featureLevels[7] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + + D3D_FEATURE_LEVEL currentFeatureLevel; private: friend class GraphicsDevice; diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 45257e9..24ef843 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -4,4 +4,4 @@ # Add source to this project's executable. add_subdirectory ("01_blank") -add_subdirectory ("02_PlatfformerStarterKit") +#add_subdirectory ("02_PlatfformerStarterKit")