Example #1
0
        public BucketInfo[] GetBucketLayoutInfo()
        {
            int count = m_BucketSizes.Count;

            BucketInfo[] buckets = new BucketInfo[count];
            for (int i = 0; i < count; i++)
            {
                int size = m_BucketSizes[i];
                buckets[i].size       = size;
                buckets[i].usedSize   = 0;
                buckets[i].attributes = new VFXAttribute[size];
                buckets[i].channels   = new int[size];
            }

            foreach (var kvp in m_AttributeLayout)
            {
                var attrib = kvp.Key;
                int size   = VFXValue.TypeToSize(attrib.type);
                int offset = kvp.Value.offset;
                for (int i = 0; i < size; i++)
                {
                    buckets[kvp.Value.bucket].attributes[i + offset] = attrib;
                    buckets[kvp.Value.bucket].channels[i + offset]   = i;
                    buckets[kvp.Value.bucket].usedSize = Math.Max(buckets[kvp.Value.bucket].usedSize, i + offset + 1);
                }
            }

            return(buckets);
        }
Example #2
0
        public void WriteCBuffer(VFXUniformMapper mapper, string bufferName)
        {
            var uniformValues = mapper.uniforms
                                .Where(e => !e.IsAny(VFXExpression.Flags.Constant | VFXExpression.Flags.InvalidOnCPU)) // Filter out constant expressions
                                .OrderByDescending(e => VFXValue.TypeToSize(e.valueType));

            var uniformBlocks = new List <List <VFXExpression> >();

            foreach (var value in uniformValues)
            {
                var block = uniformBlocks.FirstOrDefault(b => b.Sum(e => VFXValue.TypeToSize(e.valueType)) + VFXValue.TypeToSize(value.valueType) <= 4);
                if (block != null)
                {
                    block.Add(value);
                }
                else
                {
                    uniformBlocks.Add(new List <VFXExpression>()
                    {
                        value
                    });
                }
            }

            if (uniformBlocks.Count > 0)
            {
                WriteLineFormat("CBUFFER_START({0})", bufferName);
                Indent();

                int paddingIndex = 0;
                foreach (var block in uniformBlocks)
                {
                    int currentSize = 0;
                    foreach (var value in block)
                    {
                        string type = VFXExpression.TypeToUniformCode(value.valueType);
                        string name = mapper.GetName(value);
                        if (name.StartsWith("unity_")) //Reserved unity variable name (could be filled manually see : VFXMotionVector)
                        {
                            continue;
                        }

                        currentSize += VFXExpression.TypeToSize(value.valueType);

                        WriteLineFormat("{0} {1};", type, name);
                    }

                    WritePadding(4, currentSize, ref paddingIndex);
                }

                Deindent();
                WriteLine("CBUFFER_END");
            }
        }
Example #3
0
        // return size
        private int GenerateBucketLayout(List <VFXAttribute> attributes, int bucketId)
        {
            var sortedAttrib = attributes.OrderByDescending(a => VFXValue.TypeToSize(a.type));

            var attribBlocks = new List <List <VFXAttribute> >();

            foreach (var value in sortedAttrib)
            {
                var block = attribBlocks.FirstOrDefault(b => b.Sum(a => VFXValue.TypeToSize(a.type)) + VFXValue.TypeToSize(value.type) <= 4);
                if (block != null)
                {
                    block.Add(value);
                }
                else
                {
                    attribBlocks.Add(new List <VFXAttribute>()
                    {
                        value
                    });
                }
            }

            int currentOffset = 0;
            int minAlignment  = 0;

            foreach (var block in attribBlocks)
            {
                foreach (var attrib in block)
                {
                    int size      = VFXValue.TypeToSize(attrib.type);
                    int alignment = size > 2 ? 4 : size;
                    minAlignment = Math.Max(alignment, minAlignment);
                    // align offset
                    currentOffset = (currentOffset + alignment - 1) & ~(alignment - 1);
                    m_AttributeLayout.Add(attrib, new AttributeLayout(bucketId, currentOffset));
                    currentOffset += size;
                }
            }

            return((currentOffset + minAlignment - 1) & ~(minAlignment - 1));
        }