private FLBuffer ComputeFunction(FLInstructionArgument arg) { FLFunction flFunction = (FLFunction)arg.Value; //Process the Function Object FLBuffer buffer = Root.RegisterUnmanagedBuffer(new FLBuffer(Root.Instance, Root.Dimensions.x, Root.Dimensions.y, $"{flFunction.Name}_InputBuffer")); Logger.Log(LogType.Log, $"Storing Current Execution Context", MIN_INSTRUCTION_SEVERITY + 3); Root.PushContext(); //Store Dynamic Variables Logger.Log(LogType.Log, $"Executing Function: {flFunction.Name}", MIN_INSTRUCTION_SEVERITY + 2); Root.ActiveBuffer = buffer; flFunction.Process(); Logger.Log(LogType.Log, $"[{Kernel.Name}]Argument Buffer{Root.ActiveBuffer.DefinedBufferName}", MIN_INSTRUCTION_SEVERITY + 2); FLBuffer ret = Root.ActiveBuffer; //Kernel.SetBuffer(kernelArgIndex, // Root.ActiveBuffer.Buffer); //Set the Active Buffer as the Kernel Argument Logger.Log(LogType.Log, $"Returning from Function Context", MIN_INSTRUCTION_SEVERITY + 3); Root.ReturnFromContext(); //Restore active channels and buffer return(ret); }
private static void Initialize(this FLFunction function, SerializableFLFunction serializableFunction, FLProgram script, FLInstructionSet instructionSet) { function.SetInstructions(serializableFunction.Instructions.Select(x => x.Initialize(script, instructionSet)) .ToList()); }
public override void Process() { byte[] newFlags = new byte[4]; for (int i = 0; i < Arguments.Count; i++) { if (i == 0) { if (Arguments[i].Type == FLInstructionArgumentType.Buffer) { FLBuffer obj = (FLBuffer)Arguments[i].Value; Logger.Log(LogType.Log, "Setting Active Buffer: " + obj.DefinedBufferName, MIN_INSTRUCTION_SEVERITY); Root.ActiveBuffer = obj; continue; } if (Arguments[i].Type == FLInstructionArgumentType.Function) { FLBuffer buffer = Root.RegisterUnmanagedBuffer(new FLBuffer(Root.Instance, Root.Dimensions.x, Root.Dimensions.y, "FunctionInputBuffer_Registered")); FLFunction source = (FLFunction)Arguments[i].Value; Logger.Log(LogType.Log, $"Storing Current Execution Context", MIN_INSTRUCTION_SEVERITY + 3); Root.PushContext(); Logger.Log(LogType.Log, $"Executing Function: {source.Name}", MIN_INSTRUCTION_SEVERITY + 2); Root.ActiveBuffer = buffer; source.Process(); //Root.Run(Root.Instance, buffer, true, source); FLBuffer output = Root.ActiveBuffer; Logger.Log(LogType.Log, $"Returning from Function Context", MIN_INSTRUCTION_SEVERITY + 3); Root.ReturnFromContext(); Root.ActiveBuffer = output; continue; } } if (Arguments[i].Type == FLInstructionArgumentType.Number) { int channel = (int)Convert.ChangeType(Arguments[i].Value, typeof(int)); Logger.Log(LogType.Log, "Setting Active Channel: " + channel, MIN_INSTRUCTION_SEVERITY); newFlags[channel] = 1; } else { throw new InvalidOperationException("Invalid Channel ID"); } } Root.ActiveChannels = newFlags; }
public override ImplicitCastBox GetValue(FLProgram script, FLFunction func) { if (script.DefinedBuffers[Value] is IEditableBuffer buffer) { return(new ImplicitCastBox <decimal>(() => buffer.GetData()[Index])); //really slow } throw new InvalidOperationException($"{script.DefinedBuffers[Value]} does not implement IEditableBuffer"); }
public static FLInstruction Initialize( this SerializableFLInstruction instruction, FLProgram script, FLFunction func, FLInstructionSet instructionSet) { FLInstruction i = instructionSet.Create(script, func, instruction); return(i); }
public override FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction) { List <FLInstructionArgument> args = new List <FLInstructionArgument>(); for (int i = 0; i < instruction.Arguments.Count; i++) { FLInstructionArgument arg = new FLInstructionArgument(instruction.Arguments[i].GetValue(script, func)); args.Add(arg); } return(new GPUArrangeFLInstruction(args, ArrangeKernel)); }
public override FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction) { List <FLInstructionArgument> args = new List <FLInstructionArgument>(); for (int i = 0; i < instruction.Arguments.Count; i++) { FLInstructionArgument arg = new FLInstructionArgument(instruction.Arguments[i].GetValue(script, func)); args.Add(arg); } return((FLInstruction)Activator.CreateInstance(type, args)); }
public static Dictionary <IParsedObject, int> ToString(this FLProgram prog, out string s) { Dictionary <IParsedObject, int> ret = new Dictionary <IParsedObject, int>(); StringBuilder sb = new StringBuilder(); int lineCount = 0; foreach (KeyValuePair <string, FLBuffer> definedBuffer in prog.DefinedBuffers) { string f = definedBuffer.Value.ToString(); if (definedBuffer.Key != "current") { ret.Add(definedBuffer.Value, lineCount); } sb.AppendLine(f); lineCount++; } foreach (KeyValuePair <string, IFunction> externalFlFunction in prog.DefinedScripts) { string f = externalFlFunction.Value.ToString(); ret.Add(externalFlFunction.Value, lineCount); sb.AppendLine(f); lineCount++; } foreach (KeyValuePair <string, IFunction> keyValuePair in prog.FlFunctions) { ret.Add(keyValuePair.Value, lineCount); sb.AppendLine(keyValuePair.Key + ":"); lineCount++; FLFunction func = keyValuePair.Value as FLFunction; foreach (FLInstruction valueInstruction in func.Instructions) { string f = valueInstruction.ToString(); f = "\t" + f; ret.Add(valueInstruction, lineCount); sb.AppendLine(f); lineCount++; } sb.AppendLine(); lineCount++; } s = sb.ToString(); return(ret); }
public override void Process() { if (Arguments.Count != ArgumentOffset + 1 || Arguments[ArgumentOffset].Type != FLInstructionArgumentType.Function) { throw new InvalidOperationException("Jump instruction needs to point to a valid function."); } FLFunction obj = (FLFunction)Arguments[ArgumentOffset].Value; Logger.Log(LogType.Log, "Jumping to " + obj.Name, MIN_INSTRUCTION_SEVERITY); obj.Process(); }
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() )); }
public override ImplicitCastBox GetValue(FLProgram script, FLFunction func) { return(new ImplicitCastBox <decimal>(() => script.DefinedBuffers[Value].Size)); }
public override ImplicitCastBox GetValue(FLProgram script, FLFunction func) { return(new ImplicitCastBox <IFunction>(() => script.FlFunctions[Value])); }
public virtual void SetParent(FLFunction func) { Parent = func; }
public override string Identifier => Value.ToString(); //Not used anyway public override ImplicitCastBox GetValue(FLProgram script, FLFunction func) { return(new ImplicitCastBox <decimal>(() => Value)); }
public InstructionRunEventArgs(FLProgram root, FLFunction function, FLInstruction instruction) : base(root, function) { Instruction = instruction; }
public FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction) { return(GetCreator(instruction).Create(script, func, instruction)); }
public abstract FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction);
public FunctionRunEventArgs(FLProgram root, FLFunction function) : base(root) { Function = function; }
public abstract ImplicitCastBox GetValue(FLProgram script, FLFunction func);