Jump to content

  • Log In with Google      Sign In   
  • Create Account

Porting from DirectX9 to DirectX10 questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 September 2014 - 07:15 AM

Hi everybody!

 

So I am at my third or fourth attempt at porting my base application from DirectX9 to DirectX10 and while this is going better than the rest, I'm still having tons of problems.

 

I managed to get basic rendering working, but not I need to allow for the possibility of changing the device settings.

 

So here are a few questing:

 

1. How do you "recreate" the device?

 

In DX9 you could change render targets and sucks, but generally you had to reset you device.

 

In DX10 I think you can use swapChain.ResizeBuffers for simple cases, like user window resize. That fails silently for me, so I guess I need to clear up some resources.

 

I did dome Googleing and found that I need to Dispose all the resources created when the swap chain was created.

 

This works fine, but I was wondering how to manage a lot of render targets. The engine can use anywhere from 1 to around 10 for a full suite of effects. Should this be done with the swapchain or should one keep the swap chain buffer count low and manage render targets manually.

 

Secondly, how to really "Recreate" the device? Like when changing MSAA mode? All my attempts to recreate the swap chain resulted in the display driver crashing. And how to handle going from fullscreen to windowed with or without render target size change?

 

2. Effect is a lot weirder in DX10. Should I update my engine to use vertex and pixel shaders instead of effects?

 

3. Font.DrawText ruins the device context. I tried setting device.Rasterizer.State and device.OutputMerger.DepthStencilState at the beginning of the draw function but this is not enough. I temporarily fixed this by using Sprite and calling Begin/End with a parameter so it backs up the device state, but it would be better if I could set all device context variables so that rendering works without the use of Sprite.

 

4. DX9 was using BGRA colors and DX10 uses RGBA colors?



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31800

Like
2Likes
Like

Posted 05 September 2014 - 08:12 AM


That fails silently for me ... All my attempts to recreate the swap chain resulted in the display driver crashing.
Do you check every single HRESULT return value? During devleopment, it's also good to pass the D3D10_CREATE_DEVICE_DEBUG flag when creating your device, which should cause errors to print useful messages too.

1. Swap chains are just for render-targets that you're going to display to the screen. Often you just have one swap chain in the app.

2. Depends how many of the effect features you rely upon. If you use techniques/passes/states/etc and rely on setting all your constants by name, then switching away from Effect might be a lot of work...

3. What does "ruins the device context" mean?

4. DX9 and DX10 support both... bur RGBA is preferred. e.g. in D3D9 D3DDECLTYPE_UBYTE4N was an RGBA vertex format, but D3DDECLTYPE_D3DCOLOR was a special BGRA alternative.



#3 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 05 September 2014 - 08:41 AM

Thanks for the answers!

 

It is SharpDX, so if something fails one of two things happen: I get an exception or application continues but it does not behave correctly. If I debug this I get some stray jumps like with memory corruption.

 

1. OK, so then I'll keep the swap chain with a buffer size of 1 and resize my additional render targets when needed by disposing them and recreating them.

 

I found out how to recreate the swap chain without a crash. The solution was very anticlimactic: 

swapChain = new SwapChain(factory, device, pp);

 

where the parameters are the one from the original creation of the swap chain.

 

One caveat is that I must switch off fullscreen mode when doing this to avoid a crash. This is a bit problematic because when switching MSAA in fullscreen mode you get nasty flickers, but I can live with that.

 

2. There are quite a few. Shaders must be rewritten to remove device context changes from effect files and leave raw shaders, doing the rest in code. Is this worth it going forward? DX11 and 12 I believe do not rely on the effects framework.

 

3. It means that after the first DrawText, nothing renders anymore. It get the first frame rendered correctly, then the first DrawText changes the device somehow and I was wondering if someone has a complete list of changes so I can start the frame by undoing them.

 

4. In DX9 the default format is X8R8G8B8/A8R8G8B8 which is a BGRA format apparently. In DX10 I believe the default is R8G8B8A8_UNorm, which is a RGBA format. DX10 can render in BGRA but it fails on my device at device creation.

 

And I have an additional question:

5. Are random MSAA sample values theoretically supported in DX10?

In DX9 to make my code complete I test support for all MultisampleType values, even weird ones like MultisampleType.FiveSamples and MultisampleType.SevenSamples. I don't thing there is any GPU out there that supports these...

 

In DX10 I just test 1, 2, 4, 8 and 16. Did they clean up the spec to avoid odd values or should I test 1 though 16 just to be safe? Maybe someone with a 5000 dollar GPU out there can render with 13 samples MSAA :).



#4 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 08 September 2014 - 02:56 AM

DirectX 10 is not working for me well enough. Again!

 

So I decided to step back for a minute and write a minimal C++ test, just setting up DX10 and making sure that everything is 100% stable. And it is not.

 

After about 1-2 minutes of running my application crashes the display driver. Swap chain Present fails with "device removed" error. I tried catching the error and resetting the device, only to have it crash again after 1-2 minutes, so the error is not something that happens once.

 

After further testing, I noticed that the crash only happens if FRAPS is on (not recording). Fraps is a pretty good sanity checker because improperly set up devices often crash.

 

My first tests were ran on a laptop that is notoriously lenient with bad devices. A few years ago I broke my Dx9 app and it crashed on everything except this laptop. Even on the laptop it crahed if I recorded with Fraps though :). On this laptop the crash comes after 1-2 minutes.

 

On another desktop computer, FRAPS completely refuses to display the frame counter, but there is no crash. It fails to record (records blank screens). But something happened and without changing display initialization the application fails to show up lately.

 

On a third computer, the app runs fine, no crashes with or without Fraps.

 

My bet is on the device not being set up correctly though, but I have no idea why?

 

Here is my code: https://dl.dropboxusercontent.com/u/45638513/CTut01.zip

 

If anyone has an idea what is wrong, it would be greatly appreciated.

 

Thank you!



#5 DwarvesH   Members   -  Reputation: 471

Like
0Likes
Like

Posted 09 September 2014 - 03:28 PM

Still no luck. I have spent a lot of hours looking at and debugging that very short piece of code. So I thought I'd give PIX a try for the first time ever.

 

But this too did not work that well, failing to set up the device:

 

 

PIX Logfile created at: 00:10:04

 
Frame 000001 ....PRE: Frame(1)
Frame 000001 ........PRE: D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 514, 29, 0x0036FAE8, 0x0036FD74, 0x0036FD70)
Frame 000001 ............PRE: AddObject(D3D11 Device, 0x00DDFF58, 0x0048B6B4)
Frame 000001 ............POST: <TRUE> AddObject(D3D11 Device, 0x00DDFF58, 0x0048B6B4)
Frame 000001 ............PRE: AddObject(DXGI Factory, 0x03F4EF58, 0x00473330)
Frame 000001 ............POST: <TRUE> AddObject(DXGI Factory, 0x03F4EF58, 0x00473330)
Frame 000001 ............PRE: AddObject(DXGI Adapter, 0x03EF6098, 0x0047B5E0)
Frame 000001 ............POST: <TRUE> AddObject(DXGI Adapter, 0x03EF6098, 0x0047B5E0)
Frame 000001 ............PRE: AddObject(DXGI Device, 0x03EF6200, 0x0048B6B0)
Frame 000001 ............POST: <TRUE> AddObject(DXGI Device, 0x03EF6200, 0x0048B6B0)
Frame 000001 ............PRE: AddObject(DXGI Swap Chain, 0x03EF6370, 0x00497B20)
Frame 000001 ............POST: <TRUE> AddObject(DXGI Swap Chain, 0x03EF6370, 0x00497B20)
Frame 000001 ............PRE: AddObject(DXGI Surface, 0x03EF6518, 0x004782C8)
Frame 000001 ............POST: <TRUE> AddObject(DXGI Surface, 0x03EF6518, 0x004782C8)
Frame 000001 ............PRE: AddObject(D3D10 Texture2D, 0x03EF6688, 0x00478270)
Frame 000001 ............POST: <TRUE> AddObject(D3D10 Texture2D, 0x03EF6688, 0x00478270)
Frame 000001 ............PRE: AddObject(D3D11 Device Context, 0x03F4EFA8, 0x0048C420)
Frame 000001 ............POST: <TRUE> AddObject(D3D11 Device Context, 0x03F4EFA8, 0x0048C420)
Frame 000001 ........PRE: <this=0x00ddff58>ID3D11Device::QueryInterface(IID_ID3D10Device, 0x0036FD70)
Frame 000001 ........POST: <S_OK><this=0x00ddff58> ID3D11Device::QueryInterface(IID_ID3D10Device, 0x0036FD70)
Frame 000001 ........PRE: <this=0x00ddff58>ID3D11Device::Release()
Frame 000001 ........POST: <3><this=0x00ddff58> ID3D11Device::Release()
Frame 000001 ........PRE: AddObject(D3D10 Device, 0x03EE75D8, 0x0048B73C)
Frame 000001 ........POST: <TRUE> AddObject(D3D10 Device, 0x03EE75D8, 0x0048B73C)
Frame 000001 ........PRE: AddObject(DXGI Factory, 0x03F56F08, 0x00473330)
Frame 000001 ........POST: <TRUE> AddObject(DXGI Factory, 0x03F56F08, 0x00473330)
Frame 000001 ........PRE: AddObject(DXGI Adapter, 0x03F56F58, 0x0047B5E0)
Frame 000001 ........POST: <TRUE> AddObject(DXGI Adapter, 0x03F56F58, 0x0047B5E0)
Frame 000001 ........PRE: AddObject(DXGI Device, 0x03EF6C18, 0x0048B6B0)
Frame 000001 ........POST: <TRUE> AddObject(DXGI Device, 0x03EF6C18, 0x0048B6B0)
Frame 000001 ........PRE: AddObject(DXGI Swap Chain, 0x03EF6D88, 0x03EF6370)
Frame 000001 ........POST: <TRUE> AddObject(DXGI Swap Chain, 0x03EF6D88, 0x03EF6370)
Frame 000001 ........PRE: <this=0x03ef6370>IDXGISwapChain::GetDesc(0x0036F8E4)
Frame 000001 ........POST: <S_OK><this=0x03ef6370> IDXGISwapChain::GetDesc(0x0036F8E4)
Frame 000001 ........PRE: <this=0x03ef6370>IDXGISwapChain::GetBuffer(0, IID_IDXGISurface, 0x0036F8DC)
Frame 000001 ........POST: <S_OK><this=0x03ef6370> IDXGISwapChain::GetBuffer(0, IID_IDXGISurface, 0x0036F8DC)
Frame 000001 ........PRE: AddObject(DXGI Surface, 0x03EF6F30, 0x03EF6518)
Frame 000001 ........POST: <TRUE> AddObject(DXGI Surface, 0x03EF6F30, 0x03EF6518)
Frame 000001 ........PRE: <this=0x03ef6518>IDXGISurface::QueryInterface(IID_ID3D10Texture2D, 0x0036F8AC)
Frame 000001 ........POST: <S_OK><this=0x03ef6518> IDXGISurface::QueryInterface(IID_ID3D10Texture2D, 0x0036F8AC)
Frame 000001 ........PRE: AddObject(D3D10 Texture2D, 0x03EE8B48, 0x03EF6688)
Frame 000001 ............PRE: <this=0x03ef6688>ID3D10Texture2D::GetDesc(0x03EE8BA0)
Frame 000001 ............POST: <><this=0x03ef6688> ID3D10Texture2D::GetDesc(0x03EE8BA0)
Frame 000001 ........POST: <TRUE> AddObject(D3D10 Texture2D, 0x03EE8B48, 0x03EF6688)
Frame 000001 ........PRE: <this=0x03ef6688>ID3D10Texture2D::Release()
Frame 000001 ........POST: <1><this=0x03ef6688> ID3D10Texture2D::Release()
Frame 000001 ........PRE: <this=0x03ef6518>IDXGISurface::Release()
Frame 000001 ........POST: <0><this=0x03ef6518> IDXGISurface::Release()
Frame 000001 ....POST: <S_OK> D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 514, 29, 0x0036FAE8, 0x0036FD74, 0x0036FD70)
Frame 000001 ....PRE: <this=0x03ef6d88>IDXGISwapChain::GetBuffer(0, IID_ID3D10Texture2D, 0x0036FD7C)
Frame 000001 ........PRE: <this=0x03ef6370>IDXGISwapChain::GetBuffer(0, IID_ID3D10Texture2D, 0x0036FD7C)
Frame 000001 ........POST: <S_OK><this=0x03ef6370> IDXGISwapChain::GetBuffer(0, IID_ID3D10Texture2D, 0x0036FD7C)
Frame 000001 ....POST: <S_OK><this=0x03ef6d88> IDXGISwapChain::GetBuffer(0, IID_ID3D10Texture2D, 0x0036FD7C)
Frame 000001 ....PRE: <this=0x03ee75d8>ID3D10Device::CreateRenderTargetView(0x03EE8B48, NULL, 0x0036FD80)
D3D11 CORRUPTION: ID3D10Device::CreateRenderTargetView: First parameter is corrupt! [ MISCELLANEOUS CORRUPTION #13: CORRUPTED_PARAMETER1]
An unhandled exception occurred.
 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS