Example #1
0
 public OpenCLKernel(OpenCLProgram ocl, string kernelName)
 {
     // make a copy of the queue descriptor
     queue = ocl.queue;
     // load chosen kernel from program
     kernel = ocl.program.CreateKernel(kernelName);
 }
Example #2
0
        public OpenCLBuffer(OpenCLProgram ocl, uint length, int flags = ON_DEVICE + ON_HOST + READ_WRITE)
        {
            _queue = ocl.queue;
            int clflags = 0;

            if ((flags & READ_ONLY) > 0)
            {
                clflags += (int)ComputeMemoryFlags.ReadOnly;
            }
            if ((flags & WRITE_ONLY) > 0)
            {
                clflags += (int)ComputeMemoryFlags.WriteOnly;
            }
            if ((flags & READ_WRITE) > 0)
            {
                clflags += (int)ComputeMemoryFlags.ReadWrite;
            }
            if ((flags & ON_HOST) > 0)
            {
                _cpubuffer = new T[length];
                clflags   += (int)ComputeMemoryFlags.UseHostPointer;
            }
            if ((flags & ON_DEVICE) > 0)
            {
                _gpubuffer = new ComputeBuffer <T>(ocl.context, (ComputeMemoryFlags)clflags, _cpubuffer);
                if ((flags & ON_HOST) > 0)
                {
                    CopyToDevice();
                }
            }
        }
Example #3
0
        public OpenCLImage(OpenCLProgram ocl, int width, int height)
        {
            texData         = new T[width * height * 4];
            OpenGLTextureID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, OpenGLTextureID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            Type itemType = typeof(T);

            if (itemType == typeof(int))
            {
                // create an integer texture (RGBA8, 32bit per pixel)
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.Int, texData);
            }
            else if (itemType == typeof(float))
            {
                // create a floating point texture (RGBA32, 128bit per pixel)
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba32f, width, height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.Float, texData);
            }
            else
            {
                ocl.FatalError("Unsupported OpenCLImage format");
            }
            texBuffer = ComputeImage2D.CreateFromGLTexture2D(ocl.context, ComputeMemoryFlags.WriteOnly, (int)TextureTarget.Texture2D, 0, OpenGLTextureID);
        }