コード例 #1
0
ファイル: KernelFLInstruction.cs プロジェクト: ByteChkR/Byt3
        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);
        }
コード例 #2
0
 private static void Initialize(this FLFunction function, SerializableFLFunction serializableFunction,
                                FLProgram script,
                                FLInstructionSet instructionSet)
 {
     function.SetInstructions(serializableFunction.Instructions.Select(x => x.Initialize(script, instructionSet))
                              .ToList());
 }
コード例 #3
0
        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;
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        public static FLInstruction Initialize(
            this SerializableFLInstruction instruction, FLProgram script,
            FLFunction func,
            FLInstructionSet instructionSet)
        {
            FLInstruction i = instructionSet.Create(script, func, instruction);

            return(i);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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();
        }
コード例 #10
0
 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()
                ));
 }
コード例 #11
0
 public override ImplicitCastBox GetValue(FLProgram script, FLFunction func)
 {
     return(new ImplicitCastBox <decimal>(() => script.DefinedBuffers[Value].Size));
 }
コード例 #12
0
 public override ImplicitCastBox GetValue(FLProgram script, FLFunction func)
 {
     return(new ImplicitCastBox <IFunction>(() => script.FlFunctions[Value]));
 }
コード例 #13
0
ファイル: FLInstruction.cs プロジェクト: ByteChkR/Byt3
 public virtual void SetParent(FLFunction func)
 {
     Parent = func;
 }
コード例 #14
0
        public override string Identifier => Value.ToString(); //Not used anyway


        public override ImplicitCastBox GetValue(FLProgram script, FLFunction func)
        {
            return(new ImplicitCastBox <decimal>(() => Value));
        }
コード例 #15
0
ファイル: FLDebuggerEvents.cs プロジェクト: Open-FL/OpenFL
 public InstructionRunEventArgs(FLProgram root, FLFunction function, FLInstruction instruction) :
     base(root, function)
 {
     Instruction = instruction;
 }
コード例 #16
0
 public FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction)
 {
     return(GetCreator(instruction).Create(script, func, instruction));
 }
コード例 #17
0
 public abstract FLInstruction Create(FLProgram script, FLFunction func, SerializableFLInstruction instruction);
コード例 #18
0
ファイル: FLDebuggerEvents.cs プロジェクト: Open-FL/OpenFL
 public FunctionRunEventArgs(FLProgram root, FLFunction function) : base(root)
 {
     Function = function;
 }
コード例 #19
0
 public abstract ImplicitCastBox GetValue(FLProgram script, FLFunction func);