@@ -22,7 +22,6 @@ struct VFXContextCompiledData
22
22
public VFXUniformMapper uniformMapper ;
23
23
public VFXMapping [ ] parameters ;
24
24
public int indexInShaderSource ;
25
- public int indexInSystemDesc ;
26
25
}
27
26
28
27
enum VFXCompilationMode
@@ -577,6 +576,7 @@ private static VFXEditorTaskDesc[] BuildEditorTaksDescFromBlockSpawner(IEnumerab
577
576
}
578
577
579
578
private static void FillSpawner ( Dictionary < VFXContext , SpawnInfo > outContextSpawnToSpawnInfo ,
579
+ Dictionary < VFXData , uint > outDataToSystemIndex ,
580
580
List < VFXCPUBufferDesc > outCpuBufferDescs ,
581
581
List < VFXEditorSystemDesc > outSystemDescs ,
582
582
IEnumerable < VFXContext > contexts ,
@@ -648,7 +648,12 @@ private static void FillSpawner(Dictionary<VFXContext, SpawnInfo> outContextSpaw
648
648
else
649
649
throw new InvalidOperationException ( "system names manager cannot be null" ) ;
650
650
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 ) ;
652
657
contextToCompiledData [ spawnContext ] = contextData ;
653
658
654
659
outSystemDescs . Add ( new VFXEditorSystemDesc ( )
@@ -694,13 +699,13 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
694
699
{
695
700
var contextEffectiveInputLinks = subgraphInfos . contextEffectiveInputLinks ;
696
701
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 ( ) ;
699
704
700
705
var eventDescTemp = new EventDesc [ ]
701
706
{
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 > ( ) } ,
704
709
} . ToList ( ) ;
705
710
706
711
var specialNames = new HashSet < string > ( new string [ ] { VisualEffectAsset . PlayEventName , VisualEffectAsset . StopEventName } ) ;
@@ -724,9 +729,9 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
724
729
eventDescTemp . Add ( new EventDesc
725
730
{
726
731
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 > ( )
730
735
} ) ;
731
736
}
732
737
@@ -738,17 +743,17 @@ private static void FillEvent(List<EventDesc> outEventDesc, Dictionary<VFXContex
738
743
var startSystem = link . slotIndex == 0 ;
739
744
if ( startSystem )
740
745
{
741
- eventDesc . startSystems . Add ( link . context ) ;
746
+ eventDesc . startSystems . Add ( link . context . GetData ( ) ) ;
742
747
}
743
748
else
744
749
{
745
- eventDesc . stopSystems . Add ( link . context ) ;
750
+ eventDesc . stopSystems . Add ( link . context . GetData ( ) ) ;
746
751
}
747
752
}
748
753
}
749
754
else if ( link . context . contextType == VFXContextType . Init )
750
755
{
751
- eventDesc . initSystems . Add ( link . context ) ;
756
+ eventDesc . initSystems . Add ( link . context . GetData ( ) ) ;
752
757
}
753
758
else
754
759
{
@@ -971,11 +976,17 @@ void ComputeEffectiveInputLinks(ref SubgraphInfos subgraphInfos, IEnumerable<VFX
971
976
struct EventDesc
972
977
{
973
978
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 ;
977
982
}
978
983
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
+ }
979
990
980
991
public void Compile ( VFXCompilationMode compilationMode , bool forceShaderValidation )
981
992
{
@@ -1050,7 +1061,7 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
1050
1061
1051
1062
Dictionary < VFXContext , VFXContextCompiledData > contextToCompiledData = new Dictionary < VFXContext , VFXContextCompiledData > ( ) ;
1052
1063
foreach ( var context in compilableContexts )
1053
- contextToCompiledData . Add ( context , new VFXContextCompiledData ( ) { indexInShaderSource = - 1 , indexInSystemDesc = - 1 } ) ;
1064
+ contextToCompiledData . Add ( context , new VFXContextCompiledData ( ) { indexInShaderSource = - 1 } ) ;
1054
1065
1055
1066
EditorUtility . DisplayProgressBar ( progressBarTitle , "Generating mappings" , 5 / nbSteps ) ;
1056
1067
foreach ( var context in compilableContexts )
@@ -1116,7 +1127,8 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
1116
1127
} ) ;
1117
1128
1118
1129
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 ) ;
1120
1132
1121
1133
var eventDescs = new List < EventDesc > ( ) ;
1122
1134
FillEvent ( eventDescs , contextSpawnToSpawnInfo , compilableContexts , compilableData , ref subgraphInfos ) ;
@@ -1127,6 +1139,11 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
1127
1139
var contextSpawnToBufferIndex = contextSpawnToSpawnInfo . Select ( o => new { o . Key , o . Value . bufferIndex } ) . ToDictionary ( o => o . Key , o => o . bufferIndex ) ;
1128
1140
foreach ( var data in compilableData )
1129
1141
{
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
+
1130
1147
data . FillDescs ( VFXGraph . compileReporter ,
1131
1148
bufferDescs ,
1132
1149
temporaryBufferDescs ,
@@ -1146,6 +1163,17 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
1146
1163
throw new InvalidOperationException ( "There are duplicated entries in OutputEvent" ) ;
1147
1164
}
1148
1165
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
+
1149
1177
// Update transient renderer settings
1150
1178
ShadowCastingMode shadowCastingMode = compilableContexts . OfType < IVFXSubRenderer > ( ) . Any ( r => r . hasShadowCasting ) ? ShadowCastingMode . On : ShadowCastingMode . Off ;
1151
1179
MotionVectorGenerationMode motionVectorGenerationMode = compilableContexts . OfType < IVFXSubRenderer > ( ) . Any ( r => r . hasMotionVector ) ? MotionVectorGenerationMode . Object : MotionVectorGenerationMode . Camera ;
@@ -1162,9 +1190,9 @@ public void Compile(VFXCompilationMode compilationMode, bool forceShaderValidati
1162
1190
return new VFXEventDesc ( )
1163
1191
{
1164
1192
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 ( )
1168
1196
} ;
1169
1197
} ) . Where ( e =>
1170
1198
{
0 commit comments