mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 06:13:52 +02:00
Move DirectX Texture2D initialization to after OpenVR Init
This allows us to create the texture on the correct GPU.
This commit is contained in:
@@ -62,6 +62,10 @@ namespace VRCX
|
||||
|
||||
public void RenderToTexture(Texture2D texture)
|
||||
{
|
||||
// Safeguard against uninitialized texture
|
||||
if (texture == null)
|
||||
return;
|
||||
|
||||
_paintBufferLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -12,7 +12,6 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using CefSharp;
|
||||
using SharpDX;
|
||||
using SharpDX.Direct3D;
|
||||
using SharpDX.Direct3D11;
|
||||
using SharpDX.DXGI;
|
||||
using Valve.VR;
|
||||
@@ -82,30 +81,13 @@ namespace VRCX
|
||||
MainForm.Instance.Browser.ExecuteScriptAsync("console.log('VRCXVR Restarted');");
|
||||
}
|
||||
|
||||
private void ThreadLoop()
|
||||
private void SetupTextures()
|
||||
{
|
||||
var active = false;
|
||||
var e = new VREvent_t();
|
||||
var nextInit = DateTime.MinValue;
|
||||
var nextDeviceUpdate = DateTime.MinValue;
|
||||
var nextOverlay = DateTime.MinValue;
|
||||
var overlayIndex = OpenVR.k_unTrackedDeviceIndexInvalid;
|
||||
var overlayVisible1 = false;
|
||||
var overlayVisible2 = false;
|
||||
var dashboardHandle = 0UL;
|
||||
var overlayHandle1 = 0UL;
|
||||
var overlayHandle2 = 0UL;
|
||||
|
||||
// REMOVE THIS
|
||||
// nextOverlay = DateTime.MaxValue;
|
||||
// https://stackoverflow.com/questions/38312597/how-to-choose-a-specific-graphics-device-in-sharpdx-directx-11/38596725#38596725
|
||||
Factory f = new Factory1();
|
||||
var a = f.GetAdapter(1);
|
||||
|
||||
var flags = DeviceCreationFlags.BgraSupport;
|
||||
|
||||
_device = Program.GPUFix ? new Device(a, flags) : new Device(DriverType.Hardware, DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport);
|
||||
_device = new Device(f.GetAdapter(OpenVR.System.GetD3D9AdapterIndex()),
|
||||
DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport);
|
||||
|
||||
_texture1?.Dispose();
|
||||
_texture1 = new Texture2D(
|
||||
_device,
|
||||
new Texture2DDescription
|
||||
@@ -121,7 +103,8 @@ namespace VRCX
|
||||
CpuAccessFlags = CpuAccessFlags.Write
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
_texture2?.Dispose();
|
||||
_texture2 = new Texture2D(
|
||||
_device,
|
||||
new Texture2DDescription
|
||||
@@ -137,7 +120,22 @@ namespace VRCX
|
||||
CpuAccessFlags = CpuAccessFlags.Write
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void ThreadLoop()
|
||||
{
|
||||
var active = false;
|
||||
var e = new VREvent_t();
|
||||
var nextInit = DateTime.MinValue;
|
||||
var nextDeviceUpdate = DateTime.MinValue;
|
||||
var nextOverlay = DateTime.MinValue;
|
||||
var overlayIndex = OpenVR.k_unTrackedDeviceIndexInvalid;
|
||||
var overlayVisible1 = false;
|
||||
var overlayVisible2 = false;
|
||||
var dashboardHandle = 0UL;
|
||||
var overlayHandle1 = 0UL;
|
||||
var overlayHandle2 = 0UL;
|
||||
|
||||
_browser1 = new OffScreenBrowser(
|
||||
"file://vrcx/vr.html?1",
|
||||
512,
|
||||
@@ -183,6 +181,7 @@ namespace VRCX
|
||||
}
|
||||
|
||||
active = true;
|
||||
SetupTextures();
|
||||
}
|
||||
|
||||
while (system.PollNextEvent(ref e, (uint)Marshal.SizeOf(e)))
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace VRCX
|
||||
public static string ConfigLocation;
|
||||
public static string Version { get; private set; }
|
||||
public static bool LaunchDebug;
|
||||
public static bool GPUFix;
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetLogger("VRCX");
|
||||
static Program()
|
||||
{
|
||||
@@ -143,7 +142,6 @@ namespace VRCX
|
||||
ProcessMonitor.Instance.Init();
|
||||
SQLiteLegacy.Instance.Init();
|
||||
VRCXStorage.Load();
|
||||
LoadFromConfig();
|
||||
CpuMonitor.Instance.Init();
|
||||
Discord.Instance.Init();
|
||||
WebApi.Instance.Init();
|
||||
@@ -170,14 +168,5 @@ namespace VRCX
|
||||
SQLiteLegacy.Instance.Exit();
|
||||
ProcessMonitor.Instance.Exit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets GPUFix to true if it is not already set and the VRCX_GPUFix key in the database is true.
|
||||
/// </summary>
|
||||
private static void LoadFromConfig()
|
||||
{
|
||||
if (!GPUFix)
|
||||
GPUFix = VRCXStorage.Instance.Get("VRCX_GPUFix") == "true";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,6 @@ namespace VRCX
|
||||
|
||||
foreach (var arg in args)
|
||||
{
|
||||
if (arg.Contains("--gpufix"))
|
||||
Program.GPUFix = true;
|
||||
|
||||
if (arg.Length > 12 && arg.Substring(0, 12) == "/uri=vrcx://")
|
||||
LaunchCommand = arg.Substring(12);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user