/// <summary> /// Get Kernel Parameter List /// </summary> /// <param name="inKernelDefinition"></param> /// <returns></returns> public static List<KernelParameter> GetParameterList(string inKernelDefinition) { var tmpParams = new List<KernelParameter>(); var tmpParamStartmatch = new Regex(@"\(").Match(inKernelDefinition); var tmpKernelDefinition = inKernelDefinition.Substring(tmpParamStartmatch.Index + 1).Trim(); tmpKernelDefinition = tmpKernelDefinition.Substring(0,tmpKernelDefinition.Length - 1); var tmpParamIndex = 0; foreach (var tmpParamEntry in tmpKernelDefinition.Split(',')) { var tmpSplittedParam = tmpParamEntry.Replace("*", "").Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); var tmpKernelParam = new KernelParameter { Index = tmpParamIndex, Name = tmpSplittedParam[tmpSplittedParam.Length - 1], Type = _getType(tmpSplittedParam), }; if (tmpSplittedParam[0].ToLower().EndsWith("global")) { tmpKernelParam.IsStatic = true; } tmpParams.Add(tmpKernelParam); tmpParamIndex++; } return tmpParams; }
private bool CheckParameter(KernelParameter param, string name, bool isArray, int id, DataVectorTypes type, MemoryScope scope) { return(param.IsArray == isArray && param.DataType == type && param.Id == id && param.MemScope == scope && param.Name == name); }
public override FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction) { return(new KernelFLInstruction( KernelParameter.GetDataMaxSize(KernelList.GenDataType), KernelList.GetClKernel(instruction.InstructionKey), instruction.Arguments.Select( x => new FLInstructionArgument( x.GetValue( script, func ) ) ).ToList() )); }
/// <summary> /// 预处理第一关卡 /// </summary> /// <returns></returns> IEnumerator ScenePreProgressing_Level1() { yield return(new WaitForSeconds(0.1f)); //参数赋值 DialogDataAnalysisMgr.GetInstance().SetXMLPathAndRooNodeName(KernelParameter.GetDialogConfigPath(), KernelParameter.GetDialogConfigRootNodeName()); //等待参数设置完毕(要比DialogDataAnalysisMgr的延迟方法慢) yield return(new WaitForSeconds(0.7f)); //很重要 //得到XML中所有的数据 List <DialogDataFormat> DialogsDataArray = DialogDataAnalysisMgr.GetInstance().GetAllXmlDataArray(); // 测试给“对话数据管理器”加载数据 bool boolResult = DialogDataMgr.GetInstance().LoadAllDialogData(DialogsDataArray); if (!boolResult) { Log.Write(GetType() + "/Start()/对话数据管理器加载数据失败", Log.Level.High); } }
private FLLineAnalysisResult AnalyzeLine(FLInstructionData data) { if (data.InstructionType != FLInstructionType.FlFunction && data.InstructionType != FLInstructionType.ClKernel) { return(FLLineAnalysisResult.ParseError); } if (leaveStack) //This keeps the stack when returning from a "function" { leaveStack = false; } else { currentArgStack = new Stack <object>(); } FLLineAnalysisResult ret = FLLineAnalysisResult.IncreasePc; for (; currentWord < data.Arguments.Count; currentWord++) //loop through the words. start value can be != 0 when returning from a function specified as an argument to a kernel { if (data.Arguments[currentWord].argType == FLArgumentType.Function) { bool keepBuffer = data.InstructionType == FLInstructionType.FlFunction && ((FLInterpreterFunctionInfo)data.Instruction).LeaveStack; JumpTo((int)data.Arguments[currentWord].value, keepBuffer); ret = FLLineAnalysisResult.Jump; //We Jumped to another point in the code. currentArgStack .Push(null); //Push null to signal the interpreter that he returned before assigning the right value. break; } if (data.Arguments[currentWord].argType != FLArgumentType.Unknown) { currentArgStack.Push(data.Arguments[currentWord].value); } } if (currentWord == data.Arguments.Count && ret != FLLineAnalysisResult.Jump) { if (data.InstructionType == FLInstructionType.FlFunction) { ((FLInterpreterFunctionInfo)data.Instruction).Run(); return(FLLineAnalysisResult.IncreasePc); } CLKernel k = (CLKernel)data.Instruction; if (k == null || data.Arguments.Count != k.Parameter.Count - FL_HEADER_ARG_COUNT) { throw new FLInvalidFunctionUseException(this.data.Source[currentIndex], "Not the right amount of arguments."); } //Execute filter for (int i = k.Parameter.Count - 1; i >= FL_HEADER_ARG_COUNT; i--) { object obj = currentArgStack.Pop(); //Get the arguments and set them to the kernel if (obj is CLBufferInfo buf) //Unpack the Buffer from the CLBuffer Object. { obj = buf.Buffer; } k.SetArg(i, obj); } Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level8, "Running kernel: " + k.Name); CLAPI.Run(instance, k, currentBuffer.Buffer, new int3(width, height, depth), KernelParameter.GetDataMaxSize(kernelDb.GenDataType), activeChannelBuffer, channelCount); //Running the kernel } return(ret); }
private LineAnalysisResult AnalyzeLine(FLInstructionData data) { if (data.InstructionType != FLInstructionType.FLFunction && data.InstructionType != FLInstructionType.CLKernel) { Logger.Crash(new FLParseError(Data.Source[_currentIndex]), true); return(LineAnalysisResult.ParseError); } if (_leaveStack) //This keeps the stack when returning from a "function" { _leaveStack = false; } else { _currentArgStack = new Stack <object>(); } LineAnalysisResult ret = LineAnalysisResult.IncreasePC; for (; _currentWord < data.Arguments.Count; _currentWord++) //loop through the words. start value can be != 0 when returning from a function specified as an argument to a kernel { if (data.Arguments[_currentWord].argType == FLArgumentType.Function) { bool KeepBuffer = data.InstructionType == FLInstructionType.FLFunction && ((FLFunctionInfo)data.Instruction).LeaveStack; JumpTo((int)data.Arguments[_currentWord].value, KeepBuffer); ret = LineAnalysisResult.Jump; //We Jumped to another point in the code. _currentArgStack .Push(null); //Push null to signal the interpreter that he returned before assigning the right value. break; } if (data.Arguments[_currentWord].argType != FLArgumentType.Unknown) { _currentArgStack.Push(data.Arguments[_currentWord].value); } } if (_currentWord == data.Arguments.Count && ret != LineAnalysisResult.Jump) { if (data.InstructionType == FLInstructionType.FLFunction) { ((FLFunctionInfo)data.Instruction).Run(); return(LineAnalysisResult.IncreasePC); } CLKernel K = (CLKernel)data.Instruction; if (K == null || data.Arguments.Count != K.Parameter.Count - FLHeaderArgCount) { Logger.Crash(new FLInvalidFunctionUseException(Data.Source[_currentIndex], "Not the right amount of arguments."), true); return(LineAnalysisResult.ParseError); } //Execute filter for (int i = K.Parameter.Count - 1; i >= FLHeaderArgCount; i--) { object obj = _currentArgStack.Pop(); //Get the arguments and set them to the kernel if (obj is CLBufferInfo buf) //Unpack the Buffer from the CLBuffer Object. { obj = buf.Buffer; } K.SetArg(i, obj); } Logger.Log("Running kernel: " + K.Name, DebugChannel.Log | DebugChannel.OpenFL, 8); CLAPI.Run(K, _currentBuffer.Buffer, new int3(_width, _height, _depth), KernelParameter.GetDataMaxSize(_kernelDb.GenDataType), _activeChannelBuffer, _channelCount); //Running the kernel } return(ret); }
IEnumerator Start() { #region 测试内容(Log系统) /* 启用Log日志系统 */ //面向接口编程 IConfigManager configMgr = new ConfigManager(KernelParameter.GetLogPath(), KernelParameter.GetLogRootNodeName()); //string strLogPath = configMgr.AppSetting["LogPath"]; //string strLogState = configMgr.AppSetting["LogState"]; //string strLogMaxCapacity = configMgr.AppSetting["LogMaxCapacity"]; //string strLogCacheNumber = configMgr.AppSetting["LogCacheNumber"]; //print("LogPath:" + strLogPath); //print("LogState:" + strLogState); //print("LogMaxCapacity:" + strLogMaxCapacity); //print("LogCacheNumber:" + strLogCacheNumber); //测试Log.cs类(让构造函数运行起来) //Log.Write("我的企业日志系统开始运行了,第一次测试"); #endregion #region 测试内容(XML解析) ///* 测试XML解析程序 */ ////或许可以封装为一个方法,提供参数:对话XML文件地址,根节点名 ////输出参数:对话数据格式类列表 //参数赋值 DialogDataAnalysisMgr.GetInstance().SetXMLPathAndRooNodeName(KernelParameter.GetDialogConfigPath(), KernelParameter.GetDialogConfigRootNodeName()); //等待参数设置完毕(要比DialogDataAnalysisMgr的延迟方法慢) yield return(new WaitForSeconds(0.5f)); //很重要 //得到XML中所有的数据 List <DialogDataFormat> DialogsDataArray = DialogDataAnalysisMgr.GetInstance().GetAllXmlDataArray(); //foreach (DialogDataFormat data in DialogsDataArray) { // Log.Write(""); //空一行 // Log.Write("SectionNum: " + data.DiaSectionNum); // Log.Write("SectionName: " + data.DiaSectionName); // Log.Write("Index: " + data.DiaIndex); // Log.Write("Side: " + data.DiaSide); // Log.Write("Person: " + data.DiaPerson); // Log.Write("Content:" + data.DiaContent); //} //Log.SyncLogArrayToFile(); // 测试给“对话数据管理器”加载数据 bool boolResult = DialogDataMgr.GetInstance().LoadAllDialogData(DialogsDataArray); if (!boolResult) { Log.Write(GetType() + "/Start()/对话数据管理器加载数据失败"); } //###调试进入指定关卡(在这里改变调试关卡)### GlobalParaMgr.NextSceneName = SceneEnum.MajorCity; #endregion yield return(new WaitForSeconds(1f)); StartCoroutine("LoadingSceneProgress"); }
private (string, string, CLProgram[]) GenerateTargets(SerializableFLInstruction[] targets) { string newName = "opt"; string newSig = ""; List <string> lines = new List <string>(); Dictionary <string, string> funcs = new Dictionary <string, string>(); List <CLProgram> progs = new List <CLProgram>(); int count = 0; foreach (SerializableFLInstruction serializableFlInstruction in targets) { CLKernel instr = InstructionSet.Database.GetClKernel(serializableFlInstruction.InstructionKey); CLProgram prog = InstructionSet.Database.GetProgram(instr); progs.Add(prog); newName += "_" + instr.Name; string funcSig = ""; List <(string orig, string newKey)> reps = new List <(string orig, string newKey)>(); foreach (KeyValuePair <string, KernelParameter> kernelParameter in instr.Parameter.Skip(5)) { funcSig += ", "; switch (kernelParameter.Value.MemScope) { case MemoryScope.None: break; case MemoryScope.Global: funcSig += "__global "; break; case MemoryScope.Constant: funcSig += "__constant "; break; default: throw new ArgumentOutOfRangeException(); } funcSig += KernelParameter.GetDataString(kernelParameter.Value.DataType); funcSig += kernelParameter.Value.IsArray ? "* " : " "; funcSig += kernelParameter.Key + "_mrge_" + count; reps.Add((kernelParameter.Key, kernelParameter.Key + "_mrge_" + count)); count++; } newSig += funcSig; string[] block = GetBlockContent(prog.Source, instr.Name); foreach ((string orig, string newKey)valueTuple in reps) { for (int i = 0; i < block.Length; i++) { int current = block[i].IndexOf(valueTuple.orig, StringComparison.Ordinal); while (current != -1) { if (CheckBack(block[i], current + valueTuple.orig.Length - 1) && CheckFront(block[i], current)) { block[i] = block[i].Remove(current, valueTuple.orig.Length) .Insert(current, valueTuple.newKey); } current = block[i].IndexOf( valueTuple.orig, current + valueTuple.orig.Length, StringComparison.Ordinal ); } } } string genFuncArgs = reps.Count == 0 ? "" : ", " + reps.Select(x => x.newKey).Unpack(", "); if (!funcs.ContainsKey(instr.Name)) { funcs.Add( instr.Name, GetFunc( "gen_" + instr.Name, "__global uchar* image, int3 dimensions, int channelCount, float maxValue, __global uchar* channelEnableState" + funcSig, block ) ); } string line = $"\ngen_{instr.Name}(image, dimensions, channelCount, maxValue, channelEnableState{genFuncArgs});\n"; lines.Add(line); } string sig = $"__kernel void {newName}(__global uchar* image, int3 dimensions, int channelCount, float maxValue, __global uchar* channelEnableState{newSig})"; string newk = $"{funcs.Values.Distinct().Unpack("\n\n")}\n{sig}\n" + "{" + lines.Unpack("\n") + "\n}"; return(newName, newk, progs.ToArray()); }