private ComputeImage(CLMemoryHandle handle, ComputeContext context, ComputeMemoryFlags flags) : base(context, flags) { Handle = handle; Init(); }
public extern static CLMemoryHandle CreateFromGLTexture3D( CLContextHandle context, ComputeMemoryFlags flags, Int32 target, Int32 miplevel, Int32 texture, out ComputeErrorCode errcode_ret);
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);
private ComputeImage3D(IntPtr handle, ComputeContext context, ComputeMemoryFlags flags) : base(context, flags) { Handle = handle; Init(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <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(); }
/// <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(); } }
internal ComputeSubBuffer(ComputeContext context, CLMemoryHandle handle, ComputeMemoryFlags flags) : base(context, flags) { Handle = handle; Init(); }
/// <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(); }
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)); }
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(); }
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(); }
/// <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(); }
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);
/// <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(); }
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="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(); }
///<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)); }
/// <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); }
/* * ///<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) { }
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); }
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)); }
/// <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(); }
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); }
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)); }
/// <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(); } }
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(); }
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)); }
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; }
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; }
/// <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(); }
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)); }
/// <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); }
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; }
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()); }
public CLMemoryHandle CreateFromGLBuffer(CLContextHandle context, ComputeMemoryFlags flags, Int32 bufobj, out ComputeErrorCode errcode_ret) { return StaticCreateFromGLBuffer(context, flags, bufobj, out errcode_ret); }
public CLMemoryHandle CreateFromGLTexture(CLContextHandle context, ComputeMemoryFlags flags, int texture_target, int miplevel, int texture, out ComputeErrorCode errcode_ret) { throw new NotImplementedException(); }
public static extern CLMemoryHandle CreateBuffer( CLContextHandle context, ComputeMemoryFlags flags, IntPtr size, IntPtr host_ptr, out ComputeErrorCode errcode_ret);
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);
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="flags"></param> protected ComputeImage(ComputeContext context, ComputeMemoryFlags flags) : base(context, flags) { }
/// <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); }
public static unsafe extern IntPtr CreateSubBuffer( IntPtr buffer, ComputeMemoryFlags flags, ComputeBufferCreateType buffer_create_type, /* const void * */ IntPtr buffer_create_info, ComputeErrorCode* errcode_ret);
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(); }
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); }
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); }
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(); }
/// <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); }
/// <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); }
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); } }
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(); }
public CLMemoryHandle CreateSubBuffer(CLMemoryHandle buffer, ComputeMemoryFlags flags, ComputeBufferCreateType buffer_create_type, ref SysIntX2 buffer_create_info, out ComputeErrorCode errcode_ret) { throw new NotImplementedException(); }
/// <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)); }
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);
/// <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); }
/// <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); }
public ComputeBuffer(ComputeContext context, ComputeMemoryFlags flags, long count) : this(context, flags, count, IntPtr.Zero) { }
public static extern CLMemoryHandle CreateFromGLRenderbuffer( CLContextHandle context, ComputeMemoryFlags flags, Int32 renderbuffer, out ComputeErrorCode errcode_ret);
public static extern CLMemoryHandle CreateFromGLTexture3D( CLContextHandle context, ComputeMemoryFlags flags, Int32 target, Int32 miplevel, Int32 texture, out ComputeErrorCode errcode_ret);
public static extern CLMemoryHandle StaticCreateFromGLBuffer(CLContextHandle context, ComputeMemoryFlags flags, Int32 bufobj, out ComputeErrorCode errcode_ret);