internal static extern CLSampler clCreateSampler(CLContext context, CLBool normalized_coords, CLAddressingMode addressing_mode, CLFilterMode filter_mode, ref CLError errcode_ret);
internal static extern CLError clGetContextInfo(CLContext context, CLContextInfo param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
internal static extern CLError clCreateFromGLBuffer(CLContext context, CLMemFlags flags, int bufobj, ref CLError errcode_ret);
internal static extern CLCommandQueue clCreateCommandQueue(CLContext context, CLDeviceID device, CLCommandQueueProperties properties, ref CLError errcode_ret);
internal static extern CLProgram clCreateProgramWithBinary(CLContext context, int num_devices, [In] CLDeviceID[] device_list, [In] SizeT[] lengths, [In] IntPtr[] binaries, [In] int[] binary_status, ref CLError errcode_ret);
internal static extern CLMem clCreateBuffer(CLContext context, CLMemFlags flags, SizeT size, IntPtr host_ptr, ref CLError errcode_ret);
internal static extern CLError clRetainContext(CLContext context);
internal static extern CLError clGetSupportedImageFormats(CLContext context, CLMemFlags flags, CLMemObjectType image_type, int num_entries, [Out] CLImageFormat[] image_formats, ref int num_image_formats);
internal static extern CLError clReleaseContext(CLContext context);
internal static extern CLMem clCreateFromGLTexture3D(CLContext context, CLMemFlags flags, int target, int miplevel, uint texture, ref CLError errcode_ret);
internal static extern CLError clCreateFromGLRenderbuffer(CLContext context, CLMemFlags flags, int renderbuffer, ref CLError errcode_ret);
internal static extern CLMem clCreateImage3D(CLContext context, CLMemFlags flags, ref CLImageFormat image_format, SizeT image_width, SizeT image_height, SizeT image_depth, SizeT image_row_pitch, SizeT image_slice_pitch, IntPtr host_ptr, ref CLError errcode_ret);
internal static extern CLProgram clCreateProgramWithSource(CLContext context, int count, [In] string[] strings, [In] SizeT[] lengths, ref CLError errcode_ret);
private Context(CLContext openclContext, Platforms platforms, Devices devices) { this.Devices = devices; this.Platforms = platforms; this.CLContext = openclContext; }
public static Context Share(IntPtr openclContext) { SizeT devicesSize = SizeT.Zero; CLContext clContext = new CLContext { Value = openclContext }; OpenCLError.Validate(OpenCLDriver.clGetContextInfo(clContext, CLContextInfo.Devices, SizeT.Zero, IntPtr.Zero, ref devicesSize)); CLDeviceID[] devices = new CLDeviceID[((Int64)(devicesSize)) / IntPtr.Size]; GCHandle devicesHandle = GCHandle.Alloc(devices, GCHandleType.Pinned); try { OpenCLError.Validate(OpenCLDriver.clGetContextInfo(clContext, CLContextInfo.Devices, devicesSize, devicesHandle.AddrOfPinnedObject(), ref devicesSize)); Dictionary<CLPlatformID, CLPlatformID> platformsDictionary = new Dictionary<CLPlatformID, CLPlatformID>(); CLPlatformID[] platforms = null; foreach (CLDeviceID device in devices) { SizeT platformsSize = SizeT.Zero; OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, SizeT.Zero, platforms, ref platformsSize)); platforms = new CLPlatformID[((Int64)(platformsSize)) / IntPtr.Size]; OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, platformsSize, platforms, ref platformsSize)); foreach (CLPlatformID platform in platforms) { if (!platformsDictionary.ContainsKey(platform)) { platformsDictionary.Add(platform, platform); } } } platforms = new CLPlatformID[platformsDictionary.Count]; Int32 index = 0; foreach (var platform in platformsDictionary.Keys) { platforms[index++] = platform; } return new Context(clContext, new Platforms(platforms), new Devices(devices)); } finally { devicesHandle.Free(); } }