Esempio n. 1
0
        /// <summary>
        /// Enqueues a command to fill an image object with a specified color.
        /// </summary>
        /// <typeparam name="DataType">The type of image data.</typeparam>
        /// <param name="image">The image to fill.</param>
        /// <param name="color">
        /// The fill color must be a ColorFloat struct if the image channel data type is not an unnormalized signed and unsigned integer type, a ColorInt struct if the
        /// image channel data type is an unnormalized signed integer type and a ColorUInt struct if the image channel data type is an unnormalized unsigned integer type.
        /// </param>
        /// <param name="region">
        /// Structure that defines the (Width, Height, Depth) in pixels of the 1D, 2D or 3D rectangle, the (Width, Height) in pixels of the 2D rectangle and the number of images of a 2D image array
        /// or the (Width) in pixels of the 1D rectangle and the number of images of a 1D image array. If image is a 2D image object, Depth must be 1. If image is a 1D image or
        /// 1D image buffer object, Height and Depth must be 1. If image is a 1D image array object, Depth must be 1. The values in region cannot be 0. Default = all image.
        /// </param>
        /// <param name="origin">
        /// Defines the (X, Y, Z) offset in pixels in the 1D, 2D or 3D image, the (X, Y) offset and the image index in the 2D image array or the (X) offset and the image index in the 1D image array.
        /// If image is a 2D image object, Z must be 0. If image is a 1D image or 1D image buffer object, Y and Z must be 0.  If image is a 1D image array object, Z must be 0.
        /// If image is a 1D image array object, Y describes the image index in the 1D image array. If image is a 2D image array object, Z describes the image index in the 2D image array. Default = (0,0,0).
        /// </param>
        /// <param name="eventsWaitList">A list of events that need to complete before this particular command can be executed.</param>
        /// <returns>An event object that identifies this particular fill command and can be used to query or queue a wait for this particular command to complete.</returns>
        public Event EnqueueFillImage <ColorType>(Image image, ColorType color, Size region = default, Offset origin = default, List <Event> eventsWaitList = null)
        {
            IntPtr[] eventHandles = EventListToHandles(eventsWaitList, out UInt32 eventsCount);

            if (region.IsNull)
            {
                region = image.Size;
                if (image.MemoryObjectType == MemoryObjectType.Image1DArray)
                {
                    region.Height = image.ArraySize;
                }
                else if (image.MemoryObjectType == MemoryObjectType.Image2DArray)
                {
                    region.Depth = image.ArraySize;
                }
            }
            UIntPtr[] regionArray = new UIntPtr[3] {
                new UIntPtr(region.Width), new UIntPtr(region.Height), new UIntPtr(region.Depth)
            };
            UIntPtr[] originArray = new UIntPtr[3] {
                new UIntPtr(origin.X), new UIntPtr(origin.Y), new UIntPtr(origin.Z)
            };

            GCHandle gcHandle = GCHandle.Alloc(color, GCHandleType.Pinned);

            error = clEnqueueFillImage(Handle, image.Handle, gcHandle.AddrOfPinnedObject(), originArray, regionArray, eventsCount, eventHandles, out IntPtr newEvent);
            gcHandle.Free();
            if (error != ErrorCode.Success)
            {
                return(null);
            }

            return(new Event(newEvent, this));
        }
Esempio n. 2
0
        /// <summary>
        /// Enqueues a command to copy a <see cref="Image"/> object to another one.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <param name="destination">The destination image.</param>
        /// <param name="region">
        /// Structure that defines the (Width, Height, Depth) in pixels of the 1D, 2D or 3D rectangle, the (Width, Height) in pixels of the 2D rectangle and the number of images of a 2D image array
        /// or the (Width) in pixels of the 1D rectangle and the number of images of a 1D image array. If image is a 2D image object, Depth must be 1. If image is a 1D image or
        /// 1D image buffer object, Height and Depth must be 1. If image is a 1D image array object, Depth must be 1. The values in region cannot be 0. Default = all image.
        /// </param>
        /// <param name="sourceOrigin">
        /// Defines the (X, Y, Z) offset in pixels in the 1D, 2D or 3D source image, the (X, Y) offset and the image index in the 2D image array or the (X) offset and the image index in the 1D image array.
        /// If image is a 2D image object, Z must be 0. If image is a 1D image or 1D image buffer object, Y and Z must be 0.  If image is a 1D image array object, Z must be 0.
        /// If image is a 1D image array object, Y describes the image index in the 1D image array. If image is a 2D image array object, Z describes the image index in the 2D image array. Default = (0,0,0).
        /// </param>
        /// <param name="destinationOrigin">
        /// Defines the (X, Y, Z) offset in pixels in the 1D, 2D or 3D destination image, the (X, Y) offset and the image index in the 2D image array or the (X) offset and the image index in the 1D image array.
        /// If image is a 2D image object, Z must be 0. If image is a 1D image or 1D image buffer object, Y and Z must be 0.  If image is a 1D image array object, Z must be 0.
        /// If image is a 1D image array object, Y describes the image index in the 1D image array. If image is a 2D image array object, Z describes the image index in the 2D image array. Default = (0,0,0).
        /// </param>
        /// <param name="eventsWaitList">A list of events that need to complete before this particular command can be executed.</param>
        /// <returns>An event object that identifies this particular copy command and can be used to query or queue a wait for this particular command to complete.</returns>
        public Event EnqueueCopyImage(Image source, Image destination, Size region = default, Offset sourceOrigin = default, Offset destinationOrigin = default, List <Event> eventsWaitList = null)
        {
            IntPtr[] eventHandles = EventListToHandles(eventsWaitList, out UInt32 eventsCount);

            if (region.IsNull)
            {
                region = source.Size;
                if (source.MemoryObjectType == MemoryObjectType.Image1DArray)
                {
                    region.Height = source.ArraySize;
                }
                else if (source.MemoryObjectType == MemoryObjectType.Image2DArray)
                {
                    region.Depth = source.ArraySize;
                }
            }
            UIntPtr[] regionArray = new UIntPtr[3] {
                new UIntPtr(region.Width), new UIntPtr(region.Height), new UIntPtr(region.Depth)
            };
            UIntPtr[] sourceOriginArray = new UIntPtr[3] {
                new UIntPtr(sourceOrigin.X), new UIntPtr(sourceOrigin.Y), new UIntPtr(sourceOrigin.Z)
            };
            UIntPtr[] destinationOriginArray = new UIntPtr[3] {
                new UIntPtr(destinationOrigin.X), new UIntPtr(destinationOrigin.Y), new UIntPtr(destinationOrigin.Z)
            };

            error = clEnqueueCopyImage(Handle, source.Handle, destination.Handle, sourceOriginArray, destinationOriginArray, regionArray, eventsCount, eventHandles, out IntPtr newEvent);
            if (error != ErrorCode.Success)
            {
                return(null);
            }

            return(new Event(newEvent, this));
        }
Esempio n. 3
0
        /// <summary>
        /// Enqueues a command to copy a <see cref="Buffer"/> object to an <see cref="Image"/> object.
        /// </summary>
        /// <param name="source">The source buffer.</param>
        /// <param name="destination">The destination image.</param>
        /// <param name="region">
        /// Structure that defines the (Width, Height, Depth) in pixels of the 1D, 2D or 3D rectangle, the (Width, Height) in pixels of the 2D rectangle and the number of images of a 2D image array
        /// or the (Width) in pixels of the 1D rectangle and the number of images of a 1D image array. If image is a 2D image object, Depth must be 1. If image is a 1D image or
        /// 1D image buffer object, Height and Depth must be 1. If image is a 1D image array object, Depth must be 1. The values in region cannot be 0. Default = all image.
        /// </param>
        /// <param name="sourceOffset">The offset in the buffer object to read from.</param>
        /// <param name="destinationOrigin">
        /// Defines the (X, Y, Z) offset in pixels in the 1D, 2D or 3D destination image, the (X, Y) offset and the image index in the 2D image array or the (X) offset and the image index in the 1D image array.
        /// If image is a 2D image object, Z must be 0. If image is a 1D image or 1D image buffer object, Y and Z must be 0.  If image is a 1D image array object, Z must be 0.
        /// If image is a 1D image array object, Y describes the image index in the 1D image array. If image is a 2D image array object, Z describes the image index in the 2D image array. Default = (0,0,0).
        /// </param>
        /// <param name="eventsWaitList">A list of events that need to complete before this particular command can be executed.</param>
        /// <returns>An event object that identifies this particular copy command and can be used to query or queue a wait for this particular command to complete.</returns>
        public Event EnqueueCopyBufferToImage(Buffer source, Image destination, Size region = default, UInt64 sourceOffset = 0, Offset destinationOrigin = default, List <Event> eventsWaitList = null)
        {
            IntPtr[] eventHandles = EventListToHandles(eventsWaitList, out UInt32 eventsCount);

            if (region.IsNull)
            {
                region = destination.Size;
            }
            UIntPtr[] regionArray = new UIntPtr[3] {
                new UIntPtr(region.Width), new UIntPtr(region.Height), new UIntPtr(region.Depth)
            };
            UIntPtr[] destinationOriginArray = new UIntPtr[3] {
                new UIntPtr(destinationOrigin.X), new UIntPtr(destinationOrigin.Y), new UIntPtr(destinationOrigin.Z)
            };

            error = clEnqueueCopyBufferToImage(Handle, source.Handle, destination.Handle, new UIntPtr(sourceOffset), destinationOriginArray, regionArray, eventsCount, eventHandles, out IntPtr newEvent);
            if (error != ErrorCode.Success)
            {
                return(null);
            }

            return(new Event(newEvent, this));
        }
Esempio n. 4
0
        /// <summary>
        /// Enqueue a command to write to an <see cref="Image"/> object from host memory.
        /// </summary>
        /// <typeparam name="DataType">The type of image data.</typeparam>
        /// <param name="image">The image to write.</param>
        /// <param name="source">The source image.</param>
        /// <param name="region">
        /// Structure that defines the (Width, Height, Depth) in pixels of the 1D, 2D or 3D rectangle, the (Width, Height) in pixels of the 2D rectangle and the number of images of a 2D image array
        /// or the (Width) in pixels of the 1D rectangle and the number of images of a 1D image array. If image is a 2D image object, Depth must be 1. If image is a 1D image or
        /// 1D image buffer object, Height and Depth must be 1. If image is a 1D image array object, Depth must be 1. The values in region cannot be 0. Default = all image.
        /// </param>
        /// <param name="origin">
        /// Defines the (X, Y, Z) offset in pixels in the 1D, 2D or 3D image, the (X, Y) offset and the image index in the 2D image array or the (X) offset and the image index in the 1D image array.
        /// If image is a 2D image object, Z must be 0. If image is a 1D image or 1D image buffer object, Y and Z must be 0.  If image is a 1D image array object, Z must be 0.
        /// If image is a 1D image array object, Y describes the image index in the 1D image array. If image is a 2D image array object, Z describes the image index in the 2D image array. Default = (0,0,0).
        /// </param>
        /// <param name="blocking">
        /// Indicate if the write operation is blocking or nonblocking. If true, this method copies the source data and enqueues the write operation in the command-queue.
        /// The source array can be reused by the application after the method returns. If false, this method will use source data to perform a nonblocking write. As the write is non-blocking,
        /// the method return immediately. The source array cannot be reused by the application immediately after the call returns. The method returns an event object which can be used
        /// to query the execution status of the write command.
        /// </param>
        /// <param name="eventsWaitList">A list of events that need to complete before this particular command can be executed.</param>
        /// <param name="rowPitch">
        /// Is the length of each row in bytes. This value must be greater than or equal to the element size in bytes * width. If row_pitch (or input_row_pitch) is set to 0,
        /// the appropriate row pitch is calculated based on the size of each element in bytes multiplied by width.
        /// </param>
        /// <param name="slicePitch">
        /// Is the size in bytes of the 2D slice of the 3D region of a 3D image or each image of a 1D or 2D image array being read or written respectively. This must be 0 if image is
        /// a 1D or 2D image.  This value must be greater than or equal to row_pitch * height.  If slice_pitch (or input_slice_pitch) is set to 0, the appropriate slice pitch is calculated
        /// based on the row_pitch * height.
        /// </param>
        /// <returns>An event object that identifies this particular write command and can be used to query or queue a wait for this particular command to complete.</returns>
        public Event EnqueueWriteImage <DataType>(Image image, DataType[] source, Size region = default, Offset origin = default, bool blocking = false, List <Event> eventsWaitList = null, UInt64 rowPitch = 0, UInt64 slicePitch = 0)
        {
            IntPtr[] eventHandles = EventListToHandles(eventsWaitList, out UInt32 eventsCount);

            if (region.IsNull)
            {
                region = image.Size;
                if (image.MemoryObjectType == MemoryObjectType.Image1DArray)
                {
                    region.Height = image.ArraySize;
                }
                else if (image.MemoryObjectType == MemoryObjectType.Image2DArray)
                {
                    region.Depth = image.ArraySize;
                }
            }
            UIntPtr[] regionArray = new UIntPtr[3] {
                new UIntPtr(region.Width), new UIntPtr(region.Height), new UIntPtr(region.Depth)
            };
            UIntPtr[] originArray = new UIntPtr[3] {
                new UIntPtr(origin.X), new UIntPtr(origin.Y), new UIntPtr(origin.Z)
            };

            GCHandle gcHandle = GCHandle.Alloc(source, GCHandleType.Pinned);

            error = clEnqueueWriteImage(Handle, image.Handle, blocking, originArray, regionArray, new UIntPtr(rowPitch), new UIntPtr(slicePitch), gcHandle.AddrOfPinnedObject(), eventsCount, eventHandles, out IntPtr newEvent);
            gcHandle.Free();
            if (error != ErrorCode.Success)
            {
                return(null);
            }

            return(new Event(newEvent, this));
        }