我有一臺筆記本電腦與兩個適配器 - 英特爾和NVIDIA。我正在運行Windows 10,Bios中沒有關閉嵌入式Intel適配器的選項。我可以指定將NVIDIA適配器用於特定應用程序,或者指定爲所有Direct3D設備創建的默認設置。當我使用Intel適配器(這是Windows桌面的固定適配器)時,我的3D應用程序在窗口模式下工作正常。窗口渲染不同的適配器
如果我將NVIDIA全局設置更改爲強制適用於所有Direct3D設備的NVIDIA適配器,或者更改我的代碼以選擇NVIDIA適配器,則代碼執行時不會出現任何錯誤(我附帶了DirectX Debug設備),但是沒有任何渲染我的窗戶。
我認爲不可能將窗口化的交換鏈輸出連接到不是Windows桌面使用的適配器的適配器,但我從來沒有見過這樣做。
這意味着在使用Windows桌面嵌入式硬件適配器的筆記本電腦上,我無法使用Windows中功能更強大的NVIDIA適配器,並且必須使用全屏模式。
任何人都可以證實這一點,或者建議一種設備創建方法,它能夠成功地解決窗口中的第二個適配器問題嗎?
爲了清楚起見,我的設備創建代碼是;
private static void initializeDirect3DGraphicsDevice(System.Windows.Forms.Control winFormsControl, out Device device, out SharpDX.DXGI.SwapChain sc)
{
SharpDX.DXGI.SwapChainDescription destination = new SharpDX.DXGI.SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new SharpDX.DXGI.ModeDescription(
winFormsControl.ClientSize.Width,
winFormsControl.ClientSize.Height,
new SharpDX.DXGI.Rational(60, 1),
SharpDX.DXGI.Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = winFormsControl.Handle,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
SwapEffect = SharpDX.DXGI.SwapEffect.Discard,
Usage = SharpDX.DXGI.Usage.RenderTargetOutput
};
using (SharpDX.DXGI.Factory1 factory = new SharpDX.DXGI.Factory1())
{
// Pick the adapter with teh best video memory allocation - this is the NVIDIA adapter
List<SharpDX.DXGI.Adapter> adapters = factory.Adapters.OrderBy(item => (long)item.Description.DedicatedVideoMemory).Reverse().ToList();
SharpDX.DXGI.Adapter bestAdapter = adapters.First();
foreach(SharpDX.DXGI.Output output in bestAdapter.Outputs)
{
System.Diagnostics.Debug.WriteLine("Adapter " + bestAdapter.Description.Description.Substring(0,20) + " output " + output.Description.DeviceName);
}
device = new Device(bestAdapter, DeviceCreationFlags.Debug);
// Uncomment the below to allow the NVIDIA control panel to select the adapter for me.
//device = new Device(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug);
sc = new SharpDX.DXGI.SwapChain(factory, device, destination);
factory.MakeWindowAssociation(winFormsControl.Handle, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll);
System.Diagnostics.Debug.WriteLine("Device created with feature level " + device.FeatureLevel + " on adapter " + bestAdapter.Description.Description.Substring(0, 20));
System.Diagnostics.Debug.WriteLine("");
}
}
感謝您的詳細解釋。不幸的是,我已經使用了適配器枚舉並明確選擇了NVIDIA適配器,並且嘗試使用NVIDIA控制面板默認使用適配器來支持所有新的Direct3D設備創建。我懷疑是因爲我正瞄準一個窗口化的交換鏈(而不是全屏),並且Windows已經在使用英特爾適配器(無法更改),唯一有效的配置是使用英特爾適配器。我想我需要改變我的代碼,使其全屏使用您建議的方法。爲了清晰起見,我更新了設備創建代碼。 – PhillipH