Share via


Metodo ID3D12GraphicsCommandList::D rawIndexedInstanced (d3d12.h)

Disegna primitive indicizzate, con istanze.

Sintassi

void DrawIndexedInstanced(
  [in] UINT IndexCountPerInstance,
  [in] UINT InstanceCount,
  [in] UINT StartIndexLocation,
  [in] INT  BaseVertexLocation,
  [in] UINT StartInstanceLocation
);

Parametri

[in] IndexCountPerInstance

Tipo: UINT

Numero di indici letti dal buffer di indice per ogni istanza.

[in] InstanceCount

Tipo: UINT

Numero di istanze da disegnare.

[in] StartIndexLocation

Tipo: UINT

Posizione del primo indice letto dalla GPU dal buffer di indice.

[in] BaseVertexLocation

Tipo: INT

Valore aggiunto a ogni indice prima di leggere un vertice dal buffer del vertice.

[in] StartInstanceLocation

Tipo: UINT

Valore aggiunto a ogni indice prima di leggere i dati per istanza da un buffer dei vertici.

Valore restituito

nessuno

Osservazioni

Un'API di disegno invia il lavoro alla pipeline di rendering.

L'instancing può estendere le prestazioni riutilizzando la stessa geometria per disegnare più oggetti in una scena. Un esempio di instancing potrebbe essere quello di disegnare lo stesso oggetto con posizioni e colori diversi. L'instancing richiede più buffer dei vertici: almeno uno per i dati per vertice e un secondo buffer per i dati per istanza.

Esempio

L'esempio D3D12Bundles usa ID3D12GraphicsCommandList::D rawIndexedInstanced come indicato di seguito:

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);
        }
    }
}

Vedere Codice di esempio nel riferimento D3D12.

Requisiti

Requisito Valore
Piattaforma di destinazione Windows
Intestazione d3d12.h
Libreria D3d12.lib
DLL D3d12.dll

Vedi anche

ID3D12GraphicsCommandList