这是indexloc提供的服务,不要输入任何密码
Skip to content

Query API: Disallow resolve the unused queries or resolve them to 0? #1072

@haoxli

Description

@haoxli
encoder.WriteTimestamp(querySet, 0 /*queryIndex*/); 
encoder.WriteTimestamp(querySet, 2 /*queryIndex*/);
encoder.ResolveQuerySet(querySet, 0 /*firstQuery*/, 3 /*queryCount*/, destination, 0);

Vulkan spec says:

If VK_QUERY_RESULT_WAIT_BIT is set, the implementation will wait for each query’s status to be in the available state before retrieving the numerical results for that query.
If the query does not become available in a finite amount of time (e.g. due to not issuing a query since the last reset), a VK_ERROR_DEVICE_LOST error may occur.

It requires that the queries between [firstQuery, firstQuery + queryCount - 1] must be available (written by query operations: begin/end query, write timestamp), otherwise the validation error is thrown when resolving queries. But on D3D12 and Metal, the unused queries between [firstQuery, firstQuery + queryCount - 1] will be resolved to 0.

After query pool creation, each query must be reset before it is used. Queries must also be reset between uses.

Vulkan also requires that each queries in query set must be reset (call vkCmdResetQueryPool) before each use and only can reset them outside the render pass. So we need to record the used indexes in command encoder, render encoder, compute encoder when encoding commands, parse the recorded indexes to get the their intervals, then reset the queries in the intervals when creating command buffer and begin render/compute pass.

So there is a workaround for Vulkan backend if we want to resolve unused queries to 0:
When resolving the queries, call resolve commands based on each interval of the recorded indexes, first query is the first query index in each interval, query count is the number of the queries in each interval. For the left memory in destination buffer which not written values, write with 0.

We haven't decided whether to disallow resolve unused queries or follow D3D12/Metal behavior, so open it here for further discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions