示例#1
0
        public static FLInstructionSet CreateWithBuiltInTypes(CLAPI instance, string clKernelPath)
        {
            KernelDatabase db =
                new KernelDatabase(instance, clKernelPath, DataVectorTypes.Uchar1);

            return(CreateWithBuiltInTypes(db));
        }
示例#2
0
        public void OpenFL_WFCDefines_Wrong_Test()
        {
            string[] files = Directory.GetFiles("resources/filter/defines/", "test_wrong_define_wfc_*.fl");


            foreach (string file in files)
            {
                try
                {
                    FLInterpreter p = new FLInterpreter(CLAPI.MainThread, file,
                                                        CLAPI.CreateEmpty <byte>(CLAPI.MainThread, 128 * 128 * 4,
                                                                                 MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite),
                                                        128,
                                                        128,
                                                        1,
                                                        4, TestSetup.KernelDb);
                }
                catch (Exception e)
                {
                    if (!(e is FLInvalidFunctionUseException))
                    {
                        Assert.True(false);
                    }

                    //We passed
                }
            }
        }
 private void FlFinished(Dictionary <Bitmap, byte[]> result)
 {
     foreach (KeyValuePair <Bitmap, byte[]> keyValuePair in result)
     {
         CLAPI.UpdateBitmap(CLAPI.MainThread, keyValuePair.Key, keyValuePair.Value);
     }
 }
示例#4
0
 /// <summary>
 /// A public constructor
 /// </summary>
 /// <param name="instance">CLAPI Instance for the current thread</param>
 /// <param name="file">The file containing the source</param>
 /// <param name="genType">The Type of the data the interpreter is operating on</param>
 /// <param name="input">The input buffer</param>
 /// <param name="width">Width of the input buffer</param>
 /// <param name="height">Height of the input buffer</param>
 /// <param name="depth">Depth of the input buffer</param>
 /// <param name="channelCount">The Channel Count</param>
 /// <param name="kernelDbFolder">The folder the kernel data base will be initialized in</param>
 public FLInterpreter(CLAPI instance, string file, DataTypes genType, MemoryBuffer input,
                      int width, int height,
                      int depth,
                      int channelCount, string kernelDbFolder) : this(instance, file, input, width, height, depth, channelCount,
                                                                      new KernelDatabase(instance, kernelDbFolder, genType), false)
 {
 }
示例#5
0
        public virtual void Process(Action onFinish = null)
        {
            while (ProcessQueue.Count != 0)
            {
                FlScriptExecutionContext    fle    = ProcessQueue.Dequeue();
                Dictionary <string, byte[]> ret    = Process(fle);
                Dictionary <Bitmap, byte[]> texMap = new Dictionary <Bitmap, byte[]>();
                foreach (KeyValuePair <string, byte[]> bytese in ret)
                {
                    if (fle.TextureMap.ContainsKey(bytese.Key))
                    {
                        texMap.Add(fle.TextureMap[bytese.Key], bytese.Value);
                    }
                }

                foreach (KeyValuePair <Bitmap, byte[]> textureUpdate in texMap)
                {
                    CLAPI.UpdateBitmap(CLAPI.MainThread, textureUpdate.Key, textureUpdate.Value);
                }

                fle.OnFinishCallback?.Invoke(texMap);
            }

            onFinish?.Invoke();
        }
示例#6
0
 public FLScriptRunner(
     CLAPI instance, DataTypes dataTypes = DataTypes.Uchar1, string kernelFolder = "assets/kernel/")
 {
     Instance     = instance;
     Db           = new KernelDatabase(instance, kernelFolder, dataTypes);
     ProcessQueue = new Queue <FlScriptExecutionContext>();
 }
示例#7
0
        /// <summary>
        /// Resets the Interpreter to work with a new script
        /// </summary>
        /// <param name="file">The file containing the source</param>
        /// <param name="input">The input buffer</param>
        /// <param name="width">Width of the input buffer</param>
        /// <param name="height">Height of the input buffer</param>
        /// <param name="depth">Depth of the input buffer</param>
        /// <param name="channelCount">The Channel Count</param>
        /// <param name="kernelDB">The Kernel DB that will be used</param>
        /// <param name="ignoreDebug">a flag to ignore the brk statement</param>
        public void Reset(string file, MemoryBuffer input, int width, int height, int depth, int channelCount,
                          KernelDatabase kernelDB, bool ignoreDebug)
        {
            //Clear old stuff

            ReleaseResources();

            //Setting variables
            _currentBuffer = new CLBufferInfo(input, false);
            _currentBuffer.SetKey(InputBufferName);

            _ignoreDebug     = ignoreDebug;
            _width           = width;
            _height          = height;
            _depth           = depth;
            _channelCount    = channelCount;
            _kernelDb        = kernelDB;
            _activeChannels  = new byte[_channelCount];
            _currentArgStack = new Stack <object>();
            for (int i = 0; i < _channelCount; i++)
            {
                _activeChannels[i] = 1;
            }

            _activeChannelBuffer =
                CLAPI.CreateBuffer(_activeChannels, MemoryFlag.ReadOnly | MemoryFlag.CopyHostPointer);

            //Parsing File
            _currentBuffer.SetKey(InputBufferName);
            Data = LoadScriptData(file, _currentBuffer, width, height, depth, channelCount, _kernelDb, _flFunctions);

            Reset();
        }
示例#8
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);
            }
        }
示例#9
0
        protected Dictionary <string, byte[]> Process(FlScriptExecutionContext context)
        {
            MemoryBuffer  buf = CLAPI.CreateBuffer(Instance, context.Input, MemoryFlag.ReadWrite);
            FLInterpreter ret = new FLInterpreter(Instance, context.Filename, buf, context.Width,
                                                  context.Height, 1, 4, Db, true);

            do
            {
                ret.Step();
            } while (!ret.Terminated);


            byte[] buffer = ret.GetResult <byte>();
            Dictionary <string, byte[]> result = new Dictionary <string, byte[]> {
                { "result", buffer }
            };

            foreach (KeyValuePair <string, Bitmap> keyValuePair in context.TextureMap)
            {
                CLBufferInfo mbuf = ret.GetBuffer(keyValuePair.Key);
                if (mbuf == null)
                {
                    continue;
                }

                byte[] spec = CLAPI.ReadBuffer <byte>(Instance, mbuf.Buffer, (int)mbuf.Buffer.Size);
                result.Add(keyValuePair.Key, spec);
                mbuf.Buffer.Dispose();
            }

            return(result);
        }
示例#10
0
        private void RefreshImage(CLAPI instance)
        {
            if (isRefreshing)
            {
                return;
            }

            isRefreshing = true;
            SetLoadingImage(true);
            Task t = new Task(() => { DisplayContent(instance); });

            //DisplayContent(instance);
            t.Start();
            while (!t.IsCompleted)
            {
                Application.DoEvents();
            }

            if (t.IsFaulted)
            {
                StyledMessageBox.Show(
                    "Error",
                    "Can not show content of a disposed Buffer, form exiting\n" +
                    t.Exception.InnerException.Message,
                    MessageBoxButtons.OK,
                    SystemIcons.Error
                    );
                Close();
                return;
            }

            SetLoadingImage(false);
            isRefreshing = false;
        }
示例#11
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();
        }
示例#12
0
        public void OpenFL_DefineScriptFile_Wrong_Test()
        {
            string file = "resources/filter/defines/test_wrong_script_invalid_file.fl";

            for (int i = 0; i < 2; i++)
            {
                try
                {
                    FLInterpreter p = new FLInterpreter(CLAPI.MainThread, file,
                                                        CLAPI.CreateEmpty <byte>(CLAPI.MainThread, 128 * 128 * 4,
                                                                                 MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite), 128,
                                                        128,
                                                        1,
                                                        4, TestSetup.KernelDb);
                }
                catch (Exception e)
                {
                    if (!(e is FLInvalidFunctionUseException))
                    {
                        Assert.True(false);
                    }

                    //We passed
                }
            }
        }
示例#13
0
        public void CreateEmptyCopy()
        {
            byte[]       data = new byte[BufferSize];
            MemoryBuffer buf  = CLAPI.CreateBuffer(instance, data, MemoryFlag.ReadWrite, "TestEmptyAlloc");

            buf.Dispose();
        }
示例#14
0
 public FLDataContainer()
 {
     Instance       = CLAPI.GetInstance();
     InstructionSet = FLInstructionSet.CreateWithBuiltInTypes(Instance, "assets/kernel");
     BufferCreator  = BufferCreator.CreateWithBuiltInTypes();
     Parser         = new FLParser(InstructionSet, BufferCreator, WorkItemRunnerSettings.Default);
 }
示例#15
0
        public void FLDefineFile_Wrong()
        {
            DebugHelper.ThrowOnAllExceptions = true;

            string file = "resources/filter/defines/test_wrong_define_invalid_file.fl";


            for (int i = 0; i < 2; i++)
            {
                DebugHelper.ThrowOnAllExceptions = i == 0;
                try
                {
                    Interpreter P = new Interpreter(file,
                                                    CLAPI.CreateEmpty <byte>(128 * 128 * 4, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite), 128,
                                                    128,
                                                    1,
                                                    4, TestSetup.KernelDB);
                    Assert.True(!DebugHelper.ThrowOnAllExceptions);
                }
                catch (Exception e)
                {
                    Assert.True(DebugHelper.ThrowOnAllExceptions);
                    if (!(e is FLInvalidFunctionUseException))
                    {
                        Assert.True(false);
                    }

                    //We passed
                }
            }
        }
示例#16
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);
        }
示例#17
0
        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();
        }
示例#18
0
        /// <summary>
        /// Resets the FLInterpreter to work with a new script
        /// </summary>
        /// <param name="file">The file containing the source</param>
        /// <param name="input">The input buffer</param>
        /// <param name="width">Width of the input buffer</param>
        /// <param name="height">Height of the input buffer</param>
        /// <param name="depth">Depth of the input buffer</param>
        /// <param name="channelCount">The Channel Count</param>
        /// <param name="kernelDb">The Kernel DB that will be used</param>
        /// <param name="ignoreDebug">a flag to ignore the brk statement</param>
        public void Reset(string file, MemoryBuffer input, int width, int height, int depth, int channelCount,
                          KernelDatabase kernelDb, bool ignoreDebug)
        {
            //Clear old stuff

            ReleaseResources();

            //Setting variables
            currentBuffer = new CLBufferInfo(input, false);
            currentBuffer.SetKey(INPUT_BUFFER_NAME);

            this.ignoreDebug  = ignoreDebug;
            this.width        = width;
            this.height       = height;
            this.depth        = depth;
            this.channelCount = channelCount;
            this.kernelDb     = kernelDb;
            activeChannels    = new byte[this.channelCount];
            currentArgStack   = new Stack <object>();
            for (int i = 0; i < this.channelCount; i++)
            {
                activeChannels[i] = 1;
            }

            activeChannelBuffer =
                CLAPI.CreateBuffer(instance, activeChannels, MemoryFlag.ReadOnly | MemoryFlag.CopyHostPointer);

            //Parsing File
            currentBuffer.SetKey(INPUT_BUFFER_NAME);
            data = LoadScriptData(instance, file, currentBuffer, width, height, depth, channelCount, kernelDb,
                                  flFunctions);

            Reset();
        }
示例#19
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);
        }
        protected override void Arrange(byte[] newOrder)
        {
            byte[] bytes =
                CLAPI.ReadBuffer <byte>(Root.Instance, Root.ActiveBuffer.Buffer, (int)Root.ActiveBuffer.Size);
            for (int i = 0; i < bytes.Length; i++)
            {
                if (i % Root.ActiveChannels.Length == 0)
                {
                    byte[] channelValues = new byte[Root.ActiveChannels.Length];
                    for (int j = 0; j < channelValues.Length; j++)
                    {
                        channelValues[j] = bytes[i + j];
                    }

                    channelValues = SwapChannel(channelValues, newOrder);

                    for (int j = 0; j < channelValues.Length; j++)
                    {
                        bytes[i + j] = channelValues[j];
                    }
                }
            }

            byte[] test = bytes.Reverse().Take(50).Reverse().ToArray();

            CLAPI.WriteToBuffer(Root.Instance, Root.ActiveBuffer.Buffer, bytes);
        }
示例#21
0
 public override FLBuffer GetBuffer()
 {
     return(new LazyLoadingFLBuffer(root =>
                                    new FLBuffer(
                                        CLAPI.CreateEmpty <byte>(root.Instance, root.InputSize, MemoryFlag.ReadWrite,
                                                                 "EmptySerializableBuffer." + Name),
                                        root.Dimensions.x, root.Dimensions.y)));
 }
示例#22
0
 public ParseTreeStageResult(CLAPI instance, Dictionary <string, FLFunction> definedScripts,
                             Dictionary <string, FLBuffer> definedBuffers, FLFunction[] flFunctions)
 {
     Instance       = instance;
     FlFunctions    = flFunctions;
     DefinedBuffers = definedBuffers;
     DefinedScripts = definedScripts;
 }
        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);
        }
示例#24
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));
        }
示例#25
0
 public FLRunner(CLAPI instance, string kernelPath) : this(
         FLInstructionSet.CreateWithBuiltInTypes(
             instance,
             kernelPath
             ),
         BufferCreator.CreateWithBuiltInTypes()
         )
 {
 }
示例#26
0
        public byte[] GetData()
        {
            if ((Buffer.Flags & MemoryFlag.WriteOnly) != 0)
            {
                throw new InvalidOperationException("Can not read a WriteOnly Buffer");
            }

            return(CLAPI.ReadBuffer <byte>(Root.Instance, Buffer, (int)Buffer.Size));
        }
示例#27
0
 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;
 }
示例#28
0
 public FLRunner(CLAPI instance, KernelDatabase database) : this(
         instance,
         FLInstructionSet.CreateWithBuiltInTypes(
             database
             ),
         BufferCreator.CreateWithBuiltInTypes()
         )
 {
 }
        public void CompileTest()
        {
            CLAPI instance = CLAPI.GetInstance();
            KernelDatabase db = new KernelDatabase(instance, "resources/kernel", DataVectorTypes.Uchar1);

            Assert.True(db.KernelNames.Count != 0);
            Assert.Pass("Kernels Loaded: " + db.KernelNames.Count);
            db.Dispose();
            instance.Dispose();
        }
示例#30
0
 public FLBuffer(
     CLAPI instance, byte[] data, int width, int height, int depth, object handleIdentifier,
     MemoryFlag flag = MemoryFlag.ReadWrite) : this(
         CLAPI.CreateBuffer(instance, data, flag, handleIdentifier),
         width,
         height,
         depth
         )
 {
 }