Sign in to follow this  
JoshuaBaker

Dual monitors and full screen input issues

Recommended Posts

I came across the issue in another thread involving mouse cursors. It grew into a wider problem so I thought it deserved its own thread.

I am running a dual monitor setup and my code is using slimdx and c#. When I run the code in fullscreen mode I get a ridiculous amount of choppyness when ever I move the mouse or hold down a key. When I am no longer sending input event everything is silky smooth. This problem does not show up in window mode or if I DISCONNECT MY SECOND MONITOR o.0 this is causing me no end of confusion any help would be appreciated

Share this post


Link to post
Share on other sites
[quote name='Mike.Popoloski' timestamp='1342726038' post='4961039']
What does your message loop look like?
[/quote]

Thanks for trying to help Mike, hopefully you can help figure out where iv gone wrong...
My message loop looks like this.

[CODE]
public void Run() {
Initialize();
Load();
Stopwatch time = Stopwatch.StartNew();
const float deltaTime = 0.03f;
float oldTime = 0.0f;
float newTime = 0.0f;
float frameTime = 0.0f;
float accumulator = 0.0f;
MessagePump.Run(Form, () => {
newTime = (float)time.Elapsed.TotalSeconds;
frameTime = newTime - oldTime;
oldTime = newTime;
accumulator += frameTime;
while (accumulator >= deltaTime) {
_update(deltaTime);
accumulator -= deltaTime;
}
if(GraphicsDevice.IsDeviceLost()) {
Thread.Sleep(100);
}
else {
GraphicsDevice.ClearBuffer(Color.Black);
_render(accumulator / deltaTime);
GraphicsDevice.PresentBuffer();
}
});
time.Stop();
Unload();
}
[/CODE]

I am implementing the fixed time-step from gafferongames (attempting to if i got it all wrong [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] ) Some of the lost device stuff is inside my GraphicsDevice class if you think the culprit is something to do with that i can post more information.

Share this post


Link to post
Share on other sites
As far as i know it is, it's my main monitor and I have the adaptor set for 0

[CODE]
Device = new Device(direct3d, 0, DeviceType.Hardware, _form.Handle, CreateFlags.HardwareVertexProcessing, fullscreenparameters);
[/CODE]

I tried playing around with the adapter, tried setting it to 1 (my second monitor) and it showed up there ok, oddly it seemed to lessen the effect, I still had some jumpy movement every few seconds when moving the mouse, but it was dramatically different. I then turned on GPU aspect scaling for the second monitor (it was stretching it before) and the horrible effects started to happen on that monitor. o.0 Turning off GPU scaling on my primary monitor didnt change anything.

Then I did another test....if i set

[CODE]
fullscreenparameters.PresentationInterval = PresentInterval.Default;

TO

fullscreenparameters.PresentationInterval = PresentInterval.Immediate;
[/CODE]

Everything is perfect, no problems at all, so v-sync seems to cause me some problem. o.0 Perhaps it is the root culprit in some way.

Dual Monitors + Fullscreen + PresentInterval.Default = Choppy rendering when I receive input events :/
Change any variable and everything is peachy LOL weird.

Share this post


Link to post
Share on other sites
Everything is up to date, i did some more digging and found this
[url="http://www.gamedev.net/topic/592845-vsync-causing-input-lag/"]http://www.gamedev.net/topic/592845-vsync-causing-input-lag/[/url]

It starts as a lag problem, which is not really what i am seeing, input is pretty responsive, it just causes stuttering, but he later finds that the problem goes away when disconnecting his second monitor. Zone seems to blame it on the message queue, does the message queue in the Form get cleared out each iteration? It seems like slimdx is passing alot of message onto the base Form class.

Share this post


Link to post
Share on other sites
To narrow down your problem I would remove everything from your render loop, then add functionality back one by one, testing for the lag. There is really only a couple of things that can be the problem:
[list]
[*]Garbage collection (if the lag is random)
[*]CPU is outrunning the GPU (consider a new thread for a message queue that can process the input)
[*]Bad driver
[/list]

[b]In any event you should use PIX to profile your code and see where the delay is coming from.[/b]

I have 2 monitors and have never had this problem. When I ask DX for a list of adapters there are 2 adaptors returned with the same name and if I choose the second one the device creation fails so I use the default without issue. DX will give you the default adaptor.

It also might be helpful if you post more information about your rig, like your graphic card, monitors and OS info.

Share this post


Link to post
Share on other sites
I don't know if you've seen my post [url="http://www.gamedev.net/topic/627917-mousegetcurrentstate-producing-zeros-in-fullscreen/page__p__4958948#entry4958948"]http://www.gamedev.n...48#entry4958948[/url] but I didn't find a solution to this problem either. I should repeat here that i found the mouse-state to be returning empty. And I'll second your finding that it's not actually the apps performance, I checked this by just animating an image-slider control programmatically, it would move smoothly, but as i dragged the image across the screen, it would keep stopping because of course the mouseState was empty.

I gave up on that problem [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] However, I have just recently gotten my hands on some SlimDX code that does correct fullscreen switching and uses direct input but I've been working on a deferred shader (just finished last night actually) so I haven't had time to check it out. I might have a look tonight and see how he does it and I'll report back if I can locate a fix for this issue (if it's the same issue of course).

Edit. he switches in one line, so there's no magic there that i can see. But I don't notice his app jerking like mine does, his is 3d, while mine is a gui and i haven't yet traced the entire loop so I can't tell yet if there is something different or if he is somehow avoiding the problem. Edited by Gavin Williams

Share this post


Link to post
Share on other sites
[quote name='Gavin Williams' timestamp='1343020480' post='4962140']
Try using raw input. It wrote some raw-input code today and it has fixed my problem.
[/quote]

I'm using the system cursor, which is very choppy in fullscreen :P Its ok with vsync off, I had issues getting the DX9 mouse to work without flickering, but frankly this seems worse and causes the choppiness just like holding down keys does. :(

Share this post


Link to post
Share on other sites
[quote name='JWBaker' timestamp='1343081867' post='4962380']
[quote name='Gavin Williams' timestamp='1343020480' post='4962140']
Try using raw input. It wrote some raw-input code today and it has fixed my problem.
[/quote]

I'm using the system cursor, which is very choppy in fullscreen [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] Its ok with vsync off, I had issues getting the DX9 mouse to work without flickering, but frankly this seems worse and causes the choppiness just like holding down keys does. [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
[/quote]

Sounds like a possible bad driver to me. Have you updated your driver through windows when it was listed as an optional update? Is it possible to roll back your driver to the prior version? What is your graphics card make/model? Do you have 2 graphic cards? What operating system and version? Are other directX applications/games suffering from the same issue? What version of DX are you using with slimDX? What does the code look like where you process the input? If you don't do anything with the input does the issue still exist? What is the frame rate your are running and what is the refresh rate of your monitors/card? In your graphic card's control panel, do you override software settings or does your card allow the your application to enable / disable features? Have you tried using D3DPRESENT_INTERVAL_ONE?

The call to Present() will block until the appropriate time if you have vsync enabled - hence why I think this is a driver issue...

Share this post


Link to post
Share on other sites
So i double checked iv got the latest Drivers for my GTX560 Ti. v301.42

Windows 7 is the OS, no other DX games seem to have this problem.

Same issue, so i made a very simple Fullscreen test program which shows the most obvious symptom of my issue, the mouse movement being incredibly choppy..

[CODE]
using System;
using System.Windows.Forms;
using SlimDX.Windows;
using System.Threading;
using System.Drawing;
using SlimDX.Direct3D9;
using SlimDX;
using System.Runtime.InteropServices;
namespace DXTest {
static class Program {
static RenderForm Form;
static PresentParameters PresentParameters;
static Direct3D Direct3D;
static Device Device;
static bool DeviceLost = false;
[STAThread]
static void Main() {
Form = new RenderForm();
Form.ClientSize = new Size(800, 600);
Form.TopMost = true;
Form.FormBorderStyle = FormBorderStyle.None;
Form.StartPosition = FormStartPosition.WindowsDefaultLocation;
PresentParameters = new PresentParameters();
PresentParameters.BackBufferWidth = Form.ClientSize.Width;
PresentParameters.BackBufferHeight = Form.ClientSize.Height;
PresentParameters.BackBufferFormat = Format.X8R8G8B8;
PresentParameters.BackBufferCount = 1;
PresentParameters.Multisample = MultisampleType.None;
PresentParameters.MultisampleQuality = 0;
PresentParameters.SwapEffect = SwapEffect.Discard;
PresentParameters.DeviceWindowHandle = Form.Handle;
PresentParameters.Windowed = false;
PresentParameters.EnableAutoDepthStencil = false;
PresentParameters.AutoDepthStencilFormat = 0;
PresentParameters.PresentFlags = 0;
PresentParameters.FullScreenRefreshRateInHertz = 0;
PresentParameters.PresentationInterval = PresentInterval.Default;
Direct3D = new Direct3D();
Device = new Device(Direct3D, 0, DeviceType.Hardware, Form.Handle, CreateFlags.HardwareVertexProcessing, PresentParameters);
MessagePump.Run(Form, () => {
if (DeviceLost) {
if (Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) {
Device.Reset(PresentParameters);
DeviceLost = false;
}
else {
Thread.Sleep(100);
}
}
else {
try {
Device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
Device.BeginScene();
Device.EndScene();
Device.Present();
}
catch (Direct3D9Exception e) {
if (e.ResultCode == ResultCode.DeviceLost) {
DeviceLost = true;
}
else {
throw;
}
}
}
});
}

}
}
[/CODE]

When i run this simple program it goes fullscreen and the mouse is horrid when moving it around, yet if i turn off monitor 2...no issues whatsoever.

When running with both monitors, the FPS will keepa constant 60 while not doing anything, when i move the mouse or hold down a key it will dip below by 1 or 2 FPS, with 1 monitor this does not happen, its rock solid 60. Edited by JWBaker

Share this post


Link to post
Share on other sites
Looking at your code I do not see where you are trapping keys, mouse movement or raw input. Are you registered to any form events that process these requests?

Also when you say "full screen" are you referring to both monitors or just one? If it's just one then your game is being rendered to one while the other monitor is showing your desktop?

Have you tried to determine if it's the mouse movement or the key trapping that is causing the issue? Theoretically, these should be 2 separate events.

Please post the code where you are processing keys and mouse movement.

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1343245406' post='4963045']
Looking at your code I do not see where you are trapping keys, mouse movement or raw input. Are you registered to any form events that process these requests?

Also when you say "full screen" are you referring to both monitors or just one? If it's just one then your game is being rendered to one while the other monitor is showing your desktop?

Have you tried to determine if it's the mouse movement or the key trapping that is causing the issue? Theoretically, these should be 2 separate events.

Please post the code where you are processing keys and mouse movement.
[/quote]


Yes, this problem occurs [b]even when not registered to the form events[/b]. I am using the system mouse, so no need to process mouse movement myself. Fullscreen is one single monitor rendering while the other one is showing desktop. Mouse movement causes it, as well as key presses, its plain to see the issue just from this simple program just by looking at how the system mouse moves with both monitors present, compared to how it moves from a single monitor present. If you have 2 monitors check it out, if the mouse seems perfectly smooth then i know its something on my end, but this problem occurs on the other PC i have here as well with two monitors.

Share this post


Link to post
Share on other sites
Sorry JW I dont have SlimDX on this machine. Is there a SlimDx forum? Since you are not registered to any windows events that means that the app (form) is not the issue. It's either the driver or SlimDX.

Share this post


Link to post
Share on other sites
Also, digging around on the Nvidia forums there seems to be a service called "Nividia Display Driver Service" (nvsvc.exe) that is causing some dev problems. The service is responsible for spanning the desktop to two monitors and end users are reporting severe fps drops when moving the mouse in certain games.

You should probably investigate and see if you can figure out how to properly turn this service off and see if it's the culprit.

Be careful though as I'm sure this service is part of the nvidia control panel and could be used by other part of windows. You should get support through NVidia on how to properly bypass this service for testing purposes.

Share this post


Link to post
Share on other sites
I found another library that uses SlimDX, Gorgon is pretty advanced and has some examples you can run without Needing to compile...
here: [url="http://code.google.com/p/gorgonlib/downloads/list"]http://code.google.com/p/gorgonlib/downloads/list[/url]

I tried his example "Animated Debate" (make sure you turn on vsync in his advanced options, use the arrow in the setup window) and the performance was exactly like mine, Terrible when moving the mouse around. Turn off second monitor and it has no problem.

Share this post


Link to post
Share on other sites
What is the refresh rate on both monitors? Have you tried turning off Aero in windows 7 (the see through glass around windows)?

Vsync blocks Present() until the next vertical refresh. With a slower monitor refresh rate (< app's frame rate) your CPU is running ahead of the GPU. DX buffers up to a max of 3 frames of graphic commands (triple buffering), over that would induce FR drops and input lag. Turning on the second monitor only increases this lag because the OS is having to vSync 2 desktops (copying back buffers to surfaces).

To my knowledge, there is no way DX can get the time that the refresh happens and even if you could, you'd waste a lot of cycles- looping and doing nothing.
Is there a specific reason you want to use vSync? What are you trying to accomplish?

If you have to use it then you'll have to process your mouse and keyboard input in another thread which can be rather tricky because of deadlocks and the main thread (where Present() is ) blocked by vSync.

In my experience, I never use vSync. I lock the frame rate in code, measuring the elapsed time between each frame and use that ‘elapsed time’ to calculate the speed of movements and animations. Since I never use vSync I'm only familiar with what the documentation says it does not how it actually functions with other objects / code / situations.


Regards,
DJTN

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1343320115' post='4963358']
What is the refresh rate on both monitors? Have you tried turning off Aero in windows 7 (the see through glass around windows)?

Vsync blocks Present() until the next vertical refresh. With a slower monitor refresh rate (< app's frame rate) your CPU is running ahead of the GPU. DX buffers up to a max of 3 frames of graphic commands (triple buffering), over that would induce FR drops and input lag. Turning on the second monitor only increases this lag because the OS is having to vSync 2 desktops (copying back buffers to surfaces).

To my knowledge, there is no way DX can get the time that the refresh happens and even if you could, you'd waste a lot of cycles- looping and doing nothing.
Is there a specific reason you want to use vSync? What are you trying to accomplish?

If you have to use it then you'll have to process your mouse and keyboard input in another thread which can be rather tricky because of deadlocks and the main thread (where Present() is ) blocked by vSync.

In my experience, I never use vSync. I lock the frame rate in code, measuring the elapsed time between each frame and use that ‘elapsed time’ to calculate the speed of movements and animations. Since I never use vSync I'm only familiar with what the documentation says it does not how it actually functions with other objects / code / situations.


Regards,
DJTN
[/quote]

I am working with a fixed timestep(not in the simple example obviously , but im my actual code). Also, you may not use vsync, but if i force it in my driver and i see this issues then im going to complain about how broken it is with vsync on :)


[quote name='Mike.Popoloski' timestamp='1343316533' post='4963328']
Have you tried reproducing the issue in native code? If one of the D3D samples demonstrates the same issue, you'd at least know the problem wasn't in the managed code portion.
[/quote]

Ill try to find somethign this evening, also im going to try a clean sweep of my driver just to be sure. The fact that this does not show up in other DX games is making me lean toward somethign in the managed code, but i don;t know for sure. Iv tried terraria, which is an XNA game and saw no issues.

Share this post


Link to post
Share on other sites
[quote name='JWBaker' timestamp='1343321064' post='4963361']
I am working with a fixed timestep(not in the simple example obviously , but im my actual code). Also, you may not use vsync, but if i force it in my driver and i see this issues then im going to complain about how broken it is with vsync on
[/quote]

I don't think it's an issue with vSync or the driver but moreso, how you're handeling the input on a thread that is blocked until the monitor refresh occures and while the OS tries to vSync 2 desktops.

[quote name='JWBaker' timestamp='1343321064' post='4963361']
The fact that this does not show up in other DX games is making me lean toward somethign in the managed code
[/quote]

Maybe these other games are processing input on another thread when vSync is enabled.

Just sayin...

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