You’re right that a GPU interrupt can be something other than a VSync. In
my original post I also mentioned that when using multiple displays there’s
probably no way for me to tell which display the interrupt originates from,
even if I knew it was a VSync interrupt. So there definitely is a problem
for me with properly interpreting the interrupts. But in the end what I’m
looking for is just a better way of synchronizing rendering and
presentation than doing a Sleep(1) polling loop. Even I got false interrupt
notifications, that would still be better than the current solution, as
long as I at least get all the “good” interrupt notifications, too. In user
land I can ask the current VSync scanline position to check if the
interrupt notification I received is useful or not. At the moment I don’t
plan to touch GPU registers, I don’t think I need to.
“Everything is fine” with AMD mostly applies to fullscreen exclusive mode.
This is all a very complicated topic and I didn’t want to bore you with all
the complex details. My video renderer needs to support different
situations. It has to work in windowed mode. It has to work with Aero
turned on and off etc. It also has a fullscreen (exclusive) mode. I need to
make it all work. The most reliable solution is fullscreen exclusive mode.
In that mode AMD works fine, NVidia not so much. I do plan to contact
NVidia about it, hopefully they’ll fix whatever bug their drivers have. But
I need to support windowed mode, too, and for that, frankly, D3D sucks,
pardon my french. Without Aero, if you ask D3D in windowed mode to present
a frame during the next VSync period, the presentation thread goes into a
100% CPU loop and rendering is blocked during the wait. Totally unusable.
With Aero, this is not a problem, but there are different problems. In the
end, no matter what, my rendering code needs to keep track of the VSync to
make sure playback is totally smooth. No way around it. And even if all GPU
driver bugs were fixed, I’d still benefit from getting VSync interrupt
notifications to optimize my rendering and presentation synchronization.
The only case it would not help would be if it would not perform any better
than a Sleep(1) polling loop, and that’s hard for me to believe.
Best regards, Mathias.
2012/7/8 Jan Bottorff
> So I looked at the link you posted. All that is saying is there a WDDM
> driver API for the OS to give power management hints to the GPU driver.
>
>
> **
>
> What I?m saying about interrupts is the interrupt from the GPU is owned by
> the GPU driver, and ONLY the GPU driver knows the correct way to decode the
> interrupt. So let?s say one of the sources of an interrupt is currently a
> vsync. To tell the difference between a vsync interrupt and a command
> completion interrupt, the GPU driver?s ISR likely needs to read a device
> register (or the interrupt info was already delivered via DMA or part of an
> MSI-X interrupt). MOST devices have multiple sources of interrupts. YOUR
> driver would have no way to tell what caused the interrupt, and if YOUR
> driver touched the GPU registers to try and determine the source, you have
> likely just screwed up the GPU driver, because reading hardware registers
> often have side effects like clearing some status. It seems like you?re
> making some assumption that ANY interrupt MUST be a vsync interrupt, which
> is almost certainly not the case.
>
> ****
>
> You?re saying everything is fine on AMD video cards? So have you contacted
> NVidia. It?s easy to join the NVidia developer program and my very limited
> experience has been they are quite responsive about driver issues. Maybe
> NVidia can send you a fragment of sample D3D code for their hardware to do
> what you need to do. I think you would get better suggestions on how to
> solve you issue in a D3D programming list, or I assume NVidia has a
> developer community, and someone there might have a suggestion.
>
>
>
> Jan
>
> ****
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Saturday, July 07, 2012 11:30 PM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] getting access to VSync interrupt
>
> **
>
> I know how page flipping works, I’ve been using it for years. My video
> renderer uses D3D9(Ex), and I’m supporting all the various methods like
> windowed mode (with and without desktop composition), fullscreen exclusive
> mode etc. In windowed mode (without desktop composition) if you ask D3D to
> present a frame during the next VSync, D3D goes into a blocking 100% CPU
> loop, which polls for the VSync. Nasty. In fullscreen exclusive mode,
> things kinda work as expected, but I’m running into all sorts of trouble
> with NVidia driver bugs, resulting in presentation glitches being reported
> by D3D9Ex and I’m getting non-smooth playback as a result. (No probs with
> AMD hardware at the moment.)
>
> So are you saying that the GPU does not use the interrupt for VSync at
> all, anymore, in Windows? Microsoft documentation suggests otherwise:
>
> http://msdn.microsoft.com/en-us/library/windows/hardware/gg487377.aspx
>
> “Beginning with Windows Vista Service Pack 1, the operating system can
> turn off periodic VSync interrupt counting when the screen is not being
> refreshed from new graphics or mouse activity.”
>
> Best regards, Mathias.
>
>
>
>
> 2012/7/7 Jan Bottorff
>
> You know, to prevent video tearing you?re going about it all wrong. Apps
> generally use frame buffer page flipping, and the hardware knows how to
> flip the page at the right moment. You render into the offscreen page, and
> queue it up for the hardware to flip. This is normal operation for a
> modern GPU. The standard user mode DirectX/D3D API?s support this, look for
> the back buffers option on a surface.
>
>
>
> Also the interrupt from the GPU is NOT for VSync, it?s for GPU command
> completion, which timing wise may have nothing to do with VSync. Stop
> reading hardware docs from 1990, they no longer apply. Also stop reading
> the Linux source code for video drivers and thinking Windows is the same,
> it?s not. What your talked about doing has nothing to do with reality on
> Windows.
>
>
>
> Jan
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Saturday, July 07, 2012 9:24 AM
>
>
> To: Windows System Software Devs Interest List
>
> Subject: Re: [ntdev] getting access to VSync interrupt****
>
>
>
> Everything I want to do? Ouch… 
>
> So is there any supported way for me to get some more control over the GPU
> in kernel mode? I’ve read that GPU mirror drivers don’t work that well in
> Vista+, anymore (they seem to result in desktop composition being turned
> off etc). Any other options? Writing a filter/mini/whatever driver? Or am I
> totally out of luck? I’m willing to go the “proper” way, if there is one…
>
> FWIW, I don’t need perfect timing. Just looking for something better than
> a VSync scanline polling loop with a Sleep(1).
>
> Thanks, Mathias.
>
> 2012/7/7 Doron Holan
>
> Everything you want to do is way off the reservation and unsupported. Even
> if it was supported, setting the event does not necessarily immediately
> wake up the waiting thread, so you would not get the timing you want.
>
> d
>
> debt from my phone
> ------------------------------
>
> From: xxxxx@gmail.com
> Sent: 7/7/2012 2:51 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] getting access to VSync interrupt
>
> Hey guys,
>
> in order to optimize the performance and reliability (tearing etc) of my
> video renderer, I’d like to get access to the VSync interrupt for
> informational purposes. Basically what I have in mind is that I would write
> a little kernel mode driver which connects to the VSync interrupt and then
> simply sets an event in the ISR routine. The event would then wake up a
> high-priority user mode thread, which would perform video playback related
> tasks.
>
> Of course, in an ideal world either the OS or the GPU drivers would allow
> me to access this kind of functionality through APIs. But since this is not
> available, I’d like to try to realize it myself. Obviously I can’t write a
> full GPU driver. Just want to send VSync notifications to my user land
> video renderer somehow, if it is possible in any way.
>
> From what I can see, I can find out which interrupt vector the GPU uses
> via setupapi in user land. And I already have code written for kernel land
> which successfully finds the GPU PDO. So far, so good. So here are my
> questions:
>
> (1) Is it “ok” for me to simply call IoConnectInterrupt(Ex) in my virtual
> driver to connect to the VSync interrupt? I understand that it’s not really
> strictly how the PnP model is supposed to work because my driver isn’t
> really a hardware driver. So would doing this risk system stability?
>
> (2) In my ISR routine, I would ideally like to directly call ZwSetEvent.
> But that doesn’t seem to be possible because ZwSetEvent requires
> PASSIVE_LEVEL? Is there any other way I can directly set an event for user
> land from inside my ISR routine?
>
> (3) I understand interrupts can be shared by multiple different hardware
> devices. In my ISR routine, is there any way for me to find out which
> hardware the “current” interrupt came from?
>
> (4) From what I can see, every GPU just has one interrupt, even though it
> might have multiple displays connected. Is there any way for me to find out
> which display the VSync interrupt originates from? I guess probably not,
> but I thought I’d ask, just in case…
>
> Thank you!
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>