Ejemplo n.º 1
0
        /// <summary>
        ///   Creates merged parameter from given combination.
        /// </summary>
        /// <param name="combination"> The merge combination to try. </param>
        /// <param name="paramsTable"> The params table sorted by tpes in each row. </param>
        /// <param name="mergedParameter"> Will hold the merged parameter </param>
        /// <returns> </returns>
        internal static bool MergeParametersByCombination(MergeCombination combination, List <Parameter>[] paramsTable,
                                                          out MergeParameter mergedParameter)
        {
            mergedParameter = new MergeParameter();
            //Make sure we have enough parameters to combine.
            if (combination.srcParameterTypeCount[0] > paramsTable[0].Count ||
                combination.srcParameterTypeCount[1] > paramsTable[1].Count ||
                combination.srcParameterTypeCount[2] > paramsTable[2].Count ||
                combination.srcParameterTypeCount[3] > paramsTable[3].Count)
            {
                return(false);
            }

            //Create the new output parameter.
            for (int i = 0; i < 4; ++i)
            {
                var curParamList          = paramsTable[i];
                int srcParameterTypeCount = combination.srcParameterTypeCount[i];
                int srcParameterCount     = 0;

                while (srcParameterCount > 0)
                {
                    mergedParameter.AddSourceParameter(curParamList[curParamList.Count - 1],
                                                       combination.srcParameterMask[srcParameterCount]);
                    curParamList.RemoveAt(curParamList.Count - 1);
                    srcParameterCount++;
                    --srcParameterTypeCount;
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Replace references to old parameters with the new merged parameters.
        /// </summary>
        /// <param name="mergedParams"> </param>
        /// <param name="paramsRefMap"> </param>
        internal static void ReplaceParametersReferences(List <MergeParameter> mergedParams,
                                                         Dictionary <Parameter, List <Operand> > paramsRefMap)
        {
            for (int i = 0; i < mergedParams.Count; i++)
            {
                MergeParameter curMergeParameter  = mergedParams[i];
                int            paramBitMaskOffset = 0;

                for (int j = 0; j < curMergeParameter.SourceParameterCount; j++)
                {
                    Parameter curSrcParam = curMergeParameter.SourceParameter[j];

                    //Case the source parameter has some references
                    if (paramsRefMap.ContainsKey(curSrcParam))
                    {
                        List <Operand> srcParamRefs = paramsRefMap[curSrcParam];
                        Parameter      dstParameter;

                        //Case the source paramter is fully contained within the destination merged parameter.
                        if (curMergeParameter.GetSourceParameterMask(j) == (int)Operand.OpMask.All)
                        {
                            dstParameter = curMergeParameter.GetDestinationParameter((int)Operand.OpSemantic.InOut, i);

                            for (int op = 0; op < srcParamRefs.Count; op++)
                            {
                                Operand srcOperand = srcParamRefs[op];
                                int     dstOpMask;

                                if (srcOperand.Mask == (int)Operand.OpMask.All)
                                {
                                    //Case the merged parameter contains only one source - no point in adding special mask.
                                    if (curMergeParameter.SourceParameterCount == 1)
                                    {
                                        dstOpMask = (int)Operand.OpMask.All;
                                    }
                                    else
                                    {
                                        dstOpMask = GetParameterMaskByType(curSrcParam.Type) << paramBitMaskOffset;
                                    }
                                }
                                else
                                {
                                    dstOpMask = srcOperand.Mask << paramBitMaskOffset;
                                }
                                // Replace the original source operand with a new operand the reference the new merged parameter.
                                srcOperand = new Operand(dstParameter, srcOperand.Semantic, dstOpMask, 0);
                            }
                        }
                    }

                    //Update the bit mask offset
                    paramBitMaskOffset += GetParameterFloatCount(curSrcParam.Type);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Rebuild the given parameters list using the merged parameters.
        /// </summary>
        internal static void RebuildParameterList(Function fun, int paramsUsage, List <MergeParameter> mergedParams)
        {
            //Delete the old merged paramters.
            for (int i = 0; i < mergedParams.Count; ++i)
            {
                var curMergeParamter = mergedParams[i];

                for (int j = 0; j < curMergeParamter.SourceParameterCount; ++j)
                {
                    Parameter curSrcParam = curMergeParamter.SourceParameter[j];

                    if (paramsUsage == (int)Operand.OpSemantic.Out)
                    {
                        fun.DeleteOutputParameter(curSrcParam);
                    }
                    else if (paramsUsage == (int)Operand.OpSemantic.In)
                    {
                        fun.DeleteInputParameter(curSrcParam);
                    }
                }
            }

            //Add the new combined paramters.
            for (int i = 0; i < mergedParams.Count; ++i)
            {
                MergeParameter curMergeParameter = mergedParams[i];

                if (paramsUsage == (int)Operand.OpSemantic.Out)
                {
                    fun.AddOutputParameter(curMergeParameter.GetDestinationParameter(paramsUsage, i));
                }
                else if (paramsUsage == (int)Operand.OpSemantic.In)
                {
                    fun.AddInputParameter(curMergeParameter.GetDestinationParameter(paramsUsage, i));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Merge reminders parameters that could not be merged into one slot using the predefined combinations.
        /// </summary>
        /// <param name="paramsTable"> The params table sorted by types in each row. </param>
        /// <param name="mergedParams"> The merged parameters list </param>
        /// <param name="splitParams"> The split parameters list </param>
        internal static void MergeParametersReminders(List <Parameter>[] paramsTable, List <MergeParameter> mergedParams,
                                                      List <Parameter> splitParams)
        {
            //Handle reminders parameters - All of the parameters that could not be packed perfectly.
            int mergedParamsBaseIndex = mergedParams.Count;
            int remindersFloatCount   = (1 * paramsTable[0].Count) + (2 * paramsTable[1].Count) +
                                        (3 * paramsTable[2].Count) + (4 * paramsTable[3].Count);
            int reminderFloatMod          = remindersFloatCount % 4;
            int remindersFullSlotCount    = remindersFloatCount / 4;
            int remindersPartialSlotCount = reminderFloatMod > 0 ? 1 : 0;
            int remindersTotalSlotCount   = remindersFullSlotCount + remindersPartialSlotCount;

            //First pass -> fill the slots with the largest reminders paramters.
            for (int slot = 0; slot < remindersTotalSlotCount; ++slot)
            {
                MergeParameter curMergeParam;

                for (int row = 0; row < 4; ++row)
                {
                    List <Parameter> curParamList = paramsTable[3 - row];

                    //Case this list contains parameters - remove it and add to merged params.
                    if (curParamList.Count > 0)
                    {
                        curMergeParam = new MergeParameter();
                        curMergeParam.AddSourceParameter(curParamList[curParamList.Count - 1],
                                                         (int)Operand.OpMask.All);
                        curParamList.RemoveAt(curParamList.Count - 1);
                        mergedParams.Add(curMergeParam);
                    }
                }
            }

            //Second pass -> merge the reminders parameters.
            for (int row = 0; row < 4; ++row)
            {
                var curParamList = paramsTable[3 - row];

                //Merge the all the paramters of the current list.
                while (curParamList.Count > 0)
                {
                    Parameter srcParameter = curParamList[curParamList.Count - 1];
                    int       splitCount   = 0;             // How many times the source paramter has been split.
                    int       srcParamterComponents;
                    int       srcParameterFloats;
                    int       curSrcParameterFloats;

                    srcParameterFloats    = GetParameterFloatCount(srcParameter.Type);
                    curSrcParameterFloats = srcParameterFloats;
                    srcParamterComponents = GetParameterMaskByType(srcParameter.Type);

                    //while this parameter has remaining components -> split it.
                    while (curSrcParameterFloats > 0)
                    {
                        for (int slot = 0; slot < remindersTotalSlotCount && curSrcParameterFloats > 0; ++slot)
                        {
                            MergeParameter curMergeParam  = mergedParams[mergedParamsBaseIndex + slot];
                            int            freeFloatCount = 4 - curMergeParam.UsedFloatCount;

                            //Case this slot has free space.
                            if (freeFloatCount > 0)
                            {
                                //Case current components of source paramter can go all into this slot without split.
                                if (srcParameterFloats < freeFloatCount && splitCount == 0)
                                {
                                    curMergeParam.AddSourceParameter(srcParameter, (int)Operand.OpMask.All);
                                }
                                //case we have to split the current source parameter
                            }
                            else
                            {
                                int srcComponentMask;

                                //Create the mask that tell us which part of the source componetn is added to the merged paramter.
                                srcComponentMask = GetParameterMaskByFloatCount(freeFloatCount) << splitCount;

                                //Add the partial source paramter to merged paramter.
                                curMergeParam.AddSourceParameter(srcParameter, srcComponentMask & srcParamterComponents);
                            }
                            splitCount++;

                            //Update left floats count
                            if (srcParameterFloats < freeFloatCount)
                            {
                                curSrcParameterFloats -= srcParameterFloats;
                            }
                            else
                            {
                                curSrcParameterFloats -= freeFloatCount;
                            }
                        }
                    }
                    //Add to split params list
                    if (splitCount > 1)
                    {
                        splitParams.Add(srcParameter);
                    }

                    curParamList.RemoveAt(curParamList.Count - 1);
                }
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		///   Merge reminders parameters that could not be merged into one slot using the predefined combinations.
		/// </summary>
		/// <param name="paramsTable"> The params table sorted by types in each row. </param>
		/// <param name="mergedParams"> The merged parameters list </param>
		/// <param name="splitParams"> The split parameters list </param>
		internal static void MergeParametersReminders( List<Parameter>[] paramsTable, List<MergeParameter> mergedParams,
		                                               List<Parameter> splitParams )
		{
			//Handle reminders parameters - All of the parameters that could not be packed perfectly.
			int mergedParamsBaseIndex = mergedParams.Count;
			int remindersFloatCount = ( 1*paramsTable[ 0 ].Count ) + ( 2*paramsTable[ 1 ].Count ) +
			                          ( 3*paramsTable[ 2 ].Count ) + ( 4*paramsTable[ 3 ].Count );
			int reminderFloatMod = remindersFloatCount%4;
			int remindersFullSlotCount = remindersFloatCount/4;
			int remindersPartialSlotCount = reminderFloatMod > 0 ? 1 : 0;
			int remindersTotalSlotCount = remindersFullSlotCount + remindersPartialSlotCount;

			//First pass -> fill the slots with the largest reminders paramters.
			for ( int slot = 0; slot < remindersTotalSlotCount; ++slot )
			{
				MergeParameter curMergeParam;

				for ( int row = 0; row < 4; ++row )
				{
					List<Parameter> curParamList = paramsTable[ 3 - row ];

					//Case this list contains parameters - remove it and add to merged params.
					if ( curParamList.Count > 0 )
					{
						curMergeParam = new MergeParameter();
						curMergeParam.AddSourceParameter( curParamList[ curParamList.Count - 1 ],
						                                  (int)Operand.OpMask.All );
						curParamList.RemoveAt( curParamList.Count - 1 );
						mergedParams.Add( curMergeParam );
					}
				}
			}

			//Second pass -> merge the reminders parameters.
			for ( int row = 0; row < 4; ++row )
			{
				var curParamList = paramsTable[ 3 - row ];

				//Merge the all the paramters of the current list.
				while ( curParamList.Count > 0 )
				{
					Parameter srcParameter = curParamList[ curParamList.Count - 1 ];
					int splitCount = 0; // How many times the source paramter has been split.
					int srcParamterComponents;
					int srcParameterFloats;
					int curSrcParameterFloats;

					srcParameterFloats = GetParameterFloatCount( srcParameter.Type );
					curSrcParameterFloats = srcParameterFloats;
					srcParamterComponents = GetParameterMaskByType( srcParameter.Type );

					//while this parameter has remaining components -> split it.
					while ( curSrcParameterFloats > 0 )
					{
						for ( int slot = 0; slot < remindersTotalSlotCount && curSrcParameterFloats > 0; ++slot )
						{
							MergeParameter curMergeParam = mergedParams[ mergedParamsBaseIndex + slot ];
							int freeFloatCount = 4 - curMergeParam.UsedFloatCount;

							//Case this slot has free space.
							if ( freeFloatCount > 0 )
							{
								//Case current components of source paramter can go all into this slot without split.
								if ( srcParameterFloats < freeFloatCount && splitCount == 0 )
								{
									curMergeParam.AddSourceParameter( srcParameter, (int)Operand.OpMask.All );
								}
								//case we have to split the current source parameter
							}
							else
							{
								int srcComponentMask;

								//Create the mask that tell us which part of the source componetn is added to the merged paramter.
								srcComponentMask = GetParameterMaskByFloatCount( freeFloatCount ) << splitCount;

								//Add the partial source paramter to merged paramter.
								curMergeParam.AddSourceParameter( srcParameter, srcComponentMask & srcParamterComponents );
							}
							splitCount++;

							//Update left floats count
							if ( srcParameterFloats < freeFloatCount )
							{
								curSrcParameterFloats -= srcParameterFloats;
							}
							else
							{
								curSrcParameterFloats -= freeFloatCount;
							}
						}
					}
					//Add to split params list
					if ( splitCount > 1 )
					{
						splitParams.Add( srcParameter );
					}

					curParamList.RemoveAt( curParamList.Count - 1 );
				}
			}
		}
Ejemplo n.º 6
0
		/// <summary>
		///   Creates merged parameter from given combination.
		/// </summary>
		/// <param name="combination"> The merge combination to try. </param>
		/// <param name="paramsTable"> The params table sorted by tpes in each row. </param>
		/// <param name="mergedParameter"> Will hold the merged parameter </param>
		/// <returns> </returns>
		internal static bool MergeParametersByCombination( MergeCombination combination, List<Parameter>[] paramsTable,
		                                                   out MergeParameter mergedParameter )
		{
			mergedParameter = new MergeParameter();
			//Make sure we have enough parameters to combine.
			if ( combination.srcParameterTypeCount[ 0 ] > paramsTable[ 0 ].Count ||
			     combination.srcParameterTypeCount[ 1 ] > paramsTable[ 1 ].Count ||
			     combination.srcParameterTypeCount[ 2 ] > paramsTable[ 2 ].Count ||
			     combination.srcParameterTypeCount[ 3 ] > paramsTable[ 3 ].Count )
			{
				return false;
			}

			//Create the new output parameter.
			for ( int i = 0; i < 4; ++i )
			{
				var curParamList = paramsTable[ i ];
				int srcParameterTypeCount = combination.srcParameterTypeCount[ i ];
				int srcParameterCount = 0;

				while ( srcParameterCount > 0 )
				{
					mergedParameter.AddSourceParameter( curParamList[ curParamList.Count - 1 ],
					                                    combination.srcParameterMask[ srcParameterCount ] );
					curParamList.RemoveAt( curParamList.Count - 1 );
					srcParameterCount++;
					--srcParameterTypeCount;
				}
			}

			return true;
		}