From 6a0217bbf1f4b8a8db97daba2361d89482a54d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 31 Jul 2015 17:34:33 -0700 Subject: [PATCH] Fixed MinGW build. Issue #467, --- src/renderer_d3d11.cpp | 251 +++++++++++++++++++++-------------------- src/renderer_d3d9.cpp | 142 ++++++++++++----------- 2 files changed, 200 insertions(+), 193 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 130ba69cb..b96e3c4cb 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -742,152 +742,155 @@ namespace bgfx { namespace d3d11 errorState = 4; } - IDXGIDevice* device = NULL; - IDXGIAdapter* adapter = NULL; - hr = E_FAIL; - for (uint32_t ii = 0; ii < BX_COUNTOF(s_deviceIIDs) && FAILED(hr); ++ii) { - hr = m_device->QueryInterface(s_deviceIIDs[ii], (void**)&device); - BX_TRACE("D3D device 11.%d, hr %x", BX_COUNTOF(s_deviceIIDs)-1-ii, hr); - - if (SUCCEEDED(hr) ) + IDXGIDevice* device = NULL; + IDXGIAdapter* adapter = NULL; + hr = E_FAIL; + for (uint32_t ii = 0; ii < BX_COUNTOF(s_deviceIIDs) && FAILED(hr); ++ii) { + hr = m_device->QueryInterface(s_deviceIIDs[ii], (void**)&device); + BX_TRACE("D3D device 11.%d, hr %x", BX_COUNTOF(s_deviceIIDs)-1-ii, hr); + + if (SUCCEEDED(hr) ) + { #if BX_COMPILER_MSVC BX_PRAGMA_DIAGNOSTIC_PUSH(); BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4530) // warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc - try - { - // QueryInterface above can succeed, but getting adapter call might crash on Win7. - hr = device->GetAdapter(&adapter); - } - catch (...) - { - BX_TRACE("Failed to get adapter foro IID_IDXGIDevice%d.", BX_COUNTOF(s_deviceIIDs)-1-ii); - DX_RELEASE(device, 0); - hr = E_FAIL; - } + try + { + // QueryInterface above can succeed, but getting adapter call might crash on Win7. + hr = device->GetAdapter(&adapter); + } + catch (...) + { + BX_TRACE("Failed to get adapter foro IID_IDXGIDevice%d.", BX_COUNTOF(s_deviceIIDs)-1-ii); + DX_RELEASE(device, 0); + hr = E_FAIL; + } BX_PRAGMA_DIAGNOSTIC_POP(); #else - hr = device->GetAdapter(&adapter); + hr = device->GetAdapter(&adapter); #endif // BX_COMPILER_MSVC + } } - } - BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); - if (FAILED(hr) ) - { - goto error; - } - // GPA increases device ref count. - // RenderDoc makes device ref count 0 here. - // - // This causes assert in debug. When debugger is present refcount - // checks are off. - IDXGIDevice* renderdoc; - hr = m_device->QueryInterface(IID_IDXGIDeviceRenderDoc, (void**)&renderdoc); - if (SUCCEEDED(hr) ) - { - setGraphicsDebuggerPresent(true); - DX_RELEASE(renderdoc, 2); - } - else - { - setGraphicsDebuggerPresent(3 != getRefCount(device) ); - DX_RELEASE(device, 2); - } + BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); + if (FAILED(hr) ) + { + goto error; + } - hr = adapter->GetDesc(&m_adapterDesc); - BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); - if (FAILED(hr) ) - { - DX_RELEASE(adapter, 2); - goto error; - } + // GPA increases device ref count. + // RenderDoc makes device ref count 0 here. + // + // This causes assert in debug. When debugger is present refcount + // checks are off. + IDXGIDevice* renderdoc; + hr = m_device->QueryInterface(IID_IDXGIDeviceRenderDoc, (void**)&renderdoc); + if (SUCCEEDED(hr) ) + { + setGraphicsDebuggerPresent(true); + DX_RELEASE(renderdoc, 2); + } + else + { + setGraphicsDebuggerPresent(3 != getRefCount(device) ); + DX_RELEASE(device, 2); + } - g_caps.vendorId = 0 == m_adapterDesc.VendorId - ? BGFX_PCI_ID_SOFTWARE_RASTERIZER - : (uint16_t)m_adapterDesc.VendorId - ; - g_caps.deviceId = (uint16_t)m_adapterDesc.DeviceId; + hr = adapter->GetDesc(&m_adapterDesc); + BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); + if (FAILED(hr) ) + { + DX_RELEASE(adapter, 2); + goto error; + } - if (NULL == g_platformData.backBuffer) - { + g_caps.vendorId = 0 == m_adapterDesc.VendorId + ? BGFX_PCI_ID_SOFTWARE_RASTERIZER + : (uint16_t)m_adapterDesc.VendorId + ; + g_caps.deviceId = (uint16_t)m_adapterDesc.DeviceId; + + if (NULL == g_platformData.backBuffer) + { #if BX_PLATFORM_WINRT - hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory); - BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); - DX_RELEASE(adapter, 2); - if (FAILED(hr) ) - { - goto error; - } + hr = adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&m_factory); + BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); + DX_RELEASE(adapter, 2); + if (FAILED(hr) ) + { + goto error; + } - memset(&m_scd, 0, sizeof(m_scd) ); - m_scd.Width = BGFX_DEFAULT_WIDTH; - m_scd.Height = BGFX_DEFAULT_HEIGHT; - m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - m_scd.Stereo = false; - m_scd.SampleDesc.Count = 1; - m_scd.SampleDesc.Quality = 0; - m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - m_scd.BufferCount = 2; - m_scd.Scaling = DXGI_SCALING_NONE; - m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.Width = BGFX_DEFAULT_WIDTH; + m_scd.Height = BGFX_DEFAULT_HEIGHT; + m_scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_scd.Stereo = false; + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + m_scd.BufferCount = 2; + m_scd.Scaling = DXGI_SCALING_NONE; + m_scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + m_scd.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - hr = m_factory->CreateSwapChainForCoreWindow(m_device - , (::IUnknown*)g_platformData.nwh - , &m_scd - , NULL - , &m_swapChain - ); + hr = m_factory->CreateSwapChainForCoreWindow(m_device + , (::IUnknown*)g_platformData.nwh + , &m_scd + , NULL + , &m_swapChain + ); #else - hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); - BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); - DX_RELEASE(adapter, 2); - if (FAILED(hr) ) - { - goto error; - } + hr = adapter->GetParent(IID_IDXGIFactory, (void**)&m_factory); + BX_WARN(SUCCEEDED(hr), "Unable to create Direct3D11 device."); + DX_RELEASE(adapter, 2); + if (FAILED(hr) ) + { + goto error; + } - memset(&m_scd, 0, sizeof(m_scd) ); - m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; - m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; - m_scd.BufferDesc.RefreshRate.Numerator = 60; - m_scd.BufferDesc.RefreshRate.Denominator = 1; - m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - m_scd.SampleDesc.Count = 1; - m_scd.SampleDesc.Quality = 0; - m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - m_scd.BufferCount = 1; - m_scd.OutputWindow = (HWND)g_platformData.nwh; - m_scd.Windowed = true; + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.BufferDesc.Width = BGFX_DEFAULT_WIDTH; + m_scd.BufferDesc.Height = BGFX_DEFAULT_HEIGHT; + m_scd.BufferDesc.RefreshRate.Numerator = 60; + m_scd.BufferDesc.RefreshRate.Denominator = 1; + m_scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + m_scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + m_scd.BufferCount = 1; + m_scd.OutputWindow = (HWND)g_platformData.nwh; + m_scd.Windowed = true; - hr = m_factory->CreateSwapChain(m_device - , &m_scd - , &m_swapChain - ); + hr = m_factory->CreateSwapChain(m_device + , &m_scd + , &m_swapChain + ); - DX_CHECK(m_factory->MakeWindowAssociation( (HWND)g_platformData.nwh, 0 - | DXGI_MWA_NO_WINDOW_CHANGES - | DXGI_MWA_NO_ALT_ENTER - ) ); + DX_CHECK(m_factory->MakeWindowAssociation( (HWND)g_platformData.nwh, 0 + | DXGI_MWA_NO_WINDOW_CHANGES + | DXGI_MWA_NO_ALT_ENTER + ) ); #endif // BX_PLATFORM_WINRT - BX_WARN(SUCCEEDED(hr), "Failed to create swap chain."); - if (FAILED(hr) ) - { - goto error; - } + BX_WARN(SUCCEEDED(hr), "Failed to create swap chain."); + if (FAILED(hr) ) + { + goto error; + } - errorState = 5; - } - else - { - memset(&m_scd, 0, sizeof(m_scd) ); - m_scd.SampleDesc.Count = 1; - m_scd.SampleDesc.Quality = 0; - setBufferSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); - m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; - m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; + errorState = 5; + } + else + { + memset(&m_scd, 0, sizeof(m_scd) ); + m_scd.SampleDesc.Count = 1; + m_scd.SampleDesc.Quality = 0; + setBufferSize(BGFX_DEFAULT_WIDTH, BGFX_DEFAULT_HEIGHT); + m_backBufferColor = (ID3D11RenderTargetView*)g_platformData.backBuffer; + m_backBufferDepthStencil = (ID3D11DepthStencilView*)g_platformData.backBufferDS; + } } m_numWindows = 1; diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 401803ef6..7d52159a3 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -380,72 +380,73 @@ namespace bgfx { namespace d3d9 errorState = 2; - m_adapter = D3DADAPTER_DEFAULT; - m_deviceType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId - ? D3DDEVTYPE_REF - : D3DDEVTYPE_HAL - ; - - uint8_t numGPUs = uint8_t(bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ) ); - for (uint32_t ii = 0; ii < numGPUs; ++ii) { - D3DADAPTER_IDENTIFIER9 desc; - HRESULT hr = m_d3d9->GetAdapterIdentifier(ii, 0, &desc); - if (SUCCEEDED(hr) ) + m_adapter = D3DADAPTER_DEFAULT; + m_deviceType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId + ? D3DDEVTYPE_REF + : D3DDEVTYPE_HAL + ; + + uint8_t numGPUs = uint8_t(bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ) ); + for (uint32_t ii = 0; ii < numGPUs; ++ii) { - BX_TRACE("Adapter #%d", ii); - BX_TRACE("\tDriver: %s", desc.Driver); - BX_TRACE("\tDescription: %s", desc.Description); - BX_TRACE("\tDeviceName: %s", desc.DeviceName); - BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x" - , desc.VendorId - , desc.DeviceId - , desc.SubSysId - , desc.Revision - ); - - g_caps.gpu[ii].vendorId = (uint16_t)desc.VendorId; - g_caps.gpu[ii].deviceId = (uint16_t)desc.DeviceId; - - if (D3DADAPTER_DEFAULT == m_adapter) + D3DADAPTER_IDENTIFIER9 desc; + HRESULT hr = m_d3d9->GetAdapterIdentifier(ii, 0, &desc); + if (SUCCEEDED(hr) ) { - if ( (BGFX_PCI_ID_NONE != g_caps.vendorId || 0 != g_caps.deviceId) - && (BGFX_PCI_ID_NONE == g_caps.vendorId || desc.VendorId == g_caps.vendorId) - && ( 0 == g_caps.deviceId || desc.DeviceId == g_caps.deviceId) ) - { - m_adapter = ii; - } + BX_TRACE("Adapter #%d", ii); + BX_TRACE("\tDriver: %s", desc.Driver); + BX_TRACE("\tDescription: %s", desc.Description); + BX_TRACE("\tDeviceName: %s", desc.DeviceName); + BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x" + , desc.VendorId + , desc.DeviceId + , desc.SubSysId + , desc.Revision + ); - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) - && 0 != strstr(desc.Description, "PerfHUD") ) + g_caps.gpu[ii].vendorId = (uint16_t)desc.VendorId; + g_caps.gpu[ii].deviceId = (uint16_t)desc.DeviceId; + + if (D3DADAPTER_DEFAULT == m_adapter) { - m_adapter = ii; - m_deviceType = D3DDEVTYPE_REF; + if ( (BGFX_PCI_ID_NONE != g_caps.vendorId || 0 != g_caps.deviceId) + && (BGFX_PCI_ID_NONE == g_caps.vendorId || desc.VendorId == g_caps.vendorId) + && ( 0 == g_caps.deviceId || desc.DeviceId == g_caps.deviceId) ) + { + m_adapter = ii; + } + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PERFHUD) + && 0 != strstr(desc.Description, "PerfHUD") ) + { + m_adapter = ii; + m_deviceType = D3DDEVTYPE_REF; + } } } } - } - DX_CHECK(m_d3d9->GetAdapterIdentifier(m_adapter, 0, &m_identifier) ); - m_amd = m_identifier.VendorId == BGFX_PCI_ID_AMD; - m_nvidia = m_identifier.VendorId == BGFX_PCI_ID_NVIDIA; - g_caps.vendorId = 0 == m_identifier.VendorId - ? BGFX_PCI_ID_SOFTWARE_RASTERIZER - : (uint16_t)m_identifier.VendorId - ; - g_caps.deviceId = (uint16_t)m_identifier.DeviceId; + DX_CHECK(m_d3d9->GetAdapterIdentifier(m_adapter, 0, &m_identifier) ); + m_amd = m_identifier.VendorId == BGFX_PCI_ID_AMD; + m_nvidia = m_identifier.VendorId == BGFX_PCI_ID_NVIDIA; + g_caps.vendorId = 0 == m_identifier.VendorId + ? BGFX_PCI_ID_SOFTWARE_RASTERIZER + : (uint16_t)m_identifier.VendorId + ; + g_caps.deviceId = (uint16_t)m_identifier.DeviceId; - uint32_t behaviorFlags[] = - { - D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_PUREDEVICE, - D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, - D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, - }; + uint32_t behaviorFlags[] = + { + D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | D3DCREATE_PUREDEVICE, + D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, + D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, + }; - for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii) - { + for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii) + { #if 0 // BGFX_CONFIG_RENDERER_DIRECT3D9EX - DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter + DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter , m_deviceType , g_platformHooks.nwh , behaviorFlags[ii] @@ -454,14 +455,15 @@ namespace bgfx { namespace d3d9 , &m_device ) ); #else - DX_CHECK(m_d3d9->CreateDevice(m_adapter - , m_deviceType - , (HWND)g_platformData.nwh - , behaviorFlags[ii] - , &m_params - , &m_device - ) ); + DX_CHECK(m_d3d9->CreateDevice(m_adapter + , m_deviceType + , (HWND)g_platformData.nwh + , behaviorFlags[ii] + , &m_params + , &m_device + )); #endif // BGFX_CONFIG_RENDERER_DIRECT3D9EX + } } BX_WARN(NULL != m_device, "Unable to create Direct3D9 device."); @@ -597,19 +599,21 @@ namespace bgfx { namespace d3d9 } } - uint32_t index = 1; - for (const D3DFORMAT* fmt = &s_checkColorFormats[index]; *fmt != D3DFMT_UNKNOWN; ++fmt, ++index) { - for (; *fmt != D3DFMT_UNKNOWN; ++fmt) + uint32_t index = 1; + for (const D3DFORMAT* fmt = &s_checkColorFormats[index]; *fmt != D3DFMT_UNKNOWN; ++fmt, ++index) { - if (SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, *fmt) ) ) + for (; *fmt != D3DFMT_UNKNOWN; ++fmt) { - s_colorFormat[index] = *fmt; - break; + if (SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter, m_deviceType, adapterFormat, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, *fmt) ) ) + { + s_colorFormat[index] = *fmt; + break; + } } - } - for (; *fmt != D3DFMT_UNKNOWN; ++fmt); + for (; *fmt != D3DFMT_UNKNOWN; ++fmt); + } } m_fmtDepth = D3DFMT_D24S8;