ID3D12GraphicsCommandList::D rawIndexedInstanced 方法 (d3d12.h)
繪製已編製索引、實例的基本類型。
語法
void DrawIndexedInstanced(
[in] UINT IndexCountPerInstance,
[in] UINT InstanceCount,
[in] UINT StartIndexLocation,
[in] INT BaseVertexLocation,
[in] UINT StartInstanceLocation
);
參數
[in] IndexCountPerInstance
類型: UINT
從每個實例的索引緩衝區讀取的索引數目。
[in] InstanceCount
類型: UINT
要繪製的實例數目。
[in] StartIndexLocation
類型: UINT
GPU 從索引緩衝區讀取的第一個索引位置。
[in] BaseVertexLocation
類型: INT
從頂點緩衝區讀取頂點之前,新增至每個索引的值。
[in] StartInstanceLocation
類型: UINT
從頂點緩衝區讀取每個實例數據之前,新增至每個索引的值。
傳回值
無
備註
繪製 API 會將工作提交至轉譯管線。
實例可能會重複使用相同的幾何來擴充效能,以在場景中繪製多個物件。 實例的其中一個範例可能是繪製具有不同位置和色彩的相同物件。 實例需要多個頂點緩衝區:至少一個用於每個頂點數據,以及每個實例數據的第二個緩衝區。
範例
D3D12Bundles 範例使用 ID3D12GraphicsCommandList::D rawIndexedInstanced,如下所示:
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 參考中的範例程式代碼。
規格需求
需求 | 值 |
---|---|
目標平台 | Windows |
標頭 | d3d12.h |
程式庫 | D3d12.lib |
Dll | D3d12.dll |