Пример #1
0
        ///<summary>
        ///Enqueues a command to map a part of a buffer into the host address space.
        ///</summary>
        ///<param name = "buffer"> The buffer to map. </param>
        ///<param name = "blocking"> The mode of operation of this call. </param>
        ///<param name = "flags"> A list of properties for the mapping mode. </param>
        ///<param name = "offset"> The <paramref name = "buffer"/> element position where mapping starts.. </param>
        ///<param name = "region"> The region of elements to map. </param>
        ///<paramref name = "events"/> is not <c> null </c> or read-only a new <param name = "events"> A collection of events that need to complete before this command   <see cref = "ComputeEvent"/> identifying this command is created and attached to the end of the collection. </param>
        ///<remarks> If <paramref name = "blocking"/> is <c> false </c> is <c> true </c> this method will not return until the command completes.   > this method will return immediately after the command is enqueued. </remarks>
        public IntPtr Map <T>(ComputeBufferBase <T> buffer, bool blocking, ComputeMemoryMappingFlags flags, long offset, long region, ICollection <ComputeEventBase> events) where T : struct
        {
            int sizeofT = Marshal.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;

            IntPtr mappedPtr = IntPtr.Zero;

            ComputeErrorCode error = ComputeErrorCode.Success;

            mappedPtr = CL12.EnqueueMapBuffer(Handle, buffer.Handle, blocking, flags, new IntPtr(offset * sizeofT), new IntPtr(region * sizeofT), eventWaitListSize, eventHandles, newEventHandle, out error);
            ComputeException.ThrowOnError(error);

            if (eventsWritable)
            {
                events.Add(new ComputeEvent(newEventHandle[0], this));
            }

            return(mappedPtr);
        }