public FLDataContainer() { Instance = CLAPI.GetInstance(); InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(Instance, "assets/kernel"); BufferCreator = BufferCreator.CreateWithBuiltInTypes(); Parser = new FLParser(InstructionSet, BufferCreator, WorkItemRunnerSettings.Default); }
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 static void SaveProgram(Stream s, SerializableFLProgram program, FLInstructionSet iset, string[] extraSteps, FLProgramHeader programHeader = null) { Byt3Serializer main = CreateLoader(iset); MemoryStream ms = new MemoryStream(); if (!main.TryWritePacket(ms, program)) { throw new FLDeserializationException("Can not parse stream"); } if (programHeader == null) { programHeader = new FLProgramHeader("Program", "NONE", Version.Parse("0.0.0.1")); } FLHeader header = new FLHeader(FLVersions.HeaderVersion, FLVersions.SerializationVersion, FLVersions.CommonVersion, extraSteps); byte[] p = ms.ToArray(); ms.Close(); FLFileFormat file = new FLFileFormat(header, programHeader, p); if (!main.TryWritePacket(s, file)) { throw new FLDeserializationException("Can not parse stream"); } }
public FLRunner(FLInstructionSet instructionSet, BufferCreator bufferCreator) : this( CLAPI.MainThread, instructionSet, bufferCreator ) { }
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); }
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()); }
public static FLInstruction Initialize(this SerializableFLInstruction instruction, FLProgram script, FLInstructionSet instructionSet) { FLInstruction i = instructionSet.Create(script, instruction); return(i); }
public FLProgramCheckBuilder(FLInstructionSet iset, BufferCreator bc) { ProgramChecks = new List <FLProgramCheck>(); InstructionSet = iset; BufferCreator = bc; StartProfile = FLProgramCheckType.None; PluginManager.LoadPlugins(this); }
public FLRunner(CLAPI instance, FLInstructionSet instructionSet, BufferCreator bufferCreator, FLProgramCheckBuilder checkPipeline) { InstructionSet = instructionSet; BufferCreator = bufferCreator; Parser = new FLParser(InstructionSet, BufferCreator); checkPipeline.Attach(Parser, true); Instance = instance; }
public FLRunner(CLAPI instance, KernelDatabase database) : this( instance, FLInstructionSet.CreateWithBuiltInTypes( database ), BufferCreator.CreateWithBuiltInTypes() ) { }
public SerializableFLProgramSerializer(Dictionary <Type, FLBaseSerializer> serializers, FLInstructionSet iset) { instructionSet = iset; BufferSerializer = Byt3Serializer.GetDefaultSerializer(); foreach (KeyValuePair <Type, FLBaseSerializer> keyValuePair in serializers) { BufferSerializer.AddSerializer(keyValuePair.Key, keyValuePair.Value); } }
public FLRunner(CLAPI instance, string kernelPath) : this( FLInstructionSet.CreateWithBuiltInTypes( instance, kernelPath ), BufferCreator.CreateWithBuiltInTypes() ) { }
public ExternalFlFunction( string name, SerializableFLProgram external, FLInstructionSet iset, FLExecutableElementModifiers modifiers) : base("ext-func") { Name = name; Modifiers = modifiers; ExternalFunctionBlueprint = external; InstructionSet = iset; }
public FLDataContainer( CLAPI instance, FLInstructionSet iset, BufferCreator creator, FLParser parser) { Instance = instance; //KernelDB = db; InstructionSet = iset; BufferCreator = creator; Parser = parser; }
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>(); }
public FLRunner(CLAPI instance, FLInstructionSet instructionSet, BufferCreator bufferCreator) : this( instance, instructionSet, bufferCreator, FLProgramCheckBuilder .CreateDefaultCheckBuilder( instructionSet, bufferCreator ) ) { }
public static FLProgramCheckBuilder CreateDefaultCheckBuilder(FLInstructionSet iset, BufferCreator bc) { FLProgramCheckBuilder pipeline = new FLProgramCheckBuilder(iset, bc); FLProgramCheck[] checks = Default; for (int i = 0; i < checks.Length; i++) { pipeline.AddProgramCheck(checks[i]); } return(pipeline); }
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)); } }
public FLProgramCheckBuilder( FLInstructionSet iset, BufferCreator bc, FLProgramCheckType profile = FLProgramCheckType.InputValidation) { StartProfile = profile; ProgramChecks = new List <FLProgramCheck>(); ProgramChecks.Sort((x, y) => y.Priority.CompareTo(x.Priority)); InstructionSet = iset; BufferCreator = bc; PluginManager.LoadPlugins(this); }
public FLC2TexUnpacker(CLAPI instance, FLInstructionSet iset, BufferCreator bc) { runner = new FLRunner( instance, iset, bc, FLProgramCheckBuilder.CreateDefaultCheckBuilder( iset, bc, FLProgramCheckType .InputValidationOptimized ) ); }
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(); }
public FLScriptRunner(CLAPI instance, KernelDatabase dataBase, BufferCreator creator, FLInstructionSet instructionSet, FLProgramCheckBuilder checkBuilder, WorkItemRunnerSettings runnerSettings) { Db = dataBase; InstructionSet = instructionSet; BufferCreator = creator; Parser = new FLParser(InstructionSet, BufferCreator, runnerSettings); ProgramChecks = checkBuilder; checkBuilder.Attach(Parser, true); Instance = instance; ProcessQueue = new Queue <FlScriptExecutionContext>(); }
public FLParser(FLInstructionSet instructionSet, BufferCreator bufferCreator, WorkItemRunnerSettings settings = null) : base(typeof(FLParserInput), typeof(SerializableFLProgram)) { InstructionSet = instructionSet; BufferCreator = bufferCreator; WorkItemRunnerSettings = settings ?? WorkItemRunnerSettings.Default; AddSubStage(new LoadSourceStage()); AddSubStage(new RemoveCommentStage(this)); AddSubStage(new StaticInspectionStage(this)); AddSubStage(new ParseTreeStage(this)); Verify(); }
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); }
public static SerializableFLProgram LoadProgram(Stream s, FLInstructionSet iset) { Byt3Serializer main = CreateLoader(iset); if (!main.TryReadPacket(s, out FLFileFormat file)) { throw new FLDeserializationException("Can not parse FL File Format"); } MemoryStream programStream = new MemoryStream(file.Program); if (!main.TryReadPacket(programStream, out SerializableFLProgram program)) { throw new FLDeserializationException("Program Data is Corrupt"); } return(program); }
public void OpenFL_DefineFile_Wrong_Test() { TestSetup.SetupTestingSession(); string file = "resources/filter/defines/test_wrong_define_invalid_file.fl"; Assert.Catch <Byt3Exception>(() => { BufferCreator bc = new BufferCreator(); FLInstructionSet iset = new FLInstructionSet(); FLProgramCheckBuilder checkBuilder = new FLProgramCheckBuilder(iset, bc); checkBuilder.AddProgramCheck(new FilePathValidator()); FLParser parser = new FLParser(iset, bc); checkBuilder.Attach(parser, true); Assembly asm = Assembly.GetAssembly(typeof(ASerializableBufferCreator)); parser.BufferCreator.AddBufferCreatorsInAssembly(asm); SerializableFLProgram pr = parser.Process(new FLParserInput(file)); }); }
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); }
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(); }
private static Byt3Serializer CreateLoader(FLInstructionSet iset) { SerializableBufferArgumentSerializer bbuf = new SerializableBufferArgumentSerializer(); SerializableDecimalArgumentSerializer debuf = new SerializableDecimalArgumentSerializer(); SerializableFunctionArgumentSerializer fabuf = new SerializableFunctionArgumentSerializer(); SerializableExternalFunctionArgumentSerializer exbuf = new SerializableExternalFunctionArgumentSerializer(); Dictionary <Type, FLBaseSerializer> argumentParser = new Dictionary <Type, FLBaseSerializer> { { typeof(SerializeBufferArgument), bbuf }, { typeof(SerializeDecimalArgument), debuf }, { typeof(SerializeFunctionArgument), fabuf }, { typeof(SerializeExternalFunctionArgument), exbuf } }; SerializableFLFunctionSerializer efunc = new SerializableFLFunctionSerializer(argumentParser); SerializableExternalFLFunctionSerializer exfunc = new SerializableExternalFLFunctionSerializer(iset); EmptyFLBufferSerializer ebuf = new EmptyFLBufferSerializer(); RandomFLBufferSerializer rbuf = new RandomFLBufferSerializer(); UnifiedRandomFLBufferSerializer urbuf = new UnifiedRandomFLBufferSerializer(); FromImageFLBufferSerializer fibuf = new FromImageFLBufferSerializer(true); WFCFLBufferSerializer wfcbuf = new WFCFLBufferSerializer(); Dictionary <Type, Serializers.Internal.FLBaseSerializer> bufferParser = new Dictionary <Type, Serializers.Internal.FLBaseSerializer> { { typeof(SerializableExternalFLFunction), exfunc }, { typeof(SerializableFLFunction), efunc }, { typeof(SerializableEmptyFLBuffer), ebuf }, { typeof(SerializableRandomFLBuffer), rbuf }, { typeof(SerializableUnifiedRandomFLBuffer), urbuf }, { typeof(SerializableFromFileFLBuffer), fibuf }, { typeof(SerializableWaveFunctionCollapseFLBuffer), wfcbuf }, }; SerializableFLProgramSerializer prog = new SerializableFLProgramSerializer(bufferParser, iset); Byt3Serializer main = Byt3Serializer.GetDefaultSerializer(); main.AddSerializer(typeof(SerializableFLProgram), prog); main.AddSerializer(typeof(FLFileFormat), new FLFileFormatSerializer()); return(main); }
public InstructionViewerForm(FLInstructionSet instructionSet) { InstructionSet = new List <FLInstructionCreator>(); InstructionKeys = instructionSet.GetInstructionNames().ToList(); for (int i = 0; i < instructionSet.CreatorCount; i++) { InstructionSet.Add(instructionSet.GetCreatorAt(i)); } InitializeComponent(); Text = $"Viewing {InstructionKeys.Count} Instructions"; Icon = FLEditorPluginHost.FLEditorIcon; StyleManager.RegisterControls(this); //FLScriptEditor.RegisterDefaultTheme(panelInstructions); //FLScriptEditor.RegisterDefaultTheme(gbInstructions); //FLScriptEditor.RegisterDefaultTheme(lbInstructions); //FLScriptEditor.RegisterDefaultTheme(panelMainInstructionView); //FLScriptEditor.RegisterDefaultTheme(panelOverloads); //FLScriptEditor.RegisterDefaultTheme(gbOverloads); //FLScriptEditor.RegisterDefaultTheme(lbOverloads); //FLScriptEditor.RegisterDefaultTheme(panelHeaderInfo); //FLScriptEditor.RegisterDefaultTheme(lblInstructionName); //FLScriptEditor.RegisterDefaultTheme(panelLegend); //FLScriptEditor.RegisterDefaultTheme(gbLegend); //FLScriptEditor.RegisterDefaultTheme(lbLegend); //FLScriptEditor.RegisterDefaultTheme(panelInstructionInfo); //FLScriptEditor.RegisterDefaultTheme(panelInstructionDescription); //FLScriptEditor.RegisterDefaultTheme(gbInstructionDescription); //FLScriptEditor.RegisterDefaultTheme(rtbInstructionDescription); //FLScriptEditor.RegisterDefaultTheme(panelInstructionName); }