{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/101","labels_url":"https://api.github.com/repos/Microsoft/Win2D/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/Win2D/issues/101/comments","events_url":"https://api.github.com/repos/Microsoft/Win2D/issues/101/events","html_url":"https://github.com/Microsoft/Win2D/issues/101","id":85675488,"number":101,"title":"Best way to copy raw pixels","user":{"login":"pleaseking","id":2921348,"avatar_url":"https://avatars.githubusercontent.com/u/2921348?v=3","gravatar_id":"","url":"https://api.github.com/users/pleaseking","html_url":"https://github.com/pleaseking","followers_url":"https://api.github.com/users/pleaseking/followers","following_url":"https://api.github.com/users/pleaseking/following{/other_user}","gists_url":"https://api.github.com/users/pleaseking/gists{/gist_id}","starred_url":"https://api.github.com/users/pleaseking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleaseking/subscriptions","organizations_url":"https://api.github.com/users/pleaseking/orgs","repos_url":"https://api.github.com/users/pleaseking/repos","events_url":"https://api.github.com/users/pleaseking/events{/privacy}","received_events_url":"https://api.github.com/users/pleaseking/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-06T01:56:50Z","updated_at":"2015-06-06T04:13:24Z","closed_at":null,"body":"Hi,\r\n\r\nI need some advice regarding the most efficient way to copy pixels between an in-memory buffer and a `CanvasRenderTarget`. The background problem is as follows:\r\n - I have a GUI engine rendering in RGBA (now)\r\n - I need to use native Win2D text rendering\r\n - I have tried the following approaches:\r\n    - Have a `CanvasRenderTarget` of the same size as buffer (i.e. screen), copy pixels from buffer into rendertarget, draw text, copy pixels back. Problem: slow to copy that many pixels.\r\n    - Have same big `CanvasRenderTarget`, copy pixels for a rectangle surrounding text, draw text, copy pixels back (using a series of line-by-line `memcpy`'s and `GetPixelBytes(rect)` / `SetPixelBytes(rect)`). Problem: `GetPixelBytes(rect)` / `SetPixelBytes(rect)` are way slower than their counterparts for the full image - but overall this is faster than the first option.\r\n    - Create a new small CanvasRenderTarget for each text block - then I can use `GetPixelBytes()` / `SetPixelBytes()` for the full image and they are faster, but creating/destroying `CanvasRenderTarget` takes time - however, this is the fastest for now.\r\n\r\nMy problem is that even the 3rd approach does not give acceptable performance on say Lumia 520. Any advice to optimize this even further? Maybe some D2D interop to read/write pixels of a CanvasRenderTarget directly, pixel-by-pixel, without `GetPixelBytes(rect)` / `SetPixelBytes(rect)` which seem to be quite inefficient?"},"comment":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/comments/109518853","html_url":"https://github.com/Microsoft/Win2D/issues/101#issuecomment-109518853","issue_url":"https://api.github.com/repos/Microsoft/Win2D/issues/101","id":109518853,"user":{"login":"shawnhar","id":8118468,"avatar_url":"https://avatars.githubusercontent.com/u/8118468?v=3","gravatar_id":"","url":"https://api.github.com/users/shawnhar","html_url":"https://github.com/shawnhar","followers_url":"https://api.github.com/users/shawnhar/followers","following_url":"https://api.github.com/users/shawnhar/following{/other_user}","gists_url":"https://api.github.com/users/shawnhar/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnhar/subscriptions","organizations_url":"https://api.github.com/users/shawnhar/orgs","repos_url":"https://api.github.com/users/shawnhar/repos","events_url":"https://api.github.com/users/shawnhar/events{/privacy}","received_events_url":"https://api.github.com/users/shawnhar/received_events","type":"User","site_admin":false},"created_at":"2015-06-06T04:13:24Z","updated_at":"2015-06-06T04:13:24Z","body":"> I can see something like \"Read bitmap contents without memory allocation (GetPixelBytes overload that takes an IBuffer)\" in win2d backlog - would that help much? \r\n\r\nI don't think much, although it would probably make a small difference.  That feature would allow removing one CPU -> CPU copy of the data, but it doesn't remove the need for the initial GPU -> CPU copy, HW to SW format unswizzle, or the GPU pipeline stall which are the main things making any such readback slow.  These aspects are pretty much inherent to how GPUs work, not unique to Win2D or D2D."}}