Skip to content

Commit 410d55f

Browse files
authored
Merge pull request #8253 from Unity-Technologies/internal/master
Mirror Internal/master
2 parents b4a5a7f + 3a92ab6 commit 410d55f

File tree

391 files changed

+31381
-39633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

391 files changed

+31381
-39633
lines changed

Packages/com.unity.render-pipelines.core/Editor-PrivateShared/Unity.RenderPipelines.Core.Editor.Shared.asmdef

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"name": "Unity.RenderPipelines.Core.Editor.Shared",
33
"rootNamespace": "",
44
"references": [
5-
"GUID:3eae0364be2026648bf74846acb8a731"
5+
"GUID:3eae0364be2026648bf74846acb8a731",
6+
"GUID:716365d8000d25e4c8621aa2d34a92fa",
7+
"GUID:9149a3cbb036049f68e4e5b6388b9c85",
8+
"GUID:c49c619b6af2be941af9bcbca2641964",
9+
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
10+
"GUID:4fd6538c1c56b409fb53fdf0183170ec",
11+
"GUID:214c0945bb158c940aada223f3223ee8"
612
],
713
"includePlatforms": [
814
"Editor"

Packages/com.unity.render-pipelines.core/Editor/GPUDriven.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using UnityEditor;
2+
3+
namespace UnityEngine.Rendering
4+
{
5+
//@ This is a simple instance data viewer class used for instance data debugging.
6+
//@ This could become a user facing tool in the future. Where the user could see the instance data in the GPU.
7+
//@ It could show layouts, archetypes, components and instance data.
8+
internal class GPUInstanceDataBufferViewer : EditorWindow
9+
{
10+
[SerializeField] private Vector2 m_ScrollPos;
11+
12+
public static void InitializeWindow()
13+
{
14+
GPUInstanceDataBufferViewer wnd = GetWindow<GPUInstanceDataBufferViewer>();
15+
wnd.titleContent = new GUIContent("GPU Resident Instance Data Viewer");
16+
}
17+
18+
public void OnGUI()
19+
{
20+
if (!GPUResidentDrawer.IsInitialized())
21+
{
22+
EditorGUILayout.LabelField("GPU Resident Drawer is not enabled in Render Pipeline Asset.");
23+
return;
24+
}
25+
26+
m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos);
27+
28+
//@ This is usefully for internal GPU Resident Drawer debugging.
29+
30+
ref GPUArchetypeManager archetypeMgr = ref GPUResidentDrawer.GetGPUArchetypeManager().GetRef();
31+
ref DefaultGPUComponents defaultGPUComponents = ref GPUResidentDrawer.GetDefaultGPUComponents();
32+
var buffer = GPUResidentDrawer.GetInstanceDataBuffer();
33+
var readback = GPUResidentDrawer.ReadbackInstanceDataBuffer<uint>();
34+
35+
EditorGUILayout.LabelField($"Archetypes Count: {buffer.layout.archetypes.Length}");
36+
37+
for (int i = 0; i < buffer.layout.archetypes.Length; ++i)
38+
{
39+
var archetype = buffer.layout.archetypes[i];
40+
var archetypeDesc = archetypeMgr.GetArchetypeDesc(archetype);
41+
EditorGUILayout.LabelField($"Archetype {i}, ID: {archetype.index}");
42+
EditorGUILayout.LabelField("Components:");
43+
for (int j = 0; j < archetypeDesc.components.Length; ++j)
44+
{
45+
var component = archetypeDesc.components[j];
46+
var componentDesc = archetypeMgr.GetComponentDesc(component);
47+
48+
// Replace when Shader.PropertyIDToName API lands
49+
//var componentName = Shader.PropertyIDToName(componentDesc.propertyID);
50+
string componentName = "<unknown>";
51+
EditorGUILayout.LabelField($"Component {j} - Name: {componentName}, ID: {component.index}");
52+
}
53+
}
54+
55+
for (int archIndex = 0; archIndex < buffer.layout.archetypes.Length; ++archIndex)
56+
{
57+
var archetype = buffer.layout.archetypes[archIndex];
58+
var archetypeDesc = archetypeMgr.GetArchetypeDesc(archetype);
59+
60+
EditorGUILayout.LabelField($"====== Archetype {archetype} Instance Data ======");
61+
62+
var count = buffer.layout.instancesCount[archIndex];
63+
for (int instanceIndex = 0; instanceIndex < count; ++instanceIndex)
64+
{
65+
GPUInstanceIndex gpuIndex = buffer.InstanceGPUHandleToGPUIndex(InstanceGPUHandle.Create(archetype, instanceIndex));
66+
PackedMatrix objectToWorld = readback.LoadData<PackedMatrix>(defaultGPUComponents.objectToWorld, gpuIndex);
67+
EditorGUILayout.LabelField($"Instance {instanceIndex}; GPU Index: {gpuIndex.index}; ObjectToWorld {objectToWorld}");
68+
//@ Read and display more instance data here if needed...
69+
}
70+
}
71+
72+
readback.Dispose();
73+
74+
EditorGUILayout.EndScrollView();
75+
}
76+
}
77+
}

Packages/com.unity.render-pipelines.core/Editor/GPUDriven/GPUInstanceDataBufferViewer.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/AdaptiveProbeVolumes.BakePipelineDriver.cs

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Reflection;
34
using System.Runtime.CompilerServices;
4-
using UnityEditor.LightBaking;
55

66
namespace UnityEngine.Rendering
77
{
88
partial class AdaptiveProbeVolumes
99
{
1010
// This class is used to (1) access the internal class UnityEditor.LightBaking.BakePipelineDriver and (2) provide a slightly higher level API.
11-
private sealed class BakePipelineDriver : IDisposable
11+
sealed class BakePipelineDriver : IDisposable
1212
{
13-
// Keep in sync with the enum BakePipeline::Run::StageName
14-
public enum StageName : int
15-
{
16-
Initialized,
17-
Preprocess,
18-
Bake,
19-
PostProcess,
20-
AdditionalBake,
21-
Done
22-
}
23-
24-
private readonly object _bakePipelineDriver;
25-
private readonly Type _bakePipelineDriverType;
13+
readonly object m_BakePipelineDriver;
14+
readonly Type m_BakePipelineDriverType;
15+
readonly Type m_StageNameType;
2616

2717
internal BakePipelineDriver()
2818
{
29-
_bakePipelineDriverType = Type.GetType("UnityEditor.LightBaking.BakePipelineDriver, UnityEditor");
30-
bool newed = _bakePipelineDriverType != null;
31-
Debug.Assert(newed, "Unexpected, could not find the type UnityEditor.LightBaking.BakePipelineDriver");
32-
_bakePipelineDriver = newed ? Activator.CreateInstance(_bakePipelineDriverType) : null;
33-
Debug.Assert(_bakePipelineDriver != null, "Unexpected, could not new up a BakePipelineDriver");
19+
Debug.Assert(UnityEditorInternal.InternalEditorUtility.CurrentThreadIsMainThread());
20+
21+
m_BakePipelineDriverType = Type.GetType("UnityEditor.LightBaking.BakePipelineDriver, UnityEditor");
22+
Debug.Assert(m_BakePipelineDriverType != null, "Unexpected, could not find the type UnityEditor.LightBaking.BakePipelineDriver");
23+
m_StageNameType = m_BakePipelineDriverType.GetNestedType("StageName", BindingFlags.NonPublic | BindingFlags.Public);
24+
Debug.Assert(m_StageNameType is { IsEnum: true }, "Unexpected, could not find the nested enum StageName on BakePipelineDriver");
25+
Debug.Assert(IsStageNameEnumConsistent(m_StageNameType), "Unexpected, StageName enum is not consistent with BakePipelineDriver.StageName enum");
26+
m_BakePipelineDriver = Activator.CreateInstance(m_BakePipelineDriverType, nonPublic: true);
27+
Debug.Assert(m_BakePipelineDriver != null, "Unexpected, could not new up a BakePipelineDriver");
3428
}
3529

3630
internal void StartBake(bool enablePatching, ref float progress, ref StageName stage)
@@ -51,36 +45,78 @@ internal bool RunInProgress()
5145
internal void Step(ref float progress, ref StageName stage) =>
5246
Update(true, true, true, out progress, out stage);
5347

54-
private void SetEnableBakedLightmaps(bool enable) =>
48+
void SetEnableBakedLightmaps(bool enable) =>
5549
InvokeMethod(new object[] { enable }, out _);
5650

57-
private void SetEnablePatching(bool enable) =>
51+
void SetEnablePatching(bool enable) =>
5852
InvokeMethod(new object[] { enable }, out _);
5953

60-
private void Update(bool isOnDemandBakeInProgress, bool isOnDemandBakeAsync, bool shouldBeRunning,
54+
void Update(bool isOnDemandBakeInProgress, bool isOnDemandBakeAsync, bool shouldBeRunning,
6155
out float progress, out StageName stage)
6256
{
63-
object[] parameters = { isOnDemandBakeInProgress, isOnDemandBakeAsync, shouldBeRunning, -1.0f, -1 };
57+
progress = -1.0f;
58+
stage = StageName.Invalid;
59+
object[] parameters = { isOnDemandBakeInProgress, isOnDemandBakeAsync, shouldBeRunning, progress,
60+
Enum.ToObject(m_StageNameType, (int)stage) };
6461
InvokeMethod(parameters, out _);
6562
progress = (float)parameters[3];
66-
stage = (StageName)parameters[4];
63+
stage = (StageName)Convert.ToInt32(parameters[4]);
6764
}
6865

6966
public void Dispose() =>
7067
InvokeMethod(new object[] { }, out _);
7168

72-
private bool InvokeMethod(object[] parameters, out object result, [CallerMemberName] string methodName = "")
69+
bool InvokeMethod(object[] parameters, out object result, [CallerMemberName] string methodName = "")
7370
{
74-
MethodInfo methodInfo = _bakePipelineDriverType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
71+
MethodInfo methodInfo = m_BakePipelineDriverType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
7572
bool gotMethod = methodInfo != null;
7673
Debug.Assert(gotMethod, $"Unexpected, could not find {methodName} on BakePipelineDriver");
77-
if (!gotMethod)
78-
{
79-
result = null;
74+
75+
result = methodInfo.Invoke(m_BakePipelineDriver, parameters);
76+
77+
return true;
78+
}
79+
80+
// Keep this in sync with the enum in Editor\Src\GI\BakePipeline\BakePipeline.bindings.h
81+
public enum StageName
82+
{
83+
Invalid = -1,
84+
Initialized = 0,
85+
Preprocess = 1,
86+
PreprocessProbes = 2,
87+
Bake = 3,
88+
PostProcess = 4,
89+
AdditionalBake = 5,
90+
Done = 6
91+
}
92+
93+
// If StageName is not kept in sync, this should return false
94+
static bool IsStageNameEnumConsistent(Type otherType)
95+
{
96+
string[] ourNames = Enum.GetNames(typeof(StageName));
97+
string[] otherNames = Enum.GetNames(otherType);
98+
99+
if (ourNames.Length != otherNames.Length)
80100
return false;
81-
}
82101

83-
result = methodInfo.Invoke(_bakePipelineDriver, parameters);
102+
Array ourValues = Enum.GetValues(typeof(StageName));
103+
Array otherValues = Enum.GetValues(otherType);
104+
105+
// Brute-force compare each local name against the external by lookup
106+
for (int i = 0; i < ourNames.Length; i++)
107+
{
108+
string name = ourNames[i];
109+
110+
int otherIndex = Array.IndexOf(otherNames, name);
111+
if (otherIndex < 0)
112+
return false;
113+
114+
int ourVal = Convert.ToInt32(ourValues.GetValue(i));
115+
int otherVal = Convert.ToInt32(otherValues.GetValue(otherIndex));
116+
117+
if (ourVal != otherVal)
118+
return false;
119+
}
84120

85121
return true;
86122
}

0 commit comments

Comments
 (0)