Jump to content

  • Log In with Google      Sign In   
  • Create Account


Dual monitors and full screen input issues


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
27 replies to this topic

#1 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 19 July 2012 - 06:08 AM

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

Sponsor:

#2 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 19 July 2012 - 08:02 AM

Are you detecting user input through the mouse/keyboard? In other words, are you processing user input in an event?

#3 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 19 July 2012 - 08:23 AM

Yes I am hooked into the form events.

#4 Mike.Popoloski   Crossbones+   -  Reputation: 2866

Like
0Likes
Like

Posted 19 July 2012 - 01:27 PM

What does your message loop look like?
Mike Popoloski | Journal | SlimDX

#5 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 19 July 2012 - 03:59 PM

What does your message loop look like?


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

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

I am implementing the fixed time-step from gafferongames (attempting to if i got it all wrong Posted Image ) 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.

#6 Mike.Popoloski   Crossbones+   -  Reputation: 2866

Like
0Likes
Like

Posted 19 July 2012 - 05:01 PM

Nothing looks wrong there. It's weird that a second monitor would cause issues. Are you making sure that the device you create uses the right adapter for the monitor it's on?
Mike Popoloski | Journal | SlimDX

#7 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 19 July 2012 - 06:23 PM

As far as i know it is, it's my main monitor and I have the adaptor set for 0

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

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

fullscreenparameters.PresentationInterval = PresentInterval.Default;

TO

fullscreenparameters.PresentationInterval = PresentInterval.Immediate;

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.

#8 Mike.Popoloski   Crossbones+   -  Reputation: 2866

Like
-1Likes
Like

Posted 19 July 2012 - 08:20 PM

Maybe you have a bad driver. Make sure your driver is up-to-date and that you've installed all updates for your system.
Mike Popoloski | Journal | SlimDX

#9 JWBaker   Members   -  Reputation: 235

Like
1Likes
Like

Posted 20 July 2012 - 07:00 AM

Everything is up to date, i did some more digging and found this
http://www.gamedev.net/topic/592845-vsync-causing-input-lag/

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.

#10 DJTN   Members   -  Reputation: 207

Like
1Likes
Like

Posted 21 July 2012 - 08:58 AM

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:
  • 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

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

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.

#11 Gavin Williams   Members   -  Reputation: 646

Like
1Likes
Like

Posted 22 July 2012 - 01:20 AM

I don't know if you've seen my post http://www.gamedev.n...48#entry4958948 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 Posted Image 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, 22 July 2012 - 04:44 AM.


#12 Gavin Williams   Members   -  Reputation: 646

Like
1Likes
Like

Posted 22 July 2012 - 11:14 PM

Try using raw input. It wrote some raw-input code today and it has fixed my problem.

#13 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 23 July 2012 - 04:17 PM

Try using raw input. It wrote some raw-input code today and it has fixed my problem.


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. :(

#14 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 24 July 2012 - 06:12 AM


Try using raw input. It wrote some raw-input code today and it has fixed my problem.


I'm using the system cursor, which is very choppy in fullscreen Posted Image 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. Posted Image


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...

#15 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 24 July 2012 - 03:43 PM

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..

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

	}
}

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, 24 July 2012 - 03:47 PM.


#16 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 25 July 2012 - 01:43 PM

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.

#17 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 25 July 2012 - 03:15 PM

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.



Yes, this problem occurs even when not registered to the form events. 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.

#18 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 25 July 2012 - 04:11 PM

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.

#19 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 25 July 2012 - 04:45 PM

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.

#20 JWBaker   Members   -  Reputation: 235

Like
0Likes
Like

Posted 25 July 2012 - 06:22 PM

Stopped nvsvc.exe to no avail. It's so weird and truly annoying. Also this is the SlimDX forum :) Mike P. up top was a SlimDX dev




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