Advertisement Jump to content
Sign in to follow this  

[D3D12] Uploading Texture Data

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

In the first iteration of my code for uploading texture data for use in a shader, i just did a basic call to UpdateSubresources:

D3D12_SUBRESOURCE_DATA uploadData = {};
uploadData.pData = data;
uploadData.RowPitch = width * bytesPerPixel;
uploadData.SlicePitch = totalSize;
UpdateSubresources(list, resource.Get(), uploadResource.Get(), 0, 0, 1, &uploadData);

This worked just fine until I introduced a cube map that had mip maps.  Suddenly it started to crash in UpdateSubresources.  I tried setting the NumSubresources field of UpdateSubresources to (numLayers(6) * numMipMaps(11)), but it still crashed.  So I rewrote this portion of the code to call GetCopyableFootprint and fill out an array of D3D12_PLACED_SUBRESOURCE_FOOTPRINT structures, map the intermediate resource and copy to it manually using the aforementioned structures, and then finally call CopyTextureRegion for each sub resource.


This worked just fine, for mipmapped, array, and singular textures alike, until I tried to load a 4x4 32 bit non-mipmapped texture.  Suddenly it started to crash again.  After some digging, I found that the rowPitch of my footprint structure, returned from GetCopyableFootprint, was coming back as 256.  I presume it should be 16.


So then... what is the best way to load texture data?  I think I'd honestly like to just call UpdateSubresources and get it to work properly for the mip-mapped cubemap.

Share this post

Link to post
Share on other sites

The row pitch of a D3D12_PLACED_SUBRESOURCE_FOOTPRINT must be aligned to 256 bytes.


The crash sounds like you're either filling out the struct describing your source data incorrectly, or you're not allocating enough memory in your intermediate buffer. It's likely the second case. Try using GetRequiredIntermediateSize() to determine how big your intermediate needs to be. You should just be able to use UpdateSubresources and it should work properly.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!