Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Laszlo Agocs
qtrhi
Commits
d9e34389
Commit
d9e34389
authored
Nov 08, 2018
by
Laszlo Agocs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d3d: Add basic adapter selection
And avoid leaking the dxgiFactory.
parent
0930b4cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
15 deletions
+42
-15
src/rhi/qrhid3d11.cpp
src/rhi/qrhid3d11.cpp
+40
-13
src/rhi/qrhid3d11_p.h
src/rhi/qrhid3d11_p.h
+1
-1
todo.txt
todo.txt
+1
-1
No files found.
src/rhi/qrhid3d11.cpp
View file @
d9e34389
...
...
@@ -101,11 +101,40 @@ void QRhiD3D11::create()
if
(
debugLayer
)
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
)
{
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
;
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
,
&
dev
,
&
featureLevel
,
&
ctx
);
adapterToUse
->
Release
();
if
(
FAILED
(
hr
))
{
qWarning
(
"Failed to create D3D11 device and context: %s"
,
qPrintable
(
comErrorMessage
(
hr
)));
return
;
...
...
@@ -120,25 +149,23 @@ void QRhiD3D11::create()
Q_ASSERT
(
dev
&&
context
);
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
()
{
if
(
!
importedDevice
)
{
if
(
context
)
if
(
context
)
{
context
->
Release
();
context
=
nullptr
;
if
(
dev
)
context
=
nullptr
;
}
if
(
dev
)
{
dev
->
Release
();
dev
=
nullptr
;
dev
=
nullptr
;
}
}
if
(
dxgiFactory
)
{
dxgiFactory
->
Release
();
dxgiFactory
=
nullptr
;
}
}
...
...
src/rhi/qrhid3d11_p.h
View file @
d9e34389
...
...
@@ -452,7 +452,7 @@ public:
ID3D11Device
*
dev
=
nullptr
;
ID3D11DeviceContext1
*
context
=
nullptr
;
D3D_FEATURE_LEVEL
featureLevel
;
IDXGIFactory2
*
dxgiFactory
;
IDXGIFactory2
*
dxgiFactory
=
nullptr
;
static
const
int
FRAMES_IN_FLIGHT
=
QD3D11SwapChain
::
BUFFER_COUNT
;
int
currentFrameSlot
=
0
;
// 0..FRAMES_IN_FLIGHT-1
...
...
todo.txt
View file @
d9e34389
...
...
@@ -4,7 +4,6 @@ mtl: fix Dynamic for non-uniform buffers
mtl: forcing immut. to Shared should not need multiple backing buffers
mtl: textures
mtl: mrt
d3d: show something about adapter or such when starting up
d3d: msaa (onscreen)
mtl: msaa (onscreen)
test cubemap
...
...
@@ -43,6 +42,7 @@ bytecode (fxc/dxc) for d3d?
bytecode for metal?
+++ done
d3d: very basic adapter selection
what's up with instance step rate
remove geometry shader from enum
hlsl version config to qsb
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment