ID3D12GraphicsCommandList::ResolveQueryData 方法 (d3d12.h)

從查詢擷取數據。 ResolveQueryData 適用於所有堆積類型, (預設、上傳和回讀) 。

語法

void ResolveQueryData(
  [in] ID3D12QueryHeap  *pQueryHeap,
  [in] D3D12_QUERY_TYPE Type,
  [in] UINT             StartIndex,
  [in] UINT             NumQueries,
  [in] ID3D12Resource   *pDestinationBuffer,
  [in] UINT64           AlignedDestinationBufferOffset
);

參數

[in] pQueryHeap

類型: ID3D12QueryHeap*

指定要解析之查詢的 ID3D12QueryHeap

[in] Type

類型: D3D12_QUERY_TYPE

指定查詢的類型,這是 D3D12_QUERY_TYPE的一個成員。

[in] StartIndex

類型: UINT

指定要解析之第一個查詢的索引。

[in] NumQueries

類型: UINT

指定要解析的查詢數目。

[in] pDestinationBuffer

類型: ID3D12Resource*

指定 ID3D12Resource 目的地緩衝區,其必須處於狀態 D3D12_RESOURCE_STATE_COPY_DEST

[in] AlignedDestinationBufferOffset

類型: UINT64

指定目的地緩衝區的對齊位移。 必須是8個字節的倍數。

傳回值

備註

ResolveQueryData 會執行批次作業,將查詢數據寫入目的地緩衝區。 查詢數據會連續寫入目的地緩衝區和 參數。

ResolveQueryData 會將應用程式不透明查詢堆積中的 application-opaque 查詢數據轉換成應用程式可用的配接器不透明值。 解決堆積內尚未完成 (的查詢,因此已為其呼叫 ID3D12GraphicsCommandList::BeginQuery ,但不會呼叫 ID3D12GraphicsCommandList::EndQuery) 或尚未初始化,會導致未定義的行為,並可能導致裝置停止回應或移除。 如果偵錯層偵測到應用程式已解決不完整或未初始化的查詢,就會發出錯誤。

注意

解析不完整或未初始化的查詢是未定義的行為,因為驅動程式可能會在未解析的查詢內部儲存 GPUVA 或其他數據。 因此,嘗試解決未初始化數據上的這些查詢可能會導致頁面錯誤或裝置停止回應。 舊版的偵錯層未驗證此行為。

二進位遮蔽查詢會為每個查詢寫入 64 位。 最小有效位是 0 (物件完全遮蔽) ,或至少繪製 1 個物件樣本的 1 (個樣本) 。 其餘的位是 0。 遮蔽查詢會為每個查詢寫入 64 位。 此值是通過測試的樣本數目。 時間戳查詢會為每個查詢寫入 64 位,這是必須與個別命令佇列頻率進行比較的刻度值, (請參閱 計時) 。

管線統計數據查詢會為每個查詢寫入 D3D12_QUERY_DATA_PIPELINE_STATISTICS 結構。 所有串流輸出統計數據查詢都會為每個查詢寫入 D3D12_QUERY_DATA_SO_STATISTICS 結構。

核心運行時間會驗證下列專案。

  • StartIndexNumQueries 位於範圍內。
  • AlignedDestinationBufferOffset 是 8 個字節的倍數。
  • DestinationBuffer 是緩衝區。
  • 寫入的數據不會溢位輸出緩衝區。
  • 命令清單類型必須支援查詢類型。
  • 查詢堆積必須支持查詢類型。

如果目的地緩衝區不是處於D3D12_RESOURCE_STATE_COPY_DEST狀態,或者任何已解決的查詢沒有 ID3D12GraphicsCommandList::EndQuery ,偵錯層就會發出警告。

範例

D3D12PredicationQueries 範例使用 ID3D12GraphicsCommandList::ResolveQueryData,如下所示:

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

請參閱 D3D12 參考中的範例程式代碼

規格需求

需求
目標平台 Windows
標頭 d3d12.h
程式庫 D3d12.lib
Dll D3d12.dll

另請參閱

ID3D12GraphicsCommandList