Skip to content

Commit 3709c18

Browse files
Remove hacky indexInSystemDesc
... but actually, we can't identify spawn context by VFXData (see the following commit)
1 parent 0d358b2 commit 3709c18

File tree

4 files changed

+48
-33
lines changed

4 files changed

+48
-33
lines changed

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

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ struct VFXContextCompiledData
2222
public VFXUniformMapper uniformMapper;
2323
public VFXMapping[] parameters;
2424
public int indexInShaderSource;
25-
public int indexInSystemDesc;
2625
}
2726

2827
enum VFXCompilationMode
@@ -577,6 +576,7 @@ private static VFXEditorTaskDesc[] BuildEditorTaksDescFromBlockSpawner(IEnumerab
577576
}
578577

579578
private static void FillSpawner(Dictionary<VFXContext, SpawnInfo> outContextSpawnToSpawnInfo,
579+
Dictionary<VFXData, uint> outDataToSystemIndex,
580580
List<VFXCPUBufferDesc> outCpuBufferDescs,
581581
List<VFXEditorSystemDesc> outSystemDescs,
582582
IEnumerable<VFXContext> contexts,
@@ -648,7 +648,12 @@ private static void FillSpawner(Dictionary<VFXContext, SpawnInfo> outContextSpaw
648648
else
649649
throw new InvalidOperationException("system names manager cannot be null");
650650

651-
contextData.indexInSystemDesc = outSystemDescs.Count;
651+
var data = spawnContext.GetData();
652+
653+
if (outDataToSystemIndex.ContainsKey(data))
654+
throw new InvalidOperationException("Unexpected duplicated VFXData for spawner : " + nativeName);
655+
656+
outDataToSystemIndex.Add(data, (uint)outSystemDescs.Count);
652657
contextToCompiledData[spawnContext] = contextData;
653658

654659
outSystemDescs.Add(new VFXEditorSystemDesc()
@@ -694,13 +699,13 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
694699
{
695700
var contextEffectiveInputLinks = subgraphInfos.contextEffectiveInputLinks;
696701

697-
var allPlayNotLinked = contextSpawnToSpawnInfo.Where(o => !contextEffectiveInputLinks[o.Key][0].Any()).Select(o => o.Key).ToList();
698-
var allStopNotLinked = contextSpawnToSpawnInfo.Where(o => !contextEffectiveInputLinks[o.Key][1].Any()).Select(o => o.Key).ToList();
702+
var allPlayNotLinked = contextSpawnToSpawnInfo.Where(o => !contextEffectiveInputLinks[o.Key][0].Any()).Select(o => o.Key.GetData()).ToList();
703+
var allStopNotLinked = contextSpawnToSpawnInfo.Where(o => !contextEffectiveInputLinks[o.Key][1].Any()).Select(o => o.Key.GetData()).ToList();
699704

700705
var eventDescTemp = new EventDesc[]
701706
{
702-
new EventDesc() { name = VisualEffectAsset.PlayEventName, startSystems = allPlayNotLinked, stopSystems = new List<VFXContext>(), initSystems = new List<VFXContext>() },
703-
new EventDesc() { name = VisualEffectAsset.StopEventName, startSystems = new List<VFXContext>(), stopSystems = allStopNotLinked, initSystems = new List<VFXContext>() },
707+
new EventDesc() { name = VisualEffectAsset.PlayEventName, startSystems = allPlayNotLinked, stopSystems = new List<VFXData>(), initSystems = new List<VFXData>() },
708+
new EventDesc() { name = VisualEffectAsset.StopEventName, startSystems = new List<VFXData>(), stopSystems = allStopNotLinked, initSystems = new List<VFXData>() },
704709
}.ToList();
705710

706711
var specialNames = new HashSet<string>(new string[] {VisualEffectAsset.PlayEventName, VisualEffectAsset.StopEventName});
@@ -724,9 +729,9 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
724729
eventDescTemp.Add(new EventDesc
725730
{
726731
name = eventName,
727-
startSystems = new List<VFXContext>(),
728-
stopSystems = new List<VFXContext>(),
729-
initSystems = new List<VFXContext>()
732+
startSystems = new List<VFXData>(),
733+
stopSystems = new List<VFXData>(),
734+
initSystems = new List<VFXData>()
730735
});
731736
}
732737

@@ -738,17 +743,17 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
738743
var startSystem = link.slotIndex == 0;
739744
if (startSystem)
740745
{
741-
eventDesc.startSystems.Add(link.context);
746+
eventDesc.startSystems.Add(link.context.GetData());
742747
}
743748
else
744749
{
745-
eventDesc.stopSystems.Add(link.context);
750+
eventDesc.stopSystems.Add(link.context.GetData());
746751
}
747752
}
748753
}
749754
else if (link.context.contextType == VFXContextType.Init)
750755
{
751-
eventDesc.initSystems.Add(link.context);
756+
eventDesc.initSystems.Add(link.context.GetData());
752757
}
753758
else
754759
{
@@ -971,11 +976,17 @@ void ComputeEffectiveInputLinks(ref SubgraphInfos subgraphInfos, IEnumerable<VFX
971976
struct EventDesc
972977
{
973978
public string name;
974-
public List<VFXContext> startSystems;
975-
public List<VFXContext> stopSystems;
976-
public List<VFXContext> initSystems;
979+
public List<VFXData> startSystems;
980+
public List<VFXData> stopSystems;
981+
public List<VFXData> initSystems;
977982
}
978983

984+
static IEnumerable<uint> ConvertDataToSystemIndex(IEnumerable<VFXData> input, Dictionary<VFXData, uint> dataToSystemIndex)
985+
{
986+
foreach (var data in input)
987+
if (dataToSystemIndex.TryGetValue(data, out var index))
988+
yield return index;
989+
}
979990

980991
public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidation)
981992
{
@@ -1050,7 +1061,7 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
10501061

10511062
Dictionary<VFXContext, VFXContextCompiledData> contextToCompiledData = new Dictionary<VFXContext, VFXContextCompiledData>();
10521063
foreach (var context in compilableContexts)
1053-
contextToCompiledData.Add(context, new VFXContextCompiledData() { indexInShaderSource = -1, indexInSystemDesc = -1 });
1064+
contextToCompiledData.Add(context, new VFXContextCompiledData() { indexInShaderSource = -1 });
10541065

10551066
EditorUtility.DisplayProgressBar(progressBarTitle, "Generating mappings", 5 / nbSteps);
10561067
foreach (var context in compilableContexts)
@@ -1116,7 +1127,8 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
11161127
});
11171128

11181129
var contextSpawnToSpawnInfo = new Dictionary<VFXContext, SpawnInfo>();
1119-
FillSpawner(contextSpawnToSpawnInfo, cpuBufferDescs, systemDescs, compilableContexts, m_ExpressionGraph, contextToCompiledData, ref subgraphInfos, m_Graph.systemNames);
1130+
var dataToSystemIndex = new Dictionary<VFXData, uint>();
1131+
FillSpawner(contextSpawnToSpawnInfo, dataToSystemIndex, cpuBufferDescs, systemDescs, compilableContexts, m_ExpressionGraph, contextToCompiledData, ref subgraphInfos, m_Graph.systemNames);
11201132

11211133
var eventDescs = new List<EventDesc>();
11221134
FillEvent(eventDescs, contextSpawnToSpawnInfo, compilableContexts, compilableData, ref subgraphInfos);
@@ -1127,6 +1139,11 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
11271139
var contextSpawnToBufferIndex = contextSpawnToSpawnInfo.Select(o => new { o.Key, o.Value.bufferIndex }).ToDictionary(o => o.Key, o => o.bufferIndex);
11281140
foreach (var data in compilableData)
11291141
{
1142+
if (!dataToSystemIndex.ContainsKey(data)) //dataToSystemIndex could have been filled by FillSpawner (TODO: rework this approach and always use FillDescs after an appropriate ordering of compilableData)
1143+
{
1144+
dataToSystemIndex.Add(data, (uint)systemDescs.Count);
1145+
}
1146+
11301147
data.FillDescs(VFXGraph.compileReporter,
11311148
bufferDescs,
11321149
temporaryBufferDescs,
@@ -1146,6 +1163,17 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
11461163
throw new InvalidOperationException("There are duplicated entries in OutputEvent");
11471164
}
11481165

1166+
// Early check : dataToSystemIndex should be consistent
1167+
if (compilableData.Except(dataToSystemIndex.Keys).Any())
1168+
{
1169+
throw new InvalidOperationException("Missing system desc among compilable system");
1170+
}
1171+
1172+
if (dataToSystemIndex.Values.Count() != dataToSystemIndex.Distinct().Count())
1173+
{
1174+
throw new InvalidOperationException("Duplicated system index");
1175+
}
1176+
11491177
// Update transient renderer settings
11501178
ShadowCastingMode shadowCastingMode = compilableContexts.OfType<IVFXSubRenderer>().Any(r => r.hasShadowCasting) ? ShadowCastingMode.On : ShadowCastingMode.Off;
11511179
MotionVectorGenerationMode motionVectorGenerationMode = compilableContexts.OfType<IVFXSubRenderer>().Any(r => r.hasMotionVector) ? MotionVectorGenerationMode.Object : MotionVectorGenerationMode.Camera;
@@ -1162,9 +1190,9 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
11621190
return new VFXEventDesc()
11631191
{
11641192
name = e.name,
1165-
initSystems = e.initSystems.Select(s => contextToCompiledData[s].indexInSystemDesc).Where(i => i != -1).Select(i => (uint)i).ToArray(),
1166-
startSystems = e.startSystems.Select(s => contextToCompiledData[s].indexInSystemDesc).Where(i => i != -1).Select(i => (uint)i).ToArray(),
1167-
stopSystems = e.stopSystems.Select(s => contextToCompiledData[s].indexInSystemDesc).Where(i => i != -1).Select(i => (uint)i).ToArray(),
1193+
initSystems = ConvertDataToSystemIndex(e.initSystems, dataToSystemIndex).ToArray(),
1194+
startSystems = ConvertDataToSystemIndex(e.startSystems, dataToSystemIndex).ToArray(),
1195+
stopSystems = ConvertDataToSystemIndex(e.stopSystems, dataToSystemIndex).ToArray()
11681196
};
11691197
}).Where(e =>
11701198
{

com.unity.visualeffectgraph/Editor/Data/VFXDataMesh.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ public override void FillDescs(
157157
if (subMaskIndex != -1)
158158
mappings.Add(new VFXMapping("subMeshMask", subMaskIndex));
159159

160-
var compiledData = contextToCompiledData[context];
161-
compiledData.indexInSystemDesc = outBufferDescs.Count;
162-
contextToCompiledData[context] = compiledData;
163-
164160
outSystemDescs.Add(new VFXEditorSystemDesc()
165161
{
166162
tasks = new VFXEditorTaskDesc[1] { task },

com.unity.visualeffectgraph/Editor/Data/VFXDataOutputEvent.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ public override void FillDescs(
9999
});
100100
}
101101

102-
foreach (var context in allMatchingVFXOutputEvent)
103-
{
104-
var compiledData = contextToCompiledData[context];
105-
compiledData.indexInSystemDesc = outBufferDescs.Count;
106-
contextToCompiledData[context] = compiledData;
107-
}
108-
109102
outSystemDescs.Add(new VFXEditorSystemDesc()
110103
{
111104
flags = VFXSystemFlag.SystemDefault,

com.unity.visualeffectgraph/Editor/Data/VFXDataParticle.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,6 @@ public override void FillDescs(
760760

761761
var context = m_Contexts[i];
762762
var contextData = contextToCompiledData[context];
763-
contextData.indexInSystemDesc = outSystemDescs.Count;
764-
contextToCompiledData[context] = contextData;
765763

766764
var taskDesc = new VFXEditorTaskDesc();
767765
taskDesc.type = (UnityEngine.VFX.VFXTaskType)context.taskType;

0 commit comments

Comments
 (0)