1

如果我像这样创建我的设备和我的 SwapChain:

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);

我得到了预期的调试文本:在此处输入图像描述

现在,如果我像这样创建我的设备和我的 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);
4

1 回答 1

0

使用Device创建、替换的第二种方法

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

Device _device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug);

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

我必须说这是一个非常微妙的差异,我只是通过比较 2 个图形事件列表才发现的......

于 2015-02-12T12:56:26.230 回答