Beispiel #1
0
        public VFXAttributeMode GetAttributeMode(VFXAttribute attrib)
        {
            VFXAttributeMode mode = VFXAttributeMode.None;
            Dictionary <VFXContext, VFXAttributeMode> contexts;

            if (m_AttributesToContexts.TryGetValue(attrib, out contexts))
            {
                foreach (var context in contexts)
                {
                    mode |= context.Value;
                }
            }

            return(mode);
        }
Beispiel #2
0
        private string GetByteAddressBufferMethodSuffix(VFXAttribute attrib)
        {
            int size = VFXExpression.TypeToSize(attrib.type);

            if (size == 1)
            {
                return(string.Empty);
            }
            else if (size <= 4)
            {
                return(size.ToString());
            }
            else
            {
                throw new ArgumentException(string.Format("Attribute {0} of type {1} cannot be handled in ByteAddressBuffer due to its size of {2}", attrib.name, attrib.type, size));
            }
        }
Beispiel #3
0
        public VFXAttributeMode GetAttributeMode(VFXAttribute attrib, VFXContext context)
        {
            Dictionary <VFXContext, VFXAttributeMode> contexts;

            if (m_AttributesToContexts.TryGetValue(attrib, out contexts))
            {
                foreach (var c in contexts)
                {
                    if (c.Key == context)
                    {
                        return(c.Value);
                    }
                }
            }

            return(VFXAttributeMode.None);
        }
Beispiel #4
0
        public override string GetLoadAttributeCode(VFXAttribute attrib, VFXAttributeLocation location)
        {
            var attributeStore  = location == VFXAttributeLocation.Current ? m_layoutAttributeCurrent : m_layoutAttributeSource;
            var attributeBuffer = location == VFXAttributeLocation.Current ? "attributeBuffer" : "sourceAttributeBuffer";
            var index           = location == VFXAttributeLocation.Current ? "index" : "sourceIndex";

            if (location == VFXAttributeLocation.Current && !m_StoredCurrentAttributes.ContainsKey(attrib))
            {
                throw new ArgumentException(string.Format("Attribute {0} does not exist in data layout", attrib.name));
            }

            if (location == VFXAttributeLocation.Source && !m_ReadSourceAttributes.Any(a => a.name == attrib.name))
            {
                throw new ArgumentException(string.Format("Attribute {0} does not exist in data layout", attrib.name));
            }

            return(string.Format("{0}({3}.Load{1}({2}))", GetCastAttributePrefix(attrib), GetByteAddressBufferMethodSuffix(attrib), attributeStore.GetCodeOffset(attrib, index), attributeBuffer));
        }
        static private VFXShaderWriter GenerateComputeSourceIndex(VFXContext context)
        {
            var r = new VFXShaderWriter();
            var spawnCountAttribute = new VFXAttribute("spawnCount", VFXValueType.Float);

            if (!context.GetData().dependenciesIn.Any())
            {
                var spawnLinkCount = context.GetData().sourceCount;
                r.WriteLine("int sourceIndex = 0;");

                if (spawnLinkCount <= 1)
                {
                    r.WriteLine("/*//Loop with 1 iteration generate a wrong IL Assembly (and actually, useless code)");
                }

                r.WriteLine("uint currentSumSpawnCount = 0u;");
                r.WriteLineFormat("for (sourceIndex=0; sourceIndex<{0}; sourceIndex++)", spawnLinkCount);
                r.EnterScope();
                r.WriteLineFormat("currentSumSpawnCount += uint({0});", context.GetData().GetLoadAttributeCode(spawnCountAttribute, VFXAttributeLocation.Source));
                r.WriteLine("if (id < currentSumSpawnCount)");
                r.EnterScope();
                r.WriteLine("break;");
                r.ExitScope();
                r.ExitScope();

                if (spawnLinkCount <= 1)
                {
                    r.WriteLine("*/");
                }
            }
            else
            {
                /* context invalid or GPU event */
            }
            return(r);
        }
Beispiel #6
0
 public bool IsSourceAttributeUsed(VFXAttribute attrib)
 {
     return((GetAttributeMode(attrib) & VFXAttributeMode.ReadSource) != 0);
 }
Beispiel #7
0
 public bool IsCurrentAttributeUsed(VFXAttribute attrib, VFXContext context)
 {
     return((GetAttributeMode(attrib, context) & VFXAttributeMode.ReadWrite) != 0);
 }
Beispiel #8
0
 public bool IsCurrentAttributeUsed(VFXAttribute attrib)
 {
     return((GetAttributeMode(attrib) & VFXAttributeMode.ReadWrite) != 0);
 }
 public VFXAttributeInfo(VFXAttribute attrib, VFXAttributeMode mode)
 {
     this.attrib = attrib;
     this.mode   = mode;
 }
Beispiel #10
0
 public abstract string GetLoadAttributeCode(VFXAttribute attrib, VFXAttributeLocation location);
Beispiel #11
0
 public bool IsAttributeStored(VFXAttribute attrib)
 {
     return(m_StoredCurrentAttributes.ContainsKey(attrib));
 }
Beispiel #12
0
 public override string GetStoreAttributeCode(VFXAttribute attrib, string value)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 public override string GetLoadAttributeCode(VFXAttribute attrib, VFXAttributeLocation location)
 {
     throw new NotImplementedException();
 }
        protected override VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
        {
            var attribute = VFXAttribute.Find(this.attribute);

            if (attribute.variadic == VFXVariadic.True)
            {
                var attributes  = new VFXAttribute[] { VFXAttribute.Find(attribute.name + "X"), VFXAttribute.Find(attribute.name + "Y"), VFXAttribute.Find(attribute.name + "Z") };
                var expressions = attributes.Select(a => new VFXAttributeExpression(a, location)).ToArray();

                var componentStack = new Stack <VFXExpression>();
                int outputSize     = mask.Length;
                for (int iComponent = 0; iComponent < outputSize; iComponent++)
                {
                    char componentChar    = char.ToLower(mask[iComponent]);
                    int  currentComponent = Math.Min(componentChar - 'x', 2);
                    componentStack.Push(expressions[currentComponent]);
                }

                VFXExpression finalExpression = null;
                if (componentStack.Count == 1)
                {
                    finalExpression = componentStack.Pop();
                }
                else
                {
                    finalExpression = new VFXExpressionCombine(componentStack.Reverse().ToArray());
                }
                return(new[] { finalExpression });
            }
            else
            {
                var expression = new VFXAttributeExpression(attribute, location);
                return(new VFXExpression[] { expression });
            }
        }
 public VFXAttributeExpression(VFXAttribute attribute, VFXAttributeLocation location = VFXAttributeLocation.Current) : base(Flags.PerElement)
 {
     m_attribute         = attribute;
     m_attributeLocation = location;
 }
Beispiel #16
0
 public bool IsSourceAttributeUsed(VFXAttribute attrib, VFXContext context)
 {
     return((GetAttributeMode(attrib, context) & VFXAttributeMode.ReadSource) != 0);
 }
Beispiel #17
0
 public bool IsAttributeLocal(VFXAttribute attrib)
 {
     return(m_LocalCurrentAttributes.Contains(attrib));
 }
Beispiel #18
0
 public bool IsCurrentAttributeWritten(VFXAttribute attrib)
 {
     return((GetAttributeMode(attrib) & VFXAttributeMode.Write) != 0);
 }
Beispiel #19
0
 public bool IsCurrentAttributeWritten(VFXAttribute attrib, VFXContext context)
 {
     return((GetAttributeMode(attrib, context) & VFXAttributeMode.Write) != 0);
 }
Beispiel #20
0
 public bool IsAttributeUsed(VFXAttribute attrib)
 {
     return(GetAttributeMode(attrib) != VFXAttributeMode.None);
 }
Beispiel #21
0
 protected bool HasImplicitInit(VFXAttribute attrib)
 {
     return(attrib.Equals(VFXAttribute.Seed) || attrib.Equals(VFXAttribute.ParticleId));
 }
Beispiel #22
0
 public bool IsAttributeUsed(VFXAttribute attrib, VFXContext context)
 {
     return(GetAttributeMode(attrib, context) != VFXAttributeMode.None);
 }
Beispiel #23
0
 public abstract string GetStoreAttributeCode(VFXAttribute attrib, string value);
 public VFXReadEventAttributeExpression(VFXAttribute attribute, UInt32 elementOffset) : base(Flags.PerSpawn | Flags.InvalidOnGPU)
 {
     m_attribute     = attribute;
     m_elementOffset = elementOffset;
 }