Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Query resolve #1638

Closed
msiglreith opened this issue Nov 22, 2017 · 1 comment
Closed

[RFC] Query resolve #1638

msiglreith opened this issue Nov 22, 2017 · 1 comment

Comments

@msiglreith
Copy link
Contributor

msiglreith commented Nov 22, 2017

Overview

We have 3 types of queries in Vulkan: Occlusion, PipelineStatistics and Timestamp.
The first two are handled via vkCmdBeginQuery/vkCmdEndQuery and timestamps via vkCmdWriteTimestamp. Queries are allocated in heaps and marked as 'unavailable' at the beginning.
vkCmdBeginQuery calls activate queries and once the results can be obtained (after vkCmdEndQuery) the state will switch to available. vkResetQueryPool will reset them to unavailable.

Mapping to Metal

Metal doesn't expose any significant kind of timestamp or pipeline statistics support (afaik) and only supports Counting occlusion query.
Therefore, pipelineStatisticsQuery feature should be exposed as false, timestampComputeAndGraphics as false and timestampValidBits as 0 for all queues.
Occlusion queries are configured at renderpass boundary. Binary occlusion support is required and counting optional. Results are directly written to a buffer.

Mapping to D3D12

D3D12 uses query heaps, similar to Vulkan's query pools. The begin/end/write commands can be mapped without significant overhead to D3D12. Reset command implementation depends on the further Vulkan Portability API.
Resolving query data in D3D12 is implemented as a command list function ResolveQueryData(https://msdn.microsoft.com/de-de/library/windows/desktop/dn903896(v=vs.85).aspx). It write the current query values contiguously to a buffer (upload/download/local) as 64bit integers.
Vulkan exposes two functions to resolve queries: vkGetQueryPoolResults (device-side) and vkCmdCopyQueryPoolResults (command buffer-side). Beside additional effort to submit a command buffer with a query resolve to emulate the device function, the VkQueryResultFlags are difficult to handle:

  • VK_QUERY_RESULT_64_BIT denotes that values are written as u64 values (default: u32)
  • VK_QUERY_RESULT_WITH_AVAILABILITY_BIT adds an additional integer value indicating if the specific query is available to the buffer.
  • VK_QUERY_RESULT_WAIT_BIT waits on all queries to be available, else resulting in a possible device loss.

Additionally, users can define which pipeline statistics can should be recorded and only marked statistics get written to the buffer. D3D12 will emit all statistics.

Issues

  • Track the status (available/unavailable) of each query in the query heap to correctly emit the availability flags if requested. As these happen async it needs to be done in the command buffer. For example, compute shader to write availability values into an hidden buffer on command buffer end if we have Begin/EndQuery commands.
  • Compute shader to handle the case where VK_QUERY_RESULT_64_BIT is not set.
  • vkGetQueryPoolResults requires additional synchronization to ensure that queries have been processed by the command queues when VK_QUERY_RESULT_WAIT_BIT is set.

I think these are the main issues so far. Metal requires a bit further analysis but shouldn't cause major complications.

@msiglreith msiglreith added this to the Vulkan Portability MVP milestone Nov 22, 2017
This was referenced Nov 22, 2017
bors bot added a commit that referenced this issue Nov 23, 2017
1640: Query operations r=kvark a=msiglreith

First steps regarding full query support. This PR only contains query pool creation and recording. Resolve is still up to discussion #1638 .

Implementation details:
* D3D12 uses binary occlusion queries if `PRECISE` is not specified
* D3D12 internally caches the currently used query to have access on the query type on end
* Query operations are supported on compute and graphics command buffers. Therefore a new helper capability is introduced which is implemented for Compute, Graphics and General command buffers to circumvent this.

~~**WIP** as there are outstanding ash changes (and might include resolve operations)~~
@kvark kvark added the client: blocker blocker issue for a known client label Aug 18, 2018
@kvark
Copy link
Member

kvark commented Aug 18, 2018

Note: this is currently a blocker for Dolphin on Metal. Adding the tag.

bors bot added a commit that referenced this issue Aug 23, 2018
2334: Query API and basic support on Metal r=grovesNL a=kvark

Fixes #1638 (for the most part)
PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [ ] tested examples with the following backends:
- [ ] `rustfmt` run on changed code


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
bors bot added a commit that referenced this issue Aug 23, 2018
2334: Query API and basic support on Metal r=grovesNL a=kvark

Fixes #1638 (for the most part)
PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [ ] tested examples with the following backends:
- [ ] `rustfmt` run on changed code


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
bors bot added a commit that referenced this issue Aug 23, 2018
2334: Query API and basic support on Metal r=grovesNL a=kvark

Fixes #1638 (for the most part)
PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [ ] tested examples with the following backends:
- [ ] `rustfmt` run on changed code


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
@bors bors bot closed this as completed in #2334 Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants