上传YomovSDK

This commit is contained in:
Sora丶kong
2026-03-03 03:15:46 +08:00
parent 9096da7e6c
commit eb97f31065
6477 changed files with 1932208 additions and 3 deletions

View File

@@ -0,0 +1,134 @@
using System.Runtime.InteropServices;
#if UNITY_EDITOR
using UnityEditor.XR.OpenXR.Features;
#endif
using UnityEngine.Events;
using UnityEngine.XR.OpenXR.NativeTypes;
namespace UnityEngine.XR.OpenXR.Features.Extensions.PerformanceSettings
{
/// <summary>
/// Allows interaction with the Performance settings API,
/// which allows the application to provide hints to the runtime about the performance characteristics of the application,
/// and to receive notifications from the runtime about changes in performance state.
/// </summary>
/// <remarks>
/// Refer to [XR performance settings](xref:openxr-performance-settings) for additional information.
/// </remarks>
#if UNITY_EDITOR
[OpenXRFeature(
UiName = "XR Performance Settings",
Desc = "Optional extension for providing performance hints to runtime and receive notifications aobut device performance changes.",
Company = "Unity",
DocumentationLink = Constants.k_DocumentationManualURL + "features/performance-settings.html",
OpenxrExtensionStrings = extensionString,
Version = "1.0.0",
FeatureId = featureId
)]
#endif
public class XrPerformanceSettingsFeature : OpenXRFeature
{
/// <summary>
/// The feature id string.
/// </summary>
public const string featureId = "com.unity.openxr.feature.extension.performance_settings";
/// <summary>
/// Name of the OpenXR extension for performance settings.
/// </summary>
public const string extensionString = "XR_EXT_performance_settings";
/// <summary>
/// Subscribe to this event to receive performance change notifications from the OpenXR runtime.
/// </summary>
/// <remarks>
/// Refer to [Performance notifications](xref:openxr-performance-settings#performance-settings-notifications) for additional information.
/// </remarks>
/// <example>
/// <para>
/// Example of subscribing to the event and handling the performance change notification:
/// </para>
/// <code lang="cs">
/// <![CDATA[
/// XrPerformanceSettingsFeature.OnXrPerformanceChangeNotification += OnGPUPerformanceChange;
/// ]]>
/// </code>
/// <para>
/// Example of handling the performance change notification:
/// </para>
/// <code lang="cs">
/// <![CDATA[
/// void OnGPUPerformanceChange(PerformanceChangeNotification notification)
/// {
/// if (notification.domain != Domain.GPU)
/// {
/// return;
/// }
///
/// if (notification.toLevel == PerformanceNotificationLevel.Normal)
/// {
/// // Performance has improved
/// UseDefaultQuality();
/// }
/// else
/// {
/// // Performance has degraded
/// UseReducedQuality();
/// }
/// }
/// ]]>
/// </code>
/// </example>
public static event UnityAction<PerformanceChangeNotification> OnXrPerformanceChangeNotification;
/// <summary>
/// Provides the OpenXR runtime with the desired performance level to be used for the specified domain.
/// </summary>
/// <param name="domain">Domain for which the performance hit will be sent.</param>
/// <param name="level">Desired performance asked by the application.</param>
/// <returns>True if the performance level hint was successfully set, false otherwise.</returns>
/// <remarks>
/// Refer to [Performance level hints](xref: openxr-performance-settings#performance-settings-level-hints) for additional information.
/// </remarks>
public static bool SetPerformanceLevelHint(PerformanceDomain domain, PerformanceLevelHint level)
{
if (OpenXRRuntime.IsExtensionEnabled(extensionString))
{
return NativeApi.xr_performance_settings_setPerformanceLevel(domain, level);
}
return false;
}
/// <summary>
/// When an instance of the Performance setting feature is created, it allows us to confirm that the instance has been created, that the extension is enabled
/// and we have successfully registed the performance notification callback
/// </summary>
/// <param name="xrInstance">XR Session Instance</param>
/// <returns>True if the instance has successfully been created. Otherwise it returns false.</returns>
protected internal override bool OnInstanceCreate(ulong xrInstance)
{
return base.OnInstanceCreate(xrInstance) &&
OpenXRRuntime.IsExtensionEnabled(extensionString) &&
NativeApi.xr_performance_settings_setEventCallback(OnXrPerformanceNotificationCallback);
}
[AOT.MonoPInvokeCallback(typeof(NativeApi.XrPerformanceNotificationDelegate))]
private static void OnXrPerformanceNotificationCallback(PerformanceChangeNotification notification)
{
OnXrPerformanceChangeNotification?.Invoke(notification);
}
internal static class NativeApi
{
internal delegate void XrPerformanceNotificationDelegate(PerformanceChangeNotification notification);
[DllImport("UnityOpenXR")]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool xr_performance_settings_setEventCallback(XrPerformanceNotificationDelegate callback);
[DllImport("UnityOpenXR")]
[return: MarshalAs(UnmanagedType.U1)]
internal static extern bool xr_performance_settings_setPerformanceLevel(PerformanceDomain domain, PerformanceLevelHint level);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b213d3e3c7f3109449eb46a4c8ee42f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,133 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
namespace UnityEngine.XR.OpenXR.Features.Extensions.PerformanceSettings
{
/// <summary>
/// Hardware system.
/// </summary>
/// <remarks>
/// Use the members of this enumeration when setting a performance hint with <see cref="XRPerformanceSettingsFeature.SetPerformanceLevelHint(PerformanceDomain, PerformanceLevelHint)"/>.
///
/// Members of this enumeration are reported in the events dispatched by <see cref="XRPerformanceSettingsFeature.UnityAction{PerformanceChangeNotification} OnXrPerformanceChangeNotification"/>.
/// </remarks>
public enum PerformanceDomain
{
/// <summary>
/// CPU hardware domain.
/// </summary>
Cpu = 1,
/// <summary>
/// Graphics hardware domain.
/// </summary>
Gpu = 2
}
/// <summary>
/// Specific context of the hardware domain.
/// </summary>
/// <remarks>
/// Members of this enumeration are reported in the events dispatched by
/// <see cref="XRPerformanceSettingsFeature.UnityAction{PerformanceChangeNotification} OnXrPerformanceChangeNotification"/>.
/// </remarks>
public enum PerformanceSubDomain
{
/// <summary>
/// Composition of submitted layers.
/// </summary>
Compositing = 1,
/// <summary>
/// Graphics rendering and frame submission.
/// </summary>
Rendering = 2,
/// <summary>
/// Physical device temperature.
/// </summary>
Thermal = 3
}
/// <summary>
/// Performance level of the platform.
/// </summary>
/// <remarks>
/// Use the members of this enumeration when setting a performance hint with
/// <see cref="XRPerformanceSettingsFeature.SetPerformanceLevelHint(PerformanceDomain, PerformanceLevelHint)"/>.
/// </remarks>
public enum PerformanceLevelHint
{
/// <summary>
/// The application will enter a non-XR section,
/// so power savings will be prioritized over all.
/// </summary>
PowerSavings = 0,
/// <summary>
/// The application will enter a low and stable complexity section,
/// so power usage will be prioritized over late frame rendering.
/// </summary>
SustainedLow = 25,
/// <summary>
/// The application will enter a high or dynamic complexity section,
/// so the application performance will be prioritized within sustainable thermal ranges.
/// </summary>
SustainedHigh = 50,
/// <summary>
/// The application will enter a very high complexity section,
/// so performance will be boosted over sustainable thermal ranges.
/// Note that usage of this level hint is recommended for short durations (less than 30 seconds).
/// </summary>
Boost = 75
}
/// <summary>
/// Notification level about the performance state of the platform.
/// </summary>
/// <remarks>
/// Members of this enumeration are reported in the events dispatched by
/// <see cref="XRPerformanceSettingsFeature.UnityAction{PerformanceChangeNotification} OnXrPerformanceChangeNotification"/>.
/// </remarks>
public enum PerformanceNotificationLevel
{
/// <summary>
/// Performance is in nominal status.
/// </summary>
Normal = 0,
/// <summary>
/// Early warning for potential performance degradation.
/// </summary>
Warning = 25,
/// <summary>
/// Performance is degraded.
/// </summary>
Impaired = 75
}
/// <summary>
/// Notification about the performance state of the platform.
/// </summary>
/// <remarks>
/// This struct is part of the events dispatched by
/// <see cref="XRPerformanceSettingsFeature.UnityAction{PerformanceChangeNotification} OnXrPerformanceChangeNotification"/>.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public struct PerformanceChangeNotification
{
/// <summary>
/// Platform domain that the notification is about.
/// </summary>
public PerformanceDomain domain;
/// <summary>
/// Platform subdomain that the notification is about.
/// </summary>
public PerformanceSubDomain subDomain;
/// <summary>
/// Previous performance level.
/// </summary>
public PerformanceNotificationLevel fromLevel;
/// <summary>
/// Upcoming performance level.
/// </summary>
public PerformanceNotificationLevel toLevel;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 48fee7f780ee00c44bc696d37673aec9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: