Esempio n. 1
0
        public FLSetup(string testName, string kernelPath, string performance = "performance", Type[] checkPipeline = null,
                       bool useMultiThreading = false, int workSizeMultiplier = 2) : base(testName, performance)
        {
            KernelDatabase = new KernelDatabase(CLAPI.MainThread, kernelPath, DataVectorTypes.Uchar1);
            InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(KernelDatabase);
            BufferCreator  = BufferCreator.CreateWithBuiltInTypes();
            CheckBuilder   = null;
            if (checkPipeline == null)
            {
                CheckBuilder = FLProgramCheckBuilder.CreateDefaultCheckBuilder(InstructionSet, BufferCreator);
            }
            else
            {
                CheckBuilder = new FLProgramCheckBuilder(InstructionSet, BufferCreator);
                foreach (Type useCheck in checkPipeline)
                {
                    CheckBuilder.AddProgramCheck((FLProgramCheck)Activator.CreateInstance(useCheck));
                }
            }


            Parser = new FLParser(InstructionSet, BufferCreator,
                                  new WorkItemRunnerSettings(useMultiThreading, workSizeMultiplier));

            CheckBuilder.Attach(Parser, true);

            Directory.CreateDirectory(RunResultPath);
            Directory.CreateDirectory(DataOutputDirectory);
        }
Esempio n. 2
0
        public static string RunParserInitBenchmark(string testAdd, int iterations,
                                                    string performanceFolder = "performance", bool useChecks = true, bool useMultiThreading = false,
                                                    int workSizeMultiplier   = 2)
        {
            //FLSetup setup = new FLSetup("FL_ParserProcess_Performance"+ testAdd, "resources/kernel", performanceFolder,
            //    useChecks, useMultiThreading, workSizeMultiplier);
            StringBuilder logOut = new StringBuilder($"Performance Tests: {DateTime.Now:HH:mm:ss}\n");


            FLInstructionSet      iset         = null;
            BufferCreator         bc           = null;
            FLParser              parser       = null;
            FLProgramCheckBuilder checkBuilder = null;
            KernelDatabase        db           = new KernelDatabase(CLAPI.MainThread, "resources/kernel", DataVectorTypes.Uchar1);
            string key = "ParserInitPerformance";

            Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1);
            PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations, null,
                                                                                          (int its) =>
            {
                iset         = FLInstructionSet.CreateWithBuiltInTypes(db);
                bc           = BufferCreator.CreateWithBuiltInTypes();
                checkBuilder = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, bc);
                parser       = new FLParser(iset, bc);
            }, null);

            logOut.AppendLine("\t" + result);
            Logger.Log(LogType.Log, $"------------------------Run {key} Finished------------------------", 1);
            return(logOut.ToString());
        }
Esempio n. 3
0
 public FLDataContainer()
 {
     Instance       = CLAPI.GetInstance();
     InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(Instance, "assets/kernel");
     BufferCreator  = BufferCreator.CreateWithBuiltInTypes();
     Parser         = new FLParser(InstructionSet, BufferCreator, WorkItemRunnerSettings.Default);
 }
Esempio n. 4
0
 public FLRunner(CLAPI instance, string kernelPath) : this(
         FLInstructionSet.CreateWithBuiltInTypes(
             instance,
             kernelPath
             ),
         BufferCreator.CreateWithBuiltInTypes()
         )
 {
 }
Esempio n. 5
0
 public FLRunner(CLAPI instance, KernelDatabase database) : this(
         instance,
         FLInstructionSet.CreateWithBuiltInTypes(
             database
             ),
         BufferCreator.CreateWithBuiltInTypes()
         )
 {
 }
Esempio n. 6
0
        private static FLDataContainer InitializeCLKernels(string kernelPath)
        {
            {
                CLAPI instance = CLAPI.GetInstance();
                Logger.Log(LogType.Log, "Discovering Files in Path: " + kernelPath, 1);
                string[] files = IOManager.DirectoryExists(kernelPath)
                                     ? IOManager.GetFiles(kernelPath, "*.cl")
                                     : new string[0];

                if (files.Length == 0)
                {
                    Logger.Log(LogType.Error, "Error: No Files found at path: " + kernelPath, 1);
                }

                KernelDatabase dataBase             = new KernelDatabase(DataVectorTypes.Uchar1);
                List <CLProgramBuildResult> results = new List <CLProgramBuildResult>();
                bool throwEx     = false;
                int  kernelCount = 0;
                int  fileCount   = 0;

                foreach (string file in files)
                {
                    Logger.Log(
                        LogType.Log,
                        $"[{fileCount}/{files.Length}]Loading: {file} ({kernelCount})",
                        2
                        );
                    try
                    {
                        CLProgram prog = dataBase.AddProgram(instance, file, false, out CLProgramBuildResult res);
                        kernelCount += prog.ContainedKernels.Count;
                        throwEx     |= !res;
                        results.Add(res);
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogType.Error, "ERROR: " + e.Message, 2);
                    }

                    fileCount++;
                }


                Logger.Log(LogType.Log, "Kernels Loaded: " + kernelCount, 1);


                FLInstructionSet iset    = FLInstructionSet.CreateWithBuiltInTypes(dataBase);
                BufferCreator    creator = BufferCreator.CreateWithBuiltInTypes();
                FLParser         parser  = new FLParser(iset, creator, new WorkItemRunnerSettings(true, 2));

                return(new FLDataContainer(instance, iset, creator, parser));
            }
        }
Esempio n. 7
0
 public FLScriptRunner(CLAPI instance, DataVectorTypes dataVectorTypes = DataVectorTypes.Uchar1,
                       string kernelFolder = "resources/kernel")
 {
     Db             = new KernelDatabase(instance, kernelFolder, dataVectorTypes);
     InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(Db);
     BufferCreator  = BufferCreator.CreateWithBuiltInTypes();
     ProgramChecks  = FLProgramCheckBuilder.CreateDefaultCheckBuilder(InstructionSet, BufferCreator);
     Parser         = new FLParser(InstructionSet, BufferCreator);
     ProgramChecks.Attach(Parser, true);
     Instance     = instance;
     ProcessQueue = new Queue <FlScriptExecutionContext>();
 }
Esempio n. 8
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();
        }
Esempio n. 9
0
        private void Run()
        {
            FLConsole.Settings.SetVerbosity();
            BufferCreator creator = new BufferCreator();

            FLConsole.Settings.BufferCreatorTypes.ForEach(x =>
                                                          creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x)));
            KernelDatabase db = new KernelDatabase(CLAPI.MainThread, FLConsole.Settings.KernelFolder,
                                                   DataVectorTypes.Uchar1);
            FLInstructionSet      iset = FLInstructionSet.CreateWithBuiltInTypes(db);
            FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator);

            FLConsole.Settings.ProgramCheckTypes.ForEach(x =>
                                                         programCheckBuilder.AddProgramCheck((FLProgramCheck)Activator.CreateInstance(x)));


            FLScriptRunner runner =
                new FLScriptRunner(CLAPI.MainThread, db, creator, iset, programCheckBuilder,
                                   new WorkItemRunnerSettings(FLConsole.Settings.MultiThread,
                                                              FLConsole.Settings.WorkSizeMultiplier));

            string[] inputFiles  = SetInputFilesCommand.InputFiles;
            string[] outputFiles = SetOutputFilesCommand.OutputFiles;


            for (int i = 0; i < inputFiles.Length; i++)
            {
                string inp  = inputFiles[i];
                string outp = outputFiles.Length > i
                    ? outputFiles[i]
                    : $"./{Path.GetFileNameWithoutExtension(inp)}.out.png";

                Bitmap bmp = new Bitmap(FLConsole.Settings.Resolution.X,
                                        FLConsole.Settings.Resolution.Y);

                runner.Enqueue(new FlScriptExecutionContext(inp, bmp, result => OnFinishCallback(result, outp)));
            }

            runner.Process();
        }
Esempio n. 10
0
        private void Build()
        {
            FLConsole.Settings.SetVerbosity();
            string[] inputFiles  = SetInputFilesCommand.InputFiles;
            string[] outputFiles = SetOutputFilesCommand.OutputFiles;

            BufferCreator creator = new BufferCreator();

            FLConsole.Settings.BufferCreatorTypes.ForEach(x =>
                                                          creator.AddBufferCreator((ASerializableBufferCreator)Activator.CreateInstance(x)));
            FLInstructionSet iset =
                FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, FLConsole.Settings.KernelFolder);
            FLProgramCheckBuilder programCheckBuilder = new FLProgramCheckBuilder(iset, creator);

            FLParser p = new FLParser(iset, creator,
                                      new WorkItemRunnerSettings(FLConsole.Settings.MultiThread,
                                                                 FLConsole.Settings.WorkSizeMultiplier));

            programCheckBuilder.Attach(p, true);

            Logger.Log(LogType.Log, $"Building {inputFiles.Length} Files", 1);

            for (int i = 0; i < inputFiles.Length; i++)
            {
                string inp = inputFiles[i];
                Logger.Log(LogType.Log, $"Building {inp}", 2);
                string outp = outputFiles.Length > i
                    ? outputFiles[i]
                    : $"./{Path.GetFileNameWithoutExtension(inp)}.flc";

                SerializableFLProgram prog = p.Process(new FLParserInput(inp));

                Stream dst = File.Create(outp);
                FLSerializer.SaveProgram(dst, prog, iset, ExtraStepCommand.extras);
                dst.Close();
                Logger.Log(LogType.Log, $"Output: {outp}", 2);
            }

            Logger.Log(LogType.Log, $"Finished Building {inputFiles.Length} Files", 1);
        }
Esempio n. 11
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);
            Mesh plane = MeshLoader.FileToMesh("assets/models/plane.obj");

            Texture texQuad   = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureQuad");
            Texture texSphere = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureSphere");

            GameObject objSphere = new GameObject(new Vector3(1, 1, 0), "SphereDisplay");

            LitMeshRendererComponent sphereLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader,
                                                                              Prefabs.Sphere,
                                                                              texSphere, 1);

            objSphere.AddComponent(sphereLmr);
            sphereLmr.Textures = new[]
            { sphereLmr.Textures[0], DefaultFilepaths.DefaultTexture };

            objSphere.AddComponent(new RotatingComponent());

            GameObject objQuad = new GameObject(new Vector3(-1, 1, 0), "QuadDisplay");
            LitMeshRendererComponent quadLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, plane,
                                                                            texQuad, 1);

            objQuad.AddComponent(quadLmr);
            quadLmr.Textures = new[]
            { quadLmr.Textures[0], DefaultFilepaths.DefaultTexture };

            objQuad.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(45));

            GameObject sourceCube = new GameObject(new Vector3(0, 10, 10), "Light Source");

            sourceCube.AddComponent(new LightComponent());
            sourceCube.AddComponent(new RotateAroundComponent {
                Slow = 0.15f
            });
            sourceCube.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube,
                                                                 TextureLoader.ColorToTexture(Color.White), 1));

            GameObject uiText = new GameObject(new Vector3(0), "UIText");

            uiText.AddComponent(new FlGeneratorComponent(new List <LitMeshRendererComponent>
            {
                sphereLmr, quadLmr
            },
                                                         512,
                                                         512, true));

            Add(sourceCube);
            Add(uiText);
            Add(DebugConsoleComponent.CreateConsole());
            Add(objSphere);
            Add(objQuad);

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG")
            {
                Scale = new Vector3(25, 1, 25)
            };


            bgObj.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube,
                                                            GenerateGroundTexture(), 1));
            Add(bgObj);


            BasicCamera mainCamera =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            object mc = mainCamera;

            EngineConfig.LoadConfig("assets/configs/camera_fldemo.xml", ref mc);


            Add(mainCamera);
            SetCamera(mainCamera);

            GameObject camContainer = new GameObject("CamContainer");

            BasicCamera inPicCam =
                new BasicCamera(
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                         GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            inPicCam.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(0));
            inPicCam.Translate(new Vector3(0, 2, 4));
            inPicCam.AddComponent(new RotateAroundComponent());
            GameObject zeroPoint = new GameObject("Zero");

            Add(zeroPoint);
            LookAtComponent comp = new LookAtComponent();

            comp.SetTarget(zeroPoint);
            inPicCam.AddComponent(comp);
            Add(inPicCam);


            splitCam = new RenderTarget(inPicCam, 1, Color.FromArgb(0, 0, 0, 0))
            {
                MergeType = RenderTargetMergeType.Additive,
                ViewPort  = new Rectangle(0, 0, (int)(GameEngine.Instance.Width * 0.3f),
                                          (int)(GameEngine.Instance.Height * 0.3f))
            };

            Add(camContainer);
            GameEngine.Instance.AddRenderTarget(splitCam);
        }
Esempio n. 12
0
 public FLParser(KernelDatabase db) : this(
         FLInstructionSet.CreateWithBuiltInTypes(db),
         BufferCreator.CreateWithBuiltInTypes()
         )
 {
 }
Esempio n. 13
0
        private void Initialize()
        {
            CLAPI  instance = CLAPI.GetInstance();
            string path     = FLScriptEditor.Settings.KernelPath;

            StartupSequence.loaderForm.SetStatus("Discovering Files in Path: " + path);
            string[] files = IOManager.DirectoryExists(path) ? IOManager.GetFiles(path, "*.cl") : new string[0];

            if (files.Length == 0)
            {
                DialogResult res = StyledMessageBox.Show(
                    "Error",
                    "No Files found at path: " + path,
                    MessageBoxButtons.AbortRetryIgnore,
                    SystemIcons.Error
                    );
                if (res == DialogResult.Retry)
                {
                    Initialize();
                    return;
                }

                if (res == DialogResult.Abort)
                {
                    StartupSequence.loaderForm.DialogResult = DialogResult.Abort;
                    StartupSequence.loaderForm.Close();
                    return;
                }

                if (res == DialogResult.Ignore)
                {
                    StartupSequence.loaderForm.DialogResult = DialogResult.OK;
                }
            }

            KernelDatabase dataBase             = new KernelDatabase(DataVectorTypes.Uchar1);
            List <CLProgramBuildResult> results = new List <CLProgramBuildResult>();
            bool throwEx     = false;
            int  kernelCount = 0;
            int  fileCount   = 0;

            if (FLScriptEditor.Settings.ExperimentalKernelLoading)
            {
                try
                {
                    string    source = TextProcessorAPI.PreprocessSource(files, new Dictionary <string, bool>());
                    CLProgram prog   = dataBase.AddProgram(instance, source, "./", false, out CLProgramBuildResult res);
                    throwEx |= !res;
                    if (res)
                    {
                        kernelCount += prog.ContainedKernels.Count;
                    }

                    results.Add(res);
                    StartupSequence.loaderForm.SetStatus($"File Loaded(Kernels Loaded): ({kernelCount})");
                }
                catch (Exception e)
                {
                    throw new SoftException(e);
                }
            }
            else
            {
                foreach (string file in files)
                {
                    StartupSequence.loaderForm.SetStatus(
                        $"[{fileCount}/{files.Length}]Loading: {file} ({kernelCount})"
                        );
                    try
                    {
                        CLProgram prog = dataBase.AddProgram(instance, file, false, out CLProgramBuildResult res);
                        kernelCount += prog.ContainedKernels.Count;
                        throwEx     |= !res;
                        results.Add(res);
                    }
                    catch (Exception e)
                    {
                        StartupSequence.loaderForm.Log("ERROR: " + e.Message, Color.Red);

                        throw e; //Let the Exception Viewer Catch that
                    }

                    fileCount++;
                }
            }


            StartupSequence.loaderForm.SetStatus("Loading Finished");
            StartupSequence.loaderForm.Log("Loading Finished", Color.White);
            StartupSequence.loaderForm.Log("Kernels Loaded: " + kernelCount, Color.White);

            if (throwEx)
            {
                DialogResult res =
                    StyledMessageBox.Show(
                        "OpenCL Build Errors",
                        "There are errors in one or more OpenCL kernels. Do you want to open the OpenCL Build Excepion Viewer?",
                        MessageBoxButtons.YesNoCancel,
                        SystemIcons.Warning
                        );
                if (res == DialogResult.Cancel)
                {
                    StartupSequence.loaderForm.DialogResult = DialogResult.Abort;
                    StartupSequence.loaderForm.Close();
                }
                else if (res == DialogResult.Yes)
                {
                    BuildExceptionViewer bvr = new BuildExceptionViewer(new CLBuildException(results));
                    if (bvr.ShowDialog() == DialogResult.Retry)
                    {
                        dataBase.Dispose();
                        Initialize();
                    }
                }
            }

            FLInstructionSet iset    = FLInstructionSet.CreateWithBuiltInTypes(dataBase);
            BufferCreator    creator = BufferCreator.CreateWithBuiltInTypes();
            FLParser         parser  = new FLParser(iset, creator, new WorkItemRunnerSettings(true, 2));

            StartupSequence.FlContainer = new FLDataContainer(instance, iset, creator, parser);
        }