> ## 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.

# D3D12_SHADER_COMPONENT_MAPPING

> Specifies how memory gets routed by a shader resource view (SRV).

Specifies how memory gets routed by a shader resource view (SRV).

## Syntax

```cpp theme={null}
typedef enum D3D12_SHADER_COMPONENT_MAPPING
{
    D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0 = 0,
    D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1 = 1,
    D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2 = 2,
    D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3 = 3,
    D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0 = 4,
    D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1 = 5
} D3D12_SHADER_COMPONENT_MAPPING
```

## Constants

| Constant                                                      | Description                                                                                                                                                 |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FROM\_MEMORY\_COMPONENT\_0 | Indicates return component 0 (red).                                                                                                                         |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FROM\_MEMORY\_COMPONENT\_1 | Indicates return component 1 (green).                                                                                                                       |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FROM\_MEMORY\_COMPONENT\_2 | Indicates return component 2 (blue).                                                                                                                        |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FROM\_MEMORY\_COMPONENT\_3 | Indicates return component 3 (alpha).                                                                                                                       |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FORCE\_VALUE\_0            | Indicates forcing the resulting value to 0.                                                                                                                 |
| D3D12\_SHADER\_COMPONENT\_MAPPING\_FORCE\_VALUE\_1            | Indicates forcing the resulting value 1. The value of forcing 1 is either 0x1 or 1.0f depending on the format type for that component in the source format. |

## Remarks

This enum allows the SRV to select how memory gets routed to the four return components in a shader after a memory fetch. The options for each shader component \[0..3] (corresponding to RGBA) are: component 0..3 from the SRV fetch result or force 0 or force 1.

The default 1:1 mapping can be indicated by specifying **D3D12\_DEFAULT\_SHADER\_4\_COMPONENT\_MAPPING**, otherwise an arbitrary mapping can be specified using the macro **D3D12\_ENCODE\_SHADER\_4\_COMPONENT\_MAPPING**.

See below.

Note the following defines.

```cpp theme={null}
#define D3D12_SHADER_COMPONENT_MAPPING_MASK 0x7
#define D3D12_SHADER_COMPONENT_MAPPING_SHIFT 3
#define D3D12_SHADER_COMPONENT_MAPPING_ALWAYS_SET_BIT_AVOIDING_ZEROMEM_MISTAKES \
(1<<(D3D12_SHADER_COMPONENT_MAPPING_SHIFT*4))
#define D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(Src0,Src1,Src2,Src3) \
((((Src0)&D3D12_SHADER_COMPONENT_MAPPING_MASK)| \
(((Src1)&D3D12_SHADER_COMPONENT_MAPPING_MASK)<<D3D12_SHADER_COMPONENT_MAPPING_SHIFT)| \
(((Src2)&D3D12_SHADER_COMPONENT_MAPPING_MASK)<<(D3D12_SHADER_COMPONENT_MAPPING_SHIFT*2))| \
(((Src3)&D3D12_SHADER_COMPONENT_MAPPING_MASK)<<(D3D12_SHADER_COMPONENT_MAPPING_SHIFT*3))| \
D3D12_SHADER_COMPONENT_MAPPING_ALWAYS_SET_BIT_AVOIDING_ZEROMEM_MISTAKES))
#define D3D12_DECODE_SHADER_4_COMPONENT_MAPPING(ComponentToExtract,Mapping) \
((D3D12_SHADER_COMPONENT_MAPPING)(Mapping >> (D3D12_SHADER_COMPONENT_MAPPING_SHIFT*ComponentToExtract) & D3D12_SHADER_COMPONENT_MAPPING_MASK))
#define D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING(0,1,2,3)
```

## Requirements

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

## See Also

[Core enumerations](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/direct3d-12-enumerations)


## Related topics

- [D3D12_SHADER_RESOURCE_VIEW_DESC](/reference/graphics/d3d12/structs/d3d12_shader_resource_view_desc_public.md)
- [D3D12_SHADER_CACHE_SESSION_DESC](/reference/graphics/d3d12/structs/d3d12_shader_cache_session_desc_public.md)
- [D3D12_TILE_MAPPING_FLAGS](/reference/graphics/d3d12/enums/d3d12_tile_mapping_flags_public.md)
- [D3D12_SHADER_VISIBILITY](/reference/graphics/d3d12/enums/d3d12_shader_visibility_public.md)
- [D3D12_SHADER_BYTECODE](/reference/graphics/d3d12/structs/d3d12_shader_bytecode_public.md)
