summaryrefslogtreecommitdiffstats
path: root/tools/gfx/render-d3d11.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-11-29 13:55:45 -0500
committerGitHub <noreply@github.com>2018-11-29 13:55:45 -0500
commitb51a582a0ed5943765c220152b1e15cda8c2a555 (patch)
treeca59123a576c3f05eba89c74c4550b578dc7176f /tools/gfx/render-d3d11.cpp
parente5cc4660c634a0dd35a9813e03192d380f253332 (diff)
Use hardware if available for Dx11 testing (#733)
* Try using hardware device before reference on dx11 * Output error string on renderer construction failure
Diffstat (limited to 'tools/gfx/render-d3d11.cpp')
-rw-r--r--tools/gfx/render-d3d11.cpp61
1 files changed, 35 insertions, 26 deletions
diff --git a/tools/gfx/render-d3d11.cpp b/tools/gfx/render-d3d11.cpp
index 6ce482c6f..b0b2b9c04 100644
--- a/tools/gfx/render-d3d11.cpp
+++ b/tools/gfx/render-d3d11.cpp
@@ -458,35 +458,44 @@ SlangResult D3D11Renderer::initialize(const Desc& desc, void* inWindowHandle)
// `D3D11CreateDeviceAndSwapChain` up to twice: the first time with 11_1
// at the start of the list of requested feature levels, and the second
// time without it.
+ //
+ // We first try create using hardware and then software (reference) driver
+ // Test until we get a successful result
- for (int ii = 0; ii < 2; ++ii)
- {
- const HRESULT hr = D3D11CreateDeviceAndSwapChain_(
- nullptr, // adapter (use default)
- D3D_DRIVER_TYPE_REFERENCE,
-// D3D_DRIVER_TYPE_HARDWARE,
- nullptr, // software
- deviceFlags,
- &featureLevels[ii],
- totalNumFeatureLevels - ii,
- D3D11_SDK_VERSION,
- &swapChainDesc,
- m_swapChain.writeRef(),
- m_device.writeRef(),
- &featureLevel,
- m_immediateContext.writeRef());
-
- // Failures with `E_INVALIDARG` might be due to feature level 11_1
- // not being supported.
- if (hr == E_INVALIDARG)
+ {
+ Result res = SLANG_FAIL;
+ for (int ii = 0; ii < 4; ++ii)
+ {
+ const D3D_DRIVER_TYPE driverType = (ii & 2) ? D3D_DRIVER_TYPE_REFERENCE : D3D_DRIVER_TYPE_HARDWARE;
+ const int startFeatureIndex = (ii & 1);
+
+ res = D3D11CreateDeviceAndSwapChain_(
+ nullptr, // adapter (use default)
+ driverType,
+ nullptr, // software
+ deviceFlags,
+ &featureLevels[startFeatureIndex],
+ totalNumFeatureLevels - startFeatureIndex,
+ D3D11_SDK_VERSION,
+ &swapChainDesc,
+ m_swapChain.writeRef(),
+ m_device.writeRef(),
+ &featureLevel,
+ m_immediateContext.writeRef());
+
+ // Check if successfully constructed - if so we are done.
+ if (SLANG_SUCCEEDED(res))
+ {
+ break;
+ }
+ }
+ // If res is failure, means all styles have have failed, and so initialization fails.
+ if (SLANG_FAILED(res))
{
- continue;
+ return res;
}
-
- // Other failures are real, though.
- SLANG_RETURN_ON_FAIL(hr);
- // We must have a swap chain
- break;
+ // Check we have a swap chain, context and device
+ SLANG_ASSERT(m_immediateContext && m_swapChain && m_device);
}
// TODO: Add support for debugging to help detect leaks: