'Texture format DXGI_FORMAT_NV12 does not support mipmaps

I have a source texture ID3D11Texture2D with the format DXGI_FORMAT_NV12. I am trying to copy a subregion of this texture (D3D11DeviceContext::CopySubresourceRegion) and then generate a full mipmap chain down to 1x1 on the destination texture.

To generate a full set of subtextures I include the following in the destination texture's description:

D3D11_TEXTURE2D_DESC desc {};
desc.MipLevels = 0;

The problem is that the data format DXGI_FORMAT_NV12 does not support mipmaps:

D3D11 ERROR: ID3D11Device::CreateTexture2D: Invalid MipLevels (0).
The format (0x67, NV12) does not support mipmapping, so MipLevels must be 1.
[ STATE_CREATION ERROR #102: CREATETEXTURE2D_INVALIDMIPLEVELS]

How do I cast the source texture to the appropriate format to generate a full set of mipmaps on the subresource? Or, what else can be done to get around this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source