
Cloo and ComputeImage2D Problem
Posted Friday, 15 October, 2010 - 11:04 by wahabkotwal inHello..
I have created a little code using Cloo.. But im having some trouble in writing and reading an image to buffer.
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
ImgData = GetImageData(bmp); //Converts image into byte array
ComputeContextPropertyList Properties = new ComputeContextPropertyList(ComputePlatform.Platforms[0]);
Context = new ComputeContext(ComputeDeviceTypes.All, Properties, null, IntPtr.Zero);
//Create the command queue
CQ = new ComputeCommandQueue(Context, Context.Devices[0],
ComputeCommandQueueFlags.None);
//Source code compilation
CLFilterSrc src = new CLFilterSrc();
//Variable for BrighntessAmount
float[] BrightnessValue = new float[1];
BrightnessValue[0] = Convert.ToInt32(txtBrightness.Text);
CLValue = new ComputeBuffer(Context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.UseHostPointer, BrightnessValue);
ComputeProgram prog = new ComputeProgram(Context, src.src);
prog.Build(Context.Devices, "", null, IntPtr.Zero);
ComputeImage2D cmSource;
ComputeImage2D cmDestination;
float[] imgProcessed = new float[bmp.Width * bmp.Height * PIXELSIZE];
unsafe
{
fixed (byte* imgPtr = ImgData)
{
ComputeImageFormat format = new ComputeImageFormat(ComputeImageChannelOrder.Rgba, ComputeImageChannelType.Float);
cmSource = new ComputeImage2D(Context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.UseHostPointer, format, bmp.Width, bmp.Height, bmp.Width * 4 * sizeof(float), (IntPtr)imgPtr);
cmDestination = new ComputeImage2D(Context, ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.UseHostPointer, format, bmp.Width, bmp.Height, bmp.Width * 4 * sizeof(float), (IntPtr)imgPtr);
}
kernelImageProcessing = prog.CreateKernel("FilterBrightness");
kernelImageProcessing.SetMemoryArgument(0, cmSource);
kernelImageProcessing.SetMemoryArgument(1, cmDestination);
kernelImageProcessing.SetMemoryArgument(2, CLValue);
CQ.Execute(kernelImageProcessing, null, new long[] {bmp.Width,bmp.Height}, null, null);
fixed (float* imgPtr2 = imgProcessed)
{
CQ.Read(cmDestination, true, new long[] { 0, 0, 0 }, new long[] { bmp.Width, bmp.Height, 1 }, bmp.Width * 4 * sizeof(float), 0, (IntPtr)imgPtr2, null);
}
}
CQ.Dispose();
cmSource.Dispose();
cmDestination.Dispose();
pic.Image = SetImageData(imgProcessed, bmp.Width, bmp.Height);
sw.Stop();
lblTime.Text = sw.Elapsed.ToString();
But as i run the code, nothing happens at all.. Not even any single error!! I dont understand whts wrong with it.. Acutally, im new to Cloo thts why im having those problems.. Please HELP!! its SOS!


Comments
Re: Cloo and ComputeImage2D Problem
Try asking on the cloo forums on sourceforge.