MapSubresource() returning incorrectly sized databox ?

Started by
2 comments, last by 21st Century Moose 11 years, 10 months ago
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);
}
}
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);

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);
}
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement