Esempio n. 1
0
 public EntityFilter With <T>() where T : struct
 {
     _withMask |= ComponentId <T> .Id;
     _publisher.Subscribe <ComponentAddedMessage <T> >(ComponentAdded);
     _publisher.Subscribe <ComponentRemovedMessage <T> >(ComponentRemoved);
     return(this);
 }
Esempio n. 2
0
        string GetOperandDescriptionWithMask(Operand operand, ComponentMask mask)
        {
            var name    = GetOperandName(operand);
            var swizzle = GetSwizzle(operand, mask);

            return($"{name}{swizzle}");
        }
Esempio n. 3
0
 internal ShaderPassVertexShaderConstantBlockBase(BinaryReader binaryReader)
 {
     this.sourceParameter     = binaryReader.ReadStringID();
     this.scaleByTextureStage = (ScaleByTextureStage)binaryReader.ReadInt16();
     this.registerBank        = (RegisterBank)binaryReader.ReadInt16();
     this.registerIndex       = binaryReader.ReadInt16();
     this.componentMask       = (ComponentMask)binaryReader.ReadInt16();
 }
Esempio n. 4
0
        public static int GetNumberOfFlagsSet(this ComponentMask mask)
        {
            // Calculate number of bits in a
            // Taken from https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64
            // Works only up to 14 bits (we're only using up to 4)
            ulong c = (((ulong)mask) * 0x200040008001 & 0x111111111111111) % 0xf;

            return((int)c);
        }
 internal PixelShaderConstantBlockBase(BinaryReader binaryReader)
 {
     this.parameterType = (ParameterType)binaryReader.ReadByte();
     this.combinerIndex = binaryReader.ReadByte();
     this.registerIndex = binaryReader.ReadByte();
     this.componentMask = (ComponentMask)binaryReader.ReadByte();
     this.invalidName_  = binaryReader.ReadBytes(1);
     this.invalidName_0 = binaryReader.ReadBytes(1);
 }
Esempio n. 6
0
        public static string GetDescription(this ComponentMask value)
        {
            string result = string.Empty;

            result += (value.HasFlag(ComponentMask.X)) ? "x" : " ";
            result += (value.HasFlag(ComponentMask.Y)) ? "y" : " ";
            result += (value.HasFlag(ComponentMask.Z)) ? "z" : " ";
            result += (value.HasFlag(ComponentMask.W)) ? "w" : " ";

            return(result);
        }
		public SignatureParameterDescription(string semanticName, uint semanticIndex,
			Name systemValueType, RegisterComponentType componentType, uint register,
			ComponentMask mask, ComponentMask readWriteMask)
		{
			SemanticName = semanticName;
			SemanticIndex = semanticIndex;
			Register = register;
			SystemValueType = systemValueType;
			ComponentType = componentType;
			Mask = mask;
			ReadWriteMask = readWriteMask;
		}
 public SignatureParameterDescription(string semanticName, uint semanticIndex,
                                      Name systemValueType, RegisterComponentType componentType, uint register,
                                      ComponentMask mask, ComponentMask readWriteMask)
 {
     SemanticName    = semanticName;
     SemanticIndex   = semanticIndex;
     Register        = register;
     SystemValueType = systemValueType;
     ComponentType   = componentType;
     Mask            = mask;
     ReadWriteMask   = readWriteMask;
 }
Esempio n. 9
0
        public EntityGroup GetGroup(ComponentMask mask)
        {
            if (!m_Groups.TryGetValue(mask, out EntityGroup result))
            {
                result = new EntityGroup(mask);
                for (uint i = 0; i < m_EntityComponentMasks.Count; i++)
                {
                    result.HandleEntity(Get(CreateID(i)));
                }

                m_Groups.Add(mask, result);
            }
            return(result);
        }
Esempio n. 10
0
        internal void Remove <C>(Entity.Id id) where C : class, IComponent, new()
        {
            int entityId = (int)id.Index;
            int family   = ComponentIndexer.GetFamily <C>();

            ComponentMask mask = m_EntityComponentMasks[entityId];

            mask[1 << family] = false;
            m_EntityComponentMasks[entityId] = mask;

            ComponentPool <C> pool = (ComponentPool <C>)m_ComponentPools[family];

            pool.Destroy(entityId);
        }
Esempio n. 11
0
        public Entity CreateFromCopy(Entity original)
        {
            Debug.Assert((bool)original);
            Entity        clone = Create();
            ComponentMask mask  = original.ComponentMask();

            for (int i = 0; i < m_ComponentHelpers.Count; i++)
            {
                BaseComponentHelper helper = m_ComponentHelpers[i];
                if (helper != null && mask[i])
                {
                    helper.CopyComponentTo(original, clone);
                }
            }
            return(clone);
        }
Esempio n. 12
0
        public void Destroy(Entity.Id entity)
        {
            AssertValidID(entity);
            int           index = (int)entity.Index;
            ComponentMask mask  = m_EntityComponentMasks[index];

            for (int i = 0; i < m_ComponentHelpers.Count; i++)
            {
                BaseComponentHelper helper = m_ComponentHelpers[i];
                if (helper != null && mask[i])
                {
                    helper.RemoveComponent(new Entity(this, entity));
                }
            }
            m_EntityComponentMasks[index].Reset();
            m_EntityVersions[index]++;
            m_FreeList.Add((uint)index);
        }
Esempio n. 13
0
        internal C Assign <C>(Entity.Id id, C c) where C : class, IComponent, new()
        {
            AssertValidID(id);
            int           family   = ComponentIndexer.GetFamily <C>();
            int           entityId = (int)id.Index;
            ComponentMask mask     = m_EntityComponentMasks[entityId];

            Debug.Assert(!mask[1 << family]);

            ComponentPool <C> pool = AccommodateComponent <C>();

            pool.Put(c, entityId);

            mask[1 << family] = true;
            m_EntityComponentMasks[entityId] = mask;

            return(c);
        }
Esempio n. 14
0
        string GetSwizzle(Operand operand, ComponentMask mask)
        {
            string components      = string.Empty;
            var    parentType      = operand.ParentType;
            var    numComponents   = operand.NumComponents;
            var    immediateValues = operand.ImmediateValues;
            var    sb = new StringBuilder();

            if (mask == ComponentMask.None)
            {
                return("");
            }
            if (operand.ParentType != OpcodeType.DclConstantBuffer)
            {
                switch (operand.SelectionMode)
                {
                case Operand4ComponentSelectionMode.Mask:
                    var newMask = operand.ComponentMask & mask;
                    components = newMask.GetDescription();
                    break;

                case Operand4ComponentSelectionMode.Swizzle:
                    components = operand.Swizzles[0].GetDescription()
                                 + operand.Swizzles[1].GetDescription()
                                 + operand.Swizzles[2].GetDescription()
                                 + operand.Swizzles[3].GetDescription();
                    break;

                case Operand4ComponentSelectionMode.Select1:
                    components = operand.Swizzles[0].GetDescription();
                    break;

                default:
                    throw new InvalidOperationException("Unrecognised selection mode: " + operand.SelectionMode);
                }
                if (!string.IsNullOrEmpty(components))
                {
                    components = "." + components;
                }
                sb.Append(components);
            }
            return(sb.ToString());
        }
Esempio n. 15
0
 public void WriteMaskedValue(Number4 value, ComponentMask mask)
 {
     if (mask.HasFlag(ComponentMask.X))
     {
         Number0 = value.Number0;
     }
     if (mask.HasFlag(ComponentMask.Y))
     {
         Number1 = value.Number1;
     }
     if (mask.HasFlag(ComponentMask.Z))
     {
         Number2 = value.Number2;
     }
     if (mask.HasFlag(ComponentMask.W))
     {
         Number3 = value.Number3;
     }
 }
Esempio n. 16
0
 public Number GetMaskedNumber(ComponentMask mask)
 {
     if (mask.HasFlag(ComponentMask.X))
     {
         return(Number0);
     }
     if (mask.HasFlag(ComponentMask.Y))
     {
         return(Number1);
     }
     if (mask.HasFlag(ComponentMask.Z))
     {
         return(Number2);
     }
     if (mask.HasFlag(ComponentMask.W))
     {
         return(Number3);
     }
     throw new ArgumentOutOfRangeException("mask");
 }
Esempio n. 17
0
        public EntityGroup GetGroup(ComponentMask mask)
        {
            if (!m_Groups.TryGetValue(mask, out EntityGroup result))
            {
                result = new EntityGroup(mask);
                for (uint i = 0; i < m_EntityComponentMasks.Count; i++)
                {
                    result.HandleEntitySilently(Get(CreateID(i)));
                }
                m_Groups.Add(mask, result);

                foreach (int index in mask.GetSetBits())
                {
                    if (m_GroupsForIndex[index] == null)
                    {
                        m_GroupsForIndex[index] = new List <EntityGroup>();
                    }
                    m_GroupsForIndex[index].Add(result);
                }
            }
            return(result);
        }
Esempio n. 18
0
        public static string GetDescription(this ComponentMask value)
        {
            string result = string.Empty;

            if (value.HasFlag(ComponentMask.X))
            {
                result += "x";
            }
            if (value.HasFlag(ComponentMask.Y))
            {
                result += "y";
            }
            if (value.HasFlag(ComponentMask.Z))
            {
                result += "z";
            }
            if (value.HasFlag(ComponentMask.W))
            {
                result += "w";
            }

            return(result);
        }
Esempio n. 19
0
 internal bool Matches(Entity.Id m_ID, ComponentMask mask)
 {
     return((m_EntityComponentMasks[(int)m_ID.Index] & mask) == mask);
 }
Esempio n. 20
0
        public override string ToString()
        {
            switch (OperandType)
            {
            case OperandType.Immediate32:
            case OperandType.Immediate64:
            {
                string result    = (OperandType == OperandType.Immediate64) ? "d(" : "l(";
                bool   addSpaces = ParentType != OpcodeType.Mov && ParentType != OpcodeType.MovC && ParentType != OpcodeType.StoreStructured;
                for (int i = 0; i < NumComponents; i++)
                {
                    var parentType = ParentType.GetNumberType();
                    result += (OperandType == OperandType.Immediate64)
                                                                ? ImmediateValues.GetDouble(i).ToString()
                                                                : ImmediateValues.GetNumber(i).ToString(parentType);

                    if (i < NumComponents - 1)
                    {
                        result += ",";
                        if (addSpaces)
                        {
                            result += " ";
                        }
                    }
                }
                result += ")";
                return(result);
            }

            case OperandType.Null:
            {
                return(OperandType.GetDescription());
            }

            default:
            {
                string index = string.Empty;
                switch (IndexDimension)
                {
                case OperandIndexDimension._0D:
                    break;

                case OperandIndexDimension._1D:
                    index = (Indices[0].Representation == OperandIndexRepresentation.Relative ||
                             Indices[0].Representation == OperandIndexRepresentation.Immediate32PlusRelative ||
                             !OperandType.RequiresRegisterNumberFor1DIndex())
                                                                        ? string.Format("[{0}]", Indices[0])
                                                                        : Indices[0].ToString();
                    break;

                case OperandIndexDimension._2D:
                    index = (Indices[0].Representation == OperandIndexRepresentation.Relative ||
                             Indices[0].Representation == OperandIndexRepresentation.Immediate32PlusRelative ||
                             !OperandType.RequiresRegisterNumberFor2DIndex())
                                                                        ? string.Format("[{0}][{1}]", Indices[0], Indices[1])
                                                                        : string.Format("{0}[{1}]", Indices[0], Indices[1]);
                    break;

                case OperandIndexDimension._3D:
                    index = ParentType.IsDeclaration()
                                                                                ? string.Format("{0}[{1}:{2}]", Indices[0], Indices[1], Indices[2])
                                                                                : string.Format("{0}[{1}][{2}]", Indices[0], Indices[1], Indices[2]);
                    break;
                }

                string components = string.Empty;
                if (ParentType.OpcodeHasSwizzle())
                {
                    switch (SelectionMode)
                    {
                    case Operand4ComponentSelectionMode.Mask:
                        components = ComponentMask.GetDescription();
                        break;

                    case Operand4ComponentSelectionMode.Swizzle:
                        components = Swizzles[0].GetDescription()
                                     + Swizzles[1].GetDescription()
                                     + Swizzles[2].GetDescription()
                                     + Swizzles[3].GetDescription();
                        break;

                    case Operand4ComponentSelectionMode.Select1:
                        components = Swizzles[0].GetDescription();
                        break;

                    default:
                        throw new InvalidOperationException("Unrecognised selection mode: " + SelectionMode);
                    }
                    if (!string.IsNullOrEmpty(components))
                    {
                        components = "." + components;
                    }
                }
                string minPrecision = MinPrecision == OperandMinPrecision.Default ?
                                      string.Empty : $" {MinPrecision.GetDescription()}";
                return(Modifier.Wrap(string.Format("{0}{1}{2}{3}", GetOperandDescription(), index, components, minPrecision)));
            }
            }
        }
Esempio n. 21
0
 public EntityGroup(ComponentMask matcher)
 {
     Matcher = matcher;
 }
Esempio n. 22
0
        public static int GetNumSwizzleElementsWithMask(this Operand operand, ComponentMask mask)
        {
            switch (operand.OperandType)
            {
            case OperandType.InputThreadIDInGroupFlattened:
                return(1);

            case OperandType.InputThreadIDInGroup:
            case OperandType.InputThreadID:
            case OperandType.InputThreadGroupID:
                return(operand.NumComponents);

            case OperandType.Immediate32:
            case OperandType.Immediate64:
            case OperandType.OutputDepthGreaterEqual:
            case OperandType.OutputDepthLessEqual:
            case OperandType.OutputDepth:
                // Translate numComponents into bitmask
                // 1 -> 1, 2 -> 3, 3 -> 7 and 4 -> 15
                ComponentMask compMask = (ComponentMask)(1 << operand.NumComponents) - 1;
                compMask &= mask;
                return(compMask.GetNumberOfFlagsSet());
            }
            int count = 0;

            if (operand.NumComponents != 1)
            {
                if (operand.SelectionMode == Operand4ComponentSelectionMode.Mask)
                {
                    var compMask = operand.ComponentMask & mask;
                    if (compMask == ComponentMask.All)
                    {
                        return(4);
                    }
                    if (compMask.HasFlag(ComponentMask.X))
                    {
                        count++;
                    }
                    if (compMask.HasFlag(ComponentMask.Y))
                    {
                        count++;
                    }
                    if (compMask.HasFlag(ComponentMask.Z))
                    {
                        count++;
                    }
                    if (compMask.HasFlag(ComponentMask.W))
                    {
                        count++;
                    }
                }
                else if (operand.SelectionMode == Operand4ComponentSelectionMode.Swizzle)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (((int)mask & (1 << i)) == 0)
                        {
                            continue;
                        }
                        if (operand.Swizzles[0] == Operand4ComponentName.X)
                        {
                            count++;
                        }
                        if (operand.Swizzles[0] == Operand4ComponentName.Y)
                        {
                            count++;
                        }
                        if (operand.Swizzles[0] == Operand4ComponentName.Z)
                        {
                            count++;
                        }
                        if (operand.Swizzles[0] == Operand4ComponentName.W)
                        {
                            count++;
                        }
                    }
                }
                else if (operand.SelectionMode == Operand4ComponentSelectionMode.Select1)
                {
                    if (operand.Swizzles[0] == Operand4ComponentName.X && mask.HasFlag(ComponentMask.X))
                    {
                        count++;
                    }
                    if (operand.Swizzles[0] == Operand4ComponentName.Y && mask.HasFlag(ComponentMask.Y))
                    {
                        count++;
                    }
                    if (operand.Swizzles[0] == Operand4ComponentName.Z && mask.HasFlag(ComponentMask.Z))
                    {
                        count++;
                    }
                    if (operand.Swizzles[0] == Operand4ComponentName.W && mask.HasFlag(ComponentMask.W))
                    {
                        count++;
                    }
                }
            }
            if (count == 0)
            {
                var compMask = (ComponentMask)((1 << operand.NumComponents) - 1);
                compMask &= mask;
                return(compMask.GetNumberOfFlagsSet());
            }
            return(count);
        }
Esempio n. 23
0
		public void WriteMaskedValue(Number4 value, ComponentMask mask)
		{
			if (mask.HasFlag(ComponentMask.X))
				Number0 = value.Number0;
			if (mask.HasFlag(ComponentMask.Y))
				Number1 = value.Number1;
			if (mask.HasFlag(ComponentMask.Z))
				Number2 = value.Number2;
			if (mask.HasFlag(ComponentMask.W))
				Number3 = value.Number3;
		}
Esempio n. 24
0
		public Number GetMaskedNumber(ComponentMask mask)
		{
			if (mask.HasFlag(ComponentMask.X))
				return Number0;
			if (mask.HasFlag(ComponentMask.Y))
				return Number1;
			if (mask.HasFlag(ComponentMask.Z))
				return Number2;
			if (mask.HasFlag(ComponentMask.W))
				return Number3;
			throw new ArgumentOutOfRangeException("mask");
		}
Esempio n. 25
0
 void WriteOperandWithMask(Operand operand, ComponentMask mask)
 {
     Output.Append(GetOperandDescriptionWithMask(operand, mask));
 }
Esempio n. 26
0
 public int ComponentMaskIndexByType()
 {
     return(ComponentMask.GetComponentIndex(typeof(TestComponentThing)));
 }
Esempio n. 27
0
 public int ComponentMaskIndex()
 {
     return(ComponentMask.GetComponentIndex <TestComponentThing>());
 }