public void FrameArrivedDevice(FrameInformation frame) { using var _ = _resource.Map(); var resourceArray = _resource.GetMappedArray(); var rgbSize = frame.GetRgba32Size(); var width = frame.Info.Width; var rgba32Pitch = width * 4; var rgba32PitchPtr = (IntPtr)rgba32Pitch; using (var destPtr = CuDeviceMemory.Allocate(rgbSize)) { frame.DecodeToDeviceRgba32(destPtr); var memcopy = new CuMemcopy2D { SrcMemoryType = CuMemoryType.Device, SrcDevice = destPtr, SrcPitch = rgba32PitchPtr, DstMemoryType = CuMemoryType.Array, DstArray = resourceArray, WidthInBytes = rgba32PitchPtr, Height = (IntPtr)frame.Info.Height }; memcopy.Memcpy2D(); } _swap?.Present(1, PresentFlags.None); }
public unsafe void FrameArrivedHost(FrameInformation frame) { var rgbSize = frame.GetRgba32Size(); var width = frame.Info.Width; var rgba32Pitch = width * 4; var buffer = _swap.GetBackBuffer <Texture2D>(0); // TODO: Pool the buffer. var destHost = new byte[rgbSize]; fixed(byte *destHostPtr = destHost) { _device.ImmediateContext.UpdateSubresource( buffer, 0, null, (IntPtr)destHostPtr, rgba32Pitch, 0); } _swap?.Present(1, PresentFlags.None); }