Advertisement

Depth CubeMap error when creating DepthStencilView

Started by September 02, 2019 10:05 PM
3 comments, last by そら 5 years ago

Hi everyone!

So, I'm trying to create a Depth CubeMap, but get an error when trying to Create the DepthStencilView with a FirstArraySlice >= 1. When set to only FirstArraySlice = 0 everything works as expected (all depths get rendered to just one face of the cubemap... but any value bigger than that returns an E_INVALIDARG error.

Here's the code snipet with the settings I'm using:


  D3D11_TEXTURE2D_DESC textDesc;
  ZeroMemory(&textDesc, sizeof(D3D11_TEXTURE2D_DESC));
  textDesc.Width = 1024;
  textDesc.Height = 1024;
  textDesc.MipLevels = 1;
  textDesc.ArraySize = 6;
  textDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  textDesc.SampleDesc.Count = 1;
  textDesc.Usage = D3D11_USAGE_DEFAULT;
  textDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
  textDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;

  m_pd3dDevice->CreateTexture2D(&textDesc, NULL, &m_pTexture);
  // Everything OK so far...



  D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
  dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
  dsvDesc.Flags = 0;
  dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
  dsvDesc.Texture2DArray.ArraySize = textDesc.ArraySize;
  dsvDesc.Texture2DArray.MipSlice = 0;

  for( UINT i = 0; i < textDesc.ArraySize; i++ ){
    dsvDesc.Texture2DArray.FirstArraySlice = i;
    m_pd3dDevice->CreateDepthStencilView(m_pTexture, &dsvDesc, &m_pDepthStencilView[i]);
  }
  // OK FirstArraySlice = 0
  // ERROR FirstArraySlice >= 1

 

Am I missing something in here?

Thanks!

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

You can't have a DepthStencilView with an ArraySize of 6 starting at any slice other than 0 since you only have 6 slices in your array to begin with. I assume you meant to set ArraySize to 1 in dsvDesc.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Advertisement

Indeed, you can have either one DSV:

dsvDesc.Texture2DArray.ArraySize = 6; dsvDesc.Texture2DArray.FirstArraySlice = 0;

or six DSVs:

dsvDesc.Texture2DArray.ArraySize = 1; dsvDesc.Texture2DArray.FirstArraySlice = { 0 .. 5 };

In the former case, you'll need to have a geometry shader (!) with SV_RenderTargetArrayIndex on its output. That will select one of the 6 sub-textures to render to. Note that also your render targets (if any) will need to have 6 slices, in this case. I don't think you want that.

In the later case, which is probably what you want, you just have 6 views, each of which looks like a normal 2D texture with 1 slice. Normal rendering, face by face.

Aaah!... right!.. that was it!..

D'oh!.. sounds pretty obvious in restrospective.

Didn't know about the SV_RenderTArgetArrayIndex in the geometry shader, though.

Anyways!.. thank you both Adam Miles & pcmaster.

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

This topic is closed to new replies.

Advertisement