• Advertisement
Sign in to follow this  

MapSubresource() returning incorrectly sized databox ?

This topic is 2046 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

Hi again,

I've loaded a texture 32 x 32 with Format.R8G8B8A8_UNorm. When i MapSubresource() into a DataBox, the databox has a row-pitch of 256 and a slice-pitch of 8192. That seems incorrect to me as the format has a width of 4 bytes.

When I perform the following operation, my textures are striped with zero's (horizontal black lines). I believe MapSubresource is incorrectly mapping the texture.


if (GetFormatType(format) == FormatModifiers.UNorm)
{
byte[] buffer = new byte[formatWidth]; // formatWidth = 4
while (dataStream.Position < dataStream.Length) // datastream.length = 4096
{
databox.Data.Read(buffer, 0, formatWidth);
dataStream.Write(buffer, 0, formatWidth);
}
}

Share this post


Link to post
Share on other sites
Advertisement
You have to write data per row/scanline as the driver may add extra padding at the end of each row.

e.g. for a single array slice:



for(int i = 0; i < 256; ++i) memcpy((byte*)databox.pData + databox.RowPitch * i, sysmem + 256 * 4 * i, 256 * 4);

Edited by eppo

Share this post


Link to post
Share on other sites
Curious, is that a hangover or what ?

Here's my SlimDX version of your code :


for (int row = 0; row < height; row++)
{
byte[] buffer = new byte[width * formatWidth];
databox.Data.Seek(row * databox.RowPitch, System.IO.SeekOrigin.Begin);
databox.Data.Read(buffer, 0, width * formatWidth);
dataStream.Write(buffer, 0, width *formatWidth);
}

Share this post


Link to post
Share on other sites
This also happens in native D3D10/11. Some hardware/drivers will allocate a padded resource where others won't, and it's entirely down to how the hardware/driver decides to allocate the resource.

Share this post


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

  • Advertisement