예제 #1
0
        public void TestEvents()
        {
            checkSetup();
            CommandQueue queue  = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);
            Buffer       buffer = Buffer.Create(context, MemFlags.ReadWrite, (IntPtr)16);

            Float4 vec = new Float4();

            vec.X = 1.0f; vec.Y = 2.0f; vec.Z = 3.0f; vec.W = 4.0f;

            IntPtr vecBuff = Marshal.AllocHGlobal(16);

            try{
                Marshal.StructureToPtr(vec, vecBuff, false);

                unsafe {
                    Event writeEvent;
                    buffer.EnqueueWriteRaw(queue, (IntPtr)0, (IntPtr)16, vecBuff, out writeEvent);
                    Assert.True(writeEvent.Handle != IntPtr.Zero, "writeEvent handle was null.");

                    writeEvent.Wait();
                    Assert.AreEqual(CommandType.WriteBuffer, writeEvent.CommandType);
                    Assert.AreEqual(CommandExecutionStatus.Complete, writeEvent.ExecutionStatus);
                    Trace.WriteLine("writeEvent.ReferenceCount: " + writeEvent.ReferenceCount.ToString(), "notice");
                }
            }
            finally{
                Marshal.FreeHGlobal(vecBuff);
                buffer.Dispose();
                queue.Dispose();
            }
        }
예제 #2
0
        public void TestBufferReadWriteRaw()
        {
            checkSetup();
            CommandQueue queue  = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);
            Buffer       buffer = Buffer.Create(context, MemFlags.ReadWrite, (IntPtr)16);

            Float4 vec = new Float4();

            vec.X = 1.0f; vec.Y = 2.0f; vec.Z = 3.0f; vec.W = 4.0f;

            IntPtr vecBuff = Marshal.AllocHGlobal(16);

            try{
                Marshal.StructureToPtr(vec, vecBuff, false);

                unsafe {
                    Event writeEvent;
                    buffer.EnqueueWriteRaw(queue, (IntPtr)0, (IntPtr)16, vecBuff, out writeEvent);
                    writeEvent.Wait();

                    float v0, v1, v2, v3;
                    buffer.ReadRaw(queue, (IntPtr)0, (IntPtr)4, (IntPtr)(&v0));
                    buffer.ReadRaw(queue, (IntPtr)4, (IntPtr)4, (IntPtr)(&v1));
                    buffer.ReadRaw(queue, (IntPtr)8, (IntPtr)4, (IntPtr)(&v2));
                    buffer.ReadRaw(queue, (IntPtr)12, (IntPtr)4, (IntPtr)(&v3));

                    Assert.AreEqual(1.0f, v0);
                    Assert.AreEqual(2.0f, v1);
                    Assert.AreEqual(3.0f, v2);
                    Assert.AreEqual(4.0f, v3);

                    float k = 9.0f;
                    buffer.WriteRaw(queue, (IntPtr)4, (IntPtr)4, (IntPtr)(&k));
                    buffer.ReadRaw(queue, (IntPtr)4, (IntPtr)4, (IntPtr)(&v1));
                    Assert.AreEqual(9.0f, v1);
                }
            }
            finally{
                Marshal.FreeHGlobal(vecBuff);
                buffer.Dispose();
                queue.Dispose();
            }
        }