/// <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); } } }
/// <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)); } } }