public void OnProgramStart(FLProgram program, FLDebuggerEvents.ProgramStartEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnProgramStart(args); } }
public void OnAddInternalBuffer(FLProgram program, FLBuffer internalBuffer) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnAddInternalBuffer(internalBuffer); } }
public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator) { progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3); SerializableFLProgram prog = FLSerializer.LoadProgram(stream, runner.InstructionSet); progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3); FLProgram p = runner.Run(prog, 512, 512, 1); string filePath = Path.Combine( targetDir, name.Replace("/", "\\").StartsWith("\\") ? name.Replace("/", "\\").Substring(1) : name.Replace("/", "\\") ); Directory.CreateDirectory(Path.GetDirectoryName(filePath)); filePath = filePath.Remove(filePath.Length - 3, 3) + "png"; progressIndicator?.SetProgress( $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}", 3, 3 ); Bitmap bmp = new Bitmap(512, 512); CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer); bmp.Save(filePath); stream.Close(); p.FreeResources(); progressIndicator?.Dispose(); }
public void OnBufferWarm(FLProgram program, FLDebuggerEvents.WarmEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnBufferWarm(args); } }
private Texture GenerateMenuBackground() { Stopwatch sw = new Stopwatch(); sw.Start(); int texWidth = 128; int texHeight = 128; FLRunner runner = new FLRunner(CLAPI.MainThread, "resources/kernel"); FLProgram prog = runner.Run("assets/filter/game/menubg.fl", texWidth, texHeight); //Interpreter i = new Interpreter(Clapi.MainThread, "assets/filter/game/menubg.fl", DataTypes.Uchar1, // Clapi.CreateEmpty<byte>(Clapi.MainThread, texWidth * texHeight * 4, MemoryFlag.ReadWrite), texWidth, // texHeight, 1, 4, "assets/kernel/", true); //do //{ // i.Step(); //} while (!i.Terminated); Texture tex = TextureLoader.ParameterToTexture(texWidth, texHeight, "MenugBG"); TextureLoader.Update(CLAPI.MainThread, tex, prog.GetActiveBuffer(false).Buffer); Logger.Log(DebugChannel.Log, "Time for Menu Background(ms): " + sw.ElapsedMilliseconds, 10); sw.Stop(); prog.FreeResources(); return(tex); }
public static string RunProgramInitBenchmark(string testAdd, List <string> files, int iterations, string performanceFolder = "performance", Type[] checkPipeline = null, bool useMultiThreading = false, int workSizeMultiplier = 2) { FLSetup setup = new FLSetup("FL_ProgramInit_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++) { //Untimed SerializableFLProgram pr = setup.Parser.Process(new FLParserInput(files[i])); FLProgram program = null; string key = "ProgramInitPerformance+" + Path.GetFileNameWithoutExtension(files[i]) + "." + i; Logger.Log(LogType.Log, $"------------------------Run {key} Starting------------------------", 1); PerformanceTester.PerformanceResult result = PerformanceTester.Tester.RunTest(key, iterations, null, (int its) => { program = pr.Initialize(setup.InstructionSet); }, (int its) => program.FreeResources()); 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()); }
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); }
public CodeView(FLProgram program) { Program = program; marks = Program.ToString(out string source); Source = source; InitializeComponent(); }
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 void AfterFunction(FLProgram program, FLDebuggerEvents.FunctionRunEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].AfterFunction(args); } }
public void OnInstructionStepInto(FLProgram program, FLDebuggerEvents.InstructionRunEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnInstructionStepInto(args); } }
public void OnInternalBufferLoad(FLProgram program, FLDebuggerEvents.InternalBufferLoadEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnInternalBufferLoad(args); } }
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(); }
public void SubProgramEnded(FLProgram program, FLProgram script) { if (Debuggers[program].FollowScripts) { ProgramExit(script); } Debuggers[program].SubProgramEnded(); }
public void ProgramStart(FLProgram program) { if (!Debuggers.ContainsKey(program)) { Register(program); } Debuggers[program].ProgramStart(); }
public void OnProgramExit(FLProgram program, FLDebuggerEvents.ProgramExitEventArgs args) { if (Debuggers.ContainsKey(program)) { Debuggers[program].OnProgramExit(args); Debuggers.Remove(program); } }
public virtual void Process() { while (ProcessQueue.Count != 0) { FlScriptExecutionContext fle = ProcessQueue.Dequeue(); FLProgram ret = Process(fle); fle.OnFinishCallback?.Invoke(ret); } }
public SubProgramStartEventArgs( FLProgram root, ExternalFlFunction externalSymbol, IFunction entryFunction, bool warmBuffers) : base( root, entryFunction, warmBuffers ) { ExternalSymbol = externalSymbol; }
public void ProcessEvent(FLParsedObject obj) { FLProgram rt = obj.Root; if (Debuggers.ContainsKey(rt)) { Debuggers[rt].ProcessEvent(obj); } }
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()); }
public void SubProgramStarted(FLProgram program, ExternalFlFunction subProgram, FLProgram script) { Debuggers[program].ProcessEvent(subProgram); Debuggers[program].SubProgramStarted(); if (Debuggers[program].FollowScripts) { ProgramStart(script); } }
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)); }
public static FLInstruction Initialize( this SerializableFLInstruction instruction, FLProgram script, FLFunction func, FLInstructionSet instructionSet) { FLInstruction i = instructionSet.Create(script, func, instruction); return(i); }
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"); }
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(); } } }
private object _proc() { while (ProcessQueue.Count != 0) { FlScriptExecutionContext fle = ProcessQueue.Dequeue(); FLProgram texUpdate = Process(fle); fle.OnFinishCallback?.Invoke(texUpdate); } OnFinishQueue?.Invoke(); return(new object()); }
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(); }
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, 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)); args.Add(arg); } return((FLInstruction)Activator.CreateInstance(type, new object[] { args })); }
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(); }