/// <summary> /// Enqueues a command to copy data from buffer to <see cref="ComputeImage"/>. /// </summary> /// <typeparam name="T"> The type of data in <paramref name="source"/>. </typeparam> /// <param name="source"> The buffer to copy from. </param> /// <param name="destination"> The image to copy to. </param> /// <param name="sourceOffset"> The <paramref name="source"/> element position where reading starts. </param> /// <param name="destinationOffset"> The <paramref name="destination"/> element position where writing starts. </param> /// <param name="region"> The region of elements to copy. </param> /// <param name="events"> A collection of events that need to complete before this particular command can be executed. If <paramref name="events"/> is not <c>null</c> or read-only a new <see cref="ComputeEvent"/> identifying this command is created and attached to the end of the collection. </param> public void Copy <T>(ComputeBufferBase <T> source, ComputeImage destination, long sourceOffset, SysIntX3 destinationOffset, SysIntX3 region, ICollection <ComputeEventBase> events) where T : struct { int sizeofT = HDSPUtils.SizeOf(typeof(T)); int eventWaitListSize; CLEventHandle[] eventHandles = ComputeTools.ExtractHandles(events, out eventWaitListSize); bool eventsWritable = (events != null && !events.IsReadOnly); CLEventHandle[] newEventHandle = (eventsWritable) ? new CLEventHandle[1] : null; ComputeErrorCode error = CL10.EnqueueCopyBufferToImage(Handle, source.Handle, destination.Handle, new IntPtr(sourceOffset * sizeofT), ref destinationOffset, ref region, eventWaitListSize, eventHandles, newEventHandle); ComputeException.ThrowOnError(error); if (eventsWritable) { events.Add(new ComputeEvent(newEventHandle[0], this)); } }
/// <summary> /// Enqueues a command to copy data from buffer to <see cref="OpenCLImage"/>. /// </summary> /// <typeparam name="T"> The type of data in <paramref name="source"/>. </typeparam> /// <param name="source"> The buffer to copy from. </param> /// <param name="destination"> The image to copy to. </param> /// <param name="sourceOffset"> The <paramref name="source"/> element position where reading starts. </param> /// <param name="destinationOffset"> The <paramref name="destination"/> element position where writing starts. </param> /// <param name="region"> The region of elements to copy. </param> /// <param name="events"> A collection of events that need to complete before this particular command can be executed. If <paramref name="events"/> is not <c>null</c> or read-only a new <see cref="OpenCLEvent"/> identifying this command is created and attached to the end of the collection. </param> public void Copy(OpenCLBufferBase source, OpenCLImage destination, long sourceOffset, SysIntX3 destinationOffset, SysIntX3 region, IReadOnlyList <OpenCLEventBase> events = null, IList <OpenCLEventBase> newEvents = null) { int sizeofT = Marshal.SizeOf(source.ElementType); int eventWaitListSize; CLEventHandle[] eventHandles = OpenCLTools.ExtractHandles(events, out eventWaitListSize); CLEventHandle[] newEventHandle = (newEvents != null) ? new CLEventHandle[1] : null; OpenCLErrorCode error = CL10.EnqueueCopyBufferToImage(Handle, source.Handle, destination.Handle, new IntPtr(sourceOffset * sizeofT), ref destinationOffset, ref region, eventWaitListSize, eventHandles, newEventHandle); OpenCLException.ThrowOnError(error); if (newEvents != null) { lock (newEvents) { newEvents.Add(new OpenCLEvent(newEventHandle[0], this)); } } }