1

In fact, I got this problem from this question I posted before. It works under windows 10 with directx 12. But I failed to create Texture2D under windows 7 with directx 11. I created a second texture2d to generate mipmaps like this:

D3D11_TEXTURE2D_DESC textureDesc;
textureDesc.Width = nWidth;//Video width
textureDesc.Height = nHeight;//Video height
textureDesc.MipLevels = 0;//generate a full set of subtextures.
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
m_pD3dDevice->CreateTexture2D(&textureDesc, NULL, &m_pTexture);

I just got "Invalid arguments" under Windows7. It seems that only DirectX11.1 guarantees this kind of usage according to Extended support for shared Texture2D resources. Bind flags of D3D11_BIND_SHADER_RESOURCE and D3D11_BIND_RENDER_TARGET are not supported under Windows 7(the version of DirectX should be directx11).And without this,ID3D11DeviceContext::GenerateMips method has no effect. My application must support Windows 7, so Is there any alternative solution?

Ziauz
  • 773
  • 4
  • 22
RustOnce
  • 13
  • 5
  • The first step in debugging Direct3D issues is to enable the debug device. Did you get any diagnostic output from it? Also, DirectX 11.1 is supported on Windows 7 if you have [KB2670838](https://blogs.msdn.microsoft.com/chuckw/2013/02/26/directx-11-1-and-windows-7-update/) installed. Autogen mipmaps work just fine on DirectX 11.0 or later, so the problem is likely something else... – Chuck Walbourn May 11 '18 at 18:01

1 Answers1

2

The reason it fails on Windows 7 but works on Windows 10 is because you are actually making use of a Direct3D 11.2 Runtime optional feature: D3D11_FEATURE_DATA_D3D11_OPTIONS1.MapOnDefaultBuffers. You have D3D11_USAGE_DEFAULT and D3D11_CPU_ACCESS_WRITE set at the same time which is not supported without this optional feature, and is never supported on Windows 7. There are devices even on Windows 10 that don't support this feature as well, so you can't rely on it working 100% of the time.

To get CPU write access, you need to use D311_USAGE_DYNAMIC. This can impact performance of using that texture for rendering, so more typically you'd use D3D11_USAGE_DEFAULT without CPU write access. To initialize such textures you use another texture which is set to D3D11_USAGE_STAGING which always supports CPU write access and then copy to the DEFAULT resource, or you can make use of UpdateSubresource.

For C++ source example of doing all this including auto-gen mipmapping, see WICTextureLoader in the DirectX Tool Kit for DX11

Windows 7 Service Pack 1 can be updated to the DirectX 11.1 Runtime by using KB2670838 and at this point it's pretty widely deployed. There are some limitations when run on Windows 7 listed on MSDN, primarily that it only supports 'software' features and no 'hardware' features which require WDDM 1.2 drivers. The DirectX 11.2 Runtime or later is not supported for Windows 7.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • 1
    I just changed ``D3D11_CPU_ACCESS_WRITE`` to 0, then it worked.It is strange that ``D3D11_CPU_ACCESS_READ`` is not OK.Thanks a lot! – RustOnce May 14 '18 at 02:35
  • This slightly dated article on [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ee418784(v=vs.85).aspx) might help... – Chuck Walbourn May 14 '18 at 06:37