Example #1
0
        public void TestImage2DReadWrite()
        {
            checkSetup();
            CommandQueue queue = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);

            ImageFormat fmt = new ImageFormat(ChannelOrder.R, ChannelType.Float);
            Image2D     img = Image2D.Create(context, MemFlags.ReadOnly, fmt, 4, 2);

            Assert.AreEqual((IntPtr)4, img.ElementSize);

            float[,] pix = new float[, ] {
                { 1.0f, 0.0f, 1.0f, 0.0f }, { 2.0f, 0.0f, 2.0f, 0.0f }
            };
            float[,] ret = new float[2, 4];
            img.Write(queue, pix);

            img.Read(queue, ret);

            for (int r = 0; r < pix.GetLength(0); r++)
            {
                for (int c = 0; c < pix.GetLength(1); c++)
                {
                    Assert.AreEqual(pix[r, c], ret[r, c]);
                }
            }

            img.Dispose();
            queue.Dispose();
        }
Example #2
0
        public void TestImage2DProperties()
        {
            checkSetup();
            CommandQueue queue = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);

            ImageFormat fmt = new ImageFormat(ChannelOrder.Ra, ChannelType.Float);
            Image2D     img = Image2D.Create(context, MemFlags.ReadOnly, fmt, 2, 2);

            Assert.AreEqual(2, img.Width);
            Assert.AreEqual(2, img.Height);
            Assert.AreEqual(fmt, img.ImageFormat);
            Assert.AreEqual((IntPtr)8, img.ElementSize);

            img.Dispose();
            queue.Dispose();
        }
Example #3
0
        public void CopyTo(Image2D dstImage, CommandQueue queue,
                           int srcOriginX, int srcOriginY, int dstOriginX, int dstOriginY,
                           int width, int height)
        {
            IntPtr evtHandle = IntPtr.Zero;

            IntPtr[] srcOrg = new IntPtr[] { (IntPtr)srcOriginX, (IntPtr)srcOriginY, (IntPtr)0 };
            IntPtr[] dstOrg = new IntPtr[] { (IntPtr)dstOriginX, (IntPtr)dstOriginY, (IntPtr)0 };
            IntPtr[] region = new IntPtr[] { (IntPtr)width, (IntPtr)height, (IntPtr)1 };

            unsafe
            {
                fixed(IntPtr *p_srcOrg = srcOrg, p_dstOrg = dstOrg, p_region = region)
                {
                    Native.Call(Native.EnqueueCopyImage(
                                    queue.Handle, this.Handle, dstImage.Handle,
                                    p_srcOrg, p_dstOrg, p_region, 0, null, &evtHandle));
                }
            }
            Event evt = new Event(evtHandle);

            evt.Wait();
            evt.Dispose();
        }
Example #4
0
 public Image2D CreateImage2D(MemFlags flags, ImageFormat format, int width, int height)
 {
     return(Image2D.Create(this, flags, format, width, height));
 }