MapParamNameToIndex() public méthode

Maps a parameter name to the specified constant index.
public MapParamNameToIndex ( string name, int index ) : void
name string Name of the param.
index int Constant index of the param.
Résultat void
		public GpuProgramParameters Clone()
		{
			GpuProgramParameters p = new GpuProgramParameters();

			// copy int constants
			for ( int i = 0; i < intConstants.Count; i++ )
			{
				IntConstantEntry e = intConstants[ i ] as IntConstantEntry;
				if ( e.isSet )
				{
					p.SetConstant( i, e.val );
				}
			}

			// copy float constants
			for ( int i = 0; i < floatConstants.Count; i++ )
			{
				FloatConstantEntry e = floatConstants[ i ] as FloatConstantEntry;
				if ( e.isSet )
				{
					p.SetConstant( i, e.val );
				}
			}

			// copy auto constants
			for ( int i = 0; i < autoConstantList.Count; i++ )
			{
				AutoConstantEntry entry = autoConstantList[ i ] as AutoConstantEntry;
				p.SetAutoConstant( entry.Clone() );
			}

			// copy named params
			foreach ( string key in namedParams.Keys )
			{
				p.MapParamNameToIndex( key, namedParams[ key ] );
			}

			for ( int i = 0; i < paramTypeList.Count; i++ )
			{
			}
			foreach ( ParameterEntry pEntry in paramTypeList )
			{
				p.AddParameterToDefaultsList( pEntry.ParameterType, pEntry.ParameterName );
			}

			// copy value members
			p.transposeMatrices = transposeMatrices;
			p.autoAddParamName = autoAddParamName;

			return p;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="prefix"></param>
        /// <param name="index"></param>
        /// <param name="parms"></param>
        protected void ProcessParamElement(D3D.EffectHandle parent, string prefix, int index, GpuProgramParameters parms)
        {
            D3D.EffectHandle constant = constantTable.GetConstant(parent, index);

            // Since D3D HLSL doesn't deal with naming of array and struct parameters
            // automatically, we have to do it by hand
            D3D.ConstantDescription[] descs = constantTable.GetConstantDescription(constant, 1);
            D3D.ConstantDescription desc = descs[0];

            string paramName = desc.Name;

            // trim the odd '$' which appears at the start of the names in HLSL
            if(paramName.StartsWith("$")) {
                paramName = paramName.Remove(0, 1);
            }

            // If it's an array, elements will be > 1
            for(int e = 0; e < desc.Elements; e++) {
                if(desc.Class == ParameterClass.Struct) {
                    // work out a new prefix for the nextest members
                    // if its an array, we need the index
                    if(desc.Elements > 1) {
                        prefix += string.Format("{0}[{1}].", paramName, e);
                    }
                    else {
                        prefix += ".";
                    }

                    // cascade into the struct members
                    for(int i = 0; i < desc.StructMembers; i++) {
                        ProcessParamElement(constant, prefix, i, parms);
                    }
                }
                else {
                    // process params
                    if(desc.ParameterType == ParameterType.Float ||
                        desc.ParameterType == ParameterType.Integer ||
                        desc.ParameterType == ParameterType.Boolean) {

                        int paramIndex = desc.RegisterIndex;
                        string newName = prefix + paramName;

                        // if this is an array, we need to appent the element index
                        if(desc.Elements > 1) {
                            newName += string.Format("[{0}]", e);
                        }

                        // map the named param to the index
                        parms.MapParamNameToIndex(newName, paramIndex+e);
                    }
                }
            }
        }
Exemple #3
0
		/// <summary>
		///
		/// </summary>
		/// <param name="parms"></param>
		protected override void PopulateParameterNames( GpuProgramParameters parms )
		{
			Debug.Assert( cgProgram != IntPtr.Zero );

			// Note use of 'leaf' format so we only get bottom-level params, not structs
			IntPtr param = Cg.cgGetFirstLeafParameter( cgProgram, Cg.CG_PROGRAM );

			int index = 0;

			// loop through the rest of the params
			while ( param != IntPtr.Zero )
			{

				// get the type of this param up front
				int paramType = Cg.cgGetParameterType( param );

				// Look for uniform parameters only
				// Don't bother enumerating unused parameters, especially since they will
				// be optimized out and therefore not in the indexed versions
				if ( Cg.cgIsParameterReferenced( param ) != 0
					&& Cg.cgGetParameterVariability( param ) == Cg.CG_UNIFORM
					&& Cg.cgGetParameterDirection( param ) != Cg.CG_OUT
					&& paramType != Cg.CG_SAMPLER1D
					&& paramType != Cg.CG_SAMPLER2D
					&& paramType != Cg.CG_SAMPLER3D
					&& paramType != Cg.CG_SAMPLERCUBE
					&& paramType != Cg.CG_SAMPLERRECT )
				{

					// get the name and index of the program param
					string name = Cg.cgGetParameterName( param );

					// fp30 uses named rather than indexed params, so Cg returns
					// 0 for the index. However, we need the index to be unique here
					// Resource type 3256 doesn't have a define in the Cg header, so I assume
					// it means an unused or non-indexed params, since it is also returned
					// for programs that have a param that is not referenced in the program
					// and ends up getting pruned by the Cg compiler
					if ( selectedCgProfile == Cg.CG_PROFILE_FP30 )
					{
						// use a fake index just to order the named fp30 params
						index++;
					}
					else
					{
						// get the param constant index the normal way
						index = Cg.cgGetParameterResourceIndex( param );
					}

					// get the underlying resource type of this param
					// we need a special case for the register combiner
					// stage constants.
					int resource = Cg.cgGetParameterResource( param );

					// Get the parameter resource, so we know what type we're dealing with
					switch ( resource )
					{
						case Cg.CG_COMBINER_STAGE_CONST0:
							// register combiner, const 0
							// the index relates to the texture stage; store this as (stage * 2) + 0
							index = index * 2;
							break;

						case Cg.CG_COMBINER_STAGE_CONST1:
							// register combiner, const 1
							// the index relates to the texture stage; store this as (stage * 2) + 1
							index = ( index * 2 ) + 1;
							break;
					}

					// map the param to the index
					parms.MapParamNameToIndex( name, index );
				}

				// get the next param
				param = Cg.cgGetNextLeafParameter( param );
			}
		}
        public GpuProgramParameters Clone()
        {
            GpuProgramParameters p = new GpuProgramParameters();

            // copy int constants
            for ( int i = 0; i < intConstants.Count; i++ )
            {
                IntConstantEntry e = intConstants[i];
                if ( e.isSet )
                {
                    p.SetConstant(i, e.val);
                }
            }

            // copy float constants
            p.floatConstantsArray = new float[floatConstantsArray.Length];
            Array.Copy(floatConstantsArray, p.floatConstantsArray, floatConstantsArray.Length);
            p.floatIsSet = new bool[floatIsSet.Length];
            Array.Copy(floatIsSet, p.floatIsSet, floatIsSet.Length);
            p.float4VecConstantsCount = float4VecConstantsCount;
            p.maxSetCount = maxSetCount;

            // copy auto constants
            for(int i = 0; i < autoConstantList.Count; i++)
            {
                AutoConstantEntry entry = autoConstantList[i];
                p.SetAutoConstant(entry.Clone());
            }

            // copy named params
            foreach ( DictionaryEntry e in namedParams )
            {
                p.MapParamNameToIndex(e.Key as string, (int)e.Value);
            }

            for ( int i = 0; i < paramTypeList.Count; i++ )
            {

            }
            foreach ( ParameterEntry pEntry in paramTypeList )
            {
                p.AddParameterToDefaultsList(pEntry.ParameterType, pEntry.ParameterName);
            }

            // copy value members
            p.transposeMatrices = transposeMatrices;
            p.autoAddParamName = autoAddParamName;

            return p;
        }