Skip to content

Pipeline statistics clarifications #794

Closed

Description

@Kangz

While looking at the pipeline statistics queries and how it would change webgpu.h, I had the following two questions:

  • Should they be allowed in GPURenderBundle? They currently are, but it seems to conflict with our earlier decision to disallow occlusion queries on render bundles.
  • Are pipeline statistics queries allowed to be nested, or even interleaved? If not, then endPipelineStatisticsQuery should not take any argument.

+CC @haoxli

Activity

  1. Kangz commented on May 20, 2020

    @Kangz
    ContributorAuthor

    For nesting, the Vulkan spec says:

    queryPool must have been created with a queryType that differs from that of any queries that are active within commandBuffer.

    So I think that should be disallowed, and endPipelineStatisticsQuery can have no argument.

  2. haoxli commented on May 21, 2020

    @haoxli
    Contributor

    Should they be allowed in GPURenderBundle? They currently are, but it seems to conflict with our earlier decision to disallow occlusion queries on render bundles.

    Yes, you're right, D3D12 and Metal don't support Query API on render bundles. I will move the Pipeline Statistcs APIs to GPURenderPassEncoder and GPUComputePassEncoder.

    queryPool must have been created with a queryType that differs from that of any queries that are active within commandBuffer.

    It only does not allow to create queryPool with same query type, but we can nest the query operation for a same query type, even for different query types, such as:

    pass.beginPipelineStatisticsQuery(queryset, 0);
    pass.beginPipelineStatisticsQuery(queryset, 1);
    pass.draw(3, 1, 0, 0);
    pass.endPipelineStatisticsQuery(queryset, 1);
    pass.draw(6, 1, 3, 0);
    pass.endPipelineStatisticsQuery(queryset, 0);
    

    or

    pass.beginPipelineStatisticsQuery(psQuerySet, 0);
    pass.writeTimestamp(tsQuerySet, 0);
    pass.draw(3, 1, 0, 0);
    pass.writeTimestamp(tsQuerySet, 1);
    pass.draw(6, 1, 3, 0);
    pass.endPipelineStatisticsQuery(psQuerySet, 0);
    

    Maybe we can remove the args of queryset becase we have seprate api for different queries, but if removed, we need told users which the queryset the results are stored in, and the created queryset is only used when resolving, maybe also considerring not expose queryset, and resolving the data with query type instead, becasue there is only one queryset for each type, we can handle them in native. I think it will increase the complexity of the implementation, so currently I prefer to keep these arguments.

  3. Kangz commented on May 21, 2020

    @Kangz
    ContributorAuthor

    It only does not allow to create queryPool with same query type, but we can nest the query operation for a same query type, even for different query types, such as:

    I'm pretty sure that's not allowed, because when there is the first beginPipelineStatisticsQuery call, that query becomes active, and the validation text I quoted above will be triggered in the second call to beginPipelineStatisticsQuery. The Vulkan spec doesn't have any special text to allow additional queries if the query pool is already "active", it only cares whether any query is active for that type.

  4. haoxli commented on May 21, 2020

    @haoxli
    Contributor

    Oh, understand what you mean, but strangely, I can test this case pass with Vulkan validation layers, I will file the issue for the validation and add description on spec to disallow the nesting.

  5. kvark commented on May 21, 2020

    @kvark
    Contributor

    I'm a tiny bit concerned about how the pipeline statistics are going to be specified. In Vulkan the spec allows a lot of freedom to implementors, e.g.:

    VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT specifies that queries managed by the pool will count the number of compute shader invocations. The counter’s value is incremented every time the compute shader is invoked. Implementations may skip the execution of certain compute shader invocations or execute additional compute shader invocations for implementation-dependent reasons as long as the results of rendering otherwise remain unchanged.

    We can't put more strict wording, as we are constrained by the backend APIs. At the same time, if we have loose requirements like in Vulkan, we might as well just make it a part of WebGPU core and return zeroes where it's not supported :/

  6. haoxli commented on May 25, 2020

    @haoxli
    Contributor

    I filed an issue for the nested queries in Vulkan validation layers: KhronosGroup/Vulkan-ValidationLayers#1874.

    @kvark Now we use an array of enum in GPUPipelineStatisticName to specified pipeline statistics, and also return 0 if the specified pipeline statistics is not supported. Difference is the number and order of the results written to buffer match the number and order of the specified pipeline statistics, in Vulkan, they are fixed.

  7. kvark commented on May 25, 2020

    @kvark
    Contributor

    I don't think my concern is understood. What I'm saying is that it seems perfectly valid for a Vulkan implementation to return 0 for the number of compute shader invocation. We have no way of knowing that behavior and detecting it explicitly, so that we could make a decision to not expose this extension.

  8. Kangz commented on May 26, 2020

    @Kangz
    ContributorAuthor

    The pipeline statistics are purely informational because the hardware / driver / WebGPU implementation can do whatever it wants. For example any of these could decide to implement some copies with a compute shader, and that will modify the hardware counter. This is fine as long as the extension is exposed in more trusted contexts, or that it influences the privacy budget.

    Because of the privacy implications, I think it is actually better to have the feature listed separately, so web pages know they will pay some privacy budget, or know they are not trusted to have this feature that can improve fingerprinting.

  9. kvark commented on May 26, 2020

    @kvark
    Contributor

    I'm just worried about this extension because we can't strictly specify what it does. The information it provides is unreliable, at least when it comes to Vulkan backend. I.e. how do we describe the semantics of the numbers here? The Web has a higher bar for specifying behaviour than native.

    Perhaps, a deeper investigation is needed - to find out if Metal and D3D12 have more strict guarantees about the numbers.

    Or perhaps, we should just say that this extension will only be available locally for developers having dev-tools enabled, and isn't useful/available for applications that ship.

  10. Kangz commented on May 26, 2020

    @Kangz
    ContributorAuthor

    Or perhaps, we should just say that this extension will only be available locally for developers having dev-tools enabled, and isn't useful/available for applications that ship.

    Yeah basically it would be 100% informational. We might want to make this slightly less restrictive so it can be used for telemetry too but the intent of the extension should definitely to give numbers that can't really be used for accurate accounting during the frame.

  11. haoxli commented on May 27, 2020

    @haoxli
    Contributor

    @kvark Thanks for clarify. Metal just specify what the returned values are stand for. D3D12 has some descriptions to explain what will affect the results.

    I think these values are intended to measure relative complexity of different parts of applications and get insights into the GPU operations while performance tuning. So how about add description to reminder users like this:
    Note: These values are intended to measure relative statistics generated by operations of the device. Be careful to use these values in the release version of applications, because various device architectures may count these values differently.

  12. kvark commented on May 28, 2020

    @kvark
    Contributor

    Here is a radical proposal: let's not have pipeline statistics in the main specification.

    First, we can't specify this. We can't just say this is a bunch of numbers.

    Secondly, it may expose the details of driver/HW that makes fingerprinting easier. For example, a particular driver decides to work around a hardware bug by using compute shaders for copying data between buffers and textures (internally!). This is now observable.

    We already know (and I think we agree?) that this isn't useful for shipped applications. It's only useful during development, so in some sort of "dev-tools" mode of the API. So I think it's best to have a separate document for the dev-tools side of the API, explaining the synchronous error modes, additional extensions, etc.

  13. Kangz commented on May 28, 2020

    @Kangz
    ContributorAuthor

    We already know (and I think we agree?) that this isn't useful for shipped applications. It's only useful during development, so in some sort of "dev-tools" mode of the API. So I think it's best to have a separate document for the dev-tools side of the API, explaining the synchronous error modes, additional extensions, etc.

    I don't exactly agree. Things like timestamps are also super useful for telemetry. Also imagine something like the three.js debugger, you don't want to tell people to add the debugger in a <script> tag but also go and flip a couple scary switches in the devtools. It's better if it is broadly available but explains that you can get varying numbers back.

  14. kainino0x commented on May 28, 2020

    @kainino0x
    Contributor

    I think timestamps are needed in core for dynamic performance tuning (and telemetry). But I agree that pipeline statistics don't seem that useful in shipped applications.

    I think it's okay to require developers to open dev tools and check a box (#814) in order to e.g. get extra features in the three.js debugger.

  15. added this to the V1.0 milestone on Sep 20, 2021
  16. Kangz commented on Sep 20, 2021

    @Kangz
    ContributorAuthor

    For V1, we need to move the extension to a separate doc anyway.

  17. kainino0x commented on Nov 4, 2021

    @kainino0x
    Contributor

    Issue triage: These particular topics above may still need some investigation. The feature itself may or may not need to move to a separate doc; we still need to discuss more. (Is this feature something we want to expose on end user machines? Can the results be fuzzed enough to avoid privacy issues?)

  18. kainino0x commented on Nov 10, 2021

    @kainino0x
    Contributor

    We currently don't see a need to make this a web-exposed feature, so I'm going to propose removing it from the main spec (probably moving it into an "extension" document - #814). I think we had already tentatively agreed on this a while ago.

    @haoxli just want to make sure, is this OK with you? Or do you know of a use-case for exposing pipeline statistics queries to the Web (that would justify including the feature and doing the work to figure out how to round the results to combat fingerprinting)?

  19. haoxli commented on Nov 11, 2021

    @haoxli
    Contributor

    @kainino0x It's OK to move pipeline statistics queries to a seperate documents now. I think it could be used for pipeline profiling by developers, but I don’t have specific scenarios yet. We can implement it when we need.

  20. added a commit that references this issue on Nov 11, 2021
  21. litherum commented on Nov 11, 2021

    @litherum
    Contributor

    #2296 is a PR to tentatively delete pipeline statistics from the main spec (presumably so it can possibly be moved to a separate document).

  22. added a commit that references this issue on Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions