@@ -56,7 +56,7 @@ private void CompileExpressionContext(IEnumerable<VFXContext> contexts,
56
56
if ( mapper != null )
57
57
{
58
58
foreach ( var exp in mapper . expressions )
59
- expressionContext . RegisterExpression ( exp ) ;
59
+ expressionContext . RegisterExpression ( exp , context ) ;
60
60
contextsToExpressions . Add ( context , mapper ) ;
61
61
}
62
62
}
@@ -82,22 +82,18 @@ private void CompileExpressionContext(IEnumerable<VFXContext> contexts,
82
82
foreach ( var exp in expressionsToReduced . Values )
83
83
AddExpressionDataRecursively ( m_ExpressionsData , exp ) ;
84
84
85
- var bufferUsage = m_BufferUsage
86
- . Concat ( expressionContext . GraphicsBufferUsageType )
87
- . GroupBy ( o => o . Key ) . ToArray ( ) ;
88
-
89
- m_BufferUsage . Clear ( ) ;
90
- foreach ( var expression in bufferUsage )
85
+ foreach ( var bufferTypeUsage in expressionContext . GraphicsBufferTypeUsagePerContext )
91
86
{
92
- var types = expression . Select ( o => o . Value ) ;
93
- if ( types . Count ( ) != 1 )
94
- throw new InvalidOperationException ( "Diverging type usage for GraphicsBuffer : " + types . Select ( o => o . ToString ( ) ) . Aggregate ( ( a , b ) => a + b ) ) ;
95
- m_BufferUsage . Add ( expression . Key , types . First ( ) ) ;
87
+ m_BufferTypeUsagePerContext . TryAdd ( bufferTypeUsage . Key , bufferTypeUsage . Value ) ;
96
88
}
97
89
90
+
98
91
if ( target == VFXDeviceTarget . GPU )
99
92
{
100
- m_CustomHLSLExpressions = expressionContext . hlslCodeHolders ;
93
+ foreach ( var hlslCodeHolder in expressionContext . hlslCodeHoldersPerContext )
94
+ {
95
+ m_CustomHLSLExpressionsPerContext . Add ( hlslCodeHolder . Key , hlslCodeHolder . Value ) ;
96
+ }
101
97
}
102
98
}
103
99
@@ -294,12 +290,27 @@ private VFXExpressionMapper BuildMapper(VFXContext context, Dictionary<VFXContex
294
290
295
291
public IEnumerable < VFXLayoutElementDesc > GlobalEventAttributes => m_GlobalEventAttributes ;
296
292
297
- public ReadOnlyDictionary < VFXExpression , BufferUsage > BufferUsage => new ReadOnlyDictionary < VFXExpression , BufferUsage > ( m_BufferUsage ) ;
293
+ public ReadOnlyDictionary < VFXExpression , BufferUsage > GetBufferTypeUsage ( VFXContext context )
294
+ {
295
+ if ( m_BufferTypeUsagePerContext . TryGetValue ( context , out var bufferTypeUsage ) )
296
+ {
297
+ return new ReadOnlyDictionary < VFXExpression , BufferUsage > ( bufferTypeUsage ) ;
298
+ }
298
299
299
- public IHLSLCodeHolder [ ] customHLSLExpressions => m_CustomHLSLExpressions ;
300
+ return new ReadOnlyDictionary < VFXExpression , BufferUsage > ( new Dictionary < VFXExpression , BufferUsage > ( ) ) ;
301
+ }
302
+
303
+ public IHLSLCodeHolder [ ] GetCustomHLSLExpressions ( VFXContext context )
304
+ {
305
+ if ( m_CustomHLSLExpressionsPerContext . TryGetValue ( context , out var hlslCodeHolders ) )
306
+ {
307
+ return hlslCodeHolders . ToArray ( ) ;
308
+ }
309
+ return Array . Empty < IHLSLCodeHolder > ( ) ;
310
+ }
300
311
301
- private IHLSLCodeHolder [ ] m_CustomHLSLExpressions ;
302
- private Dictionary < VFXExpression , BufferUsage > m_BufferUsage = new Dictionary < VFXExpression , BufferUsage > ( ) ;
312
+ private Dictionary < VFXContext , List < IHLSLCodeHolder > > m_CustomHLSLExpressionsPerContext = new ( ) ;
313
+ private Dictionary < VFXContext , Dictionary < VFXExpression , BufferUsage > > m_BufferTypeUsagePerContext = new ( ) ;
303
314
private HashSet < VFXExpression > m_Expressions = new HashSet < VFXExpression > ( ) ;
304
315
private Dictionary < VFXExpression , VFXExpression > m_CPUExpressionsToReduced = new Dictionary < VFXExpression , VFXExpression > ( ) ;
305
316
private Dictionary < VFXExpression , VFXExpression > m_GPUExpressionsToReduced = new Dictionary < VFXExpression , VFXExpression > ( ) ;
0 commit comments