Example #1
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();
        }
Example #2
0
        public void CreateEmptyCopy()
        {
            byte[]       data = new byte[BufferSize];
            MemoryBuffer buf  = CLAPI.CreateBuffer(instance, data, MemoryFlag.ReadWrite, "TestEmptyAlloc");

            buf.Dispose();
        }
Example #3
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);
        }
Example #4
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();
        }
Example #5
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
         )
 {
 }
Example #6
0
        public void OpenCL_CreateBuffer_Test()
        {
            //CLAPI.Reinitialize();
            byte[] b = new byte[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = (byte)i;
            }

            MemoryBuffer buffer =
                CLAPI.CreateBuffer(CLAPI.MainThread, b, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite);

            Assert.True(buffer != null);
            Assert.True(buffer.Size == 255);
        }
Example #7
0
        public void OpenCL_CreateBuffer_Test()
        {
            byte[] b = new byte[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = (byte)i;
            }

            MemoryBuffer buffer =
                CLAPI.CreateBuffer(CLAPI.MainThread, b, MemoryFlag.WriteOnly | MemoryFlag.AllocateHostPointer,
                                   "TestBuffer");

            Assert.True(buffer != null);
            Assert.True(buffer.Size == 255);
        }
Example #8
0
        public void CreateBuffer()
        {
            CLAPI.Reinitialize();
            DebugHelper.ThrowOnAllExceptions = true;
            byte[] b = new byte[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = (byte)i;
            }

            MemoryBuffer buffer = CLAPI.CreateBuffer(b, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite);

            Assert.True(buffer != null);
            Assert.True(buffer.Size == 255);
        }
Example #9
0
        public void OpenCL_ReadBuffer_Test()
        {
            float[] b = new float[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = i;
            }

            MemoryBuffer buffer =
                CLAPI.CreateBuffer(CLAPI.MainThread, b, MemoryFlag.ReadWrite, "TestBuffer");

            float[] c = CLAPI.ReadBuffer <float>(CLAPI.MainThread, buffer, b.Length);


            Assert.True(CheckValues(c, b));
        }
Example #10
0
        public void ReadBuffer()
        {
            CLAPI.Reinitialize();
            DebugHelper.ThrowOnAllExceptions = true;
            float[] b = new float[255];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = i;
            }

            MemoryBuffer buffer = CLAPI.CreateBuffer(b, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite);

            float[] c = CLAPI.ReadBuffer <float>(buffer, b.Length);


            Assert.True(CheckValues(c, b));
        }
        protected override void Arrange(byte[] newOrder)
        {
            MemoryBuffer newOrderBuffer =
                CLAPI.CreateBuffer(Root.Instance, newOrder, MemoryFlag.ReadOnly, "gpuarrange_neworder");

            //Copy Active Buffer
            MemoryBuffer source = CLAPI.Copy <byte>(Root.Instance, Root.ActiveBuffer.Buffer);


            ArrangeKernel.SetBuffer(0, Root.ActiveBuffer.Buffer);
            ArrangeKernel.SetBuffer(1, source);
            ArrangeKernel.SetArg(2, Root.ActiveChannels.Length);
            ArrangeKernel.SetBuffer(3, newOrderBuffer);
            CLAPI.Run(
                Root.Instance,
                ArrangeKernel,
                (int)Root.ActiveBuffer.Size /
                Root.ActiveChannels
                .Length
                );      //Only iterating through the length as if it only has one channel. The cl kernel implementation will deal with that
            newOrderBuffer.Dispose();
            source.Dispose();
        }
Example #12
0
 /// <summary>
 /// Reads Texture Data from CL into CPU Memory and passes it into the CL implementation
 /// </summary>
 /// <param name="instance">Clapi Instance for the current thread</param>
 /// <param name="tex">Input Texture</param>
 /// <returns>CL Buffer Object containing the image data</returns>
 public static MemoryBuffer TextureToMemoryBuffer(CLAPI instance, Texture tex, object handleIdentifier)
 {
     byte[] buffer = TextureToByteArray(tex);
     return(CLAPI.CreateBuffer(instance, buffer, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite,
                               handleIdentifier));
 }
Example #13
0
 public FLBuffer(CLAPI instance, byte[] data, int width, int height, object handleIdentifier) : this(
         CLAPI.CreateBuffer(instance, data, MemoryFlag.ReadWrite, handleIdentifier), width, height)
 {
 }
Example #14
0
 /// <summary>
 /// Reads Texture Data from CL into CPU Memory and passes it into the CL implementation
 /// </summary>
 /// <param name="tex">Input Texture</param>
 /// <returns>CL Buffer Object containing the image data</returns>
 public static MemoryBuffer TextureToMemoryBuffer(Texture tex)
 {
     byte[] buffer = TextureToByteArray(tex);
     return(CLAPI.CreateBuffer(buffer, MemoryFlag.CopyHostPointer | MemoryFlag.ReadWrite));
 }