Skip to content

Pipeline statistics

What it does

<RI/Helpers/Statistics.hpp> reads the result of one counter query (RI::QueryType::ePipelineStatistics, RI::QueryType::eMeshPipelineStatistics, or RI::QueryType::eMeshPrimitives) into a fixed RI::Helpers::PipelineStatistics struct whose fields are the same on Vulkan and D3D12.

Vulkan and D3D12 write pipeline-statistics counters in different orders, so RI reports each counter's byte offset in RI::PipelineStatisticsLayout (returned by RI::pipelineStatisticsLayout(device, type)) instead of converting the data itself. RI::Helpers::readPipelineStatistics(layout, result) performs that conversion on the CPU. Pass it the RI::PipelineStatisticsLayout for the query pool's RI::QueryType and a pointer to one resolved query result (layout.size bytes) in readback memory, after the submission that called RI::cmdResolveQueries has reached its timeline point.

Each uint64 field of RI::Helpers::PipelineStatistics holds one counter. Any counter that the query type does not include, or that the GPU does not support, is read as 0. The function keeps no state and submits no GPU work.

Example

const RI::PipelineStatisticsLayout layout = RI::pipelineStatisticsLayout(device);
// ... cmdBeginQuery / cmdEndQuery around the draws, cmdResolveQueries into `results`,
// submit, then wait for the point ...
const RI::Helpers::PipelineStatistics stats = RI::Helpers::readPipelineStatistics(layout, results.mapped);
std::printf("%llu pixel shader runs\n", static_cast<unsigned long long>(stats.pixelShaderInvocations));

// Around mesh draws: the mesh set, and the primitive count where the GPU has it.
const RI::PipelineStatisticsLayout meshLayout =
    RI::pipelineStatisticsLayout(device, RI::QueryType::eMeshPrimitives);
if (meshLayout.meshPrimitives != RI::kNoCounter) {
    // ... a pool of type eMeshPrimitives, resolved into `primitives` ...
    const auto counts = RI::Helpers::readPipelineStatistics(meshLayout, primitives.mapped);
    std::printf("%llu mesh primitives\n", static_cast<unsigned long long>(counts.meshPrimitives));
}

How to roll your own

Each counter is a 64-bit unsigned integer (RI::uint64) at byte offset layout.<counter> from result. If layout.<counter> is RI::kNoCounter, the query type does not include that counter or the GPU does not support it. Copy the counters you need with std::memcpy.