displaymanager experiments for superior vsync

This commit is contained in:
zeromus 2012-06-10 20:48:04 +00:00
parent 2b5fd9e8d9
commit 07ad0acdbe
2 changed files with 57 additions and 7 deletions

View File

@ -593,14 +593,36 @@ namespace BizHawk.MultiClient
displayThread.Start(); displayThread.Start();
} }
volatile bool VsyncToggle = false;
volatile bool VsyncRequested = false;
SwappableDisplaySurfaceSet sourceSurfaceSet = new SwappableDisplaySurfaceSet(); SwappableDisplaySurfaceSet sourceSurfaceSet = new SwappableDisplaySurfaceSet();
public void UpdateSource(IVideoProvider videoProvider) public void UpdateSource(IVideoProvider videoProvider)
{ {
VsyncRequested = Global.Config.DisplayVSync;
//needsclear = false because we're about to clobber the data with AcceptIntArray //needsclear = false because we're about to clobber the data with AcceptIntArray
var newPendingSurface = sourceSurfaceSet.AllocateSurface(videoProvider.BufferWidth, videoProvider.BufferHeight, false); var newPendingSurface = sourceSurfaceSet.AllocateSurface(videoProvider.BufferWidth, videoProvider.BufferHeight, false);
newPendingSurface.AcceptIntArray(videoProvider.GetVideoBuffer()); newPendingSurface.AcceptIntArray(videoProvider.GetVideoBuffer());
sourceSurfaceSet.SetPending(newPendingSurface); sourceSurfaceSet.SetPending(newPendingSurface);
wakeupEvent.Set(); wakeupEvent.Set();
if (VsyncRequested)
{
VsyncToggle = true;
for (; ; )
{
//if (Direct3DRenderPanel.vsyncEvent.WaitOne(1)) break;
if (!VsyncToggle) break;
Application.DoEvents();
}
}
//for(;;)
//{
// if (Direct3DRenderPanel.vsyncEvent.WaitOne(1)) break;
// Application.DoEvents();
//}
} }
public bool Disposed { get; private set; } public bool Disposed { get; private set; }
@ -609,6 +631,7 @@ namespace BizHawk.MultiClient
{ {
if (Disposed) return; if (Disposed) return;
shutdownFlag = true; shutdownFlag = true;
VsyncToggle = true;
while (shutdownFlag) Thread.Sleep(1); while (shutdownFlag) Thread.Sleep(1);
wakeupEvent.Dispose(); wakeupEvent.Dispose();
Disposed = true; Disposed = true;
@ -649,7 +672,7 @@ namespace BizHawk.MultiClient
Display(); Display();
//wait until we receive something interesting, or just a little while anyway //wait until we receive something interesting, or just a little while anyway
wakeupEvent.WaitOne(10); wakeupEvent.WaitOne(1);
if (suspendFlag) if (suspendFlag)
{ {
@ -729,7 +752,7 @@ namespace BizHawk.MultiClient
{ {
if (Global.Config.SuppressGui) if (Global.Config.SuppressGui)
{ {
Global.RenderPanel.FastRenderAndPresent(currentSourceSurface); Global.RenderPanel.Render(currentSourceSurface);
} }
else else
{ {
@ -739,12 +762,13 @@ namespace BizHawk.MultiClient
{ {
Global.OSD.DrawScreenInfo(g); Global.OSD.DrawScreenInfo(g);
Global.OSD.DrawMessages(g); Global.OSD.DrawMessages(g);
//Thread.Sleep(1);
} }
nativeBmp.FromBitmap(); nativeBmp.FromBitmap();
Global.RenderPanel.RenderOverlay(nativeBmp); Global.RenderPanel.RenderOverlay(nativeBmp);
//release the native resolution image //release the native resolution image
nativeDisplaySurfaceSet.ReleaseSurface(nativeBmp); nativeDisplaySurfaceSet.ReleaseSurface(nativeBmp);
Global.RenderPanel.Present(); //Global.RenderPanel.Present();
} }
} }
else else
@ -781,12 +805,25 @@ namespace BizHawk.MultiClient
//send the native resolution image to the render panel //send the native resolution image to the render panel
Global.RenderPanel.Render(nativeBmp); Global.RenderPanel.Render(nativeBmp);
Global.RenderPanel.Present(); //Global.RenderPanel.Present();
//release the native resolution image //release the native resolution image
nativeDisplaySurfaceSet.ReleaseSurface(nativeBmp); nativeDisplaySurfaceSet.ReleaseSurface(nativeBmp);
} }
Global.RenderPanel.Present();
if (VsyncRequested)
{
for (; ; )
{
//if (Direct3DRenderPanel.vsyncEvent.WaitOne(1)) break;
if (VsyncToggle) break;
}
VsyncToggle = false;
}
} }
Thread displayThread; Thread displayThread;

View File

@ -46,6 +46,10 @@ namespace BizHawk.MultiClient
if (width == 0 || height == 0) return; if (width == 0 || height == 0) return;
bool needsRecreating = false; bool needsRecreating = false;
//experiment:
//needsRecreating = true;
if (Texture == null) if (Texture == null)
{ {
needsRecreating = true; needsRecreating = true;
@ -58,6 +62,8 @@ namespace BizHawk.MultiClient
needsRecreating = true; needsRecreating = true;
} }
} }
// If we need to recreate the texture, do so. // If we need to recreate the texture, do so.
if (needsRecreating) if (needsRecreating)
{ {
@ -78,7 +84,7 @@ namespace BizHawk.MultiClient
} }
// Copy the image data to the texture. // Copy the image data to the texture.
using (var Data = Texture.LockRectangle(0, new Rectangle(0, 0, imageWidth, imageHeight), LockFlags.None).Data) using (var Data = Texture.LockRectangle(0, LockFlags.Discard | LockFlags.NoDirtyUpdate).Data)
{ {
if (imageWidth == textureWidth) if (imageWidth == textureWidth)
{ {
@ -348,13 +354,18 @@ namespace BizHawk.MultiClient
backingControl.Invoke(() => CreateDevice()); backingControl.Invoke(() => CreateDevice());
Resized = false; Resized = false;
//TODO //TODO
//BackgroundColor = Color.FromArgb(video.BackgroundColor); //BackgroundColor = Color.FromArgb(video.BackgroundColor);
if (overlay)
{
//return;
}
Texture.SetImage(surface, surface.Width, surface.Height); Texture.SetImage(surface, surface.Width, surface.Height);
if(!overlay) Device.Clear(ClearFlags.Target, BackgroundColor, 0.0f, 0); if(!overlay) Device.Clear(ClearFlags.Target, BackgroundColor, 0.0f, 0);
// figure out scaling factor // figure out scaling factor
float widthScale = (float)backingControl.Size.Width / surface.Width; float widthScale = (float)backingControl.Size.Width / surface.Width;
float heightScale = (float)backingControl.Size.Height / surface.Height; float heightScale = (float)backingControl.Size.Height / surface.Height;
@ -369,7 +380,7 @@ namespace BizHawk.MultiClient
Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point); Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
Sprite.Transform = Matrix.Scaling(finalScale, finalScale, 0f); Sprite.Transform = Matrix.Scaling(finalScale, finalScale, 0f);
Sprite.Draw(Texture.Texture, new Rectangle(0, 0, surface.Width, surface.Height), new Vector3(surface.Width / 2f, surface.Height / 2f, 0), new Vector3(backingControl.Size.Width / 2f / finalScale, backingControl.Size.Height / 2f / finalScale, 0), Color.White); Sprite.Draw(Texture.Texture, new Rectangle(0, 0, surface.Width, surface.Height), new Vector3(surface.Width / 2f, surface.Height / 2f, 0), new Vector3(backingControl.Size.Width / 2f / finalScale, backingControl.Size.Height / 2f / finalScale, 0), Color.White);
if (overlay) Device.SetRenderState(RenderState.AlphaBlendEnable, false); //if (overlay) Device.SetRenderState(RenderState.AlphaBlendEnable, false);
Sprite.End(); Sprite.End();
Device.EndScene(); Device.EndScene();
@ -379,8 +390,10 @@ namespace BizHawk.MultiClient
{ {
//Device.Present(SlimDX.Direct3D9.Present.DoNotWait); //Device.Present(SlimDX.Direct3D9.Present.DoNotWait);
Device.Present(SlimDX.Direct3D9.Present.None); Device.Present(SlimDX.Direct3D9.Present.None);
vsyncEvent.Set();
} }
public static EventWaitHandle vsyncEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
private bool disposed; private bool disposed;