Пример #1
0
        private void AllocateNv12FrameBuffer(
            CuMemoryType type, IntPtr frameByteSize,
            out CuDeviceMemory frameDevicePtr,
            out IntPtr frameLocalPtr)
        {
            frameDevicePtr = default;
            frameLocalPtr  = default;

            var pooled = _nv12BufferPool.Get();

            if (pooled != null)
            {
                // Only use exact size matches to allow memory reduction when
                // sizing down.
                if (pooled.Size == frameByteSize &&
                    pooled.MemoryType == type)
                {
                    frameLocalPtr  = pooled.Bytes;
                    frameDevicePtr = pooled.DeviceMemory;
                    return;
                }

                // The memory type or size has changed. Deallocate the old
                // buffer and allocate new.
                pooled.Dispose();
            }

            if (type == CuMemoryType.Host)
            {
                frameLocalPtr = Marshal.AllocHGlobal(frameByteSize);
                return;
            }

            frameDevicePtr = CuDeviceMemory.Allocate(frameByteSize);
        }
Пример #2
0
 public BufferStorage(
     IntPtr bytes,
     CuMemoryType memoryType,
     CuDeviceMemory deviceMemory,
     IntPtr size)
 {
     Bytes        = bytes;
     Size         = size;
     DeviceMemory = deviceMemory;
     MemoryType   = memoryType;
 }