From e8a64cebf64a04a7655100b2030a6beee32ed332 Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 20 Sep 2018 16:06:58 +0200 Subject: [PATCH 01/30] version bump to 3.0.0.6 --- Xenko.xkpkg | 2 +- sources/shared/SharedAssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Xenko.xkpkg b/Xenko.xkpkg index 581a0bc352..dffb639a2e 100644 --- a/Xenko.xkpkg +++ b/Xenko.xkpkg @@ -3,7 +3,7 @@ Id: cc1bcc78-50b2-4da6-8902-f7a3ae42898b SerializedVersion: {Assets: 0.0.4} Meta: Name: Xenko - Version: 3.0.0.5-dev + Version: 3.0.0.6-dev Owners: - Xenko Authors: diff --git a/sources/shared/SharedAssemblyInfo.cs b/sources/shared/SharedAssemblyInfo.cs index c3904e7190..1c21548ab3 100644 --- a/sources/shared/SharedAssemblyInfo.cs +++ b/sources/shared/SharedAssemblyInfo.cs @@ -26,7 +26,7 @@ internal class XenkoVersion /// /// The version used by editor for display purpose. 4th digit needs to be at least 1 if used (due to NuGet special cases). /// - public const string PublicVersion = "3.0.0.5"; + public const string PublicVersion = "3.0.0.6"; /// /// The current assembly version as text, currently same as . From a7decbe0c2a76fc6deacfd7c9c840816ec35539e Mon Sep 17 00:00:00 2001 From: joreg Date: Mon, 24 Sep 2018 17:32:57 +0200 Subject: [PATCH 02/30] added TrackedDevices for OpenVR, other VR APIs return null for now --- .../Xenko.VirtualReality/DeviceEnums.cs | 21 +++++++ .../Xenko.VirtualReality/DeviceState.cs | 11 ---- .../Xenko.VirtualReality/DummyDevice.cs | 2 + .../Xenko.VirtualReality/Fove/FoveHmd.cs | 2 + .../OculusOVR/OculusOvrHmd.cs | 2 + .../Xenko.VirtualReality/OpenVR/OpenVR.cs | 50 +++++++++++++++ .../Xenko.VirtualReality/OpenVR/OpenVrHmd.cs | 9 +++ .../OpenVR/OpenVrTrackedDevice.cs | 63 +++++++++++++++++++ .../Xenko.VirtualReality/TrackedDevice.cs | 33 ++++++++++ .../engine/Xenko.VirtualReality/VRDevice.cs | 2 + 10 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 sources/engine/Xenko.VirtualReality/DeviceEnums.cs delete mode 100644 sources/engine/Xenko.VirtualReality/DeviceState.cs create mode 100644 sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs create mode 100644 sources/engine/Xenko.VirtualReality/TrackedDevice.cs diff --git a/sources/engine/Xenko.VirtualReality/DeviceEnums.cs b/sources/engine/Xenko.VirtualReality/DeviceEnums.cs new file mode 100644 index 0000000000..1b865c3a17 --- /dev/null +++ b/sources/engine/Xenko.VirtualReality/DeviceEnums.cs @@ -0,0 +1,21 @@ +// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +namespace Xenko.VirtualReality +{ + public enum DeviceState + { + Invalid, + OutOfRange, + Valid, + } + + public enum DeviceClass + { + Invalid, //There is no device at this index + HMD, //The device at this index is an HMD + Controller, //The device is a controller + GenericTracker, //The device is a tracker + TrackingReference, //The device is a camera, Lighthouse base station, or other device that supplies tracking ground truth. + DisplayRedirect //Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices + } +} diff --git a/sources/engine/Xenko.VirtualReality/DeviceState.cs b/sources/engine/Xenko.VirtualReality/DeviceState.cs deleted file mode 100644 index 020abd8e52..0000000000 --- a/sources/engine/Xenko.VirtualReality/DeviceState.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) -// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. -namespace Xenko.VirtualReality -{ - public enum DeviceState - { - Invalid, - OutOfRange, - Valid, - } -} diff --git a/sources/engine/Xenko.VirtualReality/DummyDevice.cs b/sources/engine/Xenko.VirtualReality/DummyDevice.cs index 8cd3096524..b1fab4ef99 100644 --- a/sources/engine/Xenko.VirtualReality/DummyDevice.cs +++ b/sources/engine/Xenko.VirtualReality/DummyDevice.cs @@ -43,6 +43,8 @@ public class DummyDevice : VRDevice public override TouchController RightHand => null; + public override TrackedDevice[] TrackedDevices => null; + public override bool CanInitialize => true; /// diff --git a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs index 207039e4b1..8fc5dc7344 100644 --- a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs +++ b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs @@ -136,6 +136,8 @@ public override void Draw(GameTime gameTime) public override TouchController RightHand => null; + public override TrackedDevice[] TrackedDevices => null; + public override bool CanInitialize => Fove.Startup() && Fove.IsHardwareReady(); } } diff --git a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs index 185aa0b985..7e133b54e5 100644 --- a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs @@ -137,6 +137,8 @@ public override DeviceState State public override TouchController RightHand => rightHandController; + public override TrackedDevice[] TrackedDevices => null; + public override bool CanInitialize { get diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 7705adfbc5..42bd0d86d4 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -150,6 +150,27 @@ public void Update() } } + public class TrackedDevice + { + public TrackedDevice(int trackerIndex) + { + TrackerIndex = trackerIndex; + } + + public void Update() + { + var error = ETrackedPropertyError.TrackedProp_Success; + var result = new System.Text.StringBuilder((int)64); + Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); + DeviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); + SerialNumber = result.ToString(); + } + + internal int TrackerIndex; + internal ETrackedDeviceClass DeviceClass; + internal string SerialNumber; + } + private static readonly TrackedDevicePose_t[] DevicePoses = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount]; private static readonly TrackedDevicePose_t[] GamePoses = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount]; @@ -268,6 +289,35 @@ private static unsafe DeviceState GetControllerPoseUnsafe(int controllerIndex, o return DeviceState.Invalid; } + public static DeviceState GetTrackerPose(int trackerIndex, out Matrix pose, out Vector3 velocity, out Vector3 angVelocity) + { + return GetTrackerPoseUnsafe(trackerIndex, out pose, out velocity, out angVelocity); + } + + private static unsafe DeviceState GetTrackerPoseUnsafe(int trackerIndex, out Matrix pose, out Vector3 velocity, out Vector3 angVelocity) + { + pose = Matrix.Identity; + velocity = Vector3.Zero; + angVelocity = Vector3.Zero; + var index = trackerIndex; + + Utilities.CopyMemory((IntPtr)Interop.Fixed(ref pose), (IntPtr)Interop.Fixed(ref DevicePoses[index].mDeviceToAbsoluteTracking), Utilities.SizeOf()); + Utilities.CopyMemory((IntPtr)Interop.Fixed(ref velocity), (IntPtr)Interop.Fixed(ref DevicePoses[index].vVelocity), Utilities.SizeOf()); + Utilities.CopyMemory((IntPtr)Interop.Fixed(ref angVelocity), (IntPtr)Interop.Fixed(ref DevicePoses[index].vAngularVelocity), Utilities.SizeOf()); + + var state = DeviceState.Invalid; + if (DevicePoses[index].bDeviceIsConnected && DevicePoses[index].bPoseIsValid) + { + state = DeviceState.Valid; + } + else if (DevicePoses[index].bDeviceIsConnected && !DevicePoses[index].bPoseIsValid && DevicePoses[index].eTrackingResult == ETrackingResult.Running_OutOfRange) + { + state = DeviceState.OutOfRange; + } + + return state; + } + public static DeviceState GetHeadPose(out Matrix pose, out Vector3 linearVelocity, out Vector3 angularVelocity) { return GetHeadPoseUnsafe(out pose, out linearVelocity, out angularVelocity); diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs index ded6517c4d..a8a878e92a 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs @@ -18,6 +18,7 @@ internal class OpenVRHmd : VRDevice private DeviceState state; private OpenVRTouchController leftHandController; private OpenVRTouchController rightHandController; + private OpenVRTrackedDevice[] trackedDevices; private bool needsMirror; private Matrix currentHead; private Vector3 currentHeadPos; @@ -55,6 +56,10 @@ public override void Enable(GraphicsDevice device, GraphicsDeviceManager graphic leftHandController = new OpenVRTouchController(TouchControllerHand.Left); rightHandController = new OpenVRTouchController(TouchControllerHand.Right); + + trackedDevices = new OpenVRTrackedDevice[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount]; + for (int i=0; i rightHandController; + public override TrackedDevice[] TrackedDevices => trackedDevices; + public override Texture MirrorTexture { get; protected set; } public override float RenderFrameScaling { get; set; } = 1.4f; diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs new file mode 100644 index 0000000000..da4d6d985b --- /dev/null +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs @@ -0,0 +1,63 @@ +// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +#if XENKO_GRAPHICS_API_DIRECT3D11 + +using System; +using Xenko.Core.Mathematics; +using Xenko.Games; + +namespace Xenko.VirtualReality +{ + internal class OpenVRTrackedDevice : TrackedDevice + { + private readonly int id; + private OpenVR.TrackedDevice trackedDevice; + private DeviceState internalState; + private Vector3 currentPos; + private Vector3 currentLinearVelocity; + private Vector3 currentAngularVelocity; + private Quaternion currentRot; + + internal OpenVRTrackedDevice(int index) + { + trackedDevice = new OpenVR.TrackedDevice(index); + } + + public override void Update(GameTime gameTime) + { + if (trackedDevice != null) + { + trackedDevice.Update(); + + Matrix mat; + Vector3 vel, angVel; + internalState = OpenVR.GetTrackerPose(trackedDevice.TrackerIndex, out mat, out vel, out angVel); + if (internalState != DeviceState.Invalid) + { + Vector3 scale; + mat.Decompose(out scale, out currentRot, out currentPos); + currentLinearVelocity = vel; + currentAngularVelocity = new Vector3(MathUtil.DegreesToRadians(angVel.X), MathUtil.DegreesToRadians(angVel.Y), MathUtil.DegreesToRadians(angVel.Z)); + } + } + + base.Update(gameTime); + } + + public override Vector3 Position => currentPos; + + public override Quaternion Rotation => currentRot; + + public override Vector3 LinearVelocity => currentLinearVelocity; + + public override Vector3 AngularVelocity => currentAngularVelocity; + + public override DeviceState State => internalState; + + public override DeviceClass Class => (DeviceClass)trackedDevice.DeviceClass; + + public override string SerialNumber => trackedDevice.SerialNumber; + } +} + +#endif diff --git a/sources/engine/Xenko.VirtualReality/TrackedDevice.cs b/sources/engine/Xenko.VirtualReality/TrackedDevice.cs new file mode 100644 index 0000000000..1bcc27a9fd --- /dev/null +++ b/sources/engine/Xenko.VirtualReality/TrackedDevice.cs @@ -0,0 +1,33 @@ +// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +using System; +using Xenko.Core.Mathematics; +using Xenko.Games; + +namespace Xenko.VirtualReality +{ + public abstract class TrackedDevice : IDisposable + { + public abstract Vector3 Position { get; } + + public abstract Quaternion Rotation { get; } + + public abstract Vector3 LinearVelocity { get; } + + public abstract Vector3 AngularVelocity { get; } + + public abstract DeviceState State { get; } + + public abstract DeviceClass Class { get; } + + public abstract string SerialNumber { get; } + + public virtual void Update(GameTime time) + { + } + + public virtual void Dispose() + { + } + } +} diff --git a/sources/engine/Xenko.VirtualReality/VRDevice.cs b/sources/engine/Xenko.VirtualReality/VRDevice.cs index 8d4b2e4ac2..656efca23d 100644 --- a/sources/engine/Xenko.VirtualReality/VRDevice.cs +++ b/sources/engine/Xenko.VirtualReality/VRDevice.cs @@ -38,6 +38,8 @@ protected VRDevice() public abstract TouchController RightHand { get; } + public abstract TrackedDevice[] TrackedDevices { get; } + public VRApi VRApi { get; protected set; } /// From b60b013eb9bacdff0728b37f0c144d86fc069420 Mon Sep 17 00:00:00 2001 From: joreg Date: Mon, 1 Oct 2018 17:25:49 +0200 Subject: [PATCH 03/30] TrackedDevice collection properties now return empty array, rather than null --- sources/engine/Xenko.VirtualReality/DummyDevice.cs | 2 +- sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs | 2 +- sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/DummyDevice.cs b/sources/engine/Xenko.VirtualReality/DummyDevice.cs index b1fab4ef99..ae8d53609e 100644 --- a/sources/engine/Xenko.VirtualReality/DummyDevice.cs +++ b/sources/engine/Xenko.VirtualReality/DummyDevice.cs @@ -43,7 +43,7 @@ public class DummyDevice : VRDevice public override TouchController RightHand => null; - public override TrackedDevice[] TrackedDevices => null; + public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; public override bool CanInitialize => true; diff --git a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs index 8fc5dc7344..16dea00a3e 100644 --- a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs +++ b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs @@ -136,7 +136,7 @@ public override void Draw(GameTime gameTime) public override TouchController RightHand => null; - public override TrackedDevice[] TrackedDevices => null; + public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; public override bool CanInitialize => Fove.Startup() && Fove.IsHardwareReady(); } diff --git a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs index 7e133b54e5..e633689601 100644 --- a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs @@ -137,7 +137,7 @@ public override DeviceState State public override TouchController RightHand => rightHandController; - public override TrackedDevice[] TrackedDevices => null; + public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; public override bool CanInitialize { From 46a7602b88b2d1aefd696fe03cf48d2de754047b Mon Sep 17 00:00:00 2001 From: joreg Date: Mon, 1 Oct 2018 18:06:46 +0200 Subject: [PATCH 04/30] renamed Xenko.VirtualReality.TrackedDevice to TrackedItem to not be confused with OpenVR.TrackedDevice --- sources/engine/Xenko.VirtualReality/DummyDevice.cs | 2 +- sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs | 2 +- sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs | 2 +- sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs | 2 +- .../engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs | 2 +- .../Xenko.VirtualReality/{TrackedDevice.cs => TrackedItem.cs} | 2 +- sources/engine/Xenko.VirtualReality/VRDevice.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename sources/engine/Xenko.VirtualReality/{TrackedDevice.cs => TrackedItem.cs} (94%) diff --git a/sources/engine/Xenko.VirtualReality/DummyDevice.cs b/sources/engine/Xenko.VirtualReality/DummyDevice.cs index ae8d53609e..d006d2f706 100644 --- a/sources/engine/Xenko.VirtualReality/DummyDevice.cs +++ b/sources/engine/Xenko.VirtualReality/DummyDevice.cs @@ -43,7 +43,7 @@ public class DummyDevice : VRDevice public override TouchController RightHand => null; - public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; + public override TrackedItem[] TrackedItems => new TrackedItem[0]; public override bool CanInitialize => true; diff --git a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs index 16dea00a3e..60589ffeda 100644 --- a/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs +++ b/sources/engine/Xenko.VirtualReality/Fove/FoveHmd.cs @@ -136,7 +136,7 @@ public override void Draw(GameTime gameTime) public override TouchController RightHand => null; - public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; + public override TrackedItem[] TrackedItems => new TrackedItem[0]; public override bool CanInitialize => Fove.Startup() && Fove.IsHardwareReady(); } diff --git a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs index e633689601..dc3724b703 100644 --- a/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OculusOVR/OculusOvrHmd.cs @@ -137,7 +137,7 @@ public override DeviceState State public override TouchController RightHand => rightHandController; - public override TrackedDevice[] TrackedDevices => new TrackedDevice[0]; + public override TrackedItem[] TrackedItems => new TrackedItem[0]; public override bool CanInitialize { diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs index a8a878e92a..037ecb7461 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs @@ -143,7 +143,7 @@ public override void Recenter() public override TouchController RightHand => rightHandController; - public override TrackedDevice[] TrackedDevices => trackedDevices; + public override TrackedItem[] TrackedItems => trackedDevices; public override Texture MirrorTexture { get; protected set; } diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs index da4d6d985b..c636412faf 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs @@ -8,7 +8,7 @@ namespace Xenko.VirtualReality { - internal class OpenVRTrackedDevice : TrackedDevice + internal class OpenVRTrackedDevice : TrackedItem { private readonly int id; private OpenVR.TrackedDevice trackedDevice; diff --git a/sources/engine/Xenko.VirtualReality/TrackedDevice.cs b/sources/engine/Xenko.VirtualReality/TrackedItem.cs similarity index 94% rename from sources/engine/Xenko.VirtualReality/TrackedDevice.cs rename to sources/engine/Xenko.VirtualReality/TrackedItem.cs index 1bcc27a9fd..f1855892f8 100644 --- a/sources/engine/Xenko.VirtualReality/TrackedDevice.cs +++ b/sources/engine/Xenko.VirtualReality/TrackedItem.cs @@ -6,7 +6,7 @@ namespace Xenko.VirtualReality { - public abstract class TrackedDevice : IDisposable + public abstract class TrackedItem : IDisposable { public abstract Vector3 Position { get; } diff --git a/sources/engine/Xenko.VirtualReality/VRDevice.cs b/sources/engine/Xenko.VirtualReality/VRDevice.cs index 656efca23d..0be7afbc1f 100644 --- a/sources/engine/Xenko.VirtualReality/VRDevice.cs +++ b/sources/engine/Xenko.VirtualReality/VRDevice.cs @@ -38,7 +38,7 @@ protected VRDevice() public abstract TouchController RightHand { get; } - public abstract TrackedDevice[] TrackedDevices { get; } + public abstract TrackedItem[] TrackedItems { get; } public VRApi VRApi { get; protected set; } From 8f0dfc8458d655a7d6a70e51321b14fe227e14ab Mon Sep 17 00:00:00 2001 From: joreg Date: Mon, 1 Oct 2018 18:07:52 +0200 Subject: [PATCH 05/30] added BatteryPercentage to TrackedItem --- sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs | 7 ++++++- .../Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs | 2 ++ sources/engine/Xenko.VirtualReality/TrackedItem.cs | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 42bd0d86d4..0fd35559cc 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -162,13 +162,18 @@ public void Update() var error = ETrackedPropertyError.TrackedProp_Success; var result = new System.Text.StringBuilder((int)64); Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); - DeviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); SerialNumber = result.ToString(); + + BatteryPercentage = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); + SerialNumber = result.ToString(); + + DeviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); } internal int TrackerIndex; internal ETrackedDeviceClass DeviceClass; internal string SerialNumber; + internal float BatteryPercentage; } private static readonly TrackedDevicePose_t[] DevicePoses = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount]; diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs index c636412faf..5011301a71 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs @@ -57,6 +57,8 @@ public override void Update(GameTime gameTime) public override DeviceClass Class => (DeviceClass)trackedDevice.DeviceClass; public override string SerialNumber => trackedDevice.SerialNumber; + + public override float BatteryPercentage => trackedDevice.BatteryPercentage; } } diff --git a/sources/engine/Xenko.VirtualReality/TrackedItem.cs b/sources/engine/Xenko.VirtualReality/TrackedItem.cs index f1855892f8..b5cb7271f9 100644 --- a/sources/engine/Xenko.VirtualReality/TrackedItem.cs +++ b/sources/engine/Xenko.VirtualReality/TrackedItem.cs @@ -22,6 +22,8 @@ public abstract class TrackedItem : IDisposable public abstract string SerialNumber { get; } + public abstract float BatteryPercentage { get; } + public virtual void Update(GameTime time) { } From 2b5c5918526b1c701181fd76e06c0cb9bed684a8 Mon Sep 17 00:00:00 2001 From: tebjan Date: Sun, 7 Oct 2018 23:04:30 +0200 Subject: [PATCH 06/30] removed double ToString call and moved serial number getter to constructor since it doesn't change at runtime (cherry picked from commit b6a8f4912637b7f89b0017da07df3ae6efc53a57) --- sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 0fd35559cc..0110ac5149 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -155,17 +155,19 @@ public class TrackedDevice public TrackedDevice(int trackerIndex) { TrackerIndex = trackerIndex; + + var error = ETrackedPropertyError.TrackedProp_Success; + var result = new System.Text.StringBuilder((int)64); + Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); + if (error == ETrackedPropertyError.TrackedProp_Success) + SerialNumber = result.ToString(); } public void Update() { var error = ETrackedPropertyError.TrackedProp_Success; - var result = new System.Text.StringBuilder((int)64); - Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); - SerialNumber = result.ToString(); BatteryPercentage = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); - SerialNumber = result.ToString(); DeviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); } From 44e467c044d60ab2709eaa6a554a8eb21ec5fc48 Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 8 Oct 2018 01:47:35 +0200 Subject: [PATCH 07/30] added TextureOptions to create directx 11 textures with the Shared or SharedNtHandle option. also added SharedHandle property to Texture class to read the handle after texture creation. --- .../Direct3D/Texture.Direct3D.cs | 44 ++++++++++++++-- sources/engine/Xenko.Graphics/Texture.cs | 24 +++++++++ .../TextureDescription.Extensions2D.cs | 11 ++-- .../Xenko.Graphics/TextureDescription.cs | 5 ++ .../engine/Xenko.Graphics/TextureOptions.cs | 51 +++++++++++++++++++ 5 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 sources/engine/Xenko.Graphics/TextureOptions.cs diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index d6997a3d7d..258a84656f 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -75,6 +75,7 @@ private set } } + public void Recreate(DataBox[] dataBoxes = null) { InitializeFromImpl(dataBoxes); @@ -154,7 +155,36 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) NativeShaderResourceView = GetShaderResourceView(ViewType, ArraySlice, MipLevel); NativeUnorderedAccessView = GetUnorderedAccessView(ViewType, ArraySlice, MipLevel); NativeRenderTargetView = GetRenderTargetView(ViewType, ArraySlice, MipLevel); - NativeDepthStencilView = GetDepthStencilView(out HasStencil); + NativeDepthStencilView = GetDepthStencilView(out HasStencil); + + if (textureDescription.Options == TextureOptions.Shared) + { + try + { + switch (textureDescription.Options) + { + case TextureOptions.None: + break; + case TextureOptions.Shared: + var sharedResource = NativeDeviceChild.QueryInterface(); + SharedHandle = sharedResource.SharedHandle; + break; + case TextureOptions.SharedNthandle: + var sharedResource1 = NativeDeviceChild.QueryInterface(); + var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); + SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); + SharedNtHandleName = uniqueName; + break; + default: + SharedHandle = IntPtr.Zero; + break; + } + } + catch + { + SharedHandle = IntPtr.Zero; + } + } } protected internal override void OnDestroyed() @@ -537,7 +567,7 @@ private Texture1DDescription ConvertToNativeDescription1D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; return desc; } @@ -568,6 +598,7 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript Usage = (GraphicsResourceUsage)description.Usage, ArraySize = description.ArraySize, Flags = TextureFlags.None, + Options = TextureOptions.None }; if ((description.BindFlags & BindFlags.RenderTarget) != 0) @@ -579,6 +610,11 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript if ((description.BindFlags & BindFlags.ShaderResource) != 0) desc.Flags |= TextureFlags.ShaderResource; + if ((description.OptionFlags & ResourceOptionFlags.Shared) != 0) + desc.Options |= TextureOptions.Shared; + if ((description.OptionFlags & ResourceOptionFlags.SharedNthandle) != 0) + desc.Options |= TextureOptions.SharedNthandle; + return desc; } @@ -656,7 +692,7 @@ private Texture2DDescription ConvertToNativeDescription2D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; if (textureDescription.Dimension == TextureDimension.TextureCube) @@ -733,7 +769,7 @@ private Texture3DDescription ConvertToNativeDescription3D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; return desc; } diff --git a/sources/engine/Xenko.Graphics/Texture.cs b/sources/engine/Xenko.Graphics/Texture.cs index d103dbed77..4e6b242c57 100644 --- a/sources/engine/Xenko.Graphics/Texture.cs +++ b/sources/engine/Xenko.Graphics/Texture.cs @@ -287,6 +287,27 @@ public TextureFlags Flags } } + /// + /// Resource options for DirextX 11 textures. + /// + public TextureOptions Options + { + get + { + return textureDescription.Options; + } + } + + /// + /// The shared handle if created with TextureOption.Shared or TextureOption.SharedNthandle, IntPtr.Zero otherwise. + /// + public IntPtr SharedHandle { get; private set; } = IntPtr.Zero; + + /// + /// Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle. + /// + public string SharedNtHandleName { get; private set; } = string.Empty; + /// /// Gets a value indicating whether this instance is a render target. /// @@ -359,6 +380,9 @@ public bool IsMultisample } } + + + /// /// Gets a boolean indicating whether this is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). /// diff --git a/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs b/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs index c195e4cc87..0d23db264d 100644 --- a/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs +++ b/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs @@ -14,9 +14,9 @@ public partial struct TextureDescription /// Size of the texture 2D array, default to 1. /// The usage. /// A new instance of class. - public static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) + public static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions textureOptions = TextureOptions.None) { - return New2D(width, height, false, format, textureFlags, arraySize, usage); + return New2D(width, height, false, format, textureFlags, arraySize, usage, MultisampleCount.None, textureOptions); } /// @@ -31,12 +31,12 @@ public static TextureDescription New2D(int width, int height, PixelFormat format /// The usage. /// The multisample count. /// A new instance of class. - public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None) + public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None, TextureOptions textureOptions = TextureOptions.None) { - return New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount); + return New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount, textureOptions); } - private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount) + private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount, TextureOptions textureOptions = TextureOptions.None) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) usage = GraphicsResourceUsage.Default; @@ -53,6 +53,7 @@ private static TextureDescription New2D(int width, int height, PixelFormat forma Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width, height), Usage = Texture.GetUsageWithFlags(usage, textureFlags), + Options = textureOptions }; return desc; } diff --git a/sources/engine/Xenko.Graphics/TextureDescription.cs b/sources/engine/Xenko.Graphics/TextureDescription.cs index 8cb0929700..f447f9a1b7 100644 --- a/sources/engine/Xenko.Graphics/TextureDescription.cs +++ b/sources/engine/Xenko.Graphics/TextureDescription.cs @@ -100,6 +100,11 @@ public partial struct TextureDescription : IEquatable /// public TextureFlags Flags; + /// + /// Resource options for DirextX 11 textures. + /// + public TextureOptions Options; + /// /// Gets a value indicating whether this instance is a render target. /// diff --git a/sources/engine/Xenko.Graphics/TextureOptions.cs b/sources/engine/Xenko.Graphics/TextureOptions.cs new file mode 100644 index 0000000000..62ddd4894b --- /dev/null +++ b/sources/engine/Xenko.Graphics/TextureOptions.cs @@ -0,0 +1,51 @@ +// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +using System; + +namespace Xenko.Graphics +{ + /// + /// Resource options for textures. + /// + /// + /// This enumeration is used in TextureDescription.The TextureOptions + /// must be 'None' when creating textures with CPU access flags. + /// + [Flags] + public enum TextureOptions + { + /// + /// None. The default. + /// + None = 0, + + /// + /// Enables resource data sharing between two or more Direct3D devices. The only + /// resources that can be shared are 2D non-mipmapped textures. SharpDX.Direct3D11.ResourceOptionFlags.Shared + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex are mutually exclusive. + /// WARP and REF devices do not support shared resources. If you try to create a + /// resource with this flag on either a WARP or REF device, the create method will + /// return an E_OUTOFMEMORY error code. Note?? Starting with Windows?8, WARP devices + /// fully support shared resources. ? Note?? Starting with Windows?8, we recommend + /// that you enable resource data sharing between two or more Direct3D devices by + /// using a combination of the SharpDX.Direct3D11.ResourceOptionFlags.SharedNthandle + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex flags instead. ? + /// + Shared = 2, + + /// + /// Set this flag to enable the use of NT HANDLE values when you create a shared + /// resource. By enabling this flag, you deprecate the use of existing HANDLE values. + /// When you use this flag, you must combine it with the SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex + /// flag by using a bitwise OR operation. The resulting value specifies a new shared + /// resource type that directs the runtime to use NT HANDLE values for the shared + /// resource. The runtime then must confirm that the shared resource works on all + /// hardware at the specified feature level. Without this flag set, the runtime does + /// not strictly validate shared resource parameters (that is, formats, flags, usage, + /// and so on). When the runtime does not validate shared resource parameters, behavior + /// of much of the Direct3D API might be undefined and might vary from driver to + /// driver. Direct3D 11 and earlier: This value is not supported until Direct3D 11.1. + /// + SharedNthandle = 2048, + } +} From d405caf99276414f9e1adea930ea3e12ef2ad668 Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 8 Oct 2018 02:06:27 +0200 Subject: [PATCH 08/30] SharedKeyedmutex was missing. --- .../Direct3D/Texture.Direct3D.cs | 2 ++ .../engine/Xenko.Graphics/TextureOptions.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index 258a84656f..8fed003976 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -612,6 +612,8 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript if ((description.OptionFlags & ResourceOptionFlags.Shared) != 0) desc.Options |= TextureOptions.Shared; + if ((description.OptionFlags & ResourceOptionFlags.SharedKeyedmutex) != 0) + desc.Options |= TextureOptions.SharedKeyedmutex; if ((description.OptionFlags & ResourceOptionFlags.SharedNthandle) != 0) desc.Options |= TextureOptions.SharedNthandle; diff --git a/sources/engine/Xenko.Graphics/TextureOptions.cs b/sources/engine/Xenko.Graphics/TextureOptions.cs index 62ddd4894b..649318425c 100644 --- a/sources/engine/Xenko.Graphics/TextureOptions.cs +++ b/sources/engine/Xenko.Graphics/TextureOptions.cs @@ -33,6 +33,32 @@ public enum TextureOptions /// Shared = 2, + /// + /// Enables the resource to be synchronized by using the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) + /// and SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs. The following Direct3D?11 + /// resource creation APIs, that take SharpDX.Direct3D11.ResourceOptionFlags parameters, + /// have been extended to support the new flag. SharpDX.Direct3D11.Device.CreateTexture1D(SharpDX.Direct3D11.Texture1DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture1D) + /// SharpDX.Direct3D11.Device.CreateTexture2D(SharpDX.Direct3D11.Texture2DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture2D) + /// SharpDX.Direct3D11.Device.CreateTexture3D(SharpDX.Direct3D11.Texture3DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture3D) + /// SharpDX.Direct3D11.Device.CreateBuffer(SharpDX.Direct3D11.BufferDescription@,System.Nullable{SharpDX.DataBox},SharpDX.Direct3D11.Buffer) + /// If you call any of these methods with the SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex + /// flag set, the interface returned will support the SharpDX.DXGI.KeyedMutex interface. + /// You can retrieve a reference to the SharpDX.DXGI.KeyedMutex interface from the + /// resource by using IUnknown::QueryInterface. The SharpDX.DXGI.KeyedMutex interface + /// implements the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) and + /// SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs to synchronize access to the + /// surface. The device that creates the surface, and any other device that opens + /// the surface by using OpenSharedResource, must call SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) + /// before they issue any rendering commands to the surface. When those devices finish + /// rendering, they must call SharpDX.DXGI.KeyedMutex.Release(System.Int64). SharpDX.Direct3D11.ResourceOptionFlags.Shared + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex are mutually exclusive. + /// WARP and REF devices do not support shared resources. If you try to create a + /// resource with this flag on either a WARP or REF device, the create method will + /// return an E_OUTOFMEMORY error code. Note?? Starting with Windows?8, WARP devices + /// fully support shared resources. ? + /// + SharedKeyedmutex = 256, + /// /// Set this flag to enable the use of NT HANDLE values when you create a shared /// resource. By enabling this flag, you deprecate the use of existing HANDLE values. From 9cd61b2e6aa4389c453d440d5d1ed6061f9c52e0 Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 8 Oct 2018 02:26:26 +0200 Subject: [PATCH 09/30] added TextureOptions to create directx 11 textures with the Shared or SharedNtHandle option. also added SharedHandle property to Texture class to read the handle after texture creation. --- .../Direct3D/Texture.Direct3D.cs | 46 ++++++++++- sources/engine/Xenko.Graphics/Texture.cs | 24 ++++++ .../TextureDescription.Extensions2D.cs | 11 +-- .../Xenko.Graphics/TextureDescription.cs | 5 ++ .../engine/Xenko.Graphics/TextureOptions.cs | 77 +++++++++++++++++++ 5 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 sources/engine/Xenko.Graphics/TextureOptions.cs diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index d6997a3d7d..8fed003976 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -75,6 +75,7 @@ private set } } + public void Recreate(DataBox[] dataBoxes = null) { InitializeFromImpl(dataBoxes); @@ -154,7 +155,36 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) NativeShaderResourceView = GetShaderResourceView(ViewType, ArraySlice, MipLevel); NativeUnorderedAccessView = GetUnorderedAccessView(ViewType, ArraySlice, MipLevel); NativeRenderTargetView = GetRenderTargetView(ViewType, ArraySlice, MipLevel); - NativeDepthStencilView = GetDepthStencilView(out HasStencil); + NativeDepthStencilView = GetDepthStencilView(out HasStencil); + + if (textureDescription.Options == TextureOptions.Shared) + { + try + { + switch (textureDescription.Options) + { + case TextureOptions.None: + break; + case TextureOptions.Shared: + var sharedResource = NativeDeviceChild.QueryInterface(); + SharedHandle = sharedResource.SharedHandle; + break; + case TextureOptions.SharedNthandle: + var sharedResource1 = NativeDeviceChild.QueryInterface(); + var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); + SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); + SharedNtHandleName = uniqueName; + break; + default: + SharedHandle = IntPtr.Zero; + break; + } + } + catch + { + SharedHandle = IntPtr.Zero; + } + } } protected internal override void OnDestroyed() @@ -537,7 +567,7 @@ private Texture1DDescription ConvertToNativeDescription1D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; return desc; } @@ -568,6 +598,7 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript Usage = (GraphicsResourceUsage)description.Usage, ArraySize = description.ArraySize, Flags = TextureFlags.None, + Options = TextureOptions.None }; if ((description.BindFlags & BindFlags.RenderTarget) != 0) @@ -579,6 +610,13 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript if ((description.BindFlags & BindFlags.ShaderResource) != 0) desc.Flags |= TextureFlags.ShaderResource; + if ((description.OptionFlags & ResourceOptionFlags.Shared) != 0) + desc.Options |= TextureOptions.Shared; + if ((description.OptionFlags & ResourceOptionFlags.SharedKeyedmutex) != 0) + desc.Options |= TextureOptions.SharedKeyedmutex; + if ((description.OptionFlags & ResourceOptionFlags.SharedNthandle) != 0) + desc.Options |= TextureOptions.SharedNthandle; + return desc; } @@ -656,7 +694,7 @@ private Texture2DDescription ConvertToNativeDescription2D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; if (textureDescription.Dimension == TextureDimension.TextureCube) @@ -733,7 +771,7 @@ private Texture3DDescription ConvertToNativeDescription3D() MipLevels = textureDescription.MipLevels, Usage = (ResourceUsage)textureDescription.Usage, CpuAccessFlags = GetCpuAccessFlagsFromUsage(textureDescription.Usage), - OptionFlags = ResourceOptionFlags.None, + OptionFlags = (ResourceOptionFlags)textureDescription.Options, }; return desc; } diff --git a/sources/engine/Xenko.Graphics/Texture.cs b/sources/engine/Xenko.Graphics/Texture.cs index d103dbed77..4e6b242c57 100644 --- a/sources/engine/Xenko.Graphics/Texture.cs +++ b/sources/engine/Xenko.Graphics/Texture.cs @@ -287,6 +287,27 @@ public TextureFlags Flags } } + /// + /// Resource options for DirextX 11 textures. + /// + public TextureOptions Options + { + get + { + return textureDescription.Options; + } + } + + /// + /// The shared handle if created with TextureOption.Shared or TextureOption.SharedNthandle, IntPtr.Zero otherwise. + /// + public IntPtr SharedHandle { get; private set; } = IntPtr.Zero; + + /// + /// Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle. + /// + public string SharedNtHandleName { get; private set; } = string.Empty; + /// /// Gets a value indicating whether this instance is a render target. /// @@ -359,6 +380,9 @@ public bool IsMultisample } } + + + /// /// Gets a boolean indicating whether this is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). /// diff --git a/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs b/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs index c195e4cc87..0d23db264d 100644 --- a/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs +++ b/sources/engine/Xenko.Graphics/TextureDescription.Extensions2D.cs @@ -14,9 +14,9 @@ public partial struct TextureDescription /// Size of the texture 2D array, default to 1. /// The usage. /// A new instance of class. - public static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) + public static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions textureOptions = TextureOptions.None) { - return New2D(width, height, false, format, textureFlags, arraySize, usage); + return New2D(width, height, false, format, textureFlags, arraySize, usage, MultisampleCount.None, textureOptions); } /// @@ -31,12 +31,12 @@ public static TextureDescription New2D(int width, int height, PixelFormat format /// The usage. /// The multisample count. /// A new instance of class. - public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None) + public static TextureDescription New2D(int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, MultisampleCount multisampleCount = MultisampleCount.None, TextureOptions textureOptions = TextureOptions.None) { - return New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount); + return New2D(width, height, format, textureFlags, mipCount, arraySize, usage, multisampleCount, textureOptions); } - private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount) + private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage, MultisampleCount multisampleCount, TextureOptions textureOptions = TextureOptions.None) { if ((textureFlags & TextureFlags.UnorderedAccess) != 0) usage = GraphicsResourceUsage.Default; @@ -53,6 +53,7 @@ private static TextureDescription New2D(int width, int height, PixelFormat forma Format = format, MipLevels = Texture.CalculateMipMapCount(mipCount, width, height), Usage = Texture.GetUsageWithFlags(usage, textureFlags), + Options = textureOptions }; return desc; } diff --git a/sources/engine/Xenko.Graphics/TextureDescription.cs b/sources/engine/Xenko.Graphics/TextureDescription.cs index 8cb0929700..f447f9a1b7 100644 --- a/sources/engine/Xenko.Graphics/TextureDescription.cs +++ b/sources/engine/Xenko.Graphics/TextureDescription.cs @@ -100,6 +100,11 @@ public partial struct TextureDescription : IEquatable /// public TextureFlags Flags; + /// + /// Resource options for DirextX 11 textures. + /// + public TextureOptions Options; + /// /// Gets a value indicating whether this instance is a render target. /// diff --git a/sources/engine/Xenko.Graphics/TextureOptions.cs b/sources/engine/Xenko.Graphics/TextureOptions.cs new file mode 100644 index 0000000000..649318425c --- /dev/null +++ b/sources/engine/Xenko.Graphics/TextureOptions.cs @@ -0,0 +1,77 @@ +// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +using System; + +namespace Xenko.Graphics +{ + /// + /// Resource options for textures. + /// + /// + /// This enumeration is used in TextureDescription.The TextureOptions + /// must be 'None' when creating textures with CPU access flags. + /// + [Flags] + public enum TextureOptions + { + /// + /// None. The default. + /// + None = 0, + + /// + /// Enables resource data sharing between two or more Direct3D devices. The only + /// resources that can be shared are 2D non-mipmapped textures. SharpDX.Direct3D11.ResourceOptionFlags.Shared + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex are mutually exclusive. + /// WARP and REF devices do not support shared resources. If you try to create a + /// resource with this flag on either a WARP or REF device, the create method will + /// return an E_OUTOFMEMORY error code. Note?? Starting with Windows?8, WARP devices + /// fully support shared resources. ? Note?? Starting with Windows?8, we recommend + /// that you enable resource data sharing between two or more Direct3D devices by + /// using a combination of the SharpDX.Direct3D11.ResourceOptionFlags.SharedNthandle + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex flags instead. ? + /// + Shared = 2, + + /// + /// Enables the resource to be synchronized by using the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) + /// and SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs. The following Direct3D?11 + /// resource creation APIs, that take SharpDX.Direct3D11.ResourceOptionFlags parameters, + /// have been extended to support the new flag. SharpDX.Direct3D11.Device.CreateTexture1D(SharpDX.Direct3D11.Texture1DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture1D) + /// SharpDX.Direct3D11.Device.CreateTexture2D(SharpDX.Direct3D11.Texture2DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture2D) + /// SharpDX.Direct3D11.Device.CreateTexture3D(SharpDX.Direct3D11.Texture3DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture3D) + /// SharpDX.Direct3D11.Device.CreateBuffer(SharpDX.Direct3D11.BufferDescription@,System.Nullable{SharpDX.DataBox},SharpDX.Direct3D11.Buffer) + /// If you call any of these methods with the SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex + /// flag set, the interface returned will support the SharpDX.DXGI.KeyedMutex interface. + /// You can retrieve a reference to the SharpDX.DXGI.KeyedMutex interface from the + /// resource by using IUnknown::QueryInterface. The SharpDX.DXGI.KeyedMutex interface + /// implements the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) and + /// SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs to synchronize access to the + /// surface. The device that creates the surface, and any other device that opens + /// the surface by using OpenSharedResource, must call SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) + /// before they issue any rendering commands to the surface. When those devices finish + /// rendering, they must call SharpDX.DXGI.KeyedMutex.Release(System.Int64). SharpDX.Direct3D11.ResourceOptionFlags.Shared + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex are mutually exclusive. + /// WARP and REF devices do not support shared resources. If you try to create a + /// resource with this flag on either a WARP or REF device, the create method will + /// return an E_OUTOFMEMORY error code. Note?? Starting with Windows?8, WARP devices + /// fully support shared resources. ? + /// + SharedKeyedmutex = 256, + + /// + /// Set this flag to enable the use of NT HANDLE values when you create a shared + /// resource. By enabling this flag, you deprecate the use of existing HANDLE values. + /// When you use this flag, you must combine it with the SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex + /// flag by using a bitwise OR operation. The resulting value specifies a new shared + /// resource type that directs the runtime to use NT HANDLE values for the shared + /// resource. The runtime then must confirm that the shared resource works on all + /// hardware at the specified feature level. Without this flag set, the runtime does + /// not strictly validate shared resource parameters (that is, formats, flags, usage, + /// and so on). When the runtime does not validate shared resource parameters, behavior + /// of much of the Direct3D API might be undefined and might vary from driver to + /// driver. Direct3D 11 and earlier: This value is not supported until Direct3D 11.1. + /// + SharedNthandle = 2048, + } +} From 7510b74477d2afcbd3d3a6c62f57e87c74c26ce4 Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 8 Oct 2018 02:43:11 +0200 Subject: [PATCH 10/30] typo in comment --- sources/engine/Xenko.Graphics/Texture.cs | 2 +- sources/engine/Xenko.Graphics/TextureDescription.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Texture.cs b/sources/engine/Xenko.Graphics/Texture.cs index 4e6b242c57..5986632d79 100644 --- a/sources/engine/Xenko.Graphics/Texture.cs +++ b/sources/engine/Xenko.Graphics/Texture.cs @@ -288,7 +288,7 @@ public TextureFlags Flags } /// - /// Resource options for DirextX 11 textures. + /// Resource options for DirectX 11 textures. /// public TextureOptions Options { diff --git a/sources/engine/Xenko.Graphics/TextureDescription.cs b/sources/engine/Xenko.Graphics/TextureDescription.cs index f447f9a1b7..5f8cbe3eb6 100644 --- a/sources/engine/Xenko.Graphics/TextureDescription.cs +++ b/sources/engine/Xenko.Graphics/TextureDescription.cs @@ -101,7 +101,7 @@ public partial struct TextureDescription : IEquatable public TextureFlags Flags; /// - /// Resource options for DirextX 11 textures. + /// Resource options for DirectX 11 textures. /// public TextureOptions Options; From 0f362f4c53079e2a3629f9a9176bb8c6c37c0876 Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 8 Oct 2018 16:34:01 +0200 Subject: [PATCH 11/30] removed unnecessary if and also assign IntPrt.Zero in 'None' case. --- .../Direct3D/Texture.Direct3D.cs | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index 8fed003976..356e3cf468 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -75,7 +75,6 @@ private set } } - public void Recreate(DataBox[] dataBoxes = null) { InitializeFromImpl(dataBoxes); @@ -157,34 +156,32 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) NativeRenderTargetView = GetRenderTargetView(ViewType, ArraySlice, MipLevel); NativeDepthStencilView = GetDepthStencilView(out HasStencil); - if (textureDescription.Options == TextureOptions.Shared) + try { - try + switch (textureDescription.Options) { - switch (textureDescription.Options) - { - case TextureOptions.None: - break; - case TextureOptions.Shared: - var sharedResource = NativeDeviceChild.QueryInterface(); - SharedHandle = sharedResource.SharedHandle; - break; - case TextureOptions.SharedNthandle: - var sharedResource1 = NativeDeviceChild.QueryInterface(); - var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); - SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); - SharedNtHandleName = uniqueName; - break; - default: - SharedHandle = IntPtr.Zero; - break; - } - } - catch - { - SharedHandle = IntPtr.Zero; + case TextureOptions.None: + SharedHandle = IntPtr.Zero; + break; + case TextureOptions.Shared: + var sharedResource = NativeDeviceChild.QueryInterface(); + SharedHandle = sharedResource.SharedHandle; + break; + case TextureOptions.SharedNthandle: + var sharedResource1 = NativeDeviceChild.QueryInterface(); + var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); + SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); + SharedNtHandleName = uniqueName; + break; + default: + SharedHandle = IntPtr.Zero; + break; } } + catch + { + SharedHandle = IntPtr.Zero; + } } protected internal override void OnDestroyed() From 6bbf2e9bd0ce91c7150ed8f63a39adb6b6c0f689 Mon Sep 17 00:00:00 2001 From: joreg Date: Wed, 10 Oct 2018 19:57:15 +0200 Subject: [PATCH 12/30] moved SerialNumber getter back to update since it can change at runtime for a given slot --- sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 0110ac5149..33af2e7945 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -155,17 +155,15 @@ public class TrackedDevice public TrackedDevice(int trackerIndex) { TrackerIndex = trackerIndex; + } + public void Update() + { var error = ETrackedPropertyError.TrackedProp_Success; var result = new System.Text.StringBuilder((int)64); Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); if (error == ETrackedPropertyError.TrackedProp_Success) SerialNumber = result.ToString(); - } - - public void Update() - { - var error = ETrackedPropertyError.TrackedProp_Success; BatteryPercentage = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); From 3d5655944444a8e93df0dc165e8d710f4d9ca7ad Mon Sep 17 00:00:00 2001 From: joreg Date: Wed, 10 Oct 2018 19:57:57 +0200 Subject: [PATCH 13/30] added VRDevice.SetTrackingSpace --- sources/engine/Xenko.VirtualReality/DeviceEnums.cs | 7 +++++++ sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs | 5 +++++ sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs | 5 +++++ sources/engine/Xenko.VirtualReality/VRDevice.cs | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/sources/engine/Xenko.VirtualReality/DeviceEnums.cs b/sources/engine/Xenko.VirtualReality/DeviceEnums.cs index 1b865c3a17..696a3c2eec 100644 --- a/sources/engine/Xenko.VirtualReality/DeviceEnums.cs +++ b/sources/engine/Xenko.VirtualReality/DeviceEnums.cs @@ -18,4 +18,11 @@ public enum DeviceClass TrackingReference, //The device is a camera, Lighthouse base station, or other device that supplies tracking ground truth. DisplayRedirect //Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices } + + public enum TrackingSpace + { + Seated, + Standing, + RawAndUncalibrated + } } diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 33af2e7945..6a37c72da4 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -252,6 +252,11 @@ public static void Recenter() Valve.VR.OpenVR.System.ResetSeatedZeroPose(); } + public static void SetTrackingSpace(ETrackingUniverseOrigin space) + { + Valve.VR.OpenVR.Compositor.SetTrackingSpace(space); + } + public static DeviceState GetControllerPose(int controllerIndex, out Matrix pose, out Vector3 velocity, out Vector3 angVelocity) { return GetControllerPoseUnsafe(controllerIndex, out pose, out velocity, out angVelocity); diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs index 037ecb7461..f4af4949c6 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrHmd.cs @@ -129,6 +129,11 @@ public override void Recenter() OpenVR.Recenter(); } + public override void SetTrackingSpace(TrackingSpace space) + { + OpenVR.SetTrackingSpace((Valve.VR.ETrackingUniverseOrigin)space); + } + public override DeviceState State => state; public override Vector3 HeadPosition => currentHeadPos; diff --git a/sources/engine/Xenko.VirtualReality/VRDevice.cs b/sources/engine/Xenko.VirtualReality/VRDevice.cs index 0be7afbc1f..28bcae58b2 100644 --- a/sources/engine/Xenko.VirtualReality/VRDevice.cs +++ b/sources/engine/Xenko.VirtualReality/VRDevice.cs @@ -67,6 +67,10 @@ public virtual void Recenter() { } + public virtual void SetTrackingSpace(TrackingSpace space) + { + } + public abstract void ReadEyeParameters(Eyes eye, float near, float far, ref Vector3 cameraPosition, ref Matrix cameraRotation, bool ignoreHeadRotation, bool ignoreHeadPosition, out Matrix view, out Matrix projection); public abstract void Commit(CommandList commandList, Texture renderFrame); From 8cc7fd6fd6e8720351ab04df196efb66d76a6618 Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 11 Oct 2018 00:36:32 +0200 Subject: [PATCH 14/30] texture initialization now throws an exception when retrieving of the shared handle failed. moved summary explanations to remarks in TextureOptions.cs --- .../Direct3D/Texture.Direct3D.cs | 40 ++++++++----------- .../engine/Xenko.Graphics/TextureOptions.cs | 27 ++++++++----- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index 356e3cf468..17255d0a73 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -156,31 +156,23 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) NativeRenderTargetView = GetRenderTargetView(ViewType, ArraySlice, MipLevel); NativeDepthStencilView = GetDepthStencilView(out HasStencil); - try + switch (textureDescription.Options) { - switch (textureDescription.Options) - { - case TextureOptions.None: - SharedHandle = IntPtr.Zero; - break; - case TextureOptions.Shared: - var sharedResource = NativeDeviceChild.QueryInterface(); - SharedHandle = sharedResource.SharedHandle; - break; - case TextureOptions.SharedNthandle: - var sharedResource1 = NativeDeviceChild.QueryInterface(); - var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); - SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); - SharedNtHandleName = uniqueName; - break; - default: - SharedHandle = IntPtr.Zero; - break; - } - } - catch - { - SharedHandle = IntPtr.Zero; + case TextureOptions.None: + SharedHandle = IntPtr.Zero; + break; + case TextureOptions.Shared: + var sharedResource = NativeDeviceChild.QueryInterface(); + SharedHandle = sharedResource.SharedHandle; + break; + case TextureOptions.SharedNthandle: + var sharedResource1 = NativeDeviceChild.QueryInterface(); + var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); + SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); + SharedNtHandleName = uniqueName; + break; + default: + throw new ArgumentOutOfRangeException("textureDescription.Options"); } } diff --git a/sources/engine/Xenko.Graphics/TextureOptions.cs b/sources/engine/Xenko.Graphics/TextureOptions.cs index 649318425c..61346a4b88 100644 --- a/sources/engine/Xenko.Graphics/TextureOptions.cs +++ b/sources/engine/Xenko.Graphics/TextureOptions.cs @@ -20,8 +20,10 @@ public enum TextureOptions None = 0, /// - /// Enables resource data sharing between two or more Direct3D devices. The only - /// resources that can be shared are 2D non-mipmapped textures. SharpDX.Direct3D11.ResourceOptionFlags.Shared + /// Enables resource data sharing between two or more Direct3D devices. + /// + /// + /// The only resources that can be shared are 2D non-mipmapped textures. SharpDX.Direct3D11.ResourceOptionFlags.Shared /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex are mutually exclusive. /// WARP and REF devices do not support shared resources. If you try to create a /// resource with this flag on either a WARP or REF device, the create method will @@ -29,14 +31,16 @@ public enum TextureOptions /// fully support shared resources. ? Note?? Starting with Windows?8, we recommend /// that you enable resource data sharing between two or more Direct3D devices by /// using a combination of the SharpDX.Direct3D11.ResourceOptionFlags.SharedNthandle - /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex flags instead. ? - /// + /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex flags instead. + /// Shared = 2, /// /// Enables the resource to be synchronized by using the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) - /// and SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs. The following Direct3D?11 - /// resource creation APIs, that take SharpDX.Direct3D11.ResourceOptionFlags parameters, + /// and SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs. + /// + /// + /// The following Direct3D 11 resource creation APIs, that take SharpDX.Direct3D11.ResourceOptionFlags parameters, /// have been extended to support the new flag. SharpDX.Direct3D11.Device.CreateTexture1D(SharpDX.Direct3D11.Texture1DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture1D) /// SharpDX.Direct3D11.Device.CreateTexture2D(SharpDX.Direct3D11.Texture2DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture2D) /// SharpDX.Direct3D11.Device.CreateTexture3D(SharpDX.Direct3D11.Texture3DDescription@,SharpDX.DataBox[],SharpDX.Direct3D11.Texture3D) @@ -55,13 +59,16 @@ public enum TextureOptions /// WARP and REF devices do not support shared resources. If you try to create a /// resource with this flag on either a WARP or REF device, the create method will /// return an E_OUTOFMEMORY error code. Note?? Starting with Windows?8, WARP devices - /// fully support shared resources. ? - /// + /// fully support shared resources. + /// SharedKeyedmutex = 256, /// /// Set this flag to enable the use of NT HANDLE values when you create a shared - /// resource. By enabling this flag, you deprecate the use of existing HANDLE values. + /// resource. + /// + /// + /// By enabling this flag, you deprecate the use of existing HANDLE values. /// When you use this flag, you must combine it with the SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex /// flag by using a bitwise OR operation. The resulting value specifies a new shared /// resource type that directs the runtime to use NT HANDLE values for the shared @@ -71,7 +78,7 @@ public enum TextureOptions /// and so on). When the runtime does not validate shared resource parameters, behavior /// of much of the Direct3D API might be undefined and might vary from driver to /// driver. Direct3D 11 and earlier: This value is not supported until Direct3D 11.1. - /// + /// SharedNthandle = 2048, } } From b4b97447583d44caa7fd3466f3abfdeb6eabb9f5 Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 11 Oct 2018 01:17:55 +0200 Subject: [PATCH 15/30] reusing same StringBuilder in ever frame to get the SerialNumber --- sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 6a37c72da4..f8dcaa4e2a 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -3,6 +3,7 @@ #if XENKO_GRAPHICS_API_DIRECT3D11 using System; +using System.Text; using SharpDX.Direct3D11; using Valve.VR; using Xenko.Core; @@ -157,13 +158,15 @@ public TrackedDevice(int trackerIndex) TrackerIndex = trackerIndex; } + const int StringBuilderSize = 64; + StringBuilder serialNumberStringBuilder = new StringBuilder(StringBuilderSize); public void Update() { var error = ETrackedPropertyError.TrackedProp_Success; - var result = new System.Text.StringBuilder((int)64); - Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, result, 64, ref error); + serialNumberStringBuilder.Clear(); + Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); if (error == ETrackedPropertyError.TrackedProp_Success) - SerialNumber = result.ToString(); + SerialNumber = serialNumberStringBuilder.ToString(); BatteryPercentage = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); From 69fefe61275162d5c0ae75c63fdc5e2d77c73489 Mon Sep 17 00:00:00 2001 From: tebjan Date: Sat, 13 Oct 2018 18:35:43 +0200 Subject: [PATCH 16/30] windows/d3d11 specific texture sharing options now in #if regions --- .../engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs | 9 ++++++--- sources/engine/Xenko.Graphics/Texture.cs | 4 +++- sources/engine/Xenko.Graphics/TextureOptions.cs | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs index 17255d0a73..83565b772a 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Texture.Direct3D.cs @@ -165,12 +165,14 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) var sharedResource = NativeDeviceChild.QueryInterface(); SharedHandle = sharedResource.SharedHandle; break; - case TextureOptions.SharedNthandle: +#if XENKO_GRAPHICS_API_DIRECT3D11 + case TextureOptions.SharedNthandle | TextureOptions.SharedKeyedmutex: var sharedResource1 = NativeDeviceChild.QueryInterface(); var uniqueName = "Xenko:" + Guid.NewGuid().ToString(); SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); SharedNtHandleName = uniqueName; - break; + break; +#endif default: throw new ArgumentOutOfRangeException("textureDescription.Options"); } @@ -601,11 +603,12 @@ private static TextureDescription ConvertFromNativeDescription(Texture2DDescript if ((description.OptionFlags & ResourceOptionFlags.Shared) != 0) desc.Options |= TextureOptions.Shared; +#if XENKO_GRAPHICS_API_DIRECT3D11 if ((description.OptionFlags & ResourceOptionFlags.SharedKeyedmutex) != 0) desc.Options |= TextureOptions.SharedKeyedmutex; if ((description.OptionFlags & ResourceOptionFlags.SharedNthandle) != 0) desc.Options |= TextureOptions.SharedNthandle; - +#endif return desc; } diff --git a/sources/engine/Xenko.Graphics/Texture.cs b/sources/engine/Xenko.Graphics/Texture.cs index 5986632d79..49e65a83aa 100644 --- a/sources/engine/Xenko.Graphics/Texture.cs +++ b/sources/engine/Xenko.Graphics/Texture.cs @@ -303,10 +303,12 @@ public TextureOptions Options /// public IntPtr SharedHandle { get; private set; } = IntPtr.Zero; +#if XENKO_GRAPHICS_API_DIRECT3D11 /// /// Gets the name of the shared Nt handle when created with TextureOption.SharedNthandle. /// - public string SharedNtHandleName { get; private set; } = string.Empty; + public string SharedNtHandleName { get; private set; } = string.Empty; +#endif /// /// Gets a value indicating whether this instance is a render target. diff --git a/sources/engine/Xenko.Graphics/TextureOptions.cs b/sources/engine/Xenko.Graphics/TextureOptions.cs index 61346a4b88..f18bcec597 100644 --- a/sources/engine/Xenko.Graphics/TextureOptions.cs +++ b/sources/engine/Xenko.Graphics/TextureOptions.cs @@ -34,7 +34,7 @@ public enum TextureOptions /// and SharpDX.Direct3D11.ResourceOptionFlags.SharedKeyedmutex flags instead. /// Shared = 2, - +#if XENKO_GRAPHICS_API_DIRECT3D11 /// /// Enables the resource to be synchronized by using the SharpDX.DXGI.KeyedMutex.Acquire(System.Int64,System.Int32) /// and SharpDX.DXGI.KeyedMutex.Release(System.Int64) APIs. @@ -80,5 +80,6 @@ public enum TextureOptions /// driver. Direct3D 11 and earlier: This value is not supported until Direct3D 11.1. /// SharedNthandle = 2048, +#endif } } From 1584991d1bcdd53dae20db1e833dac8807190b0a Mon Sep 17 00:00:00 2001 From: tebjan Date: Sat, 13 Oct 2018 21:02:03 +0200 Subject: [PATCH 17/30] exposed MatrixTransform as a property of FastTextRenderer, was hidden in constructor --- sources/engine/Xenko.Graphics/FastTextRenderer.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sources/engine/Xenko.Graphics/FastTextRenderer.cs b/sources/engine/Xenko.Graphics/FastTextRenderer.cs index 45942c33dc..0d8a74fa54 100644 --- a/sources/engine/Xenko.Graphics/FastTextRenderer.cs +++ b/sources/engine/Xenko.Graphics/FastTextRenderer.cs @@ -137,7 +137,6 @@ private unsafe void Initialize(GraphicsContext graphicsContext, int maxCharacter // Create the effect simpleEffect = new EffectInstance(new Effect(graphicsContext.CommandList.GraphicsDevice, SpriteEffect.Bytecode)); - simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, Matrix.Identity); simpleEffect.Parameters.Set(TexturingKeys.Sampler, graphicsContext.CommandList.GraphicsDevice.SamplerStates.LinearClamp); simpleEffect.UpdateEffect(graphicsContext.CommandList.GraphicsDevice); @@ -191,7 +190,8 @@ public void End([NotNull] GraphicsContext graphicsContext) // Set the rendering parameters simpleEffect.Parameters.Set(TexturingKeys.Texture0, DebugSpriteFont); simpleEffect.Parameters.Set(SpriteEffectKeys.Color, TextColor); - + simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, MatrixTransform); + // Swap vertex buffer activeVertexBufferIndex = ++activeVertexBufferIndex >= VertexBufferCount ? 0 : activeVertexBufferIndex; @@ -277,5 +277,10 @@ public void End([NotNull] GraphicsContext graphicsContext) /// Height of font Texture . /// public int DebugSpriteHeight { get; set; } = 64; + + /// + /// A general matrix transformation for the text. Should include view and projection if needed. + /// + public Matrix MatrixTransform { get; set; } = Matrix.Identity; } } From 79cad5e29ba2b5b3718c94046a757697031705db Mon Sep 17 00:00:00 2001 From: Nicolas Musset Date: Wed, 17 Oct 2018 15:32:46 +0200 Subject: [PATCH 18/30] cosmetics, removed trailing spaces --- sources/engine/Xenko.Graphics/FastTextRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/engine/Xenko.Graphics/FastTextRenderer.cs b/sources/engine/Xenko.Graphics/FastTextRenderer.cs index 0d8a74fa54..c9e819a9c6 100644 --- a/sources/engine/Xenko.Graphics/FastTextRenderer.cs +++ b/sources/engine/Xenko.Graphics/FastTextRenderer.cs @@ -190,7 +190,7 @@ public void End([NotNull] GraphicsContext graphicsContext) // Set the rendering parameters simpleEffect.Parameters.Set(TexturingKeys.Texture0, DebugSpriteFont); simpleEffect.Parameters.Set(SpriteEffectKeys.Color, TextColor); - simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, MatrixTransform); + simpleEffect.Parameters.Set(SpriteBaseKeys.MatrixTransform, MatrixTransform); // Swap vertex buffer activeVertexBufferIndex = ++activeVertexBufferIndex >= VertexBufferCount ? 0 : activeVertexBufferIndex; From dfe9c05adcdefc643ade1392738c9cae7f7aaf32 Mon Sep 17 00:00:00 2001 From: joreg Date: Thu, 25 Oct 2018 17:51:26 +0200 Subject: [PATCH 19/30] moved BatteryPercentage, SerialNumber and DeviceClass from update into getters --- .../Xenko.VirtualReality/OpenVR/OpenVR.cs | 42 ++++++++++++------- .../OpenVR/OpenVrTrackedDevice.cs | 2 - 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index f8dcaa4e2a..9e1043b829 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -159,24 +159,36 @@ public TrackedDevice(int trackerIndex) } const int StringBuilderSize = 64; - StringBuilder serialNumberStringBuilder = new StringBuilder(StringBuilderSize); - public void Update() - { - var error = ETrackedPropertyError.TrackedProp_Success; - serialNumberStringBuilder.Clear(); - Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); - if (error == ETrackedPropertyError.TrackedProp_Success) - SerialNumber = serialNumberStringBuilder.ToString(); - - BatteryPercentage = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); - - DeviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); + StringBuilder serialNumberStringBuilder = new StringBuilder(StringBuilderSize); + internal string SerialNumber + { + get + { + var error = ETrackedPropertyError.TrackedProp_Success; + serialNumberStringBuilder.Clear(); + Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); + if (error == ETrackedPropertyError.TrackedProp_Success) + return serialNumberStringBuilder.ToString(); + else + return ""; + } } + internal float BatteryPercentage + { + get + { + var error = ETrackedPropertyError.TrackedProp_Success; + var value = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); + if (error == ETrackedPropertyError.TrackedProp_Success) + return value; + else + return 0; + } + } + internal int TrackerIndex; - internal ETrackedDeviceClass DeviceClass; - internal string SerialNumber; - internal float BatteryPercentage; + internal ETrackedDeviceClass DeviceClass => Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); } private static readonly TrackedDevicePose_t[] DevicePoses = new TrackedDevicePose_t[Valve.VR.OpenVR.k_unMaxTrackedDeviceCount]; diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs index 5011301a71..ca2f6c0002 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs @@ -27,8 +27,6 @@ public override void Update(GameTime gameTime) { if (trackedDevice != null) { - trackedDevice.Update(); - Matrix mat; Vector3 vel, angVel; internalState = OpenVR.GetTrackerPose(trackedDevice.TrackerIndex, out mat, out vel, out angVel); From 5ab34de4e7fcb7091773e6bc9744d4ad29645cf5 Mon Sep 17 00:00:00 2001 From: joreg Date: Fri, 26 Oct 2018 13:30:28 +0200 Subject: [PATCH 20/30] fixed line-endings to LF --- .../Xenko.VirtualReality/OpenVR/OpenVR.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs index 9e1043b829..e94477d656 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVR.cs @@ -159,33 +159,33 @@ public TrackedDevice(int trackerIndex) } const int StringBuilderSize = 64; - StringBuilder serialNumberStringBuilder = new StringBuilder(StringBuilderSize); - internal string SerialNumber - { - get - { + StringBuilder serialNumberStringBuilder = new StringBuilder(StringBuilderSize); + internal string SerialNumber + { + get + { var error = ETrackedPropertyError.TrackedProp_Success; - serialNumberStringBuilder.Clear(); + serialNumberStringBuilder.Clear(); Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_SerialNumber_String, serialNumberStringBuilder, StringBuilderSize, ref error); - if (error == ETrackedPropertyError.TrackedProp_Success) - return serialNumberStringBuilder.ToString(); - else + if (error == ETrackedPropertyError.TrackedProp_Success) + return serialNumberStringBuilder.ToString(); + else return ""; - } + } } - internal float BatteryPercentage - { - get - { - var error = ETrackedPropertyError.TrackedProp_Success; - var value = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); - if (error == ETrackedPropertyError.TrackedProp_Success) - return value; - else - return 0; - } - } + internal float BatteryPercentage + { + get + { + var error = ETrackedPropertyError.TrackedProp_Success; + var value = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty((uint)TrackerIndex, ETrackedDeviceProperty.Prop_DeviceBatteryPercentage_Float, ref error); + if (error == ETrackedPropertyError.TrackedProp_Success) + return value; + else + return 0; + } + } internal int TrackerIndex; internal ETrackedDeviceClass DeviceClass => Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)TrackerIndex); From 6cbc56b34b9530b36d24ec4a4ba82cd19c7c39a1 Mon Sep 17 00:00:00 2001 From: tebjan Date: Sat, 27 Oct 2018 03:58:40 +0200 Subject: [PATCH 21/30] fixed geometry shader with stream out creation and added BufferFlags.StreamOutput --- .../engine/Xenko.Graphics/Buffer.Vertex.cs | 14 ++++++++----- sources/engine/Xenko.Graphics/BufferFlags.cs | 5 +++++ .../Direct3D/Buffer.Direct3D.cs | 3 +++ .../Direct3D/PipelineState.Direct3D.cs | 21 +++++++++++-------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Buffer.Vertex.cs b/sources/engine/Xenko.Graphics/Buffer.Vertex.cs index 64edcdbcda..43d7600485 100644 --- a/sources/engine/Xenko.Graphics/Buffer.Vertex.cs +++ b/sources/engine/Xenko.Graphics/Buffer.Vertex.cs @@ -33,15 +33,19 @@ public partial class Buffer public static class Vertex { /// - /// Creates a new Vertex buffer with uasge by default. + /// Creates a new Vertex buffer with uasge by default. /// - /// The . + /// The . /// The size in bytes. /// The usage. - /// A Vertex buffer - public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) + /// if set to true the buffer can be bound to the geometry shader stream output stage. + /// + /// A Vertex buffer + /// + public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, bool isStreamOutput = false) { - return Buffer.New(device, size, BufferFlags.VertexBuffer, usage); + var flags = isStreamOutput ? BufferFlags.VertexBuffer | BufferFlags.StreamOutput : BufferFlags.VertexBuffer; + return Buffer.New(device, size, flags, usage); } /// diff --git a/sources/engine/Xenko.Graphics/BufferFlags.cs b/sources/engine/Xenko.Graphics/BufferFlags.cs index e1c9c34852..6a89d202be 100644 --- a/sources/engine/Xenko.Graphics/BufferFlags.cs +++ b/sources/engine/Xenko.Graphics/BufferFlags.cs @@ -71,5 +71,10 @@ public enum BufferFlags /// Creates an indirect arguments buffer. /// ArgumentBuffer = 1024, + + /// + /// Creates a buffer for the geometry shader stream-output stage. + /// + StreamOutput = 2048, } } diff --git a/sources/engine/Xenko.Graphics/Direct3D/Buffer.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/Buffer.Direct3D.cs index 29f291d97e..e91782fe42 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/Buffer.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/Buffer.Direct3D.cs @@ -240,6 +240,9 @@ private static SharpDX.Direct3D11.BufferDescription ConvertToNativeDescription(B if ((bufferFlags & BufferFlags.ArgumentBuffer) == BufferFlags.ArgumentBuffer) desc.OptionFlags |= ResourceOptionFlags.DrawIndirectArguments; + if ((bufferFlags & BufferFlags.StreamOutput) != 0) + desc.BindFlags |= BindFlags.StreamOutput; + return desc; } diff --git a/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs index 175b3858cf..fd3a30fa52 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs @@ -196,20 +196,23 @@ private void CreateShaders(DevicePipelineStateCache pipelineStateCache) case ShaderStage.Geometry: if (reflection.ShaderStreamOutputDeclarations != null && reflection.ShaderStreamOutputDeclarations.Count > 0) { - // Calculate the strides - var soStrides = new List(); + // stream out elements + var soElements = new List(); foreach (var streamOutputElement in reflection.ShaderStreamOutputDeclarations) { - for (int i = soStrides.Count; i < (streamOutputElement.Stream + 1); i++) + var soElem = new SharpDX.Direct3D11.StreamOutputElement() { - soStrides.Add(0); - } - - soStrides[streamOutputElement.Stream] += streamOutputElement.ComponentCount * sizeof(float); + Stream = streamOutputElement.Stream, + SemanticIndex = streamOutputElement.SemanticIndex, + SemanticName = streamOutputElement.SemanticName, + StartComponent = streamOutputElement.StartComponent, + ComponentCount = streamOutputElement.ComponentCount, + OutputSlot = streamOutputElement.OutputSlot + }; + soElements.Add(soElem); } - var soElements = new SharpDX.Direct3D11.StreamOutputElement[0]; // TODO CREATE StreamOutputElement from bytecode.Reflection.ShaderStreamOutputDeclarations // TODO GRAPHICS REFACTOR better cache - geometryShader = new SharpDX.Direct3D11.GeometryShader(GraphicsDevice.NativeDevice, shaderBytecode, soElements, soStrides.ToArray(), reflection.StreamOutputRasterizedStream); + geometryShader = new SharpDX.Direct3D11.GeometryShader(GraphicsDevice.NativeDevice, shaderBytecode, soElements.ToArray(), reflection.StreamOutputStrides, reflection.StreamOutputRasterizedStream); } else { From 40db5ce885dd543f3dd02ebfdf377e5a12c3ae9b Mon Sep 17 00:00:00 2001 From: tebjan Date: Mon, 29 Oct 2018 14:43:10 +0100 Subject: [PATCH 22/30] version bump to 3.0.0.7 --- Xenko.xkpkg | 2 +- sources/shared/SharedAssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Xenko.xkpkg b/Xenko.xkpkg index dffb639a2e..0244127a49 100644 --- a/Xenko.xkpkg +++ b/Xenko.xkpkg @@ -3,7 +3,7 @@ Id: cc1bcc78-50b2-4da6-8902-f7a3ae42898b SerializedVersion: {Assets: 0.0.4} Meta: Name: Xenko - Version: 3.0.0.6-dev + Version: 3.0.0.7-dev Owners: - Xenko Authors: diff --git a/sources/shared/SharedAssemblyInfo.cs b/sources/shared/SharedAssemblyInfo.cs index 1c21548ab3..ac0a0e7b1a 100644 --- a/sources/shared/SharedAssemblyInfo.cs +++ b/sources/shared/SharedAssemblyInfo.cs @@ -26,7 +26,7 @@ internal class XenkoVersion /// /// The version used by editor for display purpose. 4th digit needs to be at least 1 if used (due to NuGet special cases). /// - public const string PublicVersion = "3.0.0.6"; + public const string PublicVersion = "3.0.0.7"; /// /// The current assembly version as text, currently same as . From ad27deb25a3f24ea6a486a8e5bd876bbbf11232d Mon Sep 17 00:00:00 2001 From: azeno Date: Tue, 30 Oct 2018 00:09:59 +0100 Subject: [PATCH 23/30] [Graphics] When mixing Dispatch and Draw calls in Direct3D11 the set shaders on the native device context got mixed up. For example effect A sets a hull shader, effect B a compute shader and effect C only vertex and pixel shaders - the hull shader from effect A was now still set on the native device context leading to a broken draw call because when applying effect B the draw shaders were not cleared and follow up comparison when applying C failed. --- .../Direct3D/PipelineState.Direct3D.cs | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs b/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs index 175b3858cf..3dce2f9529 100644 --- a/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs +++ b/sources/engine/Xenko.Graphics/Direct3D/PipelineState.Direct3D.cs @@ -71,25 +71,19 @@ internal void Apply(CommandList commandList, PipelineState previousPipeline) } if (effectBytecode != previousPipeline.effectBytecode) - { - if (computeShader != null) - { - if (computeShader != previousPipeline.computeShader) - nativeDeviceContext.ComputeShader.Set(computeShader); - } - else - { - if (vertexShader != previousPipeline.vertexShader) - nativeDeviceContext.VertexShader.Set(vertexShader); - if (pixelShader != previousPipeline.pixelShader) - nativeDeviceContext.PixelShader.Set(pixelShader); - if (hullShader != previousPipeline.hullShader) - nativeDeviceContext.HullShader.Set(hullShader); - if (domainShader != previousPipeline.domainShader) - nativeDeviceContext.DomainShader.Set(domainShader); - if (geometryShader != previousPipeline.geometryShader) - nativeDeviceContext.GeometryShader.Set(geometryShader); - } + { + if (computeShader != previousPipeline.computeShader) + nativeDeviceContext.ComputeShader.Set(computeShader); + if (vertexShader != previousPipeline.vertexShader) + nativeDeviceContext.VertexShader.Set(vertexShader); + if (pixelShader != previousPipeline.pixelShader) + nativeDeviceContext.PixelShader.Set(pixelShader); + if (hullShader != previousPipeline.hullShader) + nativeDeviceContext.HullShader.Set(hullShader); + if (domainShader != previousPipeline.domainShader) + nativeDeviceContext.DomainShader.Set(domainShader); + if (geometryShader != previousPipeline.geometryShader) + nativeDeviceContext.GeometryShader.Set(geometryShader); } if (blendState != previousPipeline.blendState || sampleMask != previousPipeline.sampleMask) From d4ff27c161ea728c97edeca59b1d04823998945b Mon Sep 17 00:00:00 2001 From: tebjan Date: Tue, 30 Oct 2018 02:48:29 +0100 Subject: [PATCH 24/30] replaced isStreamOutput with bindFlags --- sources/engine/Xenko.Graphics/Buffer.Vertex.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Buffer.Vertex.cs b/sources/engine/Xenko.Graphics/Buffer.Vertex.cs index 43d7600485..733457b08c 100644 --- a/sources/engine/Xenko.Graphics/Buffer.Vertex.cs +++ b/sources/engine/Xenko.Graphics/Buffer.Vertex.cs @@ -33,19 +33,18 @@ public partial class Buffer public static class Vertex { /// - /// Creates a new Vertex buffer with uasge by default. + /// Creates a new Vertex buffer with uasge by default. /// - /// The . + /// The . /// The size in bytes. /// The usage. - /// if set to true the buffer can be bound to the geometry shader stream output stage. + /// The bind flags, can be combined with to use the buffer as a stream output target. /// /// A Vertex buffer /// - public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, bool isStreamOutput = false) + public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, BufferFlags bindFlags = BufferFlags.VertexBuffer) { - var flags = isStreamOutput ? BufferFlags.VertexBuffer | BufferFlags.StreamOutput : BufferFlags.VertexBuffer; - return Buffer.New(device, size, flags, usage); + return Buffer.New(device, size, bindFlags, usage); } /// From 2f9bdca708700fbab974efce31652cdccca64f89 Mon Sep 17 00:00:00 2001 From: Elias Holzer Date: Thu, 15 Nov 2018 13:57:03 +0100 Subject: [PATCH 25/30] Quick fix as suggested by @xen2 in chat to avoid crash in shader compiler --- sources/shaders/Xenko.Core.Shaders/Ast/TypeBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/shaders/Xenko.Core.Shaders/Ast/TypeBase.cs b/sources/shaders/Xenko.Core.Shaders/Ast/TypeBase.cs index 2c87308d5d..4ae2f9e3f7 100644 --- a/sources/shaders/Xenko.Core.Shaders/Ast/TypeBase.cs +++ b/sources/shaders/Xenko.Core.Shaders/Ast/TypeBase.cs @@ -215,7 +215,7 @@ public override bool Equals(object obj) /// public override int GetHashCode() { - return Name.GetHashCode(); + return Name?.GetHashCode() ?? 0; } /// @@ -226,7 +226,7 @@ public override int GetHashCode() /// public override string ToString() { - return Name.ToString(); + return Name?.ToString(); } #endregion From 77bd139878b8b47f9aba1f6d3b482f74ec0b6a8a Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 15 Nov 2018 16:38:59 +0100 Subject: [PATCH 26/30] Revert "Update to C# 7.2 (#264)" This reverts commit 2eb9a6f0b34b182026e7eda7255e86521419dba8. --- build/Xenko.Core.GlobalSettings.Local.targets | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/Xenko.Core.GlobalSettings.Local.targets b/build/Xenko.Core.GlobalSettings.Local.targets index e6ddf0c0c0..01e13a75cd 100644 --- a/build/Xenko.Core.GlobalSettings.Local.targets +++ b/build/Xenko.Core.GlobalSettings.Local.targets @@ -9,8 +9,4 @@ $(MSBuildThisFileDirectory)..\Bin\$(XenkoBuildDirectory)\ $([System.IO.Path]::GetFullPath('$(XenkoOutputCommonDir)')) - - - 7.2 - \ No newline at end of file From 011114ef6ad4672a2fdf2e50ff54829b970602f3 Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 15 Nov 2018 16:38:59 +0100 Subject: [PATCH 27/30] Revert "Update to C# 7.2 (#264)" This reverts commit 2eb9a6f0b34b182026e7eda7255e86521419dba8. --- build/Xenko.Core.GlobalSettings.Local.targets | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/Xenko.Core.GlobalSettings.Local.targets b/build/Xenko.Core.GlobalSettings.Local.targets index e6ddf0c0c0..01e13a75cd 100644 --- a/build/Xenko.Core.GlobalSettings.Local.targets +++ b/build/Xenko.Core.GlobalSettings.Local.targets @@ -9,8 +9,4 @@ $(MSBuildThisFileDirectory)..\Bin\$(XenkoBuildDirectory)\ $([System.IO.Path]::GetFullPath('$(XenkoOutputCommonDir)')) - - - 7.2 - \ No newline at end of file From 48da56c4370c3b8309aca8d83963f23c33537537 Mon Sep 17 00:00:00 2001 From: Virgile Bello Date: Thu, 22 Nov 2018 13:32:25 +0900 Subject: [PATCH 28/30] [Audio] Various fixes so that SoundInstance.SetRange() works better --- .../Xenko.Audio/CompressedSoundSource.cs | 51 ++++++++++++------- .../engine/Xenko.Audio/DynamicSoundSource.cs | 7 +-- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/sources/engine/Xenko.Audio/CompressedSoundSource.cs b/sources/engine/Xenko.Audio/CompressedSoundSource.cs index c57f58f182..8b68d37046 100644 --- a/sources/engine/Xenko.Audio/CompressedSoundSource.cs +++ b/sources/engine/Xenko.Audio/CompressedSoundSource.cs @@ -162,24 +162,36 @@ protected override void PrepareInternal() // Ignore invalid data at beginning (due to encoder delay) & end of stream (due to packet size) var samplesToSkip = decoder.GetDecoderSampleDelay(); + // Compute boundaries + var sampleBegin = (channels * samplesToSkip); + var sampleEnd = sampleBegin + (channels * samples); + var frameSize = SamplesPerFrame * channels; //ok we need to handle this case properly, this means that the user wants to use a different then full audio stream range... - var sampleStart = (channels * samplesToSkip) + (int)Math.Floor(sampleRate * (double)channels * range.Start.TotalSeconds); - startPktSampleIndex = sampleStart % (frameSize); + var sampleStart = sampleBegin + (int)Math.Floor(sampleRate * (double)channels * range.Start.TotalSeconds); + // Make sure start is at least one sample before the end to avoid edge cases where startingPacketIndex == numberOfPackets + sampleStart = Math.Min(Math.Max(sampleStart, sampleBegin), sampleEnd - 1 * channels); - var sampleStop = (channels * samplesToSkip) + var sampleStop = sampleBegin + (range.Length != TimeSpan.Zero ? (int)Math.Floor(sampleRate * (double)channels * range.End.TotalSeconds) : (channels * samples)); - endPktSampleIndex = frameSize - sampleStop % frameSize; + // Make sure stop is at least one sample after start + sampleStop = Math.Min(Math.Max(sampleStop, sampleStart + 1 * channels), sampleEnd); + + // Compute start/end packet + startingPacketIndex = sampleStart / frameSize; + endPacketIndex = (sampleStop - 1) / frameSize; // -1 to make sure we stay in last packet if using all of it - var skipCounter = startingPacketIndex = sampleStart / frameSize; - endPacketIndex = sampleStop / frameSize; + // How much data to use in start/end packet + startPktSampleIndex = sampleStart % (frameSize); + endPktSampleIndex = frameSize - sampleStop % frameSize; // skip to the starting packet - if (startingPacketIndex < numberOfPackets && endPacketIndex < numberOfPackets && startingPacketIndex < endPacketIndex) + if (startingPacketIndex < numberOfPackets && endPacketIndex < numberOfPackets && startingPacketIndex <= endPacketIndex) // this shouldn't happen anymore with the min/max clamps { //valid offsets.. process it + var skipCounter = startingPacketIndex; while (skipCounter-- > 0) { //skip data to reach starting packet @@ -238,7 +250,7 @@ protected override unsafe void ExtractAndFillData() for (var i = 0; i < passes; i++) { endingPacket = endPacketIndex == currentPacketIndex; - + //read one packet, size first, then data var len = reader.ReadInt16(); compressedSoundStream.Read(compressedBuffer, 0, len); @@ -254,19 +266,11 @@ protected override unsafe void ExtractAndFillData() if (endingPacket || compressedSoundStream.Position == compressedSoundStream.Length) { - if (looped) //prepare again to play from begin - { - PrepareInternal(); - } - else // stops the sound - { - StopInternal(); - } - break; } } + // Send buffer to hardware var finalPtr = new IntPtr(bufferPtr + (startingPacket ? startPktSampleIndex : 0)); var finalSize = (offset - (startingPacket ? startPktSampleIndex : 0) - (endingPacket ? endPktSampleIndex : 0)) * sizeof(short); @@ -281,6 +285,19 @@ protected override unsafe void ExtractAndFillData() begin = false; } FillBuffer(finalPtr, finalSize, bufferType); + + // Go back to beginning if necessary + if (endingPacket || compressedSoundStream.Position == compressedSoundStream.Length) + { + if (looped) //prepare again to play from begin + { + PrepareInternal(); + } + else // stops the sound + { + StopInternal(false); + } + } } } } diff --git a/sources/engine/Xenko.Audio/DynamicSoundSource.cs b/sources/engine/Xenko.Audio/DynamicSoundSource.cs index 4ef462d991..e2964935c9 100644 --- a/sources/engine/Xenko.Audio/DynamicSoundSource.cs +++ b/sources/engine/Xenko.Audio/DynamicSoundSource.cs @@ -245,11 +245,12 @@ protected virtual void PauseInternal() AudioLayer.SourcePause(soundInstance.Source); } - protected virtual void StopInternal() + protected virtual void StopInternal(bool ignoreQueuedBuffer = true) { Ended.TrySetResult(true); state = PlayState.Stopped; - AudioLayer.SourceStop(soundInstance.Source); + if (ignoreQueuedBuffer) + AudioLayer.SourceStop(soundInstance.Source); RestartInternal(); } @@ -397,7 +398,7 @@ private static unsafe void Worker() continue; } - if (source.CanFill) + if (source.CanFill && source.isSourcePausedOrPlaying) source.ExtractAndFillData(); } From b9b6a08a36018e89afaca57ca9f4f651a4034418 Mon Sep 17 00:00:00 2001 From: tebjan Date: Thu, 22 Nov 2018 18:46:21 +0100 Subject: [PATCH 29/30] added TextureOptions to Texture.Extensions2D --- .../Xenko.Graphics/Texture.Extensions2D.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sources/engine/Xenko.Graphics/Texture.Extensions2D.cs b/sources/engine/Xenko.Graphics/Texture.Extensions2D.cs index 2a57e2929d..58b0c40c51 100644 --- a/sources/engine/Xenko.Graphics/Texture.Extensions2D.cs +++ b/sources/engine/Xenko.Graphics/Texture.Extensions2D.cs @@ -40,9 +40,9 @@ public partial class Texture /// Size of the texture 2D array, default to 1. /// The usage. /// A new instance of 2D class. - public static Texture New2D(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) + public static Texture New2D(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions options = TextureOptions.None) { - return New2D(device, width, height, false, format, textureFlags, arraySize, usage); + return New2D(device, width, height, false, format, textureFlags, arraySize, usage, options); } /// @@ -57,9 +57,9 @@ public static Texture New2D(GraphicsDevice device, int width, int height, PixelF /// Size of the texture 2D array, default to 1. /// The usage. /// A new instance of 2D class. - public static Texture New2D(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) + public static Texture New2D(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, TextureOptions options = TextureOptions.None) { - return new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage)); + return new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage, MultisampleCount.None, options)); } /// @@ -77,25 +77,28 @@ public static Texture New2D(GraphicsDevice device, int width, int height, MipMap /// /// Each value in textureData is a pixel in the destination texture. /// - public static unsafe Texture New2D(GraphicsDevice device, int width, int height, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : struct + public static unsafe Texture New2D(GraphicsDevice device, int width, int height, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable, TextureOptions options = TextureOptions.None) where T : struct { - return New2D(device, width, height, 1, format, new[] { GetDataBox(format, width, height, 1, textureData, (IntPtr)Interop.Fixed(textureData)) }, textureFlags, 1, usage); + return New2D(device, width, height, 1, format, new[] { GetDataBox(format, width, height, 1, textureData, (IntPtr)Interop.Fixed(textureData)) }, textureFlags, 1, usage, MultisampleCount.None, options); } /// /// Creates a new 2D . /// - /// The . + /// The . /// The width. /// The height. + /// Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. /// Describes the format to use. - /// Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count. - /// Texture datas through an array of + /// Texture datas through an array of /// true if the texture needs to support unordered read write. /// Size of the texture 2D array, default to 1. /// The usage. /// The multisample count. - /// A new instance of 2D class. + /// The options, e.g. sharing + /// + /// A new instance of 2D class. + /// public static Texture New2D( GraphicsDevice device, int width, @@ -106,9 +109,10 @@ public static Texture New2D( TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, - MultisampleCount multisampleCount = MultisampleCount.None) + MultisampleCount multisampleCount = MultisampleCount.None, + TextureOptions options = TextureOptions.None) { - return new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage, multisampleCount), textureData); + return new Texture(device).InitializeFrom(TextureDescription.New2D(width, height, mipCount, format, textureFlags, arraySize, usage, multisampleCount, options), textureData); } } } From 6a207c8e749e4bddf73ec5efb7ff145eb5e6dad2 Mon Sep 17 00:00:00 2001 From: joreg Date: Fri, 25 Jan 2019 03:18:09 +0100 Subject: [PATCH 30/30] VR tracker support (#213) # Conflicts: # sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs # sources/engine/Xenko.VirtualReality/TrackedItem.cs --- .../Xenko.VirtualReality/DeviceClass.cs | 35 +++++++++++++++++++ .../OpenVR/OpenVrTrackedDevice.cs | 2 +- .../Xenko.VirtualReality/TrackedItem.cs | 2 +- .../Xenko.VirtualReality/TrackingSpace.cs | 23 ++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 sources/engine/Xenko.VirtualReality/DeviceClass.cs create mode 100644 sources/engine/Xenko.VirtualReality/TrackingSpace.cs diff --git a/sources/engine/Xenko.VirtualReality/DeviceClass.cs b/sources/engine/Xenko.VirtualReality/DeviceClass.cs new file mode 100644 index 0000000000..6b83f12d1d --- /dev/null +++ b/sources/engine/Xenko.VirtualReality/DeviceClass.cs @@ -0,0 +1,35 @@ +// Copyright (c) Xenko contributors (https://xenko.com) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +namespace Xenko.VirtualReality +{ + /// + /// Describes what kind of object is being tracked at a given ID + /// + public enum DeviceClass + { + /// + /// There is no device at this index + /// + Invalid, + /// + /// The device at this index is an HMD + /// + HMD, + /// + /// The device is a controller + /// + Controller, + /// + /// The device is a tracker + /// + GenericTracker, + /// + /// The device is a camera, Lighthouse base station, or other device that supplies tracking ground truth. + /// + TrackingReference, + /// + /// Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices + /// + DisplayRedirect + } +} diff --git a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs index ca2f6c0002..972c4ef18f 100644 --- a/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs +++ b/sources/engine/Xenko.VirtualReality/OpenVR/OpenVrTrackedDevice.cs @@ -1,4 +1,4 @@ -// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Copyright (c) Xenko contributors (https://xenko.com) // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. #if XENKO_GRAPHICS_API_DIRECT3D11 diff --git a/sources/engine/Xenko.VirtualReality/TrackedItem.cs b/sources/engine/Xenko.VirtualReality/TrackedItem.cs index b5cb7271f9..ffa32f266c 100644 --- a/sources/engine/Xenko.VirtualReality/TrackedItem.cs +++ b/sources/engine/Xenko.VirtualReality/TrackedItem.cs @@ -1,4 +1,4 @@ -// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) +// Copyright (c) Xenko contributors (https://xenko.com) // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using Xenko.Core.Mathematics; diff --git a/sources/engine/Xenko.VirtualReality/TrackingSpace.cs b/sources/engine/Xenko.VirtualReality/TrackingSpace.cs new file mode 100644 index 0000000000..30942b7981 --- /dev/null +++ b/sources/engine/Xenko.VirtualReality/TrackingSpace.cs @@ -0,0 +1,23 @@ +// Copyright (c) Xenko contributors (https://xenko.com) +// Distributed under the MIT license. See the LICENSE.md file in the project root for more information. +namespace Xenko.VirtualReality +{ + /// + /// Identifies which style of tracking origin the application wants to use for the poses it is requesting + /// + public enum TrackingSpace + { + /// + /// Poses are provided relative to the seated zero pose + /// + Seated, + /// + /// Poses are provided relative to the safe bounds configured by the user + /// + Standing, + /// + /// Poses are provided in the coordinate system defined by the driver. It has Y up and is unified for devices of the same driver. You usually don't want this one. + /// + RawAndUncalibrated + } +}