【发布时间】:2018-08-31 16:41:19
【问题描述】:
我正在尝试使用 SharpDx 在 SwapChainPanel 中渲染 DirectX12,但由于未知原因创建 SwapChain 失败。这是我所拥有的简化版本:
// select adapter based on some simple scoring mechanism
SelectedAdapter = SelectAdapter();
// create device
using (var defaultDevice = new Device(SelectedAdapter, FeatureLevel.Level_12_0))
Device = defaultDevice.QueryInterface<SharpDX.Direct3D12.Device2>();
// describe swap chain
SwapChainDescription1 swapChainDescription = new SwapChainDescription1
{
AlphaMode = AlphaMode.Ignore,
BufferCount = 2,
Format = Format.R8G8B8A8_UNorm,
Height = (int)(MainSwapChainPanel.RenderSize.Height),
Width = (int)(MainSwapChainPanel.RenderSize.Width),
SampleDescription = new SampleDescription(1, 0),
Scaling = Scaling.Stretch,
Stereo = false,
SwapEffect = SwapEffect.FlipSequential,
Usage = Usage.RenderTargetOutput
};
// create swap chain
using (var factory2 = SelectedAdapter.GetParent<Factory2>())
{
/*--> throws exception:*/
SwapChain1 swapChain1 = new SwapChain1(factory2, Device, ref swapChainDescription);
SwapChain = swapChain1.QueryInterface<SwapChain2>();
}
// tie created swap chain with swap chain panel
using (ISwapChainPanelNative nativeObject = ComObject.As<ISwapChainPanelNative>(MainSwapChainPanel))
nativeObject.SwapChain = SwapChain;
适配器的选择按预期工作(我有 2 个适配器 + 软件适配器)。我可以创建一个设备,我可以看到任务管理器中的应用程序正在使用该选定的适配器。
交换链的创建主要基于此文档:https://docs.microsoft.com/en-us/windows/uwp/gaming/directx-and-xaml-interop#swapchainpanel-and-gaming
我得到 factory2(列举了所有的适配器和其他东西)。 SwapChain1 的构造函数在内部使用 factory2 创建交换链:https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.DXGI/SwapChain1.cs#L64
我将此方法与其他几个示例和教程进行了比较,这是应该完成的方式,但是,无论我选择什么格式或适配器,我都会不断收到此异常:
{SharpDX.SharpDXException:HRESULT:[0x887A0001],模块: [SharpDX.DXGI],ApiCode:[DXGI_ERROR_INVALID_CALL/InvalidCall], 消息:应用程序进行了无效的调用。无论是 调用的参数或某些对象的状态不正确。 启用 D3D 调试层以便通过调试消息查看详细信息。
在 SharpDX.Result.CheckError() 在 SharpDX.DXGI.Factory2.CreateSwapChainForComposition(IUnknown deviceRef、SwapChainDescription1& descRef、输出限制输出引用、 SwapChain1 swapChainOut) 在 SharpDX.DXGI.SwapChain1..ctor(Factory2 工厂、ComObject 设备、SwapChainDescription1& 描述、输出 在 UI.MainPage.CreateSwapChain()}
中的 restrictToOutput)
DebugLayer 不显示任何附加信息。
应用程序本身是常规的 Windows 通用空白应用程序(最低目标版本 Creators Update 15063)。我知道我可以在我当前的硬件上运行 Directx12(C++ hello world 工作得很好)。
有什么想法吗?
【问题讨论】:
-
上次我在创建 SwapChain 时遇到问题,我必须先创建一个新的 DeviceContext。
标签: c# xaml uwp sharpdx directx-12