Skip to content

Commit 87d0a8c

Browse files
gabrieldelacruzEvergreen
authored andcommitted
[VFX] Integrate the basic structure of new VFX graph compiler.
1 parent 1379ddd commit 87d0a8c

190 files changed

Lines changed: 13075 additions & 47 deletions

File tree

Some content is hidden

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

Packages/com.unity.visualeffectgraph/Editor/Compiler/VFXGraphCompiledData.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,17 +1094,7 @@ public struct VFXCompileOutput
10941094

10951095
public HashSet<string> sourceDependencies;
10961096

1097-
public VFXExpressionSheet sheet;
1098-
public VFXEditorSystemDesc[] systemDesc;
1099-
public VFXEventDesc[] eventDesc;
1100-
public VFXGPUBufferDesc[] gpuBufferDesc;
1101-
public VFXCPUBufferDesc[] cpuBufferDesc;
1102-
public VFXTemporaryGPUBufferDesc[] temporaryBufferDesc;
1103-
public VFXShaderSourceDesc[] shaderSourceDesc;
1104-
public VFXRendererSettings rendererSettings;
1105-
public VFXInstancingDisabledReason instancingDisabledReason;
1106-
1107-
public uint version;
1097+
public VisualEffectAssetDesc assetDesc;
11081098
}
11091099

11101100
public VFXCompileOutput Compile(VFXCompilationMode compilationMode, bool enableShaderDebugSymbols, VFXAnalytics analytics)
@@ -1125,8 +1115,8 @@ public VFXCompileOutput Compile(VFXCompilationMode compilationMode, bool enableS
11251115
if (m_Graph.children.Count() == 0)
11261116
{
11271117
output.success = true;
1128-
output.version = compiledVersion;
1129-
output.systemDesc = Array.Empty<VFXEditorSystemDesc>();
1118+
output.assetDesc.version = compiledVersion;
1119+
output.assetDesc.systemDesc = Array.Empty<VFXEditorSystemDesc>();
11301120
return output;
11311121
}
11321122

@@ -1351,16 +1341,17 @@ public VFXCompileOutput Compile(VFXCompilationMode compilationMode, bool enableS
13511341

13521342
output.success = true;
13531343

1354-
output.sheet = expressionSheet;
1355-
output.systemDesc = systemDescs.ToArray();
1356-
output.eventDesc = vfxEventDesc;
1357-
output.gpuBufferDesc = bufferDescs.ToArray();
1358-
output.cpuBufferDesc = cpuBufferDescs.ToArray();
1359-
output.temporaryBufferDesc = temporaryBufferDescs.ToArray();
1360-
output.shaderSourceDesc = shaderSources;
1361-
output.rendererSettings = new() { shadowCastingMode = shadowCastingMode, motionVectorGenerationMode = motionVectorGenerationMode };
1362-
output.instancingDisabledReason = instancingDisabledReason;
1363-
output.version = compiledVersion;
1344+
output.assetDesc.sheet = expressionSheet;
1345+
output.assetDesc.systemDesc = systemDescs.ToArray();
1346+
output.assetDesc.eventDesc = vfxEventDesc;
1347+
output.assetDesc.gpuBufferDesc = bufferDescs.ToArray();
1348+
output.assetDesc.cpuBufferDesc = cpuBufferDescs.ToArray();
1349+
output.assetDesc.temporaryBufferDesc = temporaryBufferDescs.ToArray();
1350+
output.assetDesc.shaderSourceDesc = shaderSources;
1351+
output.assetDesc.rendererSettings = new() { shadowCastingMode = shadowCastingMode, motionVectorGenerationMode = motionVectorGenerationMode };
1352+
output.assetDesc.instancingDisabledReason = instancingDisabledReason;
1353+
output.assetDesc.compilationMode = compilationMode;
1354+
output.assetDesc.version = compiledVersion;
13641355

13651356
m_ExpressionValues = expressionSheet.values;
13661357
}

Packages/com.unity.visualeffectgraph/Editor/GraphCommon.meta

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

Packages/com.unity.visualeffectgraph/Editor/GraphCommon/Collections.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace Unity.GraphCommon.LowLevel.Editor
6+
{
7+
/// <summary>
8+
/// A double-ended queue (deque) implementation that allows adding and removing elements from both ends.
9+
/// </summary>
10+
/// <typeparam name="T">The type that the deque is holding.</typeparam>
11+
/*public*/ class Deque<T> : IEnumerable<T>
12+
{
13+
private T[] m_Buffer;
14+
private int m_Head;
15+
private int m_Tail;
16+
private int m_Count;
17+
private const int DefaultCapacity = 4;
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="Deque{T}"/> class with the default capacity.
21+
/// </summary>
22+
public Deque() : this(DefaultCapacity)
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="Deque{T}"/> class with a specified capacity.
28+
/// </summary>
29+
/// <param name="capacity"> The initial capacity of the deque. </param>
30+
/// <exception cref="ArgumentOutOfRangeException">Throws if capacity is negative.</exception>
31+
public Deque(int capacity)
32+
{
33+
if (capacity < 0)
34+
throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity cannot be negative");
35+
36+
m_Buffer = new T[capacity];
37+
m_Head = 0;
38+
m_Tail = 0;
39+
m_Count = 0;
40+
}
41+
42+
/// <summary>
43+
/// Gets the number of elements in the deque.
44+
/// </summary>
45+
public int Count => m_Count;
46+
47+
/// <summary>
48+
/// Returns true if the deque is empty. False otherwise.
49+
/// </summary>
50+
public bool IsEmpty => m_Count == 0;
51+
52+
/// <summary>
53+
/// Adds an element to the front of the deque.
54+
/// </summary>
55+
/// <param name="item">The element to add.</param>
56+
public void AddFront(T item)
57+
{
58+
if (m_Count == m_Buffer.Length)
59+
{
60+
Resize();
61+
}
62+
63+
m_Head = (m_Head - 1 + m_Buffer.Length) % m_Buffer.Length;
64+
m_Buffer[m_Head] = item;
65+
m_Count++;
66+
}
67+
68+
/// <summary>
69+
/// Adds an element to the back of the deque.
70+
/// </summary>
71+
/// <param name="item">The element to add.</param>
72+
public void AddBack(T item)
73+
{
74+
if (m_Count == m_Buffer.Length)
75+
{
76+
Resize();
77+
}
78+
79+
m_Buffer[m_Tail] = item;
80+
m_Tail = (m_Tail + 1) % m_Buffer.Length;
81+
m_Count++;
82+
}
83+
84+
/// <summary>
85+
/// Removes and returns the element at the front of the deque.
86+
/// </summary>
87+
/// <returns>The element removed from the front.</returns>
88+
/// <exception cref="InvalidOperationException">Thrown if the deque is empty.</exception>
89+
public T RemoveFront()
90+
{
91+
if (IsEmpty)
92+
throw new InvalidOperationException("Deque is empty");
93+
94+
T item = m_Buffer[m_Head];
95+
m_Buffer[m_Head] = default(T); // Clear reference
96+
m_Head = (m_Head + 1) % m_Buffer.Length;
97+
m_Count--;
98+
return item;
99+
}
100+
101+
/// <summary>
102+
/// Removes and returns the element at the back of the deque.
103+
/// </summary>
104+
/// <returns>The element removed from the back.</returns>
105+
/// <exception cref="InvalidOperationException">Thrown if the deque is empty.</exception>
106+
public T RemoveBack()
107+
{
108+
if (IsEmpty)
109+
throw new InvalidOperationException("Deque is empty");
110+
111+
m_Tail = (m_Tail - 1 + m_Buffer.Length) % m_Buffer.Length;
112+
T item = m_Buffer[m_Tail];
113+
m_Buffer[m_Tail] = default(T); // Clear reference
114+
m_Count--;
115+
return item;
116+
}
117+
118+
/// <summary>
119+
/// Returns the element at the front of the deque without removing it.
120+
/// </summary>
121+
/// <returns>The element at the front.</returns>
122+
/// <exception cref="InvalidOperationException">Thrown if the deque is empty.</exception>
123+
public T PeekFront()
124+
{
125+
if (IsEmpty)
126+
throw new InvalidOperationException("Deque is empty");
127+
128+
return m_Buffer[m_Head];
129+
}
130+
131+
/// <summary>
132+
/// Returns the element at the back of the deque without removing it.
133+
/// </summary>
134+
/// <returns>The element at the back.</returns>
135+
/// <exception cref="InvalidOperationException">Thrown if the deque is empty.</exception>
136+
public T PeekBack()
137+
{
138+
if (IsEmpty)
139+
throw new InvalidOperationException("Deque is empty");
140+
141+
int lastIndex = (m_Tail - 1 + m_Buffer.Length) % m_Buffer.Length;
142+
return m_Buffer[lastIndex];
143+
}
144+
145+
// Indexer for random access
146+
private T this[int index]
147+
{
148+
get
149+
{
150+
if (index < 0 || index >= m_Count)
151+
throw new ArgumentOutOfRangeException(nameof(index));
152+
153+
int actualIndex = (m_Head + index) % m_Buffer.Length;
154+
return m_Buffer[actualIndex];
155+
}
156+
set
157+
{
158+
if (index < 0 || index >= m_Count)
159+
throw new ArgumentOutOfRangeException(nameof(index));
160+
161+
int actualIndex = (m_Head + index) % m_Buffer.Length;
162+
m_Buffer[actualIndex] = value;
163+
}
164+
}
165+
166+
/// <summary>
167+
/// Removes all elements from the deque.
168+
/// </summary>
169+
public void Clear()
170+
{
171+
if (m_Count > 0)
172+
{
173+
Array.Clear(m_Buffer, 0, m_Buffer.Length);
174+
m_Head = 0;
175+
m_Tail = 0;
176+
m_Count = 0;
177+
}
178+
}
179+
180+
// Resize the internal buffer when capacity is reached
181+
private void Resize()
182+
{
183+
int newCapacity = m_Buffer.Length == 0 ? DefaultCapacity : m_Buffer.Length * 2;
184+
T[] newBuffer = new T[newCapacity];
185+
186+
// Copy elements to new buffer in order
187+
for (int i = 0; i < m_Count; i++)
188+
{
189+
newBuffer[i] = this[i];
190+
}
191+
192+
m_Buffer = newBuffer;
193+
m_Head = 0;
194+
m_Tail = m_Count;
195+
}
196+
197+
/// <summary>
198+
/// Returns an enumerator that iterates through the deque.
199+
/// </summary>
200+
/// <returns>An enumerator for the deque.</returns>
201+
public IEnumerator<T> GetEnumerator()
202+
{
203+
for (int i = 0; i < m_Count; i++)
204+
{
205+
yield return this[i];
206+
}
207+
}
208+
209+
IEnumerator IEnumerable.GetEnumerator()
210+
{
211+
return GetEnumerator();
212+
}
213+
}
214+
}

Packages/com.unity.visualeffectgraph/Editor/GraphCommon/Collections/Deque.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.

0 commit comments

Comments
 (0)