Sign in to follow this  
Gavin Williams

MapSubresource() returning incorrectly sized databox ?

Recommended Posts

Gavin Williams    986
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.

[code]
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);
}
}
[/code]

Share this post


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

e.g. for a single array slice:

[CODE]

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

[/CODE] Edited by eppo

Share this post


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

Here's my SlimDX version of your code :

[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);
}
[/CODE]

Share this post


Link to post
Share on other sites
mhagain    13430
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this