1
\$\begingroup\$

I'm trying to create immutable texture in d3d11 so I want to use subresourceData, every tutorial on textures creates them with 2nd argument being null and after that updates subresource but I want to create it using the 2nd argument. This code works:

hResult = m_device->CreateTexture2D(&textureDesc, NULL, &m_cubeTexture);
if (FAILED(hResult)) {
    return false;
}

int rowPitch = textureWidth * 4;
m_deviceContext->UpdateSubresource(m_cubeTexture, 0, NULL, &(decodedTexture[0]), rowPitch, rowPitch * textureHeight);

And this does not:

int rowPitch = textureWidth * 4;
D3D11_SUBRESOURCE_DATA tSData;
tSData.pSysMem = &(decodedTexture[0]);
tSData.SysMemPitch = rowPitch;
tSData.SysMemSlicePitch = rowPitch * textureHeight;

hResult = m_device->CreateTexture2D(&textureDesc, &tSData, &m_cubeTexture);
if (FAILED(hResult)) {
    return false;
}

DirectX11 debug layer outputs this:

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

Which I don't understand since it's not even an array and texture array size is set to 1

\$\endgroup\$
  • \$\begingroup\$ If it's not an array texture then you must have miplevels specified (each miplevel is also a subresource). What is the value of textureDesc.MipLevels? Anything other than 1 will cause this. \$\endgroup\$ – Maximus Minimus Sep 10 '17 at 16:50
  • \$\begingroup\$ For DDSTextureLoader and WICTextureLoader in the DirectX Tool Kit I use initData initialization. The source code for these should help. \$\endgroup\$ – Chuck Walbourn Sep 11 '17 at 21:55
  • \$\begingroup\$ This thread has the answer: gamedev.net/forums/topic/… \$\endgroup\$ – Soonts Nov 25 '17 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.