/// <summary>Creates a new OpenCL filter from a core code which reads (float4)P[][] RGBA and outputs (float4)outP RGBA, colors from 0 to 1</summary> /// <param name="CoreCode">Kernel core code</param> public static void AddCLFilterFromCode(string kernelName, string CoreCode) { string fullCode = CLFilter.CreateKernelCode(kernelName, CoreCode); CLFilter filter = new CLFilter(fullCode, kernelName); CLFilters.Add(filter); }
bool Analyze(string code) { string[] words = code.Split(" ", StringSplitOptions.RemoveEmptyEntries); string function = words.Length == 0 ? "" : words[0]; CLFilter filter = null; if (function == "") { return(false); } bool isBakedFunction = bakedFunctions.ContainsKey(function); bool isDirectExecute = function == "jmp"; if (!isBakedFunction && !CLFilterAPI.TryGetFilter(function, out filter)) { throw new NotImplementedException("Argument Not found in line " + code + "."); } if (leaveStack) //This keeps the stack when returning from a "function" { leaveStack = false; } else { currentArgStack = new Stack <object>(); } bool ret = true; for (; currentWord < words.Length; currentWord++) //loop through the words. start value can be != 0 when returning from a function specified as an argument to a kernel { if (AnalyzeWord(words[currentWord], out object val)) { JumpTo(jumpLocations[words[currentWord]], isDirectExecute); ret = false; //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; } else { currentArgStack.Push(val); //push the value to the stack } } if (currentWord == words.Length && ret) //We finished parsing the line and we didnt jump. { if (isBakedFunction) { bakedFunctions[function](); //Execute baked function } else if (filter == null || words.Length - 1 != filter.parameter.Count - 4) { throw new Exception("Not the right amount of arguments."); } else { //Execute filter for (int i = filter.parameter.Count - 1; i >= 4; i--) { object obj = currentArgStack.Pop(); //Get the arguments and set them to the kernel filter.SetArg(i, obj); } this.Log("Running kernel: " + filter.name, DebugChannel.Log, 10); filter.Run(cq, activeBuffer, new int3(width, height, depth), chEnableStateBuffer, channelCount); //Running the kernel byte[] buf = cq.EnqueueReadBuffer <byte>(activeBuffer, (int)activeBuffer.Size); } } return(ret); }