> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateShaderResourceView

> Creates a shader-resource view for accessing data in a resource. (ID3D12Device.CreateShaderResourceView)

Creates a shader-resource view for accessing data in a resource.

## Syntax

```cpp theme={null}
void CreateShaderResourceView(
    ID3D12Resource  pResource,
    const D3D12_SHADER_RESOURCE_VIEW_DESC  pDesc,
    D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor
)
```

### Parameters

*pResource \[in, optional]*<br />Type: ID3D12Resource \*

A pointer to the [ID3D12Resource](/reference/graphics/d3d12_xs/interfaces/ID3D12Resource/id3d12resource_xs) object that represents the shader resource.

At least one of <i>pResource</i> or <i>pDesc</i>  must be provided. A null <i>pResource</i> is used to initialize a null descriptor, which guarantees D3D11-like null binding behavior (reading 0s, writes are discarded), but must have a valid <i>pDesc</i> in order to determine the descriptor type.

*pDesc \[in, optional]*<br />Type: const D3D12\_SHADER\_RESOURCE\_VIEW\_DESC \*

A pointer to a [D3D12\_SHADER\_RESOURCE\_VIEW\_DESC](/reference/graphics/d3d12/structs/d3d12_shader_resource_view_desc_public) structure that describes the shader-resource view.

A null <i>pDesc</i> is used to initialize a default descriptor, if possible. This behavior is identical to the D3D11 null descriptor behavior, where defaults are filled in. This behavior inherits the resource format and dimension (if not typeless) and for buffers SRVs target a full buffer and are typed (not raw or structured), and for textures SRVs target a full texture, all mips and all array slices. Not all resources support null descriptor initialization.

*DestDescriptor \[in]*<br />Type: D3D12\_CPU\_DESCRIPTOR\_HANDLE

Describes the CPU descriptor handle that represents the shader-resource view. This handle can be created in a shader-visible or non-shader-visible descriptor heap.

### Return value

Type: void

None.

## Remarks

<h3><a id="Processing_YUV_4_2_0_video_formats" /><a id="processing_yuv_4_2_0_video_formats" /><a id="PROCESSING_YUV_4_2_0_VIDEO_FORMATS" />Processing YUV 4:2:0 video formats</h3> An app must map the luma (Y) plane separately from the chroma (UV) planes. Developers do this by calling **CreateShaderResourceView** twice for the same texture and passing in 1-channel and 2-channel formats. Passing in a 1-channel format compatible with the Y plane maps only the Y plane. Passing in a 2-channel format compatible with the UV planes (together) maps only the U and V planes as a single resource view.

YUV 4:2:0 formats are listed in [DXGI\_FORMAT](https://learn.microsoft.com/en-us/windows/desktop/api/dxgiformat/ne-dxgiformat-dxgi_format).

#### Examples

The [D3D12nBodyGravity](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) sample uses **ID3D12Device::CreateShaderResourceView** as follows:

Describe and create two shader resource views based on one description.

```cpp theme={null}
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Format = DXGI_FORMAT_UNKNOWN;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
srvDesc.Buffer.FirstElement = 0;
srvDesc.Buffer.NumElements = ParticleCount;
srvDesc.Buffer.StructureByteStride = sizeof(Particle);
srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;

CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle0(m_srvUavHeap->GetCPUDescriptorHandleForHeapStart(), SrvParticlePosVelo0 + index, m_srvUavDescriptorSize);
CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle1(m_srvUavHeap->GetCPUDescriptorHandleForHeapStart(), SrvParticlePosVelo1 + index, m_srvUavDescriptorSize);
m_device->CreateShaderResourceView(m_particleBuffer0[index].Get(), &srvDesc, srvHandle0);
m_device->CreateShaderResourceView(m_particleBuffer1[index].Get(), &srvDesc, srvHandle1);
```

Refer to the [Example Code in the D3D12 Reference](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code).

<div class="code" />

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h<br />**Library:** d3d12\_xs.lib or d3d12\_x.lib<br />**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

[ID3D12Device](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [D3D12_SHADER_RESOURCE_VIEW_DESC](/reference/graphics/d3d12/structs/d3d12_shader_resource_view_desc_public.md)
- [D3D12_TEX1D_SRV](/reference/graphics/d3d12/structs/d3d12_tex1d_srv_public.md)
- [D3D12_CPU_DESCRIPTOR_HANDLE](/reference/graphics/d3d12/structs/d3d12_cpu_descriptor_handle_public.md)
- [D3D12_TEX3D_SRV](/reference/graphics/d3d12/structs/d3d12_tex3d_srv_public.md)
- [D3D12_TEXCUBE_SRV](/reference/graphics/d3d12/structs/d3d12_texcube_srv_public.md)
