Jump to content
  • Advertisement
Sign in to follow this  
Semei

DX11 [DX11 / SharpDX] MapSubresource returned data size mismatch

This topic is 2694 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been using MapSubresource function to read some texture data back to CPU, and come to find out that memory is not laid out in the same manner i declared texture and its not even the same size.

Basically, if i create texture of size like 257x257 then when mapping with RowPitch of 257*TexelSizeInBytes i get part of data returned as junk, and the only way to get all the data is to specify RowPitch as size of multiple of 32. So if i have texture width of 257 then real texture size to map correctly would be 257 + (32 - 257 % 32)=288! Im concerned about this because im not sure if this is constant through different GPU's, im currently using Nvidia GTX460 with latest drivers.

Any information on this?What would be the correct way to calculate real RowPitch, regardless of gpu/driver implementation? (I see that mapping texture with declared size, returns real RowPitch, but i cant(don't want to!) call Map twice just to get RowPitch correct... )

Share this post


Link to post
Share on other sites
Advertisement
This is normal and expected behavior. Mapped resource can include any bytes of RowPitch as long as it can include original data - meaning it can have arbitrary padding (including 0). It's up to GPU/driver to decide how to layout resource in memory, that is either for performance reasons or for GPU hardware reasons.

Why do you need to calculate RowPitch anyway? Usually you take number that Map method returns and use it to calculate needed offset in buffer.

Share this post


Link to post
Share on other sites

Why do you need to calculate RowPitch anyway? Usually you take number that Map method returns and use it to calculate needed offset in buffer.


Because while returned RowPitch is correct, SlicePitch is RealRowPitch * DeclaredTextureWidth, and while reading this data, i get only part of array, basically some part of texture is missing.

For example, using 257x257 texture, and element width of 1byte i get:

returned RowPitch: 288
returned SlicePitch: 288*257! while size of real SlicePitch is 288*288

Share this post


Link to post
Share on other sites
Afaik yours 288*257 is valid number for slice size. Basically SlicePitch = RowPitch * Height (not width).

Share this post


Link to post
Share on other sites

Afaik yours 288*257 is valid number for slice size. Basically SlicePitch = RowPitch * Height (not width).


Found the problem - its in the way SharpDX generates returned array, using provided pointer to data and then accessing data with created pointer works fine.

Like: float* data = (float*)Box.Data.NativePointer(or smth like that)
And then accessing data like data[number]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!