locked
Using NV12 texture in Windows Developer Preview

    Question

  • Hi all,

    I would like to use the texture with NV12 format in my DirectX allplication.

    I can create a 2D texture with NV12 format successfully, but fail when I want to create a ShaderResourceView.

    The error code is 0x80070057 (E_INVALIDARG).

    According to this page: http://msdn.microsoft.com/en-us/library/windows/apps/bb173059.aspx, the NV12 format should be already supported in Windows Developer Preview.

    Does anyone know how to create ShaderResourceView with NV12 format?

    Below is my code:

    // Create texture

    HRSULT hr;
     D3D11_TEXTURE2D_DESC desc;
     desc.Width = width;
     desc.Height = height;
     desc.Format = DXGI_FORMAT_NV12;
     desc.MipLevels = 1;
     desc.ArraySize = 1;
     desc.SampleDesc.Count = 1;
     desc.SampleDesc.Quality = 0;
     desc.Usage = D3D11_USAGE_DEFAULT;
     desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
     desc.CPUAccessFlags = 0;
     desc.MiscFlags = 0;

     ID3D11Texture2D* tex = nullptr;
     hr =m_d3dDevice->CreateTexture2D(
       &desc,
       NULL,
       &tex);

     // Create shader texture view

     ID3D11ShaderResourceView* textureView;
     D3D11_TEXTURE2D_DESC texDesc;
     tex->GetDesc(&texDesc);

     D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
     SRVDesc.Format =  texDesc.Format;
     SRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
     SRVDesc.Texture2D.MipLevels = 1;

     hr = m_d3dDevice->CreateShaderResourceView(
             tex,
             &SRVDesc,
             &textureView);   // return 0x80070057


    • Edited by JanChen Thursday, December 01, 2011 4:15 AM
    Thursday, December 01, 2011 4:15 AM

Answers

  • The documentation makes it sound like the luminance and chrominance surfaces are distinct views. You probably need a second ShaderResourceView on the same NV12 texture that is DXGI_FORMAT_R8G8_UNORM or DXGI_FORMAT_R8G8_UINT format.

     

    DXGI_FORMAT_NV12

    Most common YUV 4:2:0 video resource format. Valid luminance data view formats for this video resource format are DXGI_FORMAT_R8_UNORM and DXGI_FORMAT_R8_UINT. Valid chrominance data view formats (width and height are each 1/2 of luminance view) for this video resource format are DXGI_FORMAT_R8G8_UNORM and DXGI_FORMAT_R8G8_UINT. Supported view types are SRV, RTV, and UAV. For luminance data view, the mapping to the view channel is Y->R8. For chrominance data view, the mapping to the view channel is U->R8 and V->G8.

    Friday, December 02, 2011 9:05 PM

All replies

  • The video formats are a little more complicated because they are not directly supported by the rendering API. You can't create a shader resource view directly using video formats like NV12.

    You can create views on resources of this format using some 'equivalent' formats that the rendering API can handle.

    In this case you need to set SRVDesc.Format = DXGI_FORMAT_R8_UNORM or DXGI_FORMAT_R8_UINT.

    See http://msdn.microsoft.com/en-us/library/windows/desktop/bb173059(v=vs.85).aspx

     

    Friday, December 02, 2011 1:12 AM
  • Dear Chuck,

    Thanks for your reply.

    I tried to create a shader resource view by format DXGI_FORMAT_R8_UNORM and it can be created successfully. But the texture display is only red color.

    Could you advise more detail about how to bind NV12 texture to shader resource view?

    Besides, I use Map to get the texture buffer then I found the buffer length is only 512*320 (my picture is 480*320). It looks like there is only Y channel data in it. Is it normal?

    Thanks.


    • Edited by JanChen Friday, December 02, 2011 1:58 AM
    Friday, December 02, 2011 1:58 AM
  • The documentation makes it sound like the luminance and chrominance surfaces are distinct views. You probably need a second ShaderResourceView on the same NV12 texture that is DXGI_FORMAT_R8G8_UNORM or DXGI_FORMAT_R8G8_UINT format.

     

    DXGI_FORMAT_NV12

    Most common YUV 4:2:0 video resource format. Valid luminance data view formats for this video resource format are DXGI_FORMAT_R8_UNORM and DXGI_FORMAT_R8_UINT. Valid chrominance data view formats (width and height are each 1/2 of luminance view) for this video resource format are DXGI_FORMAT_R8G8_UNORM and DXGI_FORMAT_R8G8_UINT. Supported view types are SRV, RTV, and UAV. For luminance data view, the mapping to the view channel is Y->R8. For chrominance data view, the mapping to the view channel is U->R8 and V->G8.

    Friday, December 02, 2011 9:05 PM
  • Friday, December 02, 2011 9:26 PM
  • Did you slove the problem that a shader resource view by format  DXGI_FORMAT_R8_UNORM but texture display is only red color?
    Thursday, April 26, 2012 8:50 AM