add asset graph

This commit is contained in:
StarBeats 2025-04-10 20:39:04 +08:00
parent 61b4f13b7d
commit ff3a72b4f7
84 changed files with 4615 additions and 183 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a359b65f33dc9df43950bf68bd99b6ee
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
{
"name": "AssetDependencyGraph-Editor",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0f6edbbfd6f04b1479b191b629a0421f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9303f9c952516f34cbc668b8d9217ee7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,233 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace AssetDependencyGraph
{
[BsonIgnoreExtraElements]
public class AssetIdentify
{
public string Path;
public string AssetType;
[AllowNull]
public string Guid;
[AllowNull]
public string Md5;
}
[BsonIgnoreExtraElements]
public class AssetNode
{
public AssetIdentify Self;
public string AssetType;
public HashSet<AssetIdentify> Dependencies = new();
public HashSet<AssetIdentify> Dependent = new();
}
[BsonIgnoreExtraElements]
public sealed class FolderNode : AssetNode
{
}
[BsonIgnoreExtraElements]
public sealed class PackageNode : AssetNode
{
}
public class AssetDependencyGraphDB
{
MongoClient client;
IMongoCollection<FolderNode> FolderNodes;
IMongoCollection<PackageNode> PackageNodes;
IMongoCollection<AssetNode> AssetNodes;
Dictionary<string, AssetNode> findCacheDic = new();
public AssetDependencyGraphDB(string user, string passwd, string ip)
{
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl($"mongodb://{user}:{passwd}@{ip}:27017/"));
settings.ConnectTimeout = TimeSpan.FromSeconds(5);
settings.MinConnectionPoolSize = 1;
settings.MaxConnectionPoolSize = 25;
client = new MongoClient(settings);
var db = client.GetDatabase("assetgraph");
FolderNodes = db.GetCollection<FolderNode>("folder_nodes");
PackageNodes = db.GetCollection<PackageNode>("package_nodes");
AssetNodes = db.GetCollection<AssetNode>("asset_nodes");
}
public void Clean()
{
client.DropDatabase("assetgraph");
var db = client.GetDatabase("assetgraph");
FolderNodes = db.GetCollection<FolderNode>("folder_nodes");
PackageNodes = db.GetCollection<PackageNode>("package_nodes");
AssetNodes = db.GetCollection<AssetNode>("asset_nodes");
}
public void UpdateOrInsert<T>(T node) where T : AssetNode
{
switch (node)
{
case FolderNode folderNode:
{
var filter = Builders<FolderNode>.Filter.And(
Builders<FolderNode>.Filter.Eq(fn=>fn.Self.Path,node.Self.Path)
);
var found = FolderNodes.Find(filter);
if (found == null || found.CountDocuments() == 0)
{
FolderNodes.InsertOne(folderNode);
}
else
{
var result = FolderNodes.UpdateOne(filter, Builders<FolderNode>.Update.Combine(
Builders<FolderNode>.Update.Set(fn => fn.Self, folderNode.Self),
Builders<FolderNode>.Update.Set(fn => fn.AssetType, folderNode.AssetType),
Builders<FolderNode>.Update.Set(fn => fn.Dependencies, folderNode.Dependencies),
Builders<FolderNode>.Update.Set(fn => fn.Dependent, folderNode.Dependent)
));
}
break;
}
case PackageNode packageNode:
{
var filter = Builders<PackageNode>.Filter.And(
Builders<PackageNode>.Filter.Eq(fn => fn.Self.Path, node.Self.Path)
);
var found = PackageNodes.Find(filter);
if (found == null || found.CountDocuments() == 0)
{
PackageNodes.InsertOne(packageNode);
}
else
{
var result = PackageNodes.UpdateOne(filter, Builders<PackageNode>.Update.Combine(
Builders<PackageNode>.Update.Set(fn => fn.Self, packageNode.Self),
Builders<PackageNode>.Update.Set(fn => fn.AssetType, packageNode.AssetType),
Builders<PackageNode>.Update.Set(fn => fn.Dependencies, packageNode.Dependencies),
Builders<PackageNode>.Update.Set(fn => fn.Dependent, packageNode.Dependent)
));
}
break;
}
case AssetNode assetNode:
{
var filter = Builders<AssetNode>.Filter.And(
Builders<AssetNode>.Filter.Eq(fn => fn.Self.Path, node.Self.Path)
);
var found = AssetNodes.Find(filter);
if (found == null || found.CountDocuments() == 0)
{
AssetNodes.InsertOne(assetNode);
}
else
{
var result = AssetNodes.UpdateOne(filter, Builders<AssetNode>.Update.Combine(
Builders<AssetNode>.Update.Set(fn => fn.Self, assetNode.Self),
Builders<AssetNode>.Update.Set(fn => fn.AssetType, assetNode.AssetType),
Builders<AssetNode>.Update.Set(fn => fn.Dependencies, assetNode.Dependencies),
Builders<AssetNode>.Update.Set(fn => fn.Dependent, assetNode.Dependent)
));
}
break;
}
default:
break;
}
}
public void Delete<T>(T node) where T : AssetNode
{
switch (node)
{
case FolderNode folderNode:
{
var filter = Builders<FolderNode>.Filter.And(
Builders<FolderNode>.Filter.Eq(fn => fn.Self.Path, node.Self.Path)
);
var found = FolderNodes.Find(filter);
if (found != null && found.CountDocuments() == 0)
{
// TODO: del ref dep
FolderNodes.DeleteOne(filter);
}
break;
}
case PackageNode packageNode:
{
var filter = Builders<PackageNode>.Filter.And(
Builders<PackageNode>.Filter.Eq(fn => fn.Self.Path, node.Self.Path)
);
var found = PackageNodes.Find(filter);
if (found != null && found.CountDocuments() == 0)
{
// TODO: del ref dep
PackageNodes.DeleteOne(filter);
}
break;
}
case AssetNode assetNode:
{
var filter = Builders<AssetNode>.Filter.And(
Builders<AssetNode>.Filter.Eq(fn => fn.Self.Path, node.Self.Path)
);
var found = AssetNodes.Find(filter);
if (found != null && found.CountDocuments() == 0)
{
// TODO: del ref dep
AssetNodes.DeleteOne(filter);
}
break;
}
default:
break;
}
}
public AssetNode Find(string path)
{
if(findCacheDic.TryGetValue(path, out var assetNode))
{
return assetNode;
}
var filter = Builders<AssetNode>.Filter.And(
Builders<AssetNode>.Filter.Eq(fn => fn.Self.Path, path)
);
var found = AssetNodes.Find(filter);
if (found != null && found.CountDocuments() != 0)
{
assetNode = found.First();
findCacheDic[path] = assetNode;
return assetNode;
}
var filter1 = Builders<PackageNode>.Filter.And(
Builders<PackageNode>.Filter.Eq(fn => fn.Self.Path, path)
);
var found1 = PackageNodes.Find(filter1);
if (found1 != null && found1.CountDocuments() != 0)
{
assetNode = found1.First();
findCacheDic[path] = assetNode;
return assetNode;
}
var filter2 = Builders<FolderNode>.Filter.And(
Builders<FolderNode>.Filter.Eq(fn => fn.Self.Path, path)
);
var found2 = FolderNodes.Find(filter2);
if (found2 != null && found2.CountDocuments() != 0)
{
assetNode = found2.First();
findCacheDic[path] = assetNode;
return assetNode;
}
return null;
}
}
}

View File

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

View File

@ -0,0 +1,911 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
namespace AssetDependencyGraph
{
public class AssetGraphView : GraphView
{
public AssetGraphView()
{
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
this.AddManipulator(new FreehandSelector());
VisualElement background = new VisualElement
{
style =
{
backgroundColor = new Color(0.17f, 0.17f, 0.17f, 1f)
}
};
Insert(0, background);
background.StretchToParentSize();
}
}
public class AssetGroup
{
public AssetNode AssetNode;
public Group GroupNode = new Group();
public Node MainGraphNode = new Node();
public Rect MainGraphNodeLastPosition = new Rect();
public List<GraphElement> AssetGraphNodes = new List<GraphElement>();
public List<GraphElement> AssetGraphConnections = new List<GraphElement>();
public List<Node> DependenciesForPlacement = new List<Node>();
}
public class AssetDependencyGraph : EditorWindow
{
private const float NodeWidth = 300.0f;
DependencyAnalyzer da = new DependencyAnalyzer();
AssetDependencyGraphDB db = new AssetDependencyGraphDB("admin", "CCS20190109", "10.225.0.170");
Dictionary<string, Toggle> type2Toogle = new();
(string assetType, bool show)[] assetTypeHidenTogleItems = new[] {
("MonoScript", true), ("Material", false), ("Shader", true),
("ComputeShader" ,true), ("AudioClip", false), ("VideoClip", false),
("AnimationClip", false), ("Executable" , true), ("UnityAssembly", true),
("SourceFile", true), ("VolumeProfile", true),
};
Toggle AlignmentToggle;
private GraphView graphView;
private readonly List<Object> selectedObjects = new List<Object>();
private readonly List<AssetGroup> assetGroups = new List<AssetGroup>();
private readonly Dictionary<string, Node> fullPathNodeLookup = new Dictionary<string, Node>();
[MenuItem("Window/Asset Dependency Graph")]
public static void CreateTestGraphViewWindow()
{
var window = GetWindow<AssetDependencyGraph>(true);
window.titleContent = new GUIContent("Asset Dependency Graph");
}
public void OnEnable()
{
CreateGraph();
}
public void OnDisable()
{
rootVisualElement.Remove(graphView);
}
void CreateGraph()
{
graphView = new AssetGraphView
{
name = "Asset Dependency Graph",
};
VisualElement toolbar = CreateToolbar();
VisualElement toolbar2 = CreateFilterbar();
rootVisualElement.Add(toolbar);
rootVisualElement.Add(toolbar2);
rootVisualElement.Add(graphView);
graphView.StretchToParentSize();
toolbar.BringToFront();
toolbar2.BringToFront();
}
VisualElement CreateToolbar()
{
var toolbar = new VisualElement
{
style =
{
flexDirection = FlexDirection.Row,
flexGrow = 0,
backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f)
}
};
var options = new VisualElement
{
style = { alignContent = Align.Center }
};
toolbar.Add(options);
toolbar.Add(new Button(ExploreAsset)
{
text = "Explore Asset",
});
toolbar.Add(new Button(ClearGraph)
{
text = "Clear"
});
toolbar.Add(new Button(ResetGroups)
{
text = "Reset Groups"
});
toolbar.Add(new Button(ResetAllNodes)
{
text = "Reset Nodes"
});
toolbar.Add(new Button(() =>
{
da.Analyze(Application.dataPath);
})
{
text = "Analyze Asset"
});
var ts = new ToolbarSearchField();
ts.RegisterValueChangedCallback(x =>
{
if (string.IsNullOrEmpty(x.newValue))
{
graphView.FrameAll();
return;
}
graphView.ClearSelection();
graphView.graphElements.ToList().ForEach(y =>
{
if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0)
{
graphView.AddToSelection(node);
}
});
graphView.FrameSelection();
});
toolbar.Add(ts);
AlignmentToggle = new Toggle();
AlignmentToggle.text = "Horizontal Layout";
AlignmentToggle.value = true;
AlignmentToggle.RegisterValueChangedCallback(x =>
{
ResetAllNodes();
});
toolbar.Add(AlignmentToggle);
return toolbar;
}
VisualElement CreateFilterbar()
{
var toolbar = new VisualElement
{
style =
{
flexDirection = FlexDirection.Row,
flexGrow = 0,
backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f)
}
};
var options = new VisualElement
{
style = { alignContent = Align.Center }
};
toolbar.Add(options);
toolbar.Add(new Label("Filters: "));
foreach (var pair in assetTypeHidenTogleItems)
{
var assetTypeTogle = new Toggle();
assetTypeTogle.text = "Hide " + pair.assetType;
assetTypeTogle.value = pair.show;
assetTypeTogle.RegisterValueChangedCallback(x =>
{
FilterAssetGroups();
});
toolbar.Add(assetTypeTogle);
type2Toogle[pair.assetType] = assetTypeTogle;
}
return toolbar;
}
private void ExploreAsset()
{
Object[] objs = Selection.objects;
foreach (var obj in objs)
{
//Prevent readding same object
if (selectedObjects.Contains(obj))
{
Debug.Log("Object already loaded");
return;
}
selectedObjects.Add(obj);
AssetGroup AssetGroup = new AssetGroup();
AssetGroup.AssetNode = db.Find(AssetDatabase.GetAssetPath(obj).ToUnityFullPath());
assetGroups.Add(AssetGroup);
// assetPath will be empty if obj is null or isn't an asset (a scene object)
if (obj == null)
return;
AssetGroup.GroupNode = new Group { title = obj.name };
PopulateGroup(AssetGroup, obj, new Rect(10, graphView.contentRect.height / 2, 0, 0));
}
}
void PopulateGroup(AssetGroup AssetGroup, Object obj, Rect position)
{
if (obj == null)
{
obj = AssetDatabase.LoadMainAssetAtPath(AssetGroup.AssetNode.Self.Path.ToUnityRelatePath());
if (obj == null)
{
Debug.Log("Object doesn't exist anymore");
return;
}
}
AssetGroup.MainGraphNode = CreateNode(AssetGroup, AssetGroup.AssetNode, obj, true);
AssetGroup.MainGraphNode.userData = 0;
AssetGroup.MainGraphNode.SetPosition(position);
if (!graphView.Contains(AssetGroup.GroupNode))
{
graphView.AddElement(AssetGroup.GroupNode);
}
graphView.AddElement(AssetGroup.MainGraphNode);
AssetGroup.GroupNode.AddElement(AssetGroup.MainGraphNode);
CreateDependencyNodes(AssetGroup, AssetGroup.AssetNode, AssetGroup.MainGraphNode, AssetGroup.GroupNode, 1);
CreateDependentNodes(AssetGroup, AssetGroup.AssetNode, AssetGroup.MainGraphNode, AssetGroup.GroupNode, -1);
AssetGroup.AssetGraphNodes.Add(AssetGroup.MainGraphNode);
AssetGroup.GroupNode.capabilities &= ~Capabilities.Deletable;
AssetGroup.GroupNode.Focus();
AssetGroup.MainGraphNode.RegisterCallback<GeometryChangedEvent, AssetGroup>(
UpdateGroupDependencyNodePlacement, AssetGroup
);
}
//Recreate the groups but use the already created groups instead of new ones
void FilterAssetGroups()
{
//first collect the main node's position and then clear the graph
foreach (var AssetGroup in assetGroups)
{
AssetGroup.MainGraphNodeLastPosition = AssetGroup.MainGraphNode.GetPosition();
}
fullPathNodeLookup.Clear();
foreach (var AssetGroup in assetGroups)
{
//clear the nodes and dependencies after getting the position of the main node
CleanGroup(AssetGroup);
PopulateGroup(AssetGroup, null, AssetGroup.MainGraphNodeLastPosition);
}
}
void CleanGroup(AssetGroup assetGroup)
{
if (assetGroup.AssetGraphConnections.Count > 0)
{
foreach (var edge in assetGroup.AssetGraphConnections)
{
graphView.RemoveElement(edge);
}
}
assetGroup.AssetGraphConnections.Clear();
foreach (var node in assetGroup.AssetGraphNodes)
{
graphView.RemoveElement(node);
}
assetGroup.AssetGraphNodes.Clear();
assetGroup.DependenciesForPlacement.Clear();
}
private void CreateDependencyNodes(AssetGroup assetGroup, AssetNode asssetNode, Node selfGraphNode, Group groupGraphNode, int depth)
{
foreach (var dependAssetId in asssetNode.Dependencies)
{
AssetNode dependAssetNode = db.Find(dependAssetId.Path);
var typeName = dependAssetNode.AssetType;
//filter out selected asset types
if (FilterType(typeName))
{
continue;
}
Node dependGraphNode = CreateNode(assetGroup, dependAssetNode, AssetDatabase.LoadMainAssetAtPath(dependAssetId.Path.ToUnityRelatePath()), false);
if (!assetGroup.AssetGraphNodes.Contains(dependGraphNode))
{
dependGraphNode.userData = depth;
}
//CreateDependencyNodes(assetGroup, dependAssetNode, dependGraphNode, groupGraphNode, depth + 1);
//if the node doesnt exists yet, put it in the group
if (!graphView.Contains(dependGraphNode))
{
graphView.AddElement(dependGraphNode);
assetGroup.DependenciesForPlacement.Add(dependGraphNode);
groupGraphNode.AddElement(dependGraphNode);
}
else
{
//TODO: if it already exists, put it in a separate group for shared assets
//Check if the dependencyNode is in the same group or not
//if it's a different group move it to a new shared group
/*
if (SharedToggle.value) {
if (!assetGroup.m_AssetNodes.Contains(dependencyNode)) {
if (assetGroup.SharedGroup == null) {
assetGroup.SharedGroup = new AssetGroup();
AssetGroups.Add(assetGroup.SharedGroup);
assetGroup.SharedGroup.assetPath = assetGroup.assetPath;
assetGroup.SharedGroup.groupNode = new Group { title = "Shared Group" };
assetGroup.SharedGroup.mainNode = dependencyNode;
assetGroup.SharedGroup.mainNode.userData = 0;
}
if (!m_GraphView.Contains(assetGroup.SharedGroup.groupNode)) {
m_GraphView.AddElement(assetGroup.SharedGroup.groupNode);
}
//add the node to the group and remove it from the previous group
assetGroup.m_AssetNodes.Remove(dependencyNode);
//assetGroup.groupNode.RemoveElement(dependencyNode);
assetGroup.m_DependenciesForPlacement.Remove(dependencyNode);
assetGroup.SharedGroup.m_DependenciesForPlacement.Add(dependencyNode);
if (!assetGroup.SharedGroup.groupNode.ContainsElement(dependencyNode)) {
assetGroup.SharedGroup.groupNode.AddElement(dependencyNode);
}
assetGroup.SharedGroup.m_AssetNodes.Add(dependencyNode);
}
}*/
}
Edge edge = CreateEdge(dependGraphNode, selfGraphNode);
assetGroup.AssetGraphConnections.Add(edge);
assetGroup.AssetGraphNodes.Add(dependGraphNode);
}
}
private void CreateDependentNodes(AssetGroup assetGroup, AssetNode asssetNode, Node selfGraphNode, Group groupGraphNode, int depth)
{
foreach (var dependAssetId in asssetNode.Dependent)
{
AssetNode dependAssetNode = db.Find(dependAssetId.Path);
var typeName = dependAssetNode.AssetType;
//filter out selected asset types
if (FilterType(typeName))
{
continue;
}
Node dependentGraphNode = CreateNode(assetGroup, dependAssetNode, AssetDatabase.LoadMainAssetAtPath(dependAssetId.Path.ToUnityRelatePath()), false);
if (!assetGroup.AssetGraphNodes.Contains(dependentGraphNode))
{
dependentGraphNode.userData = depth;
}
//CreateDependencyNodes(assetGroup, dependAssetNode, dependGraphNode, groupGraphNode, depth - 1);
//if the node doesnt exists yet, put it in the group
if (!graphView.Contains(dependentGraphNode))
{
graphView.AddElement(dependentGraphNode);
assetGroup.DependenciesForPlacement.Add(dependentGraphNode);
groupGraphNode.AddElement(dependentGraphNode);
}
else
{
//TODO: if it already exists, put it in a separate group for shared assets
//Check if the dependencyNode is in the same group or not
//if it's a different group move it to a new shared group
/*
if (SharedToggle.value) {
if (!assetGroup.m_AssetNodes.Contains(dependencyNode)) {
if (assetGroup.SharedGroup == null) {
assetGroup.SharedGroup = new AssetGroup();
AssetGroups.Add(assetGroup.SharedGroup);
assetGroup.SharedGroup.assetPath = assetGroup.assetPath;
assetGroup.SharedGroup.groupNode = new Group { title = "Shared Group" };
assetGroup.SharedGroup.mainNode = dependencyNode;
assetGroup.SharedGroup.mainNode.userData = 0;
}
if (!m_GraphView.Contains(assetGroup.SharedGroup.groupNode)) {
m_GraphView.AddElement(assetGroup.SharedGroup.groupNode);
}
//add the node to the group and remove it from the previous group
assetGroup.m_AssetNodes.Remove(dependencyNode);
//assetGroup.groupNode.RemoveElement(dependencyNode);
assetGroup.m_DependenciesForPlacement.Remove(dependencyNode);
assetGroup.SharedGroup.m_DependenciesForPlacement.Add(dependencyNode);
if (!assetGroup.SharedGroup.groupNode.ContainsElement(dependencyNode)) {
assetGroup.SharedGroup.groupNode.AddElement(dependencyNode);
}
assetGroup.SharedGroup.m_AssetNodes.Add(dependencyNode);
}
}*/
}
Edge edge = CreateEdge(selfGraphNode, dependentGraphNode);
assetGroup.AssetGraphConnections.Add(edge);
assetGroup.AssetGraphNodes.Add(dependentGraphNode);
}
}
Edge CreateEdge(Node dependencyNode, Node parentNode)
{
Edge edge = new Edge
{
input = dependencyNode.inputContainer[0] as Port,
output = parentNode.outputContainer[0] as Port,
};
edge.input?.Connect(edge);
edge.output?.Connect(edge);
dependencyNode.RefreshPorts();
graphView.AddElement(edge);
edge.capabilities &= ~Capabilities.Deletable;
return edge;
}
private Node CreateNode(AssetGroup assetGroup, AssetNode assetNode, Object obj, bool isMainNode)
{
Node resultNode;
string fullPath = assetNode.Self.Path;
if (fullPathNodeLookup.TryGetValue(fullPath, out resultNode))
{
//----not sure what this is, the more dependencies the further removed on the chart?
//int currentDepth = (int)resultNode.userData;
//resultNode.userData = currentDepth + 1;
return resultNode;
}
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var assetGuid, out long _))
{
var objNode = new Node
{
title = obj.name,
style =
{
width = NodeWidth
}
};
objNode.extensionContainer.style.backgroundColor = new Color(0.24f, 0.24f, 0.24f, 0.8f);
#region Select button
objNode.titleContainer.Add(new Button(() =>
{
Selection.activeObject = obj;
EditorGUIUtility.PingObject(obj);
})
{
style =
{
height = 16.0f,
alignSelf = Align.Center,
alignItems = Align.Center
},
text = "Select"
});
objNode.titleContainer.Add(new Button(() =>
{
// assetNode
})
{
style =
{
height = 16.0f,
alignSelf = Align.Center,
alignItems = Align.Center
},
text = "Delete"
});
#endregion
#region Padding
var infoContainer = new VisualElement
{
style =
{
paddingBottom = 4.0f,
paddingTop = 4.0f,
paddingLeft = 4.0f,
paddingRight = 4.0f
}
};
#endregion
#region Asset Path, removed to improve visibility with large amount of assets
// infoContainer.Add(new Label {
// text = assetPath,
//#if UNITY_2019_1_OR_NEWER
// style = { whiteSpace = WhiteSpace.Normal }
//#else
// style = { wordWrap = true }
//#endif
// });
#endregion
#region Asset type
var typeName = assetNode.AssetType;
var typeLabel = new Label
{
text = $"Type: {typeName}",
};
infoContainer.Add(typeLabel);
objNode.extensionContainer.Add(infoContainer);
#endregion
var typeContainer = new VisualElement
{
style =
{
paddingBottom = 4.0f,
paddingTop = 4.0f,
paddingLeft = 4.0f,
paddingRight = 4.0f,
backgroundColor = GetColorByAssetType(typeName)
}
};
objNode.extensionContainer.Add(typeContainer);
#region Node Icon, replaced with color
//Texture assetTexture = AssetPreview.GetAssetPreview(obj);
//if (!assetTexture)
// assetTexture = AssetPreview.GetMiniThumbnail(obj);
//if (assetTexture)
//{
// AddDivider(objNode);
// objNode.extensionContainer.Add(new Image
// {
// image = assetTexture,
// scaleMode = ScaleMode.ScaleToFit,
// style =
// {
// paddingBottom = 4.0f,
// paddingTop = 4.0f,
// paddingLeft = 4.0f,
// paddingRight = 4.0f
// }
// });
//}
#endregion
// Ports
var dependentAmount = 0;
foreach (var item in assetNode.Dependent)
{
if (item.AssetType != "Folder")
{
++dependentAmount;
}
}
if (assetNode.Dependent.Count > 0)
{
Port port = objNode.InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(Object));
port.Add(new Button(() =>
{
CreateDependentNodes(assetGroup, assetNode, fullPathNodeLookup[fullPath], assetGroup.GroupNode, (int)fullPathNodeLookup[fullPath].userData - 1);
EditorApplication.delayCall += () => ResetAllNodes();
})
{
style =
{
height = 16.0f,
alignSelf = Align.Center,
alignItems = Align.Center
},
text = "展开"
});
port.portName = dependentAmount + "个引用";
objNode.inputContainer.Add(port);
}
var dependencyAmount = assetNode.Dependencies.Count;
if (dependencyAmount > 0)
{
Port port = objNode.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(Object));
port.Add(new Button(() =>
{
CreateDependencyNodes(assetGroup, assetNode, fullPathNodeLookup[fullPath], assetGroup.GroupNode, (int)fullPathNodeLookup[fullPath].userData + 1);
EditorApplication.delayCall += () => ResetAllNodes();
})
{
style =
{
height = 16.0f,
alignSelf = Align.Center,
alignItems = Align.FlexEnd
},
text = "展开"
});
port.portName = dependencyAmount + "个依赖";
objNode.outputContainer.Add(port);
objNode.RefreshPorts();
}
resultNode = objNode;
resultNode.RefreshExpandedState();
resultNode.RefreshPorts();
resultNode.capabilities &= ~Capabilities.Deletable;
resultNode.capabilities |= Capabilities.Collapsible;
}
fullPathNodeLookup[fullPath] = resultNode;
return resultNode;
}
bool FilterType(string type)
{
if (type2Toogle.TryGetValue(type, out var result))
{
return result.value;
}
return false;
}
StyleColor GetColorByAssetType(string typeName)
{
switch (typeName)
{
case "MonoScript":
return Color.black;
case "Material":
return new Color(0.1f, 0.5f, 0.1f); //green
case "Texture2D":
return new Color(0.5f, 0.1f, 0.1f); //red
case "RenderTexture":
return new Color(0.8f, 0.1f, 0.1f); //red
case "Shader":
return new Color(0.1f, 0.1f, 0.5f); //dark blue
case "ComputeShader":
return new Color(0.1f, 0.1f, 0.5f); //dark blue
case "GameObject":
return new Color(0f, 0.8f, 0.7f); //light blue
case "AnimationClip":
return new Color(1, 0.7f, 1); //pink
case "AnimatorController":
return new Color(1, 0.7f, 0.8f); //pink
case "AudioClip":
return new Color(1, 0.8f, 0); //orange
case "AudioMixerController":
return new Color(1, 0.8f, 0); //orange
case "Font":
return new Color(0.9f, 1, 0.9f); //light green
case "TMP_FontAsset":
return new Color(0.9f, 1, 0.9f); //light green
case "Mesh":
return new Color(0.5f, 0, 0.5f); //purple
case "TerrainLayer":
return new Color(0.5f, 0.8f, 0f); //green
default:
break;
}
return CustomColor(typeName);
}
//Add custom assets here
StyleColor CustomColor(string assetType)
{
switch (assetType)
{
case "GearObject":
return new Color(0.9f, 0, 0.9f); //pink
case "TalentObject":
return new Color(0.9f, 0, 0.9f); //
case "AbilityInfo":
return new Color(0.9f, 0, 0.9f); //
case "HealthSO":
return new Color(0.9f, 0, 0.9f); //
default:
break;
}
//standard color
return new Color(0.24f, 0.24f, 0.24f, 0.8f);
}
private static void AddDivider(Node objNode)
{
var divider = new VisualElement { name = "divider" };
divider.AddToClassList("horizontal");
objNode.extensionContainer.Add(divider);
}
private void ClearGraph()
{
selectedObjects.Clear();
foreach (var assetGroup in assetGroups)
{
EmptyGroup(assetGroup);
}
fullPathNodeLookup.Clear();
assetGroups.Clear();
}
void EmptyGroup(AssetGroup assetGroup)
{
if (assetGroup.AssetGraphConnections.Count > 0)
{
foreach (var edge in assetGroup.AssetGraphConnections)
{
graphView.RemoveElement(edge);
}
}
assetGroup.AssetGraphConnections.Clear();
foreach (var node in assetGroup.AssetGraphNodes)
{
graphView.RemoveElement(node);
}
assetGroup.AssetGraphNodes.Clear();
assetGroup.DependenciesForPlacement.Clear();
graphView.RemoveElement(assetGroup.GroupNode);
assetGroup.GroupNode = null;
}
private void UpdateGroupDependencyNodePlacement(GeometryChangedEvent e, AssetGroup assetGroup)
{
assetGroup.MainGraphNode.UnregisterCallback<GeometryChangedEvent, AssetGroup>(
UpdateGroupDependencyNodePlacement
);
ResetNodes(assetGroup);
}
void ResetAllNodes()
{
foreach (var assetGroup in assetGroups)
{
ResetNodes(assetGroup);
}
}
//Reset the node positions of the given group
void ResetNodes(AssetGroup assetGroup)
{
// The current y offset in per depth
var depthOffset = new Dictionary<int, float>();
foreach (var node in assetGroup.DependenciesForPlacement)
{
int depth = (int)node.userData;
if (!depthOffset.ContainsKey(depth))
depthOffset.Add(depth, 0.0f);
if (AlignmentToggle.value)
{
depthOffset[depth] += node.layout.height;
}
else
{
depthOffset[depth] += node.layout.width;
}
}
// Move half of the node into negative y space so they're on either size of the main node in y axis
var depths = new List<int>(depthOffset.Keys);
foreach (int depth in depths)
{
if (depth == 0)
continue;
float offset = depthOffset[depth];
depthOffset[depth] = (0f - offset / 2.0f);
}
Rect mainNodeRect = assetGroup.MainGraphNode.GetPosition();
foreach (var node in assetGroup.DependenciesForPlacement)
{
int depth = (int)node.userData;
if (AlignmentToggle.value)
{
node.SetPosition(new Rect(mainNodeRect.x + node.layout.width * 1.5f * depth, mainNodeRect.y + depthOffset[depth], 0, 0));
}
else
{
node.SetPosition(new Rect(mainNodeRect.x + depthOffset[depth], mainNodeRect.y + node.layout.height * 1.5f * depth, 0, 0));
}
if (AlignmentToggle.value)
{
depthOffset[depth] += node.layout.height;
}
else
{
depthOffset[depth] += node.layout.width;
}
}
}
//fix the position of the groups so they dont overlap
void ResetGroups()
{
float y = 0;
float x = 0;
foreach (var assetGroup in assetGroups)
{
if (AlignmentToggle.value)
{
Rect pos = assetGroup.GroupNode.GetPosition();
pos.x = x;
assetGroup.GroupNode.SetPosition(pos);
x += assetGroup.GroupNode.GetPosition().width;
}
else
{
Rect pos = assetGroup.GroupNode.GetPosition();
pos.y = y;
assetGroup.GroupNode.SetPosition(pos);
y += assetGroup.GroupNode.GetPosition().height;
}
}
}
}
}

View File

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

View File

@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using Object = UnityEngine.Object;
namespace AssetDependencyGraph
{
public interface IDependencyAnalysis
{
void Analyze(string path, Dictionary<AssetIdentify, AssetNode> result);
public (AssetIdentify id, AssetNode node) GetOrCreateFolderNode(string path, Dictionary<AssetIdentify, AssetNode> result)
{
AssetIdentify k = null;
foreach (var item in result.Keys)
{
if (item.Path == path)
{
k = item;
}
}
if (k == null)
{
k = new AssetIdentify()
{
Path = path,
AssetType = "Folder",
Guid = null,
Md5 = null
};
result[k] = new FolderNode()
{
Self = k,
AssetType = "Folder",
};
}
return (k, result[k]);
}
public (AssetIdentify id, AssetNode node) GetOrCreateAssetNode(string path, Dictionary<AssetIdentify, AssetNode> result)
{
AssetIdentify k = null;
foreach (var item in result.Keys)
{
if (item.Path == path)
{
k = item;
}
}
if (k == null)
{
k = new AssetIdentify()
{
Path = path,
Guid = null,
Md5 = Utils.Md5(path)
};
if (path.EndsWith(".prefab") || path.EndsWith(".unity"))
{
result[k] = new PackageNode()
{
Self = k,
};
}
else
{
result[k] = new AssetNode()
{
Self = k,
};
}
}
return (k, result[k]);
}
public bool Exclude(string path) => path.EndsWith(".meta");
public string GetTypeByExtension(string ext)
{
switch (ext.ToLowerInvariant())
{
case ".a":
case ".dll":
case ".so":
case ".exe":
case ".dynlib":
return "Executable";
case ".asmdef":
case ".asmref":
return "UnityAssembly";
case ".cs":
case ".lua":
case ".js":
case ".ts":
case ".java":
case ".h":
case ".cpp":
case ".cxx":
case ".mm":
return "SourceFile";
case ".json":
case ".json5":
return "JsonFile";
case ".xml":
return "XmlFile";
case ".dat":
return "DatFile";
default:
return null;
}
}
}
public class UnityDependencyAnalysis : IDependencyAnalysis
{
HashSet<string> processed = new();
public void Analyze(string path, Dictionary<AssetIdentify, AssetNode> result)
{
if (!processed.Add(path))
{
return;
}
var dependencyAnalysis = (this as IDependencyAnalysis);
var kv = dependencyAnalysis.GetOrCreateAssetNode(path, result);
var relatePath = path.ToUnityRelatePath();
kv.id.Guid = AssetDatabase.AssetPathToGUID(relatePath);
var selfNode = kv.node;
if (dependencyAnalysis.GetTypeByExtension(Path.GetExtension(path)) is string assetType && assetType != null)
{
kv.id.AssetType = assetType;
selfNode.AssetType = assetType;
}
else
{
if (relatePath.EndsWith("Rock_01_Prefab.prefab"))
{
Console.WriteLine();
}
Object mainObject = AssetDatabase.LoadMainAssetAtPath(relatePath);
if (mainObject != null)
{
var prefabType = PrefabUtility.GetPrefabAssetType(mainObject);
if (prefabType != PrefabAssetType.NotAPrefab)
{
selfNode.AssetType = prefabType.ToString();
}
else
{
selfNode.AssetType = mainObject.GetType().Name;
}
kv.id.AssetType = selfNode.AssetType;
string[] dependencies = AssetDatabase.GetDependencies(relatePath, false);
for (int i = 0; i < dependencies.Length; i++)
{
var dep = dependencies[i].ToUnityFullPath();
var depkv = dependencyAnalysis.GetOrCreateAssetNode(dep, result);
depkv.node.Dependent.Add(selfNode.Self);
selfNode.Dependencies.Add(depkv.id);
Analyze(dep, result);
}
}
else
{
UnityEngine.Debug.LogWarning("unknown type:" + path);
}
}
}
}
public class FolderDependencyAnalysis : IDependencyAnalysis
{
public void Analyze(string path, Dictionary<AssetIdentify, AssetNode> result)
{
var dependencyAnalysis = (this as IDependencyAnalysis);
var k = dependencyAnalysis.GetOrCreateFolderNode(path, result);
Utils.TraverseDirectory(path, (p) =>
{
p = p.ToUniversalPath();
if (dependencyAnalysis.Exclude(p))
{
return;
}
var selfNode = result[k.id];
if (Directory.Exists(p))
{
var kv = dependencyAnalysis.GetOrCreateFolderNode(p, result);
kv.node.Dependent.Add(selfNode.Self);
selfNode.Dependencies.Add(kv.id);
}
else if (File.Exists(p))
{
var kv = dependencyAnalysis.GetOrCreateAssetNode(p, result);
kv.node.Dependent.Add(selfNode.Self);
selfNode.Dependencies.Add(kv.id);
}
}, 1);
}
}
internal class DependencyAnalyzer
{
private Dictionary<Predicate<string>, IDependencyAnalysis> dependencyAnalysisDic = new();
private Dictionary<AssetIdentify, AssetNode> assetIdentify2AssetNodeDic = new();
private bool Exclude(string path) => path.EndsWith(".meta");
public DependencyAnalyzer()
{
dependencyAnalysisDic.Add(new Predicate<string>(path => !Directory.Exists(path)), new UnityDependencyAnalysis());
dependencyAnalysisDic.Add(new Predicate<string>(path => Directory.Exists(path)), new FolderDependencyAnalysis());
}
private void Visivt(string path)
{
path = path.ToUniversalPath();
if (Exclude(path))
{
return;
}
foreach (var item in dependencyAnalysisDic)
{
if (item.Key(path))
{
item.Value.Analyze(path, assetIdentify2AssetNodeDic);
}
}
}
public void Analyze(string rootFolder)
{
Stopwatch sw = Stopwatch.StartNew();
sw.Start();
Utils.TraverseDirectory(rootFolder, Visivt, -1);
sw.Stop();
UnityEngine.Debug.Log($"分析引用耗时:{sw.ElapsedMilliseconds / 1000f}s");
AssetDependencyGraphDB db = new AssetDependencyGraphDB("admin", "CCS20190109", "10.225.0.170");
sw.Restart();
db.Clean();
Parallel.ForEach(assetIdentify2AssetNodeDic, item =>
{
db.UpdateOrInsert(item.Value);
});
sw.Stop();
UnityEngine.Debug.Log($"更新数据库:{sw.ElapsedMilliseconds / 1000f}s");
}
}
}

View File

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

View File

@ -0,0 +1,75 @@
using System;
using System.IO;
using UnityEngine;
namespace AssetDependencyGraph
{
public static class Utils
{
public static string Md5(string filename)
{
try
{
FileStream fs = new FileStream(filename, FileMode.Open);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(fs);
fs.Close();
return BitConverter.ToString(retVal).ToLower().Replace("-", "");
}
catch
{
throw;
}
}
public static void TraverseDirectory(string path, Action<string> action, int depth = 1)
{
if(depth == 0)
{
return;
}
foreach (string file in Directory.EnumerateFiles(path))
{
action.Invoke(file);
}
foreach (string directory in Directory.EnumerateDirectories(path))
{
action.Invoke(directory);
TraverseDirectory(directory, action, --depth);
}
}
public static string ToUniversalPath(this string path)
{
return path.Replace("\\", "/");
}
public static string ToUnityRelatePath(this string path)
{
if(path.StartsWith(Application.dataPath.ToUniversalPath().Replace("Assets", "")) && !path.StartsWith(Application.dataPath.ToUniversalPath() + "/Assets"))
{
return path.Replace(Application.dataPath.ToUniversalPath().Replace("Assets", ""), "");
}
return path.Replace(Application.dataPath.ToUniversalPath(), "Assets");
}
public static string ToUnityFullPath(this string path)
{
if(path.StartsWith("Packages"))
{
var fullPath = (Application.dataPath.ToUniversalPath().Replace("Assets", "") + path);
fullPath ??= (Application.dataPath.ToUniversalPath().Replace("Assets", "Library/PackageCache") + path);
if (!File.Exists(fullPath) && Directory.Exists(fullPath))
{
Debug.LogWarning($"ToUnityFullPath failure:{path}");
}
return fullPath;
}
return Application.dataPath.ToUniversalPath().Replace("Assets", "") + path;
}
}
}

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a251feda1c6acfa418d3cb94f0255dbe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,81 @@
fileFormatVersion: 2
guid: 38356707733942742b1bd8da40abed2e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: CylNsSn5V385rwZDZ0c3ZH2bVn7sAt4uXYM3ovG+CFkMBMj6NWTM5h0=
guid: f80f2e68fd0af0b4e86097f187a00ffa
PluginImporter:
externalObjects: {}
serializedVersion: 2
@ -18,11 +18,11 @@ PluginImporter:
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 0
Exclude OSXUniversal: 0
Exclude OpenHarmony: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 0
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
@ -40,26 +40,19 @@ PluginImporter:
second:
enabled: 1
settings:
CPU: x86_64
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
OpenHarmony: OpenHarmony
second:
enabled: 0
settings:
CPU: ARMv7
OpenHarmonySharedLibraryType: Executable
- first:
Standalone: Linux64
second:
enabled: 1
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 1
enabled: 0
settings:
CPU: AnyCPU
- first:
@ -71,9 +64,20 @@ PluginImporter:
- first:
Standalone: Win64
second:
enabled: 1
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
fileFormatVersion: 2
guid: 8639b566b8d0cfd4daca122ad15c9c71
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,83 @@
fileFormatVersion: 2
guid: 1ead4ac145c227142af0602db4c79b87
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
AndroidSharedLibraryType: Executable
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,83 @@
fileFormatVersion: 2
guid: 78d79268cf082b846a2a63642acc37f4
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
AndroidSharedLibraryType: Executable
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,81 @@
fileFormatVersion: 2
guid: 3de0577458e380243be22140907c0bc0
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
fileFormatVersion: 2
guid: c945cad0736669340b6639d058b729c8
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,83 @@
fileFormatVersion: 2
guid: e44a450d127d0824cbc021fc238d7b80
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
AndroidSharedLibraryType: Executable
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,81 @@
fileFormatVersion: 2
guid: e1cd43f2c984df240a8c23991b2f1e1c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,87 @@
fileFormatVersion: 2
guid: 75990583b0a472b44bd9f0946b424361
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
AndroidSharedLibraryType: Executable
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings:
AddToEmbeddedBinaries: false
CPU: AnyCPU
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,87 @@
fileFormatVersion: 2
guid: 83f2ea0e93026104faa9df07b11e4a1c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
Exclude iOS: 1
- first:
Android: Android
second:
enabled: 0
settings:
AndroidSharedLibraryType: Executable
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: Windows
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
iPhone: iOS
second:
enabled: 0
settings:
AddToEmbeddedBinaries: false
CPU: AnyCPU
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: WXgdsS2sVH9xLw8qkLUSbNyC4dSg6j4oqWPsSDV1FVxWrM8vTXd2QrY=
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,5 @@
%YAML 1.1
%TAG !u! tag:yousandi.cn,2023:
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
@ -56,17 +56,11 @@ Texture2D:
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 4
serializedVersion: 2
m_Width: 64
m_Height: 1
m_CompleteImageSize: 508
m_MipsStripped: 0
m_WebStreaming: 0
m_PriorityLevel: 0
m_UploadedMode: 0
m_DataStreamData:
size: 0
path:
m_TextureFormat: 4
m_MipCount: 7
m_IsReadable: 1
@ -97,6 +91,3 @@ Texture2D:
offset: 0
size: 0
path:
m_OriginalWidth: 0
m_OriginalHeight: 0
m_OriginalAssetGuid: 00000000000000000000000000000000

View File

@ -125,8 +125,7 @@ public class Test : MonoBehaviour
}
if (xessOn)
{
asset.superResolution = ESuperResolution.XESS13;
xess.SetSR(ESuperResolution.XESS13);
}
else
{

View File

@ -1,5 +1,5 @@
%YAML 1.1
%TAG !u! tag:yousandi.cn,2023:
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
@ -28,7 +28,7 @@ MonoBehaviour:
m_SupportsHDR: 1
m_HDRColorBufferPrecision: 0
m_MSAA: 1
m_RenderScale: 0.58823526
m_RenderScale: 1
m_UpscalingFilter: 0
m_FsrOverrideSharpness: 1
m_FsrSharpness: 1
@ -114,5 +114,5 @@ MonoBehaviour:
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
m_ShadowCascades: 0
superResolution: 5
superResolution: 0
vrsRate: 0

View File

@ -1,5 +1,5 @@
%YAML 1.1
%TAG !u! tag:yousandi.cn,2023:
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-8576419846133267094
MonoBehaviour:
m_ObjectHideFlags: 0
@ -27,6 +27,11 @@ MonoBehaviour:
m_Name: DLSS
m_EditorClassIdentifier:
m_Active: 0
quality: 0
useOptimalSetting: 0
sharpness: 0
preExposure: 0
mipMapBias: 0
--- !u!114 &-7390778553674367771
MonoBehaviour:
m_ObjectHideFlags: 0
@ -79,7 +84,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a00dddc5b3ea7fe45953ccbd49b58b94, type: 3}
m_Name: GSR
m_EditorClassIdentifier:
m_Active: 1
m_Active: 0
quality: 4
v1settings:
EnableEdgeDirection: 1

View File

@ -1,5 +1,5 @@
%YAML 1.1
%TAG !u! tag:yousandi.cn,2023:
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -1,7 +1,7 @@
fileFormatVersion: 2
guid: 3bcc50adabc5941a1a221dceb9b7e299
ModelImporter:
serializedVersion: 21202
serializedVersion: 22200
internalIDToNameTable: []
externalObjects: {}
materials:
@ -40,6 +40,7 @@ ModelImporter:
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
importPhysicalCameras: 1
importVisibility: 1
importBlendShapes: 1
importCameras: 1
@ -67,6 +68,7 @@ ModelImporter:
secondaryUVMinObjectScale: 1
secondaryUVPackMargin: 4
useFileScale: 1
strictVertexDataChecks: 0
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
@ -99,6 +101,8 @@ ModelImporter:
humanoidOversampling: 1
avatarSetup: 0
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
importBlendShapeDeformPercent: 0
remapMaterialsIfMaterialImportModeIsNone: 1
additionalBone: 0
userData:
assetBundleName:

View File

@ -1,31 +1,31 @@
[
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI.cpp.o", "RenderAPI.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderAPI.cpp.obj", "RenderAPI.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderAPI.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D11.cpp.o", "RenderAPI_D3D11.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderAPI_D3D11.cpp.obj", "RenderAPI_D3D11.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderAPI_D3D11.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_D3D12.cpp.o", "RenderAPI_D3D12.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderAPI_D3D12.cpp.obj", "RenderAPI_D3D12.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderAPI_D3D12.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_OpenGLCoreES.cpp.o", "RenderAPI_OpenGLCoreES.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderAPI_OpenGLCoreES.cpp.obj", "RenderAPI_OpenGLCoreES.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderAPI_OpenGLCoreES.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderAPI_Vulkan.cpp.o", "RenderAPI_Vulkan.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderAPI_Vulkan.cpp.obj", "RenderAPI_Vulkan.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderAPI_Vulkan.cpp"
},
{
"directory": "g:\\TJURP\\NativeRenderPlugin",
"arguments": ["D:\\tj\\2022.3.48t2\\Editor\\Data\\PlaybackEngines\\OpenHarmonyPlayer\\SDK\\12\\native\\llvm\\bin\\clang.exe", "-c", "-Qunused-arguments", "-D__MUSL__", "--target=aarch64-linux-ohos", "--sysroot=C:/Users/xinyt/AppData/Local/OpenHarmony/Sdk/12/native/sysroot", "-std=c++20", "-Igl3w", "-IUnity", "-DSUPPORT_OPENGL_UNIFIED=1", "-DSUPPORT_OPENGL_ES=1", "-DOHOS=1", "-IC:\\Program Files\\Huawei\\DevEco Studio\\sdk\\default\\hms\\native\\sysroot\\usr\\include", "-DMYCLANG", "-DOHOS_STL=c++_shared", "-fPIE", "-fPIC", "-o", "build\\.objs\\GfxPluginNativeRender\\harmonyos\\aarch64\\debug\\RenderingPlugin.cpp.o", "RenderingPlugin.cpp"],
"arguments": ["C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/std:c++20", "/Igl3w", "/IUnity", "/IC:\\VulkanSDK\\1.3.283.0\\Include", "/Iexternal\\include", "/DNOMINMAX", "/DSUPPORT_D3D11=1", "/DSUPPORT_D3D12=1", "/EHsc", "/Fobuild\\.objs\\GfxPluginNativeRender\\windows\\x64\\release\\RenderingPlugin.cpp.obj", "RenderingPlugin.cpp", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um", "-imsvc", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt", "-imsvc", "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include"],
"file": "RenderingPlugin.cpp"
}]

View File

@ -21,7 +21,6 @@ enum GraphicsFeature
METAL_FX_TEMPORAL_SR,
VIVO_TEMPORAL_SR,
QCOM_AFME,
XESS13,
MAX_CNT
};
@ -93,12 +92,6 @@ public:
virtual bool getFeatureSupport(GraphicsFeature feature);
virtual void enableXESS1(void* data) {}
virtual void doXESS1(void* data) {}
virtual void configXESS1(void* data) {}
virtual void disableXESS1() {}
virtual bool getInputResolution(uint32_t outw, uint32_t outh, int quality, uint32_t& width, uint32_t& height) { return false; }
virtual void SetVKPSOHook(bool enable) {}
protected:
virtual void initSupportFeature() = 0;

View File

@ -19,8 +19,6 @@
#include <map>
#include <iostream>
#include "xess1/xess.h"
#define ReturnOnFail(x, hr, OnFailureMsg, onFailureReturnValue) hr = x; if(FAILED(hr)){OutputDebugStringA(OnFailureMsg); return onFailureReturnValue;}
#define D3D12_DEFAULT_HEAP_TRIANGLE_BUFFER_NAME L"Native Plugin Default Heap Triangle Vertex Buffer"
@ -99,16 +97,7 @@ public:
virtual void initSupportFeature() override;
virtual void enableXESS1(void* data) override;
virtual void doXESS1(void* data) override;
virtual void disableXESS1() override;
virtual void configXESS1(void* data) override;
virtual bool getInputResolution(uint32_t outw, uint32_t outh, int quality, uint32_t& width, uint32_t& height) override;
IUnityGraphicsD3D12v7* s_d3d12;
XessV13* xess;
static RenderAPI_D3D12* instance;
};
RenderAPI_D3D12* RenderAPI_D3D12::instance = nullptr;
@ -150,7 +139,6 @@ void RenderAPI_D3D12::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInt
config_2.flags = kUnityD3D12EventConfigFlag_SyncWorkerThreads | kUnityD3D12EventConfigFlag_ModifiesCommandBuffersState | kUnityD3D12EventConfigFlag_EnsurePreviousFrameSubmission;
config_2.ensureActiveRenderTextureIsBound = false;
s_d3d12->ConfigureEvent(2, &config_2);
xess = new XessV13(s_d3d12->GetDevice());
initSupportFeature();
break;
case kUnityGfxDeviceEventShutdown:
@ -254,44 +242,8 @@ void RenderAPI_D3D12::initSupportFeature()
// 表示支持 2x4、4x2 和 4x4
}
support_features[GraphicsFeature::XESS13] = true;
}
void RenderAPI_D3D12::enableXESS1(void* data)
{
xess->enable([](const char* msg)
{
unityLog(msg);
}
);
}
void RenderAPI_D3D12::doXESS1(void* data)
{
UnityGraphicsD3D12RecordingState recordingState;
if (!s_d3d12->CommandRecordingState(&recordingState))
{
return;
}
xess->execute(data, recordingState.commandList);
}
void RenderAPI_D3D12::disableXESS1()
{
xess->disable();
}
void RenderAPI_D3D12::configXESS1(void* data)
{
//s_d3d12->GetCommandQueue()->Wait(s_d3d12->GetFrameFence(), 5);
xess->configxess(data);
}
bool RenderAPI_D3D12::getInputResolution(uint32_t outw, uint32_t outh, int quality, uint32_t& width, uint32_t& height)
{
return xess->get_input_resolution(outw, outh, quality, width, height);
}
#undef ReturnOnFail

View File

@ -107,10 +107,6 @@ enum NativeRenderingEvent
PostFGExtrapolation,
DisableFGExtrapolation,
SpatialUpScale,
EnableXESS1,
DoXESS1,
UpdateXESS1Config,
DisableXESS1,
};
static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data)
@ -159,31 +155,6 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data)
s_current_api->doFGExtrapolation(param->src, param->data, param->dst);
break;
}
case NativeRenderingEvent::EnableXESS1:
{
s_current_api->enableXESS1(data);
unityLog("enableXESS1");
break;
}
case NativeRenderingEvent::DisableXESS1:
{
unityLog("disableXESS0");
s_current_api->disableXESS1();
unityLog("disableXESS1");
break;
}
case NativeRenderingEvent::UpdateXESS1Config:
{
unityLog("configXESS1 0");
s_current_api->configXESS1(data);
unityLog("configXESS1 1");
break;
}
case NativeRenderingEvent::DoXESS1:
{
s_current_api->doXESS1(data);
break;
}
default:
break;
}
@ -202,12 +173,6 @@ extern "C" UNITY_INTERFACE_EXPORT bool GetFeatureSupport(int feature)
return s_current_api->getFeatureSupport((GraphicsFeature)feature);
}
extern "C" UNITY_INTERFACE_EXPORT bool GetInputResolution(uint32_t outw, uint32_t outh, int quality, uint32_t& width, uint32_t& height)
{
return s_current_api->getInputResolution(outw, outh, quality, width, height);
}
extern "C" UNITY_INTERFACE_EXPORT void SetVKPSOHook(bool enable)
{
s_current_api->SetVKPSOHook(enable);

View File

@ -47,11 +47,10 @@ target("GfxPluginNativeRender")
add_defines("SUPPORT_D3D12=1")
add_includedirs("external/include")
add_linkdirs("external/lib")
add_links("libxess")
add_includedirs("features/")
add_headerfiles("features/**.h")
add_files("features/**.cpp")
-- add_includedirs("features/")
-- add_headerfiles("features/**.h")
-- add_files("features/**.cpp")
end
end

View File

@ -503,7 +503,6 @@ namespace UnityEngine.Rendering.Universal
colorDescriptor.width = cameraData.camera.pixelWidth;
colorDescriptor.height = cameraData.camera.pixelHeight;
if (asset.SuperResolution == ESuperResolution.GSR2_COMPUTE
|| asset.SuperResolution == ESuperResolution.XESS13
|| asset.SuperResolution == ESuperResolution.DLSS1
|| asset.SuperResolution == ESuperResolution.DLSS2
|| asset.SuperResolution == ESuperResolution.DLSS3
@ -512,11 +511,6 @@ namespace UnityEngine.Rendering.Universal
{
colorDescriptor.enableRandomWrite = true;
}
colorDescriptor.enableRandomWrite = true;
if (asset.SuperResolution == ESuperResolution.XESS13)
{
colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat;
}
renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear);

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: Ciwd4SukVHjmo3sbv6mbRQOAS8tMmDtogzuA8jtsvh3tUelT2TDaMkM=
guid: 5f2d1973ed81cfa48a2454937af74b84
PluginImporter:
externalObjects: {}
serializedVersion: 2
@ -23,6 +23,7 @@ PluginImporter:
Exclude OpenHarmony: 1
Exclude Win: 0
Exclude Win64: 0
Exclude iOS: 1
- first:
Android: Android
second:
@ -74,6 +75,15 @@ PluginImporter:
enabled: 1
settings:
CPU: None
- first:
iPhone: iOS
second:
enabled: 0
settings:
AddToEmbeddedBinaries: false
CPU: AnyCPU
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -77,7 +77,6 @@ namespace X.Rendering.Feature
METAL_FX_TEMPORAL_SR,
VIVO_TEMPORAL_SR,
QCOM_AFME,
XESS13,
MAX_CNT
};

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
@ -26,10 +25,10 @@ namespace X.Rendering.Feature
DLSS3,
STP,// Unity 6 空间-时间后处理中的 upscaling
/// <summary>
/// Intel XeSS 1.3.1
/// <see cref="https://github.com/intel/xess.git"/>
/// Intel XeSS 2
/// <see cref="https://www.intel.com/content/www/us/en/developer/articles/technical/xess-sr-developer-guide.html"/>
/// </summary>
XESS13,
XESS2,
}
public enum SrQuality

View File

@ -247,18 +247,18 @@ namespace X.Rendering.Feature
{
switch (resolution)
{
case ESuperResolution.XESS13:
{
SetActive(true);
needTurnOnXess = true;
}
break;
default:
{
SetActive(false);
needTurnOffXess = false;
}
break;
// case ESuperResolution.XESS13:
// {
// SetActive(true);
// needTurnOnXess = true;
// }
// break;
// default:
// {
// SetActive(false);
// needTurnOffXess = false;
// }
// break;
}
}

View File

@ -0,0 +1,59 @@
using Intel;
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace X.Rendering.Feature
{
internal class XESS2 : ScriptableRendererFeature, ISuperResolutionFeature
{
private ProfilingSampler profiler;
private XeSS.xess_context_handle_t xessContext;
private bool xessCreated;
private bool xessInitialized;
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
}
public override void Create()
{
profiler = new ProfilingSampler("Xess2");
}
public bool InitFeature()
{
if (!XeSS.IsFeatureSupported())
{
Debug.LogWarning("XeSS not supported!");
return false;
}
XeSS.xess_result_t ret;
if ((ret = XeSS.xessCreateContext(ref xessContext)) != XeSS.xess_result_t.XESS_RESULT_SUCCESS)
{
xessCreated = false;
xessInitialized = false;
Debug.Log("XeSS context create failed:" + ret.ToString());
return false;
}
return true;
}
public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData)
{
}
public float GetRenderScale()
{
throw new NotImplementedException();
}
public void SetSR(ESuperResolution resolution)
{
}
}
}

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c4301ccc37809a3448fefbc8de9ce5eb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 56fdb40150d59f34a8c3378fa82df160
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: 109a6f5cf23637641961a8ed71f813b7
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: 87f82eba8f6e5fa4dabde39c2869c1d0
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
fileFormatVersion: 2
guid: 464b92b4db4ce5446a9d2445057c4a26
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,933 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
/// <summary>
/// Wrapper for Intel xess
/// </summary>
namespace Intel
{
internal static class LibXeSSWrapper
{
[DllImport("libxess", EntryPoint = "xessGetVersion")]
public static extern XeSS.xess_result_t xessGetVersion(IntPtr pVersion);
[DllImport("libxess", EntryPoint = "xessGetIntelXeFXVersion")]
public static extern XeSS.xess_result_t xessGetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion);
[DllImport("libxess", EntryPoint = "xessGetProperties")]
public static extern XeSS.xess_result_t xessGetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties);
[DllImport("libxess", EntryPoint = "xessGetInputResolution")]
public static extern XeSS.xess_result_t xessGetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution);
[DllImport("libxess", EntryPoint = "xessGetOptimalInputResolution")]
public static extern XeSS.xess_result_t xessGetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax);
[DllImport("libxess", EntryPoint = "xessGetJitterScale")]
public static extern XeSS.xess_result_t xessGetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY);
[DllImport("libxess", EntryPoint = "xessGetVelocityScale")]
public static extern XeSS.xess_result_t xessGetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY);
[DllImport("libxess", EntryPoint = "xessDestroyContext")]
public static extern XeSS.xess_result_t xessDestroyContext(IntPtr hContext);
[DllImport("libxess", EntryPoint = "xessSetJitterScale")]
public static extern XeSS.xess_result_t xessSetJitterScale(IntPtr hContext, float x, float y);
[DllImport("libxess", EntryPoint = "xessSetVelocityScale")]
public static extern XeSS.xess_result_t xessSetVelocityScale(IntPtr hContext, float x, float y);
[DllImport("libxess", EntryPoint = "xessSetLoggingCallback")]
public static extern XeSS.xess_result_t xessSetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback);
[DllImport("libxess", EntryPoint = "xessIsOptimalDriver")]
public static extern XeSS.xess_result_t xessIsOptimalDriver(IntPtr hContext);
}
internal static class LibXeSSD3D11Wrapper
{
[DllImport("libxess_dx11", EntryPoint = "xessGetVersion")]
public static extern XeSS.xess_result_t xessGetVersion(IntPtr pVersion);
[DllImport("libxess_dx11", EntryPoint = "xessGetIntelXeFXVersion")]
public static extern XeSS.xess_result_t xessGetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion);
[DllImport("libxess_dx11", EntryPoint = "xessGetProperties")]
public static extern XeSS.xess_result_t xessGetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties);
[DllImport("libxess_dx11", EntryPoint = "xessGetInputResolution")]
public static extern XeSS.xess_result_t xessGetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution);
[DllImport("libxess_dx11", EntryPoint = "xessGetOptimalInputResolution")]
public static extern XeSS.xess_result_t xessGetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax);
[DllImport("libxess_dx11", EntryPoint = "xessGetJitterScale")]
public static extern XeSS.xess_result_t xessGetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY);
[DllImport("libxess_dx11", EntryPoint = "xessGetVelocityScale")]
public static extern XeSS.xess_result_t xessGetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY);
[DllImport("libxess_dx11", EntryPoint = "xessDestroyContext")]
public static extern XeSS.xess_result_t xessDestroyContext(IntPtr hContext);
[DllImport("libxess_dx11", EntryPoint = "xessSetJitterScale")]
public static extern XeSS.xess_result_t xessSetJitterScale(IntPtr hContext, float x, float y);
[DllImport("libxess_dx11", EntryPoint = "xessSetVelocityScale")]
public static extern XeSS.xess_result_t xessSetVelocityScale(IntPtr hContext, float x, float y);
[DllImport("libxess_dx11", EntryPoint = "xessSetLoggingCallback")]
public static extern XeSS.xess_result_t xessSetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback);
[DllImport("libxess_dx11", EntryPoint = "xessIsOptimalDriver")]
public static extern XeSS.xess_result_t xessIsOptimalDriver(IntPtr hContext);
}
internal static class LibXeSSUnityPluginWrapper
{
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_xessCreateContext")]
public static extern XeSS.xess_result_t RenderingPlugin_xessCreateContext(IntPtr phContext);
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_xessBuildPipelines")]
public static extern XeSS.xess_result_t RenderingPlugin_xessBuildPipelines(IntPtr pContext, bool blocking, UInt32 initFlags);
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_xessGetInitParams")]
public static extern XeSS.xess_result_t RenderingPlugin_xessGetInitParams(IntPtr pContext, IntPtr pInitParams);
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_xessDestroyContext")]
public static extern XeSS.xess_result_t RenderingPlugin_xessDestroyContext(IntPtr pContext);
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_GetXeSSInitializeEvent")]
public static extern IntPtr RenderingPlugin_GetXeSSInitializeEvent();
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_GetXeSSDestroyContextEvent")]
public static extern IntPtr RenderingPlugin_GetXeSSDestroyContextEvent();
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_GetXeSSExecuteEventFunc")]
public static extern IntPtr RenderingPlugin_GetXeSSExecuteEventFunc();
[DllImport("XeSSRenderingPlugin", EntryPoint = "UnityPluginLoaded")]
public static extern bool UnityPluginLoaded();
[DllImport("XeSSRenderingPlugin", EntryPoint = "RenderingPlugin_xessIsValid")]
public static extern bool RenderingPlugin_xessIsValid(IntPtr hContext);
};
internal static class XeSSShaderIDs
{
// Shader resource views, i.e. read-only bindings
internal static readonly int SrvInputColor = Shader.PropertyToID("r_xess_input_color_jittered");
internal static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_xess_input_motion_vectors");
internal static readonly int SrvInputDepth = Shader.PropertyToID("r_xess_input_depth");
internal static readonly int SrvInputExposure = Shader.PropertyToID("r_xess_input_exposure");
internal static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_xess_upscaled_output");
};
public static class XeSS
{
abstract internal class Processer
{
abstract internal xess_result_t GetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion);
abstract internal xess_result_t GetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties);
abstract internal xess_result_t GetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution);
abstract internal xess_result_t GetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax);
abstract internal xess_result_t GetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY);
abstract internal xess_result_t GetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY);
abstract internal xess_result_t SetJitterScale(IntPtr hContext, float x, float y);
abstract internal xess_result_t SetVelocityScale(IntPtr hContext, float x, float y);
abstract internal xess_result_t SetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback);
abstract internal xess_result_t IsOptimalDriver(IntPtr hContext);
abstract internal xess_result_t GetInitParams(XeSS.xess_context_handle_t hContext, out XeSS.xess_init_params_t pInitParams);
abstract internal xess_result_t Initialize(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_init_params_t pInitParams);
abstract internal xess_result_t Execute(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_execute_params_t pExecParams);
}
/// <summary>
/// X<sup>e</sup>SS context.
/// </summary>
public class xess_context_handle_t
{
public IntPtr context;
internal Processer processer = null;
// internal pointer for init/exec/destroy
internal IntPtr[] pEventParams_internal = new IntPtr[2];
internal IntPtr[] pNativeParams_internal = new IntPtr[2];
internal void AllocEventParam(int idx, int size)
{
if (pEventParams_internal[idx] == IntPtr.Zero)
{
pEventParams_internal[idx] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_event_params_t)));
}
if (pNativeParams_internal[idx] == IntPtr.Zero)
{
pNativeParams_internal[idx] = Marshal.AllocHGlobal(size);
}
}
internal void FreeEventParams()
{
for (int i = 0; i < 2; i++)
{
if (pEventParams_internal[i] != IntPtr.Zero)
{
Marshal.FreeHGlobal(pEventParams_internal[i]);
pEventParams_internal[i] = IntPtr.Zero;
}
if (pNativeParams_internal[i] != IntPtr.Zero)
{
Marshal.FreeHGlobal(pNativeParams_internal[i]);
pNativeParams_internal[i] = IntPtr.Zero;
}
}
}
internal void InitEventParams()
{
for (int i = 0; i < 2; i++)
{
pEventParams_internal[i] = IntPtr.Zero;
pNativeParams_internal[i] = IntPtr.Zero;
}
}
public xess_context_handle_t()
{
context = IntPtr.Zero;
InitEventParams();
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D12)
{
processer = new XeSSD3D12.Processer_D3D12();
}
else if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan)
{
processer = new XeSSVK.Processer_VK();
}
else if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11)
{
processer = new XeSSD3D11.Processer_D3D11();
}
}
~xess_context_handle_t()
{
FreeEventParams();
}
};
/// <summary>
/// Set profiler sample for XeSS execution.
/// </summary>
/// <param name="sampler">Sampler for XeSS execution time.</param>
static public void SetProfilerSampler(CustomSampler sampler)
{
XeSSSampler = sampler;
}
internal static CustomSampler XeSSSampler = null;
/// <summary>
/// Check if the XeSS feature is supported.
/// </summary>
/// <returns>Whether the XeSS feature is supported.</returns>
static public bool IsFeatureSupported()
{
// D3D12 and Vulkan are full supported, and D3D11 is only supported on intel hardware
if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Direct3D12 &&
SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan &&
!(SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 && SystemInfo.graphicsDeviceVendorID == 0x8086))
{
return false;
}
if (!XeSS.xessPluginLoaded())
{
return false;
}
XeSS.xess_context_handle_t tryCreateXeSSContext = new XeSS.xess_context_handle_t();
XeSS.xess_result_t ret;
if ((ret = XeSS.xessCreateContext(ref tryCreateXeSSContext)) != XeSS.xess_result_t.XESS_RESULT_SUCCESS)
{
return false;
}
XeSS.xessDestroyContext(tryCreateXeSSContext);
return true;
}
/// <summary>
/// X<sup>e</sup>SS version.
/// X<sup>e</sup>SS uses major.minor.patch version format and Numeric 90+ scheme for development stage builds.
/// </summary>
public struct xess_version_t
{
public UInt16 major;
public UInt16 minor;
public UInt16 patch;
public UInt16 reserved;
};
/// <summary>
/// 2D variable.
/// </summary>
public struct xess_2d_t
{
public xess_2d_t(UInt32 _x, UInt32 _y)
{
x = _x;
y = _y;
}
public UInt32 x;
public UInt32 y;
};
/// <summary>
/// 2D coordinates.
/// </summary>
public struct xess_coord_t
{
public xess_coord_t(UInt32 _x, UInt32 _y)
{
x = _x;
y = _y;
}
public UInt32 x;
public UInt32 y;
};
/// <summary>
/// X<sup>e</sup>SS quality settings.
/// </summary>
public enum xess_quality_settings_t
{
XESS_QUALITY_SETTING_ULTRA_PERFORMANCE = 100,
XESS_QUALITY_SETTING_PERFORMANCE = 101,
XESS_QUALITY_SETTING_BALANCED = 102,
XESS_QUALITY_SETTING_QUALITY = 103,
XESS_QUALITY_SETTING_ULTRA_QUALITY = 104,
XESS_QUALITY_SETTING_ULTRA_QUALITY_PLUS = 105,
XESS_QUALITY_SETTING_AA = 106,
};
/// <summary>
/// X<sup>e</sup>SS initialization flags.
/// </summary>
public enum xess_init_flags_t
{
XESS_INIT_FLAG_NONE = 0,
/** Use motion vectors at target resolution. */
XESS_INIT_FLAG_HIGH_RES_MV = 1 << 0,
/** Use inverted (increased precision) depth encoding */
XESS_INIT_FLAG_INVERTED_DEPTH = 1 << 1,
/** Use exposure texture to scale input color. */
XESS_INIT_FLAG_EXPOSURE_SCALE_TEXTURE = 1 << 2,
/** Use responsive pixel mask texture. */
XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK = 1 << 3,
/** Use velocity in NDC */
XESS_INIT_FLAG_USE_NDC_VELOCITY = 1 << 4,
/** Use external descriptor heap */
XESS_INIT_FLAG_EXTERNAL_DESCRIPTOR_HEAP = 1 << 5,
/** Disable tonemapping for input and output */
XESS_INIT_FLAG_LDR_INPUT_COLOR = 1 << 6,
/** Remove jitter from input velocity*/
XESS_INIT_FLAG_JITTERED_MV = 1 << 7,
/** Enable automatic exposure calculation. */
XESS_INIT_FLAG_ENABLE_AUTOEXPOSURE = 1 << 8
};
/// <summary>
/// Properties for internal X<sup>e</sup>SS resources.
/// </summary>
public struct xess_properties_t
{
/** Required amount of descriptors for X<sup>e</sup>SS */
public UInt32 requiredDescriptorCount;
/** The heap size required by X<sup>e</sup>SS for temporary buffer storage. */
public UInt64 tempBufferHeapSize;
/** The heap size required by X<sup>e</sup>SS for temporary texture storage. */
public UInt64 tempTextureHeapSize;
};
/// <summary>
/// X<sup>e</sup>SS return codes.
/// </summary>
public enum xess_result_t
{
/** Warning. Folder to store dump data doesn't exist. Write operation skipped.*/
XESS_RESULT_WARNING_NONEXISTING_FOLDER = 1,
/** An old or outdated driver. */
XESS_RESULT_WARNING_OLD_DRIVER = 2,
/** X<sup>e</sup>SS operation was successful. */
XESS_RESULT_SUCCESS = 0,
/** X<sup>e</sup>SS not supported on the GPU. An SM 6.4 capable GPU is required. */
XESS_RESULT_ERROR_UNSUPPORTED_DEVICE = -1,
/** An unsupported driver. */
XESS_RESULT_ERROR_UNSUPPORTED_DRIVER = -2,
/** Execute called without initialization. */
XESS_RESULT_ERROR_UNINITIALIZED = -3,
/** Invalid argument such as descriptor handles. */
XESS_RESULT_ERROR_INVALID_ARGUMENT = -4,
/** Not enough available GPU memory. */
XESS_RESULT_ERROR_DEVICE_OUT_OF_MEMORY = -5,
/** Device function such as resource or descriptor creation. */
XESS_RESULT_ERROR_DEVICE = -6,
/** The function is not implemented */
XESS_RESULT_ERROR_NOT_IMPLEMENTED = -7,
/** Invalid context. */
XESS_RESULT_ERROR_INVALID_CONTEXT = -8,
/** Operation not finished yet. */
XESS_RESULT_ERROR_OPERATION_IN_PROGRESS = -9,
/** Operation not supported in current configuration. */
XESS_RESULT_ERROR_UNSUPPORTED = -10,
/** The library cannot be loaded. */
XESS_RESULT_ERROR_CANT_LOAD_LIBRARY = -11,
/** The c# wrapper error. */
XESS_RESULT_ERROR_CSHARP_WRAPPER = -100,
/** The invalid paramaters passed to c#. */
XESS_RESULT_ERROR_CSHARP_INVALID_ARGUMENT = -101,
/** Unknown internal failure */
XESS_RESULT_ERROR_UNKNOWN = -1000,
};
/// <summary>
/// X<sup>e</sup>SS logging level
/// </summary>
public enum xess_logging_level_t
{
XESS_LOGGING_LEVEL_DEBUG = 0,
XESS_LOGGING_LEVEL_INFO = 1,
XESS_LOGGING_LEVEL_WARNING = 2,
XESS_LOGGING_LEVEL_ERROR = 3
};
/// <summary>
/// Initialization parameters for X<sup>e</sup>SS.
/// </summary>
public struct xess_init_params_t
{
/** Output width and height. */
public XeSS.xess_2d_t outputResolution;
/** Quality setting */
public XeSS.xess_quality_settings_t qualitySetting;
/** Initialization flags. */
public UInt32 initFlags;
/** Specifies the node mask for internally created resources on
* multi-adapter systems. */
public UInt32 creationNodeMask;
/** Specifies the node visibility mask for internally created resources
* on multi-adapter systems. */
public UInt32 visibleNodeMask;
};
/// <summary>
/// Execution parameters for X<sup>e</sup>SS
/// </summary>
public struct xess_execute_params_t
{
/** Input color texture.*/
public Texture colorTexture;
/** Input motion vector texture.*/
public Texture velocityTexture;
/** Optional depth texture. Required if XESS_INIT_FLAG_HIGH_RES_MV has not been specified.*/
public Texture depthTexture;
/** Optional 1x1 exposure scale texture. Required if XESS_INIT_FLAG_EXPOSURE_TEXTURE has been
* specified.*/
public Texture exposureScaleTexture;
/** Optional responsive pixel mask texture. Required if XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK
* has been specified.*/
public Texture responsivePixelMaskTexture;
/** Output texture in target resolution.*/
public Texture outputTexture;
/** Jitter X coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetX;
/** Jitter Y coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetY;
/** Optional input color scaling. Default is 1. */
public float exposureScale;
/** Resets the history accumulation in this frame. */
public UInt32 resetHistory;
/** Input color width. */
public UInt32 inputWidth;
/** Input color height. */
public UInt32 inputHeight;
/** Base coordinate for the input color in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputColorBase;
/** Base coordinate for the input motion vector in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputMotionVectorBase;
/** Base coordinate for the input depth in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputDepthBase;
/** Base coordinate for the input responsive pixel mask in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputResponsiveMaskBase;
/** Reserved parameter. */
public XeSS.xess_coord_t reserved0;
/** Base coordinate for the output color. Default is (0,0). */
public XeSS.xess_coord_t outputColorBase;
};
/// <summary>
/// XeSS rendering event param for native plugin
/// </summary>
public struct xess_event_params_t
{
public IntPtr hContext;
public XeSS.xess_result_t result;
public IntPtr pParams;
};
/// <summary>
/// A logging callback provided by the application.
/// </summary>
/// <param name="message">message</param>
/// <param name="loggingLevel">login level</param>
public delegate void xess_app_log_callback_t(string message, xess_logging_level_t loggingLevel);
/// <summary>
/// Gets the X<sup>e</sup>SS version. This is baked into the X<sup>e</sup>SS SDK release.
/// </summary>
/// <param name="pVersion">Returned X<sup>e</sup>SS version.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessGetVersion(out xess_version_t pVersion)
{
IntPtr pVersion_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_version_t)));
if (pVersion_internal != IntPtr.Zero)
{
xess_result_t ret;
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11)
ret = LibXeSSD3D11Wrapper.xessGetVersion(pVersion_internal);
else
ret = LibXeSSWrapper.xessGetVersion(pVersion_internal);
pVersion = (xess_version_t)Marshal.PtrToStructure(pVersion_internal, typeof(xess_version_t));
Marshal.FreeHGlobal(pVersion_internal);
return ret;
}
pVersion.major = pVersion.minor = pVersion.patch = pVersion.reserved = 0;
return xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
}
/// <summary>
/// Check if the XeSS unity native plugin loaded.
/// </summary>
/// <returns>Is the plugin loaded</returns>
public static bool xessPluginLoaded()
{
return LibXeSSUnityPluginWrapper.UnityPluginLoaded();
}
/// <summary>
/// Gets the version of the loaded Intel XeFX library. When running on Intel platforms ,
/// this function will return the version of the loaded Intel XeFX library, for other
/// platforms 0.0.0 will be returned.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pVersion">Returned Intel XeFX library version.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessGetIntelXeFXVersion(xess_context_handle_t hContext, out xess_version_t pVersion)
{
IntPtr pVersion_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_version_t)));
if (pVersion_internal != IntPtr.Zero)
{
xess_result_t ret = hContext.processer.GetIntelXeFXVersion(hContext.context, pVersion_internal);
pVersion = (xess_version_t)Marshal.PtrToStructure(pVersion_internal, typeof(xess_version_t));
Marshal.FreeHGlobal(pVersion_internal);
return ret;
}
pVersion.major = pVersion.minor = pVersion.patch = pVersion.reserved = 0;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Gets X<sup>e</sup>SS internal resources properties.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pOutputResolution">Output resolution to calculate properties for.</param>
/// <param name="pBindingProperties">Returned properties.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessGetProperties(xess_context_handle_t hContext, xess_2d_t pOutputResolution, out xess_properties_t pBindingProperties)
{
IntPtr pBindingProperties_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_properties_t)));
IntPtr pOutputResolution_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
if (pBindingProperties_internal != IntPtr.Zero && pOutputResolution_internal != IntPtr.Zero)
{
Marshal.StructureToPtr(pOutputResolution, pOutputResolution_internal, false);
xess_result_t ret = hContext.processer.GetProperties(hContext.context, pOutputResolution_internal, pBindingProperties_internal);
pBindingProperties = (xess_properties_t)Marshal.PtrToStructure(pBindingProperties_internal, typeof(xess_properties_t));
Marshal.FreeHGlobal(pBindingProperties_internal);
Marshal.FreeHGlobal(pOutputResolution_internal);
return ret;
}
pBindingProperties.requiredDescriptorCount = 0;
pBindingProperties.tempBufferHeapSize = 0;
pBindingProperties.tempTextureHeapSize = 0;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Get the input resolution for a specified output resolution for a given quality setting.
/// X<sup> e</sup>SS expects all the input buffers except motion vectors to be in the returned resolution.
/// Motion vectors can be either in output resolution (XESS_INIT_FLAG_HIGH_RES_MV) or
/// returned resolution (default).
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pOutputResolution">Output resolution to calculate input resolution for.</param>
/// <param name="qualitySettings">Desired quality setting.</param>
/// <param name="pInputResolution">Required input resolution.</param>
/// <returns></returns>
public static xess_result_t xessGetInputResolution(xess_context_handle_t hContext, xess_2d_t pOutputResolution, xess_quality_settings_t qualitySettings, out xess_2d_t pInputResolution)
{
IntPtr pInputResolution_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
IntPtr pOutputResolution_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
if (pInputResolution_internal != IntPtr.Zero && pOutputResolution_internal != IntPtr.Zero)
{
Marshal.StructureToPtr(pOutputResolution, pOutputResolution_internal, false);
xess_result_t ret = hContext.processer.GetInputResolution(hContext.context, pOutputResolution_internal, qualitySettings, pInputResolution_internal); ;
pInputResolution = (xess_2d_t)Marshal.PtrToStructure(pInputResolution_internal, typeof(xess_2d_t));
Marshal.FreeHGlobal(pInputResolution_internal);
Marshal.FreeHGlobal(pOutputResolution_internal);
return ret;
}
pInputResolution.x = pInputResolution.y = 0;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Get the optimal input resolution and possible range for a specified output resolution for a given quality setting.
/// X<sup> e</sup>SS expects all the input buffers except motion vectors to be in the returned resolution range
/// and all input buffers to be in the same resolution.
/// Motion vectors can be either in output resolution (XESS_INIT_FLAG_HIGH_RES_MV) or
/// in the same resolution as other input buffers (by default).
/// @note Aspect ratio of the input resolution must be the same as for the output resoulution.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pOutputResolution">Output resolution to calculate input resolution for.</param>
/// <param name="qualitySettings">Desired quality setting.</param>
/// <param name="pInputResolutionOptimal">Optimal input resolution.</param>
/// <param name="pInputResolutionMin">Required minimal input resolution.</param>
/// <param name="pInputResolutionMax">Required maximal input resolution.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static XeSS.xess_result_t xessGetOptimalInputResolution(xess_context_handle_t hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, out xess_2d_t pInputResolutionOptimal, out xess_2d_t pInputResolutionMin, out xess_2d_t pInputResolutionMax)
{
IntPtr pInputResolutionOptional_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
IntPtr pInputResolutionMin_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
IntPtr pInputResolutionMax_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
IntPtr pOutputResolution_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_2d_t)));
if (pInputResolutionOptional_internal != IntPtr.Zero && pOutputResolution_internal != IntPtr.Zero &&
pInputResolutionMin_internal != IntPtr.Zero && pInputResolutionMax_internal != IntPtr.Zero)
{
Marshal.StructureToPtr(pOutputResolution, pOutputResolution_internal, false);
xess_result_t ret = hContext.processer.GetOptimalInputResolution(hContext.context, pOutputResolution_internal, qualitySettings, pInputResolutionOptional_internal, pInputResolutionMin_internal, pInputResolutionMax_internal); ;
pInputResolutionOptimal = (xess_2d_t)Marshal.PtrToStructure(pInputResolutionOptional_internal, typeof(xess_2d_t));
pInputResolutionMin = (xess_2d_t)Marshal.PtrToStructure(pInputResolutionMin_internal, typeof(xess_2d_t));
pInputResolutionMax = (xess_2d_t)Marshal.PtrToStructure(pInputResolutionMax_internal, typeof(xess_2d_t));
Marshal.FreeHGlobal(pInputResolutionOptional_internal);
Marshal.FreeHGlobal(pInputResolutionMin_internal);
Marshal.FreeHGlobal(pInputResolutionMax_internal);
Marshal.FreeHGlobal(pOutputResolution_internal);
return ret;
}
pInputResolutionOptimal.x = pInputResolutionOptimal.y = 0;
pInputResolutionMin.x = pInputResolutionMin.y = 0;
pInputResolutionMax.x = pInputResolutionMax.y = 0;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Gets jitter scale value.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pX">Jitter scale pointer for the X axis.</param>
/// <param name="pY">Jitter scale pointer for the Y axis.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessGetJitterScale(xess_context_handle_t hContext, out float pX, out float pY)
{
IntPtr pX_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)));
IntPtr pY_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)));
if (pX_internal != IntPtr.Zero && pY_internal != IntPtr.Zero)
{
xess_result_t ret = hContext.processer.GetJitterScale(hContext.context, pX_internal, pY_internal);
pX = (float)Marshal.PtrToStructure(pX_internal, typeof(float));
pY = (float)Marshal.PtrToStructure(pY_internal, typeof(float));
Marshal.FreeHGlobal(pX_internal);
Marshal.FreeHGlobal(pY_internal);
return ret;
}
pX = pY = 1.0f;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Gets velocity scale value.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pX">Velocity scale pointer for the X axis.</param>
/// <param name="pY">Velocity scale pointer for the Y axis.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessGetVelocityScale(xess_context_handle_t hContext, out float pX, out float pY)
{
IntPtr pX_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)));
IntPtr pY_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)));
if (pX_internal != IntPtr.Zero && pY_internal != IntPtr.Zero)
{
xess_result_t ret = hContext.processer.GetVelocityScale(hContext.context, pX_internal, pY_internal);
pX = (float)Marshal.PtrToStructure(pX_internal, typeof(float));
pY = (float)Marshal.PtrToStructure(pY_internal, typeof(float));
Marshal.FreeHGlobal(pX_internal);
Marshal.FreeHGlobal(pY_internal);
return ret;
}
pX = pY = 1.0f;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Initiates pipeline build process
/// This function can only be called between xessCreateContext and
/// xessInit
/// </summary>
/// <param name="hContext"></param>
/// <param name="blocking"></param>
/// <param name="initFlags"></param>
/// <returns></returns>
public static xess_result_t xessBuildPipelines(xess_context_handle_t hContext, bool blocking, UInt32 initFlags)
{
return LibXeSSUnityPluginWrapper.RenderingPlugin_xessBuildPipelines(hContext.context, blocking, initFlags);
}
/// <summary>
/// Create an X<sup>e</sup>SS context.
/// </summary>
/// <param name="hContext">Returned xess context handle.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessCreateContext(ref xess_context_handle_t hContext)
{
hContext.InitEventParams();
IntPtr context_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
if (context_internal != IntPtr.Zero)
{
xess_result_t ret = LibXeSSUnityPluginWrapper.RenderingPlugin_xessCreateContext(context_internal);
hContext.context = (IntPtr)Marshal.PtrToStructure(context_internal, typeof(IntPtr));
Marshal.FreeHGlobal(context_internal);
return ret;
}
hContext.context = IntPtr.Zero;
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Destroys the X<sup>e</sup>SS context.
/// May happen in main thread or rendering thread.
/// This function makes sure the pending command list has completed
/// Note:
/// If it is called in main thread, please make sure no pending command list is recorded in rendering thread by yourself
/// Normally we use the function in main thread just for checking if the XeSS feature is supported.
/// </summary>
/// <param name="hContext">The X<sup>e</sup> SS context handle.</param>
/// <param name="callInRenderingThread">If the XeSS function happens in rendering thread.</param>
/// <param name="commandBuffer">Unity command buffer.</param>
/// <returns>X<sup>e</sup> SS return status code</returns>
public static xess_result_t xessDestroyContext(xess_context_handle_t hContext, bool callInRenderingThread = false, CommandBuffer commandBuffer = null)
{
hContext.FreeEventParams();
if (!callInRenderingThread)
{
return LibXeSSUnityPluginWrapper.RenderingPlugin_xessDestroyContext(hContext.context);
}
else if (commandBuffer != null)
{
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSDestroyContextEvent(), 1, hContext.context);
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_INVALID_ARGUMENT;
}
/// <summary>
/// Sets jitter scale value
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="x">scale for the X axis</param>
/// <param name="y">scale for the Y axis</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessSetJitterScale(xess_context_handle_t hContext, float x, float y)
{
return hContext.processer.SetJitterScale(hContext.context, x, y);
}
/// <summary>
/// Sets velocity scale value
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="x">scale for the X axis</param>
/// <param name="y">scale for the Y axis</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessSetVelocityScale(xess_context_handle_t hContext, float x, float y)
{
return hContext.processer.SetVelocityScale(hContext.context, x, y);
}
/// <summary>
/// Sets logging callback
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="loggingLevel">Minimum logging level for logging callback.</param>
/// <param name="loggingCallback">Logging callback</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static xess_result_t xessSetLoggingCallback(xess_context_handle_t hContext, xess_logging_level_t loggingLevel, xess_app_log_callback_t loggingCallback)
{
IntPtr loggingCallback_internal = Marshal.GetFunctionPointerForDelegate(loggingCallback);
if (loggingCallback_internal != null)
{
return hContext.processer.SetLoggingCallback(hContext.context, loggingLevel, loggingCallback_internal);
}
return xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
/// <summary>
/// Indicates if the installed driver supports best X<sup>e</sup>SS experience.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <returns>xessIsOptimalDriver returns XESS_RESULT_SUCCESS, or XESS_RESULT_WARNING_OLD_DRIVER
/// if installed driver may result in degraded performance or visual quality.
/// xessD3D12CreateContext(..) will return XESS_RESULT_ERROR_UNSUPPORTED_DRIVER if driver does
/// not support X<sup> e</sup>SS at all.</returns>
public static xess_result_t xessIsOptimalDriver(xess_context_handle_t hContext)
{
return hContext.processer.IsOptimalDriver(hContext.context);
}
/// <summary>
/// Check if the context is a valid context.
/// </summary>
/// <param name="hContext"></param>
/// <returns>If the context is a valid context. Context may be remodestroied in plugin by device removed.</returns>
public static bool xessIsValid(xess_context_handle_t hContext)
{
return LibXeSSUnityPluginWrapper.RenderingPlugin_xessIsValid(hContext.context);
}
/// <summary>
/// Get X<sup>e</sup>SS initialization parameters.
/// This function will return @ref XESS_RESULT_ERROR_UNINITIALIZED if @ref xessD3D12Init has not been called.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="pInitParams">Returned initialization parameters.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static XeSS.xess_result_t xessGetInitParams(XeSS.xess_context_handle_t hContext, out XeSS.xess_init_params_t pInitParams)
{
return hContext.processer.GetInitParams(hContext, out pInitParams);
}
/// <summary>
/// Initialize X<sup>e</sup>SS.
/// Add initialization event to rendering thread.
/// In rendering thread:
/// This is a blocking call that initializes X<sup>e</sup>SS and triggers internal
/// resources allocation and JIT for the X<sup>e</sup> SS kernels.The user must ensure that
/// any pending command lists are completed before re-initialization.When
/// During initialization, X<sup> e</sup>SS can create staging buffers and copy queues to
/// upload internal data.These will be destroyed at the end of initialization.
/// @note X<sup> e</sup>SS supports devices starting from D3D12_RESOURCE_HEAP_TIER_1, which means
/// that buffers and textures can not live in the same resource heap.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="commandBuffer">Unity command buffer.</param>
/// <param name="pInitParams">Initialization parameters.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static XeSS.xess_result_t xessInitialize(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_init_params_t pInitParams)
{
return hContext.processer.Initialize(hContext, commandBuffer, pInitParams);
}
/// <summary>
/// Record X<sup>e</sup>SS upscaling commands into the command list.
/// Add execution event to rendering thread.
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="commandBuffer">Unity command buffer.</param>
/// <param name="pExecParams">Execution parameters.</param>
/// <returns></returns>
public static XeSS.xess_result_t xessExecute(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_execute_params_t pExecParams)
{
return hContext.processer.Execute(hContext, commandBuffer, pExecParams);
}
public static class Utility
{
static bool usingFixedJitterPhaseCount = true;
const int fixedJitterPhaseCount = 64;
public static void SetUseFixedJitterPhaseCount(bool isUsingFixedJitterPhaseCount)
{
usingFixedJitterPhaseCount = isUsingFixedJitterPhaseCount;
}
public static float GetMipmapBiasOffset(uint renderWidth, uint displayWidth)
{
return Mathf.Log((float)renderWidth / displayWidth, 2.0f);
}
public static int GetJitterPhaseCount(uint renderWidth, uint displayWidth)
{
if (!usingFixedJitterPhaseCount)
{
const float basePhaseCount = 8.0f;
int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f));
return jitterPhaseCount;
}
return fixedJitterPhaseCount;
}
public static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount)
{
outX = Halton((index % phaseCount) + 1, 2) - 0.5f;
outY = Halton((index % phaseCount) + 1, 3) - 0.5f;
}
// Calculate halton number for index and base.
private static float Halton(int index, int @base)
{
float f = 1.0f, result = 0.0f;
for (int currentIndex = index; currentIndex > 0;)
{
f /= @base;
result += f * (currentIndex % @base);
currentIndex = (int)Mathf.Floor((float)currentIndex / @base);
}
return result;
}
}
}
}

View File

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

View File

@ -0,0 +1,242 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using System.Runtime.InteropServices;
namespace Intel
{
public static class XeSSD3D11
{
internal class Processer_D3D11 : XeSS.Processer
{
internal override XeSS.xess_result_t GetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion)
{
return LibXeSSD3D11Wrapper.xessGetIntelXeFXVersion(hContext, pVersion);
}
internal override XeSS.xess_result_t GetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties)
{
return LibXeSSD3D11Wrapper.xessGetProperties(hContext, pOutputResolution, pBindingProperties);
}
internal override XeSS.xess_result_t GetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution)
{
return LibXeSSD3D11Wrapper.xessGetInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolution);
}
internal override XeSS.xess_result_t GetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax)
{
return LibXeSSD3D11Wrapper.xessGetOptimalInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolutionOptimal, pInputResolutionMin, pInputResolutionMax);
}
internal override XeSS.xess_result_t GetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSD3D11Wrapper.xessGetJitterScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t GetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSD3D11Wrapper.xessGetVelocityScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t SetJitterScale(IntPtr hContext, float x, float y)
{
return LibXeSSD3D11Wrapper.xessSetJitterScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetVelocityScale(IntPtr hContext, float x, float y)
{
return LibXeSSD3D11Wrapper.xessSetVelocityScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback)
{
return LibXeSSD3D11Wrapper.xessSetLoggingCallback(hContext, loggingLevel, loggingCallback);
}
internal override XeSS.xess_result_t IsOptimalDriver(IntPtr hContext)
{
return LibXeSSD3D11Wrapper.xessIsOptimalDriver(hContext);
}
internal override XeSS.xess_result_t GetInitParams(XeSS.xess_context_handle_t hContext, out XeSS.xess_init_params_t pInitParams)
{
IntPtr pInitParams_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (pInitParams_internal != IntPtr.Zero)
{
XeSS.xess_result_t ret = LibXeSSUnityPluginWrapper.RenderingPlugin_xessGetInitParams(hContext.context, pInitParams_internal);
xess_native_init_params_t pInitParams_native = (xess_native_init_params_t)Marshal.PtrToStructure(pInitParams_internal, typeof(xess_native_init_params_t));
pInitParams = new XeSS.xess_init_params_t();
pInitParams_native.to_xess_init_params_t(pInitParams);
Marshal.FreeHGlobal(pInitParams_internal);
return ret;
}
pInitParams = new XeSS.xess_init_params_t();
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
internal override XeSS.xess_result_t Initialize(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_init_params_t pInitParams)
{
if (commandBuffer != null)
{
hContext.AllocEventParam(0, Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (hContext.pEventParams_internal[0] != IntPtr.Zero && hContext.pNativeParams_internal[0] != IntPtr.Zero)
{
// construct init params
xess_native_init_params_t pNativeInitParams = new xess_native_init_params_t(pInitParams);
Marshal.StructureToPtr(pNativeInitParams, hContext.pNativeParams_internal[0], false);
// construct init event params
XeSS.xess_event_params_t pInitEventParams = new XeSS.xess_event_params_t();
pInitEventParams.pParams = hContext.pNativeParams_internal[0];
pInitEventParams.hContext = hContext.context;
pInitEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pInitEventParams, hContext.pEventParams_internal[0], false);
// xess init
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSInitializeEvent(), 1, hContext.pEventParams_internal[0]);
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_INVALID_ARGUMENT;
}
internal override XeSS.xess_result_t Execute(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_execute_params_t pExecParams)
{
hContext.AllocEventParam(1, Marshal.SizeOf(typeof(xess_native_execute_params_t)));
if (hContext.pEventParams_internal[1] != IntPtr.Zero && hContext.pNativeParams_internal[1] != IntPtr.Zero)
{
// construct exec params
xess_native_execute_params_t pNativeExecParams = new xess_native_execute_params_t(pExecParams);
Marshal.StructureToPtr(pNativeExecParams, hContext.pNativeParams_internal[1], false);
// construct event params
XeSS.xess_event_params_t pExecEventParams = new XeSS.xess_event_params_t();
pExecEventParams.pParams = hContext.pNativeParams_internal[1];
pExecEventParams.hContext = hContext.context;
pExecEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pExecEventParams, hContext.pEventParams_internal[1], false);
// xess execute
if (XeSS.XeSSSampler != null)
{
commandBuffer.BeginSample(XeSS.XeSSSampler);
}
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSExecuteEventFunc(), 1, hContext.pEventParams_internal[1]);
if (XeSS.XeSSSampler != null)
{
commandBuffer.EndSample(XeSS.XeSSSampler);
}
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
}
internal struct xess_native_execute_params_t
{
public xess_native_execute_params_t(XeSS.xess_execute_params_t pExecParams)
{
colorTexture = pExecParams.colorTexture.GetNativeTexturePtr();
velocityTexture = pExecParams.velocityTexture.GetNativeTexturePtr();
depthTexture = pExecParams.depthTexture.GetNativeTexturePtr();
exposureScaleTexture = pExecParams.exposureScaleTexture != null ? pExecParams.exposureScaleTexture.GetNativeTexturePtr() : IntPtr.Zero;
responsivePixelMaskTexture = pExecParams.responsivePixelMaskTexture != null ? pExecParams.responsivePixelMaskTexture.GetNativeTexturePtr() : IntPtr.Zero;
outputTexture = pExecParams.outputTexture.GetNativeTexturePtr();
jitterOffsetX = pExecParams.jitterOffsetX;
jitterOffsetY = pExecParams.jitterOffsetY;
exposureScale = pExecParams.exposureScale;
resetHistory = pExecParams.resetHistory;
inputWidth = pExecParams.inputWidth;
inputHeight = pExecParams.inputHeight;
inputColorBase = pExecParams.inputColorBase;
inputMotionVectorBase = pExecParams.inputMotionVectorBase;
inputDepthBase = pExecParams.inputDepthBase;
inputResponsiveMaskBase = pExecParams.inputResponsiveMaskBase;
reserved0 = pExecParams.reserved0;
outputColorBase = pExecParams.outputColorBase;
}
/** Input color texture.*/
public IntPtr colorTexture;
/** Input motion vector texture.*/
public IntPtr velocityTexture;
/** Optional depth texture. Required if XESS_INIT_FLAG_HIGH_RES_MV has not been specified.*/
public IntPtr depthTexture;
/** Optional 1x1 exposure scale texture. Required if XESS_INIT_FLAG_EXPOSURE_TEXTURE has been
* specified.*/
public IntPtr exposureScaleTexture;
/** Optional responsive pixel mask texture. Required if XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK
* has been specified.*/
public IntPtr responsivePixelMaskTexture;
/** Output texture in target resolution.*/
public IntPtr outputTexture;
/** Jitter X coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetX;
/** Jitter Y coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetY;
/** Optional input color scaling. Default is 1. */
public float exposureScale;
/** Resets the history accumulation in this frame. */
public UInt32 resetHistory;
/** Input color width. */
public UInt32 inputWidth;
/** Input color height. */
public UInt32 inputHeight;
/** Base coordinate for the input color in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputColorBase;
/** Base coordinate for the input motion vector in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputMotionVectorBase;
/** Base coordinate for the input depth in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputDepthBase;
/** Base coordinate for the input responsive pixel mask in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputResponsiveMaskBase;
/** Reserved parameter. */
public XeSS.xess_coord_t reserved0;
/** Base coordinate for the output color. Default is (0,0). */
public XeSS.xess_coord_t outputColorBase;
};
internal struct xess_native_init_params_t
{
public xess_native_init_params_t(XeSS.xess_init_params_t pInitParams)
{
outputResolution = pInitParams.outputResolution;
qualitySetting = pInitParams.qualitySetting;
initFlags = pInitParams.initFlags;
}
public void to_xess_init_params_t(XeSS.xess_init_params_t pInitParams)
{
pInitParams.outputResolution = outputResolution;
pInitParams.qualitySetting = qualitySetting;
pInitParams.initFlags = initFlags;
}
/** Output width and height. */
public XeSS.xess_2d_t outputResolution;
/** Quality setting */
public XeSS.xess_quality_settings_t qualitySetting;
/** Initialization flags. */
public UInt32 initFlags;
}
}
}

View File

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

View File

@ -0,0 +1,279 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using System.Runtime.InteropServices;
namespace Intel
{
public static class XeSSD3D12
{
internal class Processer_D3D12 : XeSS.Processer
{
internal override XeSS.xess_result_t GetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion)
{
return LibXeSSWrapper.xessGetIntelXeFXVersion(hContext, pVersion);
}
internal override XeSS.xess_result_t GetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties)
{
return LibXeSSWrapper.xessGetProperties(hContext, pOutputResolution, pBindingProperties);
}
internal override XeSS.xess_result_t GetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution)
{
return LibXeSSWrapper.xessGetInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolution);
}
internal override XeSS.xess_result_t GetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax)
{
return LibXeSSWrapper.xessGetOptimalInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolutionOptimal, pInputResolutionMin, pInputResolutionMax);
}
internal override XeSS.xess_result_t GetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSWrapper.xessGetJitterScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t GetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSWrapper.xessGetVelocityScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t SetJitterScale(IntPtr hContext, float x, float y)
{
return LibXeSSWrapper.xessSetJitterScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetVelocityScale(IntPtr hContext, float x, float y)
{
return LibXeSSWrapper.xessSetVelocityScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback)
{
return LibXeSSWrapper.xessSetLoggingCallback(hContext, loggingLevel, loggingCallback);
}
internal override XeSS.xess_result_t IsOptimalDriver(IntPtr hContext)
{
return LibXeSSWrapper.xessIsOptimalDriver(hContext);
}
internal override XeSS.xess_result_t GetInitParams(XeSS.xess_context_handle_t hContext, out XeSS.xess_init_params_t pInitParams)
{
IntPtr pInitParams_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (pInitParams_internal != IntPtr.Zero)
{
XeSS.xess_result_t ret = LibXeSSUnityPluginWrapper.RenderingPlugin_xessGetInitParams(hContext.context, pInitParams_internal);
xess_native_init_params_t pInitParams_native = (xess_native_init_params_t)Marshal.PtrToStructure(pInitParams_internal, typeof(xess_native_init_params_t));
pInitParams = new XeSS.xess_init_params_t();
pInitParams_native.to_xess_init_params_t(pInitParams);
Marshal.FreeHGlobal(pInitParams_internal);
return ret;
}
pInitParams = new XeSS.xess_init_params_t();
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
internal override XeSS.xess_result_t Initialize(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_init_params_t pInitParams)
{
if (commandBuffer != null)
{
hContext.AllocEventParam(0, Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (hContext.pEventParams_internal[0] != IntPtr.Zero && hContext.pNativeParams_internal[0] != IntPtr.Zero)
{
// construct init params
xess_native_init_params_t pNativeInitParams = new xess_native_init_params_t(pInitParams);
Marshal.StructureToPtr(pNativeInitParams, hContext.pNativeParams_internal[0], false);
// construct init event params
XeSS.xess_event_params_t pInitEventParams = new XeSS.xess_event_params_t();
pInitEventParams.pParams = hContext.pNativeParams_internal[0];
pInitEventParams.hContext = hContext.context;
pInitEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pInitEventParams, hContext.pEventParams_internal[0], false);
// xess init
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSInitializeEvent(), 1, hContext.pEventParams_internal[0]);
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_INVALID_ARGUMENT;
}
internal override XeSS.xess_result_t Execute(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_execute_params_t pExecParams)
{
hContext.AllocEventParam(1, Marshal.SizeOf(typeof(xess_native_execute_params_t)));
if (hContext.pEventParams_internal[1] != IntPtr.Zero && hContext.pNativeParams_internal[1] != IntPtr.Zero)
{
// construct exec params
xess_native_execute_params_t pNativeExecParams = new xess_native_execute_params_t(pExecParams);
Marshal.StructureToPtr(pNativeExecParams, hContext.pNativeParams_internal[1], false);
// construct event params
XeSS.xess_event_params_t pExecEventParams = new XeSS.xess_event_params_t();
pExecEventParams.pParams = hContext.pNativeParams_internal[1];
pExecEventParams.hContext = hContext.context;
pExecEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pExecEventParams, hContext.pEventParams_internal[1], false);
// xess execute
if (XeSS.XeSSSampler != null)
{
commandBuffer.BeginSample(XeSS.XeSSSampler);
}
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSExecuteEventFunc(), 1, hContext.pEventParams_internal[1]);
if (XeSS.XeSSSampler != null)
{
commandBuffer.EndSample(XeSS.XeSSSampler);
}
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
}
internal struct xess_native_execute_params_t
{
public xess_native_execute_params_t(XeSS.xess_execute_params_t pExecParams)
{
pColorTexture = pExecParams.colorTexture.GetNativeTexturePtr();
pVelocityTexture = pExecParams.velocityTexture.GetNativeTexturePtr();
pDepthTexture = pExecParams.depthTexture.GetNativeTexturePtr();
pExposureScaleTexture = pExecParams.exposureScaleTexture != null ? pExecParams.exposureScaleTexture.GetNativeTexturePtr() : IntPtr.Zero;
pResponsivePixelMaskTexture = pExecParams.responsivePixelMaskTexture != null ? pExecParams.responsivePixelMaskTexture.GetNativeTexturePtr() : IntPtr.Zero;
pOutputTexture = pExecParams.outputTexture.GetNativeTexturePtr();
jitterOffsetX = pExecParams.jitterOffsetX;
jitterOffsetY = pExecParams.jitterOffsetY;
exposureScale = pExecParams.exposureScale;
resetHistory = pExecParams.resetHistory;
inputWidth = pExecParams.inputWidth;
inputHeight = pExecParams.inputHeight;
inputColorBase = pExecParams.inputColorBase;
inputMotionVectorBase = pExecParams.inputMotionVectorBase;
inputDepthBase = pExecParams.inputDepthBase;
inputResponsiveMaskBase = pExecParams.inputResponsiveMaskBase;
reserved0 = pExecParams.reserved0;
outputColorBase = pExecParams.outputColorBase;
pDescriptorHeap = IntPtr.Zero;
descriptorHeapOffset = descriptorHeapOffset = 0;
}
/** Input color texture. Must be in NON_PIXEL_SHADER_RESOURCE state.*/
public IntPtr pColorTexture;
/** Input motion vector texture. Must be in NON_PIXEL_SHADER_RESOURCE state.*/
public IntPtr pVelocityTexture;
/** Optional depth texture. Required if XESS_INIT_FLAG_HIGH_RES_MV has not been specified.
* Must be in NON_PIXEL_SHADER_RESOURCE state.*/
public IntPtr pDepthTexture;
/** Optional 1x1 exposure scale texture. Required if XESS_INIT_FLAG_EXPOSURE_TEXTURE has been
* specified. Must be in NON_PIXEL_SHADER_RESOURCE state */
public IntPtr pExposureScaleTexture;
/** Optional responsive pixel mask texture. Required if XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK
* has been specified. Must be in NON_PIXEL_SHADER_RESOURCE state */
public IntPtr pResponsivePixelMaskTexture;
/** Output texture in target resolution. Must be in UNORDERED_ACCESS state.*/
public IntPtr pOutputTexture;
/** Jitter X coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetX;
/** Jitter Y coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetY;
/** Optional input color scaling. Default is 1. */
public float exposureScale;
/** Resets the history accumulation in this frame. */
public UInt32 resetHistory;
/** Input color width. */
public UInt32 inputWidth;
/** Input color height. */
public UInt32 inputHeight;
/** Base coordinate for the input color in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputColorBase;
/** Base coordinate for the input motion vector in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputMotionVectorBase;
/** Base coordinate for the input depth in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputDepthBase;
/** Base coordinate for the input responsive pixel mask in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputResponsiveMaskBase;
/** Reserved parameter. */
public XeSS.xess_coord_t reserved0;
/** Base coordinate for the output color. Default is (0,0). */
public XeSS.xess_coord_t outputColorBase;
/** Optional external descriptor heap. */
IntPtr pDescriptorHeap;
/** Offset in external descriptor heap in bytes.*/
UInt32 descriptorHeapOffset;
};
internal struct xess_native_init_params_t
{
public xess_native_init_params_t(XeSS.xess_init_params_t pInitParams)
{
outputResolution = pInitParams.outputResolution;
qualitySetting = pInitParams.qualitySetting;
initFlags = pInitParams.initFlags;
creationNodeMask = pInitParams.creationNodeMask;
visibleNodeMask = pInitParams.visibleNodeMask;
pTempBufferHeap = IntPtr.Zero;
bufferHeapOffset = bufferHeapOffset = 0;
pTempTextureHeap = IntPtr.Zero;
textureHeapOffset = textureHeapOffset = 0;
pPipelineLibrary = IntPtr.Zero;
}
public void to_xess_init_params_t(XeSS.xess_init_params_t pInitParams)
{
pInitParams.outputResolution = outputResolution;
pInitParams.qualitySetting = qualitySetting;
pInitParams.initFlags = initFlags;
pInitParams.creationNodeMask = creationNodeMask;
pInitParams.visibleNodeMask = visibleNodeMask;
}
/** Output width and height. */
public XeSS.xess_2d_t outputResolution;
/** Quality setting */
public XeSS.xess_quality_settings_t qualitySetting;
/** Initialization flags. */
public UInt32 initFlags;
/** Specifies the node mask for internally created resources on
* multi-adapter systems. */
public UInt32 creationNodeMask;
/** Specifies the node visibility mask for internally created resources
* on multi-adapter systems. */
public UInt32 visibleNodeMask;
/** Optional externally allocated buffer storage for X<sup>e</sup>SS. If NULL the
* storage is allocated internally. If allocated, the heap type must be
* D3D12_HEAP_TYPE_DEFAULT. This heap is not accessed by the CPU. */
IntPtr pTempBufferHeap;
/** Offset in the externally allocated heap for temporary buffer storage. */
UInt64 bufferHeapOffset;
/** Optional externally allocated texture storage for X<sup>e</sup>SS. If NULL the
* storage is allocated internally. If allocated, the heap type must be
* D3D12_HEAP_TYPE_DEFAULT. This heap is not accessed by the CPU. */
IntPtr pTempTextureHeap;
/** Offset in the externally allocated heap for temporary texture storage. */
UInt64 textureHeapOffset;
/** Pointer to pipeline library. If not NULL will be used for pipeline caching. */
IntPtr pPipelineLibrary;
};
}
}

View File

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

View File

@ -0,0 +1,166 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Runtime.InteropServices;
using UnityEngine;
/// <summary>
/// Wrapper for Intel xess
/// </summary>
namespace Intel
{
internal static class LibXeSSDebugWrapper
{
[DllImport("libxess", EntryPoint = "xessSelectNetworkModel")]
public static extern XeSS.xess_result_t xessSelectNetworkModel(IntPtr hContext, XeSSDebug.xess_network_model_t network);
[DllImport("libxess", EntryPoint = "xessStartDump")]
public static extern XeSS.xess_result_t xessStartDump(IntPtr hContext, IntPtr dump_parameters);
}
public static class XeSSDebug
{
/// <summary>
/// X<sup>e</sup>SS network type.
/// </summary>
public enum xess_network_model_t
{
XESS_NETWORK_MODEL_KPSS = 0,
XESS_NETWORK_MODEL_SPLAT = 1,
};
/// <summary>
/// X<sup>e</sup>SS dump bits.
/// </summary>
public enum xess_dump_element_bits_t
{
XESS_DUMP_INPUT_COLOR = 0x01,
XESS_DUMP_INPUT_VELOCITY = 0x02,
XESS_DUMP_INPUT_DEPTH = 0x04,
XESS_DUMP_INPUT_EXPOSURE_SCALE = 0x08,
XESS_DUMP_INPUT_RESPONSIVE_PIXEL_MASK = 0x10,
XESS_DUMP_OUTPUT = 0x20,
XESS_DUMP_HISTORY = 0x40,
XESS_DUMP_EXECUTION_PARAMETERS = 0x80, ///< All parameters passed to xessExecute
XESS_DUMP_ALL_INPUTS = XESS_DUMP_INPUT_COLOR | XESS_DUMP_INPUT_VELOCITY |
XESS_DUMP_INPUT_DEPTH | XESS_DUMP_INPUT_EXPOSURE_SCALE |
XESS_DUMP_INPUT_RESPONSIVE_PIXEL_MASK | XESS_DUMP_EXECUTION_PARAMETERS,
XESS_DUMP_ALL = 0x7FFFFFFF,
};
/// <summary>
/// X<sup>e</sup>SS dump parameters
/// </summary>
public struct xess_dump_parameters_t
{
public string path;
/** Frame index. Will be used as start for frame sequence. */
public UInt32 frame_idx;
/** Frame count to dump. Few frames less may be dumped due to possible frames in flight in
* application
*/
public UInt32 frame_count;
/** Bitset showing set of elements that must be dumped. Element will be dumped if it exist
* and corrseponding bit is not 0.
* Since it's meaningless to call Dump with empty set value of 0 will mean DUMP_ALL_INPUTS
*/
public UInt32 dump_elements_mask;
/** In case of depth render target with TYPELESS format it is not always possible
* to interpret depth values during dumping process.
*/
}
internal struct xess_native_dump_parameters_t
{
public xess_native_dump_parameters_t(xess_dump_parameters_t dump_param)
{
path = IntPtr.Zero;
frame_idx = dump_param.frame_idx;
frame_count = dump_param.frame_count;
dump_elements_mask = dump_param.dump_elements_mask;
}
public IntPtr path;
/** Frame index. Will be used as start for frame sequence. */
public UInt32 frame_idx;
/** Frame count to dump. Few frames less may be dumped due to possible frames in flight in
* application
*/
public UInt32 frame_count;
/** Bitset showing set of elements that must be dumped. Element will be dumped if it exist
* and corrseponding bit is not 0.
* Since it's meaningless to call Dump with empty set value of 0 will mean DUMP_ALL_INPUTS
*/
public UInt32 dump_elements_mask;
/** In case of depth render target with TYPELESS format it is not always possible
* to interpret depth values during dumping process.
*/
}
/// <summary>
/// Select network to be used by X<sup>e</sup>SS
/// Selects network model to use by X<sup>e</sup>SS.
/// After call to this function - X<sup>e</sup>SS init function *must* be called
/// </summary>
/// <param name="hContext">The X<sup>e</sup>SS context handle.</param>
/// <param name="network">The network model.</param>
/// <returns>X<sup>e</sup>SS return status code.</returns>
public static XeSS.xess_result_t xessSelectNetworkModel(XeSS.xess_context_handle_t hContext, xess_network_model_t network)
{
return LibXeSSDebugWrapper.xessSelectNetworkModel(hContext.context, network);
}
/// <summary>
/// Dumps sequence of frames to the provided folder
/// Call to this function initiates a dump for selected elements.
/// X<sup> e</sup>SS SDK uses RAM cache to reduce dump overhead.Application should provide reasonable
/// value for @ref xess_dump_parameters_t::frame_count frames (about 50 megs needed per cached frame).
/// To enable several dumps per run application should provide correct
/// @ref xess_dump_parameters_t::frame_idx value.This value used as a start index for frame
/// dumping.
/// After call to this function - each call to @ref xessD3D12Execute will result in new frame dumped to
/// RAM cache.
/// After @ref xess_dump_parameters_t::frame_count frames application will be blocked on call to
/// @ref xessD3D12Execute in order to save cached frames to disk.This operation can take long time.
/// Repetetive calls to this function can result in XESS_RESULT_ERROR_OPERATION_IN_PROGRESS which means that
/// frame dump is in progress.
/// </summary>
/// <param name="hContext">X<sup>e</sup>SS context</param>
/// <param name="dump_parameters">dump configuration</param>
/// <returns>operation status</returns>
public static XeSS.xess_result_t xessStartDump(XeSS.xess_context_handle_t hContext, xess_dump_parameters_t dump_parameters)
{
xess_native_dump_parameters_t pDumpParams_native = new xess_native_dump_parameters_t(dump_parameters);
IntPtr pDumpParams_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_native_dump_parameters_t)));
if (pDumpParams_internal != IntPtr.Zero)
{
pDumpParams_native.path = Marshal.StringToHGlobalAnsi(dump_parameters.path);
Marshal.StructureToPtr(pDumpParams_native, pDumpParams_internal, false);
XeSS.xess_result_t ret = LibXeSSDebugWrapper.xessStartDump(hContext.context, pDumpParams_internal);
Marshal.FreeHGlobal(pDumpParams_native.path);
Marshal.FreeHGlobal(pDumpParams_internal);
return ret;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
}
}

View File

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

View File

@ -0,0 +1,271 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using System.Runtime.InteropServices;
namespace Intel
{
public static class XeSSVK
{
internal class Processer_VK : XeSS.Processer
{
internal override XeSS.xess_result_t GetIntelXeFXVersion(IntPtr hContext, IntPtr pVersion)
{
return LibXeSSWrapper.xessGetIntelXeFXVersion(hContext, pVersion);
}
internal override XeSS.xess_result_t GetProperties(IntPtr hContext, IntPtr pOutputResolution, IntPtr pBindingProperties)
{
return LibXeSSWrapper.xessGetProperties(hContext, pOutputResolution, pBindingProperties);
}
internal override XeSS.xess_result_t GetInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolution)
{
return LibXeSSWrapper.xessGetInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolution);
}
internal override XeSS.xess_result_t GetOptimalInputResolution(IntPtr hContext, IntPtr pOutputResolution, XeSS.xess_quality_settings_t qualitySettings, IntPtr pInputResolutionOptimal, IntPtr pInputResolutionMin, IntPtr pInputResolutionMax)
{
return LibXeSSWrapper.xessGetOptimalInputResolution(hContext, pOutputResolution, qualitySettings, pInputResolutionOptimal, pInputResolutionMin, pInputResolutionMax);
}
internal override XeSS.xess_result_t GetJitterScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSWrapper.xessGetJitterScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t GetVelocityScale(IntPtr hContext, IntPtr pX, IntPtr pY)
{
return LibXeSSWrapper.xessGetVelocityScale(hContext, pX, pY);
}
internal override XeSS.xess_result_t SetJitterScale(IntPtr hContext, float x, float y)
{
return LibXeSSWrapper.xessSetJitterScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetVelocityScale(IntPtr hContext, float x, float y)
{
return LibXeSSWrapper.xessSetVelocityScale(hContext, x, y);
}
internal override XeSS.xess_result_t SetLoggingCallback(IntPtr hContext, XeSS.xess_logging_level_t loggingLevel, IntPtr loggingCallback)
{
return LibXeSSWrapper.xessSetLoggingCallback(hContext, loggingLevel, loggingCallback);
}
internal override XeSS.xess_result_t IsOptimalDriver(IntPtr hContext)
{
return LibXeSSWrapper.xessIsOptimalDriver(hContext);
}
internal override XeSS.xess_result_t GetInitParams(XeSS.xess_context_handle_t hContext, out XeSS.xess_init_params_t pInitParams)
{
IntPtr pInitParams_internal = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (pInitParams_internal != IntPtr.Zero)
{
XeSS.xess_result_t ret = LibXeSSUnityPluginWrapper.RenderingPlugin_xessGetInitParams(hContext.context, pInitParams_internal);
xess_native_init_params_t pInitParams_native = (xess_native_init_params_t)Marshal.PtrToStructure(pInitParams_internal, typeof(xess_native_init_params_t));
pInitParams = new XeSS.xess_init_params_t();
pInitParams_native.to_xess_init_params_t(pInitParams);
Marshal.FreeHGlobal(pInitParams_internal);
return ret;
}
pInitParams = new XeSS.xess_init_params_t();
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
internal override XeSS.xess_result_t Initialize(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_init_params_t pInitParams)
{
if (commandBuffer != null)
{
hContext.AllocEventParam(0, Marshal.SizeOf(typeof(xess_native_init_params_t)));
if (hContext.pEventParams_internal[0] != IntPtr.Zero && hContext.pNativeParams_internal[0] != IntPtr.Zero)
{
// construct init params
xess_native_init_params_t pNativeInitParams = new xess_native_init_params_t(pInitParams);
Marshal.StructureToPtr(pNativeInitParams, hContext.pNativeParams_internal[0], false);
// construct init event params
XeSS.xess_event_params_t pInitEventParams = new XeSS.xess_event_params_t();
pInitEventParams.pParams = hContext.pNativeParams_internal[0];
pInitEventParams.hContext = hContext.context;
pInitEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pInitEventParams, hContext.pEventParams_internal[0], false);
// xess init
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSInitializeEvent(), 1, hContext.pEventParams_internal[0]);
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_INVALID_ARGUMENT;
}
internal override XeSS.xess_result_t Execute(XeSS.xess_context_handle_t hContext, CommandBuffer commandBuffer, XeSS.xess_execute_params_t pExecParams)
{
hContext.AllocEventParam(1, Marshal.SizeOf(typeof(xess_native_execute_params_t)));
if (hContext.pEventParams_internal[1] != IntPtr.Zero && hContext.pNativeParams_internal[1] != IntPtr.Zero)
{
// construct exec params
xess_native_execute_params_t pNativeExecParams = new xess_native_execute_params_t(pExecParams);
Marshal.StructureToPtr(pNativeExecParams, hContext.pNativeParams_internal[1], false);
// construct event params
XeSS.xess_event_params_t pExecEventParams = new XeSS.xess_event_params_t();
pExecEventParams.pParams = hContext.pNativeParams_internal[1];
pExecEventParams.hContext = hContext.context;
pExecEventParams.result = XeSS.xess_result_t.XESS_RESULT_ERROR_UNKNOWN;
Marshal.StructureToPtr(pExecEventParams, hContext.pEventParams_internal[1], false);
// xess execute
if (XeSS.XeSSSampler != null)
{
commandBuffer.BeginSample(XeSS.XeSSSampler);
}
commandBuffer.IssuePluginEventAndData(LibXeSSUnityPluginWrapper.RenderingPlugin_GetXeSSExecuteEventFunc(), 1, hContext.pEventParams_internal[1]);
if (XeSS.XeSSSampler != null)
{
commandBuffer.EndSample(XeSS.XeSSSampler);
}
return XeSS.xess_result_t.XESS_RESULT_SUCCESS;
}
return XeSS.xess_result_t.XESS_RESULT_ERROR_CSHARP_WRAPPER;
}
}
internal struct xess_native_execute_params_t
{
public xess_native_execute_params_t(XeSS.xess_execute_params_t pExecParams)
{
colorTexture = pExecParams.colorTexture.GetNativeTexturePtr();
velocityTexture = pExecParams.velocityTexture.GetNativeTexturePtr();
depthTexture = pExecParams.depthTexture.GetNativeTexturePtr();
exposureScaleTexture = pExecParams.exposureScaleTexture != null ? pExecParams.exposureScaleTexture.GetNativeTexturePtr() : IntPtr.Zero;
responsivePixelMaskTexture = pExecParams.responsivePixelMaskTexture != null ? pExecParams.responsivePixelMaskTexture.GetNativeTexturePtr() : IntPtr.Zero;
outputTexture = pExecParams.outputTexture.GetNativeTexturePtr();
jitterOffsetX = pExecParams.jitterOffsetX;
jitterOffsetY = pExecParams.jitterOffsetY;
exposureScale = pExecParams.exposureScale;
resetHistory = pExecParams.resetHistory;
inputWidth = pExecParams.inputWidth;
inputHeight = pExecParams.inputHeight;
inputColorBase = pExecParams.inputColorBase;
inputMotionVectorBase = pExecParams.inputMotionVectorBase;
inputDepthBase = pExecParams.inputDepthBase;
inputResponsiveMaskBase = pExecParams.inputResponsiveMaskBase;
reserved0 = pExecParams.reserved0;
outputColorBase = pExecParams.outputColorBase;
}
/** Input color texture. Must be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state.*/
public IntPtr colorTexture;
/** Input motion vector texture. Must be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state.*/
public IntPtr velocityTexture;
/** Optional depth texture. Required if XESS_INIT_FLAG_HIGH_RES_MV has not been specified.
* Must be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state.*/
public IntPtr depthTexture;
/** Optional 1x1 exposure scale texture. Required if XESS_INIT_FLAG_EXPOSURE_TEXTURE has been
* specified. Must be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state */
public IntPtr exposureScaleTexture;
/** Optional responsive pixel mask texture. Required if XESS_INIT_FLAG_RESPONSIVE_PIXEL_MASK
* has been specified. Must be in VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL state */
public IntPtr responsivePixelMaskTexture;
/** Output texture in target resolution. Must be in VK_IMAGE_LAYOUT_GENERAL state.*/
public IntPtr outputTexture;
/** Jitter X coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetX;
/** Jitter Y coordinate in the range [-0.5, 0.5]. */
public float jitterOffsetY;
/** Optional input color scaling. Default is 1. */
public float exposureScale;
/** Resets the history accumulation in this frame. */
public UInt32 resetHistory;
/** Input color width. */
public UInt32 inputWidth;
/** Input color height. */
public UInt32 inputHeight;
/** Base coordinate for the input color in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputColorBase;
/** Base coordinate for the input motion vector in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputMotionVectorBase;
/** Base coordinate for the input depth in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputDepthBase;
/** Base coordinate for the input responsive pixel mask in the texture. Default is (0,0). */
public XeSS.xess_coord_t inputResponsiveMaskBase;
/** Reserved parameter. */
public XeSS.xess_coord_t reserved0;
/** Base coordinate for the output color. Default is (0,0). */
public XeSS.xess_coord_t outputColorBase;
};
internal struct xess_native_init_params_t
{
public xess_native_init_params_t(XeSS.xess_init_params_t pInitParams)
{
outputResolution = pInitParams.outputResolution;
qualitySetting = pInitParams.qualitySetting;
initFlags = pInitParams.initFlags;
creationNodeMask = pInitParams.creationNodeMask;
visibleNodeMask = pInitParams.visibleNodeMask;
tempBufferHeap = IntPtr.Zero;
bufferHeapOffset = bufferHeapOffset = 0;
tempTextureHeap = IntPtr.Zero;
textureHeapOffset = textureHeapOffset = 0;
pipelineCache = IntPtr.Zero;
}
public void to_xess_init_params_t(XeSS.xess_init_params_t pInitParams)
{
pInitParams.outputResolution = outputResolution;
pInitParams.qualitySetting = qualitySetting;
pInitParams.initFlags = initFlags;
pInitParams.creationNodeMask = creationNodeMask;
pInitParams.visibleNodeMask = visibleNodeMask;
}
/** Output width and height. */
public XeSS.xess_2d_t outputResolution;
/** Quality setting */
public XeSS.xess_quality_settings_t qualitySetting;
/** Initialization flags. */
public UInt32 initFlags;
/** Specifies the node mask for internally created resources on
* multi-adapter systems. */
public UInt32 creationNodeMask;
/** Specifies the node visibility mask for internally created resources
* on multi-adapter systems. */
public UInt32 visibleNodeMask;
/** Optional externally allocated buffer storage for X<sup>e</sup>SS. If NULL the
* storage is allocated internally. If allocated, the heap type must be
* VK_HEAP_TYPE_DEFAULT. This heap is not accessed by the CPU. */
IntPtr tempBufferHeap;
/** Offset in the externally allocated heap for temporary buffer storage. */
UInt64 bufferHeapOffset;
/** Optional externally allocated texture storage for X<sup>e</sup>SS. If NULL the
* storage is allocated internally. If allocated, the heap type must be
* VK_HEAP_TYPE_DEFAULT. This heap is not accessed by the CPU. */
IntPtr tempTextureHeap;
/** Offset in the externally allocated heap for temporary texture storage. */
UInt64 textureHeapOffset;
/** Pointer to pipeline cache. If not NULL will be used for pipeline creation. */
IntPtr pipelineCache;
}
}
}

View File

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

View File

@ -8,7 +8,7 @@
"com.unity.mathematics": "1.2.1",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.cinemachine": {
"version": "2.10.1",
@ -17,28 +17,28 @@
"dependencies": {
"com.unity.test-framework": "1.1.31"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.collab-proxy": {
"version": "2.5.2",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.editorcoroutines": {
"version": "1.0.0",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.ide.rider": {
"version": "3.0.31",
@ -47,7 +47,7 @@
"dependencies": {
"com.unity.ext.nunit": "1.0.6"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.ide.visualstudio": {
"version": "2.0.22",
@ -56,14 +56,14 @@
"dependencies": {
"com.unity.test-framework": "1.1.9"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.ide.vscode": {
"version": "1.2.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.inputsystem": {
"version": "1.11.0",
@ -72,7 +72,7 @@
"dependencies": {
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.learn.iet-framework": {
"version": "3.1.3",
@ -82,14 +82,14 @@
"com.unity.editorcoroutines": "1.0.0",
"com.unity.settings-manager": "1.0.3"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.mathematics": {
"version": "1.2.6",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.memoryprofiler": {
"version": "1.1.1",
@ -98,7 +98,7 @@
"dependencies": {
"com.unity.editorcoroutines": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.recorder": {
"version": "4.0.3",
@ -107,7 +107,7 @@
"dependencies": {
"com.unity.timeline": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.render-pipelines.core": {
"version": "14.0.11",
@ -145,14 +145,14 @@
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.settings-manager": {
"version": "2.0.1",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.shadergraph": {
"version": "14.0.11",
@ -172,7 +172,7 @@
"com.unity.mathematics": "1.2.1",
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.test-framework": {
"version": "1.1.33",
@ -183,7 +183,7 @@
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.textmeshpro": {
"version": "3.0.7",
@ -192,7 +192,7 @@
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.timeline": {
"version": "1.7.6",
@ -204,7 +204,7 @@
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0"
},
"url": "https://packages.tuanjie.cn"
"url": "https://packages.unity.cn"
},
"com.unity.ugui": {
"version": "1.0.0",
@ -237,10 +237,7 @@
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.animation": "1.0.0"
}
"dependencies": {}
},
"com.unity.modules.audio": {
"version": "1.0.0",