Пример #1
0
        private ComputeImage(CLMemoryHandle handle, ComputeContext context, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
Пример #2
0
 public extern static CLMemoryHandle CreateFromGLTexture3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     Int32 target,
     Int32 miplevel,
     Int32 texture,
     out ComputeErrorCode errcode_ret);
Пример #3
0
 public extern static ComputeErrorCode GetSupportedImageFormats(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ComputeMemoryType image_type,
     Int32 num_entries,
     [Out, MarshalAs(UnmanagedType.LPArray)] ComputeImageFormat[] image_formats,
     out Int32 num_image_formats);
Пример #4
0
        private ComputeImage3D(IntPtr handle, ComputeContext context, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
Пример #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Creates a new <see cref="ComputeImage3D"/>. </summary>
        ///
        /// <param name="handle">   The handle. </param>
        /// <param name="context">  The context. </param>
        /// <param name="flags">    The flags. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private ComputeImage3D(CLMemoryHandle handle, ComputeContext context, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
Пример #6
0
        /// <summary>
        /// Creates a new <see cref="ComputeImage2D"/> from a <c>Bitmap</c>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage2D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage2D"/>. </param>
        /// <param name="bitmap"> The bitmap to use. </param>
        /// <remarks> Note that only bitmaps with <c>Alpha</c>, <c>Format16bppRgb555</c>, <c>Format16bppRgb565</c> or <c>Format32bppArgb</c> pixel formats are currently supported. </remarks>
        public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, Bitmap bitmap)
            : base(context, flags)
        {
            unsafe
            {
                ComputeImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
                BitmapData bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);

                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateImage2D(
                    context.Handle,
                    flags,
                    &format,
                    new IntPtr(bitmap.Width),
                    new IntPtr(bitmap.Height),
                    new IntPtr(bitmapData.Stride),
                    bitmapData.Scan0,
                    &error);
                ComputeException.ThrowOnError(error);

                bitmap.UnlockBits(bitmapData);

                Init();
            }
        }
Пример #7
0
        internal ComputeSubBuffer(ComputeContext context, CLMemoryHandle handle, ComputeMemoryFlags flags)
            : base(context, flags)
        {
            Handle = handle;

            Init();
        }
Пример #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 /// <param name="flags"></param>
 /// <param name="packetSize"></param>
 /// <param name="maxPackets"></param>
 public ComputePipe(ComputeContext context, ComputeMemoryFlags flags, int packetSize, int maxPackets)
     : this(context, flags)
 {
     ComputeErrorCode error;
     Handle = CLInterface.CL20.CreatePipe(context.Handle, flags, packetSize, maxPackets, null, out error);
     ComputeException.ThrowOnError(error);
     Init();
 }
Пример #9
0
        public static ComputeImage3D CreateFromGLTexture3D(ComputeContext context, ComputeMemoryFlags flags, int textureTarget, int mipLevel, int textureId)
        {
            var image = CL12.CreateFromGLTexture3D(context.Handle, flags, textureTarget, mipLevel, textureId, out var error);

            ComputeException.ThrowOnError(error);

            return(new ComputeImage3D(image, context, flags));
        }
Пример #10
0
        public ComputeImage3D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, int depth, long rowPitch, long slicePitch, IntPtr data)
            : base(context, flags)
        {
            Handle = CL12.CreateImage3D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(depth), new IntPtr(rowPitch), new IntPtr(slicePitch), data, out var error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Пример #11
0
        public void CreateFloatBuffer(string key, float[] hostBuffer, ComputeMemoryFlags flags)
        {
            _floatBuffers.Add(key, hostBuffer);

            if (HardwareAccelerationEnabled)
            {
                _floatComputeBuffers.Add(key, new ComputeBuffer <float>(_context, flags, hostBuffer));
            }
        }
        /// <summary>
        /// Creates a new <see cref="ComputeImage3D"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage3D"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage3D"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage3D"/>. </param>
        /// <param name="width"> The width of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="height"> The height of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="depth"> The depth of the <see cref="ComputeImage3D"/> in pixels. </param>
        /// <param name="rowPitch"> The size in bytes of each row of elements of the <see cref="ComputeImage3D"/>. If <paramref name="rowPitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.Width"/> and <see cref="ComputeImage.ElementSize"/>. </param>
        /// <param name="slicePitch"> The size in bytes of each 2D slice in the <see cref="ComputeImage3D"/>. If <paramref name="slicePitch"/> is zero, OpenCL will compute the proper value based on <see cref="ComputeImage.RowPitch"/> and <see cref="ComputeImage.Height"/>. </param>
        /// <param name="data"> The data to initialize the <see cref="ComputeImage3D"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage3D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, int depth, long rowPitch, long slicePitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CL10.CreateImage3D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(depth), new IntPtr(rowPitch), new IntPtr(slicePitch), data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Пример #13
0
        /// <summary>
        /// Creates a new buffer from a specified buffer.
        /// </summary>
        /// <param name="buffer"> The buffer to create the buffer from. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the buffer. </param>
        /// <param name="offset"> The index of the element of <paramref name="buffer"/>, where the buffer starts. </param>
        /// <param name="count"> The number of elements of <paramref name="buffer"/> to include in the buffer. </param>
        public ComputeSubBuffer(ComputeBuffer <T> buffer, ComputeMemoryFlags flags, long offset, long count)
            : base(buffer.Context, flags)
        {
            SysIntX2 region = new SysIntX2(offset * Marshal.SizeOf(typeof(T)), count * Marshal.SizeOf(typeof(T)));

            CL11.CreateSubBuffer(Handle, flags, ComputeBufferCreateType.Region, ref region, out ComputeErrorCode error);
            ComputeException.ThrowOnError(error);
            Init();
        }
Пример #14
0
 public extern static CLMemoryHandle CreateImage2D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_row_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret);
Пример #15
0
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="count"> The number of elements of the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="dataPtr"> A pointer to the data for the <see cref="ComputeBuffer{T}"/>. </param>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CL10.CreateBuffer(context.Handle, flags, new IntPtr(Marshal.SizeOf(typeof(T)) * count), dataPtr, out error);
            ComputeException.ThrowOnError(error);
            Init();
        }
Пример #16
0
        public void CreateFloatBuffer(string key, float[] hostBuffer, ComputeMemoryFlags flags)
        {
            _floatBuffers.Add(key, hostBuffer);

            if (HardwareAccelerationEnabled)
            {
                _floatComputeBuffers.Add(key, new ComputeBuffer<float>(_context, flags, hostBuffer));
            }
        }
Пример #17
0
        /// <summary>
        /// Creates a new <see cref="ComputeImage"/>.
        /// </summary>
        /// <param name="context"> A valid <see cref="ComputeContext"/> in which the <see cref="ComputeImage"/> is created. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeImage"/>. </param>
        /// <param name="format"> A structure that describes the format properties of the <see cref="ComputeImage"/>. </param>
        /// <param name="imageDescription"> A structure that describes the <see cref="ComputeImage"/>. </param>
        /// <param name="data"> The data to initialize the <see cref="ComputeImage"/>. Can be <c>IntPtr.Zero</c>. </param>
        public ComputeImage(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, ComputeImageDescription imageDescription, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            Handle = CLInterface.CL12.CreateImage(context.Handle, flags, ref format, ref imageDescription, data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Пример #18
0
        ///<summary>
        ///Creates a new <see cref = "ComputeImage 2 D"/> from an OpenGL 2D texture object.
        ///</summary>
        ///<param name = "context"> A <see cref = "ComputeContext"/> with enabled CL / GL sharing. </param>
        ///Only <c> ComputeMemoryFlags.ReadOnly </c>, <c> ComputeMemoryFlags.WriteOnly </c>, where <param name = "flags"> A bit-field that is used to specify usage information about the <   / c> and <c> ComputeMemoryFlags.ReadWrite </c> are allowed.. </param>
        ///<Param name = "textureTarget"> One of the following values:.. GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or GL_TEXTURE_RECTANGLE Using GL_TEXTURE_RECTANGLE for texture_target requires OpenGL 3.1 Alternatively, GL_TEXTURE_RECTANGLE_ARB may be specified if the OpenGL extension GL_ARB_texture_rectangle   is supported. </param>
        ///<param name = "mipLevel"> The mipmap level of the OpenGL 2D texture object to be used. </param>
        ///<param name = "textureId"> The OpenGL 2D texture object id to use. </param>
        ///<returns> The created <see cref = "ComputeImage2D"/>. </returns>
        public static ComputeImage2D CreateFromGLTexture2D(ComputeContext context, ComputeMemoryFlags flags, int textureTarget, int mipLevel, int textureId)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            CLMemoryHandle   image = CL12.CreateFromGLTexture2D(context.Handle, flags, textureTarget, mipLevel, textureId, out error);

            ComputeException.ThrowOnError(error);

            return(new ComputeImage2D(image, context, flags));
        }
Пример #19
0
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="count"> The number of elements of the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="dataPtr"> A pointer to the data for the <see cref="ComputeBuffer{T}"/>. </param>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr)
            : base(context, flags)
        {
            var size = ComputeTools.SizeOf <T>() * count;

            Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr, out var error);
            ComputeException.ThrowOnError(error);
            Init(size, count);
        }
Пример #20
0
        /*
         * ///<summary>
         * /// Creates a new <see cref="ComputeImage2D"/> from a <c>Bitmap</c>.
         * ///</summary>
         * ///<para name = "context"> A valid <see cref = "ComputeContext"/> in which the <see cref = "ComputeImage 2 D"/> is created. </param>
         * ///<para name = "flags"> A bit-field that is used to specify allocation and usage information about the <see cref = "ComputeImage 2 D"/>. </param>
         * /// <param name="bitmap"> The bitmap to use. </param>
         * /// <remarks> Note that only bitmaps with <c>Format32bppArgb</c> pixel format are currently supported. </remarks>
         * public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, Bitmap bitmap)
         *  :base(context, flags)
         * {
         *  unsafe
         *  {
         *      if(bitmap.PixelFormat != PixelFormat.Format32bppArgb)
         *          throw new ArgumentException("Pixel format not supported.");
         *
         *      //ComputeImageFormat format = Tools.ConvertImageFormat(bitmap.PixelFormat);
         *      ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Bgra, ComputeImageChannelType.UnsignedInt8);
         *      BitmapData bitmapData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);
         *
         *      try
         *      {
         *          ComputeErrorCode error = ComputeErrorCode.Success;
         *          Handle = CL12.CreateImage2D(
         *              context.Handle,
         *              flags,
         *              &format,
         *              new IntPtr(bitmap.Width),
         *              new IntPtr(bitmap.Height),
         *              new IntPtr(bitmapData.Stride),
         *              bitmapData.Scan0,
         *              &error);
         *          ComputeException.ThrowOnError(error);
         *      }
         *      finally
         *      {
         *          bitmap.UnlockBits(bitmapData);
         *      }
         *
         *      Init();
         *  }
         * }*/

        ///<summary>
        ///Creates a new <see cref = "ComputeImage 2 D"/>.
        ///</summary>
        ///<para name = "context"> A valid <see cref = "ComputeContext"/> in which the <see cref = "ComputeImage 2 D"/> is created. </param>
        ///<para name = "flags"> A bit-field that is used to specify allocation and usage information about the <see cref = "ComputeImage 2 D"/>. </param>
        ///<param name = "format"> A structure that describes the format properties of the <see cref = "ComputeImage 2 D"/>. </param>
        ///<param name = "width"> The width of the <see cref = "ComputeImage 2 D"/> in pixels. </param>
        ///<param name = "height"> The height of the <see cref = "ComputeImage 2 D"/> in pixels. </param>
        ///<para name = "rowPitch">> ​​The size in bytes of each row of elements of the <see cref = "ComputeImage2D"/>. If <paramref name = "rowPitch"/> is zero, OpenCL will compute the proper value based on   <see cref = "ComputeImage.Width"/> and <see cref = "ComputeImage.ElementSize"/>. </param>
        ///<param name = "data"> The data to initialize the <see cref = "ComputeImage 2 D"/>. Can be <c> IntPtr.Zero </c>. </param>
        public ComputeImage2D(ComputeContext context, ComputeMemoryFlags flags, ComputeImageFormat format, int width, int height, long rowPitch, IntPtr data)
            : base(context, flags)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;

            Handle = CL12.CreateImage2D(context.Handle, flags, ref format, new IntPtr(width), new IntPtr(height), new IntPtr(rowPitch), data, out error);
            ComputeException.ThrowOnError(error);

            Init();
        }
 public ManagedComputeImage2D(
     ComputeContext context,
     ComputeMemoryFlags flags,
     ComputeImageFormat format,
     int width,
     int height,
     long rowPitch,
     IntPtr data)
     : base(context, flags, format, width, height, rowPitch, data)
 {
 }
Пример #22
0
 public static new CLMemoryHandle CreateFromGLTexture3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     Int32 target,
     Int32 miplevel,
     Int32 texture,
     out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! clCreateFromGLTexture3D has been deprecated in OpenCL 1.2.");
     return CL11.CreateFromGLTexture3D(context, flags, target, miplevel, texture, out errcode_ret);
 }
Пример #23
0
 public new static CLMemoryHandle CreateFromGLTexture3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     Int32 target,
     Int32 miplevel,
     Int32 texture,
     out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! clCreateFromGLTexture3D has been deprecated in OpenCL 1.2.");
     return(CL11.CreateFromGLTexture3D(context, flags, target, miplevel, texture, out errcode_ret));
 }
Пример #24
0
        /// <summary>
        /// Creates a new <see cref="ComputeSubBuffer{T}"/> from a specified <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="buffer"> The buffer to create the <see cref="ComputeSubBuffer{T}"/> from. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="offset"> The index of the element of <paramref name="buffer"/>, where the <see cref="ComputeSubBuffer{T}"/> starts. </param>
        /// <param name="count"> The number of elements of <paramref name="buffer"/> to include in the <see cref="ComputeSubBuffer{T}"/>. </param>
        public ComputeSubBuffer(ComputeBuffer <T> buffer, ComputeMemoryFlags flags, long offset, long count)
            : base(buffer.Context, flags)
        {
            var sizeofT = ComputeTools.SizeOf <T>();

            SysIntX2 region = new SysIntX2(offset * sizeofT, count * sizeofT);

            Handle = CL11.CreateSubBuffer(buffer.Handle, flags, ComputeBufferCreateType.Region, ref region, out var error);
            ComputeException.ThrowOnError(error);

            Init();
        }
Пример #25
0
 public static new CLMemoryHandle CreateImage2D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_row_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! clCreateImage2D has been deprecated in OpenCL 1.2.");
     return CL11.CreateImage2D(context, flags, ref image_format, image_width, image_height, image_row_pitch, host_ptr, out errcode_ret);
 }
Пример #26
0
 public new static CLMemoryHandle CreateImage2D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_row_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret)
 {
     Trace.WriteLine("WARNING! clCreateImage2D has been deprecated in OpenCL 1.2.");
     return(CL11.CreateImage2D(context, flags, ref image_format, image_width, image_height, image_row_pitch, host_ptr, out errcode_ret));
 }
Пример #27
0
        /// <summary>
        /// Creates a new buffer from the given 2-dimensional array.
        /// </summary>
        /// <param name="context"> A context used to create the buffer. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the buffer.  Any xxxHostPointer flags are ignored. </param>
        /// <param name="data"> The 2-dimensional data for the buffer. </param>
        public ComputeBuffer(IComputeContext context, ComputeMemoryFlags flags, T[,] data)
            : base(context, flags)
        {
            GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                InternalCreateBuffer(context, (flags | ComputeMemoryFlags.CopyHostPointer) & ~(ComputeMemoryFlags.UseHostPointer | ComputeMemoryFlags.AllocateHostPointer), data.Length, dataPtr.AddrOfPinnedObject());
            }
            finally
            {
                dataPtr.Free();
            }
        }
Пример #28
0
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data)
        {
            GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                handle = CL10.CreateBuffer(context.handle, flags, new IntPtr(Unsafe.SizeOf <T>() * data.Length), dataPtr.AddrOfPinnedObject(), out _);
            }
            finally
            {
                dataPtr.Free();
            }

            Init();
        }
Пример #29
0
 public new static CLMemoryHandle CreateImage3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_depth,
     IntPtr image_row_pitch,
     IntPtr image_slice_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret)
 {
     RILogManager.Default?.SendTrace("WARNING! clCreateImage3D has been deprecated in OpenCL 1.2.");
     return(CL11.CreateImage3D(context, flags, ref image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, out errcode_ret));
 }
Пример #30
0
        public XArrayMemory(ComputeContext context, ComputeMemoryFlags flags, XArray obj) : base(context, flags)
        {
            var hostPtr = IntPtr.Zero;

            if ((flags & (ComputeMemoryFlags.CopyHostPointer | ComputeMemoryFlags.UseHostPointer)) != ComputeMemoryFlags.None)
            {
                hostPtr = obj.NativePtr;
            }

            ComputeErrorCode error = ComputeErrorCode.Success;
            var handle             = CL12.CreateBuffer(context.Handle, flags, new IntPtr(obj.Count), hostPtr, out error);

            this.Size   = obj.Count;
            this.Handle = handle;
        }
Пример #31
0
        public GenericArrayMemory(ComputeContext context, ComputeMemoryFlags flags, object obj) : base(context, flags)
        {
            Array array = (Array)obj;

            if (array.Length == 0)
            {
                return;
            }

            int size               = Marshal.SizeOf(array.GetValue(0).GetType()) * array.Length;
            var datagch            = GCHandle.Alloc(obj, GCHandleType.Pinned);
            ComputeErrorCode error = ComputeErrorCode.Success;
            var handle             = CL12.CreateBuffer(context.Handle, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.CopyHostPointer, new IntPtr(size), datagch.AddrOfPinnedObject(), out error);

            this.Size   = size;
            this.Handle = handle;
        }
Пример #32
0
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="data"> The data for the <see cref="ComputeBuffer{T}"/>. </param>
        /// <remarks> Note, that <paramref name="data"/> cannot be an "immediate" parameter, i.e.: <c>new T[100]</c>, because it could be quickly collected by the GC causing Cloo to send and invalid reference to OpenCL. </remarks>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data)
            : base(context, flags)
        {
            GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                ComputeErrorCode error = ComputeErrorCode.Success;
                Handle = CL10.CreateBuffer(context.Handle, flags, new IntPtr(Marshal.SizeOf(typeof(T)) * data.Length), dataPtr.AddrOfPinnedObject(), out error);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                dataPtr.Free();
            }
            Init();
        }
Пример #33
0
        public ComputeBuffer <float> ConvertBuffer(ComputeMemoryFlags flag, float[] data)
        {
            switch (flag)
            {
            case ComputeMemoryFlags.ReadOnly:
                flag = ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer;
                break;

            case ComputeMemoryFlags.WriteOnly:
                flag = ComputeMemoryFlags.WriteOnly | ComputeMemoryFlags.CopyHostPointer;
                break;

            default:
                break;
            }
            return(new ComputeBuffer <float>(Option.Context, flag, data));
        }
Пример #34
0
        /// <summary>
        /// Creates a new <see cref="ComputeBuffer{T}"/>.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> used to create the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="flags"> A bit-field that is used to specify allocation and usage information about the <see cref="ComputeBuffer{T}"/>. </param>
        /// <param name="data"> The data for the <see cref="ComputeBuffer{T}"/>. </param>
        /// <remarks> Note, that <paramref name="data"/> cannot be an "immediate" parameter, i.e.: <c>new T[100]</c>, because it could be quickly collected by the GC causing Amplifier.OpenCL.Cloo to send and invalid reference to OpenCL. </remarks>
        public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, T[] data)
            : base(context, flags)
        {
            var size = ComputeTools.SizeOf <T>() * data.Length;

            GCHandle dataPtr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                Handle = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), dataPtr.AddrOfPinnedObject(), out var error);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                dataPtr.Free();
            }

            Init(size, data.Length);
        }
Пример #35
0
        public GenericArrayMemory(ComputeContext context, ComputeMemoryFlags flags, Array array) : base(context, flags)
        {
            if (array.Length == 0)
            {
                return;
            }

            int size    = Marshal.SizeOf(array.GetValue(0).GetType()) * array.Length;
            var hostPtr = IntPtr.Zero;

            if ((flags & (ComputeMemoryFlags.CopyHostPointer | ComputeMemoryFlags.UseHostPointer)) != ComputeMemoryFlags.None)
            {
                var datagch = GCHandle.Alloc(array, GCHandleType.Pinned);
                hostPtr = datagch.AddrOfPinnedObject();
            }

            ComputeErrorCode error = ComputeErrorCode.Success;
            var handle             = CL12.CreateBuffer(context.Handle, flags, new IntPtr(size), hostPtr, out error);

            this.Size   = size;
            this.Handle = handle;
        }
Пример #36
0
        private static ComputeMemory[] WrapDeviceVariables(Object[] kernelParams, ComputeContext context)
        {
            ComputeMemoryFlags flags = ComputeMemoryFlags.ReadOnly | ComputeMemoryFlags.CopyHostPointer;

            return(kernelParams.Select <Object, ComputeMemory>(obj =>
            {
                if (EnclosesInType <int>(obj))
                {
                    return new ComputeBuffer <int>(context, flags, EncloseInType <int>(obj));
                }
                else if (EnclosesInType <float>(obj))
                {
                    return new ComputeBuffer <float>(context, flags, EncloseInType <float>(obj));
                }
                else if (EnclosesInType <char>(obj))
                {
                    return new ComputeBuffer <char>(context, flags, EncloseInType <char>(obj));
                }
                else
                {
                    throw new NotImplementedException("Type " + obj.GetType() + " is unhandled.");
                }
            }).ToArray());
        }
Пример #37
0
 public CLMemoryHandle CreateFromGLBuffer(CLContextHandle context, ComputeMemoryFlags flags, Int32 bufobj, out ComputeErrorCode errcode_ret)
 {
     return StaticCreateFromGLBuffer(context, flags, bufobj, out errcode_ret);
 }
Пример #38
0
 public CLMemoryHandle CreateFromGLTexture(CLContextHandle context, ComputeMemoryFlags flags, int texture_target, int miplevel, int texture, out ComputeErrorCode errcode_ret)
 {
     throw new NotImplementedException();
 }
Пример #39
0
 public static extern CLMemoryHandle CreateBuffer(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     IntPtr size,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret);
Пример #40
0
 public static extern ComputeErrorCode GetSupportedImageFormats(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ComputeMemoryType image_type,
     Int32 num_entries,
     [Out, MarshalAs(UnmanagedType.LPArray)] ComputeImageFormat[] image_formats,
     out Int32 num_image_formats);
Пример #41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 /// <param name="flags"></param>
 protected ComputeImage(ComputeContext context, ComputeMemoryFlags flags)
     : base(context, flags)
 {
 }
Пример #42
0
 /// <summary>
 /// Creates a new <c>ComputeImage3D</c> from an OpenGL 3D texture object.
 /// </summary>
 /// <param name="context"> A <c>ComputeContext</c> with enabled CL/GL sharing. </param>
 /// <param name="flags"> A bit-field that is used to specify usage information about the <c>ComputeImage3D</c>. Only <c>ComputeMemoryFlags.ReadOnly</c>, <c>ComputeMemoryFlags.WriteOnly</c> and <c>ComputeMemoryFlags.ReadWrite</c> are allowed. </param>
 /// <param name="textureTarget"> The image type of texture. Must be GL_TEXTURE_3D. </param>
 /// <param name="mipLevel"> The mipmap level of the OpenGL 2D texture object to be used. </param>
 /// <param name="textureId"> The OpenGL 2D texture object id to use. </param>
 /// <returns> The created <c>ComputeImage2D</c>. </returns>
 public static ComputeImage3D CreateFromGLTexture3D(ComputeContext context, ComputeMemoryFlags flags, int textureTarget, int mipLevel, int textureId)
 {
     IntPtr image = IntPtr.Zero;
     unsafe
     {
         ComputeErrorCode error = ComputeErrorCode.Success;
         image = CL10.CreateFromGLTexture3D(
             context.Handle,
             flags,
             textureTarget,
             mipLevel,
             textureId,
             &error);
         ComputeException.ThrowOnError(error);
     }
     return new ComputeImage3D(image, context, flags);
 }
Пример #43
0
 public static unsafe extern IntPtr CreateSubBuffer(
     IntPtr buffer,
     ComputeMemoryFlags flags,
     ComputeBufferCreateType buffer_create_type,
     /* const void * */ IntPtr buffer_create_info,
     ComputeErrorCode* errcode_ret);
Пример #44
0
 public CLMemoryHandle CreatePipe(CLContextHandle context, ComputeMemoryFlags flags, int pipe_packet_size, int pipe_max_packets, [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, out ComputeErrorCode errcode_ret)
 {
     throw new NotImplementedException();
 }
Пример #45
0
 public CLMemoryHandle CreateImage2D(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, IntPtr image_width, IntPtr image_height, IntPtr image_row_pitch, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     return StaticCreateImage2D(context, flags,ref image_format, image_width, image_height, image_row_pitch, host_ptr, out errcode_ret);
 }
Пример #46
0
 public CLMemoryHandle CreateFromGLTexture2D(CLContextHandle context, ComputeMemoryFlags flags, Int32 target, Int32 miplevel, Int32 texture, out ComputeErrorCode errcode_ret)
 {
     return StaticCreateFromGLTexture2D(context, flags, target, miplevel, texture, out errcode_ret);
 }
Пример #47
0
 public CLMemoryHandle CreateImage(CLContextHandle context, ComputeMemoryFlags flags, ref ComputeImageFormat image_format, ref ComputeImageDescription image_desc, IntPtr host_ptr, out ComputeErrorCode errcode_ret)
 {
     throw new NotImplementedException();
 }
Пример #48
0
        /// <summary>
        /// Creates a new <see cref="ComputeImage2D"/> from an OpenGL 2D texture object.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> with enabled CL/GL sharing. </param>
        /// <param name="flags"> A bit-field that is used to specify usage information about the <see cref="ComputeImage2D"/>. Only <c>ComputeMemoryFlags.ReadOnly</c>, <c>ComputeMemoryFlags.WriteOnly</c> and <c>ComputeMemoryFlags.ReadWrite</c> are allowed. </param>
        /// <param name="textureTarget"> One of the following values: GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, or GL_TEXTURE_RECTANGLE. Using GL_TEXTURE_RECTANGLE for texture_target requires OpenGL 3.1. Alternatively, GL_TEXTURE_RECTANGLE_ARB may be specified if the OpenGL extension GL_ARB_texture_rectangle is supported. </param>
        /// <param name="mipLevel"> The mipmap level of the OpenGL 2D texture object to be used. </param>
        /// <param name="textureId"> The OpenGL 2D texture object id to use. </param>
        /// <returns> The created <see cref="ComputeImage2D"/>. </returns>
        public static ComputeImage2D CreateFromGLTexture2D(ComputeContext context, ComputeMemoryFlags flags, int textureTarget, int mipLevel, int textureId)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            CLMemoryHandle image = CL12.CreateFromGLTexture2D(context.Handle, flags, textureTarget, mipLevel, textureId, out error);
            ComputeException.ThrowOnError(error);

            return new ComputeImage2D(image, context, flags);
        }
Пример #49
0
        /// <summary>
        /// Creates a new <see cref="ComputeImage2D"/> from an OpenGL renderbuffer object.
        /// </summary>
        /// <param name="context"> A <see cref="ComputeContext"/> with enabled CL/GL sharing. </param>
        /// <param name="flags"> A bit-field that is used to specify usage information about the <see cref="ComputeImage2D"/>. Only <c>ComputeMemoryFlags.ReadOnly</c>, <c>ComputeMemoryFlags.WriteOnly</c> and <c>ComputeMemoryFlags.ReadWrite</c> are allowed. </param>
        /// <param name="renderbufferId"> The OpenGL renderbuffer object id to use. </param>
        /// <returns> The created <see cref="ComputeImage2D"/>. </returns>
        public static ComputeImage2D CreateFromGLRenderbuffer(ComputeContext context, ComputeMemoryFlags flags, int renderbufferId)
        {
            ComputeErrorCode error = ComputeErrorCode.Success;
            CLMemoryHandle image = CL12.CreateFromGLRenderbuffer(context.Handle, flags, renderbufferId, out error);
            ComputeException.ThrowOnError(error);

            return new ComputeImage2D(image, context, flags);
        }
Пример #50
0
        protected static ICollection<ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            unsafe
            {
                int formatCountRet = 0;
                ComputeErrorCode error = CL10.GetSupportedImageFormats(context.Handle, flags, type, 0, null, &formatCountRet);
                ComputeException.ThrowOnError(error);

                ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
                fixed (ComputeImageFormat* formatsPtr = formats)
                {
                    error = CL10.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formatsPtr, null);
                    ComputeException.ThrowOnError(error);
                }

                return new Collection<ComputeImageFormat>(formats);
            }
        }
Пример #51
0
 public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count, IntPtr dataPtr)
 {
     handle = CL10.CreateBuffer(context.handle, flags, new IntPtr(Unsafe.SizeOf <T>() * count), dataPtr, out _);
     Init();
 }
Пример #52
0
 public CLMemoryHandle CreateSubBuffer(CLMemoryHandle buffer, ComputeMemoryFlags flags, ComputeBufferCreateType buffer_create_type, ref SysIntX2 buffer_create_info, out ComputeErrorCode errcode_ret)
 {
     throw new NotImplementedException();
 }
Пример #53
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="flags"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected static ICollection <ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            int formatCountRet     = 0;
            ComputeErrorCode error = CL12.GetSupportedImageFormats(context.Handle, flags, type, 0, null, out formatCountRet);

            ComputeException.ThrowOnError(error);

            ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
            error = CL12.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formats, out formatCountRet);
            ComputeException.ThrowOnError(error);

            return(new Collection <ComputeImageFormat>(formats));
        }
Пример #54
0
 public static extern CLMemoryHandle CreateImage3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     ref ComputeImageFormat image_format,
     IntPtr image_width,
     IntPtr image_height,
     IntPtr image_depth,
     IntPtr image_row_pitch,
     IntPtr image_slice_pitch,
     IntPtr host_ptr,
     out ComputeErrorCode errcode_ret);
Пример #55
0
 /// <summary>
 /// Gets a collection of supported <c>ComputeImage3D</c> <c>ComputeImageFormat</c>s in a <c>ComputeContext</c>.
 /// </summary>
 /// <param name="context"> The <c>ComputeContext</c> for which the collection of <c>ComputeImageFormat</c>s is queried. </param>
 /// <param name="flags"> The <c>ComputeMemoryFlags</c> for which the collection of <c>ComputeImageFormat</c>s is queried. </param>
 /// <returns> The collection of the required <c>ComputeImageFormat</c>s. </returns>
 public static ICollection<ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags)
 {
     return GetSupportedFormats(context, flags, ComputeMemoryType.Image3D);
 }
Пример #56
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="flags"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected static ICollection<ComputeImageFormat> GetSupportedFormats(ComputeContext context, ComputeMemoryFlags flags, ComputeMemoryType type)
        {
            int formatCountRet = 0;
            ComputeErrorCode error = CL12.GetSupportedImageFormats(context.Handle, flags, type, 0, null, out formatCountRet);
            ComputeException.ThrowOnError(error);

            ComputeImageFormat[] formats = new ComputeImageFormat[formatCountRet];
            error = CL12.GetSupportedImageFormats(context.Handle, flags, type, formatCountRet, formats, out formatCountRet);
            ComputeException.ThrowOnError(error);

            return new Collection<ComputeImageFormat>(formats);
        }
Пример #57
0
 public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count) : this(context, flags, count, IntPtr.Zero)
 {
 }
Пример #58
0
 public static extern CLMemoryHandle CreateFromGLRenderbuffer(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     Int32 renderbuffer,
     out ComputeErrorCode errcode_ret);
Пример #59
0
 public static extern CLMemoryHandle CreateFromGLTexture3D(
     CLContextHandle context,
     ComputeMemoryFlags flags,
     Int32 target,
     Int32 miplevel,
     Int32 texture,
     out ComputeErrorCode errcode_ret);
Пример #60
0
 public static extern CLMemoryHandle StaticCreateFromGLBuffer(CLContextHandle context, ComputeMemoryFlags flags, Int32 bufobj, out ComputeErrorCode errcode_ret);