1

If I create my Device and my SwapChain like this:

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

I get the expected debugging text:enter image description here

Now if I create my Device and my SwapChain like this:

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

I don't get the expected debugging text:
enter image description here

In addition to not getting the expected debugging text, I get a load of new messages in my output:

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]

Where the last message repeats itself every frame...

Why is this happening? What's the difference between the 2 creation methods? How can I use the second creation method properly?

PS: I want to use the second creation method because I need the device to determine anti-aliasing settings...

PPS: In case it's needed, here's the code that creates the 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);
ManIkWeet
  • 1,298
  • 1
  • 15
  • 36
  • 1
    Have you checked which adapter is used? On some machine, the first adapter is not the default – xoofx Feb 12 '15 at 11:24
  • @xoofx _factory.Adapters has only one adapter inside of it, which, in my knowledge can only be the default in this case. – ManIkWeet Feb 12 '15 at 12:46
  • What is your GPU? Have you latest graphics drivers installed? – xoofx Feb 12 '15 at 23:39
  • @xoofx It happened first on a nVidia Quadro FX 1700, with the latest nVidia drivers. It also happens on a nVidia GTX 780, with the latest drivers. On the GTX 780 it's giving one extra message: `D3D11 ERROR: ID3D11Device::OpenSharedResource: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #381: DEVICE_OPEN_SHARED_RESOURCE_INVALIDARG_RETURN]`. My response is late because I couldn't reach stackoverflow... – ManIkWeet Feb 14 '15 at 13:09
  • 1
    Ah sorry, completely missed the original issue with debugging you were talking about (you should mention this in your question, because it is absolutely not clear that you are using VS integrated Graphics Debugger). The issue is most related to the graphics debugger that is only hooking Device.CreateWithSwapChain and nothing else. Doing the same with pure C++ native code would do the same. Just use a [RenderDoc](https://renderdoc.org/) which is currently much better than VS Graphics Debugger. – xoofx Feb 14 '15 at 13:25
  • I didn't know there was a different way to debug graphics. I'll check this one out then! Sorry for not mentioning I use Visual Studio, I thought it was the normal way people go. – ManIkWeet Feb 14 '15 at 15:15

1 Answers1

0

Using the second method of Device creating, replacing

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

with

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

makes the debug text appear again. It also seems to remove the warning messages and the first-chance exceptions

I must say this in an extremely subtle difference, which I only found through comparing the 2 Graphics Event Lists...

ManIkWeet
  • 1,298
  • 1
  • 15
  • 36