Exemplo 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);
        }
Exemplo n.º 2
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;
		}
Exemplo n.º 3
0
        /// <summary>
        ///   Creates merged parameters using pre-defined combinations.
        /// </summary>
        /// <param name="paramsTable"> Source parameters table. </param>
        /// <param name="mergedParams"> The merged parameters list </param>
        internal static void MergeParametersByPredefinedCombinations(List <Parameter>[] paramsTable,
                                                                     List <MergeParameter> mergedParams)
        {
            if (paramMergeCombinations == null)
            {
                BuildMergeCombinations();
            }

            //Create the full used merged params - means FLOAT4 params that all of their components are used.
            for (int i = 0; i < paramMergeCombinations.Count; ++i)
            {
                MergeCombination curCombination = paramMergeCombinations[i];

                //Case all parameters have been merged.
                if (paramsTable[0].Count + paramsTable[1].Count +
                    paramsTable[2].Count + paramsTable[3].Count == 0)
                {
                    return;
                }

                MergeParameter curMergeParam;

                while (MergeParametersByCombination(curCombination, paramsTable, out curMergeParam))
                {
                    mergedParams.Add(curMergeParam);
                    curMergeParam.Clear();
                }
            }

            //Case low/medium compactin policy = use these simplified combinations in order to prevent splits.
            if (ShaderGenerator.Instance.VertexShaderOutputsCompactPolicy == ShaderGenerator.OutputsCompactPolicy.Low ||
                ShaderGenerator.Instance.VertexShaderOutputsCompactPolicy ==
                ShaderGenerator.OutputsCompactPolicy.Medium)
            {
                int curUsedSlots     = mergedParams.Count;
                int float1ParamCount = paramsTable[0].Count;
                int float2ParamCount = paramsTable[1].Count;
                int float3ParamCount = paramsTable[2].Count;
                int reqSlots         = 0;

                //Compute the required slots.

                //Add all float3 since each one of them requires one slot for himself.
                reqSlots += float3ParamCount;

                //Add the float2 count -> at max it will be 1 since all pairs have been merged previously.
                if (float2ParamCount > 1)
                {
                    throw new Axiom.Core.AxiomException("Invalid float2 reminder count.");
                }
                reqSlots += float2ParamCount;

                //Compute how much space needed for the float1(s) that left -> at max it will be 3.
                if (float1ParamCount > 0)
                {
                    if (float2ParamCount > 3)
                    {
                        throw new Axiom.Core.AxiomException("Invalid float1 reminder count.");
                    }
                    //No float2 -> we need one more slot for these float1(s).
                    if (float2ParamCount == 0)
                    {
                        reqSlots++;
                    }
                    else
                    {
                        //float2 exists -> there must be at max 1 float1.
                        if (float1ParamCount > 1)
                        {
                            throw new Axiom.Core.AxiomException("Invalid float1 reminder count");
                        }
                    }
                }
                //Case maximium slot count will be exceeded -> fall back to full compaction
                if (curUsedSlots + reqSlots > maxTexCoordSlots)
                {
                    return;
                }

                var simpleCombination = new MergeCombination[6]
                {
                    //Deal with the float3 paramters.
                    new MergeCombination(
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        1, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All),
                    //Deal with the float2 + float1 combination
                    new MergeCombination(
                        1, (int)Operand.OpMask.All,
                        1, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All),
                    //Deal with the float2 paramter.
                    new MergeCombination(
                        0, (int)Operand.OpMask.All,
                        1, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All),
                    //Deal with the 3 float1 combination.
                    new MergeCombination(
                        3, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All),
                    //Deal with the 2 float1 combination
                    new MergeCombination(
                        2, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All),
                    //Deal with the 1 float1 combination
                    new MergeCombination(
                        1, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All,
                        0, (int)Operand.OpMask.All)
                };

                for (int i = 0; i < 6; i++)
                {
                    MergeCombination curCombination = simpleCombination[i];

                    //Case all parameters have been merged.
                    if (paramsTable[0].Count + paramsTable[1].Count + paramsTable[2].Count +
                        paramsTable[3].Count == 0)
                    {
                        break;
                    }

                    MergeParameter curMergeParam;

                    while (MergeParametersByCombination(curCombination, paramsTable, out curMergeParam))
                    {
                        mergedParams.Add(curMergeParam);
                        curMergeParam.Clear();
                    }
                }
            }
        }
Exemplo n.º 4
0
		/// <summary>
		///   Creates merged parameters using pre-defined combinations.
		/// </summary>
		/// <param name="paramsTable"> Source parameters table. </param>
		/// <param name="mergedParams"> The merged parameters list </param>
		internal static void MergeParametersByPredefinedCombinations( List<Parameter>[] paramsTable,
		                                                              List<MergeParameter> mergedParams )
		{
			if ( paramMergeCombinations == null )
			{
				BuildMergeCombinations();
			}

			//Create the full used merged params - means FLOAT4 params that all of their components are used.
			for ( int i = 0; i < paramMergeCombinations.Count; ++i )
			{
				MergeCombination curCombination = paramMergeCombinations[ i ];

				//Case all parameters have been merged.
				if ( paramsTable[ 0 ].Count + paramsTable[ 1 ].Count +
				     paramsTable[ 2 ].Count + paramsTable[ 3 ].Count == 0 )
				{
					return;
				}

				MergeParameter curMergeParam;

				while ( MergeParametersByCombination( curCombination, paramsTable, out curMergeParam ) )
				{
					mergedParams.Add( curMergeParam );
					curMergeParam.Clear();
				}
			}

			//Case low/medium compactin policy = use these simplified combinations in order to prevent splits.
			if ( ShaderGenerator.Instance.VertexShaderOutputsCompactPolicy == ShaderGenerator.OutputsCompactPolicy.Low ||
			     ShaderGenerator.Instance.VertexShaderOutputsCompactPolicy ==
			     ShaderGenerator.OutputsCompactPolicy.Medium )
			{
				int curUsedSlots = mergedParams.Count;
				int float1ParamCount = paramsTable[ 0 ].Count;
				int float2ParamCount = paramsTable[ 1 ].Count;
				int float3ParamCount = paramsTable[ 2 ].Count;
				int reqSlots = 0;

				//Compute the required slots.

				//Add all float3 since each one of them requires one slot for himself.
				reqSlots += float3ParamCount;

				//Add the float2 count -> at max it will be 1 since all pairs have been merged previously.
				if ( float2ParamCount > 1 )
				{
					throw new Axiom.Core.AxiomException( "Invalid float2 reminder count." );
				}
				reqSlots += float2ParamCount;

				//Compute how much space needed for the float1(s) that left -> at max it will be 3.
				if ( float1ParamCount > 0 )
				{
					if ( float2ParamCount > 3 )
					{
						throw new Axiom.Core.AxiomException( "Invalid float1 reminder count." );
					}
					//No float2 -> we need one more slot for these float1(s).
					if ( float2ParamCount == 0 )
					{
						reqSlots++;
					}
					else
					{
						//float2 exists -> there must be at max 1 float1.
						if ( float1ParamCount > 1 )
						{
							throw new Axiom.Core.AxiomException( "Invalid float1 reminder count" );
						}
					}
				}
				//Case maximium slot count will be exceeded -> fall back to full compaction
				if ( curUsedSlots + reqSlots > maxTexCoordSlots )
				{
					return;
				}

				var simpleCombination = new MergeCombination[6]
				                        {
				                        	//Deal with the float3 paramters.
				                        	new MergeCombination(
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		1, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All ),
				                        	//Deal with the float2 + float1 combination
				                        	new MergeCombination(
				                        		1, (int)Operand.OpMask.All,
				                        		1, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All ),
				                        	//Deal with the float2 paramter.
				                        	new MergeCombination(
				                        		0, (int)Operand.OpMask.All,
				                        		1, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All ),
				                        	//Deal with the 3 float1 combination.
				                        	new MergeCombination(
				                        		3, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All ),
				                        	//Deal with the 2 float1 combination
				                        	new MergeCombination(
				                        		2, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All ),
				                        	//Deal with the 1 float1 combination
				                        	new MergeCombination(
				                        		1, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All,
				                        		0, (int)Operand.OpMask.All )
				                        };

				for ( int i = 0; i < 6; i++ )
				{
					MergeCombination curCombination = simpleCombination[ i ];

					//Case all parameters have been merged.
					if ( paramsTable[ 0 ].Count + paramsTable[ 1 ].Count + paramsTable[ 2 ].Count +
					     paramsTable[ 3 ].Count == 0 )
					{
						break;
					}

					MergeParameter curMergeParam;

					while ( MergeParametersByCombination( curCombination, paramsTable, out curMergeParam ) )
					{
						mergedParams.Add( curMergeParam );
						curMergeParam.Clear();
					}
				}
			}
		}