add alternate vsync method for d3d display method, in case youre the lucky owner of a system that sucks

This commit is contained in:
zeromus 2016-03-27 04:49:17 -05:00
parent b8fd885d3f
commit 10272b4857
9 changed files with 145 additions and 25 deletions

View File

@ -201,9 +201,17 @@ namespace BizHawk.Client.Common
public int SaveStateCompressionLevelRewind = DefaultSaveStateCompressionLevelRewind;//this isnt actually used yet
public int MovieCompressionLevel = 2;
/// <summary>use vsync. if VSyncThrottle = false, this will try to use vsync without throttling to it</summary>
/// <summary>
/// Use vsync when presenting all 3d accelerated windows.
/// For the main window, if VSyncThrottle = false, this will try to use vsync without throttling to it
/// </summary>
public bool VSync = false;
/// <summary>
/// Tries to use an alternate vsync mechanism, for video cards that just can't do it right
/// </summary>
public bool DispAlternateVsync = false;
public static class DefaultMessageOptions
{
public const int

View File

@ -1259,6 +1259,7 @@
</EmbeddedResource>
<EmbeddedResource Include="config\DisplayConfigLite.resx">
<DependentUpon>DisplayConfigLite.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="config\FileExtensionPreferences.resx">
<DependentUpon>FileExtensionPreferences.cs</DependentUpon>

View File

@ -772,11 +772,27 @@ namespace BizHawk.Client.EmuHawk
//apply the vsync setting (should probably try to avoid repeating this)
bool vsync = Global.Config.VSyncThrottle || Global.Config.VSync;
//only used by alternate vsync
var dx9 = GlobalWin.GL as BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9;
//for now, it's assumed that the presentation panel is the main window, but that may not always be true
bool alternateVsync = false;
if (dx9 != null)
{
alternateVsync = Global.Config.DispAlternateVsync && vsync && Global.Config.VSyncThrottle;
//unset normal vsync if we've chosen the alternate vsync
if (alternateVsync)
vsync = false;
}
//TODO - whats so hard about triple buffering anyway? just enable it always, and change api to SetVsync(enable,throttle)
//maybe even SetVsync(enable,throttlemethod) or just SetVsync(enable,throttle,advanced)
//ok, now this is a bit undesireable.
//maybe the user wants vsync, but not vsync throttle.
//this makes sense... but we dont have the infrastructure to support it now (we'd have to enable triple buffering or something like that)
//so what we're gonna do is disable vsync no matter what if throttling is off, and maybe nobody will notice.
//update 26-mar-2016: this upsets me. When fastforwarding and skipping frames, vsync should still work
//update 26-mar-2016: this upsets me. When fastforwarding and skipping frames, vsync should still work. But I'm not changing it yet
if (Global.DisableSecondaryThrottling)
vsync = false;
@ -786,15 +802,23 @@ namespace BizHawk.Client.EmuHawk
{
// Workaround for vsync not taking effect at startup (Intel graphics related?)
presentationPanel.GraphicsControl.SetVsync(false);
}
presentationPanel.GraphicsControl.SetVsync(vsync);
LastVsyncSettingGraphicsControl = presentationPanel.GraphicsControl;
LastVsyncSetting = vsync;
}
//wait for vsync to begin
if (alternateVsync) dx9.AlternateVsyncPass(0);
//present and conclude drawing
presentationPanel.GraphicsControl.SwapBuffers();
//wait for vsync to end
if (alternateVsync) dx9.AlternateVsyncPass(1);
//nope. dont do this. workaround for slow context switching on intel GPUs. just switch to another context when necessary before doing anything
//presentationPanel.GraphicsControl.End();

View File

@ -219,6 +219,7 @@ namespace BizHawk.Client.EmuHawk
//TODO GL - a lot of disorganized wiring-up here
CGC.CGCBinPath = Path.Combine(PathManager.GetDllDirectory(), "cgc.exe");
PresentationPanel = new PresentationPanel();
PresentationPanel.GraphicsControl.MainWindow = true;
GlobalWin.DisplayManager = new DisplayManager(PresentationPanel);
Controls.Add(PresentationPanel);
Controls.SetChildIndex(PresentationPanel, 0);

View File

@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DisplayConfigLite));
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
@ -63,12 +64,15 @@
this.label5 = new System.Windows.Forms.Label();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tpAR = new System.Windows.Forms.TabPage();
this.cbAutoPrescale = new System.Windows.Forms.CheckBox();
this.label11 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.nudPrescale = new System.Windows.Forms.NumericUpDown();
this.tpDispMethod = new System.Windows.Forms.TabPage();
this.label6 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label13 = new System.Windows.Forms.Label();
this.cbAlternateVsync = new System.Windows.Forms.CheckBox();
this.label8 = new System.Windows.Forms.Label();
this.rbD3D9 = new System.Windows.Forms.RadioButton();
this.label7 = new System.Windows.Forms.Label();
@ -93,9 +97,10 @@
this.cbMenuWindowed = new System.Windows.Forms.CheckBox();
this.cbCaptionWindowed = new System.Windows.Forms.CheckBox();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.cbAutoPrescale = new System.Windows.Forms.CheckBox();
this.tbScanlineIntensity = new BizHawk.Client.EmuHawk.TransparentTrackBar();
this.trackbarFrameSizeWindowed = new BizHawk.Client.EmuHawk.TransparentTrackBar();
this.btnDefaults = new System.Windows.Forms.Button();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.groupBox1.SuspendLayout();
this.grpFinalFilter.SuspendLayout();
this.grpARSelection.SuspendLayout();
@ -435,7 +440,7 @@
//
this.rbOpenGL.AutoSize = true;
this.rbOpenGL.Checked = true;
this.rbOpenGL.Location = new System.Drawing.Point(6, 73);
this.rbOpenGL.Location = new System.Drawing.Point(6, 103);
this.rbOpenGL.Name = "rbOpenGL";
this.rbOpenGL.Size = new System.Drawing.Size(65, 17);
this.rbOpenGL.TabIndex = 3;
@ -445,7 +450,7 @@
//
// label5
//
this.label5.Location = new System.Drawing.Point(21, 93);
this.label5.Location = new System.Drawing.Point(21, 123);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(359, 47);
this.label5.TabIndex = 16;
@ -469,6 +474,7 @@
//
// tpAR
//
this.tpAR.Controls.Add(this.btnDefaults);
this.tpAR.Controls.Add(this.cbAutoPrescale);
this.tpAR.Controls.Add(this.label11);
this.tpAR.Controls.Add(this.groupBox1);
@ -486,6 +492,16 @@
this.tpAR.Text = "Scaling & Filtering";
this.tpAR.UseVisualStyleBackColor = true;
//
// cbAutoPrescale
//
this.cbAutoPrescale.AutoSize = true;
this.cbAutoPrescale.Location = new System.Drawing.Point(6, 171);
this.cbAutoPrescale.Name = "cbAutoPrescale";
this.cbAutoPrescale.Size = new System.Drawing.Size(92, 17);
this.cbAutoPrescale.TabIndex = 17;
this.cbAutoPrescale.Text = "Auto Prescale";
this.cbAutoPrescale.UseVisualStyleBackColor = true;
//
// label11
//
this.label11.AutoSize = true;
@ -539,14 +555,16 @@
//
// label6
//
this.label6.Location = new System.Drawing.Point(5, 229);
this.label6.Location = new System.Drawing.Point(3, 258);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(359, 47);
this.label6.Size = new System.Drawing.Size(359, 23);
this.label6.TabIndex = 18;
this.label6.Text = "Changes require restart of program to take effect.\r\n";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label13);
this.groupBox3.Controls.Add(this.cbAlternateVsync);
this.groupBox3.Controls.Add(this.label8);
this.groupBox3.Controls.Add(this.rbD3D9);
this.groupBox3.Controls.Add(this.label7);
@ -555,15 +573,34 @@
this.groupBox3.Controls.Add(this.rbOpenGL);
this.groupBox3.Location = new System.Drawing.Point(6, 5);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(389, 221);
this.groupBox3.Size = new System.Drawing.Size(415, 241);
this.groupBox3.TabIndex = 16;
this.groupBox3.TabStop = false;
//
// label13
//
this.label13.Location = new System.Drawing.Point(45, 60);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(359, 43);
this.label13.TabIndex = 22;
this.label13.Text = resources.GetString("label13.Text");
this.label13.Click += new System.EventHandler(this.label13_Click);
this.label13.DoubleClick += new System.EventHandler(this.label13_Click);
//
// cbAlternateVsync
//
this.cbAlternateVsync.AutoSize = true;
this.cbAlternateVsync.Location = new System.Drawing.Point(28, 60);
this.cbAlternateVsync.Name = "cbAlternateVsync";
this.cbAlternateVsync.Size = new System.Drawing.Size(15, 14);
this.cbAlternateVsync.TabIndex = 21;
this.cbAlternateVsync.UseVisualStyleBackColor = true;
//
// label8
//
this.label8.Location = new System.Drawing.Point(21, 30);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(359, 47);
this.label8.Size = new System.Drawing.Size(359, 27);
this.label8.TabIndex = 20;
this.label8.Text = " • Best compatibility\r\n • May have trouble with OpenGL-based cores (Saturn,N64)\r\n" +
"";
@ -582,7 +619,7 @@
//
// label7
//
this.label7.Location = new System.Drawing.Point(21, 170);
this.label7.Location = new System.Drawing.Point(21, 191);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(359, 47);
this.label7.TabIndex = 18;
@ -593,7 +630,7 @@
//
this.rbGDIPlus.AutoSize = true;
this.rbGDIPlus.Checked = true;
this.rbGDIPlus.Location = new System.Drawing.Point(6, 150);
this.rbGDIPlus.Location = new System.Drawing.Point(6, 171);
this.rbGDIPlus.Name = "rbGDIPlus";
this.rbGDIPlus.Size = new System.Drawing.Size(50, 17);
this.rbGDIPlus.TabIndex = 17;
@ -677,9 +714,10 @@
this.cbAllowDoubleclickFullscreen.AutoSize = true;
this.cbAllowDoubleclickFullscreen.Location = new System.Drawing.Point(12, 223);
this.cbAllowDoubleclickFullscreen.Name = "cbAllowDoubleclickFullscreen";
this.cbAllowDoubleclickFullscreen.Size = new System.Drawing.Size(347, 17);
this.cbAllowDoubleclickFullscreen.Size = new System.Drawing.Size(471, 17);
this.cbAllowDoubleclickFullscreen.TabIndex = 27;
this.cbAllowDoubleclickFullscreen.Text = "Allow Double-Click Fullscreen (hold shift to force fullscreen to toggle)";
this.cbAllowDoubleclickFullscreen.Text = "Allow Double-Click Fullscreen (hold shift to force fullscreen to toggle in case u" +
"sing zapper, etc.)";
this.cbAllowDoubleclickFullscreen.UseVisualStyleBackColor = true;
//
// groupBox4
@ -818,16 +856,6 @@
this.linkLabel1.Text = "Documentation";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// cbAutoPrescale
//
this.cbAutoPrescale.AutoSize = true;
this.cbAutoPrescale.Location = new System.Drawing.Point(6, 171);
this.cbAutoPrescale.Name = "cbAutoPrescale";
this.cbAutoPrescale.Size = new System.Drawing.Size(92, 17);
this.cbAutoPrescale.TabIndex = 17;
this.cbAutoPrescale.Text = "Auto Prescale";
this.cbAutoPrescale.UseVisualStyleBackColor = true;
//
// tbScanlineIntensity
//
this.tbScanlineIntensity.LargeChange = 32;
@ -852,6 +880,17 @@
this.trackbarFrameSizeWindowed.Value = 1;
this.trackbarFrameSizeWindowed.ValueChanged += new System.EventHandler(this.trackbarFrameSizeWindowed_ValueChanged);
//
// btnDefaults
//
this.btnDefaults.Location = new System.Drawing.Point(447, 262);
this.btnDefaults.Name = "btnDefaults";
this.btnDefaults.Size = new System.Drawing.Size(75, 23);
this.btnDefaults.TabIndex = 18;
this.btnDefaults.Text = "Defaults";
this.toolTip1.SetToolTip(this.btnDefaults, "Unless I forgot to update the button\'s code when I changed a default");
this.btnDefaults.UseVisualStyleBackColor = true;
this.btnDefaults.Click += new System.EventHandler(this.btnDefaults_Click);
//
// DisplayConfigLite
//
this.AcceptButton = this.btnOk;
@ -949,8 +988,6 @@
private System.Windows.Forms.CheckBox cbMenuFullscreen;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label lblFrameTypeWindowed;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox cbFullscreenHacks;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.NumericUpDown nudPrescale;
@ -966,5 +1003,11 @@
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox txtCustomARX;
private System.Windows.Forms.CheckBox cbAutoPrescale;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.CheckBox cbAlternateVsync;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox cbFullscreenHacks;
private System.Windows.Forms.Button btnDefaults;
private System.Windows.Forms.ToolTip toolTip1;
}
}

View File

@ -40,6 +40,8 @@ namespace BizHawk.Client.EmuHawk.config
cbFullscreenHacks.Checked = Global.Config.DispFullscreenHacks;
cbAutoPrescale.Checked = Global.Config.DispAutoPrescale;
cbAlternateVsync.Checked = Global.Config.DispAlternateVsync;
if (Global.Config.DispSpeedupFeatures == 2) rbDisplayFull.Checked = true;
if (Global.Config.DispSpeedupFeatures == 1) rbDisplayMinimal.Checked = true;
if (Global.Config.DispSpeedupFeatures == 0) rbDisplayAbsoluteZero.Checked = true;
@ -117,6 +119,8 @@ namespace BizHawk.Client.EmuHawk.config
Global.Config.DispFixScaleInteger = checkPadInteger.Checked;
Global.Config.DispFullscreenHacks = cbFullscreenHacks.Checked;
Global.Config.DispAutoPrescale = cbAutoPrescale.Checked;
Global.Config.DispAlternateVsync = cbAlternateVsync.Checked;
Global.Config.DispChrome_StatusBarWindowed = cbStatusBarWindowed.Checked;
Global.Config.DispChrome_CaptionWindowed = cbCaptionWindowed.Checked;
@ -285,5 +289,20 @@ namespace BizHawk.Client.EmuHawk.config
System.Diagnostics.Process.Start("http://tasvideos.org/Bizhawk/DisplayConfig.html");
}
private void label13_Click(object sender, EventArgs e)
{
cbAlternateVsync.Checked ^= true;
}
private void btnDefaults_Click(object sender, EventArgs e)
{
nudPrescale.Value = 1;
rbNone.Checked = true;
cbAutoPrescale.Checked = true;
rbFinalFilterBilinear.Checked = true;
checkLetterbox.Checked = true;
rbUseSystem.Checked = true;
}
}
}

View File

@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="label13.Text" xml:space="preserve">
<value>Alternate VSync Method: Some GPUs have problems VSyncing. It seems to manifest on full-screen windows. There will be hiccups when throttling to VSync. Use this to try and solve it (busy loop; burns major CPU)</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>For Windows operating systems &gt;= Vista, with some video cards, the monitors may flicker when going 'windowed fullscreen' while the system disobeys us and goes actual fullscreen instead. This hack prevents that, but may increase frame latency (since in Microsoft's new and disimproved operating systems, windowed mode things may have higher latency)</value>
</data>

View File

@ -53,6 +53,18 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX
CreateRenderStates();
}
public void AlternateVsyncPass(int pass)
{
for (; ; )
{
var status = dev.GetRasterStatus(0);
if (status.InVBlank && pass == 0) return; //wait for vblank to begin
if (!status.InVBlank && pass == 1) return; //wait for vblank to end
//STOP! think you can use System.Threading.SpinWait? No, it's way too slow.
//(on my system, the vblank is something like 24 of 1074 scanlines @ 60hz ~= 0.35ms which is an awfully small window to nail)
}
}
private void DestroyDevice()
{
if (dev != null)
@ -829,6 +841,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX
try
{
var result = control.SwapChain.Present(Present.None);
//var rs = dev.GetRasterStatus(0);
}
catch(d3d9.Direct3D9Exception ex)
{

View File

@ -41,6 +41,11 @@ namespace BizHawk.Bizware.BizwareGL
Managed.Paint += new PaintEventHandler(GraphicsControl_Paint);
}
/// <summary>
/// If this is the main window, things may be special
/// </summary>
public bool MainWindow;
void GraphicsControl_Paint(object sender, PaintEventArgs e)
{
OnPaint(e);