ID3D11Device::CreateTexture2D: pInitialData[0].SysMemPitch cannot be 0

17:07
Sat
09
Jan 2016

ID3D11Device::CreateTexture2D: pInitialData[0].SysMemPitch cannot be 0

The concept of "stride" or "pitch" - a step (in bytes) to be taken to proceed to next element of a data structure - is brilliant, because it gives great flexibility. In 3D graphics for example, explicitly specified number of bytes between vertices in a vertex buffer or rows in a texture can be:

  1. Equal to exact size of vertex structure or texture row, when these entries are laid out next to each other.
  2. Greater, so additional padding can exist at the end of each entry or entries can be interleaved with some other data to be skipped in particular case.
  3. Zero, so that the same single entry will be read over and over.

This is a theory, because I just discovered that option 3 doesn't work in Direct3D 11 when passing pInitialData to created texture. I cannot see any reason why specifying D3D11_SUBRESOURCE_DATA::SysMemPitch == 0 should be considered invalid, other than trying to save developer from possibly unintended mistake. I think it is actually pretty useful for initializing a texture with the same data in each row, so it would be enough to allocate and fill the data for just one row, instead of full texture. And still, following code fails on call to CreateTexture2D:

CD3D11_TEXTURE2D_DESC textureDesc = CD3D11_TEXTURE2D_DESC(
    TEXTURE_FORMAT, // format
    (UINT)TEXTURE_SIZE.x, // width
    (UINT)TEXTURE_SIZE.y, // height
    1, // arraySize
    1, // mipLevels
    D3D11_BIND_SHADER_RESOURCE, // bindFlags
    D3D11_USAGE_DYNAMIC, // usage
    D3D11_CPU_ACCESS_WRITE); // cpuaccessFlags
std::vector<uint32_t> initialTextureRow(TEXTURE_SIZE.x);
ZeroMemory(&initialTextureRow[0], TEXTURE_SIZE.x * sizeof(uint32_t));
D3D11_SUBRESOURCE_DATA textureInitialData = {
    &initialTextureRow[0], // pSysMem
    0, // SysMemPitch
    0 }; // SysMemSlicePitch
ID3D11Texture2D *texture = nullptr;
ERR_GUARD_DIRECTX( m_Dev->CreateTexture2D(&textureDesc, &textureInitialData, &texture) );

DirectX debug layer reports error:

D3D11 ERROR: ID3D11Device::CreateTexture2D: pInitialData[0].SysMemPitch cannot be 0 [ STATE_CREATION ERROR #100: CREATETEXTURE2D_INVALIDINITIALDATA]

Dear Microsoft: Why? :)

Comments (1) | Tags: directx | Author: Adam Sawicki | Share

Comments

Yeezy boost 350
2016-03-06 03:13:04
http://www.nikeoutletfactorystore.com/ Nike Outlet Factory
http://www.longchamp--outlet.com/ Longchamp Outlet
http://www.nikeflyknit.org/ Nike Flyknit
http://www.oakleysunglassesoutlet.name/ Oakley Outlet
http://www.oakleyoutletstore.net.co/ Oakley Outlet
http://www.tomsoutletstore.org/ Toms Outlet
http://www.ralphlaurenoutletstoreonline.com/ polo ralph lauren outlet online
http://www.katespadeoutletsstore.com/ Kate Spade Outlet
http://www.air-max2015.org/ nike air max 2015
http://www.adidasoutletstore.org/ Adidas Outlet Store
http://www.yeezyboost350.us.com/ Yeezy Boost 350
http://www.nikeoutletsstore.com/ Nike Outlet
http://www.yeezyboost.org/ Yeezy Boost 350
http://www.longchampoutletstore.us.com/ longchamp outlet
http://www.katespade-outlet.org/ kate spade outlet
http://www.nfljerseyswhosale.us.com/ Cheap NFL Jerseys
http://www.airmax2016.us.com/ Nike Air Max 2016
http://www.raybanoutletsunglasses.net/ Ray Ban Outlet
http://www.burberryoutletstoreonline.org/ Burberry Outlet
http://www.adidasyeezyboost350.org/ Adidas Yeezy

Post comment

Nick *
Your name or nickname
E-mail
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki