MCPcopy Create free account
hub / github.com/carbonengine/trinity / InitializeDirect3D

Function InitializeDirect3D

trinityal/dx12/Tr2VideoAdapterInfoALDx12.cpp:112–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112ALResult InitializeDirect3D()
113{
114 s_adapters.resize( 0 );
115 s_deviceInfo.resize( 0 );
116
117 s_factory = nullptr;
118
119 CR_RETURN_HR( CreateDXGIFactory1(
120 __uuidof( IDXGIFactory1 ),
121 (void**)( &s_factory ) ) );
122
123 if( !s_factory )
124 {
125 return E_FAIL;
126 }
127
128 CComPtr<IDXGIAdapter1> adapterPtr;
129
130 uint32_t adapterIndex = 0;
131 while( SUCCEEDED( s_factory->EnumAdapters1( adapterIndex++, &adapterPtr ) ) )
132 {
133 CComPtr<ID3D12Device> device;
134 if( FAILED( D3D12CreateDevice( adapterPtr, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS( &device ) ) ) )
135 {
136 continue;
137 }
138
139 DXGI_ADAPTER_DESC1 adapterDesc;
140 CR_RETURN_HR( adapterPtr->GetDesc1( &adapterDesc ) );
141
142 CCP_LOG( "Found video adapter \"%S\"", adapterDesc.Description );
143
144 DeviceInfo deviceInfo;
145 memset( deviceInfo.m_formatSupport, 0, sizeof( deviceInfo.m_formatSupport ) );
146 for( unsigned i = 0; i < DeviceInfo::FORMAT_COUNT; ++i )
147 {
148 D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { static_cast<DXGI_FORMAT>( i ), D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE };
149 device->CheckFeatureSupport( D3D12_FEATURE_FORMAT_SUPPORT, &formatSupport, sizeof( formatSupport ) );
150 deviceInfo.m_formatSupport[i] = formatSupport.Support1;
151 }
152
153 CComPtr<IDXGIOutput> outputPtr;
154 uint32_t outputIndex = 0;
155 bool hasValidOutputs = false;
156 while( SUCCEEDED( adapterPtr->EnumOutputs( outputIndex++, &outputPtr ) ) )
157 {
158 AdapterInfo adapter;
159 adapter.m_adapter = adapterPtr;
160 adapter.m_desc = adapterDesc;
161 adapter.m_output = outputPtr;
162 adapter.m_deviceInfoIndex = s_deviceInfo.size();
163
164 CR_RETURN_HR( outputPtr->GetDesc( &adapter.m_outputDesc ) );
165
166 CCP_LOG( "Found video adapter output \"%S\"", adapter.m_outputDesc.DeviceName );
167
168 CR_RETURN_HR( PopulateDisplayModes( adapter, DXGI_FORMAT_B8G8R8A8_UNORM ) );
169 if( !adapter.m_displayModes[DXGI_FORMAT_B8G8R8A8_UNORM].empty() )

Callers 2

RefreshDataMethod · 0.70
GetVideoAdapterFunction · 0.70

Calls 4

sizeMethod · 0.80
emptyMethod · 0.80
ReleaseMethod · 0.80
PopulateDisplayModesFunction · 0.70

Tested by

no test coverage detected