Procházet zdrojové kódy

Exposed software rasterizer.

Branimir Karadžić před 10 roky
rodič
revize
e5ed5db1f1
3 změnil soubory, kde provedl 59 přidání a 33 odebrání
  1. 5 4
      include/bgfxdefines.h
  2. 45 26
      src/renderer_d3d11.cpp
  3. 9 3
      src/renderer_d3d9.cpp

+ 5 - 4
include/bgfxdefines.h

@@ -338,9 +338,10 @@
 #define BGFX_SUBMIT_EYE_FIRST BGFX_SUBMIT_EYE_LEFT
 
 ///
-#define BGFX_PCI_ID_NONE   UINT16_C(0x0000)
-#define BGFX_PCI_ID_AMD    UINT16_C(0x1002)
-#define BGFX_PCI_ID_INTEL  UINT16_C(0x8086)
-#define BGFX_PCI_ID_NVIDIA UINT16_C(0x10de)
+#define BGFX_PCI_ID_NONE                UINT16_C(0x0000)
+#define BGFX_PCI_ID_SOFTWARE_RASTERIZER UINT16_C(0x0001)
+#define BGFX_PCI_ID_AMD                 UINT16_C(0x1002)
+#define BGFX_PCI_ID_INTEL               UINT16_C(0x8086)
+#define BGFX_PCI_ID_NVIDIA              UINT16_C(0x10de)
 
 #endif // BGFX_DEFINES_H_HEADER_GUARD

+ 45 - 26
src/renderer_d3d11.cpp

@@ -538,7 +538,10 @@ namespace bgfx { namespace d3d11
 			if (NULL == m_device)
 			{
 				m_adapter    = NULL;
-				m_driverType = D3D_DRIVER_TYPE_HARDWARE;
+				m_driverType = BGFX_PCI_ID_SOFTWARE_RASTERIZER == g_caps.vendorId
+					? D3D_DRIVER_TYPE_WARP
+					: D3D_DRIVER_TYPE_HARDWARE
+					;
 
 				IDXGIAdapter* adapter;
 				for (uint32_t ii = 0
@@ -606,36 +609,49 @@ namespace bgfx { namespace d3d11
 					D3D_FEATURE_LEVEL_9_1,
 				};
 
-				uint32_t flags = 0
-					| D3D11_CREATE_DEVICE_SINGLETHREADED
-					| D3D11_CREATE_DEVICE_BGRA_SUPPORT
-					| (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0)
-					;
-
-				hr = E_FAIL;
-				for (uint32_t ii = 0; ii < 3 && FAILED(hr);)
+				for (;;)
 				{
-					hr = D3D11CreateDevice(m_adapter
-						, m_driverType
-						, NULL
-						, flags
-						, &features[ii]
-						, BX_COUNTOF(features)-ii
-						, D3D11_SDK_VERSION
-						, &m_device
-						, &m_featureLevel
-						, &m_deviceCtx
-						);
+					uint32_t flags = 0
+						| D3D11_CREATE_DEVICE_SINGLETHREADED
+						| D3D11_CREATE_DEVICE_BGRA_SUPPORT
+						| (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0)
+						;
+
+					hr = E_FAIL;
+					for (uint32_t ii = 0; ii < 3 && FAILED(hr);)
+					{
+						hr = D3D11CreateDevice(m_adapter
+							, m_driverType
+							, NULL
+							, flags
+							, &features[ii]
+							, BX_COUNTOF(features)-ii
+							, D3D11_SDK_VERSION
+							, &m_device
+							, &m_featureLevel
+							, &m_deviceCtx
+							);
+						if (FAILED(hr)
+						&&  0 != (flags & D3D11_CREATE_DEVICE_DEBUG) )
+						{
+							// Try without debug in case D3D11 SDK Layers
+							// is not present?
+							flags &= ~D3D11_CREATE_DEVICE_DEBUG;
+							continue;
+						}
+
+						++ii;
+					}
+
 					if (FAILED(hr)
-					&&  0 != (flags & D3D11_CREATE_DEVICE_DEBUG) )
+					&&  D3D_DRIVER_TYPE_WARP != m_driverType)
 					{
-						// Try without debug in case D3D11 SDK Layers
-						// is not present?
-						flags &= ~D3D11_CREATE_DEVICE_DEBUG;
+						// Try with WARP
+						m_driverType = D3D_DRIVER_TYPE_WARP;
 						continue;
 					}
 
-					++ii;
+					break;
 				}
 				BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device.");
 
@@ -692,7 +708,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 
 			hr = adapter->GetDesc(&m_adapterDesc);
 			BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device.");
-			g_caps.vendorId = (uint16_t)m_adapterDesc.VendorId;
+			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)

+ 9 - 3
src/renderer_d3d9.cpp

@@ -357,8 +357,11 @@ namespace bgfx { namespace d3d9
 
 			BGFX_FATAL(m_d3d9, Fatal::UnableToInitialize, "Unable to create Direct3D.");
 
-			m_adapter = D3DADAPTER_DEFAULT;
-			m_deviceType = D3DDEVTYPE_HAL;
+			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)
@@ -403,7 +406,10 @@ namespace bgfx { namespace d3d9
 			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 = (uint16_t)m_identifier.VendorId;
+			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[] =