Explain XXXView in DirectX

15 Oct 2025

Reading time ~1 minute

what is RenderTargetView/DepthStencilView/ShaderResourceView means

A resource view (a.k.a descriptor or descriptor view) is an object that allows us to tell the GPU how to interpret our data in a resource into something it could use in a shader or pipeline

Example

A recent work of me can explain this very easy, example you want to use a texture2Darray to store your cascade shadow map.

then you need to fill DepthOrArraySize in D3D12_RESOURCE_DESC when create the texture.

typedef struct D3D12_RESOURCE_DESC {
  D3D12_RESOURCE_DIMENSION Dimension;
  UINT64                   Alignment;
  UINT64                   Width;
  UINT                     Height;
  UINT16                   DepthOrArraySize;
  UINT16                   MipLevels;
  DXGI_FORMAT              Format;
  DXGI_SAMPLE_DESC         SampleDesc;
  D3D12_TEXTURE_LAYOUT     Layout;
  D3D12_RESOURCE_FLAGS     Flags;
} D3D12_RESOURCE_DESC;

the texture is used for shadowmap pass, so you need create a depthstencilview for it


typedef struct D3D12_DEPTH_STENCIL_VIEW_DESC {
  DXGI_FORMAT         Format;
  D3D12_DSV_DIMENSION ViewDimension;
  D3D12_DSV_FLAGS     Flags;
  union {
    D3D12_TEX1D_DSV         Texture1D;
    D3D12_TEX1D_ARRAY_DSV   Texture1DArray;
    D3D12_TEX2D_DSV         Texture2D;
    D3D12_TEX2D_ARRAY_DSV   Texture2DArray;
    D3D12_TEX2DMS_DSV       Texture2DMS;
    D3D12_TEX2DMS_ARRAY_DSV Texture2DMSArray;
  };
} D3D12_DEPTH_STENCIL_VIEW_DESC;

typedef struct D3D12_TEX2D_ARRAY_DSV {
  UINT MipSlice;
  UINT FirstArraySlice;
  UINT ArraySize;
} D3D12_TEX2D_ARRAY_DSV;

we want to render the each cascade with one render pass, so fill the Texture2DArray.FirstArraySlice with cascade index, and Texture2DArray.ArraySize with 1.(another way is to fill them with 0, N and use a geometry shader)

debug your program with a renderdoc framecap

alt text

to use the shadowmap in shading pass, you need to create a shaderresoureview for it, when you fill D3D12_SHADER_RESOURCE_VIEW_DESC , you should fill the Texture2DArray.FirstArraySlice with 0, and Texture2DArray.ArraySize with N. to access all slices in you texture2darray.



Share Tweet +1