C# SharpDX调试:“;Device.CreateWithSwapChain()创建;对;新的交换链();?

C# SharpDX调试:“;Device.CreateWithSwapChain()创建;对;新的交换链();?,c#,directx,sharpdx,rendertarget,C#,Directx,Sharpdx,Rendertarget,如果我像这样创建设备和交换链: SwapChain _swapChain; Device _device; // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(500, 300, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowe

如果我像这样创建设备和交换链:

SwapChain _swapChain;
Device _device;
// SwapChain description
var desc = new SwapChainDescription()
{
    BufferCount = 1,
    ModeDescription = new ModeDescription(500, 300, new Rational(60, 1), Format.R8G8B8A8_UNorm),
    IsWindowed = true,
    OutputHandle = _windowHandle,
    SampleDescription = new SampleDescription(1, 0),
    Usage = Usage.RenderTargetOutput
};

Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug,
    desc, out _device, out _swapChain);
Factory _factory = new Factory();
Adapter adapter = _factory.GetAdapter(0);
SwapChain _swapChain;
Device _device = new Device(adapter, DeviceCreationFlags.Debug);

// SwapChain description
var desc = new SwapChainDescription()
{
    BufferCount = 1,
    ModeDescription = new ModeDescription(500, 300, new Rational(60, 1), Format.R8G8B8A8_UNorm),
    IsWindowed = true,
    OutputHandle = _windowHandle,
    SampleDescription = new SampleDescription(1, 0),
    Usage = Usage.RenderTargetOutput
};

_swapChain = new SwapChain(_factory, _device, desc);
我得到了预期的调试文本:

现在,如果我像这样创建设备和交换链:

SwapChain _swapChain;
Device _device;
// SwapChain description
var desc = new SwapChainDescription()
{
    BufferCount = 1,
    ModeDescription = new ModeDescription(500, 300, new Rational(60, 1), Format.R8G8B8A8_UNorm),
    IsWindowed = true,
    OutputHandle = _windowHandle,
    SampleDescription = new SampleDescription(1, 0),
    Usage = Usage.RenderTargetOutput
};

Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug,
    desc, out _device, out _swapChain);
Factory _factory = new Factory();
Adapter adapter = _factory.GetAdapter(0);
SwapChain _swapChain;
Device _device = new Device(adapter, DeviceCreationFlags.Debug);

// SwapChain description
var desc = new SwapChainDescription()
{
    BufferCount = 1,
    ModeDescription = new ModeDescription(500, 300, new Rational(60, 1), Format.R8G8B8A8_UNorm),
    IsWindowed = true,
    OutputHandle = _windowHandle,
    SampleDescription = new SampleDescription(1, 0),
    Usage = Usage.RenderTargetOutput
};

_swapChain = new SwapChain(_factory, _device, desc);
我没有得到预期的调试文本:

除了没有获得预期的调试文本外,我在输出中还收到了大量新消息:

First-chance exception at 0x7631C42D in Tester.exe: Microsoft C++ exception: _com_error at memory location 0x064EEC28.
First-chance exception at 0x7631C42D in Tester.exe: Microsoft C++ exception: _com_error at memory location 0x064EED6C.
First-chance exception at 0x7631C42D in Tester.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
D3D11 ERROR: ID3D11Device::OpenSharedResource: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #381: DEVICE_OPEN_SHARED_RESOURCE_INVALIDARG_RETURN]
D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is inaccessible because of a previous call to ReleaseSync or GetDC. [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD]
D3D11 WARNING: ID3D11DeviceContext::Draw: The Pixel Shader expects a Render Target View bound to slot 0, but none is bound. This is OK, as writes of an unbound Render Target View are discarded. It is also possible the developer knows the data will not be used anyway. This is only a problem if the developer actually intended to bind a Render Target View here. [ EXECUTION WARNING #3146081: DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET]
D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is inaccessible because of a previous call to ReleaseSync or GetDC. [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD]
最后一条消息每帧都会重复

为什么会这样?这两种创作方法有什么不同?如何正确使用第二种创建方法

PS:我想使用第二种创建方法,因为我需要设备来确定抗锯齿设置

PPS:如果需要,下面是创建RenderTargetView的代码:

using (Texture2D backBuffer = _swapChain.GetBackBuffer<Texture2D>(0))
{
    _renderTargetView = new RenderTargetView(_device, backBuffer);
}
_context = _device.ImmediateContext;
_context.OutputMerger.SetRenderTargets(_renderTargetView);
_context.Rasterizer.SetViewport(0, 0, 500, 300);
使用(Texture2D backBuffer=\u swapChain.GetBackBuffer(0))
{
_renderTargetView=新的renderTargetView(_设备,backBuffer);
}
_上下文=_device.ImmediateContext;
_context.outputMerge.SetRenderTargets(_renderTargetView);
_context.Rasterizer.SetViewport(0,0500300);

使用第二种方法创建、替换设备

Device _device = new Device(adapter, DeviceCreationFlags.Debug);

使调试文本再次显示。它似乎还删除了警告消息和第一次机会异常


我必须说这是一个极其微妙的区别,我只是通过比较两个图形事件列表发现了这一点…

您检查过使用哪个适配器了吗?在某些机器上,第一个适配器不是default@xoofx_factory.Adapters内部只有一个适配器,据我所知,这只能是本例中的默认适配器。您的GPU是什么?您是否安装了最新的图形驱动程序?@xoofx它首先出现在一台nVidia Quadro FX 1700上,并安装了最新的nVidia驱动程序。它也发生在nVidia GTX 780上,配备最新的驱动程序。在GTX 780上,它给出了一条额外的消息:
D3D11错误:ID3D11Device::OpenSharedResource:返回E_INVALIDARG,表示传递了无效参数。[状态\u创建错误\381:设备\u打开\u共享\u资源\u无效\u返回]
。我的回复很晚,因为我无法联系stackoverflow…啊,很抱歉,完全错过了您所谈论的调试的原始问题(您应该在问题中提到这一点,因为您绝对不清楚您是否正在使用VS integrated Graphics Debugger)。这个问题与图形调试器最相关,它只是挂接Device.CreateWithSwapChain,而不是其他任何东西。用纯C++本地代码执行同样的操作也会同样。只需使用一个比VS图形调试器更好的调试器。