@@ -47,75 +47,27 @@ fn should_keep_adapter(adapter: &Dxgi::IDXGIAdapter1) -> bool {
47
47
}
48
48
49
49
pub enum DxgiAdapter {
50
- Adapter1 ( Dxgi :: IDXGIAdapter1 ) ,
51
- Adapter2 ( Dxgi :: IDXGIAdapter2 ) ,
50
+ /// Provided by DXGI 1.4
52
51
Adapter3 ( Dxgi :: IDXGIAdapter3 ) ,
52
+ /// Provided by DXGI 1.6
53
53
Adapter4 ( Dxgi :: IDXGIAdapter4 ) ,
54
54
}
55
55
56
- impl windows:: core:: Param < Dxgi :: IDXGIAdapter > for & DxgiAdapter {
57
- unsafe fn param ( self ) -> windows:: core:: ParamValue < Dxgi :: IDXGIAdapter > {
58
- unsafe { self . deref ( ) . param ( ) }
59
- }
60
- }
61
-
62
56
impl Deref for DxgiAdapter {
63
- type Target = Dxgi :: IDXGIAdapter ;
57
+ type Target = Dxgi :: IDXGIAdapter3 ;
64
58
65
59
fn deref ( & self ) -> & Self :: Target {
66
60
match self {
67
- DxgiAdapter :: Adapter1 ( a) => a,
68
- DxgiAdapter :: Adapter2 ( a) => a,
69
61
DxgiAdapter :: Adapter3 ( a) => a,
70
62
DxgiAdapter :: Adapter4 ( a) => a,
71
63
}
72
64
}
73
65
}
74
66
75
- impl DxgiAdapter {
76
- pub fn as_adapter2 ( & self ) -> Option < & Dxgi :: IDXGIAdapter2 > {
77
- match self {
78
- Self :: Adapter1 ( _) => None ,
79
- Self :: Adapter2 ( f) => Some ( f) ,
80
- Self :: Adapter3 ( f) => Some ( f) ,
81
- Self :: Adapter4 ( f) => Some ( f) ,
82
- }
83
- }
84
-
85
- pub fn unwrap_adapter2 ( & self ) -> & Dxgi :: IDXGIAdapter2 {
86
- self . as_adapter2 ( ) . unwrap ( )
87
- }
88
- }
89
-
90
67
pub fn enumerate_adapters ( factory : DxgiFactory ) -> Vec < DxgiAdapter > {
91
68
let mut adapters = Vec :: with_capacity ( 8 ) ;
92
69
93
70
for cur_index in 0 .. {
94
- if let DxgiFactory :: Factory6 ( ref factory6) = factory {
95
- profiling:: scope!( "IDXGIFactory6::EnumAdapterByGpuPreference" ) ;
96
- // We're already at dxgi1.6, we can grab IDXGIAdapter4 directly
97
- let adapter4: Dxgi :: IDXGIAdapter4 = match unsafe {
98
- factory6. EnumAdapterByGpuPreference (
99
- cur_index,
100
- Dxgi :: DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE ,
101
- )
102
- } {
103
- Ok ( a) => a,
104
- Err ( e) if e. code ( ) == Dxgi :: DXGI_ERROR_NOT_FOUND => break ,
105
- Err ( e) => {
106
- log:: error!( "Failed enumerating adapters: {}" , e) ;
107
- break ;
108
- }
109
- } ;
110
-
111
- if !should_keep_adapter ( & adapter4) {
112
- continue ;
113
- }
114
-
115
- adapters. push ( DxgiAdapter :: Adapter4 ( adapter4) ) ;
116
- continue ;
117
- }
118
-
119
71
profiling:: scope!( "IDXGIFactory1::EnumAdapters1" ) ;
120
72
let adapter1: Dxgi :: IDXGIAdapter1 = match unsafe { factory. EnumAdapters1 ( cur_index) } {
121
73
Ok ( a) => a,
@@ -130,31 +82,12 @@ pub fn enumerate_adapters(factory: DxgiFactory) -> Vec<DxgiAdapter> {
130
82
continue ;
131
83
}
132
84
133
- // Do the most aggressive casts first, skipping Adapter4 as we definitely don't have dxgi1_6.
134
-
135
- // Adapter1 -> Adapter3
136
- match adapter1. cast :: < Dxgi :: IDXGIAdapter3 > ( ) {
137
- Ok ( adapter3) => {
138
- adapters. push ( DxgiAdapter :: Adapter3 ( adapter3) ) ;
139
- continue ;
140
- }
141
- Err ( err) => {
142
- log:: warn!( "Failed casting Adapter1 to Adapter3: {}" , err) ;
143
- }
144
- }
145
-
146
- // Adapter1 -> Adapter2
147
- match adapter1. cast :: < Dxgi :: IDXGIAdapter2 > ( ) {
148
- Ok ( adapter2) => {
149
- adapters. push ( DxgiAdapter :: Adapter2 ( adapter2) ) ;
150
- continue ;
151
- }
152
- Err ( err) => {
153
- log:: warn!( "Failed casting Adapter1 to Adapter2: {}" , err) ;
154
- }
85
+ if let Ok ( adapter4) = adapter1. cast :: < Dxgi :: IDXGIAdapter4 > ( ) {
86
+ adapters. push ( DxgiAdapter :: Adapter4 ( adapter4) ) ;
87
+ } else {
88
+ let adapter3 = adapter1. cast :: < Dxgi :: IDXGIAdapter3 > ( ) . unwrap ( ) ;
89
+ adapters. push ( DxgiAdapter :: Adapter3 ( adapter3) ) ;
155
90
}
156
-
157
- adapters. push ( DxgiAdapter :: Adapter1 ( adapter1) ) ;
158
91
}
159
92
160
93
adapters
0 commit comments