Skip to content

Commit 482d2f8

Browse files
authored
Merge pull request #7975 from Unity-Technologies/internal/master
Internal/master
2 parents b2905e2 + 7553a37 commit 482d2f8

File tree

193 files changed

+6566
-2046
lines changed

Some content is hidden

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

193 files changed

+6566
-2046
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,18 +1075,18 @@ static void BakeProbeVolumeOnly()
10751075
var positionsBufferID = ctx.CreateBuffer(positionsBytes);
10761076
using var positionsNative = new NativeArray<Vector3>(probePositions, Allocator.TempJob);
10771077
ctx.WriteBuffer(positionsBufferID, positionsNative.Reinterpret<byte>(sizeOfFloat * 3));
1078-
var positionsSlice = new BufferSlice(positionsBufferID, 0);
1078+
var positionsSlice = new BufferSlice<Vector3>(positionsBufferID, 0);
10791079

10801080
LightmapParameters parameters = LightmapParameters.GetLightmapParametersForLightingSettings(lightingSettings);
1081-
integrator.Prepare(world, positionsSlice, parameters.pushoff, bounceCount);
1081+
integrator.Prepare(ctx, world, positionsSlice, parameters.pushoff, bounceCount);
10821082
integrator.SetProgressReporter(progress);
10831083

10841084
var positionOffset = 0; // can be used to bake portions/tiles of the full set of positions.
10851085
var shBytes = (ulong)(sizeSHL2RGB * positionsLength);
10861086
var directRadianceBufferId = ctx.CreateBuffer(shBytes);
10871087
var indirectRadianceBufferId = ctx.CreateBuffer(shBytes);
1088-
var directRadianceSlice = new BufferSlice(directRadianceBufferId, 0);
1089-
var indirectRadianceSlice = new BufferSlice(indirectRadianceBufferId, 0);
1088+
var directRadianceSlice = new BufferSlice<SphericalHarmonicsL2>(directRadianceBufferId, 0);
1089+
var indirectRadianceSlice = new BufferSlice<SphericalHarmonicsL2>(indirectRadianceBufferId, 0);
10901090

10911091
// Bake direct radiance.
10921092
var integrationResult = integrator.IntegrateDirectRadiance(ctx, positionOffset, positionsLength,
@@ -1101,7 +1101,7 @@ static void BakeProbeVolumeOnly()
11011101
// Bake validity.
11021102
var validityBytes = (ulong)(sizeOfFloat * positionsLength);
11031103
var validityBufferId = ctx.CreateBuffer(validityBytes);
1104-
var validitySlice = new BufferSlice(validityBufferId, 0);
1104+
var validitySlice = new BufferSlice<float>(validityBufferId, 0);
11051105
var validityResult = integrator.IntegrateValidity(ctx, positionOffset, positionsLength,
11061106
sampleCountValidity, validitySlice);
11071107
Assert.AreEqual(IProbeIntegrator.ResultType.Success, validityResult.type, "IntegrateLightProbeValidity failed.");
@@ -1114,7 +1114,7 @@ static void BakeProbeVolumeOnly()
11141114
// Note that windowing can be controlled separately from de-ringing.
11151115
// Windowing and de-ringing are done together to stay as close to legacy light probe baking behaviour as possible.
11161116
var windowedDirectSHBufferId = ctx.CreateBuffer(shBytes);
1117-
var windowedDirectRadianceSlice = new BufferSlice(windowedDirectSHBufferId, 0);
1117+
var windowedDirectRadianceSlice = new BufferSlice<SphericalHarmonicsL2>(windowedDirectSHBufferId, 0);
11181118
bool dering = true; // TODO: get this from LightProbeGroup.dering or APV UI?
11191119
if (dering)
11201120
{
@@ -1128,7 +1128,7 @@ static void BakeProbeVolumeOnly()
11281128

11291129
// Apply indirect intensity multiplier to indirect radiance.
11301130
var boostedIndirectSHBufferId = ctx.CreateBuffer(shBytes);
1131-
var boostedIndirectRadianceSlice = new BufferSlice(boostedIndirectSHBufferId, 0);
1131+
var boostedIndirectRadianceSlice = new BufferSlice<SphericalHarmonicsL2>(boostedIndirectSHBufferId, 0);
11321132
if (lightingSettings.indirectScale.Equals(1.0f) == false)
11331133
{
11341134
bool multiplyOk = postProcessor.ScaleSphericalHarmonicsL2(ctx, indirectRadianceSlice, boostedIndirectRadianceSlice, positionsLength, lightingSettings.indirectScale);
@@ -1141,13 +1141,13 @@ static void BakeProbeVolumeOnly()
11411141

11421142
// Combine direct and indirect radiance.
11431143
var combinedSHBufferId = ctx.CreateBuffer(shBytes);
1144-
var combinedSHBufferSlice = new BufferSlice(combinedSHBufferId, 0);
1144+
var combinedSHBufferSlice = new BufferSlice<SphericalHarmonicsL2>(combinedSHBufferId, 0);
11451145
bool addOk = postProcessor.AddSphericalHarmonicsL2(ctx, windowedDirectRadianceSlice, boostedIndirectRadianceSlice, combinedSHBufferSlice, positionsLength);
11461146
Assert.IsTrue(addOk);
11471147

11481148
// Convert radiance to irradiance and transform to the format expected by the Unity renderer.
11491149
var irradianceBufferId = ctx.CreateBuffer(shBytes);
1150-
var irradianceSlice = new BufferSlice(irradianceBufferId, 0);
1150+
var irradianceSlice = new BufferSlice<SphericalHarmonicsL2>(irradianceBufferId, 0);
11511151
bool convolvedOk = postProcessor.ConvolveRadianceToIrradiance(ctx, combinedSHBufferSlice, irradianceSlice, positionsLength);
11521152
Assert.IsTrue(convolvedOk);
11531153

@@ -1170,9 +1170,9 @@ static void BakeProbeVolumeOnly()
11701170
Assert.IsTrue(flushOk);
11711171

11721172
// Wait for read backs to complete.
1173-
bool waitResult = ctx.WaitForAsyncOperation(irradianceReadEvent);
1173+
bool waitResult = ctx.Wait(irradianceReadEvent);
11741174
Debug.Assert(waitResult, "Failed to read irradiance from context.");
1175-
waitResult = ctx.WaitForAsyncOperation(validityReadEvent);
1175+
waitResult = ctx.Wait(validityReadEvent);
11761176
Debug.Assert(waitResult, "Failed to read validity from context.");
11771177

11781178
// Output data in result buffers is now ready, in CPU side memory, release all buffers.

Packages/com.unity.render-pipelines.core/Editor/RenderGraph/Viewer/RenderGraphDebugger.cs

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using UnityEngine.Experimental.Rendering.RenderGraphModule;
44
using UnityEngine.Experimental.Rendering.RenderGraphModule.NativeRenderPassCompiler;
5+
using UnityEngine.Rendering;
56

67
internal class RenderGraphDebugger : IRenderGraphDebugger
78
{
@@ -19,7 +20,7 @@ public void OutputGraph(NativePassCompiler graph)
1920
if (captureNextGraph)
2021
{
2122
var view = RenderGraphWindow.OpenGraphVisualizer();
22-
CollectGraphDebugData(graph.contextData, graph.graph.m_ResourcesForDebugOnly, view);
23+
CollectGraphDebugData(graph.contextData, graph.graph, view);
2324
view.UpdateNodeVisualisation();
2425
captureNextGraph = false;
2526
}
@@ -32,10 +33,92 @@ public enum InputUsageType
3233
Fetch //Used with fetch ops
3334
}
3435

36+
// Actual values of global variables when a certain pass executes
37+
class PassGlobalState
38+
{
39+
public PassGlobalState() { }
40+
public PassGlobalState(PassGlobalState copyFrom)
41+
{
42+
values = new DynamicArray<ValueTuple<int, ResourceHandle>>(copyFrom.values);
43+
}
44+
45+
public void SetGlobalValue(int shaderPropertyId, ResourceHandle value)
46+
{
47+
if (TryFind(shaderPropertyId, out var index))
48+
{
49+
values[index].Item2 = value;
50+
}
51+
else
52+
{
53+
values.Add(ValueTuple.Create(shaderPropertyId, value));
54+
}
55+
}
56+
57+
public ResourceHandle GetGlobalValue(int shaderPropertyId)
58+
{
59+
if (TryFind(shaderPropertyId, out var index))
60+
{
61+
return values[index].Item2;
62+
}
63+
return new ResourceHandle();
64+
}
65+
66+
public bool IsUsedAsGlobal(ResourceHandle h)
67+
{
68+
for (int i = 0; i < values.size; i++)
69+
{
70+
if (h.index == values[i].Item2.index)
71+
{
72+
return true;
73+
}
74+
}
75+
return false;
76+
}
77+
78+
private bool TryFind(int shaderPropertyId, out int idx)
79+
{
80+
for (int i = 0; i < values.size; i++)
81+
{
82+
if (shaderPropertyId == values[i].Item1)
83+
{
84+
idx = i;
85+
return true;
86+
}
87+
}
88+
idx = -1;
89+
return false;
90+
}
91+
92+
DynamicArray<ValueTuple<int, ResourceHandle>> values = new DynamicArray<ValueTuple<int, ResourceHandle>>();
93+
}
94+
95+
3596
private static RenderGraphWindow debugWindow;
3697
static void CollectGraphDebugData(CompilerContextData ctx,
37-
RenderGraphResourceRegistry resources, RenderGraphView view)
98+
NativePassCompiler.RenderGraphInputInfo inputInfo, RenderGraphView view)
3899
{
100+
var resources = inputInfo.m_ResourcesForDebugOnly;
101+
102+
// Derive the state of the global variables at each pass
103+
List<PassGlobalState> passGlobals = new List<PassGlobalState>(ctx.passData.Length);
104+
for (var i = 0; i < ctx.passData.Length; i++)
105+
passGlobals.Add(null);
106+
passGlobals[0] = new PassGlobalState();// first pass has empty globals set
107+
108+
for (var i = 0; i < ctx.passData.Length; i++)
109+
{
110+
ref readonly var pass = ref ctx.passData.ElementAt(i);
111+
if (pass.passId == ctx.passData.Length-1) continue; // last pass doesn't matter
112+
var nextGlobalState = new PassGlobalState(passGlobals[pass.passId]);
113+
var globals = inputInfo.m_RenderPasses[pass.passId].setGlobalsList;
114+
foreach (var g in globals)
115+
{
116+
nextGlobalState.SetGlobalValue(g.Item2, g.Item1.handle);
117+
}
118+
119+
passGlobals[pass.passId + 1] = nextGlobalState;
120+
}
121+
39122
//loop over all passes to add them and their resources to the graph
40123
for (int passIndex = 0; passIndex < ctx.passData.Length; passIndex++)
41124
{
@@ -297,7 +380,8 @@ static void CollectGraphDebugData(CompilerContextData ctx,
297380

298381
if (pointToVer.written)
299382
{
300-
view.AddConnection(prevPass.identifier, pass.identifier, resourceVersionedName, resourceName, mergeMessage, use);
383+
bool isGlobal = passGlobals[pass.passId].IsUsedAsGlobal(inputResource);
384+
view.AddConnection(prevPass.identifier, pass.identifier, resourceVersionedName, resourceName, mergeMessage, use, isGlobal);
301385
}
302386
}
303387
}

Packages/com.unity.render-pipelines.core/Editor/RenderGraph/Viewer/RenderGraphView.cs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,23 @@ internal void AddNRP(string nrpString)
262262

263263
foreach (var pass in nrpPasses)
264264
{
265-
nrp.title += pass.title + " ";
265+
nrp.title += pass.title + ", ";
266266
m_Passes.Remove(pass);
267267
MoveConnections(pass, nrp, nrp.m_MergedPasses);
268268
}
269269

270-
for (int i = 0; i < nrp.m_InputPort.Count; ++i)
270+
for (int i = nrp.m_InputPort.Count-1; i >= 0; i--)
271271
{
272-
if (LinqButNotLinq.Any(nrp.m_InputPort[i].connections) == false)
272+
bool isGlobal = (nrp.m_InputPort[i].portType == typeof(bool)); //HACK: Find a better way to keep track of globals
273+
if (LinqButNotLinq.Any(nrp.m_InputPort[i].connections) == false && !isGlobal)
273274
{
275+
274276
nrp.inputContainer.Remove(nrp.m_InputPort[i]);
275277
nrp.m_InputPort.RemoveAt(i);
276278
}
277279
}
278280

279-
for (int i = 0; i < nrp.m_OutputPort.Count; ++i)
281+
for (int i = nrp.m_OutputPort.Count-1; i >= 0; i--)
280282
{
281283
if (LinqButNotLinq.Any(nrp.m_OutputPort[i].connections) == false)
282284
{
@@ -311,7 +313,8 @@ void MoveConnections(RenderGraphNode origin, RenderGraphNode destination, List<R
311313
Port destPort = destination.GetPort(Direction.Input, port.name);
312314
if (destPort == null)
313315
{
314-
destPort = destination.AddPort(Direction.Input, port.name);
316+
bool isGlobal = (port.portType == typeof(bool)); //HACK: Find a better way to keep track of globals
317+
destPort = destination.AddPort(Direction.Input, port.name, isGlobal);
315318
}
316319

317320
foreach (var edge in port.connections)
@@ -341,7 +344,7 @@ void MoveConnections(RenderGraphNode origin, RenderGraphNode destination, List<R
341344
var destPort = destination.GetPort(Direction.Output, port.name);
342345
if (destPort == null)
343346
{
344-
destPort = destination.AddPort(Direction.Output, port.name);
347+
destPort = destination.AddPort(Direction.Output, port.name, false);
345348
}
346349

347350
foreach (var edge in port.connections)
@@ -426,7 +429,7 @@ internal void AddPass(string passID, string passName, RenderGraphWindow.PassDebu
426429
}
427430

428431
internal void AddConnection(string from, string to, string resourceName,
429-
string resourceNameNoVersion, string mergeMessage, RenderGraphDebugger.InputUsageType use)
432+
string resourceNameNoVersion, string mergeMessage, RenderGraphDebugger.InputUsageType use, bool isGlobal)
430433
{
431434
var fromNode = m_Passes.Find(node => node.m_ID == from);
432435
var toNode = m_Passes.Find(node => node.m_ID == to);
@@ -457,23 +460,28 @@ internal void AddConnection(string from, string to, string resourceName,
457460
Port fromPort = fromNode.GetPort(Direction.Output, resourceNameNoVersion);
458461
if (fromPort == null)
459462
{
460-
fromPort = fromNode.AddPort(Direction.Output, resourceNameNoVersion);
463+
fromPort = fromNode.AddPort(Direction.Output, resourceNameNoVersion, isGlobal);
461464
}
462465

463466
Port toPort = toNode.GetPort(Direction.Input, resourceNameNoVersion);
464467
if (toPort == null)
465468
{
466-
toPort = toNode.AddPort(Direction.Input, resourceNameNoVersion);
469+
toPort = toNode.AddPort(Direction.Input, resourceNameNoVersion, isGlobal);
467470
}
468471

469472
//connect ports
470-
var edge = new RenderGraphEdge();
471-
edge.view = this;
472-
edge.tooltip = mergeMessage;
473-
edge.input = toPort;
474-
edge.output = fromPort;
475-
toPort.Connect(edge);
476-
fromPort.Connect(edge);
473+
if (!isGlobal)
474+
{
475+
var edge = new RenderGraphEdge();
476+
edge.view = this;
477+
edge.tooltip = mergeMessage;
478+
edge.input = toPort;
479+
edge.output = fromPort;
480+
toPort.Connect(edge);
481+
fromPort.Connect(edge);
482+
483+
AddElement(edge);
484+
}
477485

478486
//save input/output connections to make sorting the view easier
479487
if (!fromNode.m_Outputs.Contains(toNode))
@@ -485,8 +493,6 @@ internal void AddConnection(string from, string to, string resourceName,
485493
{
486494
toNode.m_Inputs.Add(fromNode);
487495
}
488-
489-
AddElement(edge);
490496
}
491497

492498
internal ResourceNode AddResource(string resourceID, string label, RenderGraphWindow.ResourceDebugData data)
@@ -910,10 +916,9 @@ public Port GetPort(Direction direction, string connectionName)
910916
return null;
911917
}
912918

913-
public Port AddPort(Direction portDirection, string connectionName,
914-
Port.Capacity capacity = Port.Capacity.Multi)
919+
public Port AddPort(Direction portDirection, string connectionName, bool isGlobal)
915920
{
916-
var n = InstantiatePort(Orientation.Horizontal, portDirection, capacity, typeof(string));
921+
var n = InstantiatePort(Orientation.Horizontal, portDirection, Port.Capacity.Multi, (isGlobal) ? typeof(bool) : typeof(string));
917922
n.name = connectionName;
918923
n.portName = connectionName;
919924
if (portDirection == Direction.Output)

Packages/com.unity.render-pipelines.core/Runtime/Common/DynamicArray.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34

45
namespace UnityEngine.Rendering
@@ -62,7 +63,7 @@ public DynamicArray(int size)
6263
/// Constructor. This overload allows you to only allocate memory without setting the size.
6364
/// </summary>
6465
/// <param name="capacity">The nubmer of elements to allocate.</param>
65-
/// <param name="resize">If true, also set the size of the array to the passed in capacity. If false, only allocate data but keep the size at 0.</param>///
66+
/// <param name="resize">If true, also set the size of the array to the passed in capacity. If false, only allocate data but keep the size at 0.</param>///
6667
public DynamicArray(int capacity, bool resize)
6768
{
6869
m_Array = new T[capacity];
@@ -72,6 +73,20 @@ public DynamicArray(int capacity, bool resize)
7273
#endif
7374
}
7475

76+
/// <summary>
77+
/// Constructor. This constructor allocates memory and does a deep copy of the provided array.
78+
/// </summary>
79+
/// <param name="deepCopy">Array to be copied</param>
80+
public DynamicArray(DynamicArray<T> deepCopy)
81+
{
82+
m_Array = new T[deepCopy.size];
83+
size = deepCopy.size;
84+
Array.Copy(deepCopy.m_Array, m_Array, size);
85+
#if DEVELOPMENT_BUILD || UNITY_EDITOR
86+
version = 0;
87+
#endif
88+
}
89+
7590
/// <summary>
7691
/// Clear the array of all elements.
7792
/// </summary>
@@ -102,7 +117,7 @@ public int Add(in T value)
102117
// Grow array if needed;
103118
if (index >= m_Array.Length)
104119
{
105-
var newArray = new T[m_Array.Length * 2];
120+
var newArray = new T[Math.Max(m_Array.Length * 2,1)];
106121
Array.Copy(m_Array, newArray, m_Array.Length);
107122
m_Array = newArray;
108123
}
@@ -193,7 +208,7 @@ public void RemoveRange(int index, int count)
193208
{
194209
if (count == 0)
195210
return;
196-
211+
197212
#if DEVELOPMENT_BUILD || UNITY_EDITOR
198213
if (index < 0 || index >= size || count < 0 || index + count > size)
199214
throw new ArgumentOutOfRangeException();

0 commit comments

Comments
 (0)