Jump to content

  • Log In with Google      Sign In   
  • Create Account

MapSubresource() returning incorrectly sized databox ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Gavin Williams   Members   -  Reputation: 776

Like
0Likes
Like

Posted 16 June 2012 - 01:37 PM

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


Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2621

Like
3Likes
Like

Posted 16 June 2012 - 02:39 PM

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, 16 June 2012 - 02:41 PM.


#3 Gavin Williams   Members   -  Reputation: 776

Like
0Likes
Like

Posted 16 June 2012 - 03:47 PM

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


#4 mhagain   Crossbones+   -  Reputation: 8275

Like
1Likes
Like

Posted 16 June 2012 - 03:57 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS