Exemple #1
0
        public static IMTLBuffer CreateBuffer <T> (this IMTLDevice This, T [] data, MTLResourceOptions options) where T : struct
        {
            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);              // This requires a pinned GCHandle, since it's not possible to use unsafe code to get the address of a generic object.

            try {
                IntPtr ptr = handle.AddrOfPinnedObject();
                return(This.CreateBuffer(ptr, (nuint)(data.Length * Marshal.SizeOf(typeof(T))), options));
            } finally {
                handle.Free();
            }
        }
Exemple #2
0
        public static IMTLBuffer CreateBuffer <T> (this IMTLDevice This, T [] data, MTLResourceOptions options) where T : struct
        {
            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try {
                IntPtr ptr = handle.AddrOfPinnedObject();
                return(This.CreateBuffer(ptr, (nuint)(data.Length * Marshal.SizeOf(typeof(T))), options));
            } finally {
                handle.Free();
            }
        }
Exemple #3
0
 public static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, Selector selector, void *a, UIntPtr b, MTLResourceOptions c);
        public static IMTLBuffer?CreateBufferNoCopy <T> (this IMTLDevice This, T [] data, MTLResourceOptions options, MTLDeallocator deallocator) where T : struct
        {
            if (data == null)
            {
                ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(data));
            }

            var    handle = GCHandle.Alloc(data, GCHandleType.Pinned);           // This requires a pinned GCHandle, since it's not possible to use unsafe code to get the address of a generic object.
            IntPtr ptr    = handle.AddrOfPinnedObject();

            return(This.CreateBufferNoCopy(ptr, (nuint)(data.Length * Marshal.SizeOf(typeof(T))), options, (pointer, length) => {
                handle.Free();
                deallocator(pointer, length);
            }));
        }