Commit d9e34389 authored by Laszlo Agocs's avatar Laszlo Agocs

d3d: Add basic adapter selection

And avoid leaking the dxgiFactory.
parent 0930b4cb
...@@ -101,11 +101,40 @@ void QRhiD3D11::create() ...@@ -101,11 +101,40 @@ void QRhiD3D11::create()
if (debugLayer) if (debugLayer)
flags |= D3D11_CREATE_DEVICE_DEBUG; flags |= D3D11_CREATE_DEVICE_DEBUG;
HRESULT hr = CreateDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast<void **>(&dxgiFactory));
if (FAILED(hr)) {
qWarning("Failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr)));
return;
}
if (!importedDevice) { if (!importedDevice) {
IDXGIAdapter1 *adapterToUse = nullptr;
IDXGIAdapter1 *adapter;
int requestedAdapterIndex = -1;
if (qEnvironmentVariableIsSet("QT_D3D_ADAPTER_INDEX"))
requestedAdapterIndex = qEnvironmentVariableIntValue("QT_D3D_ADAPTER_INDEX");
for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
const QString name = QString::fromUtf16((char16_t *) desc.Description);
qDebug("Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags);
if (!adapterToUse && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) {
adapterToUse = adapter;
qDebug(" using this adapter");
} else {
adapter->Release();
}
}
if (!adapterToUse) {
qWarning("No adapter");
return;
}
ID3D11DeviceContext *ctx = nullptr; ID3D11DeviceContext *ctx = nullptr;
HRESULT hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, HRESULT hr = D3D11CreateDevice(adapterToUse, D3D_DRIVER_TYPE_UNKNOWN, nullptr, flags,
nullptr, 0, D3D11_SDK_VERSION, nullptr, 0, D3D11_SDK_VERSION,
&dev, &featureLevel, &ctx); &dev, &featureLevel, &ctx);
adapterToUse->Release();
if (FAILED(hr)) { if (FAILED(hr)) {
qWarning("Failed to create D3D11 device and context: %s", qPrintable(comErrorMessage(hr))); qWarning("Failed to create D3D11 device and context: %s", qPrintable(comErrorMessage(hr)));
return; return;
...@@ -120,25 +149,23 @@ void QRhiD3D11::create() ...@@ -120,25 +149,23 @@ void QRhiD3D11::create()
Q_ASSERT(dev && context); Q_ASSERT(dev && context);
featureLevel = dev->GetFeatureLevel(); featureLevel = dev->GetFeatureLevel();
} }
HRESULT hr = CreateDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast<void **>(&dxgiFactory));
if (FAILED(hr)) {
qWarning("Failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr)));
return;
}
qDebug("D3D11");
} }
void QRhiD3D11::destroy() void QRhiD3D11::destroy()
{ {
if (!importedDevice) { if (!importedDevice) {
if (context) if (context) {
context->Release(); context->Release();
context = nullptr; context = nullptr;
if (dev) }
if (dev) {
dev->Release(); dev->Release();
dev = nullptr; dev = nullptr;
}
}
if (dxgiFactory) {
dxgiFactory->Release();
dxgiFactory = nullptr;
} }
} }
......
...@@ -452,7 +452,7 @@ public: ...@@ -452,7 +452,7 @@ public:
ID3D11Device *dev = nullptr; ID3D11Device *dev = nullptr;
ID3D11DeviceContext1 *context = nullptr; ID3D11DeviceContext1 *context = nullptr;
D3D_FEATURE_LEVEL featureLevel; D3D_FEATURE_LEVEL featureLevel;
IDXGIFactory2 *dxgiFactory; IDXGIFactory2 *dxgiFactory = nullptr;
static const int FRAMES_IN_FLIGHT = QD3D11SwapChain::BUFFER_COUNT; static const int FRAMES_IN_FLIGHT = QD3D11SwapChain::BUFFER_COUNT;
int currentFrameSlot = 0; // 0..FRAMES_IN_FLIGHT-1 int currentFrameSlot = 0; // 0..FRAMES_IN_FLIGHT-1
......
...@@ -4,7 +4,6 @@ mtl: fix Dynamic for non-uniform buffers ...@@ -4,7 +4,6 @@ mtl: fix Dynamic for non-uniform buffers
mtl: forcing immut. to Shared should not need multiple backing buffers mtl: forcing immut. to Shared should not need multiple backing buffers
mtl: textures mtl: textures
mtl: mrt mtl: mrt
d3d: show something about adapter or such when starting up
d3d: msaa (onscreen) d3d: msaa (onscreen)
mtl: msaa (onscreen) mtl: msaa (onscreen)
test cubemap test cubemap
...@@ -43,6 +42,7 @@ bytecode (fxc/dxc) for d3d? ...@@ -43,6 +42,7 @@ bytecode (fxc/dxc) for d3d?
bytecode for metal? bytecode for metal?
+++ done +++ done
d3d: very basic adapter selection
what's up with instance step rate what's up with instance step rate
remove geometry shader from enum remove geometry shader from enum
hlsl version config to qsb hlsl version config to qsb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment