From 641d294b9d8b750b5f308410473bcb8bdf2e9372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 8 Apr 2016 17:30:35 -0700 Subject: [PATCH] Cleanup. --- examples/common/entry/entry_p.h | 2 +- examples/common/entry/entry_winrt.cpp | 40 +++- src/renderer_d3d11.cpp | 260 ++++++++++++++------------ 3 files changed, 175 insertions(+), 127 deletions(-) diff --git a/examples/common/entry/entry_p.h b/examples/common/entry/entry_p.h index f44a42194..971b88055 100644 --- a/examples/common/entry/entry_p.h +++ b/examples/common/entry/entry_p.h @@ -14,7 +14,7 @@ #include // memcpy #ifndef ENTRY_CONFIG_USE_NOOP -# define ENTRY_CONFIG_USE_NOOP (BX_PLATFORM_QNX || BX_PLATFORM_XBOXONE) +# define ENTRY_CONFIG_USE_NOOP (BX_PLATFORM_QNX) #endif // ENTRY_CONFIG_USE_NOOP #ifndef ENTRY_CONFIG_USE_SDL diff --git a/examples/common/entry/entry_winrt.cpp b/examples/common/entry/entry_winrt.cpp index caf4f235a..9edbc36e9 100644 --- a/examples/common/entry/entry_winrt.cpp +++ b/examples/common/entry/entry_winrt.cpp @@ -5,7 +5,7 @@ #include "entry_p.h" -#if BX_PLATFORM_WINRT +#if BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE #include #include @@ -17,7 +17,9 @@ using namespace Windows::UI::Core; using namespace Windows::UI::Input; using namespace Windows::System; using namespace Windows::Foundation; +#if BX_PLATFORM_WINRT using namespace Windows::Graphics::Display; +#endif // BX_PLATFORM_WINRT using namespace Platform; static char* g_emptyArgs[] = { "" }; @@ -36,13 +38,23 @@ public: // IFrameworkView Methods. virtual void Initialize(CoreApplicationView^ applicationView) { - applicationView->Activated += ref new TypedEventHandler(this, &App::OnActivated); + applicationView->Activated += ref new + TypedEventHandler(this, &App::OnActivated); + + CoreApplication::Suspending += ref new + EventHandler(this, &App::OnSuspending); + + CoreApplication::Resuming += ref new + EventHandler(this, &App::OnResuming); } virtual void SetWindow(CoreWindow^ window) { - window->VisibilityChanged += ref new TypedEventHandler(this, &App::OnVisibilityChanged); - window->Closed += ref new TypedEventHandler(this, &App::OnWindowClosed); + window->VisibilityChanged += ref new + TypedEventHandler(this, &App::OnVisibilityChanged); + + window->Closed += ref new + TypedEventHandler(this, &App::OnWindowClosed); bgfx::winrtSetWindow(reinterpret_cast(window) ); } @@ -58,13 +70,15 @@ public: CoreWindow^ window = CoreWindow::GetForCurrentThread(); auto bounds = window->Bounds; - auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi; +#if BX_PLATFORM_WINRT + auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi; static const float dipsPerInch = 96.0f; g_eventQueue.postSizeEvent(g_defaultWindow - , lround(floorf(bounds.Width * dpi / dipsPerInch + 0.5f) ) - , lround(floorf(bounds.Height * dpi / dipsPerInch + 0.5f) ) + , lround(bx::ffloor(bounds.Width * dpi / dipsPerInch + 0.5f) ) + , lround(bx::ffloor(bounds.Height * dpi / dipsPerInch + 0.5f) ) ); +#endif // BX_PLATFORM_WINRT while (!m_windowClosed) { @@ -101,6 +115,16 @@ private: m_windowVisible = args->Visible; } + void OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) + { + SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); + BX_UNUSED(deferral); + } + + void OnResuming(Platform::Object^ sender, Platform::Object^ args) + { + } + void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) { m_windowClosed = true; @@ -189,4 +213,4 @@ int main(Array^) return 0; } -#endif // BX_PLATFORM_WINRT +#endif // BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 539ab426f..9486f9984 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -1076,13 +1076,9 @@ BX_PRAGMA_DIAGNOSTIC_POP(); DX_RELEASE(device, 2); } + memset(&m_adapterDesc, 0, sizeof(m_adapterDesc) ); hr = adapter->GetDesc(&m_adapterDesc); - if (FAILED(hr) ) - { - BX_TRACE("Unable to create Direct3D11 device."); - DX_RELEASE(adapter, 2); - goto error; - } + BX_WARN(SUCCEEDED(hr), "Adapter GetDesc failed 0x%08x.", hr); g_caps.vendorId = 0 == m_adapterDesc.VendorId ? BGFX_PCI_ID_SOFTWARE_RASTERIZER @@ -1354,140 +1350,168 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (DXGI_FORMAT_UNKNOWN != fmt) { - struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) { - DXGI_FORMAT InFormat; - UINT OutFormatSupport; - }; + struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + { + DXGI_FORMAT InFormat; + UINT OutFormatSupport; + }; - D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 - data.InFormat = fmt; - hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); - if (SUCCEEDED(hr) ) - { - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURE2D - | D3D11_FORMAT_SUPPORT_TEXTURE3D - | D3D11_FORMAT_SUPPORT_TEXTURECUBE - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_2D - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURE3D - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_3D - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURECUBE - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_CUBE - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_BUFFER - | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER - | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_SHADER_LOAD - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_RENDER_TARGET - | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_MSAA - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; - } - else - { - BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); - } - - if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) ) - { - // clear image flag for additional testing - support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE; - - data.InFormat = s_textureFormat[ii].m_fmt; - hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) ); + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 + data.InFormat = fmt; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) ) { support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD - | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE + | D3D11_FORMAT_SUPPORT_TEXTURE2D + | D3D11_FORMAT_SUPPORT_TEXTURE3D + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_2D + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_BUFFER + | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER + | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_SHADER_LOAD ) ) ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE : BGFX_CAPS_FORMAT_TEXTURE_NONE ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_RENDER_TARGET + | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_MSAA + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; } + else + { + BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + } + + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) ) + { + // clear image flag for additional testing + support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE; + + data.InFormat = s_textureFormat[ii].m_fmt; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) ); + if (SUCCEEDED(hr) ) + { + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD + | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + } + } + else + { + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_2D + | BGFX_CAPS_FORMAT_TEXTURE_3D + | BGFX_CAPS_FORMAT_TEXTURE_CUBE + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE + | BGFX_CAPS_FORMAT_TEXTURE_VERTEX + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE + | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA + | BGFX_CAPS_FORMAT_TEXTURE_MSAA + ; } } if (DXGI_FORMAT_UNKNOWN != fmtSrgb) { - struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) { - DXGI_FORMAT InFormat; - UINT OutFormatSupport; - }; + struct D3D11_FEATURE_DATA_FORMAT_SUPPORT + { + DXGI_FORMAT InFormat; + UINT OutFormatSupport; + }; - D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 - data.InFormat = fmtSrgb; - hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); - if (SUCCEEDED(hr) ) - { - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURE2D - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 + data.InFormat = fmtSrgb; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); + if (SUCCEEDED(hr) ) + { + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE2D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURE3D - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURE3D + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; - support |= 0 != (data.OutFormatSupport & (0 - | D3D11_FORMAT_SUPPORT_TEXTURECUBE - ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; + support |= 0 != (data.OutFormatSupport & (0 + | D3D11_FORMAT_SUPPORT_TEXTURECUBE + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } + else + { + BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + } } else { - BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + ; } }