Sign in to follow this  
porters

[SlimDX] Distorted Graphics after conversion from DirectX

Recommended Posts

porters    120
Hi,

I just converted my application from DirectX to SlimDX. My application runs, but the graphics are very distored. I believe it may have something to do with the way im creating my device/present parameters but i've been tinkering with them for a couple of hours now to no avail. When i try to reset my device with my PParams, i get and invalidcall exception. Some research on previous posts also points to problems with device/Pparam creation with this error.

I am using the exact same device and present parameters settings i was using in MDX, so would expect no problems using them in SlimDX. See these images to see whats happening [url="http://img217.imageshack.us/img217/8848/mdxd3d9.png"]IMG_DirectX [/url] [url="http://img32.imageshack.us/img32/6407/slimdx.png"]IMG_SlimDX[/url].

Also, if it helps. The crosshairs (the white lines) you see in those images are supposed to be drawn at the cursor location. This happens in the directx version, but not the slimDX version. The cross hairs are drawn a fair way off the cursor location in SlimDX, and seem to be drawn further away from the cursor the more you move the mouse.

I have test various multisampling levels to no avail.

Any help would be much appreciated.

EDIT: I have also installed the latest graphics drivers for my video card with no effect.

Share this post


Link to post
Share on other sites
porters    120
[quote name='Christopher G.' timestamp='1311011478' post='4836906']
Could you post your D3DPRESENT_PARAMETERS?

Those pictures look exactly the same except one seems to be at low resolution.
[/quote]


Sure. These were the setting i used that produced that image previously posted. Yes i agree with you it looks like its drawn at a much lower resolution, but i dont know why. I've also posted the device creation code. I use VB.Net.


[size="2"][color="#0000ff"][size="2"][color="#0000ff"][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Private[/color][/size][/color][/size][size="2"][color="#000000"] [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function[/color][/size][/color][/size][size="2"][color="#000000"] InitD3Dpp() [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"][color="#000000"] PresentParameters[/color]

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"] [/color][color="#0000ff"]Dim[/color][/size][/color][/size][color="#000000"][size="2"][color="#0000ff"] [/color]myD3Dpp [/size][size="2"][size="2"][color="#0000ff"]As[/color][/size][/size][size="2"][color="#0000ff"] [/color]PresentParameters = [/size][/color][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]PresentParameters()

[/color][size="2"][size="2"] [color="#0000ff"]With[/color][/size][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Dpp

.EnableAutoDepthStencil = [/color][/size][size="2"][size="2"][color="#000000"]True
[/color][/size][/size][color="#000000"][size="2"] .AutoDepthStencilFormat = Format.D16
.BackBufferWidth = [/size][size="2"][size="2"]Me[/size][/size][/color][color="#000000"][size="2"].ClientRectangle.Width
.BackBufferHeight = [/size][size="2"][size="2"]Me[/size][/size][/color][color="#000000"][size="2"].ClientRectangle.Height
.BackBufferCount = 1
.BackBufferFormat = Format.X8R8G8B8
.DeviceWindowHandle = [/size][size="2"][size="2"]Me[/size][/size][/color][size="2"][color="#000000"].Handle
.PresentFlags = PresentFlags.DiscardDepthStencil
.PresentationInterval = PresentInterval.Default
.SwapEffect = SwapEffect.Discard
.Windowed = [/color][/size][size="2"][size="2"][color="#000000"]True
[/color][/size][/size][color="#000000"][size="2"] .Multisample = MultisampleType.None

[/size][size="2"][size="2"] [color="#0000ff"]End[/color][/size][/size][/color][size="2"][color="#0000ff"] [/color][/size][size="2"][size="2"][color="#0000ff"]With
[/color][color="#000000"]
[/color][/size][size="2"][/size][size="2"][size="2"] [color="#0000ff"]Return[/color][/size][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Dpp
[/color]
[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function




[size="2"][color="#0000ff"][size="2"][color="#0000ff"]Private[/color][/size][/color][/size][size="2"][color="#000000"] [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function[/color][/size][/color][/size][size="2"][color="#000000"] InitD3Ddev() [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"][color="#000000"] Device[/color]

[/size][color="#000000"][size="2"][size="2"][color="#0000ff"]Dim[/color][/size][/size][size="2"][color="#0000ff"] [/color]d3d [/size][size="2"][size="2"]As[/size][/size][size="2"] [/size][/color][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Direct3D
[/color][size="2"][size="2"][color="#0000ff"]Dim[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]myD3Ddev [/color][/size][size="2"][size="2"][color="#0000ff"]As[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Device [/color]= [/size][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Device(d3d, d3d.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware,[/color] [/size][/size][size="2"][size="2"][color="#0000ff"]Me[/color][/size][/size][color="#000000"][size="2"].Handle, CreateFlags.HardwareVertexProcessing, D3Dpp)
[/size][/color][size="2"][size="2"][color="#0000ff"]Return[/color][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Ddev[/color]

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function

[/color][/size][/color][/size]

[/color][/size][/color][/size]
[/color][/size][/color][/size]

Share this post


Link to post
Share on other sites
porters    120
[quote name='porters' timestamp='1311033279' post='4837104']
[quote name='Christopher G.' timestamp='1311011478' post='4836906']
Could you post your D3DPRESENT_PARAMETERS?

Those pictures look exactly the same except one seems to be at low resolution.
[/quote]


Sure. These were the setting i used that produced that image previously posted. Yes i agree with you it looks like its drawn at a much lower resolution, but i dont know why. I've also posted the device creation code. I use VB.Net.


[size="2"][color="#0000ff"][size="2"][color="#0000ff"][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Private[/color][/size][/color][/size][size="2"][color="#000000"] [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function[/color][/size][/color][/size][size="2"][color="#000000"] InitD3Dpp() [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"][color="#000000"] PresentParameters[/color]

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"] [/color][color="#0000ff"]Dim[/color][/size][/color][/size][color="#000000"][size="2"][color="#0000ff"] [/color]myD3Dpp [/size][size="2"][size="2"][color="#0000ff"]As[/color][/size][/size][size="2"][color="#0000ff"] [/color]PresentParameters = [/size][/color][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]PresentParameters()

[/color][size="2"][size="2"] [color="#0000ff"]With[/color][/size][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Dpp

.EnableAutoDepthStencil = [/color][/size][size="2"][size="2"][color="#000000"]True
[/color][/size][/size][color="#000000"][size="2"] .AutoDepthStencilFormat = Format.D16
.BackBufferWidth = [/size][size="2"][size="2"]Me[/size][/size][/color][color="#000000"][size="2"].ClientRectangle.Width
.BackBufferHeight = [/size][size="2"][size="2"]Me[/size][/size][/color][color="#000000"][size="2"].ClientRectangle.Height
.BackBufferCount = 1
.BackBufferFormat = Format.X8R8G8B8
.DeviceWindowHandle = [/size][size="2"][size="2"]Me[/size][/size][/color][size="2"][color="#000000"].Handle
.PresentFlags = PresentFlags.DiscardDepthStencil
.PresentationInterval = PresentInterval.Default
.SwapEffect = SwapEffect.Discard
.Windowed = [/color][/size][size="2"][size="2"][color="#000000"]True
[/color][/size][/size][color="#000000"][size="2"] .Multisample = MultisampleType.None

[/size][size="2"][size="2"] [color="#0000ff"]End[/color][/size][/size][/color][size="2"][color="#0000ff"] [/color][/size][size="2"][size="2"][color="#0000ff"]With
[/color][color="#000000"]
[/color][/size][size="2"][/size][size="2"][size="2"] [color="#0000ff"]Return[/color][/size][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Dpp
[/color]
[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function




[size="2"][color="#0000ff"][size="2"][color="#0000ff"]Private[/color][/size][/color][/size][size="2"][color="#000000"] [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function[/color][/size][/color][/size][size="2"][color="#000000"] InitD3Ddev() [/color][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"][color="#000000"] Device[/color]

[/size][color="#000000"][size="2"][size="2"][color="#0000ff"]Dim[/color][/size][/size][size="2"][color="#0000ff"] [/color]d3d [/size][size="2"][size="2"]As[/size][/size][size="2"] [/size][/color][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Direct3D
[/color][size="2"][size="2"][color="#0000ff"]Dim[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]myD3Ddev [/color][/size][size="2"][size="2"][color="#0000ff"]As[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Device [/color]= [/size][size="2"][size="2"][color="#0000ff"]New[/color][/size][/size][size="2"][color="#0000ff"] [/color][color="#000000"]Device(d3d, d3d.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware,[/color] [/size][/size][size="2"][size="2"][color="#0000ff"]Me[/color][/size][/size][color="#000000"][size="2"].Handle, CreateFlags.HardwareVertexProcessing, D3Dpp)
[/size][/color][size="2"][size="2"][color="#0000ff"]Return[/color][/size][/size][size="2"][color="#000000"][color="#0000ff"] [/color]myD3Ddev[/color]

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Function

[/color][/size][/color][/size]

[/color][/size][/color][/size]
[/color][/size][/color][/size]
[/quote]



Just further to this. I have since got the graphics displaying properly. It turns out that when the form was resizing (happens when i create a new form), the device was not being reset with the present params correctly. However i could not get the device.Reset method to work. I had to create a new device instead. I have read a few posts where people were having the same problem, but i couldnt really see how they solved it. It would be nice to get device.reset working. What generally causes problems with the device.reset method? I know the Presentparams settings are fine, i think the device creation code is fine. Can you get the exception i mentioned above thrown if there are still unmanaged resources that havent been disposed of? Perhaps thats it?

Share this post


Link to post
Share on other sites
Mike.Popoloski    3258
Yes. You must dispose of all D3D resources that are allocated in the default pool. If you run with the debug runtimes enabled, D3D will tell you which ones need to be disposed in the output window.

Share this post


Link to post
Share on other sites
porters    120
[quote name='Mike.Popoloski' timestamp='1311043769' post='4837154']
Yes. You must dispose of all D3D resources that are allocated in the default pool. If you run with the debug runtimes enabled, D3D will tell you which ones need to be disposed in the output window.
[/quote]


Thanks Mike. That solved the exception i was getting on the device.reset call. However, there is a new problem now. It seems that my device is not being reset when it should. Some investigation into this shows that although the device needs resetting (or is lost), TestCooperativeLevel is not picking it up, and a SlimDXException is not being thrown. See my lost device code below. I do my resource unloaded/loading in a couple of methods called OnDeviceLost and OnDeviceReset. These are methods i have created, not the methods that belong to certain SlimDX objects.

I have purposely put my device in a situation where it shoud be lost (minimize window etc.), but for some reason the lost/reset state is not being detected.

[size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] D3DDeviceLost [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] D3Ddev.TestCooperativeLevel = ResultCode.DeviceNotReset [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"]D3Dpp = InitD3Dpp()

D3Ddev.Reset(D3Dpp)

D3DDeviceLost = [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]False

[/color][/size][/color][/size][size="2"]OnDeviceReset()

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Else

[/color][/size][/color][/size][size="2"]Thread.Sleep(100)

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Return

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Try

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#008000"][size="2"][color="#008000"]'render here

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Catch[/color][/size][/color][/size][size="2"] ex [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"] SlimDXException

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] ex.ResultCode = ResultCode.DeviceLost [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"]OnDeviceLost()

D3DDeviceLost = [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]True

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Else

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Throw

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Try

[/color][/size][/color][/size]

Share this post


Link to post
Share on other sites
porters    120
[quote name='porters' timestamp='1311060911' post='4837250']
[quote name='Mike.Popoloski' timestamp='1311043769' post='4837154']
Yes. You must dispose of all D3D resources that are allocated in the default pool. If you run with the debug runtimes enabled, D3D will tell you which ones need to be disposed in the output window.
[/quote]


Thanks Mike. That solved the exception i was getting on the device.reset call. However, there is a new problem now. It seems that my device is not being reset when it should. Some investigation into this shows that although the device needs resetting (or is lost), TestCooperativeLevel is not picking it up, and a SlimDXException is not being thrown. See my lost device code below. I do my resource unloaded/loading in a couple of methods called OnDeviceLost and OnDeviceReset. These are methods i have created, not the methods that belong to certain SlimDX objects.

I have purposely put my device in a situation where it shoud be lost (minimize window etc.), but for some reason the lost/reset state is not being detected.

[size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] D3DDeviceLost [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] D3Ddev.TestCooperativeLevel = ResultCode.DeviceNotReset [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"]D3Dpp = InitD3Dpp()

D3Ddev.Reset(D3Dpp)

D3DDeviceLost = [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]False

[/color][/size][/color][/size][size="2"]OnDeviceReset()

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Else

[/color][/size][/color][/size][size="2"]Thread.Sleep(100)

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Return

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Try

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#008000"][size="2"][color="#008000"]'render here

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Catch[/color][/size][/color][/size][size="2"] ex [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]As[/color][/size][/color][/size][size="2"] SlimDXException

[/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If[/color][/size][/color][/size][size="2"] ex.ResultCode = ResultCode.DeviceLost [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Then

[/color][/size][/color][/size][size="2"]OnDeviceLost()

D3DDeviceLost = [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]True

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Else

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Throw

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]If

[/color][/size][/color][/size][size="2"][/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]End[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000ff"][size="2"][color="#0000ff"]Try

[/color][/size][/color][/size]
[/quote]


This thread can be closed out. I have since solved the issue mentioned above. The code i used above is fine, it just seems the device was not being lost when i expected it to be. Simple as that.

Thanks for the help all.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this