sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 638 forks source link

Bitmap CopyFromMemory Performance Degradation #130

Closed attic41 closed 11 years ago

attic41 commented 11 years ago

Running into a peculiar issue. I just ported a substantial Direct2D project from MS API Code Pack to SharpDX. Part of the functionality involves copying very large bitmaps from memory (several times). The code is rather simple... The source of the bitmap is always System.Drawing.Bitmap and the destination is a BitmapRenderTarget. The code below works correctly, BUT... Each successive call to CopyFromMemory() is slower than the previous (serious performance degradation). This is strange... especially since SharpDX is almost always twice as fast as MS API Code Pack for all other CPU timings I have done.. CopyFromMemory() appears to be an exception to this rule.

I've reviewed the code in your library and see no issues. Any ideas? The source code logic is basically the following lines.

using Drawing = System.Drawing; ... Drawing.Imaging.BitmapData SourceBitmapData = SourceBitmap.LockBits(new Drawing.Rectangle(0, 0, SourceBitmap.Width, SourceBitmap.Height), Drawing.Imaging.ImageLockMode.ReadOnly, Drawing.Imaging.PixelFormat.Format32bppPArgb); BitmapRenderTarget_SurfaceV[DestinationSurfaceID]).Bitmap.CopyFromMemory(SourceBitmapData.Scan0, SourceBitmapData.Stride); SourceBitmap.UnlockBits(SourceBitmapData);

xoofx commented 11 years ago

Bitmap.CopyFromMemory is a straight call to the COM method, so technically, there is no difference. So there is probably a side effect somewhere else.