Пример #1
0
 public void OnAddInternalBuffer(FLProgram program, FLBuffer internalBuffer)
 {
     if (Debuggers.ContainsKey(program))
     {
         Debuggers[program].OnAddInternalBuffer(internalBuffer);
     }
 }
Пример #2
0
        public BufferView(CLAPI instance, FLBuffer buffer, int width, int height)
        {
            Instance = instance;
            InitializeComponent();

            if (buffer.Depth == 1)
            {
                nudFrame.Enabled = false;
            }
            else
            {
                nudFrame.Minimum = 0;
                nudFrame.Maximum = buffer.Depth - 1;
            }

            pbBufferContent = CreatePreviewBox(panelImage);
            Buffer          = buffer;
            this.width      = width;
            this.height     = height;
            Text            = buffer.DefinedBufferName + $"[{buffer.Buffer}]";


            cbImageFilterMode.Items.AddRange(Enum.GetNames(typeof(InterpolationMode)));
            cbImageFilterMode.Items.Remove(InterpolationMode.Invalid.ToString());
            cbImageFilterMode.SelectedIndex = 0;

            StyleManager.RegisterControls(this);

            Icon = FLEditorPluginHost.FLEditorIcon;

            pbIdle.Image    = FLEditorPluginHost.FLEditorImage;
            pbLoading.Image = FLEditorPluginHost.LoadingImage;

            RefreshImage(Instance);
        }
Пример #3
0
        public override void Process()
        {
            if (Arguments.Count == 0)
            {
                Logger.Log(LogType.Log, $"Writing Random Data to Active Buffer:" + Root.ActiveBuffer.DefinedBufferName,
                           MIN_INSTRUCTION_SEVERITY);
                CLAPI.WriteRandom(Root.Instance, Root.ActiveBuffer.Buffer, RandomInstructionHelper.Randombytesource,
                                  Root.ActiveChannels, false);
            }

            for (int i = 0; i < Arguments.Count; i++)
            {
                FLInstructionArgument obj = Arguments[i];

                if (obj.Type != FLInstructionArgumentType.Buffer)
                {
                    throw
                        new FLInvalidArgumentType("Argument: " + obj.Value, "MemoyBuffer/Image");
                }

                FLBuffer func = (FLBuffer)obj.Value;

                Logger.Log(LogType.Log, $"Writing Random Data to Active Buffer:" + func.DefinedBufferName,
                           MIN_INSTRUCTION_SEVERITY);

                CLAPI.WriteRandom(Root.Instance, func.Buffer, RandomInstructionHelper.Randombytesource,
                                  Root.ActiveChannels, false);
            }
        }
Пример #4
0
        private Texture GenerateGroundTexture()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            int texWidth  = 1024;
            int texHeight = 1024;

            Texture tex = TextureLoader.ParameterToTexture(texWidth, texHeight, "GroundTextureCL");

            FLBuffer buffer =
                new FLBuffer(TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, tex, "BufferForFLProgram"), 128,
                             128);


            FLProgram program = parser.Process(new FLParserInput("assets/filter/examples/grass.fl")).Initialize(iset);


            program.Run(CLAPI.MainThread, buffer, true);

            FLBuffer result = program.GetActiveBuffer(false);

            byte[] dat = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Buffer.Size);
            //Create a texture from the output.
            TextureLoader.Update(tex, dat, 1024, 1024);


            Logger.Log(DebugChannel.Log, "Time for Ground Texture(ms): " + sw.ElapsedMilliseconds, 10);
            sw.Stop();
            return(tex);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public void CorrectUnderlyingBuffer_For_IN_Test()
        {
            TestSetup.SetupTestingSession();
            string file = "resources/filter/bug_checks/set_temp_to_in_bug.fl";

            FLSetup s = new FLSetup(nameof(CorrectUnderlyingBuffer_For_IN_Test), "resources/kernel");
            SerializableFLProgram p  = s.Parser.Process(new FLParserInput(file));
            FLProgram             pp = p.Initialize(s.InstructionSet);
            FLBuffer b = new FLBuffer(CLAPI.MainThread, 128, 128, "TestInput");

            pp.Run(CLAPI.MainThread, b, true);

            FLBuffer i = pp.GetActiveBuffer(false);

            byte[] c = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, i.Buffer, (int)i.Size);
            for (int j = 0; j < c.Length; j++)
            {
                if (c[j] != 255)
                {
                    Assert.Fail("Output does not match expected");
                }
            }


            pp.FreeResources();
        }
Пример #7
0
        private void UpdateSidePanel()
        {
            FLBuffer active           = Program.GetActiveBuffer(false);
            string   activeBufferName = active == null ? "NULL" : active.DefinedBufferName;

            lblActiveBuffer.Text = "Active Buffer:\n" + activeBufferName;
            string s = "Active Channels:";

            if (Program.ActiveChannels != null)
            {
                for (int i = 0; i < Program.ActiveChannels.Length; i++)
                {
                    s += " " + Program.ActiveChannels[i];
                }
            }
            else
            {
                s += " NULL";
            }

            lblActiveChannels.Text = s;

            lbBuffers.Items.Clear();
            lbBuffers.Items.AddRange(Program.BufferNames.Cast <object>().ToArray());
        }
Пример #8
0
        public override void Process()
        {
            FLBuffer  input            = Root.ActiveBuffer;
            FLProgram externalFunction = ExternalFunctionBlueprint.Initialize(InstructionSet);

            input.SetRoot(externalFunction);

            externalFunction.ActiveChannels = Root.ActiveChannels;
            externalFunction.SetCLVariables(Root.Instance, input, false);
            //Not making it internal to the subscript because that would dispose the buffer later in the method
            FLProgram.Debugger?.SubProgramStarted(Root, this, externalFunction);

            externalFunction.EntryPoint.Process();

            FLProgram.Debugger?.SubProgramEnded(Root, externalFunction);

            FLBuffer buf = externalFunction.ActiveBuffer;

            buf.SetRoot(Root);
            input.SetRoot(Root);
            externalFunction.RemoveFromSystem(buf);
            externalFunction.RemoveFromSystem(input);

            Root.ActiveChannels = externalFunction.ActiveChannels;
            Root.ActiveBuffer   = buf;


            externalFunction.FreeResources();
        }
Пример #9
0
        protected FLProgram Process(FlScriptExecutionContext context)
        {
            FLBuffer input = new FLBuffer(
                Instance,
                context.Input,
                context.Width,
                context.Height,
                context.Depth,
                context.Filename
                );

            FLProgram program;

            if (context.IsCompiled)
            {
                Stream s = IOManager.GetStream(context.Filename);
                program = FLSerializer.LoadProgram(s, InstructionSet).Initialize(Instance, InstructionSet);
                s.Close();
            }
            else
            {
                program = Parser.Process(new FLParserInput(context.Filename)).Initialize(Instance, InstructionSet);
            }

            program.Run(input, true);

            return(program);
        }
Пример #10
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;
        }
        public static FLBuffer ComputeUrnd(bool isArray, int size, bool initializeOnStart)
        {
            LazyLoadingFLBuffer info = null;

            if (!isArray)
            {
                info = new LazyLoadingFLBuffer(
                    root =>
                {
                    FLBuffer buf = new FLBuffer(
                        root.Instance,
                        CLAPI.CreateRandom(
                            root.InputSize,
                            new byte[] { 1, 1, 1, 1 },
                            RandomInstructionHelper
                            .Randombytesource,
                            true
                            ),
                        root.Dimensions.x,
                        root.Dimensions.y,
                        root.Dimensions.z,
                        "RandomBuffer"
                        );
                    buf.SetRoot(root);
                    return(buf);
                },
                    initializeOnStart
                    );
            }
            else
            {
                info = new LazyLoadingFLBuffer(
                    root =>
                {
                    FLBuffer buf = new FLBuffer(
                        root.Instance,
                        CLAPI.CreateRandom(
                            size,
                            new byte[] { 1, 1, 1, 1 },
                            RandomInstructionHelper
                            .Randombytesource,
                            true
                            ),
                        size,
                        1,
                        1,
                        "RandomBuffer"
                        );
                    buf.SetRoot(root);
                    return(buf);
                },
                    initializeOnStart
                    );
            }


            return(info);
        }
Пример #12
0
        public FLProgram Run(FLProgram file, int width, int height)
        {
            FLBuffer buffer =
                new FLBuffer(
                    CLAPI.CreateEmpty <byte>(Instance, height * width * 4, MemoryFlag.ReadWrite,
                                             "FLRunnerExecutionCreatedBuffer"), width, height);

            return(Run(file, buffer, true));
        }
Пример #13
0
        public static string RunDeserializedFLExecutionBenchmark(string testAdd, List <string> files, int iterations,
                                                                 string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false,
                                                                 int workSizeMultiplier   = 2)
        {
            FLSetup setup = new FLSetup("FL_DeserializedExecution_Performance" + testAdd, "resources/kernel", performanceFolder,
                                        checkPipeline, useMultiThreading, workSizeMultiplier);
            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");

            for (int i = 0; i < files.Count; i++)
            {
                Bitmap   bmp = null;
                FLBuffer buf = null;
                SerializableFLProgram parsedProgram = null;
                MemoryStream          ms            = new MemoryStream();
                FLProgram             program       = null;
                string key = "FLDeserializedExecutionPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." +
                             i;

                Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);

                parsedProgram = setup.Parser.Process(new FLParserInput(files[i]));
                FLSerializer.SaveProgram(ms, parsedProgram, setup.InstructionSet, new string[0]);

                ms.Position   = 0;
                parsedProgram = FLSerializer.LoadProgram(ms, setup.InstructionSet);

                ms.Dispose();
                PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations,
                                                                                              (int its) => //BeforeTest
                {
                    bmp     = new Bitmap(BITMAP_RESOLUTION, BITMAP_RESOLUTION);
                    buf     = new FLBuffer(CLAPI.MainThread, bmp, files[i]);
                    program = parsedProgram.Initialize(setup.InstructionSet);
                },
                                                                                              (int its) => program.Run(CLAPI.MainThread, buf, true),
                                                                                              (int its) => //After Test
                {
                    if (its == iterations - 1)
                    {
                        SaveOutput("deserialized-output", bmp, program, setup, files[i]);
                    }

                    program.FreeResources();
                    bmp.Dispose();
                    buf.Dispose();
                });
                logOut.AppendLine("\t" + result);

                Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
                setup.WriteResult(result);
            }

            logOut.AppendLine();
            setup.WriteLog(logOut.ToString());
            setup.Dispose();
            return(logOut.ToString());
        }
Пример #14
0
        private void OnSaveFile()
        {
            if (sfdScript.ShowDialog() == DialogResult.OK)
            {
                if (sfdScript.FileName.EndsWith(".fl"))
                {
                    PluginHost.Editor.Path = sfdScript.FileName;
                    File.WriteAllText(PluginHost.Editor.Path, PluginHost.Editor.WrittenText);
                }
                else if (sfdScript.FileName.EndsWith(".flc"))
                {
                    PluginHost.Editor.FLContainer.SerializedProgram = null;
                    PluginHost.Editor.WriteAndBuild();
                    PluginHost.Editor.Build();
                    if (PluginHost.Editor.FLContainer.SerializedProgram == null)
                    {
                        return;
                    }

                    Stream stream = File.OpenWrite(sfdScript.FileName);
                    FLSerializer.SaveProgram(
                        stream,
                        PluginHost.Editor.FLContainer.SerializedProgram,
                        PluginHost.Editor.FLContainer.InstructionSet,
                        new string[0]
                        );
                    stream.Close();
                }
                else if (sfdScript.FileName.EndsWith(".png"))
                {
                    PluginHost.Editor.FLContainer.SerializedProgram = null;
                    PluginHost.Editor.WriteAndBuild();
                    PluginHost.Editor.Build();
                    if (PluginHost.Editor.FLContainer.SerializedProgram == null)
                    {
                        return;
                    }

                    FLBuffer input = PluginHost.Editor.FLContainer.CreateBuffer(
                        FLScriptEditor.Settings.ResX,
                        FLScriptEditor.Settings.ResY,
                        1,
                        "ImageExportInput"
                        );
                    FLProgram prog =
                        PluginHost.Editor.FLContainer.SerializedProgram.Initialize(PluginHost.Editor.FLContainer);
                    prog.Run(input, true);

                    Bitmap bmp = prog.GetActiveBitmap();

                    prog.FreeResources();
                    bmp.Save(sfdScript.FileName);
                    bmp.Dispose();
                }
            }
        }
Пример #15
0
 public override FLBuffer GetBuffer()
 {
     return(new LazyLoadingFLBuffer(root =>
     {
         Bitmap bmp = new Bitmap(Bitmap, root.Dimensions.x, root.Dimensions.y);
         FLBuffer buf = new FLBuffer(root.Instance, bmp, "BitmapBuffer." + Name);
         bmp.Dispose();
         return buf;
     }));
 }
Пример #16
0
        private void OnFinishCallback(FLProgram obj, string outputFile)
        {
            Logger.Log(LogType.Log, "Saving Output File: " + Path.GetFullPath(outputFile), 1);
            FLBuffer result = obj.GetActiveBuffer(false);
            Bitmap   bmp    = new Bitmap(result.Width, result.Height);

            CLAPI.UpdateBitmap(CLAPI.MainThread, bmp,
                               CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Size));
            bmp.Save(outputFile);
            result.Dispose();
        }
Пример #17
0
        private void LbInternalBuffersOnMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (lbInternalBuffers.SelectedItem == null)
            {
                return;
            }
            FLBuffer   buf = lbInternalBuffers.SelectedItem as FLBuffer;
            BufferView bvv = new BufferView(buf, Program.Dimensions.x, Program.Dimensions.y);

            bvv.Show();
        }
Пример #18
0
        private void LbInternalBuffersOnMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (lbInternalBuffers.SelectedItem == null || !started)
            {
                return;
            }

            FLBuffer buf = lbInternalBuffers.SelectedItem as FLBuffer;

            OnInternalBufferClick?.Invoke(Program, buf);
        }
Пример #19
0
        private static void SaveOutput(string subcategory, Bitmap bmp, FLProgram program, FLSetup setup, string file)
        {
            FLBuffer outP = program.GetActiveBuffer(false);

            CLAPI.UpdateBitmap(CLAPI.MainThread, bmp, outP.Buffer);
            outP.Dispose();
            string p         = Path.GetFileNameWithoutExtension(file) + ".png";
            Stream bmpStream = setup.GetDataFileStream(Path.Combine(subcategory, p));

            bmp.Save(bmpStream, ImageFormat.Png);
            bmpStream.Close();
        }
Пример #20
0
        public BufferView(FLBuffer buffer, int width, int height)
        {
            InitializeComponent();
            pbBufferContent = CreatePreviewBox(panelImage);
            Buffer          = buffer;
            this.width      = width;
            this.height     = height;
            Text            = buffer.DefinedBufferName + $"[{buffer.Buffer}]";

            comboBox1.Items.AddRange(Enum.GetNames(typeof(InterpolationMode)));
            comboBox1.SelectedIndex = 0;
        }
Пример #21
0
        public static FLBuffer ComputeRnd()
        {
            LazyLoadingFLBuffer info = new LazyLoadingFLBuffer(root =>
            {
                FLBuffer buf = new FLBuffer(root.Instance, CLAPI.CreateRandom(root.InputSize, new byte[] { 1, 1, 1, 1 },
                                                                              RandomInstructionHelper.Randombytesource, false), root.Dimensions.x, root.Dimensions.y,
                                            "RandomBuffer");
                buf.SetRoot(root);
                return(buf);
            });

            return(info);
        }
Пример #22
0
        protected override void InitializeScene()
        {
            creator       = BufferCreator.CreateWithBuiltInTypes();
            iset          = FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, "assets/kernel/");
            checkPipeline = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, creator);
            parser        = new FLParser(iset, creator);
            checkPipeline.Attach(parser, true);

            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.Zero);

            Add(bc);       //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from.


            GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box");  //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                       //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                            //The Mesh that is going to be used by the MeshRenderer
                tex,                                                     //Diffuse Texture to put on the mesh
                1);                                                      //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                       //Attaching the Renderer to the GameObject
            box.AddComponent(new RotateSelfComponent());                 //Adding a component that rotates the Object on the Y-Axis
            Add(box);                                                    //Adding the Object to the Scene.


            FLBuffer buffer =
                new FLBuffer(TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, tex, "BufferForFLProgram"), 128,
                             128);


            FLProgram program = parser.Process(new FLParserInput("assets/filter/red.fl")).Initialize(iset);


            program.Run(CLAPI.MainThread, buffer, true);

            FLBuffer result = program.GetActiveBuffer(false);

            byte[] dat = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Buffer.Size);
            //Create a texture from the output.
            TextureLoader.Update(tex, dat, 128, 128);
            result.Dispose();
        }
Пример #23
0
        public override void Process()
        {
            Logger.Log(LogType.Log, $"Running CL Kernel: {Kernel.Name}", MIN_INSTRUCTION_SEVERITY);

            ArgumentResult[] results = new ArgumentResult[Arguments.Count];
            Logger.Log(LogType.Log,
                       $"[{Kernel.Name}]Computing Kernel Arguments", MIN_INSTRUCTION_SEVERITY);
            for (int i = 0; i < Arguments.Count; i++)
            {
                results[i] = Compute(Arguments[i]);
            }

            for (int i = 0; i < results.Length; i++)
            {
                Logger.Log(LogType.Log,
                           $"[{Kernel.Name}]Setting Kernel Argument {Kernel.Parameter.First(x => x.Value.Id == i)}",
                           MIN_INSTRUCTION_SEVERITY + 1);
                int kernelArgIndex = i + FL_HEADER_ARG_COUNT;

                ArgumentResult arg = results[i];

                switch (arg.Type)
                {
                case FLInstructionArgumentType.Number:
                    Kernel.SetArg(kernelArgIndex, arg.Value);     //The Value is a Decimal
                    break;

                case FLInstructionArgumentType.Buffer:
                    FLBuffer bi = (FLBuffer)arg.Value;
                    Logger.Log(LogType.Log, $"[{Kernel.Name}]Argument Buffer{bi.DefinedBufferName}",
                               MIN_INSTRUCTION_SEVERITY + 2);
                    Kernel.SetBuffer(kernelArgIndex, bi.Buffer);
                    break;

                case FLInstructionArgumentType.Function:
                    FLBuffer funcBuffer = (FLBuffer)arg.Value;
                    Logger.Log(LogType.Log, $"[{Kernel.Name}]Argument Buffer{funcBuffer.DefinedBufferName}",
                               MIN_INSTRUCTION_SEVERITY + 2);
                    Kernel.SetBuffer(kernelArgIndex, funcBuffer.Buffer);
                    break;

                default:
                    throw new InvalidOperationException("Can not parse: " + arg.Value);
                }
            }

            CLAPI.Run(Root.Instance, Kernel, Root.ActiveBuffer.Buffer, Root.Dimensions, GenMaxSize,
                      Root.ActiveChannelBuffer, 4);
        }
Пример #24
0
        public void Process()
        {
            FLBuffer  input            = Root.ActiveBuffer;
            FLProgram externalFunction = ExternalFunctionBlueprint.Initialize(Root.Instance, InstructionSet);

            input.SetRoot(externalFunction);

            externalFunction.ActiveChannels = Root.ActiveChannels;
            externalFunction.SetCLVariables(input, false);

            //Not making it internal to the subscript because that would dispose the buffer later in the method
            //FLProgram.Debugger?.SubProgramStarted(Root, this, externalFunction);
            FLDebuggerHelper.OnSubProgramStart(
                Root,
                new FLDebuggerEvents.SubProgramStartEventArgs(
                    externalFunction,
                    this,
                    externalFunction
                    .EntryPoint,
                    false
                    )
                );

            //FLDebuggerHelper.OnProgramStart(externalFunction, new FLDebuggerEvents.ProgramStartEventArgs(externalFunction, externalFunction.EntryPoint, false, false));

            externalFunction.EntryPoint.Process();

            //FLProgram.Debugger?.SubProgramEnded(Root, externalFunction);
            FLDebuggerHelper.OnSubProgramExit(
                Root,
                new FLDebuggerEvents.SubProgramExitEventArgs(externalFunction, this)
                );

            //FLDebuggerHelper.OnProgramExit(externalFunction, new FLDebuggerEvents.ProgramExitEventArgs(externalFunction, false)); //Fire On Program Exit as External Function as well

            FLBuffer buf = externalFunction.ActiveBuffer;

            buf.SetRoot(Root);
            input.SetRoot(Root);
            externalFunction.RemoveFromSystem(buf);
            externalFunction.RemoveFromSystem(input);

            Root.ActiveChannels = externalFunction.ActiveChannels;
            Root.ActiveBuffer   = buf;


            externalFunction.FreeResources();
        }
Пример #25
0
        private void OnFinishCallback(FLProgram obj, Dictionary <string, Texture> map)
        {
            foreach (KeyValuePair <string, Texture> keyValuePair in map)
            {
                if (!obj.HasBufferWithName(keyValuePair.Key))
                {
                    Logger.Log(DebugChannel.OpenFL | DebugChannel.Warning,
                               "Can not Find Buffer with Name: " + keyValuePair.Key, 1);
                    continue;
                }

                FLBuffer
                    buf = obj.GetBufferWithName(keyValuePair.Key,
                                                false); //The buffer will get cleaned up when the program gets disposed.
                keyValuePair.Value.UpdateTexture(obj.Instance, buf.Buffer, buf.Width, buf.Height);
            }
        }
Пример #26
0
        private static void Apply(Texture dest, Texture spec, FLProgram prog)
        {
            GameWindow gw = new GameWindow(1, 1);

            gw.MakeCurrent();
            FLBuffer buf = prog.GetActiveBuffer(false);

            TextureLoader.Update(prog.Instance, dest, buf.Buffer);
            if (prog.BufferNames.Contains("specularOut"))
            {
                TextureLoader.Update(prog.Instance, spec, prog.GetBufferWithName("specularOut", false).Buffer);
            }

            prog.FreeResources();
            gw.Dispose();
            //GameEngine.Instance.MakeCurrent();
        }
Пример #27
0
        private void ExportViewer_Load(object sender, EventArgs e)
        {
            StyleManager.RegisterControls(this);


            Stream s = File.OpenRead(file);


            FLProgram p     = FLSerializer.LoadProgram(s, FLContainer.InstructionSet).Initialize(FLContainer);
            FLBuffer  input = FLContainer.CreateBuffer(512, 512, 1, "Input");

            p.Run(input, true);

            Bitmap bmp = p.GetActiveBitmap();

            pbExportView.Image = bmp;
        }
Пример #28
0
        public static FLProgram Initialize(this SerializableFLProgram program, FLInstructionSet instructionSet)
        {
            Dictionary <string, FLBuffer>           buffers           = new Dictionary <string, FLBuffer>();
            Dictionary <string, FLFunction>         functions         = new Dictionary <string, FLFunction>();
            Dictionary <string, ExternalFlFunction> externalFunctions = new Dictionary <string, ExternalFlFunction>();


            for (int i = 0; i < program.ExternalFunctions.Count; i++)
            {
                ExternalFlFunction extFunc = new ExternalFlFunction(program.ExternalFunctions[i].Name,
                                                                    program.ExternalFunctions[i].ExternalProgram, instructionSet);
                externalFunctions.Add(program.ExternalFunctions[i].Name, extFunc);
            }

            for (int i = 0; i < program.DefinedBuffers.Count; i++)
            {
                FLBuffer extFunc = program.DefinedBuffers[i].GetBuffer();
                extFunc.SetKey(program.DefinedBuffers[i].Name);
                buffers.Add(extFunc.DefinedBufferName, extFunc);
            }


            for (int i = 0; i < program.Functions.Count; i++)
            {
                functions.Add(program.Functions[i].Name, new FLFunction(program.Functions[i].Name));
            }

            FLProgram p = new FLProgram(externalFunctions, buffers, functions);

            for (int i = 0; i < program.Functions.Count; i++)
            {
                functions[program.Functions[i].Name].Initialize(program.Functions[i], p, instructionSet);
            }

            //TODO Resolve Functions first. then in a second step resolve the references of the arguments.
            //When a function is defined below it beeing used the program is crashing because
            //it resolves the argument before the function that the argument is pointing to is parsed(e.g. not null)
            //Create possibility to create the function objects in another loop than creating the arguments.
            //For functions
            //add the function objects with name to the dict
            //for functions
            //initialize function
            p.SetRoot();
            return(p);
        }
Пример #29
0
        private void OnFinishCallback(FLProgram obj, Dictionary <string, Texture> map)
        {
            GameWindow window = new GameWindow(100, 100, GraphicsMode.Default, "FLRunner");

            window.MakeCurrent();

            foreach (KeyValuePair <string, Texture> keyValuePair in map)
            {
                if (!obj.HasBufferWithName(keyValuePair.Key))
                {
                    Logger.Log(DebugChannel.OpenFL | DebugChannel.Warning,
                               "Can not Find Buffer with Name: " + keyValuePair.Key, 1);
                    continue;
                }

                FLBuffer buf = obj.GetBufferWithName(keyValuePair.Key, false); //program will clean the buffer
                keyValuePair.Value.UpdateTexture(obj.Instance, buf.Buffer, buf.Width, buf.Height);
            }

            obj.FreeResources();
            window.Dispose();
        }
Пример #30
0
        private FLBuffer ComputeFunction(FLInstructionArgument arg)
        {
            IFunction flFunction = (IFunction)arg.GetValue();  //Process the Function Object

            FLBuffer buffer =
                Root.RegisterUnmanagedBuffer(
                    new FLBuffer(
                        Root.Instance,
                        Root.Dimensions.x,
                        Root.Dimensions.y,
                        Root.Dimensions.z,
                        $"{flFunction.Name}_InputBuffer",
                        MemoryFlag.ReadWrite,
                        flFunction.Modifiers.GetModifiers()
                        .Contains(FLKeywords.OptimizeBufferCreationKeyword)
                        )
                    );

            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;

            Logger.Log(LogType.Log, "Returning from Function Context", MIN_INSTRUCTION_SEVERITY + 3);
            Root.ReturnFromContext(); //Restore active channels and buffer
            return(ret);
        }