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

# DrawIndexedInstanced

> 繪製已編製索引的執行個體化基本型別。

繪製已編製索引的執行個體化基本型別。

## 語法

```cpp theme={null}
void DrawIndexedInstanced(
    UINT IndexCountPerInstance,
    UINT InstanceCount,
    UINT StartIndexLocation,
    INT BaseVertexLocation,
    UINT StartInstanceLocation
)
```

### 參數

*IndexCountPerInstance \[in]*\
類型：UINT

每個執行個體從索引緩衝區讀取的索引數目。

*InstanceCount \[in]*\
類型：UINT

要繪製的執行個體數目。

*StartIndexLocation \[in]*\
類型：UINT

GPU 從索引緩衝區讀取之第一個索引的位置。

*BaseVertexLocation \[in]*\
類型：INT

從頂點緩衝區讀取頂點之前，加到每個索引的值。

*StartInstanceLocation \[in]*\
類型：UINT

從頂點緩衝區讀取每個執行個體的資料之前，加到每個索引的值。

### 傳回值

類型：void

無。

## 備註

繪製 API 會將工作提交至轉譯管線。

執行個體化可透過重複使用相同的幾何來繪製場景中的多個物件，以提升效能。執行個體化的一個範例是
以不同的位置和色彩繪製相同的物件。執行個體化需要多個頂點緩衝區：至少一個用於每個頂點的資料，
以及第二個用於每個執行個體之資料的緩衝區。

#### 範例

[D3D12Bundles](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) 範例使用 **ID3D12GraphicsCommandList::DrawIndexedInstanced** 的方式如下：

```cpp theme={null}
void FrameResource::PopulateCommandList(ID3D12GraphicsCommandList* pCommandList, ID3D12PipelineState* pPso1, ID3D12PipelineState* pPso2,
UINT frameResourceIndex, UINT numIndices, D3D12_INDEX_BUFFER_VIEW* pIndexBufferViewDesc, D3D12_VERTEX_BUFFER_VIEW* pVertexBufferViewDesc,
ID3D12DescriptorHeap* pCbvSrvDescriptorHeap, UINT cbvSrvDescriptorSize, ID3D12DescriptorHeap* pSamplerDescriptorHeap, ID3D12RootSignature* pRootSignature)
{
// If the root signature matches the root signature of the caller, then
// bindings are inherited, otherwise the bind space is reset.
pCommandList->SetGraphicsRootSignature(pRootSignature);

ID3D12DescriptorHeap* ppHeaps[] = { pCbvSrvDescriptorHeap, pSamplerDescriptorHeap };
pCommandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
pCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

pCommandList->IASetIndexBuffer(pIndexBufferViewDesc);

pCommandList->IASetVertexBuffers(0, 1, pVertexBufferViewDesc);

pCommandList->SetGraphicsRootDescriptorTable(0, pCbvSrvDescriptorHeap->GetGPUDescriptorHandleForHeapStart());
pCommandList->SetGraphicsRootDescriptorTable(1, pSamplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart());

// Calculate the descriptor offset due to multiple frame resources.
// 1 SRV + how many CBVs we have currently.
UINT frameResourceDescriptorOffset = 1 + (frameResourceIndex * m_cityRowCount * m_cityColumnCount);
CD3DX12_GPU_DESCRIPTOR_HANDLE cbvSrvHandle(pCbvSrvDescriptorHeap->GetGPUDescriptorHandleForHeapStart(), frameResourceDescriptorOffset, cbvSrvDescriptorSize);

BOOL usePso1 = TRUE;
for (UINT i = 0; i < m_cityRowCount; i++)
{
for (UINT j = 0; j < m_cityColumnCount; j++)
{
// Alternate which PSO to use; the pixel shader is different on
// each just as a PSO setting demonstration.
pCommandList->SetPipelineState(usePso1 ? pPso1 : pPso2);
usePso1 = !usePso1;

// Set this city's CBV table and move to the next descriptor.
pCommandList->SetGraphicsRootDescriptorTable(2, cbvSrvHandle);
cbvSrvHandle.Offset(cbvSrvDescriptorSize);

pCommandList->DrawIndexedInstanced(numIndices, 1, 0, 0, 0);
}
}
}

```

請參閱 [D3D12 參考中的範例程式碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code)。

<div class="code" />

## 需求

**標頭:** d3d12\_xs.h 或 d3d12\_x.h\
**程式庫:** d3d12\_xs.lib 或 d3d12\_x.lib\
**支援的平台**: XBOX Series 主機與 XBOX One 系列

## 另請參閱

[ID3D12GraphicsCommandList](/zh-TW/reference/graphics/d3d12_xs/interfaces/ID3D12GraphicsCommandList/id3d12graphicscommandlist_xs)


## Related topics

- [D3D12_DRAW_INDEXED_ARGUMENTS](/zh-TW/reference/graphics/d3d12/structs/d3d12_draw_indexed_arguments_public.md)
- [DrawInstanced](/zh-TW/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_drawinstanced_public.md)
- [D3D12_DRAW_ARGUMENTS](/zh-TW/reference/graphics/d3d12/structs/d3d12_draw_arguments_public.md)
- [XblTournamentGameResult](/zh-TW/reference/live/xsapi-c/multiplayer_c/enums/xbltournamentgameresult.md)
- [ID3D12MetaCommand](/zh-TW/reference/graphics/d3d12/interfaces/id3d12metacommand/id3d12metacommand_public.md)
