Dx9 Driver and Mouse Lag

BlitzMax Forums/BlitzMax Programming/Dx9 Driver and Mouse Lag

DStastny(Posted 2009) [#1]
I have been looking into the issue. I think I have found the best solution.

From my research there is essentially 3 ways to deal with this issue, which all involve basically stalling the CPU until the GPU is ready.

1. Lock the backbuffer before Present(Flipping). This is the solutin in the DX7 Driver. Not likely to happen since I don't want to incur the performance hit of enabling locking the back buffer. Grabpixmap does not work this way under my Dx9 implementation so not really option, although I could make it work.

2. Create a extra texture render target 1x1 and render a triangle and read it back. This is similar to 1, but does not mess with the back buffer.

3. Use the Direct X 9 query feature and query the GPU to determine that rendering is complete.

Now I have tested 3 on my hardware and looks like it will work and have the desired result however, my card does not suffer from the problem. So definitely some external testing is in order, to verify that it fixes problematic hardware combinations.

Now however I hate to apply the "fix" universally as it has significant frame rate impacts on well behaved drivers, with VSYNC off.

As of right now I have added a property to the base Driver to toggle the functionality.

My ideal solution would be to see if I can identify hardware and drivers that exhibit the lagging behavior and build a data table into the driver so that the driver can "tweak" behavior based upon capabilities of the card.

To truly create a professional level driver this hardware driver table I think is what needs to happen as the CAP Bits don't necessarily tell the whole truth. Many vendors lie or misrepresent here.

So to make a successful test what needs to happen.

I need the source for a simple program that clearly demonstrates the problem. From that I can modify it to set the Direct X Driver into different modes to "test" solutions on a variety of hardware as well as gather some CAP reports, from that information I can start building a Hardware Data table for the driver to use to automatically choose different methods.

I am looking for people who are interested in the Dx9 drivers thoughts here.


Thanks
Doug


SLotman(Posted 2009) [#2]
Cant help you there, I have no machine with such problem either :(


markcw(Posted 2009) [#3]
I haven't noticed any mouse lag but I did think 'maxarc/graphics/Snow effect + image wave.bmx' was quite a bit slower in dx9, no idea why of course.

Edit: no sorry, my mistake. dx9 was actually a bit faster than dx7, the problem was that code has 'Framework BRL.GLMax2d' and when you comment that line out it runs much slower for some reason.


MGE(Posted 2009) [#4]
damn.. I wish I wasn't knee deep in work, I would spend some time on this and help you out. I don't know if I fixed the problem or not, but last year I ended up coding this, which hacked the present flip based on window mode and vysnc mode. I didn't deploy anything with this because I was too nervous about the lag issue.

	Method Flip( dummynotused:Int=0 )
		'
          Local flags: Int=0	
          Local hr :Int
		'
		If DX9Windowed=1
     	 '
           If DX9VSyncOn = 0
           _SwapChain.Present(Null,Null,Null,Null,flags)	
           Else
            ' Wait for VBLank or error in call			
		  hr = 0
		  Repeat
		   hr=_SwapChain.GetRasterStatus(_RasterStatus)
		  Until _RasterStatus.InVBlank Or hr
		  _SwapChain.Present(Null,Null,Null,Null,flags)
	       ' Wait for VBLank or error in call			
		  hr = 0
		  Repeat
		   hr=_SwapChain.GetRasterStatus(_RasterStatus)
		  Until Not _RasterStatus.InVBlank Or hr	
           EndIf
		 '
		Else
		 '
           _SwapChain.Present(Null,Null,Null,Null,flags)	
		 '
		EndIf
          '
	End Method



GfK(Posted 2009) [#5]
I'm currently experimenting with the mouse lag problem.

Test system: P3-733MHz, 256MB RAM, 64MB GeForce2MX400, WinXP, DX9.0c.

Import dbs.d3d9max2d

SetGraphicsDriver d3d9max2ddriver()

Graphics 800,600

While Not KeyDown(key_escape) And Not AppTerminate()
	Cls
	DrawOval MouseX(),MouseY(),3,3
	Flip
Wend

The above code exhibits no lag whatsoever. The lag seems to become more evident the more that's being drawn. I'm not really sure why yet. I think the lag was evident from the outset when the same thing happened with Vista/DX7 at the launch of Blitzmax.


Abrexxes(Posted 2009) [#6]
Just a question. If you have so an old system, why you not use dx7? 256MB is hart on the limit for XP and the recommanded CPU the time XP comes out was 1.4Ghz. Make a choice for your customers where they can select between 7 and 9.

bye


GfK(Posted 2009) [#7]
Just a question. If you have so an old system, why you not use dx7?
Because not everybody has such an old system and DX9 generally renders more quickly.
Make a choice for your customers where they can select between 7 and 9
Casual gamers do not want options like that. Half of them don't even know what DirectX is, let alone which version of it they should be using.


GfK(Posted 2009) [#8]
Update: I'm no longer sure that the DX9 module is the sole cause of the mouse lag. More to follow.

[edit] Right, it isn't solely your module's fault. It may not even be your fault at all although there is no lag at all using the projection matrix with DX7.

Your DX9 mod, in conjunction with a projection matrix, here modified from a pre-existing DX7 version, causes the lag. Does it on my Vista system too only less noticeable.

So either your module is broken, my implementation of the projection matrix is wrong, or the two simply don't get along for some reason.

Anyhoo, demonstrative code:




DStastny(Posted 2009) [#9]
@GFK Good demo!

Not sure whats so different on this but I can see the problem.

I had to cobble together the missing DX7 part so I could swap it back and forth but I could see the problem on my Vista Laptop with that program.

My fix does seem to address the problem.

There is a slight draw back though as basically it limits the ability of the GPU to work full speed.

The question now will be do enough cards support Device Queries...

From my reading on this its not so much a code issue on my part but more what and how programs are drawing and interacting with user input.

I am implementing this as driver option so if desired it can be turned off but I will make the default behavior for it to be on.

Look for a updated download soon.

*Edit* I also added code to center the window when in windows mode, to keep in sync with the other windows drivers


Thanks
Doug


Arowx(Posted 2009) [#10]
OK I've got a couple of PC's I can test this on!

I just need clear instructions on what exactly to do and look out for?

DStatsny keep up the good work!