Started project

This commit is contained in:
Caleb Sandford deQuincey
2025-11-14 17:30:41 +00:00
parent 00b55a5b1e
commit 334021d04e
36526 changed files with 4940113 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
#if UNITY_EDITOR
namespace UnityEngine.Rendering
{
/// <summary>
/// Interface to define an stripper for a <see cref="IRenderPipelineGraphicsSettings"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IRenderPipelineGraphicsSettingsStripper<in T> : IStripper
where T : IRenderPipelineGraphicsSettings
{
/// <summary>
/// Specifies if a <see cref="IRenderPipelineGraphicsSettings"/> can be stripped from the build
/// </summary>
/// <param name="settings">The settings that will be stripped</param>
/// <returns>true if the setting is not used and can be stripped</returns>
public bool CanRemoveSettings(T settings);
}
}
#endif

View File

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

View File

@@ -0,0 +1,12 @@
#if UNITY_EDITOR
namespace UnityEngine.Rendering
{
public interface IStripper
{
/// <summary>
/// Returns if the stripper is active
/// </summary>
bool active { get; }
}
}
#endif

View File

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

View File

@@ -0,0 +1,89 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace UnityEngine.Rendering
{
internal static partial class RenderPipelineGraphicsSettingsStripper
{
private static bool CanRemoveSettings(this List<IStripper> strippers, [DisallowNull] Type settingsType, [DisallowNull] IRenderPipelineGraphicsSettings settings)
{
if (strippers == null)
return false;
const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var canRemoveSettings = true;
object[] methodArgs = { Convert.ChangeType(settings, settingsType) };
foreach (var stripperInstance in strippers)
{
var methodInfo = stripperInstance?.GetType().GetMethod($"{nameof(IRenderPipelineGraphicsSettingsStripper<IRenderPipelineGraphicsSettings>.CanRemoveSettings)}", flags);
if (methodInfo != null)
canRemoveSettings &= (bool)methodInfo.Invoke(stripperInstance, methodArgs);
}
return canRemoveSettings;
}
private static bool CanTransferSettingsToPlayer(
[DisallowNull] Dictionary<Type, List<IStripper>> strippersMap,
[DisallowNull] IRenderPipelineGraphicsSettings settings,
out bool isAvailableOnPlayerBuild,
out bool strippersDefined)
{
isAvailableOnPlayerBuild = false;
strippersDefined = false;
var settingsType = settings.GetType();
if (strippersMap.TryGetValue(settingsType, out var strippers) && strippers != null)
{
if (!strippers.CanRemoveSettings(settingsType, settings))
isAvailableOnPlayerBuild = true;
strippersDefined = true;
}
else
{
if (settings.isAvailableInPlayerBuild)
isAvailableOnPlayerBuild = true;
}
return isAvailableOnPlayerBuild;
}
public static void PerformStripping(
List<IRenderPipelineGraphicsSettings> settingsList,
List<IRenderPipelineGraphicsSettings> runtimeSettingsList)
{
if (settingsList == null)
throw new ArgumentNullException(nameof(settingsList));
if (runtimeSettingsList == null)
throw new ArgumentNullException(nameof(runtimeSettingsList));
using (var report = new Report())
{
runtimeSettingsList.Clear();
var strippersMap = Fetcher.ComputeStrippersMap();
for (int i = 0; i < settingsList.Count; ++i)
{
var settings = settingsList[i];
if (settings == null)
continue;
if (CanTransferSettingsToPlayer(strippersMap, settings, out var isAvailableOnPlayerBuild, out var strippersDefined))
runtimeSettingsList.Add(settings);
report.AddStrippedSetting(settings.GetType(), isAvailableOnPlayerBuild, strippersDefined);
}
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,64 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
namespace UnityEngine.Rendering
{
static partial class RenderPipelineGraphicsSettingsStripper
{
static class Fetcher
{
static readonly Type k_InterfaceType = typeof(IRenderPipelineGraphicsSettingsStripper<>);
public static Dictionary<Type, List<IStripper>> ComputeStrippersMap()
{
var validStrippers = new Dictionary<Type, List<IStripper>>();
foreach (var (stripperType, settingsType) in GetStrippersFromAssemblies())
{
var stripperInstance = Activator.CreateInstance(stripperType) as IStripper;
if (stripperInstance is not { active: true })
continue;
if (!validStrippers.TryGetValue(settingsType, out var instances))
{
instances = new List<IStripper>();
validStrippers[settingsType] = instances;
}
instances.Add(stripperInstance);
}
return validStrippers;
}
private static IEnumerable<(Type, Type)> GetStrippersFromAssemblies()
{
foreach (var stripperType in TypeCache.GetTypesDerivedFrom(typeof(IRenderPipelineGraphicsSettingsStripper<>)))
{
if (stripperType.IsAbstract)
continue;
// The ctor is private?
if (stripperType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes,
null) == null)
{
Debug.LogWarning($"{stripperType} has no public constructor, it will not be used to strip {nameof(IRenderPipelineGraphicsSettings)}.");
continue;
}
foreach (var i in stripperType.GetInterfaces())
{
if (i.IsGenericType && i.GetGenericTypeDefinition() == k_InterfaceType)
{
yield return (stripperType, i.GetGenericArguments()[0]);
}
}
}
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,80 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
namespace UnityEngine.Rendering
{
internal static partial class RenderPipelineGraphicsSettingsStripper
{
public class Report : IDisposable
{
internal static string k_OutputPath = "Temp/graphics-settings-stripping.json";
[Serializable]
class SettingsStrippingInfo
{
public string type;
public bool isAvailableInPlayerBuild;
public bool strippersDefined;
}
[Serializable]
class Export
{
public uint totalSettings = 0;
public uint totalSettingsOnPlayer = 0;
public List<SettingsStrippingInfo> settings = new();
}
public Report()
{
try
{
if (File.Exists(k_OutputPath))
File.Delete(k_OutputPath);
}
catch (Exception e)
{
Debug.LogException(e);
}
}
Export m_Data = new();
public void AddStrippedSetting(Type settingsType, bool isAvailableInPlayerBuild, bool strippersDefined)
{
m_Data.totalSettings++;
if (isAvailableInPlayerBuild)
{
m_Data.totalSettingsOnPlayer++;
}
m_Data.settings.Add(new SettingsStrippingInfo()
{
type = settingsType.AssemblyQualifiedName,
isAvailableInPlayerBuild = isAvailableInPlayerBuild,
strippersDefined = strippersDefined
});
}
static void ExportStrippingInfo(string path, Export data)
{
try
{
File.WriteAllText(path, JsonUtility.ToJson(data, true));
}
catch (Exception e)
{
Debug.LogException(e);
}
}
public void Dispose()
{
ExportStrippingInfo(k_OutputPath, m_Data);
}
}
}
}
#endif

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4f03e96382963a746a762cee65652eb3