Esempio n. 1
0
        private void CompileExpressionContext(IEnumerable <VFXContext> contexts,
                                              VFXExpressionContextOption options,
                                              VFXDeviceTarget target,
                                              VFXExpression.Flags forbiddenFlags = VFXExpression.Flags.None)
        {
            var expressionContext = new VFXExpression.Context(options, m_GlobalEventAttributes);

            var contextsToExpressions = target == VFXDeviceTarget.GPU ? m_ContextsToGPUExpressions : m_ContextsToCPUExpressions;
            var expressionsToReduced  = target == VFXDeviceTarget.GPU ? m_GPUExpressionsToReduced : m_CPUExpressionsToReduced;

            foreach (var context in contexts)
            {
                var mapper = context.GetExpressionMapper(target);
                if (mapper != null)
                {
                    foreach (var exp in mapper.expressions)
                    {
                        expressionContext.RegisterExpression(exp);
                    }
                    contextsToExpressions.Add(context, mapper);
                }
            }

            expressionContext.Compile();

            foreach (var exp in expressionContext.RegisteredExpressions)
            {
                var reduced = expressionContext.GetReduced(exp);
                if (expressionsToReduced.ContainsKey(exp))
                {
                    if (reduced != expressionsToReduced[exp])
                    {
                        throw new InvalidOperationException("Unexpected diverging expression reduction");
                    }
                    continue;
                }
                expressionsToReduced.Add(exp, reduced);
            }

            var allReduced = expressionContext.BuildAllReduced();

            m_Expressions.UnionWith(allReduced);

            foreach (var exp in expressionsToReduced.Values)
            {
                AddExpressionDataRecursively(m_ExpressionsData, exp);
            }

            var graphicsBufferUsageType = m_GraphicsBufferUsageType
                                          .Concat(expressionContext.GraphicsBufferUsageType)
                                          .GroupBy(o => o.Key).ToArray();

            m_GraphicsBufferUsageType.Clear();
            foreach (var expression in graphicsBufferUsageType)
            {
                var types = expression.Select(o => o.Value);
                if (types.Count() != 1)
                {
                    throw new InvalidOperationException("Diverging type usage for GraphicsBuffer : " + types.Select(o => o.ToString()).Aggregate((a, b) => a + b));
                }
                m_GraphicsBufferUsageType.Add(expression.Key, types.First());
            }
        }