ID3D12GraphicsCommandList::SetPredication-Methode (d3d12.h)

Legt ein Rendering-Prädikat fest.

Syntax

void SetPredication(
  [in, optional] ID3D12Resource       *pBuffer,
  [in]           UINT64               AlignedBufferOffset,
  [in]           D3D12_PREDICATION_OP Operation
);

Parameter

[in, optional] pBuffer

Typ: ID3D12Resource*

Der Puffer als ID3D12Resource, der sich im D3D12_RESOURCE_STATE_PREDICATION - oder D3D21_RESOURCE_STATE_INDIRECT_ARGUMENT-Zustand befinden muss (beide Werte sind identisch und aus Gründen der Übersichtlichkeit als Aliase angegeben) oder NULL , um die Prädication zu deaktivieren.

[in] AlignedBufferOffset

Typ: UINT64

Der ausgerichtete Pufferoffset als UINT64.

[in] Operation

Typ: D3D12_PREDICATION_OP

Gibt einen D3D12_PREDICATION_OP an, z. B. D3D12_PREDICATION_OP_EQUAL_ZERO oder D3D12_PREDICATION_OP_NOT_EQUAL_ZERO.

Rückgabewert

Keine

Bemerkungen

Verwenden Sie diese Methode, um anzugeben, dass nachfolgende Rendering- und Ressourcenbearbeitungsbefehle nicht tatsächlich ausgeführt werden, wenn die resultierenden Prädikatdaten des Prädikats dem angegebenen Vorgang entsprechen.

Im Gegensatz zu Direct3D 11 wird die Prädierung im Direct3D 12-Zustand nicht von direkten Befehlslisten geerbt, und die Prädication wird immer berücksichtigt (es gibt keine Prädicationshinweise). Alle direkten Befehlslisten beginnen mit deaktivierter Prädication. Bundles erben den Prädicationszustand. Es ist zulässig, dass dasselbe Prädikat mehrmals gebunden wird.

Ungültige API-Aufrufe führen dazu, dass Close einen Fehler zurückgibt, oder ID3D12CommandQueue::ExecuteCommandLists , der die Befehlsliste verwirft und das Gerät entfernt.

Die Debugebene gibt Immer dann Fehler aus, wenn die Laufzeitvalidierung fehlschlägt.

Weitere Informationen finden Sie unter Prädication .

Beispiele

Im D3D12PredicationQueries-Beispiel wird ID3D12GraphicsCommandList::SetPredication wie folgt verwendet:

// Fill the command list with all the render commands and dependent state.
void D3D12PredicationQueries::PopulateCommandList()
{
    // Command list allocators can only be reset when the associated 
    // command lists have finished execution on the GPU; apps should use 
    // fences to determine GPU execution progress.
    ThrowIfFailed(m_commandAllocators[m_frameIndex]->Reset());

    // However, when ExecuteCommandList() is called on a particular command 
    // list, that command list can then be reset at any time and must be before 
    // re-recording.
    ThrowIfFailed(m_commandList->Reset(m_commandAllocators[m_frameIndex].Get(), m_pipelineState.Get()));

    // Set necessary state.
    m_commandList->SetGraphicsRootSignature(m_rootSignature.Get());

    ID3D12DescriptorHeap* ppHeaps[] = { m_cbvHeap.Get() };
    m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);

    m_commandList->RSSetViewports(1, &m_viewport);
    m_commandList->RSSetScissorRects(1, &m_scissorRect);

    // Indicate that the back buffer will be used as a render target.
    m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

    CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart(), m_frameIndex, m_rtvDescriptorSize);
    CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle(m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
    m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);

    // Record commands.
    const float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };
    m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);
    m_commandList->ClearDepthStencilView(dsvHandle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

    // Draw the quads and perform the occlusion query.
    {
        CD3DX12_GPU_DESCRIPTOR_HANDLE cbvFarQuad(m_cbvHeap->GetGPUDescriptorHandleForHeapStart(), m_frameIndex * CbvCountPerFrame, m_cbvSrvDescriptorSize);
        CD3DX12_GPU_DESCRIPTOR_HANDLE cbvNearQuad(cbvFarQuad, m_cbvSrvDescriptorSize);

        m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
        m_commandList->IASetVertexBuffers(0, 1, &m_vertexBufferView);

        // Draw the far quad conditionally based on the result of the occlusion query
        // from the previous frame.
        m_commandList->SetGraphicsRootDescriptorTable(0, cbvFarQuad);
        m_commandList->SetPredication(m_queryResult.Get(), 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
        m_commandList->DrawInstanced(4, 1, 0, 0);

        // Disable predication and always draw the near quad.
        m_commandList->SetPredication(nullptr, 0, D3D12_PREDICATION_OP_EQUAL_ZERO);
        m_commandList->SetGraphicsRootDescriptorTable(0, cbvNearQuad);
        m_commandList->DrawInstanced(4, 1, 4, 0);

        // Run the occlusion query with the bounding box quad.
        m_commandList->SetGraphicsRootDescriptorTable(0, cbvFarQuad);
        m_commandList->SetPipelineState(m_queryState.Get());
        m_commandList->BeginQuery(m_queryHeap.Get(), D3D12_QUERY_TYPE_BINARY_OCCLUSION, 0);
        m_commandList->DrawInstanced(4, 1, 8, 0);
        m_commandList->EndQuery(m_queryHeap.Get(), D3D12_QUERY_TYPE_BINARY_OCCLUSION, 0);

        // Resolve the occlusion query and store the results in the query result buffer
        // to be used on the subsequent frame.
        m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_queryResult.Get(), D3D12_RESOURCE_STATE_PREDICATION, D3D12_RESOURCE_STATE_COPY_DEST));
        m_commandList->ResolveQueryData(m_queryHeap.Get(), D3D12_QUERY_TYPE_BINARY_OCCLUSION, 0, 1, m_queryResult.Get(), 0);
        m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_queryResult.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PREDICATION));
    }

    // Indicate that the back buffer will now be used to present.
    m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

    ThrowIfFailed(m_commandList->Close());
}

Weitere Informationen finden Sie unter Beispielcode in der D3D12-Referenz.

Anforderungen

   
Zielplattform Windows
Kopfzeile d3d12.h
Bibliothek D3d12.lib
DLL D3d12.dll

Weitere Informationen

ID3D12GraphicsCommandList

Exemplarische Vorgehensweise für Prädication-Abfragen