sharpdx/SharpDX

texture size is reported wrong

belveder79 opened this issue · 3 comments

I'm trying to read back a texture to CPU, so I created a staging texture. The problem is that this texture may have an arbitrary size, so I create it with something like:

stagingTextureDesc.Width = 643;
stagingTextureDesc.Height = 427;
stagingTextureDesc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.Read;
stagingTextureDesc.BindFlags = SharpDX.Direct3D11.BindFlags.None;
stagingTextureDesc.OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None;
stagingTextureDesc.Usage = SharpDX.Direct3D11.ResourceUsage.Staging;
_texIntfData.m_IntermediateStagingTexture = new SharpDX.Direct3D11.Texture2D(_texIntfData.m_IntermediateDevice, stagingTextureDesc);
_texIntfData.m_IntermediateStagingShaderResourceView = new SharpDX.Direct3D11.ShaderResourceView(_texIntfData.m_IntermediateDevice, _texIntfData.m_IntermediateMipMapTexture);

Now when I read it back later, it reports me this size, however, internally it is definitely has a width of 1024, because the data I read back (Marshal.Copy(...) is aligned to 1024 and not 643.

It does not matter if the texture is multiple of 2, 4 or 8 or an uneven number - it seems to be always the larger power of 2 in the end. The problem is, there is no way to really query the size of the texture, or am I wrong?

Ok, so I'm not fully into device capabilities etc.
I'm running on a Macbook Pro Late 2018 and a Macbook Pro Late 2015 one, the behaviour seems different on the two devices and whether I use VMWare to run Windows or use Windows natively. The problem described was observed on Windows native (which is even stranger to me). The Problem does not appear on VMWare powered Windows however...

mrvux commented

Normally when you map your resource for read (or write), the databox has a RowPitch parameter, which will tell you the size of one row in bytes.

What feature level do you use (or what function) to create your device? (also what feature level is reported by your device once created?)

you are completely right - that was what I've missed, thanks a lot!

I got a little more into this and my guess is that probably the textures on VMWare are software emulated, rather than real hardware textures. I now used the rowpitch to get everything right, as RowPitch is on VMWare indeed the width times 4, and natively 2 to the power of ceil(log(width)/log(2)) times 4. That works so far.